![](/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
global_buffers.h@43:b38b934d82e6, 2018-08-15 (annotated)
- Committer:
- dev_alexander
- Date:
- Wed Aug 15 04:12:27 2018 +0000
- Revision:
- 43:b38b934d82e6
- Parent:
- 41:1381a49e019e
Commit after publishing fork of Adafruit_GFX library
Who changed what in which revision?
User | Revision | Line number | New 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 | 28:0ed92c590607 | 22 | #define __GLOBAL_BUFFERS_H__\ |
dev_alexander | 25:1a031add188a | 23 | |
dev_alexander | 25:1a031add188a | 24 | #include "mbed.h" |
dev_alexander | 25:1a031add188a | 25 | #include "GenericPingPong.h" |
dev_alexander | 25:1a031add188a | 26 | |
dev_alexander | 23:f74a50977593 | 27 | |
dev_alexander | 23:f74a50977593 | 28 | /*************************************************************************** |
dev_alexander | 24:e8d03912f303 | 29 | * Indexes for which byte specific data begins at in the payload buffer |
dev_alexander | 23:f74a50977593 | 30 | **************************************************************************/ |
dev_alexander | 25:1a031add188a | 31 | /* size of ID data that defines what the signature of the device is */ |
dev_alexander | 25:1a031add188a | 32 | const uint8_t size_signature = 8; |
dev_alexander | 24:e8d03912f303 | 33 | |
dev_alexander | 24:e8d03912f303 | 34 | /* size of data in bytes that is acquired by the master device */ |
dev_alexander | 25:1a031add188a | 35 | const uint8_t size_of_ble = 2; |
dev_alexander | 25:1a031add188a | 36 | |
dev_alexander | 24:e8d03912f303 | 37 | /* size of data in bytes that is acquired by the slave device */ |
dev_alexander | 24:e8d03912f303 | 38 | const uint8_t size_of_grid_eye = 128; |
dev_alexander | 24:e8d03912f303 | 39 | const uint8_t size_of_gps = 20; |
dev_alexander | 41:1381a49e019e | 40 | const uint8_t size_of_MAX17055 = 22; |
dev_alexander | 24:e8d03912f303 | 41 | const uint8_t size_of_MAX77650 = 5; |
dev_alexander | 24:e8d03912f303 | 42 | |
dev_alexander | 25:1a031add188a | 43 | /* These are the sizes of each payload in bytes. Since there is different amount |
dev_alexander | 25:1a031add188a | 44 | * of data being sent in each direction, we need to declare the total size of |
dev_alexander | 25:1a031add188a | 45 | * the payload so we can instatiate the correct buffer sizes to store data that |
dev_alexander | 25:1a031add188a | 46 | * is to be delivered and for data that is received. |
dev_alexander | 25:1a031add188a | 47 | */ |
dev_alexander | 28:0ed92c590607 | 48 | |
dev_alexander | 25:1a031add188a | 49 | const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = size_signature + size_of_ble; |
dev_alexander | 25:1a031add188a | 50 | 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 | 51 | |
dev_alexander | 28:0ed92c590607 | 52 | /* determine the appropriate buffer sizes */ |
dev_alexander | 26:69aba05f010f | 53 | #if defined(TARGET_MAX32630FTHR) // Master Device: Bluetooth Gateway |
dev_alexander | 26:69aba05f010f | 54 | const uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE; |
dev_alexander | 26:69aba05f010f | 55 | const uint16_t BufferSizeRx = PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER; |
dev_alexander | 26:69aba05f010f | 56 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: Robot |
dev_alexander | 26:69aba05f010f | 57 | const uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER; |
dev_alexander | 26:69aba05f010f | 58 | const uint16_t BufferSizeRx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE; |
dev_alexander | 26:69aba05f010f | 59 | #endif |
dev_alexander | 26:69aba05f010f | 60 | |
dev_alexander | 23:f74a50977593 | 61 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 24:e8d03912f303 | 62 | /* These are indexs used to create the payload buffer to send to Slave */ |
dev_alexander | 25:1a031add188a | 63 | const uint8_t tx_idx_signature = 0; // 1st buf in tx payload (begins at byte 0) |
dev_alexander | 25:1a031add188a | 64 | const uint8_t tx_idx_ble = tx_idx_signature + size_signature; // 2nd buf in tx payload |
dev_alexander | 24:e8d03912f303 | 65 | |
dev_alexander | 25:1a031add188a | 66 | /* These are indexs used to deconstruct received payload buffer sent by the Slave */ |
dev_alexander | 25:1a031add188a | 67 | const uint8_t rx_idx_signature = 0; // 1st buf in rx payload (begins at byte 0) |
dev_alexander | 25:1a031add188a | 68 | const uint8_t rx_idx_grid_eye = rx_idx_signature + size_signature; // 2nd buf in rx payload |
dev_alexander | 25:1a031add188a | 69 | const uint8_t rx_idx_gps = rx_idx_grid_eye + size_of_grid_eye; // 3rd buf in rx payload |
dev_alexander | 25:1a031add188a | 70 | const uint8_t rx_idx_MAX17055 = rx_idx_gps + size_of_gps; // 4th buf in rx payload |
dev_alexander | 25:1a031add188a | 71 | const uint8_t rx_idx_MAX77650 = rx_idx_MAX17055 + size_of_MAX17055; // 5th buf in rx payload |
dev_alexander | 24:e8d03912f303 | 72 | |
dev_alexander | 23:f74a50977593 | 73 | #elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot |
dev_alexander | 24:e8d03912f303 | 74 | /* These are indexs used to create the payload buffer to send to Master */ |
dev_alexander | 25:1a031add188a | 75 | const uint8_t tx_idx_signature = 0; // 1st buf in tx payload (begins at byte 0) |
dev_alexander | 25:1a031add188a | 76 | const uint8_t tx_idx_grid_eye = tx_idx_signature + size_signature; // 2nd buf in tx payload |
dev_alexander | 25:1a031add188a | 77 | const uint8_t tx_idx_gps = tx_idx_grid_eye + size_of_grid_eye; // 3rd buf in tx payload |
dev_alexander | 25:1a031add188a | 78 | const uint8_t tx_idx_MAX17055 = tx_idx_gps + size_of_gps; // 4th buf in tx payload |
dev_alexander | 25:1a031add188a | 79 | const uint8_t tx_idx_MAX77650 = tx_idx_MAX17055 + size_of_MAX17055; // 5th buf in tx payload |
dev_alexander | 24:e8d03912f303 | 80 | |
dev_alexander | 24:e8d03912f303 | 81 | /* These are indexs used to deconstruct received payload buffer sent by the Master */ |
dev_alexander | 25:1a031add188a | 82 | const uint8_t rx_idx_signature = 0; // 1st buf in rx payload (begins at byte 0) |
dev_alexander | 25:1a031add188a | 83 | const uint8_t rx_idx_ble = rx_idx_signature + size_signature; // 2nd buf in rx payload |
dev_alexander | 23:f74a50977593 | 84 | #endif |
dev_alexander | 23:f74a50977593 | 85 | |
dev_alexander | 27:6b549f838f0a | 86 | |
dev_alexander | 28:0ed92c590607 | 87 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 88 | * BLE Data Buffers |
dev_alexander | 28:0ed92c590607 | 89 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 90 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 91 | static char curr_ble_data_to_slave[size_of_ble]; |
dev_alexander | 28:0ed92c590607 | 92 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 93 | static char curr_ble_data_from_master[size_of_ble]; |
dev_alexander | 28:0ed92c590607 | 94 | static char prev_ble_data_from_master[size_of_ble]; |
dev_alexander | 28:0ed92c590607 | 95 | #endif |
dev_alexander | 27:6b549f838f0a | 96 | |
dev_alexander | 28:0ed92c590607 | 97 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 98 | * Grid Eye Sensor Data Buffers |
dev_alexander | 28:0ed92c590607 | 99 | **************************************************************************/ |
dev_alexander | 27:6b549f838f0a | 100 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 101 | static char curr_raw_frame_data_from_slave[size_of_grid_eye]; |
dev_alexander | 28:0ed92c590607 | 102 | static char prev_raw_frame_data_from_slave[size_of_grid_eye]; |
dev_alexander | 28:0ed92c590607 | 103 | static int16_t conv_frame_data_from_slave[64]; |
dev_alexander | 28:0ed92c590607 | 104 | #elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 105 | static char curr_raw_frame_data_to_master[size_of_grid_eye]; |
dev_alexander | 28:0ed92c590607 | 106 | static char prev_raw_frame_data_to_master[size_of_grid_eye]; |
dev_alexander | 28:0ed92c590607 | 107 | static int16_t conv_frame_data_to_master[64]; |
dev_alexander | 28:0ed92c590607 | 108 | #endif |
dev_alexander | 28:0ed92c590607 | 109 | |
dev_alexander | 28:0ed92c590607 | 110 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 111 | * GPS Data Buffers |
dev_alexander | 28:0ed92c590607 | 112 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 113 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 114 | static char curr_gps_data_from_slave[size_of_gps]; |
dev_alexander | 28:0ed92c590607 | 115 | static char prev_gps_data_from_slave[size_of_gps]; |
dev_alexander | 27:6b549f838f0a | 116 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 117 | static char curr_gps_data_to_master[size_of_gps]; |
dev_alexander | 28:0ed92c590607 | 118 | #endif |
dev_alexander | 28:0ed92c590607 | 119 | |
dev_alexander | 28:0ed92c590607 | 120 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 121 | * MAX17055 Data Buffers |
dev_alexander | 28:0ed92c590607 | 122 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 123 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 124 | static char curr_MAX17055_from_slave[size_of_MAX17055]; |
dev_alexander | 28:0ed92c590607 | 125 | static char prev_MAX17055_from_slave[size_of_MAX17055]; |
dev_alexander | 28:0ed92c590607 | 126 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 127 | static char curr_MAX17055_to_master[size_of_MAX17055]; |
dev_alexander | 28:0ed92c590607 | 128 | #endif |
dev_alexander | 28:0ed92c590607 | 129 | |
dev_alexander | 28:0ed92c590607 | 130 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 131 | * MAX77650 Data Buffers |
dev_alexander | 28:0ed92c590607 | 132 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 133 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 134 | static char curr_MAX77650_from_slave[size_of_MAX77650]; |
dev_alexander | 28:0ed92c590607 | 135 | static char prev_MAX77650_from_slave[size_of_MAX77650]; |
dev_alexander | 28:0ed92c590607 | 136 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 137 | static char curr_MAX77650_to_master[size_of_MAX77650]; |
dev_alexander | 27:6b549f838f0a | 138 | #endif |
dev_alexander | 24:e8d03912f303 | 139 | |
dev_alexander | 24:e8d03912f303 | 140 | /** |
dev_alexander | 24:e8d03912f303 | 141 | * @brief This function constructs a payload buffer that is used in transmitting data in a LoRa Message |
dev_alexander | 24:e8d03912f303 | 142 | */ |
dev_alexander | 28:0ed92c590607 | 143 | void fillPayloadWithGlobalBufs(uint8_t * payload_buffer_tx); |
dev_alexander | 24:e8d03912f303 | 144 | |
dev_alexander | 24:e8d03912f303 | 145 | /** |
dev_alexander | 24:e8d03912f303 | 146 | * @brief This function deconstructs a payload buffer that contains data from a received LoRa Message |
dev_alexander | 24:e8d03912f303 | 147 | */ |
dev_alexander | 28:0ed92c590607 | 148 | void fillGlobalBufsWithPayload(uint8_t * payload_buffer_rx); |
dev_alexander | 24:e8d03912f303 | 149 | |
dev_alexander | 23:f74a50977593 | 150 | #endif // __GLOBAL_BUFFERS_H__ |