next up previous contents
Next: A.6 Requesting Configuration Changes Up: A. The C Client Previous: A.4 Reading Data   Contents

A.5 Writing Commands

For writing commands to devices, the C client provides the function player_write():

  /*
   * write commands to the indicated connection. writes the data contained
   * in command, up to commandlen.
   *
   * Returns:
   *    0 if everything goes OK
   *   -1 if something went wrong (you should probably close the connection!)
   */
  int player_write(player_connection_t* conn, 
                   uint16_t device, uint16_t device_index,
                   const char* command, size_t commandlen);

This function will build the appropriate message header, including appropriate byte-swapping of the fields. The first commandlen bytes of command will be copied in as the payload of a messge that will be sent to the server. Note that the caller must byte-swap the contents of the command itself. A simple example that tells the 0th position device to spin in place:

  ...
  player_position_cmd_t cmd;
  cmd.speed = htons(0);
  cmd.turnrate = htons(40);
  if(player_write(&conn, PLAYER_POSITION_CODE, 0, (char*)&cmd, 
                  sizeof(player_position_cmd_t)) == -1)
    exit(1);
  ...



2004-06-02