Commit 36268163fe19db2e49ef4a408f0b2be1960518bd

Authored by Imanol-Mikel Barba Sabariego
1 parent 4115cac3

--no commit message

Project/applications/smartcities/i2c.c
... ... @@ -3,7 +3,7 @@
3 3  
4 4 void I2C_init(void)
5 5 {
6   - DBG_I2C("Initializing I2C...\r\n");
  6 + //DBG_I2C("Initializing I2C...\r\n");
7 7 GPIO_InitTypeDef GPIO_InitStruct;
8 8 I2C_InitTypeDef I2C_InitStruct;
9 9  
... ... @@ -30,21 +30,21 @@ void I2C_init(void)
30 30  
31 31 void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction)
32 32 {
33   - DBG_I2C("Sending I2C Start...\r\n");
  33 + //DBG_I2C("Sending I2C Start...\r\n");
34 34 while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY))
35 35 {
36 36 // wait until I2C1 is not busy any more
37 37 }
38   - DBG_I2C("I2C ready\r\n");
  38 + //DBG_I2C("I2C ready\r\n");
39 39 I2C_GenerateSTART(I2Cx, ENABLE);
40   - DBG_I2C("Start sent\r\n");
  40 + //DBG_I2C("Start sent\r\n");
41 41 while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT))
42 42 {
43 43 // wait for I2C1 EV5 --> Slave has acknowledged start condition
44 44 }
45   - DBG_I2C("Start ACK\r\n");
  45 + //DBG_I2C("Start ACK\r\n");
46 46 I2C_Send7bitAddress(I2Cx, address, direction);
47   - DBG_I2C("Master -> Slave Address and R/W sent\r\n");
  47 + //DBG_I2C("Master -> Slave Address and R/W sent\r\n");
48 48 if(direction == I2C_Direction_Transmitter)
49 49 {
50 50 while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
... ... @@ -59,21 +59,21 @@ void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction)
59 59 // wait for I2Cx EV6, check if Slave has acknowledged Master receiver mode
60 60 }
61 61 }
62   - DBG_I2C("Slave -> Master ACK\r\n");
  62 + //DBG_I2C("Slave -> Master ACK\r\n");
63 63 }
64 64  
65 65 void I2C_restart(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction)
66 66 {
67   - DBG_I2C("Sending repeated I2C Start...\r\n");
  67 + //DBG_I2C("Sending repeated I2C Start...\r\n");
68 68 I2C_GenerateSTART(I2Cx, ENABLE);
69   - DBG_I2C("Start sent\r\n");
  69 + //DBG_I2C("Start sent\r\n");
70 70 while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT))
71 71 {
72 72 // wait for I2C1 EV5 --> Slave has acknowledged start condition
73 73 }
74   - DBG_I2C("Start ACK\r\n");
  74 + //DBG_I2C("Start ACK\r\n");
75 75 I2C_Send7bitAddress(I2Cx, address, direction);
76   - DBG_I2C("Master -> Slave Address and R/W sent\r\n");
  76 + //DBG_I2C("Master -> Slave Address and R/W sent\r\n");
77 77 if(direction == I2C_Direction_Transmitter)
78 78 {
79 79 while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
... ... @@ -88,51 +88,51 @@ void I2C_restart(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction)
88 88 // wait for I2Cx EV6, check if Slave has acknowledged Master receiver mode
89 89 }
90 90 }
91   - DBG_I2C("Slave -> Master ACK\r\n");
  91 + //DBG_I2C("Slave -> Master ACK\r\n");
92 92 }
93 93  
94 94 void I2C_write(I2C_TypeDef* I2Cx, uint8_t data)
95 95 {
96   - DBG_I2C("Sending I2C byte %02x...\r\n",data);
  96 + //DBG_I2C("Sending I2C byte %02x...\r\n",data);
97 97 I2C_SendData(I2Cx, data);
98 98 while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
99 99 {
100 100 // wait for I2C1 EV8_2 --> last byte is transmitted
101 101 }
102   - DBG_I2C("Data sent\r\n");
  102 + //DBG_I2C("Data sent\r\n");
103 103 }
104 104  
105 105 uint8_t I2C_read_ack(I2C_TypeDef* I2Cx)
106 106 {
107   - DBG_I2C("Listening for byte in I2C (ACK)\r\n");
  107 + //DBG_I2C("Listening for byte in I2C (ACK)\r\n");
108 108 I2C_AcknowledgeConfig(I2Cx, ENABLE);
109 109 while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED))
110 110 {
111 111 // wait until one byte has been received
112 112 }
113 113 uint8_t data = I2C_ReceiveData(I2Cx);
114   - DBG_I2C("Received byte: %02x\r\n",data);
  114 + //DBG_I2C("Received byte: %02x\r\n",data);
115 115 return data;
116 116 }
117 117  
118 118 uint8_t I2C_read_nack(I2C_TypeDef* I2Cx)
119 119 {
120   - DBG_I2C("Listening for byte in I2C (NACK)\r\n");
  120 + //DBG_I2C("Listening for byte in I2C (NACK)\r\n");
121 121 I2C_AcknowledgeConfig(I2Cx, DISABLE);
122 122 while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED))
123 123 {
124 124 // wait until one byte has been received
125 125 }
126 126 uint8_t data = I2C_ReceiveData(I2Cx);
127   - DBG_I2C("Received byte: %02x\r\n",data);
  127 + //DBG_I2C("Received byte: %02x\r\n",data);
128 128 return data;
129 129 }
130 130  
131 131 void I2C_stop(I2C_TypeDef* I2Cx)
132 132 {
133   - DBG_I2C("Sending I2C Stop...\r\n");
  133 + //DBG_I2C("Sending I2C Stop...\r\n");
134 134 I2C_GenerateSTOP(I2Cx, ENABLE);
135   - DBG_I2C("Stop sent\r\n");
  135 + //DBG_I2C("Stop sent\r\n");
136 136 }
137 137  
138 138 uint8_t I2C_check(I2C_TypeDef* I2Cx, uint8_t address)
... ... @@ -146,14 +146,14 @@ uint8_t I2C_check(I2C_TypeDef* I2Cx, uint8_t address)
146 146 {
147 147 // wait for I2C1 EV5 --> Slave has acknowledged start condition
148 148 }
149   - DBG_I2C("Probing address %x ...\r\n",address);
  149 + //DBG_I2C("Probing address %x ...\r\n",address);
150 150 I2C_Send7bitAddress(I2Cx, address, I2C_Direction_Transmitter);
151 151 chThdSleepMilliseconds(I2C_TIMEOUT);
152 152 if(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
153 153 {
154 154 return 1;
155 155 }
156   - DBG_I2C("I2C address detected: %x\r\n", address);
  156 + //DBG_I2C("I2C address detected: %x\r\n", address);
157 157 I2C_write(I2Cx,0x00);
158 158 I2C_stop(I2Cx);
159 159 return 0;
... ... @@ -161,7 +161,7 @@ uint8_t I2C_check(I2C_TypeDef* I2Cx, uint8_t address)
161 161  
162 162 void I2C_reset(I2C_TypeDef* I2Cx)
163 163 {
164   - DBG_I2C("Resetting I2C...\r\n");
  164 + //DBG_I2C("Resetting I2C...\r\n");
165 165 I2C_SoftwareResetCmd(I2Cx, ENABLE);
166 166 I2C_DeInit(I2Cx);
167 167 I2C_init();
... ... @@ -170,7 +170,7 @@ void I2C_reset(I2C_TypeDef* I2Cx)
170 170  
171 171 void I2C_scan(I2C_TypeDef* I2Cx,uint8_t *addresses)
172 172 {
173   - DBG_I2C("Scanning sensors...\r\n");
  173 + //DBG_I2C("Scanning sensors...\r\n");
174 174 uint8_t i, j = 0;
175 175 I2C_init();
176 176 for(i = 0; i < TOTAL_SENSORS; i++)
... ...
Project/applications/smartcities/json.c
... ... @@ -10,7 +10,6 @@ uint8_t register_sensor(sensor sens)
10 10 DBG_JSON("Putting additional info for pressure sensor...\r\n");
11 11 bmp085_callibration_t calib_data;
12 12 get_pressure_callibration_data(&calib_data);
13   - DBG_JSON("Got callibration data\r\n");
14 13 char *callibration_data = callibration_pressure_data_csv(&calib_data);
15 14 DBG_JSON("callibration_data is: %s\r\n",callibration_data);
16 15 statement = prepare_json_register_statement(mod,sens,callibration_data);
... ... @@ -97,13 +96,14 @@ char* prepare_json_register_statement(module mod, sensor sens, char *additional_
97 96  
98 97 char* prepare_observation(char* observation, uint32_t length)
99 98 {
  99 + DBG_JSON("Preparing: %s with length %d\r\n",observation,length);
100 100 char *json_data, *str_aux, *str_aux2;
101 101 int value_length = find_next_index(observation,length,',');
102 102 while(1)
103 103 {
104   - if(find_next_index(observation+value_length+1,length,','))
  104 + if(find_next_index(observation+value_length+1,length-value_length,','))
105 105 {
106   - value_length += find_next_index(observation+value_length+1,length,',')+1;
  106 + value_length += find_next_index(observation+value_length+1,length-value_length,',')+1;
107 107 }
108 108 else
109 109 {
... ...
Project/applications/smartcities/main.c
... ... @@ -235,6 +235,7 @@ int main(void)
235 235 }
236 236  
237 237 DBG("%c[1;35m--------------WI-SENSE STARTED-------------%c[1;00m\r\n",0x1B,0x1B);
  238 +
238 239 wifi_connect();
239 240 check_memory();
240 241  
... ...
Project/applications/smartcities/sensors.c
... ... @@ -114,22 +114,16 @@ uint16_t get_light_ch0(void)
114 114 uint16_t data = 0;
115 115  
116 116 I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter);
117   - I2C_write(I2C1, 0x8C);
  117 + I2C_write(I2C1, 0xAC);
118 118 DBG_SENSORS("[LIGHT] Sent fetch command for CH0\r\n");
119 119  
120 120 I2C_restart(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver);
121   - data = I2C_read_nack(I2C1);
122   - I2C_stop(I2C1);
  121 + data = I2C_read_ack(I2C1);
123 122 DBG_SENSORS("[LIGHT] Got low byte for CH0\r\n");
124   -
125   - I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter);
126   - I2C_write(I2C1, 0x8D);
127   -
128   - I2C_restart(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver);
129 123 data = data | (I2C_read_nack(I2C1) << 8);
130   - I2C_stop(I2C1);
131 124 DBG_SENSORS("[LIGHT] Got high byte for CH0\r\n");
132   -
  125 + I2C_stop(I2C1);
  126 +
133 127 return data;
134 128 }
135 129 uint16_t get_light_ch1(void)
... ... @@ -141,18 +135,12 @@ uint16_t get_light_ch1(void)
141 135 DBG_SENSORS("[LIGHT] Sent fetch command for CH1\r\n");
142 136  
143 137 I2C_restart(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver);
144   - data = I2C_read_nack(I2C1);
145   - I2C_stop(I2C1);
  138 + data = I2C_read_ack(I2C1);
146 139 DBG_SENSORS("[LIGHT] Got low byte for CH1\r\n");
147   -
148   - I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter);
149   - I2C_write(I2C1, 0x8F);
150   -
151   - I2C_restart(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver);
152 140 data = data | (I2C_read_nack(I2C1) << 8);
153   - I2C_stop(I2C1);
154 141 DBG_SENSORS("[LIGHT] Got high byte for CH1\r\n");
155   -
  142 + I2C_stop(I2C1);
  143 +
156 144 return data;
157 145 }
158 146  
... ...