From: Krzysztof Wieclaw Date: Wed, 26 Sep 2018 11:41:32 +0000 (+0200) Subject: Added new class in command.h file X-Git-Url: http://review.tizen.org/git/?p=apps%2Fnative%2Fgear-racing-car.git;a=commitdiff_plain;h=3c1ece609690fbfdd207433a551e6c376fd774ed Added new class in command.h file Change-Id: I445409e8fad79c176776027353c7575daaf78bab Signed-off-by: Krzysztof Wieclaw --- 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 d40e79b..5deec5c 100644 --- a/src/messages/message_command.c +++ b/src/messages/message_command.c @@ -60,6 +60,23 @@ void message_command_destroy(message_command_t *message) static int _camera_command_deserialize(command_s *cmd, reader_t *reader) { + int32_t elevation, azimuth; + int err = 0; + + err |= reader_read_int32(reader, &elevation); + err |= reader_read_int32(reader, &azimuth); + + if (err) return err; + + cmd->data.camera_position.camera_elevation = elevation; + cmd->data.camera_position.camera_azimuth = azimuth; + + return 0; +} + +static int _drive_command_deserialize(command_s *cmd, reader_t *reader) +{ + int32_t speed, dir; int err = 0; @@ -74,18 +91,24 @@ static int _camera_command_deserialize(command_s *cmd, reader_t *reader) return 0; } -static int _drive_command_deserialize(command_s *cmd, reader_t *reader) +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.camera_position.camera_elevation = elevation; - cmd->data.camera_position.camera_azimuth = azimuth; + 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; } @@ -106,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: @@ -115,6 +141,18 @@ static int _command_deserialize(command_s *cmd, reader_t *reader) static int _camera_command_serialize(command_s *cmd, writer_t *writer) { + int32_t elevation = cmd->data.camera_position.camera_elevation; + int32_t azimuth = cmd->data.camera_position.camera_azimuth; + int err = 0; + + err |= writer_write_int32(writer, elevation); + err |= writer_write_int32(writer, azimuth); + + return err; +} + +static int _drive_command_serialize(command_s *cmd, writer_t *writer) +{ int32_t speed = cmd->data.steering.speed; int32_t dir = cmd->data.steering.direction; int err = 0; @@ -125,12 +163,16 @@ static int _camera_command_serialize(command_s *cmd, writer_t *writer) return err; } -static int _drive_command_serialize(command_s *cmd, writer_t *writer) +static int _drive_and_camera_command_serialize(command_s *cmd, writer_t *writer) { - int32_t elevation = cmd->data.camera_position.camera_elevation; - int32_t azimuth = cmd->data.camera_position.camera_azimuth; + 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); @@ -151,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: