This is example code that can get you started with building your own IR vision robot that communicates over LoRa
Dependencies: Adafruit-MotorShield Adafruit-PWM-Servo-Driver Adafruit_GFX BufferedSerial MAX17055_EZconfig NEO-6m-GPS SX1276GenericLib USBDeviceHT max32630fthr max77650_charger_sample
Fork of MAX326xxFTHR_LoRa_Example_test by
Diff: SX1276GenericPingPong/GenericPingPong.cpp
- Revision:
- 26:69aba05f010f
- Parent:
- 25:1a031add188a
- Child:
- 27:6b549f838f0a
diff -r 1a031add188a -r 69aba05f010f SX1276GenericPingPong/GenericPingPong.cpp --- a/SX1276GenericPingPong/GenericPingPong.cpp Thu Jul 19 21:13:19 2018 +0000 +++ b/SX1276GenericPingPong/GenericPingPong.cpp Fri Jul 20 16:31:41 2018 +0000 @@ -87,22 +87,13 @@ */ SX1276Generic *Radio; -/* determine the appropriate buffer sizes */ -#if defined(TARGET_MAX32630FTHR) // Master Device: Bluetooth Gateway - uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE; - uint16_t BufferSizeRx = PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER; -#elif defined(TARGET_MAX32620FTHR) // Slave Device: Robot - uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER; - uint16_t BufferSizeRx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE; -#endif - uint8_t *BufferTx; uint8_t *BufferRx; DigitalOut *led3; -uint8_t * SX1276PingPongSetup(void) +int SX1276PingPongSetup(uint8_t * PointerToBufferTx, uint8_t * PointerToBufferRx) { dprintf("TEST" ); #if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) ) @@ -115,8 +106,13 @@ led3 = led; #endif - BufferTx = new uint8_t[BufferSizeTx]; - BufferRx = new uint8_t[BufferSizeRx]; + /* 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. + */ + BufferTx = PointerToBufferTx; + BufferRx = PointerToBufferRx; *led3 = 1; #ifdef B_L072Z_LRWAN1_LORA @@ -225,7 +221,6 @@ Radio->Rx( RX_TIMEOUT_VALUE ); - return BufferTx; } /**************************************************************************************************************************************** @@ -233,7 +228,6 @@ ****************************************************************************************************************************************/ int SX1276PingPong(void) { - uint8_t i; #if defined(TARGET_MAX32630FTHR) // Master Device: Bluetooth Gateway bool isMaster = true; #elif defined(TARGET_MAX32620FTHR) // Slave Device: Robot @@ -243,7 +237,7 @@ switch( State ) { case RX: -// *led3 = 0; + *led3 = 0; if( isMaster == true ) { if( BufferSizeRx > 0 ) @@ -306,7 +300,7 @@ BufferTx[i] = i - sizeof(PongMsg); } */ - fillPayloadWithGlobalBufs(BufferTx); + //fillPayloadWithGlobalBufs(BufferTx); wait_ms( 10 ); Radio->Send( BufferTx, BufferSizeTx ); } @@ -320,7 +314,7 @@ State = LOWPOWER; break; case TX: -// *led3 = 1; + *led3 = 1; if( isMaster == true ) { dprintf("Ping..." ); @@ -409,8 +403,8 @@ void OnRxDone(void *radio, void *userThisPtr, void *userData, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) { Radio->Sleep( ); - BufferSizeRx = size; - memcpy( BufferRx, payload, BufferSizeRx ); + uint16_t ActualBufferSizeRx = size; + memcpy( BufferRx, payload, ActualBufferSizeRx ); State = RX; // Call function that deconstructs payload @@ -423,7 +417,7 @@ void OnTxTimeout(void *radio, void *userThisPtr, void *userData) { -// *led3 = 0; + *led3 = 0; Radio->Sleep( ); State = TX_TIMEOUT; if(DEBUG_MESSAGE) @@ -432,7 +426,7 @@ void OnRxTimeout(void *radio, void *userThisPtr, void *userData) { -// *led3 = 0; + *led3 = 0; Radio->Sleep( ); BufferRx[BufferSizeRx-1] = 0; State = RX_TIMEOUT;