Commit e2524268c0a65589e9ffd2aa866d0243496b0a6d
1 parent
3f393e23
Documentation finished
Showing
3 changed files
with
178 additions
and
35 deletions
Project/applications/smartcities/include/httpClient.h
1 | -/* | |
2 | - * Custom http client implementation based on httpServer | |
1 | + | |
2 | +/**@file | |
3 | + * @brief Definition for the HTTP Client functions | |
4 | + * @author Ferràn Quer i Guerrero | |
5 | + * @date 08/06/2014 | |
3 | 6 | * |
7 | + * Custom http client implementation based on httpServer | |
4 | 8 | */ |
9 | + | |
5 | 10 | #ifndef HTTP_CLIENT_H |
6 | 11 | #define HTTP_CLIENT_H |
7 | 12 | |
... | ... | @@ -14,39 +19,59 @@ |
14 | 19 | #include "ch.h" |
15 | 20 | #include "globals.h" |
16 | 21 | |
17 | -#define DEFAULT_REMOTE_IP "147.83.2.135" // www.upc.edu | |
22 | +//! Default remote port (HTTP) | |
18 | 23 | #define DEFAULT_REMOTE_PORT 80 |
24 | +//! Endline definition | |
19 | 25 | #define ENDL "\r\n" |
26 | +//! Content-type header string | |
20 | 27 | #define CONTENT_TYPE_HEADER "Content-Type: application/json; charset=UTF-8" |
21 | 28 | |
29 | +//! Debug printing definition | |
30 | +/*! This definition is used for debugging purposes, it is a shorthand for printing debug information */ | |
22 | 31 | #define DBG_HTTP(fmt,...) printf("%c[1;35mhttpClient.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) |
23 | 32 | //#define DBG_HTTP(fmt,...) printf("") |
24 | 33 | |
25 | - | |
34 | +//! Available Request Methods | |
26 | 35 | typedef enum reqMethod |
27 | 36 | { |
37 | + //! POST request | |
28 | 38 | post, |
39 | + //! GET request | |
29 | 40 | get, |
41 | + //! PUT request | |
30 | 42 | put, |
43 | + //! DELETE request | |
31 | 44 | del //delete may be a special word. |
32 | 45 | |
33 | 46 | }reqMethod; |
34 | 47 | |
48 | +//! HTTP request header parameters | |
35 | 49 | typedef struct httpHeaders |
36 | 50 | { |
51 | + //! Request method | |
37 | 52 | enum reqMethod method; |
53 | + //! URI to send the request to | |
38 | 54 | char* uri; |
55 | + //! Size of the URI string | |
39 | 56 | int uri_size; |
57 | + //! HTTP host to send the request | |
40 | 58 | char* host; |
59 | + //! HTTP host string length | |
41 | 60 | int host_size; |
42 | 61 | |
43 | 62 | }httpHeaders; |
44 | 63 | |
45 | - | |
46 | -int httpRequest(struct httpHeaders head, char* content, int content_size); | |
47 | -const char* reqMethod2text(enum reqMethod method); | |
48 | -char* int2string(int num); | |
49 | -int numberofdigits(int number); | |
50 | -int response2int(char* chars); | |
64 | +//! HTTP Client request function | |
65 | +/*! This function sends a HTTP request with the specified headers and content passed by argument. */ | |
66 | +int httpRequest(struct httpHeaders head /*! HTTP Header parameters */, char* content /*! Content to send */, int content_size /*! Content length */); | |
67 | +//! Translates each request method from the enum to its string | |
68 | +const char* reqMethod2text(enum reqMethod method /*! Method to translate */); | |
69 | +//! Converts and returns an integer passed by argument as a string | |
70 | +char* int2string(int num /*! Number to convert */); | |
71 | +//! Calculates and returns the number of digits of a number passed by argument | |
72 | +int numberofdigits(int number /*! Number to count */); | |
73 | +//! HTTP response parsing function | |
74 | +/*! This function parses the HTTP response and returns the HTTP response code. */ | |
75 | +int response2int(char* chars /*! HTTP response */); | |
51 | 76 | |
52 | 77 | #endif |
53 | 78 | \ No newline at end of file | ... | ... |
Project/applications/smartcities/include/ntp.h
1 | + | |
2 | +/**@file | |
3 | + * @brief Definition for the NTP functions | |
4 | + * @author Emilio Soca Herrera | |
5 | + * @date 08/06/2014 | |
6 | + * | |
7 | + * The functions declared in this file manage the NTP functionality of the device to update local time and timestamp data | |
8 | + */ | |
9 | + | |
1 | 10 | #ifndef NTP_H |
2 | 11 | #define NTP_H |
3 | 12 | |
... | ... | @@ -18,29 +27,42 @@ |
18 | 27 | #include "ch.h" |
19 | 28 | #include "globals.h" |
20 | 29 | |
30 | +//! Debug printing definition | |
31 | +/*! This definition is used for debugging purposes, it is a shorthand for printing debug information */ | |
21 | 32 | #define DBG_NTP(fmt,...) printf("%c[1;35mntp.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) |
22 | 33 | //#define DBG_NTP(fmt,...) printf("") |
23 | 34 | |
35 | +//! Leap year calculation define | |
24 | 36 | #define LEAP_YEAR(Y) (((1970+Y)>0) && !((1970+Y)%4) && (((1970+Y)%100) || !((1970+Y)%400))) |
37 | +//! Length of NTP packet | |
25 | 38 | #define NTP_PACKET_LENGTH 48 |
39 | +//! NTP Port | |
26 | 40 | #define SNTP_PORT 123 |
27 | -/** SNTP receive timeout - in milliseconds */ | |
41 | +//! SNTP receive timeout - in milliseconds | |
28 | 42 | #define SNTP_RECV_TIMEOUT 3000 |
29 | -/** SNTP update delay - in milliseconds */ | |
43 | +//! SNTP update delay - in milliseconds | |
30 | 44 | #define SNTP_UPDATE_DELAY 60000 |
45 | +//! Maximum packet length | |
31 | 46 | #define SNTP_MAX_DATA_LEN 48 |
47 | +//! NTP receive time offset | |
32 | 48 | #define SNTP_RCV_TIME_OFS 32 |
33 | 49 | #define SNTP_LI_NO_WARNING 0x00 |
50 | +//! NTP version specification | |
34 | 51 | #define SNTP_VERSION (4/* NTP Version 4*/<<3) |
52 | +//! NTP Client mode definition | |
35 | 53 | #define SNTP_MODE_CLIENT 0x03 |
54 | +//! NTP Server mode definition | |
36 | 55 | #define SNTP_MODE_SERVER 0x04 |
56 | +//! NTP Broadcast mode definition | |
37 | 57 | #define SNTP_MODE_BROADCAST 0x05 |
58 | +//! NTP Mask mode definition | |
38 | 59 | #define SNTP_MODE_MASK 0x07 |
39 | -/* number of seconds between 1900 and 1970 */ | |
60 | +//! Number of seconds between 1900 and 1970 | |
40 | 61 | #define DIFF_SEC_1900_1970 (2208988800LL) |
41 | -/*timezone from GMT*/ | |
62 | +//! Timezone from GMT | |
42 | 63 | #define TIME_ZONE 2 |
43 | 64 | |
65 | +//! Date structure definition | |
44 | 66 | typedef struct { |
45 | 67 | int second; |
46 | 68 | int minute; |
... | ... | @@ -50,10 +72,13 @@ typedef struct { |
50 | 72 | int year; |
51 | 73 | }Date; |
52 | 74 | |
53 | -char* timestamp_data(char* value,Date time); | |
75 | +//! Data timestamping function | |
76 | +/*! Adds a timestamp to the data passed by argument and returns a new string with the data timestamped .*/ | |
77 | +char* timestamp_data(char* value /*! Data to timestamp */,Date time /*! Timestamp */); | |
78 | +//! This function returns the number of seconds since 1900 | |
54 | 79 | unsigned long getSecsSince1900(void); |
55 | -Date getDate(unsigned long); | |
56 | -void udpNtp_test(void); | |
57 | - | |
80 | +//! Timestamp to Date converting function | |
81 | +/*! This function converts a timestamp to a Date struct and returns the resulting struct. */ | |
82 | +Date getDate(unsigned long secsSince1900/*! Timestamp to convert */); | |
58 | 83 | |
59 | 84 | #endif | ... | ... |
Project/applications/smartcities/include/sensors.h
1 | + | |
2 | +/**@file | |
3 | + * @brief Definition for the sensors and sensor related functions | |
4 | + * @author Imanol Barba Sabariego | |
5 | + * @date 08/06/2014 | |
6 | + * | |
7 | + * Here are the sensor definitions and all the functions needed to fetch and parse data from the sensors. | |
8 | + * <br> REMEMBER TO UPDATE I2C SENSORS IN SENSOR DEFINITIONS IN THIS HEADER AND IN sensors.c WITH EACH NEW SENSOR!!!! | |
9 | + */ | |
10 | + | |
1 | 11 | #ifndef SENSORS_H |
2 | 12 | #define SENSORS_H |
3 | 13 | |
... | ... | @@ -8,28 +18,55 @@ |
8 | 18 | #include "module.h" |
9 | 19 | #include "adc.h" |
10 | 20 | |
21 | +//! Light sensor I2C address | |
11 | 22 | #define LIGHT_ADDR 0x39 |
23 | +//! Distance sensor I2C address | |
12 | 24 | #define DISTANCE_ADDR 0x01 |
25 | +//! Pressure sensor I2C address | |
13 | 26 | #define PRESSURE_ADDR 0x77 |
27 | +//! Humidity and temperature sensor I2C address | |
14 | 28 | #define HUMIDITY_TEMP_ADDR 0x27 |
29 | +//! Sound sensor I2C address | |
15 | 30 | #define SOUND_ADDR 0x48 |
31 | +//! Total number of sensors programmed | |
32 | +/*! This definition MUST be updated everytime a new sensor is programmed in this file. */ | |
16 | 33 | #define TOTAL_SENSORS 5 |
17 | -//REMEMBER TO UPDATE collectData ROUTINE WITH EACH NEW SENSOR!!!! | |
18 | -//REMEMBER TO UPDATE I2C sensors in sensor definitions in this header and sensors.c WITH EACH NEW SENSOR!!!! | |
19 | 34 | |
20 | -#define BATTERY_ADDR 0x00 //SIEMPRE PRESENTE, NUNCA BUSCAR EN i2c_scan | |
35 | +//! Battery I2C address | |
36 | +/*! NOTE: This is not a valid I2C address, it serves as identification ID.<br> Never scan the I2C bus looking for this address nor include it in the TOTAL_SENSORS count, | |
37 | + * as it is assumed that the battery sensor is always present (even without a battery). */ | |
38 | +#define BATTERY_ADDR 0x00 | |
21 | 39 | |
40 | +//! Debug printing definition | |
41 | +/*! This definition is used for debugging purposes, it is a shorthand for printing debug information */ | |
22 | 42 | #define DBG_SENSORS(fmt,...) printf("%c[1;35msensors.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) |
23 | 43 | //#define DBG_SENSORS(fmt,...) printf("") |
24 | 44 | |
45 | +//! Sensor information structure definition | |
25 | 46 | typedef struct { |
47 | + //! Sensor ID | |
26 | 48 | uint8_t ID; |
49 | + //! Sensor description | |
27 | 50 | char* description; |
51 | + //! Sensor type | |
28 | 52 | char* type; |
53 | + //! Unit of data measured | |
29 | 54 | char* unit; |
30 | 55 | } sensor; |
31 | 56 | |
32 | -void wakeup_sensors(uint8_t logic_address); | |
57 | +//! Sensor power control function | |
58 | +/*! This function powers sensors on and off through the GPIO pins and the logical address (NOT THE I2C address) passed by argument. | |
59 | + * <br>This works using the logical address a a byte and assigning each of the bits as one of the control pins as the following scheme shows: | |
60 | + * <br>b7 -> X | |
61 | + * <br>b6 -> X | |
62 | + * <br>b5 -> X | |
63 | + * <br>b4 -> PA7 | |
64 | + * <br>b3 -> PA6 | |
65 | + * <br>b2 -> PA5 | |
66 | + * <br>b1 -> PA4 | |
67 | + * <br>b0 -> PA3 | |
68 | + */ | |
69 | +void wakeup_sensors(uint8_t logic_address /*! Logical address to set on the pins */); | |
33 | 70 | |
34 | 71 | //SENSOR DEFINITIONS |
35 | 72 | extern sensor light_sensor; |
... | ... | @@ -44,20 +81,35 @@ extern sensor* sensors[TOTAL_SENSORS+1]; |
44 | 81 | //SENSOR FUNCTIONS |
45 | 82 | |
46 | 83 | //LIGHT SENSOR |
84 | +//! Light sensor intialization function | |
85 | +/*! This function powers the light sensor on and sends commands to start the light measurement. */ | |
47 | 86 | void init_light(void); |
87 | +//! Light sensor data acquisition function | |
88 | +/*! This function returns the light data from both CH0 and CH1 channels from the sensors. The data is serialized as CH1:CH0 */ | |
48 | 89 | uint32_t get_light_data(void); |
90 | +//! Light sensor ADC CH0 data fetch function | |
49 | 91 | uint16_t get_light_ch0(void); |
92 | +//! Light sensor ADC CH1 data fetch function | |
50 | 93 | uint16_t get_light_ch1(void); |
51 | -char* light_value(uint32_t light); | |
94 | +//! Light sensor data parsing function | |
95 | +/*! This function takes the light numeric value serialized in get_light_data and returns a string to be timestamped and sent to the server. */ | |
96 | +char* light_value(uint32_t light /*! Numeric value */); | |
52 | 97 | |
53 | 98 | //ULTRASONIC SENSOR |
99 | +//! Distance sensor data acquisition function | |
100 | +/*! This function returns the distance measurement done by the distance sensor. */ | |
54 | 101 | uint16_t get_distance_data(void); |
102 | +//! Distance sensor intialization function | |
103 | +/*! This function powers the distance sensor on and sends commands to start the distance measurement. */ | |
55 | 104 | void init_ultrasound(void); |
56 | -char* distance_value(uint16_t distance); | |
105 | +//! Distance sensor data parsing function | |
106 | +/*! This function takes the distance numeric value from get_distance_data and returns a string to be timestamped and sent to the server. */ | |
107 | +char* distance_value(uint16_t distance /*! Numeric value */); | |
57 | 108 | |
58 | 109 | |
59 | 110 | //PRESSURE SENSOR |
60 | 111 | typedef struct bmp085_callibration bmp085_callibration_t; |
112 | +//! Pressure sensor callibration parameters | |
61 | 113 | struct bmp085_callibration { |
62 | 114 | uint16_t AC1; |
63 | 115 | uint16_t AC2; |
... | ... | @@ -71,35 +123,76 @@ struct bmp085_callibration { |
71 | 123 | uint16_t MC; |
72 | 124 | uint16_t MD; |
73 | 125 | }; |
74 | - | |
126 | +//! Pressure sensor intialization function | |
127 | +/*! This function powers the pressure sensor on and sends commands to start the pressure measurement. */ | |
75 | 128 | void init_pressure(void); |
129 | +//! Temperature measurement intialization function | |
130 | +/*! This function powers the temperature measurement function from the pressure sensor on and sends commands to start the temperature measurement. */ | |
76 | 131 | void init_pressure_temperature(void); |
132 | +//! Pressure sensor data acquisition function | |
133 | +/*! This function returns the pressure measurement done by the pressure sensor. */ | |
77 | 134 | uint16_t get_pressure_data(void); |
135 | +//! Temperature data acquisition from the pressure sensor function | |
136 | +/*! This function returns the temperature measurement done by the pressure sensor. */ | |
78 | 137 | uint16_t get_pressure_temperature_data(void); |
79 | -void get_pressure_callibration_data(bmp085_callibration_t *calib_data); | |
80 | -char* callibration_pressure_data_csv(bmp085_callibration_t *parameters); | |
81 | -char* pressure_value(uint16_t pressure,uint16_t temperature); | |
138 | +//! Pressure sensor callibration parameters acquisition function | |
139 | +/*! This function retrieves the callibration parameters from the pressure sensor and writes them in the struct passed by argument. */ | |
140 | +void get_pressure_callibration_data(bmp085_callibration_t *calib_data /*! Struct to write in the callibration parameters */); | |
141 | +//! Pressure sensor callibration parameters serialization function | |
142 | +/*! This function returns a string with the callibration parameters passed by argument serialized in the following way: | |
143 | + * <br>AC1,AC2,AC3,AC4,AC5,AC6,B1,B2,MB,MC,MD | |
144 | + */ | |
145 | +char* callibration_pressure_data_csv(bmp085_callibration_t *parameters /*! Callibration parameters to serialize */); | |
146 | +//! Pressure sensor data parsing function | |
147 | +/*! This function takes the pressure and temperature numeric value from get_pressure_data and get_pressure_temperature_data and returns a string to be timestamped and sent to the server. | |
148 | + * <br>NOTE: The data is serialized as Pressure_Value,Temperature_Value | |
149 | + * <br>NOTE 2: The temperature measurement is mandatory, as the temperature data is used to calculate the true atmospheric pressure from the data returned from the pressure sensor. | |
150 | + */ | |
151 | +char* pressure_value(uint16_t pressure /*! Numeric value */,uint16_t temperature /*! Numeric value */); | |
82 | 152 | |
83 | 153 | //HUMIDITY AND TEMPERATURE SENSOR |
84 | - | |
154 | +//! Temperature and humidity sensor intialization function | |
155 | +/*! This function powers the temperature and humidity sensor on and sends commands to start the measurements. */ | |
85 | 156 | void init_humidity_temp(void); |
157 | +//! Humidity data acquisition from the humidity and temperature sensor function | |
158 | +/*! This function returns the humidity measurement done by the temperature and humidity sensor. */ | |
86 | 159 | uint16_t get_humidity_data(void); |
160 | +//! Temperature data acquisition from the temperature and humidity function | |
161 | +/*! This function returns the temperature measurement done by the humidity and temperature sensor. */ | |
87 | 162 | uint16_t get_temperature_data(void); |
88 | -char* temp_humidity_value(uint16_t temp, uint16_t humidity); | |
163 | +//! Temperature and Humidity sensor data parsing function | |
164 | +/*! This function takes the temperature and humidity numeric value from get_distance_data and get_humidity_data and returns a string to be timestamped and sent to the server. | |
165 | + * <br>NOTE: The data is serialized as Temperature_Value,Humidity_Value | |
166 | + */ | |
167 | +char* temp_humidity_value(uint16_t temp /*! Numeric value */, uint16_t humidity /*! Numeric value */); | |
89 | 168 | |
90 | 169 | //SOUND SENSOR |
91 | - | |
170 | +//! Sound sensor intialization function | |
171 | +/*! This function intializes the sound ADC channel. */ | |
92 | 172 | void init_sound(void); |
173 | +//! Sound ADC data sampling function | |
174 | +/*! This function takes a sample from the sound ADC channel and returns the numeric value. */ | |
93 | 175 | uint32_t get_sound_data(void); |
94 | -char* sound_value(uint32_t sound); | |
176 | +//! Sound sensor data parsing function | |
177 | +/*! This function takes the sound pressure level numeric value from get_battery_data and returns a string to be timestamped and sent to the server. */ | |
178 | +char* sound_value(uint32_t sound /*! Numeric value */); | |
95 | 179 | |
96 | 180 | //BATTERY SENSOR |
97 | - | |
181 | +//! Battery sensor intialization function. | |
182 | +/*! This function intializes the battery ADC channel */ | |
98 | 183 | void init_battery(void); |
184 | +//! Battery ADC data sampling function. | |
185 | +/*! This function takes a sample from the battery ADC channel and returns the numeric value */ | |
99 | 186 | uint32_t get_battery_data(void); |
100 | -char* battery_value(uint32_t battery); | |
187 | +//! Battery sensor data parsing function | |
188 | +/*! This function takes the battery level numeric value from get_battery_data and returns a string to be timestamped and sent to the server. */ | |
189 | +char* battery_value(uint32_t battery /*! Numeric value */); | |
101 | 190 | |
102 | 191 | //Collect function |
103 | -void collectData(char* valueSensors[], uint8_t* sensors); | |
192 | +//! Data fetching function | |
193 | +/*! Polls every one of the currently connected sensors for data. | |
194 | + * <br>NOTE: This routine is dependant on the sensors programmed and MUST be updated everytime a new sensor is programmed in this file. | |
195 | + */ | |
196 | +void collectData(char* valueSensors[] /*! Output array for each one of the sensors that are passed by argument*/, uint8_t* sensors /*! Sensors where data has to be collected from */); | |
104 | 197 | |
105 | 198 | #endif | ... | ... |