Sending lap time to cloud
[apps/native/gear-racing-car.git] / src / lap_counter / lap_counter.c
index dfbd299..0894a87 100644 (file)
 #include <limits.h>
 #include <stdlib.h>
 #include <time.h>
+#include "cloud/cloud_communication.h"
 
 #define MIN_LAP_TIME 5
 #define MAX_NAME_LENGTH 256
 
 typedef struct lap_counter_data {
-       const char *user_name;
+       char *user_name;
        struct timespec last_timestamp;
 } lap_counter_data_t;
 
@@ -42,11 +43,11 @@ void lap_counter_init()
 
 void lap_counter_set_user_name(const char *user_name)
 {
+       retm_if(!user_name, "New user name is NULL");
+
        free((void*)s_info.user_name);
        s_info.user_name = strdup(user_name);
-       if(!s_info.user_name) {
-               return;
-       }
+
        _D("User name set to %s", s_info.user_name);
 }
 
@@ -96,6 +97,7 @@ static inline struct timespec _calculate_lap_time(struct timespec *prev, struct
        }
        _D("----------------------------------------------");
 
+       cloud_communication_post_lap(lap.tv_sec * 1e3 + lap.tv_nsec / 1e6, s_info.user_name);
        return lap;
 }