From 8450820ad9383ca2a04b09da375a370fe778c778 Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Wed, 28 May 2014 15:28:21 +0000 Subject: [PATCH] --- Project/applications/smartcities/adc.c | 16 ++-------------- Project/applications/smartcities/adc.h | 52 ---------------------------------------------------- Project/applications/smartcities/callbacks.c | 57 +++++++++++++-------------------------------------------- Project/applications/smartcities/configServer.c | 1 - Project/applications/smartcities/include/adc.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Project/applications/smartcities/include/callbacks.h | 1 - Project/applications/smartcities/include/sensors.h | 2 +- Project/applications/smartcities/json.c | 20 +++++++++++++++++--- Project/applications/smartcities/sensors.c | 6 ------ 9 files changed, 85 insertions(+), 122 deletions(-) delete mode 100644 Project/applications/smartcities/adc.h create mode 100644 Project/applications/smartcities/include/adc.h diff --git a/Project/applications/smartcities/adc.c b/Project/applications/smartcities/adc.c index 38f5da1..aeb0346 100644 --- a/Project/applications/smartcities/adc.c +++ b/Project/applications/smartcities/adc.c @@ -11,14 +11,8 @@ uint32_t adc_batt_process() uint32_t analogValue; adcRegisterValue = adc_batt_read(); - - /* - * Calculate the register value to volts - * 1. adcRegisterValue Range is [ADC_MIN_VALUE, ADC_MAX_VALUE] - * 2. analogValue Range is [ADC_VREF_MINUS, ADC_VREF_PLUS] - */ analogValue = ADCbatt_VREF_MINUS + (((adcRegisterValue - ADCbatt_MIN_VALUE)*(ADCbatt_VREF_PLUS - ADCbatt_VREF_MINUS))/(ADCbatt_MAX_VALUE - ADCbatt_MIN_VALUE)); - DBG("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]",adcRegisterValue, analogValue, ADCbatt_GPIO_STR); return analogValue; } @@ -84,14 +78,8 @@ uint32_t adc_sound_process() uint32_t analogValue; adcRegisterValue = adc_sound_read(); - - /* - * Calculate the register value to volts - * 1. adcRegisterValue Range is [ADC_MIN_VALUE, ADC_MAX_VALUE] - * 2. analogValue Range is [ADC_VREF_MINUS, ADC_VREF_PLUS] - */ analogValue = ADCsound_VREF_MINUS + (((adcRegisterValue - ADCsound_MIN_VALUE)*(ADCsound_VREF_PLUS - ADCsound_VREF_MINUS))/(ADCsound_MAX_VALUE - ADCsound_MIN_VALUE)); - DBG("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]",adcRegisterValue, analogValue, ADCsound_GPIO_STR); return analogValue; } diff --git a/Project/applications/smartcities/adc.h b/Project/applications/smartcities/adc.h deleted file mode 100644 index c9edd93..0000000 --- a/Project/applications/smartcities/adc.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef ADC_H -#define ADC_H - -#include "libwismart.h" -#include "ch.h" - -#include "stm32f10x_gpio.h" -#include "stm32f10x_adc.h" - -#define DBG(fmt,...) if(1){printf("[ADC] "fmt"\r\n", ##__VA_ARGS__);}else{({});} - -#define ADCbatt_MIN_VALUE (0) -#define ADCbatt_MAX_VALUE (0xfff) /* 12-bit adc */ -#define ADCbatt_VREF_PLUS (3300) /* Vref+ is connected with Vdda (3.3v) */ -#define ADCbatt_VREF_MINUS (0) /* Vref- is connected with Vssa (2.1v) */ - -#define ADCsound_MIN_VALUE (0) -#define ADCsound_MAX_VALUE (0xfff) /* 12-bit adc */ -#define ADCsound_VREF_PLUS (2800) /* Vref+ is connected with Vdda (3.3v) */ -#define ADCsound_VREF_MINUS (0) /* Vref- is connected with Vssa (0v) */ - -#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_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 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_SAMPLETIME ADC_SampleTime_239Cycles5 -#define ADCsound_GPIO_PIN GPIO_Pin_2 -#define ADCsound_GPIO_PORT GPIOA -#define ADCsound_GPIO_RCC RCC_APB2Periph_GPIOA -#define ADCsound_GPIO_STR "PA2" - -void adc_batt_init(void); -uint32_t adc_batt_process(void); -uint16_t adc_batt_read(void); -void adc_batt_peripheralInit(void); - -void adc_sound_init(void); -uint32_t adc_sound_process(void); -uint16_t adc_sound_read(void); -void adc_sound_peripheralInit(void); - -#endif \ No newline at end of file diff --git a/Project/applications/smartcities/callbacks.c b/Project/applications/smartcities/callbacks.c index 5898ecd..e9059ff 100644 --- a/Project/applications/smartcities/callbacks.c +++ b/Project/applications/smartcities/callbacks.c @@ -25,7 +25,8 @@ void dhcp_connect_result_cb(int result) void wifi_connect_result_cb(int result) { - if(result==WISMART_WIFI_CONN_TIMEOUT){ + if(result==WISMART_WIFI_CONN_TIMEOUT) + { timeout=1; } printf("WiFi Connect indication: "); @@ -44,27 +45,22 @@ void wifi_connect_result_cb(int result) } } -void wifi_connect_ap_result_cb(int result) +void softapMode_apStartedCb(int result) { - - printf("New WiFi Network state: %s\r\n", (result == WISMART_WIFI_CONNECTED) ? "Created": "Failed\r\n"); -} - -void softapMode_apStartedCb(int result){ - if (result == WISMART_WIFI_CONNECTED){ - wifiConnected(WIFI_MODE_SOFTAP); + if (result == WISMART_WIFI_CONNECTED) + { + printWifiInfo(WIFI_MODE_SOFTAP); + configServer_connect(); } } - -/** - * @brief Informs the application about client events in softap mode -*/ -void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *mac, const libwismart_ip_addr_t *ip){ +void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *mac, const libwismart_ip_addr_t *ip) +{ #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" - switch(reason){ + switch(reason) + { case WISMART_WIFI_AP_CLIENT_CONNECTED: printf("Client: "MACSTR" connected\r\n",MAC2STR(mac)); break; @@ -83,35 +79,8 @@ void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *ma #undef MACSTR } -void wifiConnected(uint8_t wifiMode){ - static uint8_t networkInited = 0; - - printWifiInfo(wifiMode); - - if(networkInited != 0){ - return; - }else{ - networkInited = 1; - } - - switch(wifiMode){ - case WIFI_MODE_SOFTAP: - - configServer_connect(); - break; - case WIFI_MODE_CLIENT: - - configServer_connect(); - break; - } - -} - -void printWifiInfo(uint8_t wifiMode){ - - libwismart_ip_addr_t ip, nm, gw; - libwismart_GetCurrentIP(&ip, &nm, &gw); - +void printWifiInfo(uint8_t wifiMode) +{ printf("\r\n\r\n"); printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\n"); printf("| Network Is Ready!\r\n"); diff --git a/Project/applications/smartcities/configServer.c b/Project/applications/smartcities/configServer.c index a6757b8..852cfc3 100644 --- a/Project/applications/smartcities/configServer.c +++ b/Project/applications/smartcities/configServer.c @@ -13,7 +13,6 @@ wismart_server_resource_t configServerResources[22]; void configServer_start(uint8_t enableApScan) { - //create_keys(); configServer_buildResources(); libwismart_server_start(80, "WismartServer", configServer_dynamicCb, chHeapFree, configServerResources); } diff --git a/Project/applications/smartcities/include/adc.h b/Project/applications/smartcities/include/adc.h new file mode 100644 index 0000000..835caee --- /dev/null +++ b/Project/applications/smartcities/include/adc.h @@ -0,0 +1,52 @@ +#ifndef ADC_H +#define ADC_H + +#include "libwismart.h" +#include "ch.h" + +#include "stm32f10x_gpio.h" +#include "stm32f10x_adc.h" + +#define DBG(fmt,...) if(1){printf("[ADC] "fmt"\r\n", ##__VA_ARGS__);}else{({});} + +#define ADCbatt_MIN_VALUE (0) +#define ADCbatt_MAX_VALUE (0xfff) +#define ADCbatt_VREF_PLUS (3300) +#define ADCbatt_VREF_MINUS (0) + +#define ADCsound_MIN_VALUE (0) +#define ADCsound_MAX_VALUE (0xfff) /* 12-bit adc */ +#define ADCsound_VREF_PLUS (2800) /* Vref+ is connected with Vdda (3.3v) */ +#define ADCsound_VREF_MINUS (0) /* Vref- is connected with Vssa (0v) */ + +#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_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 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_SAMPLETIME ADC_SampleTime_239Cycles5 +#define ADCsound_GPIO_PIN GPIO_Pin_2 +#define ADCsound_GPIO_PORT GPIOA +#define ADCsound_GPIO_RCC RCC_APB2Periph_GPIOA +#define ADCsound_GPIO_STR "PA2" + +void adc_batt_init(void); +uint32_t adc_batt_process(void); +uint16_t adc_batt_read(void); +void adc_batt_peripheralInit(void); + +void adc_sound_init(void); +uint32_t adc_sound_process(void); +uint16_t adc_sound_read(void); +void adc_sound_peripheralInit(void); + +#endif \ No newline at end of file diff --git a/Project/applications/smartcities/include/callbacks.h b/Project/applications/smartcities/include/callbacks.h index 1bb2ecb..313ff28 100644 --- a/Project/applications/smartcities/include/callbacks.h +++ b/Project/applications/smartcities/include/callbacks.h @@ -15,7 +15,6 @@ void wifi_connect_ap_result_cb(int result); void wifi_connect_result_cb(int result); void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *mac, const libwismart_ip_addr_t *ip); void softapMode_apStartedCb(int result); -void wifiConnected(uint8_t wifiMode); void printWifiInfo(uint8_t wifiMode); extern uint8_t connected; diff --git a/Project/applications/smartcities/include/sensors.h b/Project/applications/smartcities/include/sensors.h index cacb8fe..ad2af33 100644 --- a/Project/applications/smartcities/include/sensors.h +++ b/Project/applications/smartcities/include/sensors.h @@ -10,7 +10,7 @@ #define LIGHT_ADDR 0x39 #define DISTANCE_ADDR 0x01 -#define PRESSURE_ADDR 0x77 //Cambiar a MPL115A +#define PRESSURE_ADDR 0x77 #define HUMIDITY_TEMP_ADDR 0x27 #define SOUND_ADDR 0x72 #define TOTAL_SENSORS 5 diff --git a/Project/applications/smartcities/json.c b/Project/applications/smartcities/json.c index 3ffd8f9..508f57b 100644 --- a/Project/applications/smartcities/json.c +++ b/Project/applications/smartcities/json.c @@ -125,22 +125,36 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen } if(sensor_ID == NULL) //Register sensor { - URL = (char*) chHeapAlloc(NULL,8+strlen(SERVER_HOSTNAME)); + URL = (char*) chHeapAlloc(NULL,1+strlen(SERVER_HOSTNAME)); strcpy(URL,SERVER_HOSTNAME); + //VANILLA SERVER (SENTILO) PATH = (char*) chHeapAlloc(NULL,19); strcpy(PATH,"/catalog/register"); - //strcpy(PATH+9,provider_ID); + //FUCKING LEWIS... + //TODO + /*PATH = (char*) chHeapAlloc(NULL,19); + strcpy(PATH,"/catalog/register"); + */ } else //Post data { URL = (char*) chHeapAlloc(NULL,1+strlen(SERVER_HOSTNAME)); strcpy(URL,SERVER_HOSTNAME); URL[strlen(SERVER_HOSTNAME)] = '\0'; + //VANILLA SERVER (SENTILO) PATH = (char*) chHeapAlloc(NULL,22+strlen(provider_ID)+strlen(sensor_ID)); strcpy(PATH,"/data/modularupload/"); strcpy(PATH+20,provider_ID); strcpy(PATH+20+strlen(provider_ID),sensor_ID); - PATH[21+strlen(provider_ID)+strlen(sensor_ID)] = '\0'; + //PATH[21+strlen(provider_ID)+strlen(sensor_ID)] = '\0'; + + //FUCKING LEWIS... + //TODO + /*PATH = (char*) chHeapAlloc(NULL,22+strlen(provider_ID)+strlen(sensor_ID)); + strcpy(PATH,"/data/modularupload/"); + strcpy(PATH+20,provider_ID); + strcpy(PATH+20+strlen(provider_ID),sensor_ID); + PATH[21+strlen(provider_ID)+strlen(sensor_ID)] = '\0';*/ } struct httpHeaders server = { put,PATH,strlen(PATH),URL,strlen(URL)}; response_code = httpRequest(server, statement, length); diff --git a/Project/applications/smartcities/sensors.c b/Project/applications/smartcities/sensors.c index 6428034..f878d00 100644 --- a/Project/applications/smartcities/sensors.c +++ b/Project/applications/smartcities/sensors.c @@ -11,12 +11,6 @@ sensor* sensors[TOTAL_SENSORS+1] = {&light_sensor,&ultrasound_sensor,&pressure_s void wakeup_sensors(uint8_t logic_address) { - /* Aquí habría que implementar un control - * inteligente de la alimentación de los - * sensores, levantándolos y durmiéndolos - * cuando tocara - */ - // X X X PA7 PA6 PA5 PA4 PA3 // b7 b6 b5 b4 b3 b2 b1 b0 -- libgit2 0.22.2