Commit 7ab257257e4a9c25ff5fe3fd21e367651e196cbc
1 parent
c2a91f76
--no commit message
Showing
8 changed files
with
714 additions
and
30856 deletions
Too many changes to show.
To preserve performance only 4 of 8 files are displayed.
Project/applications/smartcities/buffer.c
... | ... | @@ -9,6 +9,7 @@ char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len) |
9 | 9 | { |
10 | 10 | char** buffer = join_buf(buf, buf_len); |
11 | 11 | buffer[*index] = chHeapAlloc(NULL,strlen(info)+1); |
12 | + printf("%c[1;31m[ALLOC] Allocated %d bytes to %08x%c[1;00m\r\n",0x1B,strlen(info)+1,buffer[*index],0x1B); | |
12 | 13 | strcpy(buffer[*index],info); |
13 | 14 | DBG_BUFFER("Data copied\r\n"); |
14 | 15 | i = *index+1; |
... | ... | @@ -19,6 +20,7 @@ char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len) |
19 | 20 | { |
20 | 21 | DBG_BUFFER("%c[1;31m[ERROR] WTF in put_message%c[1;00m\r\n",0x1B,0x1B); |
21 | 22 | buf[*index] = chHeapAlloc(NULL,strlen(info)+1); |
23 | + printf("%c[1;31m[ALLOC] Allocated %d bytes to %08x%c[1;00m\r\n",0x1B,strlen(info)+1,buf[*index],0x1B); | |
22 | 24 | buf[*index] = info; |
23 | 25 | i = *index+1; |
24 | 26 | *index = i; |
... | ... | @@ -58,6 +60,7 @@ int send(char** buf, uint32_t *index, uint32_t *size_buf, char *provider_ID, cha |
58 | 60 | } |
59 | 61 | uint8_t res = send_json(statement, size, provider_ID, sensor_ID); |
60 | 62 | chHeapFree(statement); |
63 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,statement,0x1B); | |
61 | 64 | int i; |
62 | 65 | if(res==JSON_POST_OK) |
63 | 66 | { |
... | ... | @@ -65,10 +68,12 @@ int send(char** buf, uint32_t *index, uint32_t *size_buf, char *provider_ID, cha |
65 | 68 | for(i=0;i<*index;i++) |
66 | 69 | { |
67 | 70 | chHeapFree(buf[i]); |
71 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,buf[i],0x1B); | |
68 | 72 | } |
69 | 73 | if(buf!=NULL) |
70 | 74 | { |
71 | 75 | chHeapFree(buf); |
76 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,buf,0x1B); | |
72 | 77 | } |
73 | 78 | *index=0; |
74 | 79 | *size_buf=0; |
... | ... | @@ -82,16 +87,20 @@ char** join_buf(char** buf, uint32_t *buf_len) |
82 | 87 | char** n_buf; |
83 | 88 | int len = *buf_len; |
84 | 89 | n_buf = chHeapAlloc (NULL,sizeof (char *) * (len+1)); |
90 | + printf("%c[1;31m[ALLOC] Allocated %d bytes to %08x%c[1;00m\r\n",0x1B,sizeof(char*) * (len+1),n_buf,0x1B); | |
85 | 91 | int i; |
86 | 92 | for(i=0; i<len;i++) |
87 | 93 | { |
88 | 94 | n_buf[i] = chHeapAlloc(NULL,strlen(buf[i])+1); |
95 | + printf("%c[1;31m[ALLOC] Allocated %d bytes to %08x%c[1;00m\r\n",0x1B,strlen(buf[i])+1,n_buf[i],0x1B); | |
89 | 96 | strcpy(n_buf[i],buf[i]); |
90 | 97 | chHeapFree(buf[i]); |
98 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,buf[i],0x1B); | |
91 | 99 | } |
92 | 100 | if(len != 0) |
93 | 101 | { |
94 | 102 | chHeapFree(buf); |
103 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,buf,0x1B); | |
95 | 104 | } |
96 | 105 | len++; |
97 | 106 | *buf_len=len; | ... | ... |
Project/applications/smartcities/httpClient.c
... | ... | @@ -45,6 +45,7 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) |
45 | 45 | DBG_HTTP("Building request head\r\n"); |
46 | 46 | int request_size = head_size + content_size + 2*(strlen(ENDL)); |
47 | 47 | request = (char *) chHeapAlloc(NULL,request_size); |
48 | + printf("%c[1;31m[ALLOC] Allocated %d bytes to %08x%c[1;00m\r\n",0x1B,request_size,request,0x1B); | |
48 | 49 | strcpy(request, reqMethod2text(head.method)); |
49 | 50 | strcat(request, " "); |
50 | 51 | strcat(request, head.uri); |
... | ... | @@ -62,6 +63,7 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) |
62 | 63 | char *str_content_size = int2string(content_size); |
63 | 64 | strcat(request, str_content_size); |
64 | 65 | chHeapFree(str_content_size); |
66 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str_content_size,0x1B); | |
65 | 67 | |
66 | 68 | // Interlude |
67 | 69 | strcat(request, ENDL); |
... | ... | @@ -95,6 +97,7 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) |
95 | 97 | err_t err=netconn_write(neocon, request, request_size, NETCONN_NOCOPY); |
96 | 98 | DBG_HTTP("Write returned: %d\r\n",err); |
97 | 99 | chHeapFree(request); |
100 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,request,0x1B); | |
98 | 101 | |
99 | 102 | // Wait for Response |
100 | 103 | DBG_HTTP("Waiting for response\r\n"); |
... | ... | @@ -111,6 +114,7 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) |
111 | 114 | // Manage Response |
112 | 115 | DBG_HTTP("Response received. Let's parse the information\r\n"); |
113 | 116 | response = (char*)chHeapAlloc(NULL,4*sizeof(char)); |
117 | + printf("%c[1;31m[ALLOC] Allocated %d bytes to %08x%c[1;00m\r\n",0x1B,4 * sizeof(char),response,0x1B); | |
114 | 118 | netbuf_copy_partial(netBufs,response,3,9); // read 3B starting from 9th -> read response code. "HTTP/1.1 301 Moved Permanently" |
115 | 119 | DBG_HTTP("Response code: %s\r\n",response); |
116 | 120 | int http_response = response2int(response); |
... | ... | @@ -119,6 +123,7 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) |
119 | 123 | netconn_close(neocon); |
120 | 124 | netconn_delete(neocon); |
121 | 125 | chHeapFree(response); |
126 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,response,0x1B); | |
122 | 127 | return http_response; |
123 | 128 | } |
124 | 129 | |
... | ... | @@ -143,6 +148,7 @@ char* int2string(int num) |
143 | 148 | { |
144 | 149 | char* manders; |
145 | 150 | manders = (char*)chHeapAlloc(NULL,numberofdigits(num)+1); |
151 | + printf("%c[1;31m[ALLOC] Allocated %d bytes to %08x%c[1;00m\r\n",0x1B,numberofdigits(num)+1,manders,0x1B); | |
146 | 152 | sprintf(manders, "%d", num); |
147 | 153 | return manders; |
148 | 154 | } | ... | ... |
Project/applications/smartcities/include/buffer.h
... | ... | @@ -10,8 +10,8 @@ |
10 | 10 | #define SOFT_REACHED 1 |
11 | 11 | #define HARD_REACHED 2 |
12 | 12 | |
13 | -//#define DBG_BUFFER(fmt,...) printf("%c[1;35mbuffer.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) | |
14 | -#define DBG_BUFFER(fmt,...) printf("") | |
13 | +#define DBG_BUFFER(fmt,...) printf("%c[1;35mbuffer.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) | |
14 | +//#define DBG_BUFFER(fmt,...) printf("") | |
15 | 15 | |
16 | 16 | char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len); |
17 | 17 | int check_memory(void); | ... | ... |
Project/applications/smartcities/json.c
... | ... | @@ -14,6 +14,7 @@ uint8_t register_sensor(sensor sens) |
14 | 14 | DBG_JSON("callibration_data is: %s\r\n",callibration_data); |
15 | 15 | statement = prepare_json_register_statement(mod,sens,callibration_data); |
16 | 16 | chHeapFree(callibration_data); |
17 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,callibration_data,0x1B); | |
17 | 18 | } |
18 | 19 | else |
19 | 20 | { |
... | ... | @@ -23,6 +24,7 @@ uint8_t register_sensor(sensor sens) |
23 | 24 | sprintf(sensor_ID,"%02x",sens.ID); |
24 | 25 | result = send_json(statement,strlen(statement),mod.ID,NULL); |
25 | 26 | chHeapFree(statement); |
27 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,statement,0x1B); | |
26 | 28 | return result; |
27 | 29 | } |
28 | 30 | |
... | ... | @@ -42,6 +44,7 @@ char* prepare_json_observation_statement(char** data, uint32_t nObservations) |
42 | 44 | length--; //REMOVE LAST ',' |
43 | 45 | json_statement = join_strings(str_aux,"]}\0",length,3,JOIN_NO_FREE); |
44 | 46 | chHeapFree(str_aux); |
47 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str_aux,0x1B); | |
45 | 48 | return json_statement; |
46 | 49 | } |
47 | 50 | |
... | ... | @@ -57,40 +60,51 @@ char* prepare_json_register_statement(module mod, sensor sens, char *additional_ |
57 | 60 | length += MODULE_ID_LENGTH+2; |
58 | 61 | str_aux2 = join_strings(str_aux,"\",\"description\":\"",length,17,JOIN_NO_FREE); |
59 | 62 | chHeapFree(str_aux); |
63 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str_aux,0x1B); | |
60 | 64 | length += 17; |
61 | 65 | str_aux = join_strings(str_aux2,sens.description,length,strlen(sens.description),JOIN_NO_FREE); |
62 | 66 | chHeapFree(str_aux2); |
67 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str_aux2,0x1B); | |
63 | 68 | length += strlen(sens.description); |
64 | 69 | str_aux2 = join_strings(str_aux,"\",\"type\":\"",length,10,JOIN_NO_FREE); |
65 | 70 | chHeapFree(str_aux); |
71 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str_aux,0x1B); | |
66 | 72 | length += 10; |
67 | 73 | str_aux = join_strings(str_aux2,sens.type,length,strlen(sens.type),JOIN_NO_FREE); |
68 | 74 | chHeapFree(str_aux2); |
75 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str_aux2,0x1B); | |
69 | 76 | length += strlen(sens.type); |
70 | 77 | str_aux2 = join_strings(str_aux,"\",\"unit\":\"",length,10,JOIN_NO_FREE); |
71 | 78 | chHeapFree(str_aux); |
79 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str_aux,0x1B); | |
72 | 80 | length += 10; |
73 | 81 | str_aux = join_strings(str_aux2,sens.unit,length,strlen(sens.unit),JOIN_NO_FREE); |
74 | 82 | chHeapFree(str_aux2); |
83 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str_aux2,0x1B); | |
75 | 84 | length += strlen(sens.unit); |
76 | 85 | str_aux2 = join_strings(str_aux,"\",\"location\":\"",length,14,JOIN_NO_FREE); |
77 | 86 | chHeapFree(str_aux); |
87 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str_aux,0x1B); | |
78 | 88 | length += 14; |
79 | 89 | str_aux = join_strings(str_aux2,mod.geoloc,length,strlen(mod.geoloc),JOIN_NO_FREE); |
80 | 90 | chHeapFree(str_aux2); |
91 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str_aux2,0x1B); | |
81 | 92 | length += strlen(mod.geoloc); |
82 | 93 | if(additional_info != NULL) |
83 | 94 | { |
84 | 95 | DBG_JSON("In prepare_json_register_statement: Detected additional_info\r\n"); |
85 | 96 | str_aux2 = join_strings(str_aux,"\",\"additionalInfo\":\"",length,20,JOIN_NO_FREE); |
86 | 97 | chHeapFree(str_aux); |
98 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str_aux,0x1B); | |
87 | 99 | length += 20; |
88 | 100 | str_aux = join_strings(str_aux2,additional_info,length,strlen(additional_info),JOIN_NO_FREE); |
89 | 101 | chHeapFree(str_aux2); |
102 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str_aux2,0x1B); | |
90 | 103 | length += strlen(additional_info); |
91 | 104 | } |
92 | 105 | json_statement = join_strings(str_aux,"\"}]}\0",length,5,JOIN_NO_FREE); |
93 | 106 | chHeapFree(str_aux); |
107 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str_aux,0x1B); | |
94 | 108 | return json_statement; |
95 | 109 | } |
96 | 110 | |
... | ... | @@ -112,7 +126,9 @@ char* prepare_observation(char* observation, uint32_t length) |
112 | 126 | } |
113 | 127 | int timestamp_length = length - (value_length + 1); |
114 | 128 | char *value = (char*) chHeapAlloc(NULL,value_length+1); |
129 | + printf("%c[1;31m[ALLOC] Allocated %d bytes to %08x%c[1;00m\r\n",0x1B,value_length+1,value,0x1B); | |
115 | 130 | char *timestamp = (char*) chHeapAlloc(NULL,timestamp_length+1); |
131 | + printf("%c[1;31m[ALLOC] Allocated %d bytes to %08x%c[1;00m\r\n",0x1B,timestamp_length+1,timestamp,0x1B); | |
116 | 132 | strncpy(value,observation,value_length); |
117 | 133 | strncpy(timestamp,observation+(value_length+1),timestamp_length); |
118 | 134 | value[value_length] = '\0'; |
... | ... | @@ -122,8 +138,11 @@ char* prepare_observation(char* observation, uint32_t length) |
122 | 138 | str_aux2 = join_strings(str_aux2,timestamp,25+value_length,timestamp_length,JOIN_FREE_MEM); |
123 | 139 | json_data = join_strings(str_aux2,"\"},",25+value_length+timestamp_length,3,JOIN_NO_FREE); |
124 | 140 | chHeapFree(str_aux); |
141 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str_aux,0x1B); | |
125 | 142 | chHeapFree(str_aux2); |
143 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str_aux2,0x1B); | |
126 | 144 | chHeapFree(value); |
145 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,value,0x1B); | |
127 | 146 | return json_data; |
128 | 147 | } |
129 | 148 | |
... | ... | @@ -139,29 +158,34 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen |
139 | 158 | if(sensor_ID == NULL) //Register sensor |
140 | 159 | { |
141 | 160 | URL = (char*) chHeapAlloc(NULL,1+strlen(SERVER_HOSTNAME)); |
161 | + printf("%c[1;31m[ALLOC] Allocated %d bytes to %08x%c[1;00m\r\n",0x1B,1+strlen(SERVER_HOSTNAME),URL,0x1B); | |
142 | 162 | strcpy(URL,SERVER_HOSTNAME); |
143 | 163 | #ifdef SERVER_VANILLA |
144 | 164 | //VANILLA SERVER (SENTILO) |
145 | 165 | DBG_JSON("Server is vanilla\r\n") |
146 | 166 | PATH = (char*) chHeapAlloc(NULL,19); |
167 | + printf("%c[1;31m[ALLOC] Allocated %d bytes to %08x%c[1;00m\r\n",0x1B,19,PATH,0x1B); | |
147 | 168 | strcpy(PATH,"/catalog/register"); |
148 | 169 | #endif |
149 | 170 | #ifdef SERVER_LEWIS |
150 | 171 | //FUCKING LEWIS... |
151 | 172 | DBG_JSON("Server is lewis.upc.es\r\n"); |
152 | 173 | PATH = (char*) chHeapAlloc(NULL,50); |
174 | + printf("%c[1;31m[ALLOC] Allocated %d bytes to %08x%c[1;00m\r\n",0x1B,50,PATH,0x1B); | |
153 | 175 | strcpy(PATH,"/modularsense/wordpress/opendata/catalog/register"); |
154 | 176 | #endif |
155 | 177 | } |
156 | 178 | else //Post data |
157 | 179 | { |
158 | 180 | URL = (char*) chHeapAlloc(NULL,1+strlen(SERVER_HOSTNAME)); |
181 | + printf("%c[1;31m[ALLOC] Allocated %d bytes to %08x%c[1;00m\r\n",0x1B,1+strlen(SERVER_HOSTNAME),URL,0x1B); | |
159 | 182 | strcpy(URL,SERVER_HOSTNAME); |
160 | 183 | URL[strlen(SERVER_HOSTNAME)] = '\0'; |
161 | 184 | #ifdef SERVER_VANILLA |
162 | 185 | //VANILLA SERVER (SENTILO) |
163 | 186 | DBG_JSON("Server is vanilla\r\n") |
164 | 187 | PATH = (char*) chHeapAlloc(NULL,22+strlen(provider_ID)+strlen(sensor_ID)); |
188 | + printf("%c[1;31m[ALLOC] Allocated %d bytes to %08x%c[1;00m\r\n",0x1B,22+strlen(provider_ID)+strlen(sensor_ID),PATH,0x1B); | |
165 | 189 | strcpy(PATH,"/data/modularupload/"); |
166 | 190 | strcpy(PATH+20,provider_ID); |
167 | 191 | strcpy(PATH+20+strlen(provider_ID),sensor_ID); |
... | ... | @@ -170,6 +194,7 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen |
170 | 194 | //FUCKING LEWIS... |
171 | 195 | DBG_JSON("Server is lewis.upc.es\r\n"); |
172 | 196 | PATH = (char*) chHeapAlloc(NULL,54+strlen(provider_ID)+strlen(sensor_ID)); |
197 | + printf("%c[1;31m[ALLOC] Allocated %d bytes to %08x%c[1;00m\r\n",0x1B,54+strlen(provider_ID)+strlen(sensor_ID),PATH,0x1B); | |
173 | 198 | strcpy(PATH,"/modularsense/wordpress/opendata/data/modularupload/"); |
174 | 199 | strcpy(PATH+52,provider_ID); |
175 | 200 | strcpy(PATH+52+strlen(provider_ID),sensor_ID); |
... | ... | @@ -178,7 +203,9 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen |
178 | 203 | struct httpHeaders server = { put,PATH,strlen(PATH),URL,strlen(URL)}; |
179 | 204 | response_code = httpRequest(server, statement, length); |
180 | 205 | chHeapFree(PATH); |
206 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,PATH,0x1B); | |
181 | 207 | chHeapFree(URL); |
208 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,URL,0x1B); | |
182 | 209 | if(response_code == 200) |
183 | 210 | { |
184 | 211 | DBG_JSON("Success: %c[1;32mJSON_POST_OK%c[1;00m\r\n",0x1B,0x1B); |
... | ... | @@ -213,13 +240,16 @@ uint32_t find_next_index(char* string, uint32_t length, char delimiter) |
213 | 240 | char* join_strings(char* str1, char* str2, uint32_t len1, uint32_t len2, uint8_t free_mem) |
214 | 241 | { |
215 | 242 | char* str = (char*) chHeapAlloc(NULL,len1+len2+1); |
243 | + printf("%c[1;31m[ALLOC] Allocated %d bytes to %08x%c[1;00m\r\n",0x1B,1+len1+len2,str,0x1B); | |
216 | 244 | strncpy(str,str1,len1); |
217 | 245 | str[len1] = '\0'; |
218 | 246 | strncat(str,str2,len2); |
219 | 247 | if(free_mem) |
220 | 248 | { |
221 | 249 | chHeapFree(str1); |
250 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str1,0x1B); | |
222 | 251 | chHeapFree(str2); |
252 | + printf("%c[1;32m[FREE] Freed bytes from %08x%c[1;00m\r\n",0x1B,str2,0x1B); | |
223 | 253 | } |
224 | 254 | return str; |
225 | 255 | } |
226 | 256 | \ No newline at end of file | ... | ... |