Commit 26c6a495a3894ad9d811d8bf4ff926136378db20

Authored by Imanol-Mikel Barba Sabariego
1 parent ce796b71

--no commit message

Project/applications/smartcities/include/json.h
... ... @@ -18,6 +18,7 @@
18 18 #define JOIN_NO_FREE 0
19 19 #define JOIN_FREE_MEM 1
20 20  
  21 +uint8_t register_sensor(sensor sens);
21 22 char* prepare_json_observation_statement(char** data, uint32_t nObservations);
22 23 char* prepare_json_register_statement(module mod, sensor sens);
23 24 char* prepare_observation(char* observation, uint32_t length);
... ... @@ -25,4 +26,4 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen
25 26 uint32_t find_next_index(char* string, uint32_t length, char delimiter);
26 27 char* join_strings(char* str1, char* str2, uint32_t len1, uint32_t len2, uint8_t free_mem);
27 28  
28   -#endif
29 29 \ No newline at end of file
  30 +#endif
... ...
Project/applications/smartcities/include/sensors.h
... ... @@ -6,7 +6,7 @@
6 6 #include "i2c.h"
7 7 #include "libwismart.h"
8 8 #include "module.h"
9   -#include "json.h"
  9 +//#include "json.h"
10 10  
11 11 #define LIGHT_ADDR 0x39
12 12 #define DISTANCE_ADDR 0x01
... ... @@ -17,7 +17,7 @@ typedef struct {
17 17 char* description;
18 18 char* type;
19 19 char* unit;
20   - char* additional_data;
  20 + char* additional_info;
21 21 } sensor;
22 22  
23 23 uint8_t register_sensor(sensor sens);
... ... @@ -56,8 +56,8 @@ typedef struct {
56 56 } bmp085_callibration;
57 57  
58 58 uint16_t get_pressure_data(void);
59   -bmp085_callibration get_callibration_data(void);
60   -char* callibration_data_csv(bmp085_callibration parameters);
  59 +bmp085_callibration get_pressure_callibration_data(void);
  60 +char* callibration_pressure_data_csv(bmp085_callibration parameters);
61 61 void init_pressure(void);
62 62  
63   -#endif
64 63 \ No newline at end of file
  64 +#endif
... ...
Project/applications/smartcities/json.c
1 1 #include "json.h"
2 2  
  3 +uint8_t register_sensor(sensor sens)
  4 +{
  5 + uint8_t result;
  6 + if(sens.ID == PRESSURE_ADDR)
  7 + {
  8 + sens.additional_info = callibration_pressure_data_csv(get_pressure_callibration_data());
  9 + }
  10 + char *statement = prepare_json_register_statement(mod,sens);
  11 + chHeapFree(sens.additional_info);
  12 + sens.additional_info = NULL;
  13 + char sensor_ID[3];
  14 + sprintf(sensor_ID,"%d",sens.ID);
  15 + result = send_json(statement,strlen(statement),mod.ID,sensor_ID);
  16 + chHeapFree(statement);
  17 + return result;
  18 +}
  19 +
3 20 char* prepare_json_observation_statement(char** data, uint32_t nObservations)
4 21 {
5 22 unsigned int i, length, observation_length;
... ... @@ -163,4 +180,4 @@ char* join_strings(char* str1, char* str2, uint32_t len1, uint32_t len2, uint8_t
163 180 chHeapFree(str2);
164 181 }
165 182 return str;
166   -}
167 183 \ No newline at end of file
  184 +}
... ...
Project/applications/smartcities/ntp.c
... ... @@ -3,7 +3,6 @@
3 3 #include <string.h>
4 4 #include <stdlib.h>
5 5 #include <unistd.h>
6   -#include <errno.h>
7 6 #include <math.h>
8 7 #include <sys/time.h>
9 8  
... ...
Project/applications/smartcities/sensors.c
... ... @@ -4,21 +4,6 @@ sensor light_sensor = {LIGHT_ADDR, &quot;Light sensor&quot;, &quot;illumination&quot;, &quot;lux&quot;,NULL};
4 4 sensor ultrasound_sensor = {DISTANCE_ADDR, "Ultrasound sensor", "distance", "cm",NULL};
5 5 sensor pressure_sensor = {PRESSURE_ADDR, "Pressure sensor", "pressure", "kPa",NULL};
6 6  
7   -uint8_t register_sensor(sensor sens)
8   -{
9   - uint8_t result;
10   - if(sens.ID == PRESSURE_ADDR)
11   - {
12   - sens.additional_data = callibration_pressure_data_csv(get_pressure_callibration_data());
13   - }
14   - char *statement = prepare_json_register_statement(mod,sens);
15   - chHeapFree(sens.additional_data);
16   - sens.additional_data = NULL;
17   - result = send_json(statement,strlen(statement),mod.ID,sens.ID);
18   - chHeapFree(statement);
19   - return result;
20   -}
21   -
22 7 uint32_t get_light_data(void)
23 8 {
24 9 uint32_t data = 0;
... ... @@ -220,7 +205,6 @@ bmp085_callibration get_pressure_callibration_data(void)
220 205 }
221 206 char* callibration_pressure_data_csv(bmp085_callibration parameters)
222 207 {
223   - uint8_t i;
224 208 char *str = chHeapAlloc(NULL,sizeof(char)*(4*11-1));
225 209 memset(str,0x00,sizeof(char)*(4*11-1));
226 210 sprintf(str + strlen(str),"%d,",parameters.AC1);
... ...