Team Walter / Mbed OS Low_Power_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

Files at this revision

API Documentation at this revision

Comitter:
dev_alexander
Date:
Mon Jul 23 23:39:35 2018 +0000
Parent:
27:6b549f838f0a
Child:
29:f7a0e49b826b
Commit message:
Reworked how the buffers are loaded and unloaded. Now prints off data received from the Slave on the Master. This is a stable release.

Changed in this revision

GridEye/GridEye.cpp Show annotated file Show diff for this revision Revisions of this file
GridEye/GridEye.h Show annotated file Show diff for this revision Revisions of this file
SX1276GenericPingPong/GenericPingPong.cpp Show annotated file Show diff for this revision Revisions of this file
SX1276GenericPingPong/GenericPingPong.h Show annotated file Show diff for this revision Revisions of this file
global_buffer_declarations.h Show diff for this revision Revisions of this file
global_buffers.cpp Show annotated file Show diff for this revision Revisions of this file
global_buffers.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/GridEye/GridEye.cpp	Fri Jul 20 21:29:53 2018 +0000
+++ b/GridEye/GridEye.cpp	Mon Jul 23 23:39:35 2018 +0000
@@ -38,6 +38,8 @@
 GridEye::GridEye(I2C &i2c)
 : m_i2cBus(i2c)
 {
+    //Perform a software reset upon power on.
+    softwareReset();
 }
 
 
@@ -124,6 +126,18 @@
     return result;
 }
 
+//*********************************************************************
+int8_t GridEye::softwareReset() 
+{
+    int8_t result;
+    char initial_reset[1];
+    //This value when programmed to the Grid Eye's RESET reg will perform initial reset on device
+    initial_reset[0] = 0x3F;
+    result = this->gridEyeWriteReg(GridEye::RESET, 1, initial_reset);
+    if (result == I2C_WR_SUCCESS)
+        return result;
+    return I2C_WR_ERROR;
+}
 
 //*********************************************************************
 int8_t GridEye::setOperatingMode(GridEye::OperatingMode mode) 
@@ -155,6 +169,7 @@
     int8_t upper_byte = data[1];
     int8_t lower_byte = data[0];
     int16_t upper_byte_mask = 0x0F00;
+    //int16_t sign_bit = 0x0400;
     int16_t sign_bit = 0x0200;
     int16_t finish_neg_val = 0xFC00;
     int16_t pixel;
@@ -181,6 +196,7 @@
     int8_t upper_byte;
     int8_t lower_byte;
     int16_t upper_byte_mask = 0x0F00;
+    //int16_t sign_bit = 0x0400;
     int16_t sign_bit = 0x0200;
     int16_t finish_neg_val = 0xFC00;
     int16_t pixel;
@@ -213,6 +229,7 @@
     int8_t upper_byte;
     int8_t lower_byte;
     int16_t upper_byte_mask = 0x0F00;
+    //int16_t sign_bit = 0x1000;
     int16_t sign_bit = 0x0800;
     int16_t finish_neg_val = 0xF000;
     int16_t pixel;
@@ -223,14 +240,15 @@
         upper_byte = data[idx*2+1];
         lower_byte = data[idx*2+0];
         pixel = (upper_byte << 8);
-        pixel &= upper_byte_mask;
+        //pixel &= upper_byte_mask;
         pixel |= lower_byte;
-        
         //no shift needed since we would lose the two lsb that give 0.25*C precision
         
         //if negative, properly convert to 16 bit int format to represent 2's compliment
         if (pixel & sign_bit)
             pixel |= finish_neg_val;
+        else 
+            pixel &= 0x0FFF;
         
         //set the coresponding pixel to be in the passed in array
         frame_temp[idx] = pixel;
--- a/GridEye/GridEye.h	Fri Jul 20 21:29:53 2018 +0000
+++ b/GridEye/GridEye.h	Mon Jul 23 23:39:35 2018 +0000
@@ -220,8 +220,39 @@
     int8_t getRaw8x8FrameData(char * raw_frame_data);
     
     
+    /**
+    * @brief softwareReset
+    *
+    * @details Makes the Grid Eye device perform a software restart with Initial conditions
+    *
+    * @return int8_t - result of operation, 0 on success, -1 on failure
+    */   
+    int8_t softwareReset();
+    
+    
+    /**
+    * @brief setOperatingMode
+    *
+    * @details Sets the mode of operation for the Grid Eye device 
+    *
+    * On Entry:
+    * @param[in] mode - Choose power operating mode from struct
+    *
+    * @return int8_t - result of operation, 0 on success, -1 on failure
+    */   
     int8_t setOperatingMode(GridEye::OperatingMode mode);
     
+    
+    /**
+    * @brief setFrameRate
+    *
+    * @details Sets the frames per second that the grid eye device resolves
+    *
+    * On Entry:
+    * @param[in] mode - Choose option from either 10 fps or 1 fps
+    *
+    * @return int8_t - result of operation, 0 on success, -1 on failure
+    */   
     int8_t setFrameRate(GridEye::FrameRate rate);
 
 };
--- 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");
--- a/SX1276GenericPingPong/GenericPingPong.h	Fri Jul 20 21:29:53 2018 +0000
+++ b/SX1276GenericPingPong/GenericPingPong.h	Mon Jul 23 23:39:35 2018 +0000
@@ -38,7 +38,7 @@
 
 
 
-int SX1276PingPongSetup(uint8_t * PointerToBufferTx, uint8_t * PointerToBufferRx);
+int SX1276PingPongSetup(uint8_t *BufferTxFromMain, uint8_t *BufferRxFromMain);
 
 int SX1276PingPong(void);
 
--- a/global_buffer_declarations.h	Fri Jul 20 21:29:53 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-#ifndef __GLOBAL_BUFFERS_DECLARATIONS_H__
-#define __GLOBAL_BUFFERS_DECLARATIONS_H__
- 
-
-
-
-
-
-
- 
- 
-#endif
\ No newline at end of file
--- a/global_buffers.cpp	Fri Jul 20 21:29:53 2018 +0000
+++ b/global_buffers.cpp	Mon Jul 23 23:39:35 2018 +0000
@@ -3,99 +3,42 @@
  */
 
 #include "global_buffers.h"
-uint8_t * BufferTx;
-uint8_t * BufferRx;
-
-#if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
-    uint8_t * BLE_DATA_TO_SLAVE;
-    char    * GRID_EYE_DATA_FROM_SLAVE;
-    uint8_t * GPS_DATA_FROM_SLAVE;
-    uint8_t * MAX17055_DATA_FROM_SLAVE;
-    uint8_t * MAX77650_DATA_FROM_SLAVE;
-#elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
-    uint8_t * BLE_DATA_FROM_MASTER;
-    char    * GRID_EYE_DATA_TO_MASTER;
-    uint8_t * GPS_DATA_TO_MASTER;
-    uint8_t * MAX17055_DATA_TO_MASTER;
-    uint8_t * MAX77650_DATA_TO_MASTER;
-#endif
-
-#if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
-void createAliasesForGlobalBufs(uint8_t * BufferTx_,
-                                uint8_t * BufferRx_, 
-                                uint8_t * curr_ble_data_to_slave_,
-                                char    * curr_raw_frame_data_from_slave_,
-                                uint8_t * curr_gps_data_from_slave_,
-                                uint8_t * curr_MAX17055_from_slave_,
-                                uint8_t * curr_MAX77650_from_slave_
-                                )
-{
-    BufferTx = BufferTx_;
-    BufferTx = BufferRx_;
-    BLE_DATA_TO_SLAVE        = curr_ble_data_to_slave_;
-    GRID_EYE_DATA_FROM_SLAVE = curr_raw_frame_data_from_slave_;
-    GPS_DATA_FROM_SLAVE      = curr_gps_data_from_slave_;
-    MAX17055_DATA_FROM_SLAVE = curr_MAX17055_from_slave_;
-    MAX77650_DATA_FROM_SLAVE = curr_MAX77650_from_slave_;
-    
-}
-
-#elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
-void createAliasesForGlobalBufs(uint8_t * BufferTx_, 
-                                uint8_t * BufferRx_, 
-                                uint8_t * curr_ble_data_from_master_,
-                                char    * curr_raw_frame_data_to_master_, 
-                                uint8_t * curr_gps_data_to_master_,
-                                uint8_t * curr_MAX17055_to_master_,
-                                uint8_t * curr_MAX77650_to_master_
-                                )
-{
-    BufferTx = BufferTx_;
-    BufferTx = BufferRx_;
-    BLE_DATA_FROM_MASTER    = curr_ble_data_from_master_;
-    GRID_EYE_DATA_TO_MASTER = curr_raw_frame_data_to_master_;
-    GPS_DATA_TO_MASTER      = curr_gps_data_to_master_;
-    MAX17055_DATA_TO_MASTER = curr_MAX17055_to_master_;
-    MAX77650_DATA_TO_MASTER = curr_MAX77650_to_master_;
-}
-#endif
 
 
 /** 
  * @brief This function constructs a payload buffer that is used in transmitting data in a LoRa Message
  */
-void fillPayloadWithGlobalBufs()
+void fillPayloadWithGlobalBufs(uint8_t * payload_buffer_tx)
 {
-/* The master and slave devices will have different requirements for creating payload */
-#if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
-    memcpy(&BufferTx[tx_idx_signature], PingMsg,           size_signature); // SX1276PingPong() uses this to detect if the message was sent from the correct Slave Device
-    memcpy(&BufferTx[tx_idx_ble],       BLE_DATA_TO_SLAVE, size_of_ble);
+    /* The master and slave devices will have different requirements for creating payload */
+    #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+        memcpy(&payload_buffer_tx[tx_idx_signature], PingMsg,                       size_signature);
+        memcpy(&payload_buffer_tx[tx_idx_ble],       curr_ble_data_to_slave,        size_of_ble);
+    #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+        memcpy(&payload_buffer_tx[tx_idx_signature], PongMsg,                       size_signature);
+        memcpy(&payload_buffer_tx[tx_idx_grid_eye],  curr_raw_frame_data_to_master, size_of_grid_eye);
+        memcpy(&payload_buffer_tx[tx_idx_gps],       curr_gps_data_to_master,       size_of_gps);
+        memcpy(&payload_buffer_tx[tx_idx_MAX17055],  curr_MAX17055_to_master,       size_of_MAX17055);
+        memcpy(&payload_buffer_tx[tx_idx_MAX77650],  curr_MAX77650_to_master,       size_of_MAX77650);
+    #endif
+    
     return;
-#elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
-    memcpy(&BufferTx[tx_idx_signature], PongMsg,                  size_signature); // SX1276PingPong() uses this to detect if the message was sent from the correct Master Device
-    memcpy(&BufferTx[tx_idx_grid_eye],  GRID_EYE_DATA_TO_MASTER,  size_of_grid_eye);
-    memcpy(&BufferTx[tx_idx_gps],       GPS_DATA_TO_MASTER,       size_of_gps);
-    memcpy(&BufferTx[tx_idx_MAX17055],  MAX17055_DATA_TO_MASTER,  size_of_MAX17055);
-    memcpy(&BufferTx[tx_idx_MAX77650],  MAX77650_DATA_TO_MASTER,  size_of_MAX77650);
-    return;
-#endif
-}
-
+} 
 
 /** 
  * @brief This function deconstructs a payload buffer that contains data from a received LoRa Message
  */
-void fillGlobalBufsWithPayload()
+void fillGlobalBufsWithPayload(uint8_t * payload_buffer_rx)
 {
-/* The master and slave devices will have different requirements for offloading payload */
-#if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
-    memcpy(GRID_EYE_DATA_FROM_SLAVE, &BufferRx[rx_idx_grid_eye], size_of_grid_eye);
-    memcpy(GPS_DATA_FROM_SLAVE,      &BufferRx[rx_idx_gps],      size_of_gps);
-    memcpy(MAX17055_DATA_FROM_SLAVE, &BufferRx[rx_idx_MAX17055], size_of_MAX17055);
-    memcpy(MAX77650_DATA_FROM_SLAVE, &BufferRx[rx_idx_MAX77650], size_of_MAX77650);
+    /* The master and slave devices will have different requirements for offloading payload */
+    #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+    memcpy(curr_raw_frame_data_from_slave, &payload_buffer_rx[rx_idx_grid_eye], size_of_grid_eye);
+        memcpy(curr_gps_data_from_slave,       &payload_buffer_rx[rx_idx_gps],      size_of_gps);
+        memcpy(curr_MAX17055_from_slave,       &payload_buffer_rx[rx_idx_MAX17055], size_of_MAX17055);
+        memcpy(curr_MAX77650_from_slave,       &payload_buffer_rx[rx_idx_MAX77650], size_of_MAX77650);
+    #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+        memcpy(curr_ble_data_from_master,      &payload_buffer_rx[rx_idx_ble],  size_of_ble);
+    #endif
+    
     return;
-#elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
-    memcpy(BLE_DATA_FROM_MASTER,     &BufferRx[rx_idx_ble],      size_of_ble);
-    return;
-#endif 
-}
\ No newline at end of file
+} 
--- a/global_buffers.h	Fri Jul 20 21:29:53 2018 +0000
+++ b/global_buffers.h	Mon Jul 23 23:39:35 2018 +0000
@@ -19,14 +19,12 @@
  */
 
 #ifndef __GLOBAL_BUFFERS_H__
-#define __GLOBAL_BUFFERS_H__
+#define __GLOBAL_BUFFERS_H__\
  
 #include "mbed.h"
-#include "global_buffer_declarations.h"
 #include "GenericPingPong.h"
 
 
-
 /***************************************************************************
  * Indexes for which byte specific data begins at in the payload buffer
  **************************************************************************/
@@ -47,10 +45,11 @@
  * the payload so we can instatiate the correct buffer sizes to store data that 
  * is to be delivered and for data that is received. 
  */
+
 const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = size_signature + size_of_ble;
 const uint16_t PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER = size_signature + size_of_grid_eye + size_of_gps + size_of_MAX17055 + size_of_MAX77650;
 
-/* determine the appropriate buffer sizes for each device in master/slave config */
+/* determine the appropriate buffer sizes */
 #if   defined(TARGET_MAX32630FTHR) // Master Device: Bluetooth Gateway
     const uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE;
     const uint16_t BufferSizeRx = PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER;
@@ -85,33 +84,67 @@
 #endif
 
 
+/***************************************************************************
+ * BLE Data Buffers
+ **************************************************************************/
+#if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+    static char curr_ble_data_to_slave[size_of_ble];
+#elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+    static char curr_ble_data_from_master[size_of_ble];
+    static char prev_ble_data_from_master[size_of_ble];
+#endif
 
+/***************************************************************************
+ * Grid Eye Sensor Data Buffers
+ **************************************************************************/
 #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
-void createAliasesForGlobalBufs(uint8_t * BufferTx_,
-                                uint8_t * BufferRx_, 
-                                uint8_t * curr_ble_data_to_slave_,
-                                char    * curr_raw_frame_data_from_slave_,
-                                uint8_t * curr_gps_data_from_slave_,
-                                uint8_t * curr_MAX17055_from_slave_,
-                                uint8_t * curr_MAX77650_from_slave_);
+    static char curr_raw_frame_data_from_slave[size_of_grid_eye];
+    static char prev_raw_frame_data_from_slave[size_of_grid_eye];
+    static int16_t conv_frame_data_from_slave[64];
+#elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot
+    static char curr_raw_frame_data_to_master[size_of_grid_eye];
+    static char prev_raw_frame_data_to_master[size_of_grid_eye];
+    static int16_t conv_frame_data_to_master[64];
+#endif
+
+/***************************************************************************
+ * GPS Data Buffers
+ **************************************************************************/
+#if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+    static char curr_gps_data_from_slave[size_of_gps];
+    static char prev_gps_data_from_slave[size_of_gps];
 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
-void createAliasesForGlobalBufs(uint8_t * BufferTx_, 
-                                uint8_t * BufferRx_, 
-                                uint8_t * curr_ble_data_from_master_,
-                                char    * curr_raw_frame_data_to_master_, 
-                                uint8_t * curr_gps_data_to_master_,
-                                uint8_t * curr_MAX17055_to_master_,
-                                uint8_t * curr_MAX77650_to_master_);
+    static char curr_gps_data_to_master[size_of_gps];
+#endif
+
+/***************************************************************************
+ * MAX17055 Data Buffers
+ **************************************************************************/
+#if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+    static char curr_MAX17055_from_slave[size_of_MAX17055];
+    static char prev_MAX17055_from_slave[size_of_MAX17055];
+#elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+    static char curr_MAX17055_to_master[size_of_MAX17055];
+#endif
+
+/***************************************************************************
+ * MAX77650 Data Buffers
+ **************************************************************************/
+#if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+    static char curr_MAX77650_from_slave[size_of_MAX77650];
+    static char prev_MAX77650_from_slave[size_of_MAX77650];
+#elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+    static char curr_MAX77650_to_master[size_of_MAX77650];
 #endif
 
 /** 
  * @brief This function constructs a payload buffer that is used in transmitting data in a LoRa Message
  */
-void fillPayloadWithGlobalBufs(); 
+void fillPayloadWithGlobalBufs(uint8_t * payload_buffer_tx); 
 
 /** 
  * @brief This function deconstructs a payload buffer that contains data from a received LoRa Message
  */
-void fillGlobalBufsWithPayload(); 
+void fillGlobalBufsWithPayload(uint8_t * payload_buffer_rx); 
 
 #endif // __GLOBAL_BUFFERS_H__
\ No newline at end of file
--- a/main.cpp	Fri Jul 20 21:29:53 2018 +0000
+++ b/main.cpp	Mon Jul 23 23:39:35 2018 +0000
@@ -28,7 +28,7 @@
 
 DigitalOut myled(LED);
 
-//Serial pc(USBTX, USBRX);
+Serial pc(USBTX, USBRX);
 
 
 #if   defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
@@ -46,10 +46,6 @@
     GridEye gridEye(i2cGridEye);
 #endif
 
-
-/***************************************************************************
- * main()
- **************************************************************************/
 int main() 
 {
     /*
@@ -69,96 +65,7 @@
     #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
         dprintf("MAX32620FTHR: Slave");
     #endif
-
-/***************************************************************************
- * Lora Communication Buffers
- **************************************************************************/
-    /* Create Buffers to store both incoming and outgoing LoRa communications */
-    uint8_t BufferTx[BufferSizeTx];
-    uint8_t BufferRx[BufferSizeRx];
     
-/***************************************************************************
- * BLE Data Buffers
- **************************************************************************/
-    #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
-        uint8_t curr_ble_data_to_slave[size_of_ble];
-    #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
-        uint8_t curr_ble_data_from_master[size_of_ble];
-        uint8_t prev_ble_data_from_master[size_of_ble];
-    #endif
-/***************************************************************************
- * Grid Eye Sensor Data Buffers
- **************************************************************************/
-    #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
-        char curr_raw_frame_data_from_slave[size_of_grid_eye];
-        char prev_raw_frame_data_from_slave[size_of_grid_eye];
-        int16_t conv_frame_data_from_slave[64];
-    #elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot
-        char curr_raw_frame_data_to_master[size_of_grid_eye];
-        char prev_raw_frame_data_to_master[size_of_grid_eye];
-        int16_t conv_frame_data_to_master[64];
-    #endif
-/***************************************************************************
- * GPS Data Buffers
- **************************************************************************/
-    #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
-        uint8_t curr_gps_data_from_slave[size_of_gps];
-        uint8_t prev_gps_data_from_slave[size_of_gps];
-    #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
-        uint8_t curr_gps_data_to_master[size_of_gps];
-    #endif
-/***************************************************************************
- * MAX17055 Data Buffers
- **************************************************************************/
-    #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
-        uint8_t curr_MAX17055_from_slave[size_of_MAX17055];
-        uint8_t prev_MAX17055_from_slave[size_of_MAX17055];
-    #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
-        uint8_t curr_MAX17055_to_master[size_of_MAX17055];
-    #endif
-    
-/***************************************************************************
- * MAX77650 Data Buffers
- **************************************************************************/
-    #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
-        uint8_t curr_MAX77650_from_slave[size_of_MAX77650];
-        uint8_t prev_MAX77650_from_slave[size_of_MAX77650];
-    #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
-        uint8_t curr_MAX77650_to_master[size_of_MAX77650];
-    #endif
-/***************************************************************************
- * Store Aliases to the buffers created here in main porgram
- **************************************************************************/
-#if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
-createAliasesForGlobalBufs(BufferTx,
-                           BufferRx, 
-                           curr_ble_data_to_slave,
-                           curr_raw_frame_data_from_slave,
-                           curr_gps_data_from_slave,
-                           curr_MAX17055_from_slave,
-                           curr_MAX77650_from_slave
-                           );
-#elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
-createAliasesForGlobalBufs(BufferTx, 
-                           BufferRx, 
-                           curr_ble_data_from_master,
-                           curr_raw_frame_data_to_master, 
-                           curr_gps_data_to_master,
-                           curr_MAX17055_to_master,
-                           curr_MAX77650_to_master
-                           );
-#endif
-/***************************************************************************
- * Continue with Finishing Setup by Calling other functions
- **************************************************************************/
-    
-    
-    /* Pass in pointers to the two buffers for LoRa communication to the sx1276 
-    `* Setup so that the LoRa communications know where data needs to be both
-     * stored to in a case of Receiving or where to find data in case of a 
-     * Transmistion occuring.
-     */
-    SX1276PingPongSetup(BufferTx, BufferRx);
     
     /***************************************************************************
      * Grid Eye Sensor: Non-Buffer Program Variables
@@ -168,26 +75,84 @@
     #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
         // none yet
         int frame_idx = 0;
-        char local_curr_raw_frame_data_to_master[size_of_grid_eye];
-        char local_prev_raw_frame_data_to_master[size_of_grid_eye];
-        int16_t local_conv_frame_data_to_master[64];
     #endif
     
     
+    /***************************************************************************
+     * Combined Payload Buffers for LoRa Communications
+     **************************************************************************/
+    uint8_t BufferTx[BufferSizeTx];
+    uint8_t BufferRx[BufferSizeRx];
+    
+    /***************************************************************************
+     * BLE Data Buffers
+     **************************************************************************/
+    #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+        uint8_t curr_ble_to_slave[size_of_ble];
+    #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+        uint8_t curr_ble_from_master[size_of_ble];
+        uint8_t prev_ble_from_master[size_of_ble];
+    #endif
+    
+    /***************************************************************************
+     * Grid Eye Sensor Data Buffers
+     **************************************************************************/
+    #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+        char curr_raw_frame_from_slave[size_of_grid_eye];
+        char prev_raw_frame_from_slave[size_of_grid_eye];
+        int16_t conv_frame_from_slave[64];
+    #elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot
+        char curr_raw_frame_to_master[size_of_grid_eye];
+        char prev_raw_frame_to_master[size_of_grid_eye];
+        int16_t conv_frame_to_master[64];
+    #endif
+    
+    /***************************************************************************
+     * GPS Data Buffers
+     **************************************************************************/
+    #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+        uint8_t curr_gps_from_slave[size_of_gps];
+        uint8_t prev_gps_from_slave[size_of_gps];
+    #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+        uint8_t curr_gps_to_master[size_of_gps];
+    #endif
+    
+    /***************************************************************************
+     * MAX17055 Data Buffers
+     **************************************************************************/
+    #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+        uint8_t curr_MAX17055_from_slave[size_of_MAX17055];
+        uint8_t prev_MAX17055_from_slave[size_of_MAX17055];
+    #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+        uint8_t curr_MAX17055_to_master[size_of_MAX17055];
+    #endif
+    
+    /***************************************************************************
+     * MAX77650 Data Buffers
+     **************************************************************************/
+    #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+        uint8_t curr_MAX77650_from_slave[size_of_MAX77650];
+        uint8_t prev_MAX77650_from_slave[size_of_MAX77650];
+    #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+        uint8_t curr_MAX77650_to_master[size_of_MAX77650];
+    #endif
+    
+    /***************************************************************************
+     * Finish Setting up LoRa Radios: This passes in pointers to Buffers to send
+     **************************************************************************/
+    SX1276PingPongSetup(BufferTx, BufferRx);
+    
     while(1) 
-    {
+    {        
         /***************************************************************************
          * Grid Eye Sensor 
          **************************************************************************/
         #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
-            /*
-            //Check to see if the contents of the previous scan are the same. If they are different then continue with converting
-            if( memcmp(prev_raw_frame_data_from_slave, curr_raw_frame_data_from_slave, sizeof(curr_raw_frame_data_from_slave)) != 0 )
+            // Check to see if the contents of the previous scan are the same. If they are different then continue with converting
+            if( memcmp(prev_raw_frame_from_slave, curr_raw_frame_from_slave, sizeof(curr_raw_frame_from_slave)) != 0 )
             {
                 // Convert raw data sent from slave to a 16 bit integer array by calling this
-                convRaw8x8Data2Point25degC(curr_raw_frame_data_from_slave, conv_frame_data_from_slave);
-                
-                wait_ms(10);
+                convRaw8x8Data2Point25degC(curr_raw_frame_from_slave, conv_frame_from_slave);
                 
                 // Next Print off the Converted data
                 pc.printf("\r\nFrame %d data: \r\n", frame_idx);
@@ -196,7 +161,7 @@
                 for (int y = 0; y < 8; y++) {
                     for (int x = 0; x < 8; x++) {
                         idx = y*8 + x;
-                        pixel_data = conv_frame_data_from_slave[idx]/4.0;
+                        pixel_data = ((float)conv_frame_from_slave[idx])/4.0;
                         pc.printf("%.2f  \t", pixel_data);
                     }
                     pc.printf("\r\n\r\n");
@@ -206,26 +171,24 @@
                 // Increment frame counter
                 frame_idx = frame_idx +1;
             }
-            */
+            
             /* Next copy in data received from current data into buffer used for
              * comparison next time the memcmp above is called. This prevents the 
              * program from converting the same raw data aquired by the grid eye
              * sensor on the slave device to the floating point array with the 
              * 0.25 degrees celsius precision level when there is not new data. 
              */
-            //memcpy(prev_raw_frame_data_from_slave, curr_raw_frame_data_from_slave, sizeof(curr_raw_frame_data_from_slave));
+            memcpy(prev_raw_frame_from_slave, curr_raw_frame_from_slave, sizeof(curr_raw_frame_from_slave));
             
         #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
             // Aquire raw data about 8x8 frame from the grid eye sensor in this function call 
-            gridEye.getRaw8x8FrameData(local_curr_raw_frame_data_to_master);
-            wait_ms( 10 );  
-/*            
-            if ( memcmp(prev_raw_frame_data_to_master, curr_raw_frame_data_to_master, sizeof(curr_raw_frame_data_to_master)) != 0 )
-            {
+            gridEye.getRaw8x8FrameData(curr_raw_frame_to_master);
+            wait_ms( 10 );
+            /*
+            //if ( memcmp(prev_raw_frame_to_master, curr_raw_frame_to_master, sizeof(curr_raw_frame_to_master)) != 0 )
+            //{
                 // Convert raw data sent from slave to a 16 bit integer array by calling this
-                convRaw8x8Data2Point25degC(local_curr_raw_frame_data_to_master, local_conv_frame_data_to_master);
-                
-                wait_ms(10);
+                convRaw8x8Data2Point25degC(curr_raw_frame_to_master, conv_frame_to_master);
                 
                 // Next Print off the Converted data
                 pc.printf("\r\nFrame %d data: \r\n", frame_idx);
@@ -234,7 +197,7 @@
                 for (int y = 0; y < 8; y++) {
                     for (int x = 0; x < 8; x++) {
                         idx = y*8 + x;
-                        pixel_data = local_conv_frame_data_to_master[idx]/4.0;
+                        pixel_data = conv_frame_to_master[idx]/4.0;
                         pc.printf("%.2f  \t", pixel_data);
                     }
                     pc.printf("\r\n\r\n");
@@ -243,19 +206,46 @@
                 
                 // Increment frame counter
                 frame_idx = frame_idx +1;
-            }
-*/          
-            
-            memcpy(curr_raw_frame_data_to_master, local_curr_raw_frame_data_to_master, sizeof(curr_raw_frame_data_to_master));
-            memcpy(local_prev_raw_frame_data_to_master, local_curr_raw_frame_data_to_master, sizeof(local_curr_raw_frame_data_to_master));
+            //}
+            */
+            memcpy(prev_raw_frame_to_master, curr_raw_frame_to_master, sizeof(curr_raw_frame_to_master));
         #endif
-
+        
+        
         /***************************************************************************
-        * Lora Communications
-        **************************************************************************/
-
+         * Fill Payload Buffer With Data From Sensors for LoRa Transmition
+         **************************************************************************/
+        #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+            memcpy(&BufferTx[tx_idx_signature], PingMsg,           size_signature);
+            memcpy(&BufferTx[tx_idx_ble],       curr_ble_to_slave, size_of_ble);
+        #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+            memcpy(&BufferTx[tx_idx_signature], PongMsg,                  size_signature);
+            memcpy(&BufferTx[tx_idx_grid_eye],  curr_raw_frame_to_master, size_of_grid_eye);
+            memcpy(&BufferTx[tx_idx_gps],       curr_gps_to_master,       size_of_gps);
+            memcpy(&BufferTx[tx_idx_MAX17055],  curr_MAX17055_to_master,  size_of_MAX17055);
+            memcpy(&BufferTx[tx_idx_MAX77650],  curr_MAX77650_to_master,  size_of_MAX77650);
+        #endif
+        
+        
+        
+        /***************************************************************************
+         * Lora Communications
+         **************************************************************************/
         wait_ms( 10 );  
         SX1276PingPong();
+        
+        /***************************************************************************
+         * Fill Global Buffers With Data From Received Payload Buffer
+         **************************************************************************/
+        /* The master and slave devices will have different requirements for offloading payload */
+        #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+            memcpy(curr_raw_frame_from_slave, &BufferRx[rx_idx_grid_eye], size_of_grid_eye);
+            memcpy(curr_gps_from_slave,       &BufferRx[rx_idx_gps],      size_of_gps);
+            memcpy(curr_MAX17055_from_slave,  &BufferRx[rx_idx_MAX17055], size_of_MAX17055);
+            memcpy(curr_MAX77650_from_slave,  &BufferRx[rx_idx_MAX77650], size_of_MAX77650);
+        #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+            memcpy(curr_ble_from_master,      &BufferRx[rx_idx_ble],      size_of_ble);
+        #endif
     
         
         
@@ -264,6 +254,3 @@
     }
     
 }
-
-
-