Commit ac6a3343032c469423154bbb574bef0b8cc676e5

Authored by Imanol-Mikel Barba Sabariego
1 parent f98a930c

--no commit message

Project/applications/smartcities/buffer.c
... ... @@ -7,13 +7,10 @@ char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len)
7 7 len=*buf_len;
8 8 if(len==*index)
9 9 {
10   - DBG_BUFFER("Joining buffer...\r\n");
11 10 char** buffer = join_buf(buf, buf_len);
12   - DBG_BUFFER("Joined buffer...\r\n");
13 11 buffer[*index] = chHeapAlloc(NULL,strlen(info)+1);
14   - DBG_BUFFER("Memory allocated...\r\n");
15 12 strcpy(buffer[*index],info);
16   - DBG_BUFFER("Data copied...\r\n");
  13 + DBG_BUFFER("Data copied\r\n");
17 14 i = *index+1;
18 15 *index = i;
19 16 return buffer;
... ... @@ -31,9 +28,10 @@ char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len)
31 28  
32 29 int check_memory()
33 30 {
  31 + wismart_mem_stat_ram_t status = libwismart_GetMemFree_Ram();
34 32 DBG_BUFFER("Checking available memory...\r\n");
35   - DBG_BUFFER("%c[1;36mAvailable memory: %d B%c[1;00m\r\n",0x1B,libwismart_GetMemFree_Ram().free,0x1B);
36   - int mem = MAX_RAM - libwismart_GetMemFree_Ram().free;
  33 + DBG_BUFFER("%c[1;36mAvailable memory: %d B%c[1;00m\r\n",0x1B,status.free,0x1B);
  34 + int mem = MAX_RAM - status.free;
37 35 DBG_BUFFER("%c[1;36mUsed memory: %d B%c[1;00m\r\n",0x1B,mem,0x1B);
38 36 if(mem >= HARD_LIMIT)
39 37 {
... ... @@ -78,30 +76,23 @@ int send(char** buf, uint32_t *index, uint32_t *size_buf, char *provider_ID, cha
78 76 return res;
79 77 }
80 78  
81   -//realloc
82 79 char** join_buf(char** buf, uint32_t *buf_len)
83 80 {
  81 + DBG_BUFFER("Joining buffer...\r\n");
84 82 char** n_buf;
85 83 int len = *buf_len;
86 84 n_buf = chHeapAlloc (NULL,sizeof (char *) * (len+1));
87 85 int i;
88   - DBG_BUFFER("Start buffer join...\r\n");
89 86 for(i=0; i<len;i++)
90 87 {
91   - DBG_BUFFER("in join_buf for, Asking for %d bytes...\r\n",strlen(buf[i]+1));
92 88 n_buf[i] = chHeapAlloc(NULL,strlen(buf[i])+1);
93   - DBG_BUFFER("in join_buf for, Memory allocated...\r\n");
94 89 strcpy(n_buf[i],buf[i]);
95   - DBG_BUFFER("in join_buf for, Message copied...\r\n");
96 90 chHeapFree(buf[i]);
97   - DBG_BUFFER("in join_buf for, Memory cleared...\r\n");
98 91 }
99   - DBG_BUFFER("All data transferred\r\n");
100 92 if(len != 0)
101 93 {
102 94 chHeapFree(buf);
103 95 }
104   - DBG_BUFFER("Old buffer cleared\r\n");
105 96 len++;
106 97 *buf_len=len;
107 98 return n_buf;
... ...
Project/applications/smartcities/buglist.txt
1 1 - Investigate leaks
2   -- Pressure sensor memory
3 2 - Test sound sensor
4 3 - Test multiple sensors with DB9
5 4 \ No newline at end of file
... ...
Project/applications/smartcities/include/sensors.h
... ... @@ -56,7 +56,8 @@ char* distance_value(uint16_t distance);
56 56  
57 57  
58 58 //PRESSURE SENSOR
59   -typedef struct {
  59 +typedef struct bmp085_callibration bmp085_callibration_t;
  60 +struct bmp085_callibration {
60 61 uint16_t AC1;
61 62 uint16_t AC2;
62 63 uint16_t AC3;
... ... @@ -68,14 +69,14 @@ typedef struct {
68 69 uint16_t MB;
69 70 uint16_t MC;
70 71 uint16_t MD;
71   -} bmp085_callibration;
  72 +};
72 73  
73 74 void init_pressure(void);
74 75 void init_pressure_temperature(void);
75 76 uint16_t get_pressure_data(void);
76 77 uint16_t get_pressure_temperature_data(void);
77   -bmp085_callibration get_pressure_callibration_data(void);
78   -char* callibration_pressure_data_csv(bmp085_callibration parameters);
  78 +void get_pressure_callibration_data(bmp085_callibration_t *calib_data);
  79 +char* callibration_pressure_data_csv(bmp085_callibration_t *parameters);
79 80 char* pressure_value(uint16_t pressure,uint16_t temperature);
80 81  
81 82 //HUMIDITY AND TEMPERATURE SENSOR
... ...
Project/applications/smartcities/json.c
... ... @@ -8,7 +8,10 @@ uint8_t register_sensor(sensor sens)
8 8 if(sens.ID == PRESSURE_ADDR)
9 9 {
10 10 DBG_JSON("Putting additional info for pressure sensor...\r\n");
11   - char *callibration_data = callibration_pressure_data_csv(get_pressure_callibration_data());
  11 + bmp085_callibration_t calib_data;
  12 + get_pressure_callibration_data(&calib_data);
  13 + DBG_JSON("Got callibration data\r\n");
  14 + char *callibration_data = callibration_pressure_data_csv(&calib_data);
12 15 DBG_JSON("callibration_data is: %s\r\n",callibration_data);
13 16 statement = prepare_json_register_statement(mod,sens,callibration_data);
14 17 chHeapFree(callibration_data);
... ...
Project/applications/smartcities/main.c
... ... @@ -132,7 +132,6 @@ void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked,
132 132 DBG("Message put: %s\r\n",buffers[i][ind[i]-1]);
133 133 chHeapFree(cooked[i]);
134 134 DBG("Memory freed\n\r");
135   - DBG("[ASSERTION] Message put: %s with length %d\r\n",buffers[i][ind[i]-1] ,strlen(buffers[i][ind[i]-1]));
136 135 }
137 136 DBG("Data is now in buffer\n\r");
138 137 }
... ... @@ -196,7 +195,6 @@ void wifi_disconnect(void)
196 195 connected |= CONNECTED_PAST;
197 196 }
198 197 connected = connected & CONNECTED_PAST ;
199   - DBG("Connnected: %d\r\n",connected);
200 198 timeout = 0;
201 199 uint8_t res=libwismart_WiFiDisconnect();
202 200 if(res)
... ... @@ -212,7 +210,7 @@ int main(void)
212 210 libwismart_PowerSave_HigherProfile(TRUE);
213 211 libwismart_RegisterDhcpCB(dhcp_connect_result_cb);
214 212 libwismart_WiFiInit();
215   - libwismart_SetScanRunsForConnTimeout(4); //Edit a 4
  213 + libwismart_SetScanRunsForConnTimeout(4);
216 214 libwismart_EnableBsdSocketAPI();
217 215  
218 216 int i;
... ...
Project/applications/smartcities/ntp.c
... ... @@ -168,9 +168,7 @@ char* timestamp_data(char* value,Date time)
168 168 DBG_NTP("Writing timestamp...\r\n");
169 169 uint8_t length = strlen(value) + strlen(",00/00/0000T00:00:00") + 1;
170 170 char str_day[3],str_month[3],str_year[5],str_hour[3],str_minute[3],str_second[3];
171   - DBG_NTP("Asking for %d bytes in timestamp_data\r\n", length);
172 171 char* data = chHeapAlloc(NULL,length*sizeof(char));
173   - DBG_NTP("Data allocated in timestamp_data\r\n", length);
174 172 sprintf(str_day,"%d",time.day);
175 173 sprintf(str_month,"%d",time.month);
176 174 sprintf(str_year,"%d",time.year);
... ...
Project/applications/smartcities/sensors.c
... ... @@ -219,107 +219,105 @@ void init_pressure_temperature(void)
219 219 chThdSleepMilliseconds(5);
220 220 }
221 221  
222   -bmp085_callibration get_pressure_callibration_data(void)
  222 +void get_pressure_callibration_data(bmp085_callibration_t *calib_data)
223 223 {
224 224 DBG_SENSORS("[PRESSURE] Fetching callibration data\r\n");
225   - bmp085_callibration calib_data;
226 225  
227 226 I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter);
228 227 I2C_write(I2C1, 0xAA);
229 228 I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver);
230   - calib_data.AC1 = (I2C_read_ack(I2C1) << 8);
231   - calib_data.AC1 |= I2C_read_nack(I2C1);
  229 + calib_data->AC1 = (I2C_read_ack(I2C1) << 8);
  230 + calib_data->AC1 |= I2C_read_nack(I2C1);
232 231 I2C_stop(I2C1);
233 232  
234 233 I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter);
235 234 I2C_write(I2C1, 0xAC);
236 235 I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver);
237   - calib_data.AC2 = (I2C_read_ack(I2C1) << 8);
238   - calib_data.AC2 |= I2C_read_nack(I2C1);
  236 + calib_data->AC2 = (I2C_read_ack(I2C1) << 8);
  237 + calib_data->AC2 |= I2C_read_nack(I2C1);
239 238 I2C_stop(I2C1);
240 239  
241 240 I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter);
242 241 I2C_write(I2C1, 0xAE);
243 242 I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver);
244   - calib_data.AC3 = (I2C_read_ack(I2C1) << 8);
245   - calib_data.AC3 |= I2C_read_nack(I2C1);
  243 + calib_data->AC3 = (I2C_read_ack(I2C1) << 8);
  244 + calib_data->AC3 |= I2C_read_nack(I2C1);
246 245 I2C_stop(I2C1);
247 246  
248 247 I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter);
249 248 I2C_write(I2C1, 0xB0);
250 249 I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver);
251   - calib_data.AC4 = (I2C_read_ack(I2C1) << 8);
252   - calib_data.AC4 |= I2C_read_nack(I2C1);
  250 + calib_data->AC4 = (I2C_read_ack(I2C1) << 8);
  251 + calib_data->AC4 |= I2C_read_nack(I2C1);
253 252 I2C_stop(I2C1);
254 253  
255 254 I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter);
256 255 I2C_write(I2C1, 0xB2);
257 256 I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver);
258   - calib_data.AC5 = (I2C_read_ack(I2C1) << 8);
259   - calib_data.AC5 |= I2C_read_nack(I2C1);
  257 + calib_data->AC5 = (I2C_read_ack(I2C1) << 8);
  258 + calib_data->AC5 |= I2C_read_nack(I2C1);
260 259 I2C_stop(I2C1);
261 260  
262 261 I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter);
263 262 I2C_write(I2C1, 0xB4);
264 263 I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver);
265   - calib_data.AC6 = (I2C_read_ack(I2C1) << 8);
266   - calib_data.AC6 |= I2C_read_nack(I2C1);
  264 + calib_data->AC6 = (I2C_read_ack(I2C1) << 8);
  265 + calib_data->AC6 |= I2C_read_nack(I2C1);
267 266 I2C_stop(I2C1);
268 267  
269 268 I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter);
270 269 I2C_write(I2C1, 0xB6);
271 270 I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver);
272   - calib_data.B1 = (I2C_read_ack(I2C1) << 8);
273   - calib_data.B1 |= I2C_read_nack(I2C1);
  271 + calib_data->B1 = (I2C_read_ack(I2C1) << 8);
  272 + calib_data->B1 |= I2C_read_nack(I2C1);
274 273 I2C_stop(I2C1);
275 274  
276 275 I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter);
277 276 I2C_write(I2C1, 0xB8);
278 277 I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver);
279   - calib_data.B2 = (I2C_read_ack(I2C1) << 8);
280   - calib_data.B2 |= I2C_read_nack(I2C1);
  278 + calib_data->B2 = (I2C_read_ack(I2C1) << 8);
  279 + calib_data->B2 |= I2C_read_nack(I2C1);
281 280 I2C_stop(I2C1);
282 281  
283 282 I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter);
284 283 I2C_write(I2C1, 0xBA);
285 284 I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver);
286   - calib_data.MB = (I2C_read_ack(I2C1) << 8);
287   - calib_data.MB |= I2C_read_nack(I2C1);
  285 + calib_data->MB = (I2C_read_ack(I2C1) << 8);
  286 + calib_data->MB |= I2C_read_nack(I2C1);
288 287 I2C_stop(I2C1);
289 288  
290 289 I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter);
291 290 I2C_write(I2C1, 0xBC);
292 291 I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver);
293   - calib_data.MC = (I2C_read_ack(I2C1) << 8);
294   - calib_data.MC |= I2C_read_nack(I2C1);
  292 + calib_data->MC = (I2C_read_ack(I2C1) << 8);
  293 + calib_data->MC |= I2C_read_nack(I2C1);
295 294 I2C_stop(I2C1);
296 295  
297 296 I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter);
298 297 I2C_write(I2C1, 0xBE);
299 298 I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver);
300   - calib_data.MD = (I2C_read_ack(I2C1) << 8);
301   - calib_data.MD |= I2C_read_nack(I2C1);
  299 + calib_data->MD = (I2C_read_ack(I2C1) << 8);
  300 + calib_data->MD |= I2C_read_nack(I2C1);
302 301 I2C_stop(I2C1);
303 302  
304 303 DBG_SENSORS("[PRESSURE] Got callibration data\r\n");
305   - return calib_data;
306 304 }
307 305  
308   -char* callibration_pressure_data_csv(bmp085_callibration parameters)
  306 +char* callibration_pressure_data_csv(bmp085_callibration_t *parameters)
309 307 {
310   - char *str = chHeapAlloc(NULL,sizeof(char)*(11*11-1));
311   - memset(str,0x00,sizeof(char)*(11*11));
312   - sprintf(str + strlen(str),"%u,",parameters.AC1);
313   - sprintf(str + strlen(str),"%u,",parameters.AC2);
314   - sprintf(str + strlen(str),"%u,",parameters.AC3);
315   - sprintf(str + strlen(str),"%u,",parameters.AC4);
316   - sprintf(str + strlen(str),"%u,",parameters.AC5);
317   - sprintf(str + strlen(str),"%u,",parameters.AC6);
318   - sprintf(str + strlen(str),"%u,",parameters.B1);
319   - sprintf(str + strlen(str),"%u,",parameters.B2);
320   - sprintf(str + strlen(str),"%u,",parameters.MB);
321   - sprintf(str + strlen(str),"%u,",parameters.MC);
322   - sprintf(str + strlen(str),"%u",parameters.MD);
  308 + char *str = chHeapAlloc(NULL,(11*11-1));
  309 + memset(str,0x00,(11*11-1));
  310 + sprintf(str + strlen(str),"%u,",parameters->AC1);
  311 + sprintf(str + strlen(str),"%u,",parameters->AC2);
  312 + sprintf(str + strlen(str),"%u,",parameters->AC3);
  313 + sprintf(str + strlen(str),"%u,",parameters->AC4);
  314 + sprintf(str + strlen(str),"%u,",parameters->AC5);
  315 + sprintf(str + strlen(str),"%u,",parameters->AC6);
  316 + sprintf(str + strlen(str),"%u,",parameters->B1);
  317 + sprintf(str + strlen(str),"%u,",parameters->B2);
  318 + sprintf(str + strlen(str),"%u,",parameters->MB);
  319 + sprintf(str + strlen(str),"%u,",parameters->MC);
  320 + sprintf(str + strlen(str),"%u",parameters->MD);
323 321 return str;
324 322 }
325 323  
... ...