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:
- 32:b108ed6096b0
- Parent:
- 28:0ed92c590607
- Child:
- 34:f31a6b53d4ea
- Child:
- 35:bae9b236070b
diff -r f15747cffb20 -r b108ed6096b0 SX1276GenericPingPong/GenericPingPong.cpp --- a/SX1276GenericPingPong/GenericPingPong.cpp Tue Jul 24 18:30:26 2018 +0000 +++ b/SX1276GenericPingPong/GenericPingPong.cpp Mon Jul 30 05:53:55 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 1 +#define DEBUG_MESSAGE 0 /* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */ #define USE_MODEM_LORA 1 @@ -238,40 +238,17 @@ { 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; - 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); + if (DEBUG_MESSAGE) + dprintf( "...Pong" ); 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; @@ -286,17 +263,8 @@ if( memcmp(BufferRx, PingMsg, sizeof(PingMsg)) == 0 ) { // *led = !*led; - 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); + if (DEBUG_MESSAGE) + dprintf( "...Ping" ); wait_ms( 10 ); Radio->Send( BufferTx, BufferSizeTx ); } @@ -313,11 +281,13 @@ // *led3 = 1; if( isMaster == true ) { - dprintf("Ping..." ); + if (DEBUG_MESSAGE) + dprintf("Ping..." ); } else { - dprintf("Pong..." ); + if (DEBUG_MESSAGE) + dprintf("Pong..." ); } Radio->Rx( RX_TIMEOUT_VALUE ); State = LOWPOWER; @@ -325,15 +295,7 @@ case RX_TIMEOUT: if( isMaster == true ) { - // Send the next PING frame -// memcpy(BufferTx, PingMsg, sizeof(PingMsg)); -/* - for( i = sizeof(PingMsg); i < BufferSizeTx; i++ ) - { - BufferTx[i] = i - sizeof(PingMsg); - } -*/ - fillPayloadWithGlobalBufs(BufferTx); +// fillPayloadWithGlobalBufs(BufferTx); wait_ms( 10 ); Radio->Send( BufferTx, BufferSizeTx ); } @@ -348,7 +310,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++ ) { @@ -409,9 +371,10 @@ // 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)