Commit d6456a0f12470ea885ccf86f033325fdf330d08c
1 parent
d5ac5e26
--no commit message
Showing
10 changed files
with
35948 additions
and
35922 deletions
Too many changes to show.
To preserve performance only 2 of 10 files are displayed.
Project/applications/smartcities/buffer.c
@@ -3,20 +3,23 @@ | @@ -3,20 +3,23 @@ | ||
3 | 3 | ||
4 | char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len){ | 4 | char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len){ |
5 | 5 | ||
6 | -uint32_t i; | ||
7 | -i= *index; | ||
8 | -if(*buf_len==i) | 6 | +uint32_t i,len; |
7 | +len=*buf_len; | ||
8 | +if(len==*index) | ||
9 | { | 9 | { |
10 | + | ||
10 | char** buffer=join_buf(buf, buf_len); | 11 | char** buffer=join_buf(buf, buf_len); |
11 | - buffer[i]=chHeapAlloc(NULL,strlen(info)+1); | ||
12 | - buffer[i]=info; | ||
13 | - *index = i++; | 12 | + buffer[*index]=chHeapAlloc(NULL,strlen(info)+1); |
13 | + strcpy(buffer[*index],info); | ||
14 | + i=*index+1; | ||
15 | + *index = i; | ||
14 | return buffer; | 16 | return buffer; |
15 | } | 17 | } |
16 | else{ | 18 | else{ |
17 | - buf[i] = chHeapAlloc(NULL,strlen(info)+1); | ||
18 | - buf[i]=info; | ||
19 | - *index = i++; | 19 | + buf[*index] = chHeapAlloc(NULL,strlen(info)+1); |
20 | + buf[*index]=info; | ||
21 | + i=*index+1; | ||
22 | + *index = i; | ||
20 | return buf; | 23 | return buf; |
21 | } | 24 | } |
22 | 25 | ||
@@ -24,9 +27,11 @@ else{ | @@ -24,9 +27,11 @@ else{ | ||
24 | 27 | ||
25 | int check_memory(){ | 28 | int check_memory(){ |
26 | 29 | ||
27 | - int mem_free=libwismart_GetMemFree_Ram().free; | ||
28 | - int mem=25600-mem_free; | ||
29 | - | 30 | + //int mem_free=libwismart_GetMemFree_Ram().free_core; |
31 | + //printf("mem lliure=%d\r\n",mem_free); | ||
32 | + int mem_free=20000; | ||
33 | + int mem=38920-mem_free; | ||
34 | + printf("mem ocupada=%d\r\n",mem); | ||
30 | if(mem>=HARD_LIMIT) | 35 | if(mem>=HARD_LIMIT) |
31 | { | 36 | { |
32 | return HARD_REACHED; | 37 | return HARD_REACHED; |
@@ -37,14 +42,24 @@ int check_memory(){ | @@ -37,14 +42,24 @@ int check_memory(){ | ||
37 | return MEMORY_OK; | 42 | return MEMORY_OK; |
38 | } | 43 | } |
39 | 44 | ||
40 | -int send(char** buf, uint32_t index, char *provider_ID, char *sensor_ID){ | ||
41 | - | ||
42 | - char* statement=prepare_json_observation_statement(buf, index+1); | 45 | +int send(char** buf, uint32_t *index, uint32_t *size_buf, char *provider_ID, char *sensor_ID){ |
46 | + printf("1\r\n"); | ||
47 | + char* statement=prepare_json_observation_statement(buf, *index); | ||
48 | + printf("2\r\n"); | ||
43 | uint32_t size = strlen(statement); | 49 | uint32_t size = strlen(statement); |
50 | + printf("3\r\n"); | ||
44 | uint8_t res=send_json(statement, size, provider_ID, sensor_ID); | 51 | uint8_t res=send_json(statement, size, provider_ID, sensor_ID); |
52 | + printf("4\r\n"); | ||
45 | int i; | 53 | int i; |
46 | - for(i=0;i<index+1;i++){ | 54 | + printf("res=%d\r\n",res); |
55 | + if(res==JSON_POST_OK){ | ||
56 | + | ||
57 | + for(i=0;i<*index;i++){ | ||
47 | chHeapFree(buf[i]); | 58 | chHeapFree(buf[i]); |
59 | + } | ||
60 | + printf(" posant la mida i l'index a 0\r\n"); | ||
61 | + *index=0; | ||
62 | + *size_buf=0; | ||
48 | } | 63 | } |
49 | return res; | 64 | return res; |
50 | } | 65 | } |
@@ -71,12 +86,13 @@ char** join_buf(char** buf, uint32_t *buf_len){ | @@ -71,12 +86,13 @@ char** join_buf(char** buf, uint32_t *buf_len){ | ||
71 | n_buf=chHeapAlloc (NULL,sizeof (char *) * (len+1)); | 86 | n_buf=chHeapAlloc (NULL,sizeof (char *) * (len+1)); |
72 | int i; | 87 | int i; |
73 | for(i=0; i<len;i++){ | 88 | for(i=0; i<len;i++){ |
74 | - char* aux=buf[i]; | ||
75 | - n_buf[i]=chHeapAlloc(NULL,strlen(aux)+1); | ||
76 | - n_buf[i]=aux; | 89 | + n_buf[i]=chHeapAlloc(NULL,strlen(buf[i])+1); |
90 | + strcpy(n_buf[i],buf[i]); | ||
77 | chHeapFree(buf[i]); | 91 | chHeapFree(buf[i]); |
78 | } | 92 | } |
79 | - chHeapFree(buf); | ||
80 | - *buf_len=len++; | 93 | + if(len!=0){ |
94 | + chHeapFree(buf);} | ||
95 | + len++; | ||
96 | + *buf_len=len; | ||
81 | return n_buf; | 97 | return n_buf; |
82 | } | 98 | } |
Project/applications/smartcities/build/smartcities.bin
No preview for this file type