![](/media/cache/profiles/profile_pic_for_github_less_than_1MB.jpg.50x50_q85.jpg)
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:
- 34:f31a6b53d4ea
- Parent:
- 32:b108ed6096b0
--- a/SX1276GenericPingPong/GenericPingPong.cpp Tue Jul 31 02:00:57 2018 +0000 +++ b/SX1276GenericPingPong/GenericPingPong.cpp Tue Jul 31 15:51:43 2018 +0000 @@ -4,7 +4,7 @@ * (c) 2017 Helmut Tschemernjak * 30826 Garbsen (Hannover) Germany */ - + #include "mbed.h" #include "PinMap.h" #include "GenericPingPong.h" @@ -15,7 +15,7 @@ #ifdef FEATURE_LORA /* Set this flag to '1' to display debug messages on the console */ -#define DEBUG_MESSAGE 0 +#define DEBUG_MESSAGE 1 /* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */ #define USE_MODEM_LORA 1 @@ -238,17 +238,40 @@ { if( BufferSizeRx > 0 ) { - /*This checks if the ID of the received transaction is matching that of - * the slave device's ID. This is Defined in the GenericPingPong.h - */ if( memcmp(&BufferRx[rx_idx_signature], PongMsg, sizeof(PongMsg)) == 0 ) { // *led = !*led; - if (DEBUG_MESSAGE) - dprintf( "...Pong" ); + dprintf( "...Pong" ); + // Send the next PING frame +// memcpy(BufferTx, PingMsg, sizeof(PingMsg)); +/* + // We fill the buffer with numbers for the payload + for( i = sizeof(PingMsg); i < BufferSizeTx; i++ ) + { + BufferTx[i] = i - sizeof(PingMsg); + } +*/ + /* Construct the payload buffer so data can be transmited. */ +// fillPayloadWithGlobalBufs(BufferTx); wait_ms( 10 ); Radio->Send( BufferTx, BufferSizeTx ); } +/* else if( memcmp(Buffer, PingMsg, sizeof(PingMsg)) == 0 ) + { // A master already exists then become a slave + dprintf( "...Ping" ); +// *led = !*led; + isMaster = false; + // Send the next PONG frame + memcpy(Buffer, PongMsg, sizeof(PongMsg)); + // We fill the buffer with numbers for the payload + for( i = sizeof(PongMsg); i < BufferSize; i++ ) + { + Buffer[i] = i - sizeof(PongMsg); + } + wait_ms( 10 ); + Radio->Send( Buffer, BufferSize ); + } +*/ else // valid reception but neither a PING or a PONG message { // Set device as master ans start again //isMaster = true; @@ -263,8 +286,17 @@ if( memcmp(BufferRx, PingMsg, sizeof(PingMsg)) == 0 ) { // *led = !*led; - if (DEBUG_MESSAGE) - dprintf( "...Ping" ); + dprintf( "...Ping" ); + // Send the reply to the PING string +// memcpy(BufferTx, PongMsg, sizeof(PongMsg)); +/* + // We fill the buffer with numbers for the payload + for( i = sizeof(PongMsg); i < BufferSizeTx; i++ ) + { + BufferTx[i] = i - sizeof(PongMsg); + } +*/ + // fillPayloadWithGlobalBufs(BufferTx); wait_ms( 10 ); Radio->Send( BufferTx, BufferSizeTx ); } @@ -281,13 +313,11 @@ // *led3 = 1; if( isMaster == true ) { - if (DEBUG_MESSAGE) - dprintf("Ping..." ); + dprintf("Ping..." ); } else { - if (DEBUG_MESSAGE) - dprintf("Pong..." ); + dprintf("Pong..." ); } Radio->Rx( RX_TIMEOUT_VALUE ); State = LOWPOWER; @@ -295,7 +325,15 @@ case RX_TIMEOUT: if( isMaster == true ) { -// fillPayloadWithGlobalBufs(BufferTx); + // Send the next PING frame +// memcpy(BufferTx, PingMsg, sizeof(PingMsg)); +/* + for( i = sizeof(PingMsg); i < BufferSizeTx; i++ ) + { + BufferTx[i] = i - sizeof(PingMsg); + } +*/ + fillPayloadWithGlobalBufs(BufferTx); wait_ms( 10 ); Radio->Send( BufferTx, BufferSizeTx ); } @@ -310,7 +348,7 @@ if( isMaster == true ) { // Send the next PING frame -// memcpy(BufferTx, PingMsg, sizeof(PingMsg)); + memcpy(BufferTx, PingMsg, sizeof(PingMsg)); /* for( i = 4; i < BufferSizeTx; i++ ) { @@ -371,10 +409,9 @@ // Call function that deconstructs payload // fillGlobalBufsWithPayload(payload); - if (DEBUG_MESSAGE) { + if (DEBUG_MESSAGE) dprintf("> OnRxDone: RssiValue=%d dBm, SnrValue=%d", rssi, snr); - dump("Data:", payload, size); - } + dump("Data:", payload, size); } void OnTxTimeout(void *radio, void *userThisPtr, void *userData)