183 return STATE_PAYLOAD; |
183 return STATE_PAYLOAD; |
184 } |
184 } |
185 |
185 |
186 HPSerial::state_t HPSerial::do_state_sending(uint8_t c) |
186 HPSerial::state_t HPSerial::do_state_sending(uint8_t c) |
187 { |
187 { |
188 // ghee |
188 // check the ack value returned by the main unit |
189 if (c == 0xFF) |
189 |
|
190 if ((tr_data.pos == 1) && (tr_data.payload[0] == 0x66)) |
|
191 { |
|
192 if (c != 0x99) |
|
193 { |
|
194 //::printf("ACK ERROR %X [exp. %X]\n", c, ~(tr_data.payload[0])); |
|
195 // did not received the expected ack |
|
196 if (c == 0x66) |
|
197 { |
|
198 // we received a start of transmission while trying to emit something, |
|
199 // ignore it, the correct ack should be sent but the main unit just behind... |
|
200 set_timer(RXTIMEOUT); |
|
201 return cur_state; |
|
202 } |
|
203 else |
|
204 { |
|
205 // not sure how this may happen, in doubt, try again |
|
206 tr_data.pos--; |
|
207 } |
|
208 } |
|
209 } |
|
210 /* |
|
211 else if (c != 0x00) |
190 { // resend current char |
212 { // resend current char |
191 tr_data.pos--; |
213 tr_data.pos--; |
192 } |
214 } |
|
215 */ |
|
216 |
193 // TODO: check ACK values (c is the received ack) |
217 // TODO: check ACK values (c is the received ack) |
194 if (tr_data.pos >= tr_data.size) |
218 if (tr_data.pos >= tr_data.size) |
195 { |
219 { |
196 c = 0x55; |
220 c = 0x55; |
197 serial.write(&c, 1); // EoT |
221 serial.write(&c, 1); // EoT |