Commit 79715d2bc3c35a2b8289c60886a13962338f7298

Authored by Imanol-Mikel Barba Sabariego
1 parent c4ac6bae

--no commit message

Project/applications/smartcities/buffer.c
... ... @@ -20,7 +20,7 @@ char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len)
20 20 }
21 21 else
22 22 {
23   - DBG_BUFFER("WTF in put_message\r\n");
  23 + DBG_BUFFER("%c[1;31m[ERROR] WTF in put_message%c[1;00m\r\n",0x1B,0x1B);
24 24 buf[*index] = chHeapAlloc(NULL,strlen(info)+1);
25 25 buf[*index] = info;
26 26 i = *index+1;
... ... @@ -37,12 +37,12 @@ int check_memory()
37 37 DBG_BUFFER("%c[1;36mUsed memory: %d B%c[1;00m\r\n",0x1B,mem,0x1B);
38 38 if(mem >= HARD_LIMIT)
39 39 {
40   - DBG_BUFFER("[WARNING] Hard limit reached\r\n");
  40 + DBG_BUFFER("%c[1;33m[WARNING] Hard limit reached%c[1;00m\r\n",0x1B,0x1B);
41 41 return HARD_REACHED;
42 42 }
43 43 else if(mem >= SOFT_LIMIT)
44 44 {
45   - DBG_BUFFER("[WARNING] Soft limit reached\r\n");
  45 + DBG_BUFFER("%c[1;33m[WARNING] Soft limit reached%c[1;00m\r\n",0x1B,0x1B);
46 46 return SOFT_REACHED;
47 47 }
48 48 return MEMORY_OK;
... ... @@ -55,7 +55,7 @@ int send(char** buf, uint32_t *index, uint32_t *size_buf, char *provider_ID, cha
55 55 uint32_t size = strlen(statement);
56 56 if(buf==NULL)
57 57 {
58   - DBG_BUFFER("[ERROR] Buffer not initialized!\r\n");
  58 + DBG_BUFFER("%c[1;31m[ERROR] Buffer not initialized!%c[1;00m\r\n",0x1B,0x1B);
59 59 return 2;
60 60 }
61 61 uint8_t res = send_json(statement, size, provider_ID, sensor_ID);
... ...
Project/applications/smartcities/callbacks.c
... ... @@ -12,12 +12,12 @@ void dhcp_connect_result_cb(int result)
12 12 }
13 13 else if(result==LIBWISMART_DHCP_TIMEOUT)
14 14 {
15   - DBG_CALLBACKS("DHCP timeout\r\n");
  15 + DBG_CALLBACKS("%c[1;31m[ERROR] DHCP timeout%c[1;00m\r\n",0x1B,0x1B);
16 16 timeout = 1;
17 17 }
18 18 else
19 19 {
20   - DBG_CALLBACKS("DHCP error\r\n");
  20 + DBG_CALLBACKS("%c[1;31m[ERROR] DHCP failed%c[1;00m\r\n",0x1B,0x1B);
21 21 timeout = 1;
22 22 }
23 23  
... ... @@ -32,12 +32,12 @@ void wifi_connect_result_cb(int result)
32 32 DBG_CALLBACKS("WiFi Connect indication: ");
33 33 if(result == WISMART_WIFI_CONNECTED)
34 34 {
35   - printf("Connected\r\n");
  35 + printf("%c[1;32mConnected%c[1;00m\r\n",0x1B,0x1B);
36 36 retries = 0;
37 37 }
38 38 else
39 39 {
40   - printf("Failed\r\n");
  40 + printf("%c[1;31mFailed%c[1;00m\r\n",0x1B,0x1B);
41 41 if(++retries == MAX_RETRIES)
42 42 {
43 43 timeout = 1;
... ...
Project/applications/smartcities/httpClient.c
... ... @@ -77,13 +77,13 @@ int httpRequest(struct httpHeaders head, char* content, int content_size)
77 77 {
78 78 DBG_HTTP("Skipping void content\r\n");
79 79 }
80   - DBG_HTTP("Packet:\r\n\r\n%c[1;33m%s%c[1;00m \r\n\r\n",0x1B,request,0x1B);
  80 + DBG_HTTP("Packet:\r\n\r\n%c[1;32m%s%c[1;00m \r\n\r\n",0x1B,request,0x1B);
81 81 // Set connection
82 82 DBG_HTTP("Setting connection\r\n");
83 83 neocon = netconn_new(NETCONN_TCP);
84 84 if(neocon == NULL)
85   - {
86   - DBG_HTTP("[ERROR] Socket creation FAILED. Have you called libwismart_EnableBsdSocketAPI()?\r\n");
  85 + {
  86 + DBG_HTTP("%c[1;31m[ERROR] Socket creation FAILED. Have you called libwismart_EnableBsdSocketAPI()?%c[1;00m\r\n",0x1B,0x1B);
87 87 }
88 88 /*local_ip.addr = 0;//getip
89 89 netconn_bind(neocon, IP_ADDR_ANY, LOCAL_PORT); //88 is provisional local port.*/
... ...
Project/applications/smartcities/include/adc.h
... ... @@ -7,7 +7,7 @@
7 7 #include "stm32f10x_gpio.h"
8 8 #include "stm32f10x_adc.h"
9 9  
10   -#define DBG_ADC(fmt,...) printf("%c[1;31madc.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
  10 +#define DBG_ADC(fmt,...) printf("%c[1;35madc.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
11 11  
12 12 #define ADCbatt_MIN_VALUE (0)
13 13 #define ADCbatt_MAX_VALUE (0xfff)
... ...
Project/applications/smartcities/include/buffer.h
... ... @@ -10,7 +10,7 @@
10 10 #define SOFT_REACHED 1
11 11 #define HARD_REACHED 2
12 12  
13   -#define DBG_BUFFER(fmt,...) printf("%c[1;31mbuffer.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
  13 +#define DBG_BUFFER(fmt,...) printf("%c[1;35mbuffer.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
14 14  
15 15 char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len);
16 16 int check_memory(void);
... ...
Project/applications/smartcities/include/callbacks.h
... ... @@ -17,7 +17,7 @@ void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *ma
17 17 void softapMode_apStartedCb(int result);
18 18 void printWifiInfo(uint8_t wifiMode);
19 19  
20   -#define DBG_CALLBACKS(fmt,...) printf("%c[1;31mcallbacks.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
  20 +#define DBG_CALLBACKS(fmt,...) printf("%c[1;35mcallbacks.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
21 21  
22 22 extern uint8_t connected;
23 23 extern uint8_t timeout;
... ...
Project/applications/smartcities/include/configServer.h
... ... @@ -10,8 +10,8 @@
10 10 #include "ch.h"
11 11 #include "fsdata.c"
12 12  
13   -#define CONFIG_SERVER_DBG(fmt,...) printf("%c[1;31mconfigServer.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
14   -#define CONFIG_SERVER_DBG_WARNING(fmt,...) printf("%c[1;31mconfigServer.c:%c[1;00m [WARNING] "fmt,0x1B,0x1B, ##__VA_ARGS__)
  13 +#define CONFIG_SERVER_DBG(fmt,...) printf("%c[1;35mconfigServer.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
  14 +#define CONFIG_SERVER_DBG_WARNING(fmt,...) printf("%c[1;35mconfigServer.c:%c[1;33m[WARNING] "fmt"%c[1;00m",0x1B,0x1B,0x1B, ##__VA_ARGS__)
15 15  
16 16 void configServer_start(uint8_t enableApScan);
17 17 void configServer_connect(void);
... ...
Project/applications/smartcities/include/httpClient.h
... ... @@ -14,15 +14,12 @@
14 14 #include "ch.h"
15 15 #include "globals.h"
16 16  
17   -/*
18   - * No fem servir DEFAULT_REMOTE_IP. Fem servir en canvi SERVER_IP, definida a globals.h
19   - */
20 17 #define DEFAULT_REMOTE_IP "147.83.2.135" // www.upc.edu
21 18 #define DEFAULT_REMOTE_PORT 80
22 19 #define ENDL "\r\n"
23 20 #define CONTENT_TYPE_HEADER "Content-Type: application/json; charset=UTF-8"
24 21  
25   -#define DBG_HTTP(fmt,...) printf("%c[1;31mhttpClient.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
  22 +#define DBG_HTTP(fmt,...) printf("%c[1;35mhttpClient.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
26 23  
27 24  
28 25 typedef enum reqMethod
... ... @@ -51,24 +48,4 @@ char* int2string(int num);
51 48 int numberofdigits(int number);
52 49 int response2int(char* chars);
53 50  
54   -#endif
55   -
56   -/*
57   -
58   --------------
59   -Sentilo codes
60   --------------
61   -
62   -Error Code HTTP Description
63   -200 Success Request accepted and processed correctly
64   -4xx Client Error Error in request (Wrong format, forbidden mandatory parameters, ...)
65   -401 Unauthorized Unauthorized request: empty or invalid credential
66   -403 Forbidden Not authorized for the requested action
67   -5xx Server Error Error processing the request
68   -
69   -PUT - Publish sensor data
70   -DELETE - Erase sensor data
71   -GET - Download sensor data
72   -(POST - create new sensor or publisher?)
73   -
74   -*/
  51 +#endif
75 52 \ No newline at end of file
... ...
Project/applications/smartcities/include/i2c.h
... ... @@ -9,7 +9,7 @@
9 9  
10 10 #define I2C_TIMEOUT 100
11 11  
12   -#define DBG_I2C(fmt,...) printf("%c[1;31mi2c.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
  12 +#define DBG_I2C(fmt,...) printf("%c[1;35mi2c.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
13 13  
14 14 void I2C_init(void);
15 15 void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction);
... ...
Project/applications/smartcities/include/json.h
... ... @@ -18,7 +18,7 @@
18 18 #define JOIN_NO_FREE 0
19 19 #define JOIN_FREE_MEM 1
20 20  
21   -#define DBG_JSON(fmt,...) printf("%c[1;31mjson.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
  21 +#define DBG_JSON(fmt,...) printf("%c[1;35mjson.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
22 22  
23 23 uint8_t register_sensor(sensor sens);
24 24 char* prepare_json_observation_statement(char** data, uint32_t nObservations);
... ...
Project/applications/smartcities/include/ntp.h
... ... @@ -18,7 +18,7 @@
18 18 #include "ch.h"
19 19 #include "globals.h"
20 20  
21   -#define DBG_NTP(fmt,...) printf("%c[1;31mntp.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
  21 +#define DBG_NTP(fmt,...) printf("%c[1;35mntp.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
22 22  
23 23 #define LEAP_YEAR(Y) (((1970+Y)>0) && !((1970+Y)%4) && (((1970+Y)%100) || !((1970+Y)%400)))
24 24 #define NTP_PACKET_LENGTH 48
... ...
Project/applications/smartcities/include/sensors.h
... ... @@ -19,7 +19,7 @@
19 19  
20 20 #define BATTERY_ADDR 0x00 //SIEMPRE PRESENTE, NUNCA BUSCAR EN i2c_scan
21 21  
22   -#define DBG_SENSORS(fmt,...) printf("%c[1;31msensors.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
  22 +#define DBG_SENSORS(fmt,...) printf("%c[1;35msensors.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
23 23  
24 24 typedef struct {
25 25 uint8_t ID;
... ...
Project/applications/smartcities/include/timer-loop.h
... ... @@ -11,7 +11,7 @@
11 11 #define LONG_PERIOD 60*3 //60*3 // for testing
12 12 #define SHORT_PERIOD 60*1 //60*1 // for testing
13 13  
14   -#define DBG_TIMER(fmt,...) printf("%c[1;31mtimer-loop.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
  14 +#define DBG_TIMER(fmt,...) printf("%c[1;35mtimer-loop.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
15 15  
16 16 unsigned long getSystemTime(void);
17 17  
... ...
Project/applications/smartcities/json.c
... ... @@ -183,12 +183,13 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen
183 183 }
184 184 else if((response_code >= 400) && (response_code < 500))
185 185 {
186   - DBG_JSON("[ERROR] Communication with server FAILED: JSON_COMM_ERROR\r\n");
  186 +
  187 + DBG_JSON("%c[1;31m[ERROR] Communication with server FAILED: JSON_COMM_ERROR%c[1;00m\r\n",0x1B,0x1B);
187 188 return JSON_COMM_ERROR;
188 189 }
189 190 else
190 191 {
191   - DBG_JSON("[ERROR] Unspecified error: JSON_ERROR_OTHER\r\n");
  192 + DBG_JSON("%c[1;31m[ERROR] Unspecified error: JSON_ERROR_OTHER%c[1;00m\r\n",0x1B,0x1B);
192 193 return JSON_OTHER_ERROR;
193 194 }
194 195 }
... ...
Project/applications/smartcities/main.c
... ... @@ -12,7 +12,7 @@
12 12 #include "ntp.h"
13 13 #include "sensors.h"
14 14  
15   -#define DBG(fmt,...) printf("%c[1;31mmain.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
  15 +#define DBG(fmt,...) printf("%c[1;35mmain.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
16 16  
17 17 uint8_t connected=0;
18 18 uint8_t timeout=0;
... ... @@ -126,6 +126,7 @@ void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked,
126 126 DBG("Memory freed\n\r");
127 127 DBG("[ASSERTION] Message put: %s with length %d\r\n",buffers[i][ind[i]-1] ,strlen(buffers[i][ind[i]-1]));
128 128 }
  129 + DBG("Data is now in buffer\n\r");
129 130 }
130 131 char** timestamp_datas(char* value[],unsigned long timestamp, uint8_t* sensors)
131 132 {
... ... @@ -172,7 +173,10 @@ void send_battery_level(unsigned long timestamp)
172 173 chHeapFree(batt_data);
173 174 char id[3];
174 175 sprintf(id,"%02x",battery.ID);
175   - send_json(statement,strlen(statement),mod.ID,id);
  176 + if(send_json(statement,strlen(statement),mod.ID,id) != JSON_POST_OK)
  177 + {
  178 + DBG("%c[1;31m[ERROR] Battery level NOT sent to server due to communication error%c[1;00m\r\n",0x1B,0x1B);
  179 + }
176 180 chHeapFree(statement);
177 181 }
178 182  
... ... @@ -254,7 +258,6 @@ int main(void)
254 258 delay = getSystemTime();
255 259 values=timestamp_datas(valueSensors,timestamp,sensors);
256 260 put_buffers(buffers,ind,sizes,values,sensors);
257   - DBG("Data is now in buffer\n\r");
258 261 if (i == LONG_PERIOD/SHORT_PERIOD )
259 262 {
260 263 DBG("Programmed send cycle...\r\n");
... ... @@ -288,8 +291,7 @@ int main(void)
288 291 // El servidor no ens sap dir si tenim permisos o no sense registrar una mostra.
289 292 // Intentem enviar un buffer sencer, a veure si ja podem buidar.
290 293 // No podem enviar només una mostra perquè json és rígid en aquest sentit.
291   -
292   - DBG("[HARD LIMIT] unable to send\r\n");
  294 + DBG("%c[1;31m[HARD LIMIT] unable to send%c[1;00m\r\n",0x1B,0x1B);
293 295 chThdSleepMilliseconds(HARD_LIMIT_WAIT_TIME);
294 296 }
295 297 for(j=1;j<sensors_length;j++)
... ... @@ -309,11 +311,4 @@ int main(void)
309 311 sleep_thread(SHORT_PERIOD - time%SHORT_PERIOD);
310 312 i++;
311 313 }
312   -}
313   -
314   -/*
315   - * TO-DO
316   - *
317   - * - Test distance
318   - * - Reset timer-related defines
319   - */
  314 +}
320 315 \ No newline at end of file
... ...
Project/applications/smartcities/ntp.c
... ... @@ -117,34 +117,34 @@ unsigned long getSecsSince1900 (void)
117 117 }
118 118 else
119 119 {
120   - DBG_NTP("[ERROR] Received data did not match frame code\r\n");
  120 + DBG_NTP("%c[1;31m[ERROR] Received data did not match frame code%c[1;00m\r\n",0x1B,0x1B);
121 121 }
122 122 }
123 123 else
124 124 {
125   - DBG_NTP("[ERROR] Length of data did not match SNTP_MAX_DATA_LEN, received len %u\r\n", dataLen);
  125 + DBG_NTP("%c[1;31m[ERROR] Length of data did not match SNTP_MAX_DATA_LEN, received len %u%c[1;00m\r\n", 0x1B,dataLen,0x1B);
126 126 }
127 127 // Deallocate space hold for netbuf structure.
128 128 netbuf_delete(receiveUDPNetBuf);
129 129 }
130 130 else
131 131 {
132   - DBG_NTP("[ERROR] Netconn receive failed with %d\r\n", netconn_err(sendUDPNetConn));
  132 + DBG_NTP("%c[1;31m[ERROR] Netconn receive failed with %d%c[1;00m\r\n", 0x1B,netconn_err(sendUDPNetConn),0x1B);
133 133 }
134 134 }
135 135 else
136 136 {
137   - DBG_NTP("[ERROR] Netconn sendto failed with %d\r\n", errLWIP);
  137 + DBG_NTP("%c[1;31m[ERROR] Netconn sendto failed with %d%c[1;00m\r\n", errLWIP,0x1B);
138 138 }
139 139 }
140 140 else
141 141 {
142   - DBG_NTP("[ERROR] Netconn connect to server %X, port %u failed with %d\r\n", sntp_server_address.addr, SNTP_PORT, errLWIP);
  142 + DBG_NTP("%c[1;31m[ERROR] Netconn connect to server %X, port %u failed with %d%c[1;00m\r\n", 0x1B,sntp_server_address.addr, SNTP_PORT, errLWIP,0x1B);
143 143 }
144 144 }
145 145 else
146 146 {
147   - DBG_NTP("[ERROR] Netconn or netbuf or data allocation failed.\r\n");
  147 + DBG_NTP("%c[1;31m[ERROR] Netconn or netbuf or data allocation failed.%c[1;00m\r\n",0x1B,0x1B);
148 148 }
149 149 // Deallocate space hold for netconn and netbuf structure.
150 150 netbuf_delete(sendUDPNetBuf);
... ... @@ -152,7 +152,7 @@ unsigned long getSecsSince1900 (void)
152 152 } //if (sntp_server_address != 0)
153 153 else
154 154 {
155   - DBG_NTP("[ERROR] Invalid NTP server address %X\r\n", SNTP_SERVER_ADDRESS);
  155 + DBG_NTP("%c[1;31m[ERROR] Invalid NTP server address %X%c[1;00m\r\n", 0x1B,SNTP_SERVER_ADDRESS,0x1B);
156 156 }
157 157  
158 158 return (unsigned long) timestamp;
... ...
Project/applications/smartcities/sensors.c
... ... @@ -454,5 +454,5 @@ void collectData(char* valueSensors[], uint8_t* sensors)
454 454 valueSensors[i]=temp_humidity_value(get_temperature_data(),get_humidity_data());
455 455 }
456 456 }
457   - DBG_SENSORS("Data collected...\r\n");
  457 + DBG_SENSORS("Data collected\r\n");
458 458 }
459 459 \ No newline at end of file
... ...