Added new command class in command.h file 27/190027/6
authorKrzysztof Wieclaw <k.wieclaw@samsung.com>
Tue, 25 Sep 2018 12:37:54 +0000 (14:37 +0200)
committerKrzysztof Wieclaw <k.wieclaw@samsung.com>
Tue, 2 Oct 2018 18:17:39 +0000 (20:17 +0200)
Change-Id: I02ecf2742f30218a765caa202fe297bc1c8a5a73
Signed-off-by: Krzysztof Wieclaw <k.wieclaw@samsung.com>
inc/command.h
src/messages/message_command.c

index 2efffeb..8fd02a9 100644 (file)
@@ -23,7 +23,8 @@
 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;
 
 /**
@@ -40,6 +41,12 @@ typedef struct __command {
                        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;
 
index 6fcf179..5deec5c 100644 (file)
@@ -91,6 +91,28 @@ static int _drive_command_deserialize(command_s *cmd, reader_t *reader)
        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;
@@ -107,6 +129,9 @@ static int _command_deserialize(command_s *cmd, reader_t *reader)
                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:
@@ -138,6 +163,22 @@ static int _drive_command_serialize(command_s *cmd, writer_t *writer)
        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;
@@ -152,6 +193,9 @@ static int _command_serialize(command_s *cmd, writer_t *writer)
                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: