Team Walter / Mbed OS NonPingPong_PICO_LoRa_LP1

Dependencies:   SX1276GenericLib USBDevice

Fork of NonPingPong_PICO_LoRa_LP1 by Walter Luu

Files at this revision

API Documentation at this revision

Comitter:
walterluu
Date:
Fri Oct 16 23:26:04 2020 +0000
Parent:
7:6264bc5b6421
Commit message:
LP1 code with PingPong removal and 10 second transmission

Changed in this revision

SX1276GenericPingPong/GenericPingPong2.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
diff -r 6264bc5b6421 -r 5ff74d7381dc SX1276GenericPingPong/GenericPingPong2.cpp
--- a/SX1276GenericPingPong/GenericPingPong2.cpp	Fri Oct 16 06:50:04 2020 +0000
+++ b/SX1276GenericPingPong/GenericPingPong2.cpp	Fri Oct 16 23:26:04 2020 +0000
@@ -315,135 +315,135 @@
 /****************************************************************************************************************************************
  * 
  ****************************************************************************************************************************************/
-int SX1276PingPong(void)
-{
-#if   MASTER == 1 // Master Device: Bluetooth Gateway
-    bool isMaster = true;
-#elif SLAVE == 1 // Slave Device: Robot
-	bool isMaster = false;
-#endif
-	
-    switch( State )
-    {
-    case RX:
-//        	*led3 = 0;				// uncommented
-        if( isMaster == true )		// Master Device received payload from Slave
-        {
-            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;    
-//						*led = 0;          // changed to 0
-					if (DEBUG_MESSAGE)
-	                    ad->printf( "...Pong\r\n" );
-                    wait_ms( 10 ); 
-                    Radio->Send( BufferTx, BufferSizeTx );
-                }	// memcmp != 0
-                else // valid reception but not a PONG message
-                {    // Set device as master and start again
-                    isMaster = true;					// new update
-                    Radio->Rx( RX_TIMEOUT_VALUE );
-                }	// end of if memcmp
-            }	// end of if BufferSizeRx > 0
-        }	// end of isMaster == true
-        else		// Slave Device received payload from Master
-        {
-            if( BufferSizeRx > 0 )
-            {
-                if( memcmp(BufferRx, PingMsg, sizeof(PingMsg)) == 0 )
-                {
-//                        *led = !*led;
-//							*led = 0			//changed to 0
-					if (DEBUG_MESSAGE)
-	                    ad->printf( "...Ping\r\n" );
-                    wait_ms( 10 );  
-                    Radio->Send( BufferTx, BufferSizeTx );
-                }
-                else // valid reception but not a PING as expected
-                {    // Set device as slave and start again
-                    isMaster = false;					// new update
-                    Radio->Rx( RX_TIMEOUT_VALUE );
-                }    
-            } // end of if BufferSizeRx > 0
-        } // end of if (isMaster == True), end of checking devices
-        
-        State = LOWPOWER;		// back to LOWPOWER State
-        
-        break;
-    case TX:    
-//            *led3 = 0;		// change to 0
-        if( isMaster == true )  // Master Device
-        {
-            if (DEBUG_MESSAGE)
-	            ad->printf("Ping...\r\n" );
-        }
-        else		// Slave Device
-        {
-            if (DEBUG_MESSAGE)
-	            ad->printf("Pong...\r\n" );
-        }
-        Radio->Rx( RX_TIMEOUT_VALUE );
-        State = LOWPOWER;				// back to LOWPOWER State
-        break;
-    case RX_TIMEOUT:
-        if( isMaster == true )		// Master Device
-        {
-            wait_ms( 10 ); 
-            Radio->Send( BufferTx, BufferSizeTx );
-        }
-        else	// Slave Device
-        {
-            Radio->Rx( RX_TIMEOUT_VALUE );  
-        }             
-        State = LOWPOWER;			// back to LOWPOWER State
-        break;
-    case RX_ERROR:
-        // We have received a Packet with a CRC error, send reply as if packet was correct
-        if( isMaster == true )		// Master Device
-        {
-            // 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			// Slave Device
-        {
-            // Send the next PONG frame
-//            memcpy(BufferTx, PongMsg, sizeof(PongMsg));
-/*
-            for( i = sizeof(PongMsg); i < BufferSizeTx; i++ )
-            {
-                BufferTx[i] = i - sizeof(PongMsg);
-            }
-*/
-            wait_ms( 10 );  
-            Radio->Send( BufferTx, BufferSizeTx );
-        }
-        State = LOWPOWER;		// Back to Low Power State
-        break;
-    case TX_TIMEOUT:
-        Radio->Rx( RX_TIMEOUT_VALUE );
-        State = LOWPOWER;
-        break;
-    case LOWPOWER:
-    	sleep();
-        break;
-    default:
-        State = LOWPOWER;
-        break;
-    }    
-}
+//int SX1276PingPong(void)
+//{
+//#if   MASTER == 1 // Master Device: Bluetooth Gateway
+//    bool isMaster = true;
+//#elif SLAVE == 1 // Slave Device: Robot
+//	bool isMaster = false;
+//#endif
+//	
+//    switch( State )
+//    {
+//    case RX:
+////        	*led3 = 0;				// uncommented
+//        if( isMaster == true )		// Master Device received payload from Slave
+//        {
+//            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;    
+////						*led = 0;          // changed to 0
+//					if (DEBUG_MESSAGE)
+//	                    ad->printf( "...Pong\r\n" );
+//                    wait_ms( 10 ); 
+//                    Radio->Send( BufferTx, BufferSizeTx );
+//                }	// memcmp != 0
+//                else // valid reception but not a PONG message
+//                {    // Set device as master and start again
+//                    isMaster = true;					// new update
+//                    Radio->Rx( RX_TIMEOUT_VALUE );
+//                }	// end of if memcmp
+//            }	// end of if BufferSizeRx > 0
+//        }	// end of isMaster == true
+//        else		// Slave Device received payload from Master
+//        {
+//            if( BufferSizeRx > 0 )
+//            {
+//                if( memcmp(BufferRx, PingMsg, sizeof(PingMsg)) == 0 )
+//                {
+////                        *led = !*led;
+////							*led = 0			//changed to 0
+//					if (DEBUG_MESSAGE)
+//	                    ad->printf( "...Ping\r\n" );
+//                    wait_ms( 10 );  
+//                    Radio->Send( BufferTx, BufferSizeTx );
+//                }
+//                else // valid reception but not a PING as expected
+//                {    // Set device as slave and start again
+//                    isMaster = false;					// new update
+//                    Radio->Rx( RX_TIMEOUT_VALUE );
+//                }    
+//            } // end of if BufferSizeRx > 0
+//        } // end of if (isMaster == True), end of checking devices
+//        
+//        State = LOWPOWER;		// back to LOWPOWER State
+//        
+//        break;
+//    case TX:    
+////            *led3 = 0;		// change to 0
+//        if( isMaster == true )  // Master Device
+//        {
+//            if (DEBUG_MESSAGE)
+//	            ad->printf("Ping...\r\n" );
+//        }
+//        else		// Slave Device
+//        {
+//            if (DEBUG_MESSAGE)
+//	            ad->printf("Pong...\r\n" );
+//        }
+//        Radio->Rx( RX_TIMEOUT_VALUE );
+//        State = LOWPOWER;				// back to LOWPOWER State
+//        break;
+//    case RX_TIMEOUT:
+//        if( isMaster == true )		// Master Device
+//        {
+//            wait_ms( 10 ); 
+//            Radio->Send( BufferTx, BufferSizeTx );
+//        }
+//        else	// Slave Device
+//        {
+//            Radio->Rx( RX_TIMEOUT_VALUE );  
+//        }             
+//        State = LOWPOWER;			// back to LOWPOWER State
+//        break;
+//    case RX_ERROR:
+//        // We have received a Packet with a CRC error, send reply as if packet was correct
+//        if( isMaster == true )		// Master Device
+//        {
+//            // 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			// Slave Device
+//        {
+//            // Send the next PONG frame
+////            memcpy(BufferTx, PongMsg, sizeof(PongMsg));
+///*
+//            for( i = sizeof(PongMsg); i < BufferSizeTx; i++ )
+//            {
+//                BufferTx[i] = i - sizeof(PongMsg);
+//            }
+//*/
+//            wait_ms( 10 );  
+//            Radio->Send( BufferTx, BufferSizeTx );
+//        }
+//        State = LOWPOWER;		// Back to Low Power State
+//        break;
+//    case TX_TIMEOUT:
+//        Radio->Rx( RX_TIMEOUT_VALUE );
+//        State = LOWPOWER;
+//        break;
+//    case LOWPOWER:
+//    	sleep();
+//        break;
+//    default:
+//        State = LOWPOWER;
+//        break;
+//    }    
+//}
 
 
 int TimeOnAirSend(void) {
diff -r 6264bc5b6421 -r 5ff74d7381dc global_buffers.h
--- a/global_buffers.h	Fri Oct 16 06:50:04 2020 +0000
+++ b/global_buffers.h	Fri Oct 16 23:26:04 2020 +0000
@@ -28,35 +28,23 @@
 /***************************************************************************
  * MASTER Device
  **************************************************************************/\
-#define MASTER 1
+//#define MASTER 1
 
 /***************************************************************************
  * SLAVE Device
  **************************************************************************/\
-//#define SLAVE 1
+#define SLAVE 1
 
 
 /***************************************************************************
  * Indexes for which byte specific data begins at in the payload buffer
  **************************************************************************/
 /* size of ID data that defines what the signature of the device is */
-const uint8_t size_signature = 1;
-
-/* size of data in bytes that is acquired by the master device */
-//const uint8_t size_of_ble       = 2;
-//const uint8_t size_of_dum       = 2;
-
-/* size of data in bytes that is acquired by the slave device */
-//const uint8_t size_of_grid_eye  = 128; 
-//const uint8_t size_of_gps       = 20;
-//const uint8_t size_of_MAX17055  = 22;
-//const uint8_t size_of_MAX77650  = 5;
+const uint8_t size_signature = 0;
 
 const uint8_t size_of_MAX30208  = 2;            // temperature data
 const uint8_t size_of_MAX44009  = 2;            // light data
-const uint8_t size_of_MAX20361  = 4;            // AO32 data
-const uint8_t size_of_other  = 0;               // other data
-
+const uint8_t size_of_MAX20361  = 3;            // AO32 data
 
 /* These are the sizes of each payload in bytes. Since there is different amount 
  * of data being sent in each direction, we need to declare the total size of 
@@ -64,20 +52,12 @@
  * is to be delivered and for data that is received. 
  */
 
-const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = size_signature;
+//const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = size_signature;
+const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = 1;                 // can't be zero, will cause internal error
 //const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = 0;
 const uint16_t PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER = size_signature + size_of_MAX30208 + size_of_MAX44009 + size_of_MAX20361;
 
 /* 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;
-//#elif defined(TARGET_MAX32620FTHR) // Slave Device: Robot
-//    const uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER;
-//    const uint16_t BufferSizeRx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE;
-//#endif
-
-/* determine the appropriate buffer sizes */
 #if MASTER == 1     // Master Device 
     const uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE;
     const uint16_t BufferSizeRx = PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER;
@@ -86,91 +66,36 @@
     const uint16_t BufferSizeRx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE;
 #endif    
 
-
-//#if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
-//    /* These are indexs used to create the payload buffer to send to Slave */  
-//    const uint8_t tx_idx_signature = 0;                                   // 1st buf in tx payload (begins at byte 0)
-//    const uint8_t tx_idx_ble       = tx_idx_signature + size_signature;   // 2nd buf in tx payload
-//    
-//    /* These are indexs used to deconstruct received payload buffer sent by the Slave */
-//    const uint8_t rx_idx_signature = 0;                                   // 1st buf in rx payload (begins at byte 0)
-//    const uint8_t rx_idx_grid_eye  = rx_idx_signature + size_signature;   // 2nd buf in rx payload
-//    const uint8_t rx_idx_gps       = rx_idx_grid_eye  + size_of_grid_eye; // 3rd buf in rx payload
-//    const uint8_t rx_idx_MAX17055  = rx_idx_gps       + size_of_gps;      // 4th buf in rx payload
-//    const uint8_t rx_idx_MAX77650  = rx_idx_MAX17055  + size_of_MAX17055; // 5th buf in rx payload
-//        
-//#elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot
-//    /* These are indexs used to create the payload buffer to send to Master */
-//    const uint8_t tx_idx_signature = 0;                                   // 1st buf in tx payload (begins at byte 0)
-//    const uint8_t tx_idx_grid_eye  = tx_idx_signature + size_signature;   // 2nd buf in tx payload
-//    const uint8_t tx_idx_gps       = tx_idx_grid_eye  + size_of_grid_eye; // 3rd buf in tx payload
-//    const uint8_t tx_idx_MAX17055  = tx_idx_gps       + size_of_gps;      // 4th buf in tx payload
-//    const uint8_t tx_idx_MAX77650  = tx_idx_MAX17055  + size_of_MAX17055; // 5th buf in tx payload
-//    
-//    /* These are indexs used to deconstruct received payload buffer sent by the Master */
-//    const uint8_t rx_idx_signature = 0;                                   // 1st buf in rx payload (begins at byte 0)
-//    const uint8_t rx_idx_ble       = rx_idx_signature + size_signature;   // 2nd buf in rx payload
-//#endif
-
 #if   MASTER == 1 // Master Device
     /* These are indexs used to create the payload buffer to send to Slave */  
     const uint8_t tx_idx_signature = 0;                                   // 1st buf in tx payload (begins at byte 0)
-//    const uint8_t tx_idx_dum       = tx_idx_signature + size_signature;   // 2nd buf in tx payload
     
     /* These are indexs used to deconstruct received payload buffer sent by the Slave */
-    const uint8_t rx_idx_signature = 0;                                   // 1st buf in rx payload (begins at byte 0)
-    const uint8_t rx_idx_MAX30208  = rx_idx_signature + size_signature;   // 2nd buf in rx payload
-    const uint8_t rx_idx_MAX44009  = rx_idx_MAX30208  + size_of_MAX30208; // 3rd buf in rx payload
-    const uint8_t rx_idx_MAX20361  = rx_idx_MAX44009  + size_of_MAX44009;      // 4th buf in rx payload
-//    const uint8_t rx_idx_other  = rx_idx_MAX20361  + size_of_MAX20361; // 5th buf in rx payload
+//    const uint8_t rx_idx_signature = 0;                                   // 1st buf in rx payload (begins at byte 0)
+//    const uint8_t rx_idx_MAX30208  = rx_idx_signature + size_signature;   // 2nd buf in rx payload
+//    const uint8_t rx_idx_MAX44009  = rx_idx_MAX30208  + size_of_MAX30208; // 3rd buf in rx payload
+//    const uint8_t rx_idx_MAX20361  = rx_idx_MAX44009  + size_of_MAX44009;      // 4th buf in rx payload
+    
+    const uint8_t rx_idx_MAX30208 = 0;                                      // 1st buf in rx payload (begins at byte 0), temp data
+    const uint8_t rx_idx_MAX44009 = rx_idx_MAX30208 + size_of_MAX30208;     // 2nd buf in rx payload, lux data
+    const uint8_t rx_idx_MAX20361 = rx_idx_MAX44009 + size_of_MAX44009;     // 3rd buf in rx payload, AO32 data
         
 #elif SLAVE == 1 // Slave Device: LoRa Controlled Robot
     /* These are indexs used to create the payload buffer to send to Master */
-    const uint8_t tx_idx_signature = 0;                                   // 1st buf in tx payload (begins at byte 0)
-    const uint8_t tx_idx_MAX30208  = tx_idx_signature + size_signature;   // 2nd buf in tx payload
-    const uint8_t tx_idx_MAX44009  = tx_idx_MAX30208  + size_of_MAX30208; // 3rd buf in tx payload
-    const uint8_t tx_idx_MAX20361  = tx_idx_MAX44009  + size_of_MAX44009 ;      // 4th buf in tx payload
-//    const uint8_t tx_idx_other  = tx_idx_MAX20361  + size_of_MAX20361; // 5th buf in tx payload
+//    const uint8_t tx_idx_signature = 0;                                   // 1st buf in tx payload (begins at byte 0)
+//    const uint8_t tx_idx_MAX30208  = tx_idx_signature + size_signature;   // 2nd buf in tx payload
+//    const uint8_t tx_idx_MAX44009  = tx_idx_MAX30208  + size_of_MAX30208; // 3rd buf in tx payload
+//    const uint8_t tx_idx_MAX20361  = tx_idx_MAX44009  + size_of_MAX44009 ;      // 4th buf in tx payload
+    
+    const uint8_t tx_idx_MAX30208  = 0;                                     // 1st buf in tx payload (begins at byte 0), temp data
+    const uint8_t tx_idx_MAX44009  = tx_idx_MAX30208 + size_of_MAX30208;    // 2nd buf in tx payload, lux data
+    const uint8_t tx_idx_MAX20361  = tx_idx_MAX44009 + size_of_MAX44009;    // 3rd buf in tx payload, AO32 data
     
     /* These are indexs used to deconstruct received payload buffer sent by the Master */
     const uint8_t rx_idx_signature = 0;                                   // 1st buf in rx payload (begins at byte 0)
-//    const uint8_t rx_idx_dum       = rx_idx_signature + size_signature;   // 2nd buf in rx payload
 #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
-
-/***************************************************************************
- * Dummy Data Buffers
- **************************************************************************/
-#if MASTER == 1  // Master Device
-//    static char curr_dum_data_to_slave[size_of_dum];
-#elif SLAVE == 1 // Slave Device
-//    static char curr_dum_data_from_master[size_of_dum];
-//    static char prev_dum_data_from_master[size_of_dum];
-#endif
-
-
-/***************************************************************************
- * Grid Eye Sensor Data Buffers
- **************************************************************************/
-//#if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
-//    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
 
 
 /***************************************************************************
@@ -212,49 +137,6 @@
 //    static int16_t conv_frame_data_to_master[64];
 #endif
 
-/***************************************************************************
- * Other Data Buffers
- **************************************************************************/
-#if   MASTER == 1 // Master Device
-//    static char curr_raw_other_data_from_slave[size_of_other];
-//    static char prev_raw_other_data_from_slave[size_of_other];
-//    static int16_t conv_frame_data_from_slave[64];
-#elif SLAVE == 1 // Slave Device
-//    static char curr_raw_other_data_to_master[size_of_other];
-//    static char prev_raw_other_data_to_master[size_of_other];
-//    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
-//    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
  */
diff -r 6264bc5b6421 -r 5ff74d7381dc main.cpp
--- a/main.cpp	Fri Oct 16 06:50:04 2020 +0000
+++ b/main.cpp	Fri Oct 16 23:26:04 2020 +0000
@@ -31,7 +31,7 @@
 #include "lp.h"
 #include "rtc.h"
 //#include "board.h"      // Cannot find source?
-#define LP1_WakeTime    3 //seconds
+#define LP1_WakeTime    10 //seconds
 
 // Virtual COM related
 #include "USBSerial.h"      // for virtual COM
@@ -165,8 +165,6 @@
         //configure RTC and start for slave
         RTC_Setup();
         
-//        sleep();            // put slave in sleep mode LP2
-        
     #endif
     
      /***************************************************************************
@@ -224,23 +222,6 @@
 //    https://www.tutorialspoint.com/cprogramming/c_pointers.htm
     
     /***************************************************************************
-     * Create Dummy Data For Master and Slave
-     **************************************************************************/
-    
-    #if SLAVE == 1
-//    curr_raw_temp_to_master[0] = 99;
-//    curr_raw_temp_to_master[1] = 99;
-//
-//    curr_raw_light_to_master[0] = 25;
-//    curr_raw_light_to_master[1] = 26;
-//
-//    curr_raw_AO32_to_master[0] = 99;
-//    curr_raw_AO32_to_master[1] = 0;
-//    curr_raw_AO32_to_master[2] = 101;
-//    curr_raw_AO32_to_master[3] = 102;    
-     #endif
-    
-    /***************************************************************************
      * Loop Counter
      **************************************************************************/
     int loopCnt = 0;
@@ -288,9 +269,6 @@
     
     #if SLAVE == 1
     
-    // Slave sleeps before interrupt calls
-//    sleep();
-    
         /***************************************************************************
         * LP1 Experiment
         **************************************************************************/
@@ -369,7 +347,7 @@
         /***************************************************************************
         * Fill Payload Buffer With Data From Main Program Buffers for next LoRa Transmition
         **************************************************************************/
-        memcpy(&BufferTx[tx_idx_signature], PongMsg,                  size_signature);
+//        memcpy(&BufferTx[tx_idx_signature], PongMsg,                  size_signature);
         memcpy(&BufferTx[tx_idx_MAX30208],  curr_raw_temp_to_master, size_of_MAX30208);
         memcpy(&BufferTx[tx_idx_MAX44009],  curr_raw_light_to_master, size_of_MAX44009);
         memcpy(&BufferTx[tx_idx_MAX20361],  curr_raw_AO32_to_master,  size_of_MAX20361);
@@ -379,80 +357,6 @@
         **************************************************************************/
         SX1276SlaveSendData();
     
-        /***************************************************************************
-        * Old scheme for timer interrupt
-        **************************************************************************/
-//    if(get_data_flag) {
-//        
-//        //reset the flag
-//        get_data_flag = false;
-////        pc.printf("Timer interval reached!\r\n");
-//        
-//        /***************************************************************************
-//        * Temperature Sensor Data Measurement
-//        **************************************************************************/
-//        // obtain register hex values
-//        convert_temperature(&i2cBus0, OT07_i2c_add);  //send OW convert selected device
-//        wait_ms(CONVERT_T_DELAY);  //wait 20 ms for convert temperature to complete
-//        int temp_error = OT07_read_register(&i2cBus0, OT07_i2c_add, OT07_FIFO_DATA, rawtempdata, 2); 
-//        double tempFinal = calc_temperature(rawtempdata);
-//        
-//        //fill raw temp data into the array
-//        curr_raw_temp_to_master[0] = rawtempdata[0];
-//        curr_raw_temp_to_master[1] = rawtempdata[1];      
-//        
-//        /***************************************************************************
-//        * Light Intensity Sensor Data Measurement
-//        **************************************************************************/
-//        // obtain register hex values
-//        int lux_error = MAX44009_read_lux_register(&i2cBus0, MAX44009_i2c_add, MAX44009_LUX_HI, rawluxdata);
-//        int luxFinal = (int) (calc_lux(rawluxdata));
-//        
-//        //fill raw lux data into the array
-//        curr_raw_light_to_master[0] = rawluxdata[0];
-//        curr_raw_light_to_master[1] = rawluxdata[1];
-//        
-//        /***************************************************************************
-//        * Solar Harvester Data Measurement
-//        **************************************************************************/
-//        
-//        int ocv_error = AO32_read_register(&i2cBus0, AO32_i2c_add, AO32_VOC, rawOCVdata);
-//        int cnt_error = AO32_read_register(&i2cBus0, AO32_i2c_add, AO32_HARV_H, rawCntdata, 2); // burst read 2 bytes
-//        
-//        //calculate open circuit voltage from data
-////        double voltage = (double)(rawOCVdata[0]) / 100;
-//        double OCVFinal = calc_OCV(rawOCVdata);
-//        
-//        //calculate harvesting counts from data
-//        int countFinal = calc_Harvest(rawCntdata);
-//        
-//        //fill raw AO32 data into the array
-//        curr_raw_AO32_to_master[0] = rawOCVdata[0];         // Fill OCV hex first
-//        curr_raw_AO32_to_master[1] = rawCntdata[0];         // Fill Harvesting count high byte
-//        curr_raw_AO32_to_master[2] = rawCntdata[1];         // Fill Harvesting count low byte
-//        
-//        // print out sensor data
-//         pc.printf("SENSOR: [%.3f] [%d] [%.2f] [%d] [0]\r\n", tempFinal, luxFinal, OCVFinal, countFinal);
-//        
-//        /***************************************************************************
-//        * Fill Payload Buffer With Data From Main Program Buffers for next LoRa Transmition
-//        **************************************************************************/
-//        memcpy(&BufferTx[tx_idx_signature], PongMsg,                  size_signature);
-//        memcpy(&BufferTx[tx_idx_MAX30208],  curr_raw_temp_to_master, size_of_MAX30208);
-//        memcpy(&BufferTx[tx_idx_MAX44009],  curr_raw_light_to_master, size_of_MAX44009);
-//        memcpy(&BufferTx[tx_idx_MAX20361],  curr_raw_AO32_to_master,  size_of_MAX20361);
-//
-//        /***************************************************************************
-//        * LoRa Communication: Send Sensor Data
-//        **************************************************************************/
-////        SX1276PingPong(); 
-//        SX1276SlaveSendData();
-//        loopCnt = loopCnt + 1;
-//    } // end of transmission frequency for slave
-     /***************************************************************************
-        *  End of Old scheme for timer interrupt
-    **************************************************************************/
-    
     #endif                  // end define for Slave    
     
     
@@ -460,7 +364,7 @@
     /***************************************************************************
      * Fill Payload Buffer With Data From Main Program Buffers for next LoRa Transmition
      **************************************************************************/
-    memcpy(&BufferTx[tx_idx_signature], PingMsg,           size_signature);         // no need
+//    memcpy(&BufferTx[tx_idx_signature], PingMsg,           size_signature);         // no need
     
      /***************************************************************************
      * LoRa Communication: Gateway Receive Sensor Data
@@ -472,8 +376,8 @@
     /***************************************************************************
      * Fill Main Program Buffers With Data From Received Payload Buffer
      **************************************************************************/
-    memcpy(ID_of_slave,               &BufferRx[rx_idx_signature], size_signature);
-    memcpy(curr_raw_temp_from_slave, &BufferRx[rx_idx_MAX30208],  size_of_MAX30208);
+//    memcpy(ID_of_slave,               &BufferRx[rx_idx_signature], size_signature);
+    memcpy(curr_raw_temp_from_slave,  &BufferRx[rx_idx_MAX30208],  size_of_MAX30208);
     memcpy(curr_raw_light_from_slave, &BufferRx[rx_idx_MAX44009], size_of_MAX44009);
     memcpy(curr_raw_AO32_from_slave,  &BufferRx[rx_idx_MAX20361],  size_of_MAX20361);
 
@@ -484,18 +388,17 @@
     double tempResult = calc_temperature(curr_raw_temp_from_slave);
     int luxResult = (int) calc_lux(curr_raw_light_from_slave);
     
-    char OCVrawHex[2];
+    char OCVrawHex[1];
     OCVrawHex[0] = curr_raw_AO32_from_slave[0];
-    OCVrawHex[1] = curr_raw_AO32_from_slave[1];
+//    OCVrawHex[1] = curr_raw_AO32_from_slave[1];
     char CntrawHex[2];
-    CntrawHex[0] = curr_raw_AO32_from_slave[2];
-    CntrawHex[1] = curr_raw_AO32_from_slave[3];
+    CntrawHex[0] = curr_raw_AO32_from_slave[1];
+    CntrawHex[1] = curr_raw_AO32_from_slave[2];
     
     double OCVResult = calc_OCV(OCVrawHex);
     int CntResult = calc_Harvest(CntrawHex);
         
     //reset the flag
-    print_data_flag = false;        // no need
     pc.printf("MSG: [%.3f] [%d] [%.2f] [%d] [0]\r\n", tempResult, luxResult, OCVResult, CntResult);
     
     }   // end of SX1276MasterCheckForNewData
@@ -504,8 +407,6 @@
     
     #endif            // end define for Master
         
-//    sleep();        // going back to sleep mode    
-        
     } // end of while(1) loop
         
 }  // end of main()
\ No newline at end of file