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
main.cpp@34:f31a6b53d4ea, 2018-07-31 (annotated)
- Committer:
- dev_alexander
- Date:
- Tue Jul 31 15:51:43 2018 +0000
- Revision:
- 34:f31a6b53d4ea
- Parent:
- 33:52c898aca207
This revisions seems to work fine with the MAX32630FTHR when putc-ing buffer in correct format for processing to do it's thing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Helmut64 | 0:c43b6919ae15 | 1 | /* |
Helmut64 | 17:98f2528e8399 | 2 | * Copyright (c) 2018 HELIOS Software GmbH |
Helmut64 | 0:c43b6919ae15 | 3 | * 30826 Garbsen (Hannover) Germany |
Helmut64 | 0:c43b6919ae15 | 4 | * Licensed under the Apache License, Version 2.0); |
Helmut64 | 0:c43b6919ae15 | 5 | */ |
dev_alexander | 21:1b92cabe8a3b | 6 | |
dev_alexander | 21:1b92cabe8a3b | 7 | /* |
dev_alexander | 21:1b92cabe8a3b | 8 | * For Wiring Instructions, please visit the link below: |
dev_alexander | 21:1b92cabe8a3b | 9 | * https://www.hackster.io/DevinAlex64/getting-started-with-the-max32620fthr-and-lora-f9d8dd\ |
dev_alexander | 21:1b92cabe8a3b | 10 | */ |
dev_alexander | 21:1b92cabe8a3b | 11 | |
dev_alexander | 30:66f9750cc44c | 12 | #include "main.h" |
dev_alexander | 30:66f9750cc44c | 13 | #include "global_buffers.h" |
dev_alexander | 30:66f9750cc44c | 14 | #include "GridEye.h" |
dev_alexander | 34:f31a6b53d4ea | 15 | #include "GPS.h" |
dev_alexander | 32:b108ed6096b0 | 16 | |
dev_alexander | 32:b108ed6096b0 | 17 | #define RASPBERRY_PI |
dev_alexander | 32:b108ed6096b0 | 18 | |
dev_alexander | 23:f74a50977593 | 19 | /* If the board that is compiled is the master device (BLE enabled MAX32630FTHR), |
dev_alexander | 23:f74a50977593 | 20 | * then it needs this library and needs to be configed in order for the device to |
dev_alexander | 23:f74a50977593 | 21 | * work with a 3.3volt output instead of a 1.8 volt output. |
dev_alexander | 23:f74a50977593 | 22 | * |
dev_alexander | 23:f74a50977593 | 23 | * This is only needed for the MAX32630FTHR. The MAX325620FTHR is exampt from this |
dev_alexander | 23:f74a50977593 | 24 | * additional setup in the main program. |
dev_alexander | 23:f74a50977593 | 25 | */ |
dev_alexander | 31:f15747cffb20 | 26 | |
dev_alexander | 32:b108ed6096b0 | 27 | |
dev_alexander | 34:f31a6b53d4ea | 28 | /*************************************************************************** |
dev_alexander | 34:f31a6b53d4ea | 29 | * Create an instance of the MAX32630FTHR related Items. |
dev_alexander | 34:f31a6b53d4ea | 30 | **************************************************************************/ |
dev_alexander | 31:f15747cffb20 | 31 | #if defined(TARGET_MAX32630FTHR) |
dev_alexander | 31:f15747cffb20 | 32 | #include "max32630fthr.h" |
dev_alexander | 31:f15747cffb20 | 33 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
dev_alexander | 31:f15747cffb20 | 34 | |
dev_alexander | 34:f31a6b53d4ea | 35 | |
dev_alexander | 34:f31a6b53d4ea | 36 | |
dev_alexander | 34:f31a6b53d4ea | 37 | /* BLE Related MAX32630FTHR Specific stuff */ |
dev_alexander | 34:f31a6b53d4ea | 38 | #include "ble/BLE.h" |
dev_alexander | 34:f31a6b53d4ea | 39 | //#include "ble/Gap.h" |
dev_alexander | 34:f31a6b53d4ea | 40 | #include "UARTService_custom.h" |
dev_alexander | 34:f31a6b53d4ea | 41 | #include <events/mbed_events.h> |
dev_alexander | 34:f31a6b53d4ea | 42 | |
dev_alexander | 34:f31a6b53d4ea | 43 | DigitalOut led2(LED2); |
dev_alexander | 34:f31a6b53d4ea | 44 | UARTService *uart; |
dev_alexander | 34:f31a6b53d4ea | 45 | |
dev_alexander | 34:f31a6b53d4ea | 46 | #define NEED_CONSOLE_OUTPUT 1 /* Set this if you need debug messages on the console; |
dev_alexander | 34:f31a6b53d4ea | 47 | * it will have an impact on code-size and power consumption. */ |
dev_alexander | 34:f31a6b53d4ea | 48 | |
dev_alexander | 34:f31a6b53d4ea | 49 | #if NEED_CONSOLE_OUTPUT |
dev_alexander | 34:f31a6b53d4ea | 50 | #define DEBUG(STR) { if (uart) uart->write(STR, strlen(STR)); } |
dev_alexander | 34:f31a6b53d4ea | 51 | #define READ(STR) { if (uart) uart->read(STR, strlen(STR)); } |
dev_alexander | 34:f31a6b53d4ea | 52 | |
dev_alexander | 34:f31a6b53d4ea | 53 | #else |
dev_alexander | 34:f31a6b53d4ea | 54 | #define DEBUG(...) /* nothing */ |
dev_alexander | 34:f31a6b53d4ea | 55 | #endif /* #if NEED_CONSOLE_OUTPUT */ |
dev_alexander | 34:f31a6b53d4ea | 56 | |
dev_alexander | 34:f31a6b53d4ea | 57 | //Triggered when the robot is disconnected from the mobile app. |
dev_alexander | 34:f31a6b53d4ea | 58 | void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) |
dev_alexander | 34:f31a6b53d4ea | 59 | { |
dev_alexander | 34:f31a6b53d4ea | 60 | BLE &ble = BLE::Instance(); |
dev_alexander | 34:f31a6b53d4ea | 61 | DEBUG("Disconnected!\n\r"); |
dev_alexander | 34:f31a6b53d4ea | 62 | DEBUG("Restarting the advertising process\n\r"); |
dev_alexander | 34:f31a6b53d4ea | 63 | ble.gap().startAdvertising(); |
dev_alexander | 34:f31a6b53d4ea | 64 | } |
dev_alexander | 34:f31a6b53d4ea | 65 | |
dev_alexander | 34:f31a6b53d4ea | 66 | /* This pointer is needed to reference data in the main program when filling |
dev_alexander | 34:f31a6b53d4ea | 67 | * with data from the BLE |
dev_alexander | 34:f31a6b53d4ea | 68 | */ |
dev_alexander | 34:f31a6b53d4ea | 69 | uint8_t * onDataWritten_curr_ble_to_slave; |
dev_alexander | 34:f31a6b53d4ea | 70 | |
dev_alexander | 34:f31a6b53d4ea | 71 | // Triggered when there is data written |
dev_alexander | 34:f31a6b53d4ea | 72 | void onDataWritten(const GattWriteCallbackParams *params) |
dev_alexander | 34:f31a6b53d4ea | 73 | { |
dev_alexander | 34:f31a6b53d4ea | 74 | //LED1 will be off when button is pressed, and on when button is released. |
dev_alexander | 34:f31a6b53d4ea | 75 | led2 = !led2; |
dev_alexander | 34:f31a6b53d4ea | 76 | uint8_t button_state; |
dev_alexander | 34:f31a6b53d4ea | 77 | uint8_t direction; |
dev_alexander | 31:f15747cffb20 | 78 | |
dev_alexander | 34:f31a6b53d4ea | 79 | /* If there is a valid data sent by the mobile app */ |
dev_alexander | 34:f31a6b53d4ea | 80 | if ((uart != NULL) && (params->handle == uart ->getTXCharacteristicHandle())) { |
dev_alexander | 34:f31a6b53d4ea | 81 | const uint8_t *packet = params->data; |
dev_alexander | 34:f31a6b53d4ea | 82 | button_state = packet[3]; |
dev_alexander | 34:f31a6b53d4ea | 83 | direction = packet[2]; |
dev_alexander | 34:f31a6b53d4ea | 84 | |
dev_alexander | 34:f31a6b53d4ea | 85 | // make parameter to send over Lora |
dev_alexander | 34:f31a6b53d4ea | 86 | onDataWritten_curr_ble_to_slave[0] = direction; |
dev_alexander | 34:f31a6b53d4ea | 87 | onDataWritten_curr_ble_to_slave[1] = button_state; |
dev_alexander | 34:f31a6b53d4ea | 88 | |
dev_alexander | 34:f31a6b53d4ea | 89 | dprintf("direction: %d\n", direction); |
dev_alexander | 34:f31a6b53d4ea | 90 | dprintf("button_state: %d\n", button_state); |
dev_alexander | 34:f31a6b53d4ea | 91 | |
dev_alexander | 31:f15747cffb20 | 92 | } |
dev_alexander | 34:f31a6b53d4ea | 93 | } |
dev_alexander | 34:f31a6b53d4ea | 94 | #endif |
dev_alexander | 34:f31a6b53d4ea | 95 | |
dev_alexander | 32:b108ed6096b0 | 96 | |
dev_alexander | 34:f31a6b53d4ea | 97 | /*************************************************************************** |
dev_alexander | 34:f31a6b53d4ea | 98 | * Create an instance of the Panasonic Grid Eye Sensor (AMG88xx) |
dev_alexander | 34:f31a6b53d4ea | 99 | **************************************************************************/ |
dev_alexander | 34:f31a6b53d4ea | 100 | #if defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway |
dev_alexander | 34:f31a6b53d4ea | 101 | /* No grid eye object needed. The function the master uses to convert the raw |
dev_alexander | 34:f31a6b53d4ea | 102 | * data that is sent over from the slave deevice that contains the data from the |
dev_alexander | 34:f31a6b53d4ea | 103 | * actual grid eye sensor is actually a function that is not part of the grid eye |
dev_alexander | 34:f31a6b53d4ea | 104 | * class. this is due to the fact that the grid eye class requires n i2c bus to |
dev_alexander | 34:f31a6b53d4ea | 105 | * be assigned to a phyiscal sensor. In this case, the library for the Grid Eye |
dev_alexander | 34:f31a6b53d4ea | 106 | * sensor has a support functin that is used to convert data that is aquired from |
dev_alexander | 34:f31a6b53d4ea | 107 | * the grid eye sensor. So it is not supposed to be a class specific function. |
dev_alexander | 34:f31a6b53d4ea | 108 | */ |
dev_alexander | 34:f31a6b53d4ea | 109 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: Robot |
dev_alexander | 34:f31a6b53d4ea | 110 | //Init I2C communications in default I2C bus I2C #1 |
dev_alexander | 34:f31a6b53d4ea | 111 | I2C i2cGridEye(P3_4,P3_5); |
dev_alexander | 34:f31a6b53d4ea | 112 | GridEye gridEye(i2cGridEye); |
dev_alexander | 34:f31a6b53d4ea | 113 | #endif |
dev_alexander | 34:f31a6b53d4ea | 114 | |
dev_alexander | 34:f31a6b53d4ea | 115 | /*************************************************************************** |
dev_alexander | 34:f31a6b53d4ea | 116 | * Create an instance of the Adafruit Ultimate GPS v3 |
dev_alexander | 34:f31a6b53d4ea | 117 | |
dev_alexander | 34:f31a6b53d4ea | 118 | **************************************************************************/ |
dev_alexander | 34:f31a6b53d4ea | 119 | #if defined(TARGET_MAX32620FTHR) |
dev_alexander | 34:f31a6b53d4ea | 120 | GPS gps(P0_1, P0_0, 115200); |
dev_alexander | 30:66f9750cc44c | 121 | #endif |
dev_alexander | 30:66f9750cc44c | 122 | |
Helmut64 | 17:98f2528e8399 | 123 | DigitalOut myled(LED); |
Helmut64 | 0:c43b6919ae15 | 124 | |
dev_alexander | 28:0ed92c590607 | 125 | Serial pc(USBTX, USBRX); |
dev_alexander | 25:1a031add188a | 126 | |
dev_alexander | 23:f74a50977593 | 127 | int main() |
dev_alexander | 23:f74a50977593 | 128 | { |
Helmut64 | 17:98f2528e8399 | 129 | /* |
Helmut64 | 17:98f2528e8399 | 130 | * inits the Serial or USBSerial when available (230400 baud). |
Helmut64 | 17:98f2528e8399 | 131 | * If the serial uart is not is not connected it swiches to USB Serial |
Helmut64 | 17:98f2528e8399 | 132 | * blinking LED means USBSerial detected, waiting for a connect. |
Helmut64 | 17:98f2528e8399 | 133 | * It waits up to 30 seconds for a USB terminal connections |
Helmut64 | 17:98f2528e8399 | 134 | */ |
Helmut64 | 17:98f2528e8399 | 135 | InitSerial(30*1000, &myled); |
Helmut64 | 17:98f2528e8399 | 136 | dprintf("Welcome to the SX1276GenericLib"); |
Helmut64 | 18:d5527ce82e6b | 137 | |
Helmut64 | 17:98f2528e8399 | 138 | dprintf("Starting a simple LoRa PingPong"); |
dev_alexander | 23:f74a50977593 | 139 | |
dev_alexander | 34:f31a6b53d4ea | 140 | /* Setup begins here: */ |
dev_alexander | 34:f31a6b53d4ea | 141 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 34:f31a6b53d4ea | 142 | dprintf("MAX32630FTHR: Master"); |
dev_alexander | 34:f31a6b53d4ea | 143 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 34:f31a6b53d4ea | 144 | dprintf("MAX32620FTHR: Slave"); |
dev_alexander | 34:f31a6b53d4ea | 145 | #endif |
dev_alexander | 26:69aba05f010f | 146 | |
dev_alexander | 23:f74a50977593 | 147 | |
dev_alexander | 23:f74a50977593 | 148 | /*************************************************************************** |
dev_alexander | 23:f74a50977593 | 149 | * Grid Eye Sensor: Non-Buffer Program Variables |
dev_alexander | 23:f74a50977593 | 150 | **************************************************************************/ |
dev_alexander | 23:f74a50977593 | 151 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 23:f74a50977593 | 152 | int frame_idx = 0; |
dev_alexander | 24:e8d03912f303 | 153 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 34:f31a6b53d4ea | 154 | // none yet |
dev_alexander | 34:f31a6b53d4ea | 155 | int frame_idx = 0; |
dev_alexander | 23:f74a50977593 | 156 | #endif |
dev_alexander | 23:f74a50977593 | 157 | |
dev_alexander | 23:f74a50977593 | 158 | |
dev_alexander | 28:0ed92c590607 | 159 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 160 | * Combined Payload Buffers for LoRa Communications |
dev_alexander | 28:0ed92c590607 | 161 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 162 | uint8_t BufferTx[BufferSizeTx]; |
dev_alexander | 28:0ed92c590607 | 163 | uint8_t BufferRx[BufferSizeRx]; |
dev_alexander | 28:0ed92c590607 | 164 | |
dev_alexander | 28:0ed92c590607 | 165 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 166 | * BLE Data Buffers |
dev_alexander | 28:0ed92c590607 | 167 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 168 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 31:f15747cffb20 | 169 | uint8_t curr_ble_to_slave[size_of_ble]; |
dev_alexander | 34:f31a6b53d4ea | 170 | #if defined(COMPILE_BLE) |
dev_alexander | 34:f31a6b53d4ea | 171 | BLE &ble = BLE::Instance(); |
dev_alexander | 34:f31a6b53d4ea | 172 | /* Create alias for the BLE data to be saved in function above that |
dev_alexander | 34:f31a6b53d4ea | 173 | * writes data to this buffer when function onDataWritten is called |
dev_alexander | 34:f31a6b53d4ea | 174 | */ |
dev_alexander | 34:f31a6b53d4ea | 175 | onDataWritten_curr_ble_to_slave = curr_ble_to_slave; |
dev_alexander | 34:f31a6b53d4ea | 176 | |
dev_alexander | 34:f31a6b53d4ea | 177 | /* Initialize BLE */ |
dev_alexander | 34:f31a6b53d4ea | 178 | ble.init(); |
dev_alexander | 34:f31a6b53d4ea | 179 | ble.gap().onDisconnection(disconnectionCallback); |
dev_alexander | 34:f31a6b53d4ea | 180 | ble.gattServer().onDataWritten(onDataWritten); |
dev_alexander | 34:f31a6b53d4ea | 181 | uart = new UARTService(ble); |
dev_alexander | 34:f31a6b53d4ea | 182 | /* setup advertising */ |
dev_alexander | 34:f31a6b53d4ea | 183 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); |
dev_alexander | 34:f31a6b53d4ea | 184 | ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
dev_alexander | 34:f31a6b53d4ea | 185 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, |
dev_alexander | 34:f31a6b53d4ea | 186 | (const uint8_t *)"BLE UART", sizeof("BLE UART") - 1); |
dev_alexander | 34:f31a6b53d4ea | 187 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, |
dev_alexander | 34:f31a6b53d4ea | 188 | (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed)); |
dev_alexander | 34:f31a6b53d4ea | 189 | ble.gap().setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ |
dev_alexander | 34:f31a6b53d4ea | 190 | ble.gap().startAdvertising(); |
dev_alexander | 34:f31a6b53d4ea | 191 | #endif |
dev_alexander | 28:0ed92c590607 | 192 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 193 | uint8_t curr_ble_from_master[size_of_ble]; |
dev_alexander | 28:0ed92c590607 | 194 | uint8_t prev_ble_from_master[size_of_ble]; |
dev_alexander | 28:0ed92c590607 | 195 | #endif |
dev_alexander | 28:0ed92c590607 | 196 | |
dev_alexander | 28:0ed92c590607 | 197 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 198 | * Grid Eye Sensor Data Buffers |
dev_alexander | 28:0ed92c590607 | 199 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 200 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 201 | char curr_raw_frame_from_slave[size_of_grid_eye]; |
dev_alexander | 28:0ed92c590607 | 202 | char prev_raw_frame_from_slave[size_of_grid_eye]; |
dev_alexander | 28:0ed92c590607 | 203 | int16_t conv_frame_from_slave[64]; |
dev_alexander | 28:0ed92c590607 | 204 | #elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 205 | char curr_raw_frame_to_master[size_of_grid_eye]; |
dev_alexander | 28:0ed92c590607 | 206 | char prev_raw_frame_to_master[size_of_grid_eye]; |
dev_alexander | 28:0ed92c590607 | 207 | int16_t conv_frame_to_master[64]; |
dev_alexander | 28:0ed92c590607 | 208 | #endif |
dev_alexander | 28:0ed92c590607 | 209 | |
dev_alexander | 28:0ed92c590607 | 210 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 211 | * GPS Data Buffers |
dev_alexander | 28:0ed92c590607 | 212 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 213 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 214 | uint8_t curr_gps_from_slave[size_of_gps]; |
dev_alexander | 28:0ed92c590607 | 215 | uint8_t prev_gps_from_slave[size_of_gps]; |
dev_alexander | 28:0ed92c590607 | 216 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 217 | uint8_t curr_gps_to_master[size_of_gps]; |
dev_alexander | 28:0ed92c590607 | 218 | #endif |
dev_alexander | 28:0ed92c590607 | 219 | |
dev_alexander | 28:0ed92c590607 | 220 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 221 | * MAX17055 Data Buffers |
dev_alexander | 28:0ed92c590607 | 222 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 223 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 224 | uint8_t curr_MAX17055_from_slave[size_of_MAX17055]; |
dev_alexander | 28:0ed92c590607 | 225 | uint8_t prev_MAX17055_from_slave[size_of_MAX17055]; |
dev_alexander | 28:0ed92c590607 | 226 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 227 | uint8_t curr_MAX17055_to_master[size_of_MAX17055]; |
dev_alexander | 28:0ed92c590607 | 228 | #endif |
dev_alexander | 28:0ed92c590607 | 229 | |
dev_alexander | 28:0ed92c590607 | 230 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 231 | * MAX77650 Data Buffers |
dev_alexander | 28:0ed92c590607 | 232 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 233 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 234 | uint8_t curr_MAX77650_from_slave[size_of_MAX77650]; |
dev_alexander | 28:0ed92c590607 | 235 | uint8_t prev_MAX77650_from_slave[size_of_MAX77650]; |
dev_alexander | 28:0ed92c590607 | 236 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 237 | uint8_t curr_MAX77650_to_master[size_of_MAX77650]; |
dev_alexander | 28:0ed92c590607 | 238 | #endif |
dev_alexander | 28:0ed92c590607 | 239 | |
dev_alexander | 28:0ed92c590607 | 240 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 241 | * Finish Setting up LoRa Radios: This passes in pointers to Buffers to send |
dev_alexander | 28:0ed92c590607 | 242 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 243 | SX1276PingPongSetup(BufferTx, BufferRx); |
dev_alexander | 28:0ed92c590607 | 244 | |
dev_alexander | 22:abca9d17d13d | 245 | while(1) |
dev_alexander | 28:0ed92c590607 | 246 | { |
dev_alexander | 23:f74a50977593 | 247 | /*************************************************************************** |
dev_alexander | 30:66f9750cc44c | 248 | * BLE Radio Data |
dev_alexander | 30:66f9750cc44c | 249 | **************************************************************************/ |
dev_alexander | 30:66f9750cc44c | 250 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 30:66f9750cc44c | 251 | #if defined(COMPILE_BLE) |
dev_alexander | 30:66f9750cc44c | 252 | ble.waitForEvent(); |
dev_alexander | 30:66f9750cc44c | 253 | #endif |
dev_alexander | 30:66f9750cc44c | 254 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 34:f31a6b53d4ea | 255 | // NOTHING YET |
dev_alexander | 30:66f9750cc44c | 256 | #endif |
dev_alexander | 30:66f9750cc44c | 257 | |
dev_alexander | 30:66f9750cc44c | 258 | /*************************************************************************** |
dev_alexander | 23:f74a50977593 | 259 | * Grid Eye Sensor |
dev_alexander | 23:f74a50977593 | 260 | **************************************************************************/ |
dev_alexander | 23:f74a50977593 | 261 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 262 | // Check to see if the contents of the previous scan are the same. If they are different then continue with converting |
dev_alexander | 32:b108ed6096b0 | 263 | #if defined(RASPBERRY_PI) |
dev_alexander | 32:b108ed6096b0 | 264 | if( memcmp(prev_raw_frame_from_slave, curr_raw_frame_from_slave, sizeof(curr_raw_frame_from_slave)) != 0 ) |
dev_alexander | 32:b108ed6096b0 | 265 | { |
dev_alexander | 32:b108ed6096b0 | 266 | /* |
dev_alexander | 32:b108ed6096b0 | 267 | //for (int idx = 0; idx < 8; idx++) |
dev_alexander | 32:b108ed6096b0 | 268 | // pc.printf("%c", ID_of_slave[idx]); |
dev_alexander | 32:b108ed6096b0 | 269 | string grid_eye_msg; |
dev_alexander | 32:b108ed6096b0 | 270 | grid_eye_msg[0]=0x55; |
dev_alexander | 32:b108ed6096b0 | 271 | grid_eye_msg[1]=0xaa; |
dev_alexander | 32:b108ed6096b0 | 272 | for (int idx = 0; idx < 128; idx++) |
dev_alexander | 32:b108ed6096b0 | 273 | grid_eye_msg[idx+2] = (unsigned char)curr_raw_frame_from_slave[idx]; |
dev_alexander | 32:b108ed6096b0 | 274 | pc.printf(grid_eye_msg); |
dev_alexander | 32:b108ed6096b0 | 275 | */ |
dev_alexander | 32:b108ed6096b0 | 276 | char grid_eye_msg[130]; |
dev_alexander | 32:b108ed6096b0 | 277 | grid_eye_msg[0]=0x55; |
dev_alexander | 32:b108ed6096b0 | 278 | grid_eye_msg[1]=0xaa; |
dev_alexander | 32:b108ed6096b0 | 279 | for (int idx = 0; idx < 128; idx++) |
dev_alexander | 32:b108ed6096b0 | 280 | grid_eye_msg[idx+2] = curr_raw_frame_from_slave[idx]; |
dev_alexander | 32:b108ed6096b0 | 281 | //pc.printf(grid_eye_msg); |
dev_alexander | 32:b108ed6096b0 | 282 | for (int idx = 0; idx < 130; idx++) |
dev_alexander | 32:b108ed6096b0 | 283 | pc.putc(grid_eye_msg[idx]); |
dev_alexander | 32:b108ed6096b0 | 284 | } |
dev_alexander | 32:b108ed6096b0 | 285 | #else |
dev_alexander | 32:b108ed6096b0 | 286 | if( memcmp(prev_raw_frame_from_slave, curr_raw_frame_from_slave, sizeof(curr_raw_frame_from_slave)) != 0 ) |
dev_alexander | 32:b108ed6096b0 | 287 | { |
dev_alexander | 32:b108ed6096b0 | 288 | // Convert raw data sent from slave to a 16 bit integer array by calling this |
dev_alexander | 32:b108ed6096b0 | 289 | convRaw8x8Data2Point25degC(curr_raw_frame_from_slave, conv_frame_from_slave); |
dev_alexander | 32:b108ed6096b0 | 290 | |
dev_alexander | 32:b108ed6096b0 | 291 | // Next Print off the Converted data |
dev_alexander | 32:b108ed6096b0 | 292 | pc.printf("\r\nFrame %d data: \r\n", frame_idx); |
dev_alexander | 32:b108ed6096b0 | 293 | uint8_t idx; |
dev_alexander | 32:b108ed6096b0 | 294 | float pixel_data; |
dev_alexander | 32:b108ed6096b0 | 295 | for (int y = 0; y < 8; y++) { |
dev_alexander | 32:b108ed6096b0 | 296 | for (int x = 0; x < 8; x++) { |
dev_alexander | 32:b108ed6096b0 | 297 | idx = y*8 + x; |
dev_alexander | 32:b108ed6096b0 | 298 | pixel_data = ((float)conv_frame_from_slave[idx])/4.0; |
dev_alexander | 32:b108ed6096b0 | 299 | pc.printf("%.2f \t", pixel_data); |
dev_alexander | 32:b108ed6096b0 | 300 | } |
dev_alexander | 32:b108ed6096b0 | 301 | pc.printf("\r\n\r\n"); |
dev_alexander | 23:f74a50977593 | 302 | } |
dev_alexander | 32:b108ed6096b0 | 303 | pc.printf("\r\n"); |
dev_alexander | 32:b108ed6096b0 | 304 | |
dev_alexander | 32:b108ed6096b0 | 305 | // Increment frame counter |
dev_alexander | 32:b108ed6096b0 | 306 | frame_idx = frame_idx +1; |
dev_alexander | 23:f74a50977593 | 307 | } |
dev_alexander | 32:b108ed6096b0 | 308 | #endif |
dev_alexander | 32:b108ed6096b0 | 309 | /* Next copy in data received from current data into buffer used for |
dev_alexander | 32:b108ed6096b0 | 310 | * comparison next time the memcmp above is called. This prevents the |
dev_alexander | 32:b108ed6096b0 | 311 | * program from converting the same raw data aquired by the grid eye |
dev_alexander | 32:b108ed6096b0 | 312 | * sensor on the slave device to the floating point array with the |
dev_alexander | 32:b108ed6096b0 | 313 | * 0.25 degrees celsius precision level when there is not new data. |
dev_alexander | 32:b108ed6096b0 | 314 | */ |
dev_alexander | 32:b108ed6096b0 | 315 | |
dev_alexander | 28:0ed92c590607 | 316 | memcpy(prev_raw_frame_from_slave, curr_raw_frame_from_slave, sizeof(curr_raw_frame_from_slave)); |
dev_alexander | 24:e8d03912f303 | 317 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 23:f74a50977593 | 318 | // Aquire raw data about 8x8 frame from the grid eye sensor in this function call |
dev_alexander | 28:0ed92c590607 | 319 | gridEye.getRaw8x8FrameData(curr_raw_frame_to_master); |
dev_alexander | 32:b108ed6096b0 | 320 | wait_ms( 20 ); |
dev_alexander | 32:b108ed6096b0 | 321 | |
dev_alexander | 32:b108ed6096b0 | 322 | #if defined(DEBUG_GRID_EYE_SLAVE) |
dev_alexander | 32:b108ed6096b0 | 323 | if( memcmp(prev_raw_frame_to_master, curr_raw_frame_to_master, sizeof(curr_raw_frame_to_master)) != 0 ) |
dev_alexander | 32:b108ed6096b0 | 324 | { |
dev_alexander | 32:b108ed6096b0 | 325 | wait_ms( 5 ); |
dev_alexander | 32:b108ed6096b0 | 326 | // Convert raw data sent from slave to a 16 bit integer array by calling this |
dev_alexander | 32:b108ed6096b0 | 327 | convRaw8x8Data2Point25degC(curr_raw_frame_to_master, conv_frame_to_master); |
dev_alexander | 32:b108ed6096b0 | 328 | |
dev_alexander | 32:b108ed6096b0 | 329 | wait_ms( 5 ); |
dev_alexander | 32:b108ed6096b0 | 330 | |
dev_alexander | 32:b108ed6096b0 | 331 | // Next Print off the Converted data |
dev_alexander | 32:b108ed6096b0 | 332 | pc.printf("\r\nFrame %d data: \r\n", frame_idx); |
dev_alexander | 32:b108ed6096b0 | 333 | uint8_t idx; |
dev_alexander | 32:b108ed6096b0 | 334 | float pixel_data; |
dev_alexander | 32:b108ed6096b0 | 335 | for (int y = 0; y < 8; y++) { |
dev_alexander | 32:b108ed6096b0 | 336 | for (int x = 0; x < 8; x++) { |
dev_alexander | 32:b108ed6096b0 | 337 | idx = y*8 + x; |
dev_alexander | 32:b108ed6096b0 | 338 | pixel_data = ((float)conv_frame_to_master[idx])/4.0; |
dev_alexander | 32:b108ed6096b0 | 339 | pc.printf("%.2f \t", pixel_data); |
dev_alexander | 32:b108ed6096b0 | 340 | } |
dev_alexander | 32:b108ed6096b0 | 341 | pc.printf("\r\n\r\n"); |
dev_alexander | 25:1a031add188a | 342 | } |
dev_alexander | 32:b108ed6096b0 | 343 | pc.printf("\r\n"); |
dev_alexander | 32:b108ed6096b0 | 344 | |
dev_alexander | 32:b108ed6096b0 | 345 | // Increment frame counter |
dev_alexander | 32:b108ed6096b0 | 346 | frame_idx = frame_idx +1; |
dev_alexander | 25:1a031add188a | 347 | } |
dev_alexander | 32:b108ed6096b0 | 348 | #endif |
dev_alexander | 33:52c898aca207 | 349 | #if defined(RASPBERRY_PI) |
dev_alexander | 33:52c898aca207 | 350 | if( memcmp(prev_raw_frame_to_master, curr_raw_frame_to_master, sizeof(curr_raw_frame_to_master)) != 0 ) |
dev_alexander | 33:52c898aca207 | 351 | { |
dev_alexander | 33:52c898aca207 | 352 | char grid_eye_msg[130]; |
dev_alexander | 33:52c898aca207 | 353 | grid_eye_msg[0]=0x55; |
dev_alexander | 33:52c898aca207 | 354 | grid_eye_msg[1]=0xaa; |
dev_alexander | 33:52c898aca207 | 355 | for (int idx = 0; idx < 128; idx++) |
dev_alexander | 33:52c898aca207 | 356 | grid_eye_msg[idx+2] = curr_raw_frame_to_master[idx]; |
dev_alexander | 33:52c898aca207 | 357 | //pc.printf(grid_eye_msg); |
dev_alexander | 33:52c898aca207 | 358 | for (int idx = 0; idx < 130; idx++) |
dev_alexander | 33:52c898aca207 | 359 | pc.putc(grid_eye_msg[idx]); |
dev_alexander | 33:52c898aca207 | 360 | } |
dev_alexander | 33:52c898aca207 | 361 | #endif |
dev_alexander | 33:52c898aca207 | 362 | wait_ms( 20 ); |
dev_alexander | 33:52c898aca207 | 363 | memcpy(prev_raw_frame_to_master, curr_raw_frame_to_master, sizeof(curr_raw_frame_to_master)); |
dev_alexander | 31:f15747cffb20 | 364 | #endif |
dev_alexander | 31:f15747cffb20 | 365 | |
dev_alexander | 34:f31a6b53d4ea | 366 | |
dev_alexander | 31:f15747cffb20 | 367 | /*************************************************************************** |
dev_alexander | 31:f15747cffb20 | 368 | * GPS Sensor |
dev_alexander | 31:f15747cffb20 | 369 | **************************************************************************/ |
dev_alexander | 31:f15747cffb20 | 370 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 31:f15747cffb20 | 371 | //None yet |
dev_alexander | 31:f15747cffb20 | 372 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 31:f15747cffb20 | 373 | // The testing hasnt been done yet for the GPS Module. Will do this when more parts come in. |
dev_alexander | 31:f15747cffb20 | 374 | /* |
dev_alexander | 31:f15747cffb20 | 375 | if(gps.sample()){ |
dev_alexander | 31:f15747cffb20 | 376 | pc.printf("%f\t%c\t%f\t%c\t%f\t%f\t%f\n\r",gps.longitude, gps.ns,gps.latitude,gps.ew, gps.alt, gps.geoid, gps.time); |
dev_alexander | 31:f15747cffb20 | 377 | pc.printf("%d:%d:%d",gps.hour,gps.minute,gps.seconed); |
dev_alexander | 31:f15747cffb20 | 378 | } |
dev_alexander | 31:f15747cffb20 | 379 | */ |
dev_alexander | 31:f15747cffb20 | 380 | #endif |
dev_alexander | 28:0ed92c590607 | 381 | |
dev_alexander | 23:f74a50977593 | 382 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 383 | * Fill Payload Buffer With Data From Sensors for LoRa Transmition |
dev_alexander | 28:0ed92c590607 | 384 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 385 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 28:0ed92c590607 | 386 | memcpy(&BufferTx[tx_idx_signature], PingMsg, size_signature); |
dev_alexander | 28:0ed92c590607 | 387 | memcpy(&BufferTx[tx_idx_ble], curr_ble_to_slave, size_of_ble); |
dev_alexander | 28:0ed92c590607 | 388 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 28:0ed92c590607 | 389 | memcpy(&BufferTx[tx_idx_signature], PongMsg, size_signature); |
dev_alexander | 28:0ed92c590607 | 390 | memcpy(&BufferTx[tx_idx_grid_eye], curr_raw_frame_to_master, size_of_grid_eye); |
dev_alexander | 28:0ed92c590607 | 391 | memcpy(&BufferTx[tx_idx_gps], curr_gps_to_master, size_of_gps); |
dev_alexander | 28:0ed92c590607 | 392 | memcpy(&BufferTx[tx_idx_MAX17055], curr_MAX17055_to_master, size_of_MAX17055); |
dev_alexander | 28:0ed92c590607 | 393 | memcpy(&BufferTx[tx_idx_MAX77650], curr_MAX77650_to_master, size_of_MAX77650); |
dev_alexander | 28:0ed92c590607 | 394 | #endif |
dev_alexander | 28:0ed92c590607 | 395 | |
dev_alexander | 28:0ed92c590607 | 396 | |
dev_alexander | 28:0ed92c590607 | 397 | |
dev_alexander | 28:0ed92c590607 | 398 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 399 | * Lora Communications |
dev_alexander | 28:0ed92c590607 | 400 | **************************************************************************/ |
dev_alexander | 25:1a031add188a | 401 | wait_ms( 10 ); |
dev_alexander | 22:abca9d17d13d | 402 | SX1276PingPong(); |
dev_alexander | 28:0ed92c590607 | 403 | |
dev_alexander | 28:0ed92c590607 | 404 | /*************************************************************************** |
dev_alexander | 28:0ed92c590607 | 405 | * Fill Global Buffers With Data From Received Payload Buffer |
dev_alexander | 28:0ed92c590607 | 406 | **************************************************************************/ |
dev_alexander | 28:0ed92c590607 | 407 | /* The master and slave devices will have different requirements for offloading payload */ |
dev_alexander | 28:0ed92c590607 | 408 | #if defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway |
dev_alexander | 34:f31a6b53d4ea | 409 | memcpy(curr_raw_frame_from_slave, &BufferRx[rx_idx_grid_eye], size_of_grid_eye); |
dev_alexander | 34:f31a6b53d4ea | 410 | memcpy(curr_gps_from_slave, &BufferRx[rx_idx_gps], size_of_gps); |
dev_alexander | 34:f31a6b53d4ea | 411 | memcpy(curr_MAX17055_from_slave, &BufferRx[rx_idx_MAX17055], size_of_MAX17055); |
dev_alexander | 34:f31a6b53d4ea | 412 | memcpy(curr_MAX77650_from_slave, &BufferRx[rx_idx_MAX77650], size_of_MAX77650); |
dev_alexander | 28:0ed92c590607 | 413 | #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot |
dev_alexander | 34:f31a6b53d4ea | 414 | memcpy(curr_ble_from_master, &BufferRx[rx_idx_ble], size_of_ble); |
dev_alexander | 28:0ed92c590607 | 415 | #endif |
dev_alexander | 23:f74a50977593 | 416 | |
dev_alexander | 34:f31a6b53d4ea | 417 | |
dev_alexander | 23:f74a50977593 | 418 | |
dev_alexander | 23:f74a50977593 | 419 | |
dev_alexander | 23:f74a50977593 | 420 | |
dev_alexander | 22:abca9d17d13d | 421 | } |
dev_alexander | 22:abca9d17d13d | 422 | |
Helmut64 | 0:c43b6919ae15 | 423 | } |