typedef enum command_type {
COMMAND_TYPE_NONE, /** Command doesn't carry any information */
COMMAND_TYPE_DRIVE, /** Command carries information about steering included in data.steering. */
- COMMAND_TYPE_CAMERA /** Command carries information about camera position in data.camera_position. */
+ COMMAND_TYPE_CAMERA, /** Command carries information about camera position in data.camera_position. */
+ COMMAND_TYPE_DRIVE_AND_CAMERA /** Command carries information about both camera position and steering in data.steering_and_camera. */
} command_type_e;
/**
int camera_elevation; /** Elevation of camera to be set from range [-10000, 10000]. */
int camera_azimuth; /** Azimuth of camera to be set from range [-10000, 10000]. */
} camera_position;
+ struct {
+ int speed; /** Speed to be set from range [-10000, 10000]. */
+ int direction; /** Direction to be set from range [-10000, 10000]. */
+ int camera_elevation; /** Elevation of camera to be set from range [-10000, 10000]. */
+ int camera_azimuth; /** Azimuth of camera to be set from range [-10000, 10000]. */
+ } steering_and_camera;
} data;
} command_s;
return 0;
}
+static int _drive_and_camera_command_deserialize(command_s *cmd, reader_t *reader)
+{
+
+ int32_t speed, dir;
+ int32_t elevation, azimuth;
+ int err = 0;
+
+ err |= reader_read_int32(reader, &speed);
+ err |= reader_read_int32(reader, &dir);
+ err |= reader_read_int32(reader, &elevation);
+ err |= reader_read_int32(reader, &azimuth);
+
+ if (err) return err;
+
+ cmd->data.steering_and_camera.speed = speed;
+ cmd->data.steering_and_camera.direction = dir;
+ cmd->data.steering_and_camera.camera_elevation = elevation;
+ cmd->data.steering_and_camera.camera_azimuth = azimuth;
+
+ return 0;
+}
+
static int _command_deserialize(command_s *cmd, reader_t *reader)
{
int32_t type;
case COMMAND_TYPE_CAMERA:
return _camera_command_deserialize(cmd, reader);
break;
+ case COMMAND_TYPE_DRIVE_AND_CAMERA:
+ return _drive_and_camera_command_deserialize(cmd, reader);
+ break;
case COMMAND_TYPE_NONE:
return 0;
default:
return err;
}
+static int _drive_and_camera_command_serialize(command_s *cmd, writer_t *writer)
+{
+ int32_t speed = cmd->data.steering_and_camera.speed;
+ int32_t dir = cmd->data.steering_and_camera.direction;
+ int32_t elevation = cmd->data.steering_and_camera.camera_elevation;
+ int32_t azimuth = cmd->data.steering_and_camera.camera_azimuth;
+ int err = 0;
+
+ err |= writer_write_int32(writer, speed);
+ err |= writer_write_int32(writer, dir);
+ err |= writer_write_int32(writer, elevation);
+ err |= writer_write_int32(writer, azimuth);
+
+ return err;
+}
+
static int _command_serialize(command_s *cmd, writer_t *writer)
{
int32_t type = cmd->type;
case COMMAND_TYPE_CAMERA:
return _camera_command_serialize(cmd, writer);
break;
+ case COMMAND_TYPE_DRIVE_AND_CAMERA:
+ return _drive_and_camera_command_serialize(cmd, writer);
+ break;
case COMMAND_TYPE_NONE:
return 0;
default: