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

Committer:
dev_alexander
Date:
Fri Jul 20 21:29:53 2018 +0000
Revision:
27:6b549f838f0a
Parent:
26:69aba05f010f
Child:
28:0ed92c590607
Trying to unify how the buffers were loaded and unloaded seemed to have broke how the buffer on the MAX32630FTHR. It was working much better when the buffers were loaded in the main(). I am probably going to revert to the previous method.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dev_alexander 23:f74a50977593 1 /** Description:
dev_alexander 23:f74a50977593 2 * This File is responsible for defining the buffers that will be used in
dev_alexander 23:f74a50977593 3 * various areas of the program. The buffers that are defined here will be
dev_alexander 23:f74a50977593 4 * refferenced in the main.cpp and will be filled with data in one of two ways:
dev_alexander 23:f74a50977593 5 *
dev_alexander 23:f74a50977593 6 * 1. The buffers will be filled with data upon receiving a successful payload
dev_alexander 23:f74a50977593 7 * transmission over LoRa. In GenericPingPong.cpp, the function OnRxDone()
dev_alexander 23:f74a50977593 8 * will call the function fillGlobalBufsWithPayload() that is responsible for
dev_alexander 23:f74a50977593 9 * filling the appropriate buffers with the payload data that was received
dev_alexander 23:f74a50977593 10 * by either the master or slave device by the other device that sent it.
dev_alexander 23:f74a50977593 11 *
dev_alexander 23:f74a50977593 12 * 2. The buffers will be used to fill up a payload buffer that will be sent
dev_alexander 23:f74a50977593 13 * over LoRa by either the master or slave device to the receiving device.
dev_alexander 23:f74a50977593 14 * The function fillPayloadWithGlobalBufs() will use the global buffers that
dev_alexander 23:f74a50977593 15 * are filled with data for various sensors in the main.cpp to construct a
dev_alexander 23:f74a50977593 16 * payload to deliver to the other device when SX1276PingPong() is called
dev_alexander 23:f74a50977593 17 * in file GenericPingPong.cpp.
dev_alexander 23:f74a50977593 18 *
dev_alexander 23:f74a50977593 19 */
dev_alexander 23:f74a50977593 20
dev_alexander 23:f74a50977593 21 #ifndef __GLOBAL_BUFFERS_H__
dev_alexander 27:6b549f838f0a 22 #define __GLOBAL_BUFFERS_H__
dev_alexander 25:1a031add188a 23
dev_alexander 25:1a031add188a 24 #include "mbed.h"
dev_alexander 27:6b549f838f0a 25 #include "global_buffer_declarations.h"
dev_alexander 25:1a031add188a 26 #include "GenericPingPong.h"
dev_alexander 25:1a031add188a 27
dev_alexander 23:f74a50977593 28
dev_alexander 27:6b549f838f0a 29
dev_alexander 23:f74a50977593 30 /***************************************************************************
dev_alexander 24:e8d03912f303 31 * Indexes for which byte specific data begins at in the payload buffer
dev_alexander 23:f74a50977593 32 **************************************************************************/
dev_alexander 25:1a031add188a 33 /* size of ID data that defines what the signature of the device is */
dev_alexander 25:1a031add188a 34 const uint8_t size_signature = 8;
dev_alexander 24:e8d03912f303 35
dev_alexander 24:e8d03912f303 36 /* size of data in bytes that is acquired by the master device */
dev_alexander 25:1a031add188a 37 const uint8_t size_of_ble = 2;
dev_alexander 25:1a031add188a 38
dev_alexander 24:e8d03912f303 39 /* size of data in bytes that is acquired by the slave device */
dev_alexander 24:e8d03912f303 40 const uint8_t size_of_grid_eye = 128;
dev_alexander 24:e8d03912f303 41 const uint8_t size_of_gps = 20;
dev_alexander 24:e8d03912f303 42 const uint8_t size_of_MAX17055 = 5;
dev_alexander 24:e8d03912f303 43 const uint8_t size_of_MAX77650 = 5;
dev_alexander 24:e8d03912f303 44
dev_alexander 25:1a031add188a 45 /* These are the sizes of each payload in bytes. Since there is different amount
dev_alexander 25:1a031add188a 46 * of data being sent in each direction, we need to declare the total size of
dev_alexander 25:1a031add188a 47 * the payload so we can instatiate the correct buffer sizes to store data that
dev_alexander 25:1a031add188a 48 * is to be delivered and for data that is received.
dev_alexander 25:1a031add188a 49 */
dev_alexander 25:1a031add188a 50 const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = size_signature + size_of_ble;
dev_alexander 25:1a031add188a 51 const uint16_t PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER = size_signature + size_of_grid_eye + size_of_gps + size_of_MAX17055 + size_of_MAX77650;
dev_alexander 24:e8d03912f303 52
dev_alexander 26:69aba05f010f 53 /* determine the appropriate buffer sizes for each device in master/slave config */
dev_alexander 26:69aba05f010f 54 #if defined(TARGET_MAX32630FTHR) // Master Device: Bluetooth Gateway
dev_alexander 26:69aba05f010f 55 const uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE;
dev_alexander 26:69aba05f010f 56 const uint16_t BufferSizeRx = PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER;
dev_alexander 26:69aba05f010f 57 #elif defined(TARGET_MAX32620FTHR) // Slave Device: Robot
dev_alexander 26:69aba05f010f 58 const uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER;
dev_alexander 26:69aba05f010f 59 const uint16_t BufferSizeRx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE;
dev_alexander 26:69aba05f010f 60 #endif
dev_alexander 26:69aba05f010f 61
dev_alexander 23:f74a50977593 62 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 24:e8d03912f303 63 /* These are indexs used to create the payload buffer to send to Slave */
dev_alexander 25:1a031add188a 64 const uint8_t tx_idx_signature = 0; // 1st buf in tx payload (begins at byte 0)
dev_alexander 25:1a031add188a 65 const uint8_t tx_idx_ble = tx_idx_signature + size_signature; // 2nd buf in tx payload
dev_alexander 24:e8d03912f303 66
dev_alexander 25:1a031add188a 67 /* These are indexs used to deconstruct received payload buffer sent by the Slave */
dev_alexander 25:1a031add188a 68 const uint8_t rx_idx_signature = 0; // 1st buf in rx payload (begins at byte 0)
dev_alexander 25:1a031add188a 69 const uint8_t rx_idx_grid_eye = rx_idx_signature + size_signature; // 2nd buf in rx payload
dev_alexander 25:1a031add188a 70 const uint8_t rx_idx_gps = rx_idx_grid_eye + size_of_grid_eye; // 3rd buf in rx payload
dev_alexander 25:1a031add188a 71 const uint8_t rx_idx_MAX17055 = rx_idx_gps + size_of_gps; // 4th buf in rx payload
dev_alexander 25:1a031add188a 72 const uint8_t rx_idx_MAX77650 = rx_idx_MAX17055 + size_of_MAX17055; // 5th buf in rx payload
dev_alexander 24:e8d03912f303 73
dev_alexander 23:f74a50977593 74 #elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot
dev_alexander 24:e8d03912f303 75 /* These are indexs used to create the payload buffer to send to Master */
dev_alexander 25:1a031add188a 76 const uint8_t tx_idx_signature = 0; // 1st buf in tx payload (begins at byte 0)
dev_alexander 25:1a031add188a 77 const uint8_t tx_idx_grid_eye = tx_idx_signature + size_signature; // 2nd buf in tx payload
dev_alexander 25:1a031add188a 78 const uint8_t tx_idx_gps = tx_idx_grid_eye + size_of_grid_eye; // 3rd buf in tx payload
dev_alexander 25:1a031add188a 79 const uint8_t tx_idx_MAX17055 = tx_idx_gps + size_of_gps; // 4th buf in tx payload
dev_alexander 25:1a031add188a 80 const uint8_t tx_idx_MAX77650 = tx_idx_MAX17055 + size_of_MAX17055; // 5th buf in tx payload
dev_alexander 24:e8d03912f303 81
dev_alexander 24:e8d03912f303 82 /* These are indexs used to deconstruct received payload buffer sent by the Master */
dev_alexander 25:1a031add188a 83 const uint8_t rx_idx_signature = 0; // 1st buf in rx payload (begins at byte 0)
dev_alexander 25:1a031add188a 84 const uint8_t rx_idx_ble = rx_idx_signature + size_signature; // 2nd buf in rx payload
dev_alexander 23:f74a50977593 85 #endif
dev_alexander 23:f74a50977593 86
dev_alexander 27:6b549f838f0a 87
dev_alexander 27:6b549f838f0a 88
dev_alexander 27:6b549f838f0a 89 #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
dev_alexander 27:6b549f838f0a 90 void createAliasesForGlobalBufs(uint8_t * BufferTx_,
dev_alexander 27:6b549f838f0a 91 uint8_t * BufferRx_,
dev_alexander 27:6b549f838f0a 92 uint8_t * curr_ble_data_to_slave_,
dev_alexander 27:6b549f838f0a 93 char * curr_raw_frame_data_from_slave_,
dev_alexander 27:6b549f838f0a 94 uint8_t * curr_gps_data_from_slave_,
dev_alexander 27:6b549f838f0a 95 uint8_t * curr_MAX17055_from_slave_,
dev_alexander 27:6b549f838f0a 96 uint8_t * curr_MAX77650_from_slave_);
dev_alexander 27:6b549f838f0a 97 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
dev_alexander 27:6b549f838f0a 98 void createAliasesForGlobalBufs(uint8_t * BufferTx_,
dev_alexander 27:6b549f838f0a 99 uint8_t * BufferRx_,
dev_alexander 27:6b549f838f0a 100 uint8_t * curr_ble_data_from_master_,
dev_alexander 27:6b549f838f0a 101 char * curr_raw_frame_data_to_master_,
dev_alexander 27:6b549f838f0a 102 uint8_t * curr_gps_data_to_master_,
dev_alexander 27:6b549f838f0a 103 uint8_t * curr_MAX17055_to_master_,
dev_alexander 27:6b549f838f0a 104 uint8_t * curr_MAX77650_to_master_);
dev_alexander 27:6b549f838f0a 105 #endif
dev_alexander 24:e8d03912f303 106
dev_alexander 24:e8d03912f303 107 /**
dev_alexander 24:e8d03912f303 108 * @brief This function constructs a payload buffer that is used in transmitting data in a LoRa Message
dev_alexander 24:e8d03912f303 109 */
dev_alexander 27:6b549f838f0a 110 void fillPayloadWithGlobalBufs();
dev_alexander 24:e8d03912f303 111
dev_alexander 24:e8d03912f303 112 /**
dev_alexander 24:e8d03912f303 113 * @brief This function deconstructs a payload buffer that contains data from a received LoRa Message
dev_alexander 24:e8d03912f303 114 */
dev_alexander 27:6b549f838f0a 115 void fillGlobalBufsWithPayload();
dev_alexander 24:e8d03912f303 116
dev_alexander 23:f74a50977593 117 #endif // __GLOBAL_BUFFERS_H__