From 554a12ad76343e97f9eb0cfd7f03b4575ec4f701 Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Thu, 29 May 2014 03:17:50 +0000 Subject: [PATCH] --- Project/applications/smartcities/adc.c | 14 +++++++------- Project/applications/smartcities/include/adc.h | 12 ++++++------ Project/applications/smartcities/json.c | 17 +++++++++++++++-- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/Project/applications/smartcities/adc.c b/Project/applications/smartcities/adc.c index aeb0346..b30ba17 100644 --- a/Project/applications/smartcities/adc.c +++ b/Project/applications/smartcities/adc.c @@ -12,7 +12,7 @@ uint32_t adc_batt_process() adcRegisterValue = adc_batt_read(); analogValue = ADCbatt_VREF_MINUS + (((adcRegisterValue - ADCbatt_MIN_VALUE)*(ADCbatt_VREF_PLUS - ADCbatt_VREF_MINUS))/(ADCbatt_MAX_VALUE - ADCbatt_MIN_VALUE)); - printf("Register value is %4u [%4u milliVolts are currently given to gpio %s]",adcRegisterValue, analogValue, ADCbatt_GPIO_STR); + printf("Register value is %4u [%4u milliVolts are currently given to gpio %s]\r\n",adcRegisterValue, analogValue, ADCbatt_GPIO_STR); return analogValue; } @@ -22,7 +22,7 @@ void adc_batt_peripheralInit() ADC_InitTypeDef ADC_InitStructure; RCC_APB2PeriphClockCmd(ADCbatt_GPIO_RCC, ENABLE); GPIO_InitStructure.GPIO_Pin = ADCbatt_GPIO_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(ADCbatt_GPIO_PORT, &GPIO_InitStructure); @@ -43,6 +43,7 @@ void adc_batt_peripheralInit() /* Say how many channels would be used by the sequencer */ ADC_InitStructure.ADC_NbrOfChannel = 1; + ADC_RegularChannelConfig(ADCbatt, ADCbatt_CHANNEL, 1, ADCbatt_SAMPLETIME); ADC_Init(ADCbatt, &ADC_InitStructure); ADC_Cmd(ADCbatt, ENABLE); @@ -58,7 +59,6 @@ void adc_batt_peripheralInit() uint16_t adc_batt_read() { - ADC_RegularChannelConfig(ADCbatt, ADCbatt_CHANNEL, 1, ADCbatt_SAMPLETIME); /* Start the conversion */ ADC_SoftwareStartConvCmd(ADCbatt, ENABLE); /* Wait until conversion completion */ @@ -79,7 +79,7 @@ uint32_t adc_sound_process() adcRegisterValue = adc_sound_read(); analogValue = ADCsound_VREF_MINUS + (((adcRegisterValue - ADCsound_MIN_VALUE)*(ADCsound_VREF_PLUS - ADCsound_VREF_MINUS))/(ADCsound_MAX_VALUE - ADCsound_MIN_VALUE)); - printf("Register value is %4u [%4u milliVolts are currently given to gpio %s]",adcRegisterValue, analogValue, ADCsound_GPIO_STR); + printf("Register value is %4u [%4u milliVolts are currently given to gpio %s]\r\n",adcRegisterValue, analogValue, ADCsound_GPIO_STR); return analogValue; } @@ -89,7 +89,7 @@ void adc_sound_peripheralInit() ADC_InitTypeDef ADC_InitStructure; RCC_APB2PeriphClockCmd(ADCsound_GPIO_RCC, ENABLE); GPIO_InitStructure.GPIO_Pin = ADCsound_GPIO_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(ADCsound_GPIO_PORT, &GPIO_InitStructure); @@ -110,7 +110,8 @@ void adc_sound_peripheralInit() ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; /* Say how many channels would be used by the sequencer */ ADC_InitStructure.ADC_NbrOfChannel = 1; - + + ADC_RegularChannelConfig(ADCsound, ADCsound_CHANNEL, 1, ADCsound_SAMPLETIME); ADC_Init(ADCsound, &ADC_InitStructure); ADC_Cmd(ADCsound, ENABLE); @@ -126,7 +127,6 @@ void adc_sound_peripheralInit() uint16_t adc_sound_read() { - ADC_RegularChannelConfig(ADCsound, ADCsound_CHANNEL, 1, ADCsound_SAMPLETIME); /* Start the conversion */ ADC_SoftwareStartConvCmd(ADCsound, ENABLE); /* Wait until conversion completion */ diff --git a/Project/applications/smartcities/include/adc.h b/Project/applications/smartcities/include/adc.h index 835caee..ec22cdf 100644 --- a/Project/applications/smartcities/include/adc.h +++ b/Project/applications/smartcities/include/adc.h @@ -22,17 +22,17 @@ #define ADCbatt ADC1 #define ADCbatt_RCC RCC_APB2Periph_ADC1 /* */ #define ADCbatt_DIVIDER RCC_PCLK2_Div4 /* Can be 2/4/6/8. PCLK2 runs at 32Mhz, and max ADC clock is 14Mhz */ -#define ADCbatt_CHANNEL ADC_Channel_12 /* 0/17 */ +#define ADCbatt_CHANNEL ADC_Channel_1 /* 0/17 */ #define ADCbatt_SAMPLETIME ADC_SampleTime_239Cycles5 -#define ADCbatt_GPIO_PIN GPIO_Pin_2 -#define ADCbatt_GPIO_PORT GPIOC -#define ADCbatt_GPIO_RCC RCC_APB2Periph_GPIOC -#define ADCbatt_GPIO_STR "PC2" +#define ADCbatt_GPIO_PIN GPIO_Pin_1 +#define ADCbatt_GPIO_PORT GPIOA +#define ADCbatt_GPIO_RCC RCC_APB2Periph_GPIOA +#define ADCbatt_GPIO_STR "PA1" #define ADCsound ADC2 #define ADCsound_RCC RCC_APB2Periph_ADC2 /* */ #define ADCsound_DIVIDER RCC_PCLK2_Div4 /* Can be 2/4/6/8. PCLK2 runs at 32Mhz, and max ADC clock is 14Mhz */ -#define ADCsound_CHANNEL ADC_Channel_11 /* 0/17 */ +#define ADCsound_CHANNEL ADC_Channel_2 /* 0/17 */ #define ADCsound_SAMPLETIME ADC_SampleTime_239Cycles5 #define ADCsound_GPIO_PIN GPIO_Pin_2 #define ADCsound_GPIO_PORT GPIOA diff --git a/Project/applications/smartcities/json.c b/Project/applications/smartcities/json.c index 97c958d..d5c0c30 100644 --- a/Project/applications/smartcities/json.c +++ b/Project/applications/smartcities/json.c @@ -96,7 +96,20 @@ char* prepare_json_register_statement(module mod, sensor sens, char *additional_ char* prepare_observation(char* observation, uint32_t length) { char *json_data, *str_aux, *str_aux2; - int value_length = find_next_index(observation,length,','); //EXPECTS FORMATTING!!! + int value_length = find_next_index(observation,length,','); + while(1) + { + printf("value_length = %d\r\n",value_length); + if(find_next_index(observation+value_length+1,length,',')) + { + value_length += find_next_index(observation+value_length+1,length,',')+1; + } + else + { + printf("Comma in %d\r\n",value_length); + break; + } + } int timestamp_length = length - (value_length + 1); char *value = (char*) chHeapAlloc(NULL,value_length+1); char *timestamp = (char*) chHeapAlloc(NULL,timestamp_length+1); @@ -181,7 +194,7 @@ uint32_t find_next_index(char* string, uint32_t length, char delimiter) return i; } } - return -1; + return 0; } char* join_strings(char* str1, char* str2, uint32_t len1, uint32_t len2, uint8_t free_mem) -- libgit2 0.22.2