From 95f5f7297357bd6d764ae7b55943cc7a15a7b4bd Mon Sep 17 00:00:00 2001 From: Krzysztof Wieclaw Date: Tue, 25 Sep 2018 14:37:54 +0200 Subject: [PATCH] Added new command class in command.h file Change-Id: I02ecf2742f30218a765caa202fe297bc1c8a5a73 Signed-off-by: Krzysztof Wieclaw --- inc/command.h | 9 ++++++++- src/messages/message_command.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/inc/command.h b/inc/command.h index 2efffeb..8fd02a9 100644 --- a/inc/command.h +++ b/inc/command.h @@ -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; diff --git a/src/messages/message_command.c b/src/messages/message_command.c index 6fcf179..5deec5c 100644 --- a/src/messages/message_command.c +++ b/src/messages/message_command.c @@ -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: -- 2.7.4