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 Devin Alexander

Revision:
25:1a031add188a
Parent:
24:e8d03912f303
Child:
26:69aba05f010f
--- a/SX1276GenericPingPong/GenericPingPong.cpp	Wed Jul 18 21:25:17 2018 +0000
+++ b/SX1276GenericPingPong/GenericPingPong.cpp	Thu Jul 19 21:13:19 2018 +0000
@@ -87,10 +87,6 @@
  */
 SX1276Generic *Radio;
 
-
-const uint8_t PingMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'I', 'N', 'G'};// "PING";
-const uint8_t PongMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'O', 'N', 'G'};// "PONG";
-
 /* determine the appropriate buffer sizes */
 #if   defined(TARGET_MAX32630FTHR) // Master Device: Bluetooth Gateway
     uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE;
@@ -106,7 +102,7 @@
 DigitalOut *led3;
 
 
-int SX1276PingPongSetup(void) 
+uint8_t * SX1276PingPongSetup(void) 
 {
 	dprintf("TEST" );
 #if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) )
@@ -187,6 +183,10 @@
         dprintf("             > LORA FHSS Mode <");
     if (!LORA_FHSS_ENABLED)
         dprintf("             > LORA Mode <");
+	
+	
+	// Without this line, the default max payload length is only 64 bytes
+	Radio->SetMaxPayloadLength(MODEM_LORA, 255);
 
     Radio->SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
                          LORA_SPREADING_FACTOR, LORA_CODINGRATE,
@@ -224,8 +224,13 @@
 
         
     Radio->Rx( RX_TIMEOUT_VALUE );
+
+    return BufferTx;
 }
 
+/****************************************************************************************************************************************
+ * 
+ ****************************************************************************************************************************************/
 int SX1276PingPong(void)
 {
     uint8_t i;
@@ -234,7 +239,7 @@
 #elif defined(TARGET_MAX32620FTHR) // Slave Device: Robot
 	bool isMaster = false;
 #endif
-
+	
     switch( State )
     {
     case RX:
@@ -243,17 +248,21 @@
         {
             if( BufferSizeRx > 0 )
             {
-                if( memcmp(BufferRx, PongMsg, sizeof(PongMsg)) == 0 )
+                if( memcmp(&BufferRx[rx_idx_signature], PongMsg, sizeof(PongMsg)) == 0 )
                 {
 //                        *led = !*led;
                     dprintf( "...Pong" );
                     // Send the next PING frame            
-                    memcpy(BufferTx, PingMsg, sizeof(PingMsg));
+//                    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 );
                 }
@@ -289,12 +298,15 @@
 //                        *led = !*led;
                     dprintf( "...Ping" );
                     // Send the reply to the PING string
-                    memcpy(BufferTx, PongMsg, sizeof(PongMsg));
+//                    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 );
                 }
@@ -324,11 +336,14 @@
         if( isMaster == true )
         {
             // Send the next PING frame
-            memcpy(BufferTx, PingMsg, sizeof(PingMsg));
+//            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 );
         }
@@ -344,21 +359,27 @@
         {
             // Send the next PING frame
             memcpy(BufferTx, PingMsg, sizeof(PingMsg));
+/*            
             for( i = 4; i < BufferSizeTx; i++ )
             {
                 BufferTx[i] = i - 4;
             }
+*/
+			fillPayloadWithGlobalBufs(BufferTx);
             wait_ms( 10 );  
             Radio->Send( BufferTx, BufferSizeTx );
         }
         else
         {
             // Send the next PONG frame
-            memcpy(BufferTx, PongMsg, sizeof(PongMsg));
+//            memcpy(BufferTx, PongMsg, sizeof(PongMsg));
+/*
             for( i = sizeof(PongMsg); i < BufferSizeTx; i++ )
             {
                 BufferTx[i] = i - sizeof(PongMsg);
             }
+*/
+			fillPayloadWithGlobalBufs(BufferTx);
             wait_ms( 10 );  
             Radio->Send( BufferTx, BufferSizeTx );
         }
@@ -380,7 +401,7 @@
 void OnTxDone(void *radio, void *userThisPtr, void *userData)
 {
     Radio->Sleep( );
-    State = TX;
+    State = TX; 
     if (DEBUG_MESSAGE)
         dprintf("> OnTxDone");
 }
@@ -391,6 +412,10 @@
     BufferSizeRx = size;
     memcpy( BufferRx, payload, BufferSizeRx );
     State = RX;
+
+    // Call function that deconstructs payload
+    fillGlobalBufsWithPayload(payload);
+
     if (DEBUG_MESSAGE)
         dprintf("> OnRxDone: RssiValue=%d dBm, SnrValue=%d", rssi, snr);
     dump("Data:", payload, size);