From ac6a3343032c469423154bbb574bef0b8cc676e5 Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Thu, 5 Jun 2014 04:32:36 +0000 Subject: [PATCH] --- Project/applications/smartcities/buffer.c | 19 +++++-------------- Project/applications/smartcities/buglist.txt | 1 - Project/applications/smartcities/include/sensors.h | 9 +++++---- Project/applications/smartcities/json.c | 5 ++++- Project/applications/smartcities/main.c | 4 +--- Project/applications/smartcities/ntp.c | 2 -- Project/applications/smartcities/sensors.c | 76 +++++++++++++++++++++++++++++++++++++--------------------------------------- 7 files changed, 52 insertions(+), 64 deletions(-) diff --git a/Project/applications/smartcities/buffer.c b/Project/applications/smartcities/buffer.c index 137f9f5..c3994f2 100644 --- a/Project/applications/smartcities/buffer.c +++ b/Project/applications/smartcities/buffer.c @@ -7,13 +7,10 @@ char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len) len=*buf_len; if(len==*index) { - DBG_BUFFER("Joining buffer...\r\n"); char** buffer = join_buf(buf, buf_len); - DBG_BUFFER("Joined buffer...\r\n"); buffer[*index] = chHeapAlloc(NULL,strlen(info)+1); - DBG_BUFFER("Memory allocated...\r\n"); strcpy(buffer[*index],info); - DBG_BUFFER("Data copied...\r\n"); + DBG_BUFFER("Data copied\r\n"); i = *index+1; *index = i; return buffer; @@ -31,9 +28,10 @@ char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len) int check_memory() { + wismart_mem_stat_ram_t status = libwismart_GetMemFree_Ram(); DBG_BUFFER("Checking available memory...\r\n"); - DBG_BUFFER("%c[1;36mAvailable memory: %d B%c[1;00m\r\n",0x1B,libwismart_GetMemFree_Ram().free,0x1B); - int mem = MAX_RAM - libwismart_GetMemFree_Ram().free; + DBG_BUFFER("%c[1;36mAvailable memory: %d B%c[1;00m\r\n",0x1B,status.free,0x1B); + int mem = MAX_RAM - status.free; DBG_BUFFER("%c[1;36mUsed memory: %d B%c[1;00m\r\n",0x1B,mem,0x1B); if(mem >= HARD_LIMIT) { @@ -78,30 +76,23 @@ int send(char** buf, uint32_t *index, uint32_t *size_buf, char *provider_ID, cha return res; } -//realloc char** join_buf(char** buf, uint32_t *buf_len) { + DBG_BUFFER("Joining buffer...\r\n"); char** n_buf; int len = *buf_len; n_buf = chHeapAlloc (NULL,sizeof (char *) * (len+1)); int i; - DBG_BUFFER("Start buffer join...\r\n"); for(i=0; iAC1 = (I2C_read_ack(I2C1) << 8); + calib_data->AC1 |= I2C_read_nack(I2C1); I2C_stop(I2C1); I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); I2C_write(I2C1, 0xAC); I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver); - calib_data.AC2 = (I2C_read_ack(I2C1) << 8); - calib_data.AC2 |= I2C_read_nack(I2C1); + calib_data->AC2 = (I2C_read_ack(I2C1) << 8); + calib_data->AC2 |= I2C_read_nack(I2C1); I2C_stop(I2C1); I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); I2C_write(I2C1, 0xAE); I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver); - calib_data.AC3 = (I2C_read_ack(I2C1) << 8); - calib_data.AC3 |= I2C_read_nack(I2C1); + calib_data->AC3 = (I2C_read_ack(I2C1) << 8); + calib_data->AC3 |= I2C_read_nack(I2C1); I2C_stop(I2C1); I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); I2C_write(I2C1, 0xB0); I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver); - calib_data.AC4 = (I2C_read_ack(I2C1) << 8); - calib_data.AC4 |= I2C_read_nack(I2C1); + calib_data->AC4 = (I2C_read_ack(I2C1) << 8); + calib_data->AC4 |= I2C_read_nack(I2C1); I2C_stop(I2C1); I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); I2C_write(I2C1, 0xB2); I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver); - calib_data.AC5 = (I2C_read_ack(I2C1) << 8); - calib_data.AC5 |= I2C_read_nack(I2C1); + calib_data->AC5 = (I2C_read_ack(I2C1) << 8); + calib_data->AC5 |= I2C_read_nack(I2C1); I2C_stop(I2C1); I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); I2C_write(I2C1, 0xB4); I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver); - calib_data.AC6 = (I2C_read_ack(I2C1) << 8); - calib_data.AC6 |= I2C_read_nack(I2C1); + calib_data->AC6 = (I2C_read_ack(I2C1) << 8); + calib_data->AC6 |= I2C_read_nack(I2C1); I2C_stop(I2C1); I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); I2C_write(I2C1, 0xB6); I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver); - calib_data.B1 = (I2C_read_ack(I2C1) << 8); - calib_data.B1 |= I2C_read_nack(I2C1); + calib_data->B1 = (I2C_read_ack(I2C1) << 8); + calib_data->B1 |= I2C_read_nack(I2C1); I2C_stop(I2C1); I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); I2C_write(I2C1, 0xB8); I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver); - calib_data.B2 = (I2C_read_ack(I2C1) << 8); - calib_data.B2 |= I2C_read_nack(I2C1); + calib_data->B2 = (I2C_read_ack(I2C1) << 8); + calib_data->B2 |= I2C_read_nack(I2C1); I2C_stop(I2C1); I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); I2C_write(I2C1, 0xBA); I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver); - calib_data.MB = (I2C_read_ack(I2C1) << 8); - calib_data.MB |= I2C_read_nack(I2C1); + calib_data->MB = (I2C_read_ack(I2C1) << 8); + calib_data->MB |= I2C_read_nack(I2C1); I2C_stop(I2C1); I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); I2C_write(I2C1, 0xBC); I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver); - calib_data.MC = (I2C_read_ack(I2C1) << 8); - calib_data.MC |= I2C_read_nack(I2C1); + calib_data->MC = (I2C_read_ack(I2C1) << 8); + calib_data->MC |= I2C_read_nack(I2C1); I2C_stop(I2C1); I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); I2C_write(I2C1, 0xBE); I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver); - calib_data.MD = (I2C_read_ack(I2C1) << 8); - calib_data.MD |= I2C_read_nack(I2C1); + calib_data->MD = (I2C_read_ack(I2C1) << 8); + calib_data->MD |= I2C_read_nack(I2C1); I2C_stop(I2C1); DBG_SENSORS("[PRESSURE] Got callibration data\r\n"); - return calib_data; } -char* callibration_pressure_data_csv(bmp085_callibration parameters) +char* callibration_pressure_data_csv(bmp085_callibration_t *parameters) { - char *str = chHeapAlloc(NULL,sizeof(char)*(11*11-1)); - memset(str,0x00,sizeof(char)*(11*11)); - sprintf(str + strlen(str),"%u,",parameters.AC1); - sprintf(str + strlen(str),"%u,",parameters.AC2); - sprintf(str + strlen(str),"%u,",parameters.AC3); - sprintf(str + strlen(str),"%u,",parameters.AC4); - sprintf(str + strlen(str),"%u,",parameters.AC5); - sprintf(str + strlen(str),"%u,",parameters.AC6); - sprintf(str + strlen(str),"%u,",parameters.B1); - sprintf(str + strlen(str),"%u,",parameters.B2); - sprintf(str + strlen(str),"%u,",parameters.MB); - sprintf(str + strlen(str),"%u,",parameters.MC); - sprintf(str + strlen(str),"%u",parameters.MD); + char *str = chHeapAlloc(NULL,(11*11-1)); + memset(str,0x00,(11*11-1)); + sprintf(str + strlen(str),"%u,",parameters->AC1); + sprintf(str + strlen(str),"%u,",parameters->AC2); + sprintf(str + strlen(str),"%u,",parameters->AC3); + sprintf(str + strlen(str),"%u,",parameters->AC4); + sprintf(str + strlen(str),"%u,",parameters->AC5); + sprintf(str + strlen(str),"%u,",parameters->AC6); + sprintf(str + strlen(str),"%u,",parameters->B1); + sprintf(str + strlen(str),"%u,",parameters->B2); + sprintf(str + strlen(str),"%u,",parameters->MB); + sprintf(str + strlen(str),"%u,",parameters->MC); + sprintf(str + strlen(str),"%u",parameters->MD); return str; } -- libgit2 0.22.2