![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Demonstration program for Multitech System MTDOT-EVB an evaluation board for the mDot LoRa module
Dependencies: DOGS102 ISL29011 MMA845x MPL3115A2 NCP5623B libmDot mbed-rtos mbed
main.cpp@9:ed86d5ae29cc, 2015-11-23 (annotated)
- Committer:
- falingtrea
- Date:
- Mon Nov 23 14:51:32 2015 +0000
- Revision:
- 9:ed86d5ae29cc
- Parent:
- 7:85445a8cc189
1.05 Changed baud rate for debug from 921k to 115k. Added code to support 868 MHz band operation. Added mutex around certain mDot radio commands. Changed network name and passphrase. Changed pb references to sw to match MTDOT-BOX overlay. Changed func...
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
falingtrea | 0:bdd16076aaa5 | 1 | /** |
falingtrea | 0:bdd16076aaa5 | 2 | * @file main.cpp |
falingtrea | 0:bdd16076aaa5 | 3 | * @brief Main application for mDot-EVB demo |
falingtrea | 0:bdd16076aaa5 | 4 | * @author Tim Barr MultiTech Systems Inc. |
falingtrea | 9:ed86d5ae29cc | 5 | * @version 1.05 |
falingtrea | 0:bdd16076aaa5 | 6 | * @see |
falingtrea | 0:bdd16076aaa5 | 7 | * |
falingtrea | 0:bdd16076aaa5 | 8 | * Copyright (c) 2015 |
falingtrea | 0:bdd16076aaa5 | 9 | * |
falingtrea | 0:bdd16076aaa5 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
falingtrea | 0:bdd16076aaa5 | 11 | * you may not use this file except in compliance with the License. |
falingtrea | 0:bdd16076aaa5 | 12 | * You may obtain a copy of the License at |
falingtrea | 0:bdd16076aaa5 | 13 | * |
falingtrea | 0:bdd16076aaa5 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
falingtrea | 0:bdd16076aaa5 | 15 | * |
falingtrea | 0:bdd16076aaa5 | 16 | * Unless required by applicable law or agreed to in writing, software |
falingtrea | 0:bdd16076aaa5 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
falingtrea | 0:bdd16076aaa5 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
falingtrea | 0:bdd16076aaa5 | 19 | * See the License for the specific language governing permissions and |
falingtrea | 0:bdd16076aaa5 | 20 | * limitations under the License. |
falingtrea | 1:ac9595d0f0e7 | 21 | * |
falingtrea | 1:ac9595d0f0e7 | 22 | * 1.01 TAB 7/6/15 Removed NULL pointer from evbAmbientLight creation call. |
falingtrea | 2:75adc72aa6a0 | 23 | * |
falingtrea | 3:68e974f5f532 | 24 | * 1.02 TAB 7/8/15 Send logo to LCD before attempting connection to LoRa network. Added |
falingtrea | 2:75adc72aa6a0 | 25 | * information on setting up for public LoRa network. Moved SW setup to |
falingtrea | 2:75adc72aa6a0 | 26 | * beginning of main. Removed printf call from ISR functions. Added |
falingtrea | 2:75adc72aa6a0 | 27 | * additional checks for exit_program. |
falingtrea | 3:68e974f5f532 | 28 | * |
falingtrea | 3:68e974f5f532 | 29 | * 1.03 TAB 7/15/15 Added threads for push button switch debounce. |
falingtrea | 3:68e974f5f532 | 30 | * |
falingtrea | 4:49d19abdfd04 | 31 | * 1.04 TAB 10/22/15 Fixed format error in temperature print to LCD. Corrected error in |
falingtrea | 4:49d19abdfd04 | 32 | * public netework setup. Swapped \n and \r in prinf calls because |
falingtrea | 4:49d19abdfd04 | 33 | * Windows seems to be picky about the order |
falingtrea | 4:49d19abdfd04 | 34 | * |
falingtrea | 9:ed86d5ae29cc | 35 | * 1.05 TAB 11/17/15 Changed baud rate for debug from 921k to 115k. Added code to support |
falingtrea | 9:ed86d5ae29cc | 36 | * 868 MHz band operation. Added mutex around certain mDot radio commands. |
falingtrea | 9:ed86d5ae29cc | 37 | * Changed network name and passphrase. Changed pb references to sw to |
falingtrea | 9:ed86d5ae29cc | 38 | * match MTDOT-BOX overlay. Changed function of SW1 from end program to |
falingtrea | 9:ed86d5ae29cc | 39 | * cycle through power levels and data rates. |
falingtrea | 0:bdd16076aaa5 | 40 | */ |
falingtrea | 0:bdd16076aaa5 | 41 | |
falingtrea | 0:bdd16076aaa5 | 42 | #include "mbed.h" |
falingtrea | 0:bdd16076aaa5 | 43 | #include "MMA845x.h" |
falingtrea | 0:bdd16076aaa5 | 44 | #include "MPL3115A2.h" |
falingtrea | 0:bdd16076aaa5 | 45 | #include "ISL29011.h" |
falingtrea | 0:bdd16076aaa5 | 46 | #include "NCP5623B.h" |
falingtrea | 0:bdd16076aaa5 | 47 | #include "DOGS102.h" |
falingtrea | 0:bdd16076aaa5 | 48 | #include "font_6x8.h" |
falingtrea | 0:bdd16076aaa5 | 49 | #include "MultiTech_Logo.h" |
falingtrea | 0:bdd16076aaa5 | 50 | #include "mDot.h" |
falingtrea | 0:bdd16076aaa5 | 51 | #include "rtos.h" |
falingtrea | 0:bdd16076aaa5 | 52 | #include <string> |
falingtrea | 0:bdd16076aaa5 | 53 | #include <vector> |
falingtrea | 0:bdd16076aaa5 | 54 | |
falingtrea | 0:bdd16076aaa5 | 55 | enum LED1_COLOR { |
falingtrea | 0:bdd16076aaa5 | 56 | RED = 0, |
falingtrea | 0:bdd16076aaa5 | 57 | GREEN = 1 |
falingtrea | 0:bdd16076aaa5 | 58 | }; |
falingtrea | 0:bdd16076aaa5 | 59 | |
falingtrea | 0:bdd16076aaa5 | 60 | /* |
falingtrea | 0:bdd16076aaa5 | 61 | * union for converting from 32-bit to 4 8-bit values |
falingtrea | 0:bdd16076aaa5 | 62 | */ |
falingtrea | 0:bdd16076aaa5 | 63 | union convert32 { |
falingtrea | 0:bdd16076aaa5 | 64 | int32_t f_s; // convert from signed 32 bit int |
falingtrea | 0:bdd16076aaa5 | 65 | uint32_t f_u; // convert from unsigned 32 bit int |
falingtrea | 0:bdd16076aaa5 | 66 | uint8_t t_u[4]; // convert to 8 bit unsigned array |
falingtrea | 0:bdd16076aaa5 | 67 | }; |
falingtrea | 0:bdd16076aaa5 | 68 | |
falingtrea | 0:bdd16076aaa5 | 69 | /* |
falingtrea | 0:bdd16076aaa5 | 70 | * union for converting from 16- bit to 2 8-bit values |
falingtrea | 0:bdd16076aaa5 | 71 | */ |
falingtrea | 0:bdd16076aaa5 | 72 | union convert16 { |
falingtrea | 0:bdd16076aaa5 | 73 | int16_t f_s; // convert from signed 16 bit int |
falingtrea | 0:bdd16076aaa5 | 74 | uint16_t f_u; // convert from unsigned 16 bit int |
falingtrea | 0:bdd16076aaa5 | 75 | uint8_t t_u[2]; // convert to 8 bit unsigned array |
falingtrea | 0:bdd16076aaa5 | 76 | }; |
falingtrea | 0:bdd16076aaa5 | 77 | |
falingtrea | 0:bdd16076aaa5 | 78 | //DigitalIn mDot02(PA_2); // GPIO/UART_TX |
falingtrea | 0:bdd16076aaa5 | 79 | //DigitalOut mDot03(PA_3); // GPIO/UART_RX |
falingtrea | 0:bdd16076aaa5 | 80 | //DigitalIn mDot04(PA_6); // GPIO/SPI_MISO |
falingtrea | 0:bdd16076aaa5 | 81 | //DigitalIn mDot06(PA_8); // GPIO/I2C_SCL |
falingtrea | 0:bdd16076aaa5 | 82 | //DigitalIn mDot07(PC_9); // GPIO/I2C_SDA |
falingtrea | 0:bdd16076aaa5 | 83 | |
falingtrea | 9:ed86d5ae29cc | 84 | InterruptIn mDot08(PA_12); // GPIO/USB PB SW1 on EVB |
falingtrea | 9:ed86d5ae29cc | 85 | InterruptIn mDot09(PA_11); // GPIO/USB PB SW2 on EVB |
falingtrea | 0:bdd16076aaa5 | 86 | |
falingtrea | 0:bdd16076aaa5 | 87 | //DigitalIn mDot11(PA_7); // GPIO/SPI_MOSI |
falingtrea | 0:bdd16076aaa5 | 88 | |
falingtrea | 0:bdd16076aaa5 | 89 | InterruptIn mDot12(PA_0); // GPIO/UART_CTS PRESSURE_INT2 on EVB |
falingtrea | 0:bdd16076aaa5 | 90 | DigitalOut mDot13(PC_13,1); // GPIO LCD_C/D |
falingtrea | 0:bdd16076aaa5 | 91 | InterruptIn mDot15(PC_1); // GPIO LIGHT_PROX_INT on EVB |
falingtrea | 0:bdd16076aaa5 | 92 | InterruptIn mDot16(PA_1); // GPIO/UART_RTS ACCEL_INT2 on EVB |
falingtrea | 0:bdd16076aaa5 | 93 | DigitalOut mDot17(PA_4,1); // GPIO/SPI_NCS LCD_CS on EVB |
falingtrea | 0:bdd16076aaa5 | 94 | |
falingtrea | 0:bdd16076aaa5 | 95 | //DigitalIn mDot18(PA_5); // GPIO/SPI_SCK |
falingtrea | 0:bdd16076aaa5 | 96 | |
falingtrea | 0:bdd16076aaa5 | 97 | //DigitalInOut mDot19(PB_0,PIN_INPUT,PullNone,0); // GPIO PushPull LED Low=Red High=Green set MODE=INPUT to turn off |
falingtrea | 0:bdd16076aaa5 | 98 | AnalogIn mDot20(PB_1); // GPIO Current Sense Analog in on EVB |
falingtrea | 0:bdd16076aaa5 | 99 | |
falingtrea | 0:bdd16076aaa5 | 100 | Serial debugUART(PA_9, PA_10); // mDot debug UART |
falingtrea | 0:bdd16076aaa5 | 101 | |
falingtrea | 0:bdd16076aaa5 | 102 | //Serial mDotUART(PA_2, PA_3); // mDot external UART mDot02 and mDot03 |
falingtrea | 0:bdd16076aaa5 | 103 | |
falingtrea | 0:bdd16076aaa5 | 104 | I2C mDoti2c(PC_9,PA_8); // mDot External I2C mDot6 and mDot7 |
falingtrea | 0:bdd16076aaa5 | 105 | |
falingtrea | 0:bdd16076aaa5 | 106 | SPI mDotspi(PA_7,PA_6,PA_5); // mDot external SPI mDot11, mDot4, and mDot18 |
falingtrea | 0:bdd16076aaa5 | 107 | |
falingtrea | 2:75adc72aa6a0 | 108 | /* **** replace these values with the proper public or private network settings **** |
falingtrea | 9:ed86d5ae29cc | 109 | * config_network_name and config_network_pass are for private networks. |
falingtrea | 2:75adc72aa6a0 | 110 | */ |
falingtrea | 0:bdd16076aaa5 | 111 | |
falingtrea | 4:49d19abdfd04 | 112 | //Default network server settings |
falingtrea | 9:ed86d5ae29cc | 113 | static std::string config_network_name = "Multitech"; |
falingtrea | 9:ed86d5ae29cc | 114 | static std::string config_network_pass = "Multitech"; |
falingtrea | 9:ed86d5ae29cc | 115 | static uint8_t config_frequency_sub_band = 3; |
falingtrea | 4:49d19abdfd04 | 116 | |
falingtrea | 2:75adc72aa6a0 | 117 | /* config_app_id and config_app_key are for public networks. |
falingtrea | 2:75adc72aa6a0 | 118 | static uint8_t app_id[8] = {0x00,0x01,0x02,0x03,0x0A,0x0B,0x0C,0x0D}; |
falingtrea | 2:75adc72aa6a0 | 119 | std::vector<uint8_t> config_app_id; |
falingtrea | 2:75adc72aa6a0 | 120 | static uint8_t app_key[16] = {0x00,0x01,0x02,0x03,0x0A,0x0B,0x0C,0x0D}; |
falingtrea | 2:75adc72aa6a0 | 121 | std::vector<uint8_t> config_app_key; |
falingtrea | 2:75adc72aa6a0 | 122 | */ |
falingtrea | 2:75adc72aa6a0 | 123 | |
falingtrea | 9:ed86d5ae29cc | 124 | uint8_t result, mdot_freq; |
falingtrea | 9:ed86d5ae29cc | 125 | uint8_t pckt_time = 8; |
falingtrea | 9:ed86d5ae29cc | 126 | uint16_t xmit_delay = 8; |
falingtrea | 0:bdd16076aaa5 | 127 | char data; |
falingtrea | 0:bdd16076aaa5 | 128 | unsigned char test; |
falingtrea | 0:bdd16076aaa5 | 129 | char txtstr[17]; |
falingtrea | 9:ed86d5ae29cc | 130 | int32_t num_whole, mdot_ret, join_delay; |
falingtrea | 0:bdd16076aaa5 | 131 | uint32_t pressure; |
falingtrea | 0:bdd16076aaa5 | 132 | int16_t num_frac; |
falingtrea | 9:ed86d5ae29cc | 133 | uint8_t sf_val = mDot::SF_7; |
falingtrea | 9:ed86d5ae29cc | 134 | uint8_t pwr_val = 11; // dBm |
falingtrea | 0:bdd16076aaa5 | 135 | |
falingtrea | 0:bdd16076aaa5 | 136 | MMA845x_DATA accel_data; |
falingtrea | 0:bdd16076aaa5 | 137 | MPL3115A2_DATA baro_data; |
falingtrea | 0:bdd16076aaa5 | 138 | uint16_t lux_data; |
falingtrea | 0:bdd16076aaa5 | 139 | MMA845x* evbAccel; |
falingtrea | 0:bdd16076aaa5 | 140 | MPL3115A2* evbBaro; |
falingtrea | 0:bdd16076aaa5 | 141 | ISL29011* evbAmbLight; |
falingtrea | 0:bdd16076aaa5 | 142 | NCP5623B* evbBackLight; |
falingtrea | 0:bdd16076aaa5 | 143 | DOGS102* evbLCD; |
falingtrea | 0:bdd16076aaa5 | 144 | mDot* mdot_radio; |
falingtrea | 9:ed86d5ae29cc | 145 | Mutex mdot_mutex; |
falingtrea | 0:bdd16076aaa5 | 146 | |
falingtrea | 0:bdd16076aaa5 | 147 | convert32 convertl; |
falingtrea | 0:bdd16076aaa5 | 148 | convert16 converts; |
falingtrea | 0:bdd16076aaa5 | 149 | |
falingtrea | 3:68e974f5f532 | 150 | // flags for pushbutton debounce code |
falingtrea | 9:ed86d5ae29cc | 151 | bool sw1_low = false; |
falingtrea | 9:ed86d5ae29cc | 152 | bool sw2_low = false; |
falingtrea | 9:ed86d5ae29cc | 153 | bool toggle_text = false; |
falingtrea | 3:68e974f5f532 | 154 | |
falingtrea | 9:ed86d5ae29cc | 155 | void sw1ISR(void); |
falingtrea | 9:ed86d5ae29cc | 156 | void sw2ISR(void); |
falingtrea | 9:ed86d5ae29cc | 157 | void sw1_debounce(void const *args); |
falingtrea | 9:ed86d5ae29cc | 158 | void sw2_debounce(void const *args); |
falingtrea | 3:68e974f5f532 | 159 | Thread* thread_3; |
falingtrea | 0:bdd16076aaa5 | 160 | |
falingtrea | 0:bdd16076aaa5 | 161 | void log_error(mDot* dot, const char* msg, int32_t retval); |
falingtrea | 0:bdd16076aaa5 | 162 | |
falingtrea | 0:bdd16076aaa5 | 163 | void config_pkt_xmit (void const *args); |
falingtrea | 0:bdd16076aaa5 | 164 | |
falingtrea | 0:bdd16076aaa5 | 165 | int main() |
falingtrea | 0:bdd16076aaa5 | 166 | { |
falingtrea | 0:bdd16076aaa5 | 167 | |
falingtrea | 0:bdd16076aaa5 | 168 | std::vector<uint8_t> mdot_data; |
falingtrea | 0:bdd16076aaa5 | 169 | std::vector<uint8_t> mdot_EUI; |
falingtrea | 0:bdd16076aaa5 | 170 | uint16_t i = 0; |
falingtrea | 9:ed86d5ae29cc | 171 | uint8_t j =0; |
falingtrea | 0:bdd16076aaa5 | 172 | |
falingtrea | 9:ed86d5ae29cc | 173 | debugUART.baud(115200); |
falingtrea | 0:bdd16076aaa5 | 174 | // mDotUART.baud(9600); // mdot UART unused but available on external connector |
falingtrea | 0:bdd16076aaa5 | 175 | |
falingtrea | 9:ed86d5ae29cc | 176 | Thread thread_1(sw1_debounce); // threads for de-bouncing pushbutton switches |
falingtrea | 9:ed86d5ae29cc | 177 | Thread thread_2(sw2_debounce); |
falingtrea | 3:68e974f5f532 | 178 | |
falingtrea | 3:68e974f5f532 | 179 | thread_3 = new Thread(config_pkt_xmit); // start thread that sends LoRa packet when SW2 pressed |
falingtrea | 2:75adc72aa6a0 | 180 | |
falingtrea | 1:ac9595d0f0e7 | 181 | evbAccel = new MMA845x(mDoti2c,MMA845x::SA0_VSS); // setup Accelerometer |
falingtrea | 0:bdd16076aaa5 | 182 | evbBaro = new MPL3115A2(mDoti2c); // setup Barometric sensor |
falingtrea | 1:ac9595d0f0e7 | 183 | evbAmbLight = new ISL29011(mDoti2c); // Setup Ambient Light Sensor |
falingtrea | 0:bdd16076aaa5 | 184 | evbBackLight = new NCP5623B(mDoti2c); // setup backlight and LED 2 driver chip |
falingtrea | 1:ac9595d0f0e7 | 185 | evbLCD = new DOGS102(mDotspi, mDot17, mDot13); // setup LCD |
falingtrea | 0:bdd16076aaa5 | 186 | |
falingtrea | 2:75adc72aa6a0 | 187 | /* |
falingtrea | 2:75adc72aa6a0 | 188 | * Setup SW1 as program stop function |
falingtrea | 2:75adc72aa6a0 | 189 | */ |
falingtrea | 2:75adc72aa6a0 | 190 | mDot08.disable_irq(); |
falingtrea | 9:ed86d5ae29cc | 191 | mDot08.fall(&sw1ISR); |
falingtrea | 2:75adc72aa6a0 | 192 | |
falingtrea | 2:75adc72aa6a0 | 193 | /* |
falingtrea | 2:75adc72aa6a0 | 194 | * need to call this function after rise or fall because rise/fall sets |
falingtrea | 2:75adc72aa6a0 | 195 | * mode to PullNone |
falingtrea | 2:75adc72aa6a0 | 196 | */ |
falingtrea | 2:75adc72aa6a0 | 197 | mDot08.mode(PullUp); |
falingtrea | 2:75adc72aa6a0 | 198 | |
falingtrea | 2:75adc72aa6a0 | 199 | mDot08.enable_irq(); |
falingtrea | 2:75adc72aa6a0 | 200 | |
falingtrea | 2:75adc72aa6a0 | 201 | /* |
falingtrea | 2:75adc72aa6a0 | 202 | * Setup SW2 as packet time change |
falingtrea | 2:75adc72aa6a0 | 203 | */ |
falingtrea | 2:75adc72aa6a0 | 204 | mDot09.disable_irq(); |
falingtrea | 9:ed86d5ae29cc | 205 | mDot09.fall(&sw2ISR); |
falingtrea | 2:75adc72aa6a0 | 206 | |
falingtrea | 2:75adc72aa6a0 | 207 | /* |
falingtrea | 2:75adc72aa6a0 | 208 | * need to call this function after rise or fall because rise/fall sets |
falingtrea | 2:75adc72aa6a0 | 209 | * mode to PullNone |
falingtrea | 2:75adc72aa6a0 | 210 | */ |
falingtrea | 2:75adc72aa6a0 | 211 | mDot09.mode(PullUp); |
mfiore | 7:85445a8cc189 | 212 | |
falingtrea | 2:75adc72aa6a0 | 213 | mDot09.enable_irq(); |
falingtrea | 2:75adc72aa6a0 | 214 | |
falingtrea | 2:75adc72aa6a0 | 215 | /* |
falingtrea | 2:75adc72aa6a0 | 216 | * Setting other InterruptIn pins with Pull Ups |
falingtrea | 2:75adc72aa6a0 | 217 | */ |
falingtrea | 2:75adc72aa6a0 | 218 | mDot12.mode(PullUp); |
falingtrea | 2:75adc72aa6a0 | 219 | mDot15.mode(PullUp); |
falingtrea | 2:75adc72aa6a0 | 220 | mDot16.mode(PullUp); |
falingtrea | 2:75adc72aa6a0 | 221 | |
falingtrea | 4:49d19abdfd04 | 222 | printf("font table address %p\r\n",&font_6x8); |
falingtrea | 4:49d19abdfd04 | 223 | printf("bitmap address %p\r\n",&MultiTech_Logo); |
falingtrea | 2:75adc72aa6a0 | 224 | |
falingtrea | 2:75adc72aa6a0 | 225 | // Setup and display logo on LCD |
falingtrea | 2:75adc72aa6a0 | 226 | evbLCD->startUpdate(); |
falingtrea | 2:75adc72aa6a0 | 227 | |
falingtrea | 2:75adc72aa6a0 | 228 | evbLCD->writeBitmap(0,0,MultiTech_Logo); |
falingtrea | 2:75adc72aa6a0 | 229 | |
mfiore | 7:85445a8cc189 | 230 | printf("\r\n setup mdot\r\n"); |
falingtrea | 0:bdd16076aaa5 | 231 | |
falingtrea | 0:bdd16076aaa5 | 232 | // get a mDot handle |
falingtrea | 0:bdd16076aaa5 | 233 | mdot_radio = mDot::getInstance(); |
falingtrea | 0:bdd16076aaa5 | 234 | |
falingtrea | 0:bdd16076aaa5 | 235 | if (mdot_radio) { |
falingtrea | 9:ed86d5ae29cc | 236 | mdot_mutex.lock(); // lock mdot before setting configuration |
falingtrea | 9:ed86d5ae29cc | 237 | |
falingtrea | 0:bdd16076aaa5 | 238 | // reset to default config so we know what state we're in |
falingtrea | 0:bdd16076aaa5 | 239 | mdot_radio->resetConfig(); |
falingtrea | 0:bdd16076aaa5 | 240 | |
falingtrea | 0:bdd16076aaa5 | 241 | // Setting up LED1 as activity LED |
falingtrea | 0:bdd16076aaa5 | 242 | mdot_radio->setActivityLedPin(PB_0); |
falingtrea | 0:bdd16076aaa5 | 243 | mdot_radio->setActivityLedEnable(true); |
falingtrea | 0:bdd16076aaa5 | 244 | |
falingtrea | 9:ed86d5ae29cc | 245 | // Read node ID and frequency band |
falingtrea | 0:bdd16076aaa5 | 246 | mdot_EUI = mdot_radio->getDeviceId(); |
falingtrea | 9:ed86d5ae29cc | 247 | mdot_freq = mdot_radio->getFrequencyBand(); |
falingtrea | 9:ed86d5ae29cc | 248 | |
falingtrea | 0:bdd16076aaa5 | 249 | printf("mDot EUI = "); |
falingtrea | 0:bdd16076aaa5 | 250 | |
falingtrea | 0:bdd16076aaa5 | 251 | for (i=0; i<mdot_EUI.size(); i++) { |
falingtrea | 0:bdd16076aaa5 | 252 | printf("%02x ", mdot_EUI[i]); |
falingtrea | 0:bdd16076aaa5 | 253 | } |
falingtrea | 4:49d19abdfd04 | 254 | printf("\r\n"); |
falingtrea | 9:ed86d5ae29cc | 255 | sprintf(txtstr,"MTDOT EVB"); |
falingtrea | 9:ed86d5ae29cc | 256 | printf("mDot Frequency = "); |
falingtrea | 9:ed86d5ae29cc | 257 | if (mdot_freq == mDot::FB_868) { |
falingtrea | 9:ed86d5ae29cc | 258 | printf( "868 MHz\r\n"); |
falingtrea | 9:ed86d5ae29cc | 259 | sprintf(txtstr,"%s 868 MHz",txtstr); |
falingtrea | 9:ed86d5ae29cc | 260 | } else { |
falingtrea | 9:ed86d5ae29cc | 261 | printf("915 MHz\r\n"); |
falingtrea | 9:ed86d5ae29cc | 262 | sprintf(txtstr,"%s 915 MHz",txtstr); |
falingtrea | 9:ed86d5ae29cc | 263 | } |
falingtrea | 9:ed86d5ae29cc | 264 | |
falingtrea | 9:ed86d5ae29cc | 265 | evbLCD->writeText(0,3,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 9:ed86d5ae29cc | 266 | sprintf(txtstr,"Sensor Demo"); |
falingtrea | 9:ed86d5ae29cc | 267 | evbLCD->writeText(24,4,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 9:ed86d5ae29cc | 268 | |
falingtrea | 9:ed86d5ae29cc | 269 | evbLCD->endUpdate(); |
falingtrea | 0:bdd16076aaa5 | 270 | |
falingtrea | 0:bdd16076aaa5 | 271 | |
falingtrea | 2:75adc72aa6a0 | 272 | // Setting up the mDot with network information. |
falingtrea | 2:75adc72aa6a0 | 273 | |
mfiore | 7:85445a8cc189 | 274 | /* |
mfiore | 7:85445a8cc189 | 275 | * This call sets up private or public mode on the MTDOT. Set the function to true if |
mfiore | 7:85445a8cc189 | 276 | * connecting to a public network |
mfiore | 7:85445a8cc189 | 277 | */ |
mfiore | 7:85445a8cc189 | 278 | printf("setting Private Network Mode\r\n"); |
mfiore | 7:85445a8cc189 | 279 | if ((mdot_ret = mdot_radio->setPublicNetwork(false)) != mDot::MDOT_OK) { |
mfiore | 7:85445a8cc189 | 280 | log_error(mdot_radio, "failed to set Public Network Mode", mdot_ret); |
mfiore | 7:85445a8cc189 | 281 | } |
falingtrea | 2:75adc72aa6a0 | 282 | |
mfiore | 7:85445a8cc189 | 283 | /* |
mfiore | 7:85445a8cc189 | 284 | * Frequency sub-band is valid for NAM only and for Private networks should be set to a value |
mfiore | 7:85445a8cc189 | 285 | * between 1-8 that matches the the LoRa gateway setting. Public networks use sub-band 0 only. |
mfiore | 7:85445a8cc189 | 286 | * This function can be commented out for EU networks |
mfiore | 7:85445a8cc189 | 287 | */ |
falingtrea | 9:ed86d5ae29cc | 288 | if (mdot_freq == mDot::FB_915) { |
falingtrea | 9:ed86d5ae29cc | 289 | printf("setting frequency sub band\r\n"); |
falingtrea | 9:ed86d5ae29cc | 290 | if ((mdot_ret = mdot_radio->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) { |
falingtrea | 9:ed86d5ae29cc | 291 | log_error(mdot_radio, "failed to set frequency sub band", mdot_ret); |
falingtrea | 9:ed86d5ae29cc | 292 | } |
falingtrea | 0:bdd16076aaa5 | 293 | } |
falingtrea | 0:bdd16076aaa5 | 294 | |
mfiore | 7:85445a8cc189 | 295 | /* |
mfiore | 7:85445a8cc189 | 296 | * setNetworkName is used for private networks. |
mfiore | 7:85445a8cc189 | 297 | * Use setNetworkID(AppID) for public networks |
mfiore | 7:85445a8cc189 | 298 | */ |
falingtrea | 2:75adc72aa6a0 | 299 | |
falingtrea | 2:75adc72aa6a0 | 300 | // config_app_id.assign(app_id,app_id+7); |
falingtrea | 2:75adc72aa6a0 | 301 | |
falingtrea | 0:bdd16076aaa5 | 302 | printf("setting network name\r\n"); |
falingtrea | 0:bdd16076aaa5 | 303 | if ((mdot_ret = mdot_radio->setNetworkName(config_network_name)) != mDot::MDOT_OK) { |
falingtrea | 4:49d19abdfd04 | 304 | // if ((mdot_ret = mdot_radio->setNetworkId(config_app_id)) != mDot::MDOT_OK) { |
falingtrea | 0:bdd16076aaa5 | 305 | log_error(mdot_radio, "failed to set network name", mdot_ret); |
falingtrea | 0:bdd16076aaa5 | 306 | } |
falingtrea | 0:bdd16076aaa5 | 307 | |
mfiore | 7:85445a8cc189 | 308 | /* |
mfiore | 7:85445a8cc189 | 309 | * setNetworkPassphrase is used for private networks |
mfiore | 7:85445a8cc189 | 310 | * Use setNetworkKey for public networks |
mfiore | 7:85445a8cc189 | 311 | */ |
falingtrea | 2:75adc72aa6a0 | 312 | |
falingtrea | 2:75adc72aa6a0 | 313 | // config_app_key.assign(app_key,app_key+15); |
falingtrea | 2:75adc72aa6a0 | 314 | |
falingtrea | 0:bdd16076aaa5 | 315 | printf("setting network password\r\n"); |
falingtrea | 0:bdd16076aaa5 | 316 | if ((mdot_ret = mdot_radio->setNetworkPassphrase(config_network_pass)) != mDot::MDOT_OK) { |
falingtrea | 2:75adc72aa6a0 | 317 | // if ((mdot_ret = mdot_radio->setNetworkKey(config_app_key)) != mDot::MDOT_OK) { |
falingtrea | 0:bdd16076aaa5 | 318 | log_error(mdot_radio, "failed to set network password", mdot_ret); |
falingtrea | 0:bdd16076aaa5 | 319 | } |
falingtrea | 0:bdd16076aaa5 | 320 | |
falingtrea | 9:ed86d5ae29cc | 321 | /* |
falingtrea | 9:ed86d5ae29cc | 322 | * Setting TX power for radio. Max allowed is +14dBm for EU and +20 dBm for NAM. Default is +11 dBm |
falingtrea | 9:ed86d5ae29cc | 323 | */ |
falingtrea | 9:ed86d5ae29cc | 324 | printf("setting TX Power Level to %2d dBm\r\n", pwr_val); |
falingtrea | 9:ed86d5ae29cc | 325 | if ((mdot_ret = mdot_radio->setTxPower(pwr_val)) != mDot::MDOT_OK) { |
falingtrea | 9:ed86d5ae29cc | 326 | log_error(mdot_radio, "failed to set TX power level", mdot_ret); |
falingtrea | 0:bdd16076aaa5 | 327 | } |
falingtrea | 2:75adc72aa6a0 | 328 | |
falingtrea | 2:75adc72aa6a0 | 329 | /* |
falingtrea | 9:ed86d5ae29cc | 330 | * Setting TX data rate for radio. Max allowed is SF_12 for EU and SF10 dBm for NAM. Default is SF_9 |
falingtrea | 2:75adc72aa6a0 | 331 | */ |
falingtrea | 9:ed86d5ae29cc | 332 | printf("setting TX data rate to SF_7\r\n"); |
falingtrea | 9:ed86d5ae29cc | 333 | if ((mdot_ret = mdot_radio->setTxDataRate(sf_val)) != mDot::MDOT_OK) { |
falingtrea | 9:ed86d5ae29cc | 334 | log_error(mdot_radio, "failed to set TX data rate", mdot_ret); |
falingtrea | 2:75adc72aa6a0 | 335 | } |
falingtrea | 2:75adc72aa6a0 | 336 | |
falingtrea | 9:ed86d5ae29cc | 337 | mdot_mutex.unlock(); // unlock mdot mutex before join attempt so SW1 can work |
falingtrea | 9:ed86d5ae29cc | 338 | |
falingtrea | 9:ed86d5ae29cc | 339 | // attempt to join the network |
falingtrea | 9:ed86d5ae29cc | 340 | printf("joining network\r\n"); |
falingtrea | 9:ed86d5ae29cc | 341 | do { |
falingtrea | 9:ed86d5ae29cc | 342 | mdot_mutex.lock(); // lock mdot mutex before join attempt |
falingtrea | 9:ed86d5ae29cc | 343 | mdot_ret = mdot_radio->joinNetwork(); |
falingtrea | 9:ed86d5ae29cc | 344 | mdot_mutex.unlock(); // unlock mdot mutex after join attempt so SW1 can work |
falingtrea | 9:ed86d5ae29cc | 345 | |
falingtrea | 9:ed86d5ae29cc | 346 | if (mdot_ret != mDot::MDOT_OK) { |
falingtrea | 9:ed86d5ae29cc | 347 | log_error(mdot_radio,"failed to join network:", mdot_ret); |
falingtrea | 9:ed86d5ae29cc | 348 | |
falingtrea | 9:ed86d5ae29cc | 349 | if (toggle_text) |
falingtrea | 9:ed86d5ae29cc | 350 | sprintf(txtstr," > Join Failed <"); |
falingtrea | 9:ed86d5ae29cc | 351 | else |
falingtrea | 9:ed86d5ae29cc | 352 | sprintf(txtstr," < Join Failed >"); |
falingtrea | 9:ed86d5ae29cc | 353 | |
falingtrea | 9:ed86d5ae29cc | 354 | evbLCD->writeText(0,5,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 9:ed86d5ae29cc | 355 | |
falingtrea | 9:ed86d5ae29cc | 356 | if (mdot_radio->getFrequencyBand() == mDot::FB_868) { |
falingtrea | 9:ed86d5ae29cc | 357 | join_delay = mdot_radio->getNextTxMs(); |
falingtrea | 9:ed86d5ae29cc | 358 | } else { |
falingtrea | 9:ed86d5ae29cc | 359 | join_delay = 10; |
falingtrea | 9:ed86d5ae29cc | 360 | } |
falingtrea | 9:ed86d5ae29cc | 361 | printf("delay = %lu\r\n",join_delay); |
falingtrea | 9:ed86d5ae29cc | 362 | osDelay(join_delay + 1); |
falingtrea | 9:ed86d5ae29cc | 363 | toggle_text = !toggle_text; |
falingtrea | 9:ed86d5ae29cc | 364 | } |
falingtrea | 9:ed86d5ae29cc | 365 | /* |
falingtrea | 9:ed86d5ae29cc | 366 | * Setting TX power and Data Rate for radio just in case user requested by SW2 |
falingtrea | 9:ed86d5ae29cc | 367 | */ |
falingtrea | 9:ed86d5ae29cc | 368 | mdot_mutex.lock(); // lock mdot mutex before setting change |
falingtrea | 9:ed86d5ae29cc | 369 | mdot_radio->setTxPower(pwr_val); |
falingtrea | 9:ed86d5ae29cc | 370 | mdot_radio->setTxDataRate(sf_val); |
falingtrea | 9:ed86d5ae29cc | 371 | mdot_mutex.unlock(); // unlock mdot mutex after settings change |
falingtrea | 9:ed86d5ae29cc | 372 | |
falingtrea | 9:ed86d5ae29cc | 373 | } while (mdot_ret != mDot::MDOT_OK); |
falingtrea | 9:ed86d5ae29cc | 374 | |
falingtrea | 9:ed86d5ae29cc | 375 | sprintf(txtstr,"*Network Joined*"); |
falingtrea | 9:ed86d5ae29cc | 376 | evbLCD->writeText(0,5,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 9:ed86d5ae29cc | 377 | |
falingtrea | 0:bdd16076aaa5 | 378 | } else { |
falingtrea | 9:ed86d5ae29cc | 379 | sprintf(txtstr,"Radio Init Failed!"); |
falingtrea | 9:ed86d5ae29cc | 380 | evbLCD->writeText(0,5,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 9:ed86d5ae29cc | 381 | printf("%s\r\n",txtstr); |
falingtrea | 9:ed86d5ae29cc | 382 | exit(1); |
falingtrea | 0:bdd16076aaa5 | 383 | } |
falingtrea | 0:bdd16076aaa5 | 384 | |
falingtrea | 0:bdd16076aaa5 | 385 | osDelay(200); |
falingtrea | 0:bdd16076aaa5 | 386 | evbBackLight->setPWM(NCP5623B::LED_3,16); // enable LED2 on EVB and set to 50% PWM |
falingtrea | 0:bdd16076aaa5 | 387 | |
falingtrea | 2:75adc72aa6a0 | 388 | // sets LED2 to 50% max current |
falingtrea | 0:bdd16076aaa5 | 389 | evbBackLight->setLEDCurrent(16); |
falingtrea | 0:bdd16076aaa5 | 390 | |
falingtrea | 4:49d19abdfd04 | 391 | printf("Start of Test\r\n"); |
falingtrea | 0:bdd16076aaa5 | 392 | |
falingtrea | 2:75adc72aa6a0 | 393 | osDelay (500); // allows other threads to process |
falingtrea | 4:49d19abdfd04 | 394 | printf("shutdown LED:\r\n"); |
falingtrea | 2:75adc72aa6a0 | 395 | evbBackLight->shutdown(); |
falingtrea | 0:bdd16076aaa5 | 396 | |
falingtrea | 0:bdd16076aaa5 | 397 | osDelay (500); // allows other threads to process |
falingtrea | 4:49d19abdfd04 | 398 | printf("Turn on LED2\r\n"); |
falingtrea | 0:bdd16076aaa5 | 399 | evbBackLight->setLEDCurrent(16); |
falingtrea | 0:bdd16076aaa5 | 400 | |
falingtrea | 0:bdd16076aaa5 | 401 | data = evbAccel->getWhoAmI(); |
falingtrea | 4:49d19abdfd04 | 402 | printf("Accelerometer who_am_i value = %x \r\n", data); |
falingtrea | 0:bdd16076aaa5 | 403 | |
falingtrea | 0:bdd16076aaa5 | 404 | result = evbAccel->getStatus(); |
falingtrea | 4:49d19abdfd04 | 405 | printf("status byte = %x \r\n", result); |
falingtrea | 0:bdd16076aaa5 | 406 | |
falingtrea | 4:49d19abdfd04 | 407 | printf("Barometer who_am_i check = %s \r\n", evbBaro->testWhoAmI() ? "TRUE" : "FALSE"); |
falingtrea | 0:bdd16076aaa5 | 408 | |
falingtrea | 0:bdd16076aaa5 | 409 | result = evbBaro->getStatus(); |
falingtrea | 4:49d19abdfd04 | 410 | printf("status byte = %x \r\n", result); |
falingtrea | 0:bdd16076aaa5 | 411 | |
falingtrea | 0:bdd16076aaa5 | 412 | /* |
falingtrea | 0:bdd16076aaa5 | 413 | * Setup the Accelerometer for 8g range, 14 bit resolution, Noise reduction off, sample rate 1.56 Hz |
falingtrea | 0:bdd16076aaa5 | 414 | * normal oversample mode, High pass filter off |
falingtrea | 0:bdd16076aaa5 | 415 | */ |
falingtrea | 0:bdd16076aaa5 | 416 | evbAccel->setCommonParameters(MMA845x::RANGE_8g,MMA845x::RES_MAX,MMA845x::LN_OFF, |
falingtrea | 0:bdd16076aaa5 | 417 | MMA845x::DR_1_56,MMA845x::OS_NORMAL,MMA845x::HPF_OFF ); |
falingtrea | 0:bdd16076aaa5 | 418 | |
falingtrea | 0:bdd16076aaa5 | 419 | /* |
falingtrea | 0:bdd16076aaa5 | 420 | * Setup the Barometric sensor for post processed Ambient pressure, 4 samples per data acquisition. |
falingtrea | 0:bdd16076aaa5 | 421 | * and a sample taken every second when in active mode |
falingtrea | 0:bdd16076aaa5 | 422 | */ |
falingtrea | 0:bdd16076aaa5 | 423 | evbBaro->setParameters(MPL3115A2::DATA_NORMAL, MPL3115A2::DM_BAROMETER, MPL3115A2::OR_16, |
falingtrea | 0:bdd16076aaa5 | 424 | MPL3115A2::AT_1); |
falingtrea | 0:bdd16076aaa5 | 425 | /* |
falingtrea | 0:bdd16076aaa5 | 426 | * Setup the Ambient Light Sensor for continuous Ambient Light Sensing, 16 bit resolution, |
falingtrea | 0:bdd16076aaa5 | 427 | * and 16000 lux range |
falingtrea | 0:bdd16076aaa5 | 428 | */ |
falingtrea | 0:bdd16076aaa5 | 429 | |
falingtrea | 0:bdd16076aaa5 | 430 | evbAmbLight->setMode(ISL29011::ALS_CONT); |
falingtrea | 0:bdd16076aaa5 | 431 | evbAmbLight->setResolution(ISL29011::ADC_16BIT); |
falingtrea | 0:bdd16076aaa5 | 432 | evbAmbLight->setRange(ISL29011::RNG_16000); |
falingtrea | 0:bdd16076aaa5 | 433 | |
falingtrea | 0:bdd16076aaa5 | 434 | /* |
falingtrea | 0:bdd16076aaa5 | 435 | * Set the accelerometer for active mode |
falingtrea | 0:bdd16076aaa5 | 436 | */ |
falingtrea | 0:bdd16076aaa5 | 437 | evbAccel->activeMode(); |
falingtrea | 0:bdd16076aaa5 | 438 | |
falingtrea | 0:bdd16076aaa5 | 439 | /* |
falingtrea | 0:bdd16076aaa5 | 440 | * Clear the min-max registers in the Barometric Sensor |
falingtrea | 0:bdd16076aaa5 | 441 | */ |
falingtrea | 0:bdd16076aaa5 | 442 | evbBaro->clearMinMaxRegs(); |
falingtrea | 0:bdd16076aaa5 | 443 | |
falingtrea | 0:bdd16076aaa5 | 444 | evbBackLight->setLEDCurrent(0); |
falingtrea | 0:bdd16076aaa5 | 445 | |
falingtrea | 0:bdd16076aaa5 | 446 | /* |
falingtrea | 0:bdd16076aaa5 | 447 | * Main data acquisition loop |
falingtrea | 0:bdd16076aaa5 | 448 | */ |
falingtrea | 0:bdd16076aaa5 | 449 | |
falingtrea | 9:ed86d5ae29cc | 450 | i = 0; |
falingtrea | 9:ed86d5ae29cc | 451 | |
falingtrea | 0:bdd16076aaa5 | 452 | do { |
falingtrea | 0:bdd16076aaa5 | 453 | evbLCD->startUpdate(); |
falingtrea | 9:ed86d5ae29cc | 454 | // clear LCD line 0-6 only |
falingtrea | 9:ed86d5ae29cc | 455 | sprintf(txtstr, " "); |
falingtrea | 9:ed86d5ae29cc | 456 | for (j=0; j<6; j++) |
falingtrea | 9:ed86d5ae29cc | 457 | evbLCD->writeText(0,j,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 458 | |
falingtrea | 0:bdd16076aaa5 | 459 | /* |
falingtrea | 0:bdd16076aaa5 | 460 | * Test Accelerometer XYZ data ready bit to see if acquisition complete |
falingtrea | 0:bdd16076aaa5 | 461 | */ |
falingtrea | 0:bdd16076aaa5 | 462 | do { |
falingtrea | 0:bdd16076aaa5 | 463 | osDelay(100); // allows other threads to process |
falingtrea | 0:bdd16076aaa5 | 464 | result = evbAccel->getStatus(); |
falingtrea | 0:bdd16076aaa5 | 465 | } while ((result & MMA845x::XYZDR) == 0 ); |
falingtrea | 0:bdd16076aaa5 | 466 | |
falingtrea | 0:bdd16076aaa5 | 467 | /* |
falingtrea | 0:bdd16076aaa5 | 468 | * Retrieve and print out accelerometer data |
falingtrea | 0:bdd16076aaa5 | 469 | */ |
falingtrea | 0:bdd16076aaa5 | 470 | accel_data = evbAccel->getXYZ(); |
falingtrea | 0:bdd16076aaa5 | 471 | |
falingtrea | 9:ed86d5ae29cc | 472 | sprintf(txtstr, "Accel: x = %d", accel_data._x); |
falingtrea | 0:bdd16076aaa5 | 473 | evbLCD->writeText(0,0,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 474 | sprintf(txtstr, "y = %d", accel_data._y); |
falingtrea | 9:ed86d5ae29cc | 475 | evbLCD->writeText(42,1,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 476 | sprintf(txtstr, "z = %d", accel_data._z ); |
falingtrea | 9:ed86d5ae29cc | 477 | evbLCD->writeText(42,2,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 478 | |
falingtrea | 0:bdd16076aaa5 | 479 | /* |
falingtrea | 0:bdd16076aaa5 | 480 | * Trigger a Pressure reading |
falingtrea | 0:bdd16076aaa5 | 481 | */ |
falingtrea | 0:bdd16076aaa5 | 482 | evbBaro->setParameters(MPL3115A2::DATA_NORMAL, MPL3115A2::DM_BAROMETER, MPL3115A2::OR_16, |
falingtrea | 0:bdd16076aaa5 | 483 | MPL3115A2::AT_1); |
falingtrea | 0:bdd16076aaa5 | 484 | evbBaro->triggerOneShot(); |
falingtrea | 0:bdd16076aaa5 | 485 | |
falingtrea | 0:bdd16076aaa5 | 486 | /* |
falingtrea | 0:bdd16076aaa5 | 487 | * Test barometer device status to see if acquisition is complete |
falingtrea | 0:bdd16076aaa5 | 488 | */ |
falingtrea | 0:bdd16076aaa5 | 489 | do { |
falingtrea | 0:bdd16076aaa5 | 490 | osDelay(100); // allows other threads to process |
falingtrea | 0:bdd16076aaa5 | 491 | result = evbBaro->getStatus(); |
falingtrea | 0:bdd16076aaa5 | 492 | } while ((result & MPL3115A2::PTDR) == 0 ); |
falingtrea | 0:bdd16076aaa5 | 493 | |
falingtrea | 0:bdd16076aaa5 | 494 | /* |
falingtrea | 0:bdd16076aaa5 | 495 | * Retrieve and print out barometric pressure |
falingtrea | 0:bdd16076aaa5 | 496 | */ |
falingtrea | 0:bdd16076aaa5 | 497 | pressure = evbBaro->getBaroData() >> 12; // convert 32 bit signed to 20 bit unsigned value |
falingtrea | 0:bdd16076aaa5 | 498 | num_whole = pressure >> 2; // 18 bit integer significant |
falingtrea | 0:bdd16076aaa5 | 499 | num_frac = (pressure & 0x3) * 25; // 2 bit fractional 0.25 per bit |
falingtrea | 0:bdd16076aaa5 | 500 | sprintf(txtstr,"Press=%ld.%02d Pa", num_whole, num_frac); |
falingtrea | 9:ed86d5ae29cc | 501 | evbLCD->writeText(0,3,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 502 | |
falingtrea | 0:bdd16076aaa5 | 503 | /* |
falingtrea | 0:bdd16076aaa5 | 504 | * Trigger a Altitude reading |
falingtrea | 0:bdd16076aaa5 | 505 | */ |
falingtrea | 0:bdd16076aaa5 | 506 | evbBaro->setParameters(MPL3115A2::DATA_NORMAL, MPL3115A2::DM_ALTIMETER, MPL3115A2::OR_16, |
falingtrea | 0:bdd16076aaa5 | 507 | MPL3115A2::AT_1); |
falingtrea | 0:bdd16076aaa5 | 508 | evbBaro->triggerOneShot(); |
falingtrea | 0:bdd16076aaa5 | 509 | |
falingtrea | 0:bdd16076aaa5 | 510 | /* |
falingtrea | 0:bdd16076aaa5 | 511 | * Test barometer device status to see if acquisition is complete |
falingtrea | 0:bdd16076aaa5 | 512 | */ |
falingtrea | 0:bdd16076aaa5 | 513 | do { |
falingtrea | 0:bdd16076aaa5 | 514 | osDelay(100); // allows other threads to process |
falingtrea | 0:bdd16076aaa5 | 515 | result = evbBaro->getStatus(); |
falingtrea | 0:bdd16076aaa5 | 516 | } while ((result & MPL3115A2::PTDR) == 0 ); |
falingtrea | 0:bdd16076aaa5 | 517 | |
falingtrea | 0:bdd16076aaa5 | 518 | /* |
falingtrea | 0:bdd16076aaa5 | 519 | * Retrieve and print out altitude and temperature |
falingtrea | 0:bdd16076aaa5 | 520 | */ |
falingtrea | 0:bdd16076aaa5 | 521 | baro_data = evbBaro->getAllData(false); |
falingtrea | 0:bdd16076aaa5 | 522 | baro_data._baro /= 4096; // convert 32 bit signed to 20 bit signed value |
falingtrea | 0:bdd16076aaa5 | 523 | num_whole = baro_data._baro / 16; // 18 bit signed significant integer |
falingtrea | 0:bdd16076aaa5 | 524 | num_frac = (baro_data._baro & 0xF) * 625 / 100; // 4 bit fractional .0625 per bit |
falingtrea | 4:49d19abdfd04 | 525 | sprintf(txtstr,"Alti=%ld.%02d m", num_whole, num_frac); |
falingtrea | 9:ed86d5ae29cc | 526 | evbLCD->writeText(0,4,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 527 | num_whole = baro_data._temp / 16; // 8 bit signed significant integer |
falingtrea | 0:bdd16076aaa5 | 528 | num_frac = (baro_data._temp & 0x0F) * 625 / 100; // 4 bit fractional .0625 per bit |
falingtrea | 0:bdd16076aaa5 | 529 | sprintf(txtstr,"Temp=%ld.%03d C", num_whole, num_frac); |
falingtrea | 9:ed86d5ae29cc | 530 | evbLCD->writeText(0,5,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 531 | |
falingtrea | 0:bdd16076aaa5 | 532 | /* |
falingtrea | 0:bdd16076aaa5 | 533 | * retrieve and print out Ambient Light level |
falingtrea | 0:bdd16076aaa5 | 534 | */ |
falingtrea | 0:bdd16076aaa5 | 535 | lux_data = evbAmbLight->getData(); |
falingtrea | 0:bdd16076aaa5 | 536 | num_whole = lux_data * 24 / 100; // 16000 lux full scale .24 lux per bit |
falingtrea | 0:bdd16076aaa5 | 537 | num_frac = lux_data * 24 % 100; |
falingtrea | 0:bdd16076aaa5 | 538 | sprintf(txtstr, "Light=%ld.%02d lux", num_whole, num_frac ); |
falingtrea | 9:ed86d5ae29cc | 539 | evbLCD->writeText(0,6,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 540 | |
falingtrea | 0:bdd16076aaa5 | 541 | evbLCD->endUpdate(); |
falingtrea | 9:ed86d5ae29cc | 542 | |
falingtrea | 4:49d19abdfd04 | 543 | printf("finished iteration %d\r\n",(++i)); |
falingtrea | 0:bdd16076aaa5 | 544 | |
falingtrea | 9:ed86d5ae29cc | 545 | /* Transmit data packet based on pckt_time setting and result of |
falingtrea | 9:ed86d5ae29cc | 546 | * mdot_radio->getNextTxMs() function and mutex available. The getNextTxMs() |
falingtrea | 9:ed86d5ae29cc | 547 | * function returns the number of millisecond before another packet can be |
falingtrea | 9:ed86d5ae29cc | 548 | * sent in 868 MHz band. This can vary depending on wther the 10%, 1% or 0.1% |
falingtrea | 9:ed86d5ae29cc | 549 | * channel is used and the time on air for a specific setup of the radio |
falingtrea | 9:ed86d5ae29cc | 550 | */ |
falingtrea | 9:ed86d5ae29cc | 551 | |
falingtrea | 9:ed86d5ae29cc | 552 | if ((xmit_delay <= i) && (mdot_radio->getNextTxMs() == 0) && (mdot_mutex.trylock())) { |
falingtrea | 9:ed86d5ae29cc | 553 | /* |
falingtrea | 9:ed86d5ae29cc | 554 | * Setting TX power and Data Rate for radio just in case user requested by SW2 |
falingtrea | 9:ed86d5ae29cc | 555 | */ |
falingtrea | 9:ed86d5ae29cc | 556 | mdot_radio->setTxPower(pwr_val); |
falingtrea | 9:ed86d5ae29cc | 557 | mdot_radio->setTxDataRate(sf_val); |
falingtrea | 9:ed86d5ae29cc | 558 | |
falingtrea | 0:bdd16076aaa5 | 559 | mdot_data.clear(); |
falingtrea | 9:ed86d5ae29cc | 560 | mdot_data.push_back(0x1D); // key for start of data |
falingtrea | 0:bdd16076aaa5 | 561 | mdot_data.push_back(0x0E); // key for Current Acceleration 3-Axis Value |
falingtrea | 0:bdd16076aaa5 | 562 | converts.f_s = accel_data._x *4; // shift data 2 bits while retaining sign |
falingtrea | 0:bdd16076aaa5 | 563 | mdot_data.push_back(converts.t_u[1]); // get 8 MSB of 14 bit value |
falingtrea | 0:bdd16076aaa5 | 564 | converts.f_s = accel_data._y * 4; // shift data 2 bits while retaining sign |
falingtrea | 0:bdd16076aaa5 | 565 | mdot_data.push_back(converts.t_u[1]); // get 8 MSB of 14 bit value |
falingtrea | 0:bdd16076aaa5 | 566 | converts.f_s = accel_data._z * 4; // shift data 2 bits while retaining sign |
falingtrea | 0:bdd16076aaa5 | 567 | mdot_data.push_back(converts.t_u[1]); // get 8 MSB of 14 bit value |
falingtrea | 0:bdd16076aaa5 | 568 | mdot_data.push_back(0x08); // key for Current Pressure Value |
falingtrea | 0:bdd16076aaa5 | 569 | convertl.f_u = pressure; // pressure data is 20 bits unsigned |
falingtrea | 0:bdd16076aaa5 | 570 | mdot_data.push_back(convertl.t_u[2]); |
falingtrea | 0:bdd16076aaa5 | 571 | mdot_data.push_back(convertl.t_u[1]); |
falingtrea | 0:bdd16076aaa5 | 572 | mdot_data.push_back(convertl.t_u[0]); |
falingtrea | 9:ed86d5ae29cc | 573 | |
falingtrea | 9:ed86d5ae29cc | 574 | /* for 915 MHz band and SF_10 max packet size is 11 bytes. |
falingtrea | 9:ed86d5ae29cc | 575 | * so the payload gets split in two packets here. |
falingtrea | 9:ed86d5ae29cc | 576 | */ |
falingtrea | 9:ed86d5ae29cc | 577 | if ((mdot_freq == mDot::FB_915) && (sf_val == mDot::SF_10)) { |
falingtrea | 9:ed86d5ae29cc | 578 | mdot_ret = mdot_radio->send(mdot_data); |
falingtrea | 9:ed86d5ae29cc | 579 | if ( mdot_ret != mDot::MDOT_OK) { |
falingtrea | 9:ed86d5ae29cc | 580 | sprintf(txtstr,"mDot Send failed"); |
falingtrea | 9:ed86d5ae29cc | 581 | evbLCD->writeText(0,7,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 9:ed86d5ae29cc | 582 | log_error(mdot_radio, txtstr, mdot_ret); |
falingtrea | 9:ed86d5ae29cc | 583 | continue; |
falingtrea | 9:ed86d5ae29cc | 584 | } else { |
falingtrea | 9:ed86d5ae29cc | 585 | printf("successfully sent packet 1 to gateway\r\n"); |
falingtrea | 9:ed86d5ae29cc | 586 | } |
falingtrea | 9:ed86d5ae29cc | 587 | mdot_data.clear(); // clear data for next "chunk" |
falingtrea | 9:ed86d5ae29cc | 588 | } |
falingtrea | 9:ed86d5ae29cc | 589 | |
falingtrea | 9:ed86d5ae29cc | 590 | |
falingtrea | 0:bdd16076aaa5 | 591 | mdot_data.push_back(0x05); // key for Current Ambient Light Value |
falingtrea | 0:bdd16076aaa5 | 592 | converts.f_u = lux_data; // data is 16 bits unsigned |
falingtrea | 0:bdd16076aaa5 | 593 | mdot_data.push_back(converts.t_u[1]); |
falingtrea | 0:bdd16076aaa5 | 594 | mdot_data.push_back(converts.t_u[0]); |
falingtrea | 0:bdd16076aaa5 | 595 | mdot_data.push_back(0x0B); // key for Current Temperature Value |
falingtrea | 0:bdd16076aaa5 | 596 | converts.f_s = baro_data._temp; // temperature is signed 12 bit |
falingtrea | 0:bdd16076aaa5 | 597 | mdot_data.push_back(converts.t_u[1]); |
falingtrea | 0:bdd16076aaa5 | 598 | mdot_data.push_back(converts.t_u[0]); |
falingtrea | 9:ed86d5ae29cc | 599 | mdot_data.push_back(0x1D); // key for end of data |
falingtrea | 0:bdd16076aaa5 | 600 | |
falingtrea | 9:ed86d5ae29cc | 601 | mdot_ret = mdot_radio->send(mdot_data); |
falingtrea | 9:ed86d5ae29cc | 602 | if (mdot_ret != mDot::MDOT_OK) { |
falingtrea | 0:bdd16076aaa5 | 603 | log_error(mdot_radio, "failed to send", mdot_ret); |
falingtrea | 9:ed86d5ae29cc | 604 | sprintf(txtstr,"PKT Send Failed"); |
falingtrea | 9:ed86d5ae29cc | 605 | evbLCD->writeText(0,7,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 606 | } else { |
falingtrea | 9:ed86d5ae29cc | 607 | sprintf(txtstr,"SENT DR=%2d Pwr=%2d",(12 - sf_val),pwr_val); |
falingtrea | 9:ed86d5ae29cc | 608 | evbLCD->writeText(0,7,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 9:ed86d5ae29cc | 609 | printf("%s \r\n",txtstr); |
falingtrea | 0:bdd16076aaa5 | 610 | } |
falingtrea | 9:ed86d5ae29cc | 611 | mdot_mutex.unlock(); // unlock mutex after all data transmitted |
falingtrea | 9:ed86d5ae29cc | 612 | xmit_delay = i + pckt_time; |
falingtrea | 9:ed86d5ae29cc | 613 | if (mdot_freq == mDot::FB_868) |
falingtrea | 9:ed86d5ae29cc | 614 | printf("Next transmit time = %d milliseconds \r\n",mdot_radio->getNextTxMs()); |
falingtrea | 9:ed86d5ae29cc | 615 | |
falingtrea | 9:ed86d5ae29cc | 616 | } else { |
falingtrea | 9:ed86d5ae29cc | 617 | sprintf(txtstr," DR=%2d Pwr=%2d ",(12 - sf_val),pwr_val); |
falingtrea | 9:ed86d5ae29cc | 618 | evbLCD->writeText(0,7,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 0:bdd16076aaa5 | 619 | } |
falingtrea | 9:ed86d5ae29cc | 620 | } while(i < 65000); |
falingtrea | 0:bdd16076aaa5 | 621 | |
falingtrea | 0:bdd16076aaa5 | 622 | evbBaro->triggerOneShot(); |
falingtrea | 0:bdd16076aaa5 | 623 | |
falingtrea | 0:bdd16076aaa5 | 624 | do { |
falingtrea | 0:bdd16076aaa5 | 625 | osDelay(200); // allows other threads to process |
falingtrea | 0:bdd16076aaa5 | 626 | result = evbBaro->getStatus(); |
falingtrea | 0:bdd16076aaa5 | 627 | } while ((result & MPL3115A2::PTDR) == 0 ); |
falingtrea | 0:bdd16076aaa5 | 628 | |
falingtrea | 0:bdd16076aaa5 | 629 | baro_data = evbBaro->getAllData(true); |
falingtrea | 4:49d19abdfd04 | 630 | printf ("minBaro=%ld maxBaro=%ld minTemp=%d maxTemp=%d\r\n", baro_data._minbaro, baro_data._maxbaro, |
falingtrea | 0:bdd16076aaa5 | 631 | baro_data._mintemp, baro_data._maxtemp); |
falingtrea | 0:bdd16076aaa5 | 632 | |
falingtrea | 4:49d19abdfd04 | 633 | printf("End of Test\r\n"); |
falingtrea | 0:bdd16076aaa5 | 634 | |
falingtrea | 2:75adc72aa6a0 | 635 | evbLCD->clearBuffer(); |
falingtrea | 2:75adc72aa6a0 | 636 | sprintf(txtstr,"Exiting Program"); |
falingtrea | 2:75adc72aa6a0 | 637 | evbLCD->writeText(0,4,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 2:75adc72aa6a0 | 638 | |
falingtrea | 0:bdd16076aaa5 | 639 | } |
falingtrea | 0:bdd16076aaa5 | 640 | |
falingtrea | 0:bdd16076aaa5 | 641 | /* |
falingtrea | 9:ed86d5ae29cc | 642 | * Sets sw1_low flag. Slag is cleared in sw1_debounce thread |
falingtrea | 0:bdd16076aaa5 | 643 | */ |
falingtrea | 9:ed86d5ae29cc | 644 | void sw1ISR(void) |
falingtrea | 0:bdd16076aaa5 | 645 | { |
falingtrea | 9:ed86d5ae29cc | 646 | if (!sw1_low) |
falingtrea | 9:ed86d5ae29cc | 647 | sw1_low = true; |
falingtrea | 3:68e974f5f532 | 648 | } |
falingtrea | 0:bdd16076aaa5 | 649 | |
falingtrea | 3:68e974f5f532 | 650 | /* |
falingtrea | 9:ed86d5ae29cc | 651 | * Debounces sw1 changes spreading factor and output power |
falingtrea | 9:ed86d5ae29cc | 652 | * Cycles through SF_7-SF_9 for 4 power levels for 915 MHz band |
falingtrea | 9:ed86d5ae29cc | 653 | * Cycles through SF_7-SF_12 for 4 power levels for 868 MHz band |
falingtrea | 3:68e974f5f532 | 654 | */ |
falingtrea | 9:ed86d5ae29cc | 655 | void sw1_debounce(void const *args) |
falingtrea | 3:68e974f5f532 | 656 | { |
falingtrea | 3:68e974f5f532 | 657 | static uint8_t count = 0; |
falingtrea | 9:ed86d5ae29cc | 658 | static uint8_t test_sf = 0; |
falingtrea | 9:ed86d5ae29cc | 659 | static uint8_t test_pwr = 0; |
falingtrea | 3:68e974f5f532 | 660 | |
falingtrea | 3:68e974f5f532 | 661 | while (true) { |
falingtrea | 3:68e974f5f532 | 662 | |
falingtrea | 9:ed86d5ae29cc | 663 | if (sw1_low && (mDot08 == 0)) |
mfiore | 7:85445a8cc189 | 664 | count++; |
falingtrea | 3:68e974f5f532 | 665 | else { |
mfiore | 7:85445a8cc189 | 666 | count = 0; |
falingtrea | 9:ed86d5ae29cc | 667 | sw1_low = false; |
falingtrea | 3:68e974f5f532 | 668 | } |
mfiore | 7:85445a8cc189 | 669 | |
falingtrea | 9:ed86d5ae29cc | 670 | if (count == 5) { |
falingtrea | 9:ed86d5ae29cc | 671 | test_sf++; |
falingtrea | 9:ed86d5ae29cc | 672 | |
falingtrea | 9:ed86d5ae29cc | 673 | if (((test_sf > 3) && (mdot_freq == mDot::FB_915)) || ((test_sf > 5) && (mdot_freq == mDot::FB_868))) { |
falingtrea | 9:ed86d5ae29cc | 674 | test_sf = 0; |
falingtrea | 9:ed86d5ae29cc | 675 | test_pwr ++; |
falingtrea | 9:ed86d5ae29cc | 676 | if (test_pwr > 3) |
falingtrea | 9:ed86d5ae29cc | 677 | test_pwr = 0; |
falingtrea | 9:ed86d5ae29cc | 678 | } |
falingtrea | 9:ed86d5ae29cc | 679 | |
falingtrea | 9:ed86d5ae29cc | 680 | // selects power output level using upper bits for select |
falingtrea | 9:ed86d5ae29cc | 681 | switch(test_pwr) { |
falingtrea | 9:ed86d5ae29cc | 682 | case 0: |
falingtrea | 9:ed86d5ae29cc | 683 | pwr_val = 11; |
falingtrea | 9:ed86d5ae29cc | 684 | break; |
falingtrea | 9:ed86d5ae29cc | 685 | case 1: |
falingtrea | 9:ed86d5ae29cc | 686 | pwr_val = 14; |
falingtrea | 9:ed86d5ae29cc | 687 | break; |
falingtrea | 9:ed86d5ae29cc | 688 | case 2: |
falingtrea | 9:ed86d5ae29cc | 689 | pwr_val = 18; |
falingtrea | 9:ed86d5ae29cc | 690 | break; |
falingtrea | 9:ed86d5ae29cc | 691 | case 3: |
falingtrea | 9:ed86d5ae29cc | 692 | pwr_val = 20; |
falingtrea | 9:ed86d5ae29cc | 693 | } |
falingtrea | 9:ed86d5ae29cc | 694 | |
falingtrea | 9:ed86d5ae29cc | 695 | // sets data rate based on lower bits |
falingtrea | 9:ed86d5ae29cc | 696 | sf_val = mDot::SF_7 - (test_sf & 0x07); |
falingtrea | 9:ed86d5ae29cc | 697 | |
falingtrea | 9:ed86d5ae29cc | 698 | sprintf(txtstr," DR=%2d Pwr=%2d ",(12 - sf_val),pwr_val); |
falingtrea | 9:ed86d5ae29cc | 699 | evbLCD->writeText(0,7,font_6x8,txtstr,strlen(txtstr)); |
falingtrea | 9:ed86d5ae29cc | 700 | printf("%s \r\n",txtstr); |
falingtrea | 9:ed86d5ae29cc | 701 | } |
mfiore | 7:85445a8cc189 | 702 | |
falingtrea | 3:68e974f5f532 | 703 | Thread::wait(5); |
falingtrea | 3:68e974f5f532 | 704 | } |
falingtrea | 0:bdd16076aaa5 | 705 | } |
falingtrea | 0:bdd16076aaa5 | 706 | |
falingtrea | 0:bdd16076aaa5 | 707 | /* |
falingtrea | 9:ed86d5ae29cc | 708 | * Sets sw2_low flag. Flag is cleared in sw2_debounce thread |
falingtrea | 0:bdd16076aaa5 | 709 | */ |
falingtrea | 9:ed86d5ae29cc | 710 | void sw2ISR(void) |
falingtrea | 0:bdd16076aaa5 | 711 | { |
falingtrea | 9:ed86d5ae29cc | 712 | if (!sw2_low) |
falingtrea | 9:ed86d5ae29cc | 713 | sw2_low = true; |
falingtrea | 3:68e974f5f532 | 714 | } |
falingtrea | 0:bdd16076aaa5 | 715 | |
falingtrea | 3:68e974f5f532 | 716 | /* |
falingtrea | 9:ed86d5ae29cc | 717 | * Debounces sw2. Changes packet transmit time to every 2nd, |
falingtrea | 9:ed86d5ae29cc | 718 | * 4th, 8th, or 16th sample when SW2 pushed. For 868 MHz mode |
falingtrea | 9:ed86d5ae29cc | 719 | * the time for next packet value is also tested. |
falingtrea | 3:68e974f5f532 | 720 | * Also triggers a thread to transmit a configuration packet |
falingtrea | 3:68e974f5f532 | 721 | */ |
falingtrea | 9:ed86d5ae29cc | 722 | void sw2_debounce(void const *args) |
falingtrea | 3:68e974f5f532 | 723 | { |
falingtrea | 3:68e974f5f532 | 724 | |
falingtrea | 3:68e974f5f532 | 725 | static uint8_t count = 0; |
falingtrea | 3:68e974f5f532 | 726 | |
falingtrea | 3:68e974f5f532 | 727 | while (true) { |
falingtrea | 0:bdd16076aaa5 | 728 | |
falingtrea | 9:ed86d5ae29cc | 729 | if (sw2_low && (mDot09 == 0)) |
mfiore | 7:85445a8cc189 | 730 | count++; |
falingtrea | 3:68e974f5f532 | 731 | else { |
mfiore | 7:85445a8cc189 | 732 | count = 0; |
falingtrea | 9:ed86d5ae29cc | 733 | sw2_low = false; |
falingtrea | 3:68e974f5f532 | 734 | } |
mfiore | 7:85445a8cc189 | 735 | |
mfiore | 7:85445a8cc189 | 736 | if (count == 5) { |
falingtrea | 0:bdd16076aaa5 | 737 | |
falingtrea | 9:ed86d5ae29cc | 738 | if (pckt_time >= 4) |
mfiore | 7:85445a8cc189 | 739 | pckt_time /= 2; |
falingtrea | 9:ed86d5ae29cc | 740 | else pckt_time = 16; |
falingtrea | 3:68e974f5f532 | 741 | |
mfiore | 7:85445a8cc189 | 742 | thread_3->signal_set(0x10); // signal config_pkt_xmit to send packet |
mfiore | 7:85445a8cc189 | 743 | } |
mfiore | 7:85445a8cc189 | 744 | |
falingtrea | 3:68e974f5f532 | 745 | Thread::wait(5); |
mfiore | 7:85445a8cc189 | 746 | } |
mfiore | 7:85445a8cc189 | 747 | } |
falingtrea | 0:bdd16076aaa5 | 748 | |
falingtrea | 2:75adc72aa6a0 | 749 | /* |
falingtrea | 9:ed86d5ae29cc | 750 | * Function that prints clear text verion of mDot errors |
falingtrea | 2:75adc72aa6a0 | 751 | */ |
falingtrea | 0:bdd16076aaa5 | 752 | void log_error(mDot* dot, const char* msg, int32_t retval) |
falingtrea | 0:bdd16076aaa5 | 753 | { |
falingtrea | 0:bdd16076aaa5 | 754 | printf("%s - %ld:%s, %s\r\n", msg, retval, mDot::getReturnCodeString(retval).c_str(), dot->getLastError().c_str()); |
falingtrea | 0:bdd16076aaa5 | 755 | } |
falingtrea | 0:bdd16076aaa5 | 756 | |
falingtrea | 2:75adc72aa6a0 | 757 | /* |
falingtrea | 2:75adc72aa6a0 | 758 | * Thread that is triggered by SW2 ISR. Sends a packet to the LoRa server with the new Packet Transmission time setting |
falingtrea | 2:75adc72aa6a0 | 759 | */ |
falingtrea | 0:bdd16076aaa5 | 760 | void config_pkt_xmit (void const *args) |
falingtrea | 0:bdd16076aaa5 | 761 | { |
falingtrea | 0:bdd16076aaa5 | 762 | |
falingtrea | 0:bdd16076aaa5 | 763 | std::vector<uint8_t> data; |
falingtrea | 9:ed86d5ae29cc | 764 | uint16_t wait_time; |
falingtrea | 0:bdd16076aaa5 | 765 | |
falingtrea | 0:bdd16076aaa5 | 766 | while (true) { |
falingtrea | 9:ed86d5ae29cc | 767 | Thread::signal_wait(0x10); // wait for sw2ISR to signal send |
falingtrea | 0:bdd16076aaa5 | 768 | data.clear(); |
falingtrea | 0:bdd16076aaa5 | 769 | data.push_back(0x0F); // key for Configuration data (packet transmission timer) |
falingtrea | 0:bdd16076aaa5 | 770 | data.push_back(pckt_time); |
falingtrea | 9:ed86d5ae29cc | 771 | |
falingtrea | 9:ed86d5ae29cc | 772 | mdot_mutex.lock(); // lock mdot mutex before packet send |
falingtrea | 9:ed86d5ae29cc | 773 | |
falingtrea | 9:ed86d5ae29cc | 774 | if ((wait_time = mdot_radio->getNextTxMs()) > 0) // wait for next xmit time |
falingtrea | 9:ed86d5ae29cc | 775 | osDelay(wait_time); |
falingtrea | 0:bdd16076aaa5 | 776 | |
falingtrea | 0:bdd16076aaa5 | 777 | if ((mdot_ret = mdot_radio->send(data)) != mDot::MDOT_OK) { |
falingtrea | 0:bdd16076aaa5 | 778 | log_error(mdot_radio, "failed to send config data", mdot_ret); |
falingtrea | 0:bdd16076aaa5 | 779 | } else { |
falingtrea | 0:bdd16076aaa5 | 780 | printf("sent config data to gateway\r\n"); |
falingtrea | 0:bdd16076aaa5 | 781 | } |
falingtrea | 9:ed86d5ae29cc | 782 | mdot_mutex.unlock(); // unlock mdot mutex after packet send |
falingtrea | 0:bdd16076aaa5 | 783 | } |
falingtrea | 0:bdd16076aaa5 | 784 | } |