Controller Connection API for P2P on UDP communication 12/188912/16
authorKrzysztof Wieclaw <k.wieclaw@samsung.com>
Tue, 11 Sep 2018 15:38:01 +0000 (17:38 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Fri, 14 Sep 2018 12:46:05 +0000 (12:46 +0000)
Change-Id: I620a03bc69890847e2aee5282e337631ed035e62
Signed-off-by: Krzysztof Wieclaw <k.wieclaw@samsung.com>
inc/command.h [new file with mode: 0644]
inc/controller_connection_manager.h [new file with mode: 0644]
inc/udp_connection.h [new file with mode: 0644]

diff --git a/inc/command.h b/inc/command.h
new file mode 100644 (file)
index 0000000..2d8ac3c
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+/**
+ * @brief Types of commands used in communication.
+ */
+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_e;
+
+/**
+ * @brief Structure with info about speed and direction that should be set.
+ */
+typedef struct __command {
+       command_type_e type; /** Type of command. */
+       union {
+               struct {
+                       int speed; /** Speed to be set from range [-10000, 10000]. */
+                       int direction; /** Direction to be set from range [-10000, 10000]. */
+               } steering;
+               struct {
+                       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;
+       } data;
+} command_s;
diff --git a/inc/controller_connection_manager.h b/inc/controller_connection_manager.h
new file mode 100644 (file)
index 0000000..258bc31
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INC_CONTROLLER_CONNECTION_MANAGER_H_
+#define INC_CONTROLLER_CONNECTION_MANAGER_H_
+
+#include "command.h"
+
+/**
+ * @brief Describes state of connection.
+ */
+typedef enum controller_connection_state {
+       CONTROLLER_CONNECTION_STATE_READY, /** Listens and waits for controller. */
+       CONTROLLER_CONNECTION_STATE_RESERVED /** Currently unavailable to connect. */
+} controller_connection_state_e;
+
+/**
+ * @brief Called whenever state of connection changes.
+ * @param[in] previous Previous state of connection.
+ * @param[in] current Current state of connection.
+ */
+typedef void (*connection_state_cb)(controller_connection_state_e previous, controller_connection_state_e current);
+
+/**
+ * @brief Called whenever new message arrives.
+ * @param[in] message Message tat arrived.
+ */
+typedef void (*message_received_cb)(command_s command);
+
+/**
+ * @brief Starts listening on the given port for messages.
+ * @param[in] port Port on which application will be listening.
+ * @return 0 on success, -1 otherwise.
+ * @remarks This function allocates resources and that has to be freed with controller_connection_manager_release.
+ */
+int controller_connection_manager_listen(int port);
+
+/**
+ * @brief Gets currect connection state.
+ * @return Connection state.
+ */
+controller_connection_state_e controller_connection_manager_get_state();
+
+/**
+ * @brief Sets callback function called whenever connection state changes.
+ * @param[in] callback Callback function to be set.
+ */
+void controller_connection_set_manager_state_change_cb(connection_state_cb callback);
+
+/**
+ * @brief Sets callback function called whenever new message arrives.
+ * @param[in] callback Callback function to be set.
+ */
+void controller_connection_manager_set_message_received_cb(message_received_cb callback);
+
+/**
+ * @brief Stops listening for messages and release resources connected with it.
+ */
+void controller_connection_manager_release();
+
+#endif /* INC_CONTROLLER_CONNECTION_MANAGER_H_ */
diff --git a/inc/udp_connection.h b/inc/udp_connection.h
new file mode 100644 (file)
index 0000000..e2d41dd
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INC_UDP_CONNECTION_H_
+#define INC_UDP_CONNECTION_H_
+
+/**
+ * @brief Called whenever new UDP data arrives.
+ * @param[in] data Pointer to data that arrived.
+ * @param[in] size Size of data in bytes.
+ * @param[in] address Address of source of data.
+ * @param[in] port Port of data source.
+ */
+typedef void (*udp_receive_cb)(const char *data, unsigned int size, const char *address, int port);
+
+/**
+ * @brief Structure of data about udp_connection.
+ */
+typedef struct udp_connection udp_connection_t;
+
+/**
+ * @brief Creates UDP connection object.
+ * @param[in] port Local port on which creation should be stablished.
+ * @return new udp_connection object on success, NULL otherwise.
+ * @remarks Function allocates resources that have to be freed with udp_communication_destroy.
+ */
+udp_connection_t *udp_connection_create(int port);
+
+/**
+ * @brief Sets the receiver of sent data.
+ * @param[in] connection UDP connection object.
+ * @param[in] address IP address of receiver.
+ * @param[in] port Port of receiver to send data on.
+ * @return 0 on success, -1 otherwise.
+ */
+int udp_connection_set_receiver(udp_connection_t *connection, const char *address, int port);
+
+/**
+ * @brief Sends data to set receiver.
+ * @param[in] connection UDP connection object.
+ * @param[in] data Data to be sent.
+ * @param[in] size Size in bytes of data pointed by data pointer.
+ * @return 0 on success, -1 otherwise.
+ */
+int udp_connection_send(udp_connection_t *connection, const char *data, unsigned int size);
+
+/**
+ * @brief Sets callback for receiving data.
+ * @param[in] connection UDP connection object.
+ * @param[in] callback Callback to be set or NULL to unregister.
+ * @remarks Function is passed pointer to data and its size.
+ */
+void udp_connection_set_receive_cb(udp_connection_t *connection, udp_receive_cb callback);
+
+/**
+ * @brief Stops UDP communication and releases all resources allocated by udp_communication_create.
+ * @param[in] connection UDP connection object.
+ */
+void udp_connection_destroy(udp_connection_t *connection);
+
+#endif /* INC_UDP_CONNECTION_H_ */