Commit 8e217da719be35ffebbe61711ab683f9c2a3344e
1 parent
3813a6db
--no commit message
Showing
4 changed files
with
99 additions
and
19 deletions
Project/applications/smartcities/include/adc.h
Project/applications/smartcities/include/buffer.h
1 | + | ||
2 | +/**@file | ||
3 | + * @brief Declaration for the internal buffer and memory management | ||
4 | + * @author Maria Jorba Brosa | ||
5 | + * @date 08/06/2014 | ||
6 | + * | ||
7 | + * The functions declared in this file manage the I2C functionality of the device to use with the sensors | ||
8 | + */ | ||
9 | + | ||
1 | #ifndef BUFFER_H | 10 | #ifndef BUFFER_H |
2 | #define BUFFER_H | 11 | #define BUFFER_H |
3 | 12 | ||
4 | #include "libwismart.h" | 13 | #include "libwismart.h" |
5 | #include "json.h" | 14 | #include "json.h" |
6 | 15 | ||
16 | +//!Soft limit definition | ||
17 | +/*! This variable defines at which point the soft limit for used memory is reached. The specified value is used memory bytes. */ | ||
7 | #define SOFT_LIMIT 8192 /* en bytes -> 8k * 1024 */ | 18 | #define SOFT_LIMIT 8192 /* en bytes -> 8k * 1024 */ |
19 | + //!Hard limit definition | ||
20 | +/*! This variable defines at which point the hard limit for used memory is reached. The specified value is used memory bytes.*/ | ||
8 | #define HARD_LIMIT 10240 | 21 | #define HARD_LIMIT 10240 |
22 | + | ||
23 | +//! Memory OK status definition | ||
9 | #define MEMORY_OK 0 | 24 | #define MEMORY_OK 0 |
25 | +//! Soft limit status definition | ||
10 | #define SOFT_REACHED 1 | 26 | #define SOFT_REACHED 1 |
27 | +//! Hard limit status definition | ||
11 | #define HARD_REACHED 2 | 28 | #define HARD_REACHED 2 |
12 | 29 | ||
30 | +//! Debug printing definition | ||
31 | +/*! This definition is used for debugging purposes, it is a shorthand for printing debug information */ | ||
13 | #define DBG_BUFFER(fmt,...) printf("%c[1;35mbuffer.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) | 32 | #define DBG_BUFFER(fmt,...) printf("%c[1;35mbuffer.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) |
14 | //#define DBG_BUFFER(fmt,...) printf("") | 33 | //#define DBG_BUFFER(fmt,...) printf("") |
15 | 34 | ||
16 | -char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len); | 35 | +//! Value write into buffer function |
36 | +/*! This function stores data into a memory buffer. It frees the memory of the old one, which is passed by argument, and returns a new one with the value stored. */ | ||
37 | +char** put_message(char* info /*! Data to be stored */, char** buf /*! Old buffer */ ,uint32_t *index /*! Buffer index to store the data */, uint32_t *buf_len /*! Old buffer length */); | ||
38 | + | ||
39 | +//! Memory check function | ||
40 | +/*! This function checks the current used memory and returns the memory status definitions according to the amount of memory used. */ | ||
17 | int check_memory(void); | 41 | int check_memory(void); |
18 | -int send(char** buf, uint32_t *index, uint32_t *size, char *provider_ID, char *sensor_ID); | ||
19 | -char** join_buf(char** buf, uint32_t *buf_len); | 42 | + |
43 | +//! Buffer data send function | ||
44 | +/*! This function sends the data in a specified buffer to the server. If successful, it frees the memory used by it. */ | ||
45 | +int send(char** buf /*! Buffer to send */, uint32_t *index /*! Current buffer index */, uint32_t *size /*! Buffer size */, char *provider_ID /*! Current module ID */, char *sensor_ID /*! Sensor ID for the data stored in that buffer */); | ||
46 | + | ||
47 | +//! Buffer join function | ||
48 | +/*! This function returns a copy of the buffer passed by argument with one more slot to store another piece of data from the sensors */ | ||
49 | +char** join_buf(char** buf /*! Old buffer */, uint32_t *buf_len /*! Old buffer length*/); | ||
20 | 50 | ||
21 | #endif | 51 | #endif |
22 | \ No newline at end of file | 52 | \ No newline at end of file |
Project/applications/smartcities/include/i2c.h
1 | + | ||
2 | +/**@file | ||
3 | + * @brief Declaration for the I2C functionality | ||
4 | + * @author Imanol Barba Sabariego | ||
5 | + * @date 08/06/2014 | ||
6 | + * | ||
7 | + * The functions declared in this file manage the I2C functionality of the device to use with the sensors | ||
8 | + */ | ||
9 | + | ||
1 | #ifndef I2C_H | 10 | #ifndef I2C_H |
2 | #define I2C_H | 11 | #define I2C_H |
3 | 12 | ||
@@ -7,22 +16,54 @@ | @@ -7,22 +16,54 @@ | ||
7 | #include "sensors.h" | 16 | #include "sensors.h" |
8 | #include "libwismart.h" | 17 | #include "libwismart.h" |
9 | 18 | ||
19 | +//! I2C Response timeout | ||
20 | +/*! This variable defines how many milliseconds will the device without obtaining answer from the bus until it considers that there is no I2C device in the address being polled. */ | ||
10 | #define I2C_TIMEOUT 100 | 21 | #define I2C_TIMEOUT 100 |
11 | 22 | ||
23 | +//! Debug printing definition | ||
24 | +/*! This definition is used for debugging purposes, it is a shorthand for printing debug information */ | ||
12 | #define DBG_I2C(fmt,...) printf("%c[1;35mi2c.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) | 25 | #define DBG_I2C(fmt,...) printf("%c[1;35mi2c.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) |
13 | //#define DBG_I2C(fmt,...) printf("") | 26 | //#define DBG_I2C(fmt,...) printf("") |
14 | 27 | ||
15 | - | 28 | +//! I2C initialization function |
29 | +/*! This function initializes the I2C bus in use for the sensors, which is I2C1, at a hardware level. */ | ||
16 | void I2C_init(void); | 30 | void I2C_init(void); |
17 | -void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction); | ||
18 | -void I2C_stop(I2C_TypeDef* I2Cx); | ||
19 | -void I2C_write(I2C_TypeDef* I2Cx, uint8_t data); | ||
20 | -uint8_t I2C_read_ack(I2C_TypeDef* I2Cx); | ||
21 | -uint8_t I2C_read_nack(I2C_TypeDef* I2Cx); | ||
22 | -void I2C_scan(I2C_TypeDef* I2Cx,uint8_t *addresses); | ||
23 | -uint8_t I2C_check(I2C_TypeDef* I2Cx, uint8_t address); | ||
24 | -void I2C_reset(I2C_TypeDef* I2Cx); | ||
25 | -void I2C_restart(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction); | 31 | + |
32 | +//! I2C comunication Start function | ||
33 | +/*! This function generates a START sequence in the I2C bus and sends the 7 bit address passed in the arguments along with the R/W bit. */ | ||
34 | +void I2C_start(I2C_TypeDef* I2Cx /*! I2C device to use */, uint8_t address /*! I2C slave address */, uint8_t direction /*! R/W bit. Possible values are I2C_Direction_Transmitter and I2C_Direction_Receiver */); | ||
35 | + | ||
36 | +//! I2C communication Stop function | ||
37 | +/*! This function generaates a STOP sequence in the I2C bus, stopping the communication between master and slave */ | ||
38 | +void I2C_stop(I2C_TypeDef* I2Cx /*! I2C device to use */); | ||
39 | + | ||
40 | +//! I2C write byte function | ||
41 | +/*! This function writes a byte into the bus using the specified I2C device */ | ||
42 | +void I2C_write(I2C_TypeDef* I2Cx /*! I2C device to use */, uint8_t data /*! Byte to write */); | ||
43 | + | ||
44 | +//! I2C read byte function (with master ACK) | ||
45 | +/*! This function fetches a byte from the I2C bus that has been stored into the internal register and sends and ACK afterwards. */ | ||
46 | +uint8_t I2C_read_ack(I2C_TypeDef* I2Cx /*! I2C device to use */); | ||
47 | + | ||
48 | +//! I2C read byte function (without master ACK) | ||
49 | +/*! This function fetches a byte from the I2C bus that has been stored into the internal register without sending and ACK afterwards. */ | ||
50 | +uint8_t I2C_read_nack(I2C_TypeDef* I2Cx /*! I2C device to use */); | ||
51 | + | ||
52 | +//! I2C bus scan function | ||
53 | +/*! This function scans the I2C bus in search of known sensor addresses and returns them in the addresses array passed by argument. */ | ||
54 | +void I2C_scan(I2C_TypeDef* I2Cx /*! I2C device to use */,uint8_t *addresses /*! Array to be filled */); | ||
55 | + | ||
56 | +//! I2C presence check function | ||
57 | +/*! This function checks a specified address to see if there are any slave devices listening. */ | ||
58 | +uint8_t I2C_check(I2C_TypeDef* I2Cx /*! I2C device to use */, uint8_t address /*! Address to check */); | ||
59 | + | ||
60 | +//! I2C bus reset function | ||
61 | +/*! This function resets the I2C bus in case that a timeout occurred, pulling both lines up and resetting the internal registers to a known state. */ | ||
62 | +void I2C_reset(I2C_TypeDef* I2Cx /*! I2C device to reset */); | ||
63 | + | ||
64 | +//! I2C communication repeated Start function | ||
65 | +/*! This function sends a repeated START sequence (a START sequence for which no previous STOP sequence was sent). */ | ||
66 | +void I2C_restart(I2C_TypeDef* I2Cx /*! I2C device to use */, uint8_t address /*! I2C slave address */, uint8_t direction /*! R/W bit. Possible values are I2C_Direction_Transmitter and I2C_Direction_Receiver */); | ||
26 | 67 | ||
27 | 68 | ||
28 | #endif | 69 | #endif |
Project/applications/smartcities/main.c
1 | + | ||
2 | +/**@file | ||
3 | + * @brief Main loop and global functions and variables | ||
4 | + * @author Imanol Barba Sabariego, Ferràn Quer i Guerrero, Maria Jorba Brosa, Emilio Soca Herrera | ||
5 | + * @date 08/06/2014 | ||
6 | + * | ||
7 | + * This file holds the main function, which contains the main loop itself and necessary global functions and variables used to manage the state of the device. | ||
8 | + */ | ||
9 | + | ||
1 | #include <string.h> | 10 | #include <string.h> |
2 | #include "libwismart.h" | 11 | #include "libwismart.h" |
3 | #include "libwismart_irqs.h" /* implement irq handlers */ | 12 | #include "libwismart_irqs.h" /* implement irq handlers */ |
@@ -12,6 +21,7 @@ | @@ -12,6 +21,7 @@ | ||
12 | #include "ntp.h" | 21 | #include "ntp.h" |
13 | #include "sensors.h" | 22 | #include "sensors.h" |
14 | 23 | ||
24 | +//! Debug printing definition | ||
15 | /*! This definition is used for debugging purposes, it is a shorthand for printing debug information */ | 25 | /*! This definition is used for debugging purposes, it is a shorthand for printing debug information */ |
16 | #define DBG(fmt,...) printf("%c[1;35mmain.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) | 26 | #define DBG(fmt,...) printf("%c[1;35mmain.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) |
17 | //#define DBG(fmt,...) printf("") | 27 | //#define DBG(fmt,...) printf("") |
@@ -52,7 +62,7 @@ void initLibwismart(void) | @@ -52,7 +62,7 @@ void initLibwismart(void) | ||
52 | 62 | ||
53 | //! NTP time update function | 63 | //! NTP time update function |
54 | /*! This function is called upon NTP update request and uses the methods declared in ntp.h to do so. */ | 64 | /*! This function is called upon NTP update request and uses the methods declared in ntp.h to do so. */ |
55 | -void update_time(unsigned long *time) | 65 | +void update_time(unsigned long *time /*! Variable to store the new time */) |
56 | { | 66 | { |
57 | do | 67 | do |
58 | { | 68 | { |
@@ -136,7 +146,7 @@ void init_registry(void) | @@ -136,7 +146,7 @@ void init_registry(void) | ||
136 | 146 | ||
137 | //! Function to send data to the server | 147 | //! Function to send data to the server |
138 | /*! This function sends all the data in the memory to the server */ | 148 | /*! This function sends all the data in the memory to the server */ |
139 | -void send_data(char** buffers[], uint32_t ind[], uint32_t sizes[], uint8_t sensors[]) | 149 | +void send_data(char** buffers[] /*! Array of in-memory buffers containing the data */, uint32_t ind[] /*! Buffer indexes */ , uint32_t sizes[] /*! Buffer sizes */, uint8_t sensors[] /*! Array of sensors addresses currently connected to the device */) |
140 | { | 150 | { |
141 | int j; | 151 | int j; |
142 | for(j=0;j<sensors_length;j++) | 152 | for(j=0;j<sensors_length;j++) |
@@ -150,7 +160,7 @@ void send_data(char** buffers[], uint32_t ind[], uint32_t sizes[], uint8_t senso | @@ -150,7 +160,7 @@ void send_data(char** buffers[], uint32_t ind[], uint32_t sizes[], uint8_t senso | ||
150 | 160 | ||
151 | //! Buffer data insertion function | 161 | //! Buffer data insertion function |
152 | /*! This function inserts processed data in the memory */ | 162 | /*! This function inserts processed data in the memory */ |
153 | -void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked, uint8_t* sensors) | 163 | +void put_buffers(char** buffers[],/*! Array of in-memory buffers containing the data */, uint32_t ind[] /*! Buffer indexes */ , uint32_t sizes[] /*! Buffer sizes */,char** cooked /*! Array of processed data from the sensors */, uint8_t* sensors /*! Array of sensors addresses currently connected to the device */) |
154 | { | 164 | { |
155 | DBG("Putting data in buffers...\r\n"); | 165 | DBG("Putting data in buffers...\r\n"); |
156 | int i; | 166 | int i; |
@@ -168,7 +178,7 @@ void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked, | @@ -168,7 +178,7 @@ void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked, | ||
168 | 178 | ||
169 | //! Data timestamping function | 179 | //! Data timestamping function |
170 | /*! This function timestamps de collected data using the methods defined in ntp.h */ | 180 | /*! This function timestamps de collected data using the methods defined in ntp.h */ |
171 | -char** timestamp_datas(char* value[],unsigned long timestamp, uint8_t* sensors) | 181 | +char** timestamp_datas(char* value[] /*! Raw data collected from the sensors */,unsigned long timestamp /* Current timestamp to add to the measurements*/, uint8_t* sensors /*! Array of sensors addresses currently connected to the device */) |
172 | { | 182 | { |
173 | DBG("Timestamping data...\r\n"); | 183 | DBG("Timestamping data...\r\n"); |
174 | char** cooked_data; | 184 | char** cooked_data; |
@@ -206,7 +216,7 @@ void wifi_connect(void) | @@ -206,7 +216,7 @@ void wifi_connect(void) | ||
206 | 216 | ||
207 | //! Battery reporting function | 217 | //! Battery reporting function |
208 | /*! This function checks the battery level and sends it to the server */ | 218 | /*! This function checks the battery level and sends it to the server */ |
209 | -void send_battery_level(unsigned long timestamp) | 219 | +void send_battery_level(unsigned long timestamp /*! Current timestamp to add to the battery level measurement */) |
210 | { | 220 | { |
211 | DBG("Polling battery level...\r\n"); | 221 | DBG("Polling battery level...\r\n"); |
212 | char *batt_level = battery_value(get_battery_data()); | 222 | char *batt_level = battery_value(get_battery_data()); |