INCLUDE_DIRECTORIES(${PROJECT_ROOT_DIR}/inc)
ADD_EXECUTABLE(${PROJECT_NAME}
- ${PROJECT_ROOT_DIR}/src/messages/message_config_user_name.c
+ ${PROJECT_ROOT_DIR}/src/lap_counter/lap_counter.c
${PROJECT_ROOT_DIR}/src/messages/clock.c
${PROJECT_ROOT_DIR}/src/messages/message_command.c
${PROJECT_ROOT_DIR}/src/messages/message_factory.c
${PROJECT_ROOT_DIR}/src/controller_connection_manager.c
${PROJECT_ROOT_DIR}/src/messages/writer.c
+ ${PROJECT_ROOT_DIR}/src/messages/message_config_user_name.c
${PROJECT_ROOT_DIR}/src/messages/message_ack.c
${PROJECT_ROOT_DIR}/src/messages/message_connect_accepted.c
${PROJECT_ROOT_DIR}/src/messages/message_keep_alive.c
/**
* @brief Called whenever new command arrives.
- * @param[in] message Message tat arrived.
+ * @param[in] command Command that arrived.
*/
typedef void (*command_received_cb)(command_s command);
/**
+ * @brief Called whenever new user name arrives.
+ * @param[in] name User name that arrived.
+ */
+typedef void (*user_name_received_cb)(const char *name);
+
+/**
* @brief Starts listening on the given port for messages.
* @return 0 on success, -1 otherwise.
* @remarks This function allocates resources and that has to be freed with controller_connection_manager_release.
void controller_connection_manager_set_command_received_cb(command_received_cb callback);
/**
+ * @brief Sets callback function called whenever new message arrives.
+ * @param[in] callback Callback function to be set.
+ */
+void controller_connection_manager_set_user_name_received_cb(user_name_received_cb callback);
+
+/**
* @brief Stops listening for messages and release resources connected with it.
*/
void controller_connection_manager_release();
#include "cloud/cloud_communication.h"
#include "messages/message_manager.h"
#include "controller_connection_manager.h"
+#include "lap_counter/lap_counter.h"
#include "command.h"
#define ENABLE_MOTOR 1
unsigned int f_value;
unsigned int r_value;
unsigned int dir_state;
+ const char *user_name;
guint idle_h;
} app_data;
}
}
+static void __user_name_received_cb(const char *name) {
+ lap_counter_set_user_name(name);
+}
+
static void _initialize_config()
{
net_util_init();
cloud_communication_init();
message_manager_init();
controller_connection_manager_listen();
+ lap_counter_init();
}
static bool service_app_create(void *data)
cloud_communication_start(CLOUD_REQUESTS_FREQUENCY);
controller_connection_manager_set_command_received_cb(__command_received_cb);
+ controller_connection_manager_set_user_name_received_cb(__user_name_received_cb);
return true;
}
if (ad->idle_h)
g_source_remove(ad->idle_h);
-
+ lap_counter_shutdown();
controller_connection_manager_release();
message_manager_shutdown();
#include "messages/message_command.h"
#include "messages/message_ack.h"
#include "messages/message_factory.h"
+#include "messages/message_config_user_name.h"
#include <string.h>
#include <glib.h>
#include "log.h"
int controller_port;
connection_state_cb state_cb;
command_received_cb command_cb;
+ user_name_received_cb user_name_cb;
int keep_alive_check_attempts_left;
int connect_accept_attempts_left;
guint connect_accept_timer;
s_info.command_cb = callback;
}
+void controller_connection_manager_set_user_name_received_cb(user_name_received_cb callback)
+{
+ s_info.user_name_cb = callback;
+}
+
void controller_connection_manager_handle_message(message_t *message)
{
if(!s_info.message_factory) {
_W("Unexpectedly received BYE from %s:%d (address_match == %d)", msg_address, msg_port, address_match);
}
break;
+ case MESSAGE_CONFIG_USER_NAME:
+ if(s_info.state == CONTROLLER_CONNECTION_STATE_RESERVED && address_match) {
+ if(s_info.user_name_cb) {
+ s_info.user_name_cb(message_config_user_name_get_name((message_config_user_name_t*)message));
+ }
+ message_ack_t response;
+ message_ack_init_from_request(&response, message);
+ message_set_receiver((message_t*)&response, s_info.controller_address, s_info.controller_port);
+ message_manager_send_message((message_t*)&response);
+ message_destroy((message_t*)&response);
+ } else {
+ _W("Unexpectedly received BYE from %s:%d (address_match == %d)", msg_address, msg_port, address_match);
+ };
+ break;
default:
_W("Received incorrect message");
}