![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
LP 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
Diff: main.cpp
- Revision:
- 26:69aba05f010f
- Parent:
- 25:1a031add188a
- Child:
- 27:6b549f838f0a
diff -r 1a031add188a -r 69aba05f010f main.cpp --- a/main.cpp Thu Jul 19 21:13:19 2018 +0000 +++ b/main.cpp Fri Jul 20 16:31:41 2018 +0000 @@ -46,6 +46,23 @@ GridEye gridEye(i2cGridEye); #endif + +/*************************************************************************** + * Function Prototypes + **************************************************************************/ +/** + * @brief This function constructs a payload buffer that is used in transmitting data in a LoRa Message + */ +//void fillPayloadWithGlobalBufs(uint8_t * payload_buffer_tx); + +/** + * @brief This function deconstructs a payload buffer that contains data from a received LoRa Message + */ +//void fillGlobalBufsWithPayload(uint8_t * payload_buffer_rx); + +/*************************************************************************** + * main() + **************************************************************************/ int main() { /* @@ -66,10 +83,31 @@ dprintf("MAX32620FTHR: Slave"); #endif - /*************************************************************************** - * Lora Communications - **************************************************************************/ - SX1276PingPongSetup(); + +/*************************************************************************** + * Lora Communication Buffers + **************************************************************************/ + /* Create Buffers to store both incoming and outgoing LoRa communications */ + BufferTx = new uint8_t[BufferSizeTx]; + BufferRx = new uint8_t[BufferSizeRx]; + + + +/*************************************************************************** + * Store Aliases to the buffers created here in main porgram + **************************************************************************/ + +/*************************************************************************** + * 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 @@ -79,6 +117,9 @@ #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 @@ -89,28 +130,30 @@ **************************************************************************/ #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 ) - { + //if( memcmp(prev_raw_frame_data_from_slave, curr_raw_frame_data_from_slave, sizeof(curr_raw_frame_data_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); + // Next Print off the Converted data - dprintf("\r\nFrame %d data: \r\n", frame_idx); + pc.printf("\r\nFrame %d data: \r\n", frame_idx); uint8_t idx; float pixel_data; 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; - dprintf("%.2f \t", pixel_data); + pc.printf("%.2f \t", pixel_data); } - dprintf("\r\n\r\n"); + pc.printf("\r\n\r\n"); } - dprintf("\r\n"); + pc.printf("\r\n"); // 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 @@ -122,13 +165,15 @@ #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(curr_raw_frame_data_to_master); - wait_ms( 1000 ); - - //if ( memcmp(prev_raw_frame_data_to_master, curr_raw_frame_data_to_master, sizeof(curr_raw_frame_data_to_master)) != 0 ) - //{ + 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 ) + { // Convert raw data sent from slave to a 16 bit integer array by calling this - convRaw8x8Data2Point25degC(curr_raw_frame_data_to_master, conv_frame_data_to_master); + convRaw8x8Data2Point25degC(local_curr_raw_frame_data_to_master, local_conv_frame_data_to_master); + + wait_ms(10); // Next Print off the Converted data pc.printf("\r\nFrame %d data: \r\n", frame_idx); @@ -137,7 +182,7 @@ for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { idx = y*8 + x; - pixel_data = conv_frame_data_to_master[idx]/4.0; + pixel_data = local_conv_frame_data_to_master[idx]/4.0; pc.printf("%.2f \t", pixel_data); } pc.printf("\r\n\r\n"); @@ -146,13 +191,22 @@ // Increment frame counter frame_idx = frame_idx +1; - //} - memcpy(prev_raw_frame_data_to_master, curr_raw_frame_data_to_master, sizeof(curr_raw_frame_data_to_master)); + } +*/ + + 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)); #endif /*************************************************************************** * Lora Communications **************************************************************************/ + #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway + dprintf("MAX32630FTHR: Master"); + #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot + memcpy(&BufferTx[tx_idx_signature], PongMsg, size_signature); + memcpy(&BufferTx[tx_idx_grid_eye], local_curr_raw_frame_data_to_master, size_of_grid_eye); + #endif wait_ms( 10 ); SX1276PingPong(); @@ -163,3 +217,42 @@ } } + + + + +/** + * @brief This function constructs a payload buffer that is used in transmitting data in a LoRa Message + */ +void fillPayloadWithGlobalBufs(uint8_t * BufferTx) +{ + /* 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], curr_ble_data_to_slave, size_of_ble); + #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], curr_raw_frame_data_to_master, size_of_grid_eye); + memcpy(&BufferTx[tx_idx_gps], curr_gps_data_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 + return; +} + +/** + * @brief This function deconstructs a payload buffer that contains data from a received LoRa Message + */ +void fillGlobalBufsWithPayload(uint8_t * BufferRx) +{ + /* 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, &BufferRx[rx_idx_grid_eye], size_of_grid_eye); + memcpy(curr_gps_data_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_data_from_master, &BufferRx[rx_idx_ble], size_of_ble); + #endif + return; +} \ No newline at end of file