![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
LP Long Distance IR Vision Robot
Dependencies: max77650_charger_sample BufferedSerial SX1276GenericLib Adafruit-MotorShield NEO-6m-GPS MAX17055_EZconfig Adafruit_GFX USBDeviceHT Adafruit-PWM-Servo-Driver
Diff: SX1276GenericPingPong/GenericPingPong.cpp
- Revision:
- 28:0ed92c590607
- Parent:
- 27:6b549f838f0a
- Child:
- 32:b108ed6096b0
--- a/SX1276GenericPingPong/GenericPingPong.cpp Fri Jul 20 21:29:53 2018 +0000 +++ b/SX1276GenericPingPong/GenericPingPong.cpp Mon Jul 23 23:39:35 2018 +0000 @@ -88,13 +88,14 @@ SX1276Generic *Radio; -uint8_t * BufferTxAlias; -uint8_t * BufferRxAlias; +// Aliases for the buffers that are made in the main() +uint8_t *BufferTx; +uint8_t *BufferRx; DigitalOut *led3; -int SX1276PingPongSetup(uint8_t * PointerToBufferTx, uint8_t * PointerToBufferRx) +int SX1276PingPongSetup(uint8_t *BufferTxFromMain, uint8_t *BufferRxFromMain) { dprintf("TEST" ); #if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) ) @@ -107,13 +108,8 @@ led3 = led; #endif - /* Store aliases of pointers that were passed in that are pointeres to buffers that - * exist in the main program. The BufferTx is used in the SX1276PingPong function below - * when sending a buffer to the other microcontroller. The BufferRx is what holds - * data from a message that is received. - */ - BufferTxAlias = PointerToBufferTx; - BufferRxAlias = PointerToBufferRx; + BufferTx = BufferTxFromMain; + BufferRx = BufferRxFromMain; *led3 = 1; #ifdef B_L072Z_LRWAN1_LORA @@ -221,7 +217,6 @@ Radio->Rx( RX_TIMEOUT_VALUE ); - } /**************************************************************************************************************************************** @@ -238,12 +233,12 @@ switch( State ) { case RX: - *led3 = 0; +// *led3 = 0; if( isMaster == true ) { if( BufferSizeRx > 0 ) { - if( memcmp(&BufferRxAlias[rx_idx_signature], PongMsg, sizeof(PongMsg)) == 0 ) + if( memcmp(&BufferRx[rx_idx_signature], PongMsg, sizeof(PongMsg)) == 0 ) { // *led = !*led; dprintf( "...Pong" ); @@ -257,9 +252,9 @@ } */ /* Construct the payload buffer so data can be transmited. */ - fillPayloadWithGlobalBufs(); +// fillPayloadWithGlobalBufs(BufferTx); wait_ms( 10 ); - Radio->Send( BufferTxAlias, BufferSizeTx ); + Radio->Send( BufferTx, BufferSizeTx ); } /* else if( memcmp(Buffer, PingMsg, sizeof(PingMsg)) == 0 ) { // A master already exists then become a slave @@ -288,7 +283,7 @@ { if( BufferSizeRx > 0 ) { - if( memcmp(BufferRxAlias, PingMsg, sizeof(PingMsg)) == 0 ) + if( memcmp(BufferRx, PingMsg, sizeof(PingMsg)) == 0 ) { // *led = !*led; dprintf( "...Ping" ); @@ -301,9 +296,9 @@ BufferTx[i] = i - sizeof(PongMsg); } */ - //fillPayloadWithGlobalBufs(BufferTx); + // fillPayloadWithGlobalBufs(BufferTx); wait_ms( 10 ); - Radio->Send( BufferTxAlias, BufferSizeTx ); + Radio->Send( BufferTx, BufferSizeTx ); } else // valid reception but not a PING as expected { // Set device as master and start again @@ -315,7 +310,7 @@ State = LOWPOWER; break; case TX: - *led3 = 1; +// *led3 = 1; if( isMaster == true ) { dprintf("Ping..." ); @@ -338,9 +333,9 @@ BufferTx[i] = i - sizeof(PingMsg); } */ - fillPayloadWithGlobalBufs(); + fillPayloadWithGlobalBufs(BufferTx); wait_ms( 10 ); - Radio->Send( BufferTxAlias, BufferSizeTx ); + Radio->Send( BufferTx, BufferSizeTx ); } else { @@ -353,16 +348,16 @@ if( isMaster == true ) { // Send the next PING frame -// memcpy(BufferTxAlias, PingMsg, sizeof(PingMsg)); + memcpy(BufferTx, PingMsg, sizeof(PingMsg)); /* for( i = 4; i < BufferSizeTx; i++ ) { BufferTx[i] = i - 4; } */ - fillPayloadWithGlobalBufs(); +// fillPayloadWithGlobalBufs(BufferTx); wait_ms( 10 ); - Radio->Send( BufferTxAlias, BufferSizeTx ); + Radio->Send( BufferTx, BufferSizeTx ); } else { @@ -374,9 +369,9 @@ BufferTx[i] = i - sizeof(PongMsg); } */ - fillPayloadWithGlobalBufs(); +// fillPayloadWithGlobalBufs(BufferTx); wait_ms( 10 ); - Radio->Send( BufferTxAlias, BufferSizeTx ); + Radio->Send( BufferTx, BufferSizeTx ); } State = LOWPOWER; break; @@ -404,12 +399,15 @@ void OnRxDone(void *radio, void *userThisPtr, void *userData, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) { Radio->Sleep( ); - uint16_t ActualBufferSizeRx = size; - memcpy( BufferRxAlias, payload, ActualBufferSizeRx ); + + if(BufferSizeRx != size) + memcpy( BufferRx, payload, size ); + else + memcpy( BufferRx, payload, BufferSizeRx ); State = RX; // Call function that deconstructs payload - fillGlobalBufsWithPayload(); + // fillGlobalBufsWithPayload(payload); if (DEBUG_MESSAGE) dprintf("> OnRxDone: RssiValue=%d dBm, SnrValue=%d", rssi, snr); @@ -418,7 +416,7 @@ void OnTxTimeout(void *radio, void *userThisPtr, void *userData) { - *led3 = 0; +// *led3 = 0; Radio->Sleep( ); State = TX_TIMEOUT; if(DEBUG_MESSAGE) @@ -427,9 +425,9 @@ void OnRxTimeout(void *radio, void *userThisPtr, void *userData) { - *led3 = 0; +// *led3 = 0; Radio->Sleep( ); - BufferRxAlias[BufferSizeRx-1] = 0; + BufferRx[BufferSizeRx-1] = 0; State = RX_TIMEOUT; if (DEBUG_MESSAGE) dprintf("> OnRxTimeout");