|
23 | 23 | #include <string.h>
|
24 | 24 |
|
25 | 25 | #include <platform.h>
|
26 |
| -#include "build/build_config.h" |
27 |
| - |
28 | 26 |
|
29 | 27 | #ifdef USE_RX_SYMA
|
30 | 28 |
|
| 29 | +#include "build/build_config.h" |
| 30 | + |
31 | 31 | #include "drivers/rx_nrf24l01.h"
|
32 | 32 | #include "drivers/system.h"
|
33 | 33 |
|
|
54 | 54 | * uses address received in bind packets
|
55 | 55 | * hops between 4 channels generated from address received in bind packets
|
56 | 56 | *
|
57 |
| - * SymaX5 Protocol |
| 57 | + * SymaX5C Protocol |
58 | 58 | * No auto acknowledgment
|
59 | 59 | * Payload size is 16, static
|
60 | 60 | * Data rate is 1Mbps
|
@@ -222,47 +222,42 @@ static void setSymaXHoppingChannels(uint32_t addr)
|
222 | 222 | }
|
223 | 223 | }
|
224 | 224 |
|
225 |
| -static void symaSetBound(const uint8_t* rxTxAddr) |
226 |
| -{ |
227 |
| - protocolState = STATE_DATA; |
228 |
| - // using protocol NRF24L01_SYMA_X, since NRF24L01_SYMA_X5C went straight into data mode |
229 |
| - // set the hopping channels as determined by the rxTxAddr received in the bind packet |
230 |
| - setSymaXHoppingChannels(rxTxAddr[0]); |
231 |
| - timeOfLastHop = micros(); |
232 |
| - packetCount = 0; |
233 |
| - // set the NRF24 to use the rxTxAddr received in the bind packet |
234 |
| - NRF24L01_WriteRegisterMulti(NRF24L01_0A_RX_ADDR_P0, rxTxAddr, RX_TX_ADDR_LEN); |
235 |
| - symaRfChannelIndex = 0; |
236 |
| - NRF24L01_SetChannel(symaRfChannels[0]); |
237 |
| -} |
238 |
| - |
239 | 225 | /*
|
240 | 226 | * This is called periodically by the scheduler.
|
241 | 227 | * Returns NRF24_RECEIVED_DATA if a data packet was received.
|
242 | 228 | */
|
243 | 229 | nrf24_received_t symaNrf24DataReceived(uint8_t *payload)
|
244 | 230 | {
|
245 | 231 | nrf24_received_t ret = NRF24_RECEIVED_NONE;
|
246 |
| - uint32_t timeNowUs; |
| 232 | + |
247 | 233 | switch (protocolState) {
|
248 | 234 | case STATE_BIND:
|
249 | 235 | if (NRF24L01_ReadPayloadIfAvailable(payload, payloadSize)) {
|
250 | 236 | const bool bindPacket = symaCheckBindPacket(payload);
|
251 | 237 | if (bindPacket) {
|
252 | 238 | ret = NRF24_RECEIVED_BIND;
|
253 |
| - symaSetBound(rxTxAddr); |
| 239 | + protocolState = STATE_DATA; |
| 240 | + // using protocol NRF24L01_SYMA_X, since NRF24L01_SYMA_X5C went straight into data mode |
| 241 | + // set the hopping channels as determined by the rxTxAddr received in the bind packet |
| 242 | + setSymaXHoppingChannels(rxTxAddr[0]); |
| 243 | + // set the NRF24 to use the rxTxAddr received in the bind packet |
| 244 | + NRF24L01_WriteRegisterMulti(NRF24L01_0A_RX_ADDR_P0, rxTxAddr, RX_TX_ADDR_LEN); |
| 245 | + packetCount = 0; |
| 246 | + symaRfChannelIndex = 0; |
| 247 | + NRF24L01_SetChannel(symaRfChannels[0]); |
254 | 248 | }
|
255 | 249 | }
|
256 | 250 | break;
|
257 | 251 | case STATE_DATA:
|
258 | 252 | // read the payload, processing of payload is deferred
|
259 | 253 | if (NRF24L01_ReadPayloadIfAvailable(payload, payloadSize)) {
|
| 254 | + symaHopToNextChannel(); |
| 255 | + timeOfLastHop = micros(); |
260 | 256 | ret = NRF24_RECEIVED_DATA;
|
261 | 257 | }
|
262 |
| - timeNowUs = micros(); |
263 |
| - if ((ret == NRF24_RECEIVED_DATA) || (timeNowUs > timeOfLastHop + hopTimeout)) { |
| 258 | + if (micros() > timeOfLastHop + hopTimeout) { |
264 | 259 | symaHopToNextChannel();
|
265 |
| - timeOfLastHop = timeNowUs; |
| 260 | + timeOfLastHop = micros(); |
266 | 261 | }
|
267 | 262 | break;
|
268 | 263 | }
|
|
0 commit comments