![](/media/cache/profiles/profile_pic_for_github_less_than_1MB.jpg.50x50_q85.jpg)
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: main.cpp
- Revision:
- 27:6b549f838f0a
- Parent:
- 26:69aba05f010f
- Child:
- 28:0ed92c590607
diff -r 69aba05f010f -r 6b549f838f0a main.cpp --- a/main.cpp Fri Jul 20 16:31:41 2018 +0000 +++ b/main.cpp Fri Jul 20 21:29:53 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 @@ -48,19 +48,6 @@ /*************************************************************************** - * 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() @@ -82,21 +69,85 @@ #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 */ - BufferTx = new uint8_t[BufferSizeTx]; - BufferRx = new uint8_t[BufferSizeRx]; + 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 **************************************************************************/ @@ -124,14 +175,15 @@ 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_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); @@ -153,15 +205,15 @@ // 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_data_from_slave, curr_raw_frame_data_from_slave, sizeof(curr_raw_frame_data_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 @@ -201,12 +253,7 @@ /*************************************************************************** * 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(); @@ -220,39 +267,3 @@ - -/** - * @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