Commit 737124c7b279634d86422ea3e121de5d7d5ba5fb
1 parent
79b57a0c
--no commit message
Showing
3 changed files
with
47 additions
and
25 deletions
Project/applications/smartcities/include/timer-loop.h
... | ... | @@ -6,8 +6,10 @@ |
6 | 6 | |
7 | 7 | #define HALF_HOUR 60*30 // time in seconds |
8 | 8 | #define FIVE_MIN 60*5 // time in seconds |
9 | -#define LONG_PERIOD HALF_HOUR //60*3 // for testing | |
10 | -#define SHORT_PERIOD FIVE_MIN //60*1 // for testing | |
9 | +//#define LONG_PERIOD HALF_HOUR //60*3 // for testing | |
10 | +//#define SHORT_PERIOD FIVE_MIN //60*1 // for testing | |
11 | +#define LONG_PERIOD 60*3 //60*3 // for testing | |
12 | +#define SHORT_PERIOD 60*1 //60*1 // for testing | |
11 | 13 | |
12 | 14 | unsigned long getSystemTime(void); |
13 | 15 | ... | ... |
Project/applications/smartcities/main2.c
... | ... | @@ -115,7 +115,8 @@ void send_data(char** buffers[], uint32_t ind[], uint32_t sizes[], uint8_t senso |
115 | 115 | |
116 | 116 | void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked, uint8_t* sensors){ |
117 | 117 | int i; |
118 | - for(i=0;i<sensors_length;i++){ | |
118 | + for(i=0;i<sensors_length;i++){ | |
119 | + printf("For %d and %d\n\r", ind[i],sizes[i]); | |
119 | 120 | put_message(cooked[i], buffers[i] ,&ind[i],&sizes[i]); |
120 | 121 | chHeapFree(cooked[i]); |
121 | 122 | } |
... | ... | @@ -124,14 +125,18 @@ void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked, |
124 | 125 | char** timestamp_datas(char* value[],unsigned long timestamp, uint8_t* sensors){ |
125 | 126 | char** cooked_data; |
126 | 127 | cooked_data = (char**) chHeapAlloc(NULL,sensors_length * sizeof(char*)); |
128 | + printf("Data allocated...\r\n"); | |
127 | 129 | Date t=getDate(timestamp); |
128 | 130 | int i; |
129 | 131 | for(i=0;i<sensors_length;i++){ |
130 | - | |
132 | + printf("Calling timestamp_data...\r\n"); | |
131 | 133 | cooked_data[i]=timestamp_data(value[i], t); |
134 | + printf("Finished timestamp_data...\r\n"); | |
135 | + printf("Data is: %s",cooked_data[i]); | |
132 | 136 | chHeapFree(value[i]); |
133 | 137 | |
134 | 138 | } |
139 | + printf("Returning timestamped data...\r\n"); | |
135 | 140 | return cooked_data; |
136 | 141 | } |
137 | 142 | |
... | ... | @@ -177,15 +182,19 @@ int main(void) |
177 | 182 | |
178 | 183 | char* valueSensors[TOTAL_SENSORS]; |
179 | 184 | memset (valueSensors, 0, TOTAL_SENSORS); |
180 | - | |
181 | - I2C_scan(sensors); | |
185 | + printf("Scanning sensors...\r\n"); | |
186 | + //I2C_scan(sensors); | |
187 | + sensors[0] = LIGHT_ADDR; | |
182 | 188 | sensors_length=strlen((char*)sensors); |
189 | + printf("%d sensor detected...\r\n",sensors_length); | |
183 | 190 | //registrar sensores |
184 | 191 | //Esta funcion esta mas arriba para no repetir código luego -- Imanol |
192 | + printf("Connecting to wifi...\r\n"); | |
185 | 193 | wifi_connect(); |
186 | 194 | //unsigned int time = getNTPTime(); |
187 | 195 | unsigned int time = getSecsSince1900(); |
188 | 196 | //desconectarwifi |
197 | + printf("Disconecting wifi...\r\n"); | |
189 | 198 | wifi_disconnect(); |
190 | 199 | |
191 | 200 | unsigned long timestamp = 0; |
... | ... | @@ -201,21 +210,42 @@ int main(void) |
201 | 210 | |
202 | 211 | while(1){ |
203 | 212 | time += getElapsedTime(delay); |
204 | - printf("time (absolute):\t%d\r\ntime mod LONG_PERIOD:\t%d\r\ntime mod SHORT_PERIOD:\t%d\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); | |
213 | + printf("time (absolute):\t%ul\r\ntime mod LONG_PERIOD:\t%ul\r\ntime mod SHORT_PERIOD:\t%ul\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); | |
205 | 214 | |
206 | 215 | delay = getSystemTime(); |
207 | 216 | /* Collect data from sensors */ |
208 | 217 | //collect_data(/*a_rawData*/); |
209 | - collectData(valueSensors, sensors); | |
210 | - | |
218 | + printf("Collecting data...\r\n"); | |
219 | + //collectData(valueSensors, sensors); | |
220 | + valueSensors[0] = chHeapAlloc(NULL,6); | |
221 | + strcpy(valueSensors[0],"123456"); | |
222 | + printf("Data collected...\r\n"); | |
211 | 223 | |
212 | 224 | time += getElapsedTime(delay); |
213 | - printf("time (absolute):\t%d\r\ntime mod LONG_PERIOD:\t%d\r\ntime mod SHORT_PERIOD:\t%d\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); | |
225 | + printf("time (absolute):\t%ul\r\ntime mod LONG_PERIOD:\t%ul\r\ntime mod SHORT_PERIOD:\t%ul\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); | |
214 | 226 | |
215 | 227 | delay = getSystemTime(); |
216 | 228 | //cada mitja hora |
217 | - if (i == LONG_PERIOD/SHORT_PERIOD ){ | |
229 | + | |
230 | + //delay2 = getElapsedTime(delay); | |
231 | + | |
232 | + delay = getSystemTime(); | |
233 | + //timestamp = time - delay2; | |
234 | + timestamp = time - delay; | |
235 | + printf("timestamp (absolute):\t%ul\r\ntimestamp mod LONG_PERIOD:\t%ul\r\ntimestamp mod SHORT_PERIOD:\t%ul\r\n",timestamp,timestamp%LONG_PERIOD,timestamp%SHORT_PERIOD); | |
236 | + | |
237 | + /* Add data to the buffer with timestamp*/ | |
238 | + | |
239 | + //a_cookedData = format_data(a_rawData, timestamp); | |
240 | + printf("Timestamping data...\r\n"); | |
241 | + char** values=timestamp_datas(valueSensors,timestamp,sensors); | |
242 | + printf("Putting data in buffer...\r\n"); | |
243 | + put_buffers(buffers,ind,sizes,values,sensors); | |
244 | + printf("Data is now in buffer...\n\r"); | |
245 | + if (i == LONG_PERIOD/SHORT_PERIOD ){ | |
246 | + printf("Programmed Send cycle...\r\n"); | |
218 | 247 | /* Wi-Fi connect */ |
248 | + printf("Connecting to wifi...\r\n"); | |
219 | 249 | wifi_connect(); |
220 | 250 | /* Send data to server, empty the buffer */ |
221 | 251 | send_data(buffers, ind, sizes, sensors); |
... | ... | @@ -223,20 +253,9 @@ int main(void) |
223 | 253 | time = getSecsSince1900(); |
224 | 254 | //desconectar wifi |
225 | 255 | wifi_disconnect(); |
226 | - printf("time (absolute):\t%d\r\ntime mod LONG_PERIOD:\t%d\r\ntime mod SHORT_PERIOD:\t%d\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); | |
256 | + printf("time (absolute):\t%ul\r\ntime mod LONG_PERIOD:\t%ul\r\ntime mod SHORT_PERIOD:\t%ul\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); | |
227 | 257 | i = 0; |
228 | 258 | } |
229 | - delay2 = getElapsedTime(delay); | |
230 | - | |
231 | - delay = getSystemTime(); | |
232 | - timestamp = time - delay2; | |
233 | - printf("timestamp (absolute):\t%d\r\ntimestamp mod LONG_PERIOD:\t%d\r\ntimestamp mod SHORT_PERIOD:\t%d\r\n",timestamp,timestamp%LONG_PERIOD,timestamp%SHORT_PERIOD); | |
234 | - | |
235 | - /* Add data to the buffer with timestamp*/ | |
236 | - | |
237 | - //a_cookedData = format_data(a_rawData, timestamp); | |
238 | - char** values=timestamp_datas(valueSensors,timestamp,sensors); | |
239 | - put_buffers(buffers,ind,sizes,values,sensors); | |
240 | 259 | |
241 | 260 | printf("mirant memoria\r\n"); |
242 | 261 | int res=check_memory(); |
... | ... | @@ -286,9 +305,10 @@ int main(void) |
286 | 305 | wifi_disconnect(); |
287 | 306 | } |
288 | 307 | time += getElapsedTime(delay); |
289 | - printf("time (absolute):\t%d\r\ntime mod LONG_PERIOD:\t%d\r\ntime mod SHORT_PERIOD:\t%d\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); | |
308 | + printf("time (absolute):\t%ul\r\ntime mod LONG_PERIOD:\t%ul\r\ntime mod SHORT_PERIOD:\t%ul\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); | |
290 | 309 | |
291 | 310 | delay = getSystemTime(); |
311 | + printf("Time to sleep! for %d seconds\r\n", SHORT_PERIOD - time%SHORT_PERIOD); | |
292 | 312 | sleep_thread(SHORT_PERIOD - time%SHORT_PERIOD); |
293 | 313 | i++; |
294 | 314 | } | ... | ... |
Project/applications/smartcities/test_timer-loop.c