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