![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Lora4MakerFaire
Dependencies: HC_SR04_Ultrasonic_Library X_NUCLEO_IKS01A2 mbed LoRaWAN-lib SX1272Lib
Fork of LoRaWANdemo72 by
app/main.cpp@10:88f1c052f9e9, 2017-12-01 (annotated)
- Committer:
- rschiano
- Date:
- Fri Dec 01 10:21:46 2017 +0000
- Revision:
- 10:88f1c052f9e9
- Parent:
- 9:85c85c65299a
LoraMakerFaire;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mluis | 0:45496a70a8a5 | 1 | /* |
mluis | 0:45496a70a8a5 | 2 | / _____) _ | | |
mluis | 0:45496a70a8a5 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
mluis | 0:45496a70a8a5 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
mluis | 0:45496a70a8a5 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
mluis | 0:45496a70a8a5 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
mluis | 0:45496a70a8a5 | 7 | (C)2015 Semtech |
mluis | 0:45496a70a8a5 | 8 | |
mluis | 0:45496a70a8a5 | 9 | Description: LoRaMac classA device implementation |
mluis | 0:45496a70a8a5 | 10 | |
mluis | 0:45496a70a8a5 | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
mluis | 0:45496a70a8a5 | 12 | |
mluis | 0:45496a70a8a5 | 13 | Maintainer: Miguel Luis and Gregory Cristian |
mluis | 0:45496a70a8a5 | 14 | */ |
mluis | 0:45496a70a8a5 | 15 | #include "mbed.h" |
mluis | 0:45496a70a8a5 | 16 | #include "board.h" |
mluis | 0:45496a70a8a5 | 17 | #include "radio.h" |
mluis | 0:45496a70a8a5 | 18 | |
mluis | 0:45496a70a8a5 | 19 | #include "LoRaMac.h" |
mluis | 7:5077515c163b | 20 | #include "Commissioning.h" |
mluis | 0:45496a70a8a5 | 21 | #include "SerialDisplay.h" |
salvatoregulfo | 8:346c55cb6033 | 22 | #include "XNucleoIKS01A2.h" |
salvatoregulfo | 8:346c55cb6033 | 23 | #include "string.h" |
salvatoregulfo | 9:85c85c65299a | 24 | #include "ultrasonic.h" |
rschiano | 10:88f1c052f9e9 | 25 | #include "vt100.h" |
salvatoregulfo | 8:346c55cb6033 | 26 | |
salvatoregulfo | 8:346c55cb6033 | 27 | /* Instantiate the expansion board */ |
salvatoregulfo | 8:346c55cb6033 | 28 | static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5); |
salvatoregulfo | 9:85c85c65299a | 29 | ultrasonic usensor(D8, D9, .1, 1); |
rschiano | 10:88f1c052f9e9 | 30 | DigitalOut led(LED2); |
salvatoregulfo | 9:85c85c65299a | 31 | //static HCSR04 *myUS = ultrasonic::ultrasonic(D8,D9,.1,1) //set the trigger pin to D8 and the Echo pin to D9 |
salvatoregulfo | 8:346c55cb6033 | 32 | |
salvatoregulfo | 8:346c55cb6033 | 33 | /* Retrieve the composing elements of the expansion board */ |
rschiano | 10:88f1c052f9e9 | 34 | static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor; |
salvatoregulfo | 8:346c55cb6033 | 35 | //static LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer; |
salvatoregulfo | 8:346c55cb6033 | 36 | //static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro; |
rschiano | 10:88f1c052f9e9 | 37 | static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor; |
mluis | 0:45496a70a8a5 | 38 | /*! |
mluis | 7:5077515c163b | 39 | * Defines the application data transmission duty cycle. 5s, value in [ms]. |
mluis | 0:45496a70a8a5 | 40 | */ |
mluis | 7:5077515c163b | 41 | #define APP_TX_DUTYCYCLE 5000 |
mluis | 0:45496a70a8a5 | 42 | |
mluis | 0:45496a70a8a5 | 43 | /*! |
mluis | 0:45496a70a8a5 | 44 | * Defines a random delay for application data transmission duty cycle. 1s, |
mluis | 7:5077515c163b | 45 | * value in [ms]. |
mluis | 0:45496a70a8a5 | 46 | */ |
mluis | 7:5077515c163b | 47 | #define APP_TX_DUTYCYCLE_RND 1000 |
mluis | 0:45496a70a8a5 | 48 | |
mluis | 0:45496a70a8a5 | 49 | /*! |
mluis | 3:3152aa75c58d | 50 | * Default datarate |
mluis | 0:45496a70a8a5 | 51 | */ |
rschiano | 10:88f1c052f9e9 | 52 | #define LORAWAN_DEFAULT_DATARATE DR_5 //SF 12 |
mluis | 0:45496a70a8a5 | 53 | |
mluis | 0:45496a70a8a5 | 54 | /*! |
mluis | 0:45496a70a8a5 | 55 | * LoRaWAN confirmed messages |
mluis | 0:45496a70a8a5 | 56 | */ |
mluis | 0:45496a70a8a5 | 57 | #define LORAWAN_CONFIRMED_MSG_ON true |
mluis | 0:45496a70a8a5 | 58 | |
mluis | 0:45496a70a8a5 | 59 | /*! |
mluis | 0:45496a70a8a5 | 60 | * LoRaWAN Adaptive Data Rate |
mluis | 0:45496a70a8a5 | 61 | * |
mluis | 0:45496a70a8a5 | 62 | * \remark Please note that when ADR is enabled the end-device should be static |
mluis | 0:45496a70a8a5 | 63 | */ |
salvatoregulfo | 9:85c85c65299a | 64 | #define LORAWAN_ADR_ON 0 |
mluis | 0:45496a70a8a5 | 65 | |
mluis | 0:45496a70a8a5 | 66 | #if defined( USE_BAND_868 ) |
mluis | 0:45496a70a8a5 | 67 | |
mluis | 0:45496a70a8a5 | 68 | #include "LoRaMacTest.h" |
mluis | 0:45496a70a8a5 | 69 | |
mluis | 0:45496a70a8a5 | 70 | /*! |
mluis | 0:45496a70a8a5 | 71 | * LoRaWAN ETSI duty cycle control enable/disable |
mluis | 0:45496a70a8a5 | 72 | * |
mluis | 0:45496a70a8a5 | 73 | * \remark Please note that ETSI mandates duty cycled transmissions. Use only for test purposes |
mluis | 0:45496a70a8a5 | 74 | */ |
salvatoregulfo | 8:346c55cb6033 | 75 | #define LORAWAN_DUTYCYCLE_ON true |
mluis | 0:45496a70a8a5 | 76 | |
mluis | 3:3152aa75c58d | 77 | #define USE_SEMTECH_DEFAULT_CHANNEL_LINEUP 1 |
mluis | 3:3152aa75c58d | 78 | |
mluis | 7:5077515c163b | 79 | #if( USE_SEMTECH_DEFAULT_CHANNEL_LINEUP == 1 ) |
mluis | 3:3152aa75c58d | 80 | |
mluis | 3:3152aa75c58d | 81 | #define LC4 { 867100000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } |
mluis | 3:3152aa75c58d | 82 | #define LC5 { 867300000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } |
mluis | 3:3152aa75c58d | 83 | #define LC6 { 867500000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } |
mluis | 3:3152aa75c58d | 84 | #define LC7 { 867700000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } |
mluis | 3:3152aa75c58d | 85 | #define LC8 { 867900000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } |
mluis | 3:3152aa75c58d | 86 | #define LC9 { 868800000, { ( ( DR_7 << 4 ) | DR_7 ) }, 2 } |
mluis | 3:3152aa75c58d | 87 | #define LC10 { 868300000, { ( ( DR_6 << 4 ) | DR_6 ) }, 1 } |
mluis | 3:3152aa75c58d | 88 | |
mluis | 3:3152aa75c58d | 89 | #endif |
mluis | 3:3152aa75c58d | 90 | |
mluis | 0:45496a70a8a5 | 91 | #endif |
mluis | 0:45496a70a8a5 | 92 | |
mluis | 0:45496a70a8a5 | 93 | /*! |
mluis | 0:45496a70a8a5 | 94 | * LoRaWAN application port |
mluis | 0:45496a70a8a5 | 95 | */ |
rschiano | 10:88f1c052f9e9 | 96 | #define LORAWAN_APP_PORT 13 // 0x44 // |
mluis | 0:45496a70a8a5 | 97 | |
mluis | 0:45496a70a8a5 | 98 | /*! |
mluis | 0:45496a70a8a5 | 99 | * User application data buffer size |
mluis | 0:45496a70a8a5 | 100 | */ |
mluis | 0:45496a70a8a5 | 101 | #if ( LORAWAN_CONFIRMED_MSG_ON == 1 ) |
mluis | 0:45496a70a8a5 | 102 | #define LORAWAN_APP_DATA_SIZE 6 |
mluis | 0:45496a70a8a5 | 103 | |
mluis | 0:45496a70a8a5 | 104 | #else |
mluis | 0:45496a70a8a5 | 105 | #define LORAWAN_APP_DATA_SIZE 1 |
mluis | 0:45496a70a8a5 | 106 | |
mluis | 0:45496a70a8a5 | 107 | #endif |
mluis | 0:45496a70a8a5 | 108 | |
mluis | 0:45496a70a8a5 | 109 | static uint8_t DevEui[] = LORAWAN_DEVICE_EUI; |
mluis | 0:45496a70a8a5 | 110 | static uint8_t AppEui[] = LORAWAN_APPLICATION_EUI; |
mluis | 0:45496a70a8a5 | 111 | static uint8_t AppKey[] = LORAWAN_APPLICATION_KEY; |
mluis | 0:45496a70a8a5 | 112 | |
mluis | 5:62862ef9480b | 113 | #if( OVER_THE_AIR_ACTIVATION == 0 ) |
mluis | 0:45496a70a8a5 | 114 | |
mluis | 0:45496a70a8a5 | 115 | static uint8_t NwkSKey[] = LORAWAN_NWKSKEY; |
mluis | 0:45496a70a8a5 | 116 | static uint8_t AppSKey[] = LORAWAN_APPSKEY; |
mluis | 0:45496a70a8a5 | 117 | |
mluis | 0:45496a70a8a5 | 118 | /*! |
mluis | 0:45496a70a8a5 | 119 | * Device address |
mluis | 0:45496a70a8a5 | 120 | */ |
mluis | 0:45496a70a8a5 | 121 | static uint32_t DevAddr = LORAWAN_DEVICE_ADDRESS; |
mluis | 0:45496a70a8a5 | 122 | |
mluis | 0:45496a70a8a5 | 123 | #endif |
mluis | 0:45496a70a8a5 | 124 | |
mluis | 0:45496a70a8a5 | 125 | /*! |
mluis | 0:45496a70a8a5 | 126 | * Application port |
mluis | 0:45496a70a8a5 | 127 | */ |
mluis | 0:45496a70a8a5 | 128 | static uint8_t AppPort = LORAWAN_APP_PORT; |
mluis | 0:45496a70a8a5 | 129 | |
mluis | 0:45496a70a8a5 | 130 | /*! |
mluis | 0:45496a70a8a5 | 131 | * User application data size |
mluis | 0:45496a70a8a5 | 132 | */ |
mluis | 0:45496a70a8a5 | 133 | static uint8_t AppDataSize = LORAWAN_APP_DATA_SIZE; |
mluis | 0:45496a70a8a5 | 134 | |
mluis | 0:45496a70a8a5 | 135 | /*! |
mluis | 0:45496a70a8a5 | 136 | * User application data buffer size |
mluis | 0:45496a70a8a5 | 137 | */ |
mluis | 0:45496a70a8a5 | 138 | #define LORAWAN_APP_DATA_MAX_SIZE 64 |
mluis | 0:45496a70a8a5 | 139 | |
mluis | 0:45496a70a8a5 | 140 | /*! |
mluis | 0:45496a70a8a5 | 141 | * User application data |
mluis | 0:45496a70a8a5 | 142 | */ |
mluis | 0:45496a70a8a5 | 143 | static uint8_t AppData[LORAWAN_APP_DATA_MAX_SIZE]; |
mluis | 0:45496a70a8a5 | 144 | |
mluis | 0:45496a70a8a5 | 145 | /*! |
mluis | 0:45496a70a8a5 | 146 | * Indicates if the node is sending confirmed or unconfirmed messages |
mluis | 0:45496a70a8a5 | 147 | */ |
mluis | 0:45496a70a8a5 | 148 | static uint8_t IsTxConfirmed = LORAWAN_CONFIRMED_MSG_ON; |
mluis | 0:45496a70a8a5 | 149 | |
mluis | 0:45496a70a8a5 | 150 | /*! |
mluis | 0:45496a70a8a5 | 151 | * Defines the application data transmission duty cycle |
mluis | 0:45496a70a8a5 | 152 | */ |
mluis | 0:45496a70a8a5 | 153 | static uint32_t TxDutyCycleTime; |
mluis | 0:45496a70a8a5 | 154 | |
mluis | 0:45496a70a8a5 | 155 | /*! |
mluis | 0:45496a70a8a5 | 156 | * Timer to handle the application data transmission duty cycle |
mluis | 0:45496a70a8a5 | 157 | */ |
mluis | 0:45496a70a8a5 | 158 | static TimerEvent_t TxNextPacketTimer; |
mluis | 0:45496a70a8a5 | 159 | |
mluis | 0:45496a70a8a5 | 160 | /*! |
mluis | 0:45496a70a8a5 | 161 | * Specifies the state of the application LED |
mluis | 0:45496a70a8a5 | 162 | */ |
mluis | 0:45496a70a8a5 | 163 | static bool AppLedStateOn = false; |
mluis | 0:45496a70a8a5 | 164 | volatile bool Led3StateChanged = false; |
mluis | 0:45496a70a8a5 | 165 | /*! |
mluis | 0:45496a70a8a5 | 166 | * Timer to handle the state of LED1 |
mluis | 0:45496a70a8a5 | 167 | */ |
mluis | 0:45496a70a8a5 | 168 | static TimerEvent_t Led1Timer; |
mluis | 0:45496a70a8a5 | 169 | volatile bool Led1State = false; |
mluis | 0:45496a70a8a5 | 170 | volatile bool Led1StateChanged = false; |
mluis | 0:45496a70a8a5 | 171 | /*! |
mluis | 0:45496a70a8a5 | 172 | * Timer to handle the state of LED2 |
mluis | 0:45496a70a8a5 | 173 | */ |
mluis | 0:45496a70a8a5 | 174 | static TimerEvent_t Led2Timer; |
mluis | 0:45496a70a8a5 | 175 | volatile bool Led2State = false; |
mluis | 0:45496a70a8a5 | 176 | volatile bool Led2StateChanged = false; |
mluis | 0:45496a70a8a5 | 177 | |
mluis | 0:45496a70a8a5 | 178 | /*! |
mluis | 0:45496a70a8a5 | 179 | * Indicates if a new packet can be sent |
mluis | 0:45496a70a8a5 | 180 | */ |
mluis | 0:45496a70a8a5 | 181 | static bool NextTx = true; |
mluis | 0:45496a70a8a5 | 182 | |
salvatoregulfo | 8:346c55cb6033 | 183 | /* Helper function for printing floats & doubles */ |
salvatoregulfo | 8:346c55cb6033 | 184 | static char *print_double(char* str, double v, int decimalDigits=2) |
salvatoregulfo | 8:346c55cb6033 | 185 | { |
salvatoregulfo | 8:346c55cb6033 | 186 | int i = 1; |
salvatoregulfo | 8:346c55cb6033 | 187 | int intPart; |
salvatoregulfo | 8:346c55cb6033 | 188 | int fractPart; |
salvatoregulfo | 8:346c55cb6033 | 189 | int len; |
salvatoregulfo | 8:346c55cb6033 | 190 | char *ptr; |
salvatoregulfo | 8:346c55cb6033 | 191 | |
salvatoregulfo | 8:346c55cb6033 | 192 | /* prepare decimal digits multiplicator */ |
salvatoregulfo | 8:346c55cb6033 | 193 | for (;decimalDigits!=0; i*=10, decimalDigits--); |
salvatoregulfo | 8:346c55cb6033 | 194 | |
salvatoregulfo | 8:346c55cb6033 | 195 | /* calculate integer & fractional parts */ |
salvatoregulfo | 8:346c55cb6033 | 196 | intPart = (int)v; |
salvatoregulfo | 8:346c55cb6033 | 197 | fractPart = (int)((v-(double)(int)v)*i); |
salvatoregulfo | 8:346c55cb6033 | 198 | |
salvatoregulfo | 8:346c55cb6033 | 199 | /* fill in integer part */ |
salvatoregulfo | 8:346c55cb6033 | 200 | sprintf(str, "%i.", intPart); |
salvatoregulfo | 8:346c55cb6033 | 201 | |
salvatoregulfo | 8:346c55cb6033 | 202 | /* prepare fill in of fractional part */ |
salvatoregulfo | 8:346c55cb6033 | 203 | len = strlen(str); |
salvatoregulfo | 8:346c55cb6033 | 204 | ptr = &str[len]; |
salvatoregulfo | 8:346c55cb6033 | 205 | |
salvatoregulfo | 8:346c55cb6033 | 206 | /* fill in leading fractional zeros */ |
salvatoregulfo | 8:346c55cb6033 | 207 | for (i/=10;i>1; i/=10, ptr++) { |
salvatoregulfo | 8:346c55cb6033 | 208 | if (fractPart >= i) { |
salvatoregulfo | 8:346c55cb6033 | 209 | break; |
salvatoregulfo | 8:346c55cb6033 | 210 | } |
salvatoregulfo | 8:346c55cb6033 | 211 | *ptr = '0'; |
salvatoregulfo | 8:346c55cb6033 | 212 | } |
salvatoregulfo | 8:346c55cb6033 | 213 | |
salvatoregulfo | 8:346c55cb6033 | 214 | /* fill in (rest of) fractional part */ |
salvatoregulfo | 8:346c55cb6033 | 215 | sprintf(ptr, "%i", fractPart); |
salvatoregulfo | 8:346c55cb6033 | 216 | |
salvatoregulfo | 8:346c55cb6033 | 217 | return str; |
salvatoregulfo | 8:346c55cb6033 | 218 | } |
salvatoregulfo | 8:346c55cb6033 | 219 | |
mluis | 0:45496a70a8a5 | 220 | /*! |
mluis | 0:45496a70a8a5 | 221 | * Device states |
mluis | 0:45496a70a8a5 | 222 | */ |
mluis | 7:5077515c163b | 223 | static enum eDeviceState |
mluis | 0:45496a70a8a5 | 224 | { |
mluis | 0:45496a70a8a5 | 225 | DEVICE_STATE_INIT, |
mluis | 0:45496a70a8a5 | 226 | DEVICE_STATE_JOIN, |
mluis | 0:45496a70a8a5 | 227 | DEVICE_STATE_SEND, |
mluis | 0:45496a70a8a5 | 228 | DEVICE_STATE_CYCLE, |
mluis | 0:45496a70a8a5 | 229 | DEVICE_STATE_SLEEP |
mluis | 0:45496a70a8a5 | 230 | }DeviceState; |
mluis | 0:45496a70a8a5 | 231 | |
mluis | 0:45496a70a8a5 | 232 | /*! |
mluis | 0:45496a70a8a5 | 233 | * LoRaWAN compliance tests support data |
mluis | 0:45496a70a8a5 | 234 | */ |
mluis | 0:45496a70a8a5 | 235 | struct ComplianceTest_s |
mluis | 0:45496a70a8a5 | 236 | { |
mluis | 0:45496a70a8a5 | 237 | bool Running; |
mluis | 0:45496a70a8a5 | 238 | uint8_t State; |
mluis | 0:45496a70a8a5 | 239 | bool IsTxConfirmed; |
mluis | 0:45496a70a8a5 | 240 | uint8_t AppPort; |
mluis | 0:45496a70a8a5 | 241 | uint8_t AppDataSize; |
mluis | 0:45496a70a8a5 | 242 | uint8_t *AppDataBuffer; |
mluis | 0:45496a70a8a5 | 243 | uint16_t DownLinkCounter; |
mluis | 0:45496a70a8a5 | 244 | bool LinkCheck; |
mluis | 0:45496a70a8a5 | 245 | uint8_t DemodMargin; |
mluis | 0:45496a70a8a5 | 246 | uint8_t NbGateways; |
mluis | 0:45496a70a8a5 | 247 | }ComplianceTest; |
mluis | 0:45496a70a8a5 | 248 | |
mluis | 0:45496a70a8a5 | 249 | /* |
mluis | 0:45496a70a8a5 | 250 | * SerialDisplay managment variables |
mluis | 0:45496a70a8a5 | 251 | */ |
mluis | 0:45496a70a8a5 | 252 | |
rschiano | 10:88f1c052f9e9 | 253 | /* |
rschiano | 10:88f1c052f9e9 | 254 | * Seriale per comunicare con BBB |
rschiano | 10:88f1c052f9e9 | 255 | */ |
rschiano | 10:88f1c052f9e9 | 256 | RawSerial mySerial(PC_10,PC_11,115200); |
rschiano | 10:88f1c052f9e9 | 257 | |
rschiano | 10:88f1c052f9e9 | 258 | |
mluis | 0:45496a70a8a5 | 259 | /*! |
mluis | 0:45496a70a8a5 | 260 | * Indicates if the MAC layer network join status has changed. |
mluis | 0:45496a70a8a5 | 261 | */ |
mluis | 0:45496a70a8a5 | 262 | static bool IsNetworkJoinedStatusUpdate = false; |
mluis | 0:45496a70a8a5 | 263 | |
mluis | 0:45496a70a8a5 | 264 | /*! |
mluis | 0:45496a70a8a5 | 265 | * Strucure containing the Uplink status |
mluis | 0:45496a70a8a5 | 266 | */ |
mluis | 0:45496a70a8a5 | 267 | struct sLoRaMacUplinkStatus |
mluis | 0:45496a70a8a5 | 268 | { |
mluis | 0:45496a70a8a5 | 269 | uint8_t Acked; |
mluis | 0:45496a70a8a5 | 270 | int8_t Datarate; |
mluis | 0:45496a70a8a5 | 271 | uint16_t UplinkCounter; |
mluis | 0:45496a70a8a5 | 272 | uint8_t Port; |
mluis | 0:45496a70a8a5 | 273 | uint8_t *Buffer; |
mluis | 0:45496a70a8a5 | 274 | uint8_t BufferSize; |
salvatoregulfo | 8:346c55cb6033 | 275 | |
salvatoregulfo | 8:346c55cb6033 | 276 | }LoRaMacUplinkStatus; |
mluis | 0:45496a70a8a5 | 277 | volatile bool UplinkStatusUpdated = false; |
mluis | 0:45496a70a8a5 | 278 | |
mluis | 0:45496a70a8a5 | 279 | /*! |
mluis | 0:45496a70a8a5 | 280 | * Strucure containing the Downlink status |
mluis | 0:45496a70a8a5 | 281 | */ |
mluis | 0:45496a70a8a5 | 282 | struct sLoRaMacDownlinkStatus |
mluis | 0:45496a70a8a5 | 283 | { |
mluis | 0:45496a70a8a5 | 284 | int16_t Rssi; |
mluis | 0:45496a70a8a5 | 285 | int8_t Snr; |
mluis | 0:45496a70a8a5 | 286 | uint16_t DownlinkCounter; |
mluis | 0:45496a70a8a5 | 287 | bool RxData; |
mluis | 0:45496a70a8a5 | 288 | uint8_t Port; |
mluis | 0:45496a70a8a5 | 289 | uint8_t *Buffer; |
mluis | 0:45496a70a8a5 | 290 | uint8_t BufferSize; |
mluis | 0:45496a70a8a5 | 291 | }LoRaMacDownlinkStatus; |
mluis | 0:45496a70a8a5 | 292 | volatile bool DownlinkStatusUpdated = false; |
mluis | 0:45496a70a8a5 | 293 | |
mluis | 0:45496a70a8a5 | 294 | void SerialDisplayRefresh( void ) |
mluis | 0:45496a70a8a5 | 295 | { |
mluis | 0:45496a70a8a5 | 296 | MibRequestConfirm_t mibReq; |
mluis | 0:45496a70a8a5 | 297 | |
mluis | 0:45496a70a8a5 | 298 | SerialDisplayInit( ); |
mluis | 0:45496a70a8a5 | 299 | SerialDisplayUpdateActivationMode( OVER_THE_AIR_ACTIVATION ); |
mluis | 0:45496a70a8a5 | 300 | |
mluis | 0:45496a70a8a5 | 301 | #if( OVER_THE_AIR_ACTIVATION == 0 ) |
mluis | 0:45496a70a8a5 | 302 | SerialDisplayUpdateNwkId( LORAWAN_NETWORK_ID ); |
mluis | 0:45496a70a8a5 | 303 | SerialDisplayUpdateDevAddr( DevAddr ); |
mluis | 0:45496a70a8a5 | 304 | SerialDisplayUpdateKey( 12, NwkSKey ); |
mluis | 0:45496a70a8a5 | 305 | SerialDisplayUpdateKey( 13, AppSKey ); |
mluis | 5:62862ef9480b | 306 | #endif |
mluis | 0:45496a70a8a5 | 307 | SerialDisplayUpdateEui( 5, DevEui ); |
mluis | 0:45496a70a8a5 | 308 | SerialDisplayUpdateEui( 6, AppEui ); |
mluis | 0:45496a70a8a5 | 309 | SerialDisplayUpdateKey( 7, AppKey ); |
mluis | 0:45496a70a8a5 | 310 | |
mluis | 0:45496a70a8a5 | 311 | mibReq.Type = MIB_NETWORK_JOINED; |
mluis | 0:45496a70a8a5 | 312 | LoRaMacMibGetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 313 | SerialDisplayUpdateNetworkIsJoined( mibReq.Param.IsNetworkJoined ); |
mluis | 0:45496a70a8a5 | 314 | |
mluis | 0:45496a70a8a5 | 315 | SerialDisplayUpdateAdr( LORAWAN_ADR_ON ); |
mluis | 0:45496a70a8a5 | 316 | #if defined( USE_BAND_868 ) |
mluis | 0:45496a70a8a5 | 317 | SerialDisplayUpdateDutyCycle( LORAWAN_DUTYCYCLE_ON ); |
mluis | 0:45496a70a8a5 | 318 | #else |
mluis | 0:45496a70a8a5 | 319 | SerialDisplayUpdateDutyCycle( false ); |
mluis | 0:45496a70a8a5 | 320 | #endif |
mluis | 0:45496a70a8a5 | 321 | SerialDisplayUpdatePublicNetwork( LORAWAN_PUBLIC_NETWORK ); |
mluis | 0:45496a70a8a5 | 322 | |
mluis | 0:45496a70a8a5 | 323 | SerialDisplayUpdateLedState( 3, AppLedStateOn ); |
mluis | 0:45496a70a8a5 | 324 | } |
mluis | 0:45496a70a8a5 | 325 | |
mluis | 0:45496a70a8a5 | 326 | void SerialRxProcess( void ) |
mluis | 0:45496a70a8a5 | 327 | { |
mluis | 0:45496a70a8a5 | 328 | if( SerialDisplayReadable( ) == true ) |
mluis | 0:45496a70a8a5 | 329 | { |
mluis | 0:45496a70a8a5 | 330 | switch( SerialDisplayGetChar( ) ) |
mluis | 0:45496a70a8a5 | 331 | { |
mluis | 0:45496a70a8a5 | 332 | case 'R': |
mluis | 0:45496a70a8a5 | 333 | case 'r': |
mluis | 0:45496a70a8a5 | 334 | // Refresh Serial screen |
mluis | 0:45496a70a8a5 | 335 | SerialDisplayRefresh( ); |
mluis | 0:45496a70a8a5 | 336 | break; |
mluis | 0:45496a70a8a5 | 337 | default: |
mluis | 0:45496a70a8a5 | 338 | break; |
mluis | 0:45496a70a8a5 | 339 | } |
mluis | 0:45496a70a8a5 | 340 | } |
mluis | 0:45496a70a8a5 | 341 | } |
mluis | 0:45496a70a8a5 | 342 | |
mluis | 0:45496a70a8a5 | 343 | /*! |
mluis | 0:45496a70a8a5 | 344 | * \brief Prepares the payload of the frame |
mluis | 0:45496a70a8a5 | 345 | */ |
rschiano | 10:88f1c052f9e9 | 346 | float value1, value2,value3; |
salvatoregulfo | 8:346c55cb6033 | 347 | char buffer1[32]; |
salvatoregulfo | 9:85c85c65299a | 348 | long dist1; |
salvatoregulfo | 8:346c55cb6033 | 349 | // int16_t Myaxes_int[3]; |
salvatoregulfo | 8:346c55cb6033 | 350 | // float Myaxes[3]; |
salvatoregulfo | 8:346c55cb6033 | 351 | // float sensitivity; |
salvatoregulfo | 8:346c55cb6033 | 352 | // int32_t axes[3]; |
salvatoregulfo | 9:85c85c65299a | 353 | char Cont[64]; |
salvatoregulfo | 9:85c85c65299a | 354 | // uint32_t Cont[64]; |
salvatoregulfo | 9:85c85c65299a | 355 | // InterruptIn BlueButton(USER_BUTTON); |
rschiano | 10:88f1c052f9e9 | 356 | |
rschiano | 10:88f1c052f9e9 | 357 | extern VT100 vt; |
rschiano | 10:88f1c052f9e9 | 358 | char myChar; |
mluis | 0:45496a70a8a5 | 359 | static void PrepareTxFrame( uint8_t port ) |
mluis | 0:45496a70a8a5 | 360 | { |
salvatoregulfo | 8:346c55cb6033 | 361 | |
mluis | 0:45496a70a8a5 | 362 | switch( port ) |
mluis | 0:45496a70a8a5 | 363 | { |
rschiano | 10:88f1c052f9e9 | 364 | case 0x44: |
rschiano | 10:88f1c052f9e9 | 365 | //<key:Geiger:192.168.1.1: timestamp: 1425243676924 conteggi: 8.70 stato: attivo> |
rschiano | 10:88f1c052f9e9 | 366 | vt.PutStringAt(70,2,"Ci arriva?"); |
rschiano | 10:88f1c052f9e9 | 367 | while(!mySerial.readable()); |
rschiano | 10:88f1c052f9e9 | 368 | if(mySerial.getc()=='{'){ |
rschiano | 10:88f1c052f9e9 | 369 | int i=0; |
rschiano | 10:88f1c052f9e9 | 370 | do |
rschiano | 10:88f1c052f9e9 | 371 | Cont[i] = mySerial.getc(); |
rschiano | 10:88f1c052f9e9 | 372 | while (Cont[i++]!='}'); |
rschiano | 10:88f1c052f9e9 | 373 | Cont[--i]=0x0; |
rschiano | 10:88f1c052f9e9 | 374 | } |
rschiano | 10:88f1c052f9e9 | 375 | vt.PutStringAt(70,2,(char*) Cont); |
rschiano | 10:88f1c052f9e9 | 376 | AppDataSize = sprintf((char*)AppData, (char*)Cont); |
rschiano | 10:88f1c052f9e9 | 377 | /*int i=0; |
rschiano | 10:88f1c052f9e9 | 378 | do |
rschiano | 10:88f1c052f9e9 | 379 | Cont[i] = mySerial.getc(); |
rschiano | 10:88f1c052f9e9 | 380 | while (Cont[i++]!='>'); |
rschiano | 10:88f1c052f9e9 | 381 | AppDataSize = sprintf((char*)AppData, (char*)Cont);*/ |
rschiano | 10:88f1c052f9e9 | 382 | //<key:Geiger:192.168.1.1,TS:1425243676924,count:8.70,stato: attivo>"); */ |
rschiano | 10:88f1c052f9e9 | 383 | break; |
salvatoregulfo | 8:346c55cb6033 | 384 | case 13: |
salvatoregulfo | 8:346c55cb6033 | 385 | |
salvatoregulfo | 9:85c85c65299a | 386 | |
rschiano | 10:88f1c052f9e9 | 387 | hum_temp->get_temperature(&value1); |
rschiano | 10:88f1c052f9e9 | 388 | hum_temp->get_humidity(&value2); |
rschiano | 10:88f1c052f9e9 | 389 | press_temp->get_pressure(&value3); |
rschiano | 10:88f1c052f9e9 | 390 | //dist1 = usensor.getCurrentDistance(); |
salvatoregulfo | 9:85c85c65299a | 391 | // usensor->getCurrentDistance(&dist1); |
rschiano | 10:88f1c052f9e9 | 392 | //strcpy((char*)Cont, (char*) print_double(buffer1,(double)dist1) ); |
rschiano | 10:88f1c052f9e9 | 393 | //SerialDisplayDrawTitle("Ricchione!!!!"); |
rschiano | 10:88f1c052f9e9 | 394 | /*strcpy((char*)Cont, (char*) "Ricchione!!!" ); |
rschiano | 10:88f1c052f9e9 | 395 | led = !led;*/ |
rschiano | 10:88f1c052f9e9 | 396 | vt.PutStringAt(70,2,"Ci arriva?"); |
rschiano | 10:88f1c052f9e9 | 397 | strcpy((char*)Cont, "{Temperatura:" ); |
rschiano | 10:88f1c052f9e9 | 398 | strcat((char*)Cont, print_double(buffer1,value1) ); |
rschiano | 10:88f1c052f9e9 | 399 | strcat((char*)Cont, ",Umidità:"); |
rschiano | 10:88f1c052f9e9 | 400 | strcat((char*)Cont, print_double(buffer1,value2)); |
rschiano | 10:88f1c052f9e9 | 401 | strcat((char*)Cont, ",Pressione:"); |
rschiano | 10:88f1c052f9e9 | 402 | strcat((char*)Cont, print_double(buffer1,value3)); |
rschiano | 10:88f1c052f9e9 | 403 | strcat((char*)Cont, "}"); |
rschiano | 10:88f1c052f9e9 | 404 | vt.PutStringAt(70,2,(char*) Cont); |
salvatoregulfo | 8:346c55cb6033 | 405 | /* acc_gyro->get_x_axes(axes); |
salvatoregulfo | 8:346c55cb6033 | 406 | strcpy(Cont,(char*) print_double(buffer1,axes[0])); |
salvatoregulfo | 8:346c55cb6033 | 407 | strcat(Cont, " "); |
salvatoregulfo | 8:346c55cb6033 | 408 | strcat(Cont,(char*)print_double(buffer1,axes[1])); |
salvatoregulfo | 8:346c55cb6033 | 409 | strcat(Cont, " "); |
salvatoregulfo | 8:346c55cb6033 | 410 | strcat(Cont,(char*)print_double(buffer1,axes[2])); |
salvatoregulfo | 8:346c55cb6033 | 411 | strcat(Cont, " "); |
salvatoregulfo | 8:346c55cb6033 | 412 | strcat(Cont, (char*)print_double(buffer1,value1)); |
salvatoregulfo | 8:346c55cb6033 | 413 | strcat(Cont, " "); |
salvatoregulfo | 8:346c55cb6033 | 414 | strcat(Cont, (char*)print_double(buffer1,value2)); |
salvatoregulfo | 8:346c55cb6033 | 415 | AppDataSize = sprintf ((char*)AppData, Cont); |
salvatoregulfo | 8:346c55cb6033 | 416 | |
salvatoregulfo | 8:346c55cb6033 | 417 | acc_gyro->get_x_axes_raw(Myaxes_int); |
salvatoregulfo | 8:346c55cb6033 | 418 | acc_gyro->get_x_sensitivity(&sensitivity); |
salvatoregulfo | 8:346c55cb6033 | 419 | Myaxes[0]=((float)(Myaxes_int[0]))*sensitivity; |
salvatoregulfo | 8:346c55cb6033 | 420 | Myaxes[1]=((float)(Myaxes_int[1]))*sensitivity; |
salvatoregulfo | 8:346c55cb6033 | 421 | Myaxes[2]=((float)(Myaxes_int[2]))*sensitivity; |
salvatoregulfo | 8:346c55cb6033 | 422 | strcpy(Cont, (char*) print_double(buffer1, value1)); |
salvatoregulfo | 8:346c55cb6033 | 423 | strcat(Cont, " "); |
salvatoregulfo | 8:346c55cb6033 | 424 | strcat(Cont, (char*) print_double(buffer1, value2)); |
salvatoregulfo | 8:346c55cb6033 | 425 | strcat(Cont, " "); |
salvatoregulfo | 8:346c55cb6033 | 426 | strcat(Cont, (char*) print_double(buffer1, Myaxes[0])); |
salvatoregulfo | 8:346c55cb6033 | 427 | strcat(Cont, " "); |
salvatoregulfo | 8:346c55cb6033 | 428 | strcat(Cont, (char*) print_double(buffer1, Myaxes[1])); |
salvatoregulfo | 8:346c55cb6033 | 429 | strcat(Cont, " "); |
salvatoregulfo | 8:346c55cb6033 | 430 | strcat(Cont, (char*) print_double(buffer1, Myaxes[2])); |
salvatoregulfo | 8:346c55cb6033 | 431 | strcat(Cont, " "); |
salvatoregulfo | 8:346c55cb6033 | 432 | strcat(Cont, (char*) print_double(buffer1, value1)); |
salvatoregulfo | 8:346c55cb6033 | 433 | strcat(Cont, " "); |
salvatoregulfo | 8:346c55cb6033 | 434 | strcat(Cont, (char*) print_double(buffer1, value2)); */ |
salvatoregulfo | 8:346c55cb6033 | 435 | |
salvatoregulfo | 9:85c85c65299a | 436 | /* while(1) { |
salvatoregulfo | 9:85c85c65299a | 437 | // AppDataSize = sprintf ((char*)AppData,(char*)Cont); |
salvatoregulfo | 9:85c85c65299a | 438 | if (BlueButton) |
salvatoregulfo | 8:346c55cb6033 | 439 | { AppDataSize = sprintf((char*)AppData, "0"); |
salvatoregulfo | 9:85c85c65299a | 440 | break; |
salvatoregulfo | 9:85c85c65299a | 441 | } |
salvatoregulfo | 8:346c55cb6033 | 442 | else |
salvatoregulfo | 8:346c55cb6033 | 443 | { AppDataSize = sprintf((char*)AppData, "1"); |
salvatoregulfo | 9:85c85c65299a | 444 | break; |
salvatoregulfo | 9:85c85c65299a | 445 | } */ |
salvatoregulfo | 9:85c85c65299a | 446 | AppDataSize = sprintf((char*)AppData, (char*)Cont); |
salvatoregulfo | 9:85c85c65299a | 447 | // } |
salvatoregulfo | 8:346c55cb6033 | 448 | break; |
salvatoregulfo | 8:346c55cb6033 | 449 | |
mluis | 0:45496a70a8a5 | 450 | case 15: |
mluis | 0:45496a70a8a5 | 451 | { |
mluis | 0:45496a70a8a5 | 452 | AppData[0] = AppLedStateOn; |
mluis | 0:45496a70a8a5 | 453 | if( IsTxConfirmed == true ) |
mluis | 0:45496a70a8a5 | 454 | { |
mluis | 0:45496a70a8a5 | 455 | AppData[1] = LoRaMacDownlinkStatus.DownlinkCounter >> 8; |
mluis | 0:45496a70a8a5 | 456 | AppData[2] = LoRaMacDownlinkStatus.DownlinkCounter; |
mluis | 0:45496a70a8a5 | 457 | AppData[3] = LoRaMacDownlinkStatus.Rssi >> 8; |
mluis | 0:45496a70a8a5 | 458 | AppData[4] = LoRaMacDownlinkStatus.Rssi; |
mluis | 0:45496a70a8a5 | 459 | AppData[5] = LoRaMacDownlinkStatus.Snr; |
mluis | 0:45496a70a8a5 | 460 | } |
mluis | 0:45496a70a8a5 | 461 | } |
salvatoregulfo | 8:346c55cb6033 | 462 | break; |
mluis | 0:45496a70a8a5 | 463 | case 224: |
mluis | 0:45496a70a8a5 | 464 | if( ComplianceTest.LinkCheck == true ) |
mluis | 0:45496a70a8a5 | 465 | { |
mluis | 0:45496a70a8a5 | 466 | ComplianceTest.LinkCheck = false; |
mluis | 0:45496a70a8a5 | 467 | AppDataSize = 3; |
mluis | 0:45496a70a8a5 | 468 | AppData[0] = 5; |
mluis | 0:45496a70a8a5 | 469 | AppData[1] = ComplianceTest.DemodMargin; |
mluis | 0:45496a70a8a5 | 470 | AppData[2] = ComplianceTest.NbGateways; |
mluis | 0:45496a70a8a5 | 471 | ComplianceTest.State = 1; |
mluis | 0:45496a70a8a5 | 472 | } |
mluis | 0:45496a70a8a5 | 473 | else |
mluis | 0:45496a70a8a5 | 474 | { |
mluis | 0:45496a70a8a5 | 475 | switch( ComplianceTest.State ) |
mluis | 0:45496a70a8a5 | 476 | { |
mluis | 0:45496a70a8a5 | 477 | case 4: |
mluis | 0:45496a70a8a5 | 478 | ComplianceTest.State = 1; |
mluis | 0:45496a70a8a5 | 479 | break; |
mluis | 0:45496a70a8a5 | 480 | case 1: |
mluis | 0:45496a70a8a5 | 481 | AppDataSize = 2; |
mluis | 0:45496a70a8a5 | 482 | AppData[0] = ComplianceTest.DownLinkCounter >> 8; |
mluis | 0:45496a70a8a5 | 483 | AppData[1] = ComplianceTest.DownLinkCounter; |
mluis | 0:45496a70a8a5 | 484 | break; |
mluis | 0:45496a70a8a5 | 485 | } |
mluis | 0:45496a70a8a5 | 486 | } |
mluis | 0:45496a70a8a5 | 487 | break; |
mluis | 0:45496a70a8a5 | 488 | default: |
mluis | 0:45496a70a8a5 | 489 | break; |
mluis | 0:45496a70a8a5 | 490 | } |
mluis | 0:45496a70a8a5 | 491 | } |
mluis | 0:45496a70a8a5 | 492 | |
mluis | 0:45496a70a8a5 | 493 | /*! |
mluis | 0:45496a70a8a5 | 494 | * \brief Prepares the payload of the frame |
mluis | 0:45496a70a8a5 | 495 | * |
mluis | 0:45496a70a8a5 | 496 | * \retval [0: frame could be send, 1: error] |
mluis | 0:45496a70a8a5 | 497 | */ |
salvatoregulfo | 8:346c55cb6033 | 498 | static bool SendFrame(void) |
salvatoregulfo | 8:346c55cb6033 | 499 | |
mluis | 0:45496a70a8a5 | 500 | { |
mluis | 0:45496a70a8a5 | 501 | McpsReq_t mcpsReq; |
mluis | 0:45496a70a8a5 | 502 | LoRaMacTxInfo_t txInfo; |
mluis | 7:5077515c163b | 503 | |
mluis | 0:45496a70a8a5 | 504 | if( LoRaMacQueryTxPossible( AppDataSize, &txInfo ) != LORAMAC_STATUS_OK ) |
mluis | 0:45496a70a8a5 | 505 | { |
mluis | 0:45496a70a8a5 | 506 | // Send empty frame in order to flush MAC commands |
mluis | 0:45496a70a8a5 | 507 | mcpsReq.Type = MCPS_UNCONFIRMED; |
mluis | 0:45496a70a8a5 | 508 | mcpsReq.Req.Unconfirmed.fBuffer = NULL; |
mluis | 0:45496a70a8a5 | 509 | mcpsReq.Req.Unconfirmed.fBufferSize = 0; |
mluis | 0:45496a70a8a5 | 510 | mcpsReq.Req.Unconfirmed.Datarate = LORAWAN_DEFAULT_DATARATE; |
mluis | 3:3152aa75c58d | 511 | |
mluis | 0:45496a70a8a5 | 512 | LoRaMacUplinkStatus.Acked = false; |
mluis | 0:45496a70a8a5 | 513 | LoRaMacUplinkStatus.Port = 0; |
mluis | 0:45496a70a8a5 | 514 | LoRaMacUplinkStatus.Buffer = NULL; |
mluis | 0:45496a70a8a5 | 515 | LoRaMacUplinkStatus.BufferSize = 0; |
mluis | 0:45496a70a8a5 | 516 | SerialDisplayUpdateFrameType( false ); |
mluis | 0:45496a70a8a5 | 517 | } |
mluis | 0:45496a70a8a5 | 518 | else |
mluis | 0:45496a70a8a5 | 519 | { |
mluis | 0:45496a70a8a5 | 520 | LoRaMacUplinkStatus.Acked = false; |
mluis | 0:45496a70a8a5 | 521 | LoRaMacUplinkStatus.Port = AppPort; |
mluis | 0:45496a70a8a5 | 522 | LoRaMacUplinkStatus.Buffer = AppData; |
mluis | 0:45496a70a8a5 | 523 | LoRaMacUplinkStatus.BufferSize = AppDataSize; |
mluis | 0:45496a70a8a5 | 524 | SerialDisplayUpdateFrameType( IsTxConfirmed ); |
mluis | 0:45496a70a8a5 | 525 | |
mluis | 0:45496a70a8a5 | 526 | if( IsTxConfirmed == false ) |
mluis | 0:45496a70a8a5 | 527 | { |
mluis | 0:45496a70a8a5 | 528 | mcpsReq.Type = MCPS_UNCONFIRMED; |
mluis | 0:45496a70a8a5 | 529 | mcpsReq.Req.Unconfirmed.fPort = AppPort; |
mluis | 0:45496a70a8a5 | 530 | mcpsReq.Req.Unconfirmed.fBuffer = AppData; |
mluis | 0:45496a70a8a5 | 531 | mcpsReq.Req.Unconfirmed.fBufferSize = AppDataSize; |
mluis | 0:45496a70a8a5 | 532 | mcpsReq.Req.Unconfirmed.Datarate = LORAWAN_DEFAULT_DATARATE; |
mluis | 0:45496a70a8a5 | 533 | } |
mluis | 0:45496a70a8a5 | 534 | else |
mluis | 0:45496a70a8a5 | 535 | { |
mluis | 0:45496a70a8a5 | 536 | mcpsReq.Type = MCPS_CONFIRMED; |
mluis | 0:45496a70a8a5 | 537 | mcpsReq.Req.Confirmed.fPort = AppPort; |
mluis | 0:45496a70a8a5 | 538 | mcpsReq.Req.Confirmed.fBuffer = AppData; |
mluis | 0:45496a70a8a5 | 539 | mcpsReq.Req.Confirmed.fBufferSize = AppDataSize; |
mluis | 2:2eeaeae2c725 | 540 | mcpsReq.Req.Confirmed.NbTrials = 8; |
mluis | 0:45496a70a8a5 | 541 | mcpsReq.Req.Confirmed.Datarate = LORAWAN_DEFAULT_DATARATE; |
mluis | 0:45496a70a8a5 | 542 | } |
mluis | 0:45496a70a8a5 | 543 | } |
mluis | 0:45496a70a8a5 | 544 | |
mluis | 0:45496a70a8a5 | 545 | if( LoRaMacMcpsRequest( &mcpsReq ) == LORAMAC_STATUS_OK ) |
mluis | 0:45496a70a8a5 | 546 | { |
mluis | 0:45496a70a8a5 | 547 | return false; |
mluis | 0:45496a70a8a5 | 548 | } |
mluis | 0:45496a70a8a5 | 549 | return true; |
mluis | 0:45496a70a8a5 | 550 | } |
mluis | 0:45496a70a8a5 | 551 | |
mluis | 0:45496a70a8a5 | 552 | /*! |
mluis | 0:45496a70a8a5 | 553 | * \brief Function executed on TxNextPacket Timeout event |
mluis | 0:45496a70a8a5 | 554 | */ |
mluis | 0:45496a70a8a5 | 555 | static void OnTxNextPacketTimerEvent( void ) |
mluis | 0:45496a70a8a5 | 556 | { |
mluis | 0:45496a70a8a5 | 557 | MibRequestConfirm_t mibReq; |
mluis | 0:45496a70a8a5 | 558 | LoRaMacStatus_t status; |
mluis | 0:45496a70a8a5 | 559 | |
mluis | 0:45496a70a8a5 | 560 | TimerStop( &TxNextPacketTimer ); |
mluis | 0:45496a70a8a5 | 561 | |
mluis | 0:45496a70a8a5 | 562 | mibReq.Type = MIB_NETWORK_JOINED; |
mluis | 0:45496a70a8a5 | 563 | status = LoRaMacMibGetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 564 | |
mluis | 0:45496a70a8a5 | 565 | if( status == LORAMAC_STATUS_OK ) |
mluis | 0:45496a70a8a5 | 566 | { |
mluis | 0:45496a70a8a5 | 567 | if( mibReq.Param.IsNetworkJoined == true ) |
mluis | 0:45496a70a8a5 | 568 | { |
mluis | 0:45496a70a8a5 | 569 | DeviceState = DEVICE_STATE_SEND; |
mluis | 0:45496a70a8a5 | 570 | NextTx = true; |
mluis | 0:45496a70a8a5 | 571 | } |
mluis | 0:45496a70a8a5 | 572 | else |
mluis | 0:45496a70a8a5 | 573 | { |
mluis | 0:45496a70a8a5 | 574 | DeviceState = DEVICE_STATE_JOIN; |
mluis | 0:45496a70a8a5 | 575 | } |
mluis | 0:45496a70a8a5 | 576 | } |
mluis | 0:45496a70a8a5 | 577 | } |
mluis | 0:45496a70a8a5 | 578 | |
mluis | 0:45496a70a8a5 | 579 | /*! |
mluis | 0:45496a70a8a5 | 580 | * \brief Function executed on Led 1 Timeout event |
mluis | 0:45496a70a8a5 | 581 | */ |
mluis | 0:45496a70a8a5 | 582 | static void OnLed1TimerEvent( void ) |
mluis | 0:45496a70a8a5 | 583 | { |
mluis | 0:45496a70a8a5 | 584 | TimerStop( &Led1Timer ); |
mluis | 0:45496a70a8a5 | 585 | // Switch LED 1 OFF |
mluis | 0:45496a70a8a5 | 586 | Led1State = false; |
mluis | 0:45496a70a8a5 | 587 | Led1StateChanged = true; |
mluis | 0:45496a70a8a5 | 588 | } |
mluis | 0:45496a70a8a5 | 589 | |
mluis | 0:45496a70a8a5 | 590 | /*! |
mluis | 0:45496a70a8a5 | 591 | * \brief Function executed on Led 2 Timeout event |
mluis | 0:45496a70a8a5 | 592 | */ |
mluis | 0:45496a70a8a5 | 593 | static void OnLed2TimerEvent( void ) |
mluis | 0:45496a70a8a5 | 594 | { |
mluis | 0:45496a70a8a5 | 595 | TimerStop( &Led2Timer ); |
mluis | 0:45496a70a8a5 | 596 | // Switch LED 2 OFF |
mluis | 0:45496a70a8a5 | 597 | Led2State = false; |
mluis | 0:45496a70a8a5 | 598 | Led2StateChanged = true; |
mluis | 0:45496a70a8a5 | 599 | } |
mluis | 0:45496a70a8a5 | 600 | |
mluis | 0:45496a70a8a5 | 601 | /*! |
mluis | 0:45496a70a8a5 | 602 | * \brief MCPS-Confirm event function |
mluis | 0:45496a70a8a5 | 603 | * |
mluis | 3:3152aa75c58d | 604 | * \param [IN] mcpsConfirm - Pointer to the confirm structure, |
mluis | 0:45496a70a8a5 | 605 | * containing confirm attributes. |
mluis | 0:45496a70a8a5 | 606 | */ |
mluis | 3:3152aa75c58d | 607 | static void McpsConfirm( McpsConfirm_t *mcpsConfirm ) |
mluis | 0:45496a70a8a5 | 608 | { |
mluis | 3:3152aa75c58d | 609 | if( mcpsConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) |
mluis | 0:45496a70a8a5 | 610 | { |
mluis | 3:3152aa75c58d | 611 | switch( mcpsConfirm->McpsRequest ) |
mluis | 0:45496a70a8a5 | 612 | { |
mluis | 0:45496a70a8a5 | 613 | case MCPS_UNCONFIRMED: |
mluis | 0:45496a70a8a5 | 614 | { |
mluis | 0:45496a70a8a5 | 615 | // Check Datarate |
mluis | 0:45496a70a8a5 | 616 | // Check TxPower |
mluis | 0:45496a70a8a5 | 617 | break; |
mluis | 0:45496a70a8a5 | 618 | } |
mluis | 0:45496a70a8a5 | 619 | case MCPS_CONFIRMED: |
mluis | 0:45496a70a8a5 | 620 | { |
mluis | 0:45496a70a8a5 | 621 | // Check Datarate |
mluis | 0:45496a70a8a5 | 622 | // Check TxPower |
mluis | 0:45496a70a8a5 | 623 | // Check AckReceived |
mluis | 3:3152aa75c58d | 624 | // Check NbTrials |
mluis | 3:3152aa75c58d | 625 | LoRaMacUplinkStatus.Acked = mcpsConfirm->AckReceived; |
mluis | 0:45496a70a8a5 | 626 | break; |
mluis | 0:45496a70a8a5 | 627 | } |
mluis | 0:45496a70a8a5 | 628 | case MCPS_PROPRIETARY: |
mluis | 0:45496a70a8a5 | 629 | { |
mluis | 0:45496a70a8a5 | 630 | break; |
mluis | 0:45496a70a8a5 | 631 | } |
mluis | 0:45496a70a8a5 | 632 | default: |
mluis | 0:45496a70a8a5 | 633 | break; |
mluis | 0:45496a70a8a5 | 634 | } |
mluis | 3:3152aa75c58d | 635 | LoRaMacUplinkStatus.Datarate = mcpsConfirm->Datarate; |
mluis | 3:3152aa75c58d | 636 | LoRaMacUplinkStatus.UplinkCounter = mcpsConfirm->UpLinkCounter; |
mluis | 3:3152aa75c58d | 637 | |
mluis | 5:62862ef9480b | 638 | // Switch LED 1 ON |
mluis | 5:62862ef9480b | 639 | Led1State = true; |
mluis | 5:62862ef9480b | 640 | Led1StateChanged = true; |
mluis | 5:62862ef9480b | 641 | TimerStart( &Led1Timer ); |
mluis | 5:62862ef9480b | 642 | |
mluis | 0:45496a70a8a5 | 643 | UplinkStatusUpdated = true; |
mluis | 0:45496a70a8a5 | 644 | } |
mluis | 0:45496a70a8a5 | 645 | NextTx = true; |
mluis | 0:45496a70a8a5 | 646 | } |
mluis | 0:45496a70a8a5 | 647 | |
mluis | 0:45496a70a8a5 | 648 | /*! |
mluis | 0:45496a70a8a5 | 649 | * \brief MCPS-Indication event function |
mluis | 0:45496a70a8a5 | 650 | * |
mluis | 3:3152aa75c58d | 651 | * \param [IN] mcpsIndication - Pointer to the indication structure, |
mluis | 0:45496a70a8a5 | 652 | * containing indication attributes. |
mluis | 0:45496a70a8a5 | 653 | */ |
mluis | 3:3152aa75c58d | 654 | static void McpsIndication( McpsIndication_t *mcpsIndication ) |
mluis | 0:45496a70a8a5 | 655 | { |
mluis | 3:3152aa75c58d | 656 | if( mcpsIndication->Status != LORAMAC_EVENT_INFO_STATUS_OK ) |
mluis | 0:45496a70a8a5 | 657 | { |
mluis | 0:45496a70a8a5 | 658 | return; |
mluis | 0:45496a70a8a5 | 659 | } |
mluis | 0:45496a70a8a5 | 660 | |
mluis | 3:3152aa75c58d | 661 | switch( mcpsIndication->McpsIndication ) |
mluis | 0:45496a70a8a5 | 662 | { |
mluis | 0:45496a70a8a5 | 663 | case MCPS_UNCONFIRMED: |
mluis | 0:45496a70a8a5 | 664 | { |
mluis | 0:45496a70a8a5 | 665 | break; |
mluis | 0:45496a70a8a5 | 666 | } |
mluis | 0:45496a70a8a5 | 667 | case MCPS_CONFIRMED: |
mluis | 0:45496a70a8a5 | 668 | { |
mluis | 0:45496a70a8a5 | 669 | break; |
mluis | 0:45496a70a8a5 | 670 | } |
mluis | 0:45496a70a8a5 | 671 | case MCPS_PROPRIETARY: |
mluis | 0:45496a70a8a5 | 672 | { |
mluis | 0:45496a70a8a5 | 673 | break; |
mluis | 0:45496a70a8a5 | 674 | } |
mluis | 0:45496a70a8a5 | 675 | case MCPS_MULTICAST: |
mluis | 0:45496a70a8a5 | 676 | { |
mluis | 0:45496a70a8a5 | 677 | break; |
mluis | 0:45496a70a8a5 | 678 | } |
mluis | 0:45496a70a8a5 | 679 | default: |
mluis | 0:45496a70a8a5 | 680 | break; |
mluis | 0:45496a70a8a5 | 681 | } |
mluis | 0:45496a70a8a5 | 682 | |
mluis | 0:45496a70a8a5 | 683 | // Check Multicast |
mluis | 0:45496a70a8a5 | 684 | // Check Port |
mluis | 0:45496a70a8a5 | 685 | // Check Datarate |
mluis | 0:45496a70a8a5 | 686 | // Check FramePending |
mluis | 0:45496a70a8a5 | 687 | // Check Buffer |
mluis | 0:45496a70a8a5 | 688 | // Check BufferSize |
mluis | 0:45496a70a8a5 | 689 | // Check Rssi |
mluis | 0:45496a70a8a5 | 690 | // Check Snr |
mluis | 0:45496a70a8a5 | 691 | // Check RxSlot |
mluis | 3:3152aa75c58d | 692 | LoRaMacDownlinkStatus.Rssi = mcpsIndication->Rssi; |
mluis | 3:3152aa75c58d | 693 | if( mcpsIndication->Snr & 0x80 ) // The SNR sign bit is 1 |
mluis | 0:45496a70a8a5 | 694 | { |
mluis | 0:45496a70a8a5 | 695 | // Invert and divide by 4 |
mluis | 3:3152aa75c58d | 696 | LoRaMacDownlinkStatus.Snr = ( ( ~mcpsIndication->Snr + 1 ) & 0xFF ) >> 2; |
mluis | 0:45496a70a8a5 | 697 | LoRaMacDownlinkStatus.Snr = -LoRaMacDownlinkStatus.Snr; |
mluis | 0:45496a70a8a5 | 698 | } |
mluis | 0:45496a70a8a5 | 699 | else |
mluis | 0:45496a70a8a5 | 700 | { |
mluis | 0:45496a70a8a5 | 701 | // Divide by 4 |
mluis | 3:3152aa75c58d | 702 | LoRaMacDownlinkStatus.Snr = ( mcpsIndication->Snr & 0xFF ) >> 2; |
mluis | 0:45496a70a8a5 | 703 | } |
mluis | 0:45496a70a8a5 | 704 | LoRaMacDownlinkStatus.DownlinkCounter++; |
mluis | 3:3152aa75c58d | 705 | LoRaMacDownlinkStatus.RxData = mcpsIndication->RxData; |
mluis | 3:3152aa75c58d | 706 | LoRaMacDownlinkStatus.Port = mcpsIndication->Port; |
mluis | 3:3152aa75c58d | 707 | LoRaMacDownlinkStatus.Buffer = mcpsIndication->Buffer; |
mluis | 3:3152aa75c58d | 708 | LoRaMacDownlinkStatus.BufferSize = mcpsIndication->BufferSize; |
mluis | 0:45496a70a8a5 | 709 | |
mluis | 0:45496a70a8a5 | 710 | if( ComplianceTest.Running == true ) |
mluis | 0:45496a70a8a5 | 711 | { |
mluis | 0:45496a70a8a5 | 712 | ComplianceTest.DownLinkCounter++; |
mluis | 0:45496a70a8a5 | 713 | } |
mluis | 0:45496a70a8a5 | 714 | |
mluis | 3:3152aa75c58d | 715 | if( mcpsIndication->RxData == true ) |
mluis | 0:45496a70a8a5 | 716 | { |
mluis | 3:3152aa75c58d | 717 | switch( mcpsIndication->Port ) |
mluis | 0:45496a70a8a5 | 718 | { |
mluis | 0:45496a70a8a5 | 719 | case 1: // The application LED can be controlled on port 1 or 2 |
mluis | 0:45496a70a8a5 | 720 | case 2: |
mluis | 3:3152aa75c58d | 721 | if( mcpsIndication->BufferSize == 1 ) |
mluis | 0:45496a70a8a5 | 722 | { |
mluis | 3:3152aa75c58d | 723 | AppLedStateOn = mcpsIndication->Buffer[0] & 0x01; |
mluis | 0:45496a70a8a5 | 724 | Led3StateChanged = true; |
mluis | 0:45496a70a8a5 | 725 | } |
mluis | 0:45496a70a8a5 | 726 | break; |
mluis | 0:45496a70a8a5 | 727 | case 224: |
mluis | 0:45496a70a8a5 | 728 | if( ComplianceTest.Running == false ) |
mluis | 0:45496a70a8a5 | 729 | { |
mluis | 0:45496a70a8a5 | 730 | // Check compliance test enable command (i) |
mluis | 3:3152aa75c58d | 731 | if( ( mcpsIndication->BufferSize == 4 ) && |
mluis | 3:3152aa75c58d | 732 | ( mcpsIndication->Buffer[0] == 0x01 ) && |
mluis | 3:3152aa75c58d | 733 | ( mcpsIndication->Buffer[1] == 0x01 ) && |
mluis | 3:3152aa75c58d | 734 | ( mcpsIndication->Buffer[2] == 0x01 ) && |
mluis | 3:3152aa75c58d | 735 | ( mcpsIndication->Buffer[3] == 0x01 ) ) |
mluis | 0:45496a70a8a5 | 736 | { |
mluis | 0:45496a70a8a5 | 737 | IsTxConfirmed = false; |
mluis | 0:45496a70a8a5 | 738 | AppPort = 224; |
mluis | 0:45496a70a8a5 | 739 | AppDataSize = 2; |
mluis | 0:45496a70a8a5 | 740 | ComplianceTest.DownLinkCounter = 0; |
mluis | 0:45496a70a8a5 | 741 | ComplianceTest.LinkCheck = false; |
mluis | 0:45496a70a8a5 | 742 | ComplianceTest.DemodMargin = 0; |
mluis | 0:45496a70a8a5 | 743 | ComplianceTest.NbGateways = 0; |
mluis | 0:45496a70a8a5 | 744 | ComplianceTest.Running = true; |
mluis | 0:45496a70a8a5 | 745 | ComplianceTest.State = 1; |
mluis | 7:5077515c163b | 746 | |
mluis | 0:45496a70a8a5 | 747 | MibRequestConfirm_t mibReq; |
mluis | 0:45496a70a8a5 | 748 | mibReq.Type = MIB_ADR; |
mluis | 0:45496a70a8a5 | 749 | mibReq.Param.AdrEnable = true; |
mluis | 0:45496a70a8a5 | 750 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 751 | |
mluis | 0:45496a70a8a5 | 752 | #if defined( USE_BAND_868 ) |
mluis | 0:45496a70a8a5 | 753 | LoRaMacTestSetDutyCycleOn( false ); |
mluis | 0:45496a70a8a5 | 754 | #endif |
mluis | 0:45496a70a8a5 | 755 | } |
mluis | 0:45496a70a8a5 | 756 | } |
mluis | 0:45496a70a8a5 | 757 | else |
mluis | 0:45496a70a8a5 | 758 | { |
mluis | 3:3152aa75c58d | 759 | ComplianceTest.State = mcpsIndication->Buffer[0]; |
mluis | 0:45496a70a8a5 | 760 | switch( ComplianceTest.State ) |
mluis | 0:45496a70a8a5 | 761 | { |
mluis | 0:45496a70a8a5 | 762 | case 0: // Check compliance test disable command (ii) |
mluis | 0:45496a70a8a5 | 763 | IsTxConfirmed = LORAWAN_CONFIRMED_MSG_ON; |
mluis | 0:45496a70a8a5 | 764 | AppPort = LORAWAN_APP_PORT; |
mluis | 0:45496a70a8a5 | 765 | AppDataSize = LORAWAN_APP_DATA_SIZE; |
mluis | 0:45496a70a8a5 | 766 | ComplianceTest.DownLinkCounter = 0; |
mluis | 0:45496a70a8a5 | 767 | ComplianceTest.Running = false; |
mluis | 7:5077515c163b | 768 | |
mluis | 0:45496a70a8a5 | 769 | MibRequestConfirm_t mibReq; |
mluis | 0:45496a70a8a5 | 770 | mibReq.Type = MIB_ADR; |
mluis | 0:45496a70a8a5 | 771 | mibReq.Param.AdrEnable = LORAWAN_ADR_ON; |
mluis | 0:45496a70a8a5 | 772 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 773 | #if defined( USE_BAND_868 ) |
mluis | 0:45496a70a8a5 | 774 | LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON ); |
mluis | 0:45496a70a8a5 | 775 | #endif |
mluis | 0:45496a70a8a5 | 776 | break; |
mluis | 0:45496a70a8a5 | 777 | case 1: // (iii, iv) |
mluis | 0:45496a70a8a5 | 778 | AppDataSize = 2; |
mluis | 0:45496a70a8a5 | 779 | break; |
mluis | 0:45496a70a8a5 | 780 | case 2: // Enable confirmed messages (v) |
mluis | 0:45496a70a8a5 | 781 | IsTxConfirmed = true; |
mluis | 0:45496a70a8a5 | 782 | ComplianceTest.State = 1; |
mluis | 0:45496a70a8a5 | 783 | break; |
mluis | 0:45496a70a8a5 | 784 | case 3: // Disable confirmed messages (vi) |
mluis | 0:45496a70a8a5 | 785 | IsTxConfirmed = false; |
mluis | 0:45496a70a8a5 | 786 | ComplianceTest.State = 1; |
mluis | 0:45496a70a8a5 | 787 | break; |
mluis | 0:45496a70a8a5 | 788 | case 4: // (vii) |
mluis | 3:3152aa75c58d | 789 | AppDataSize = mcpsIndication->BufferSize; |
mluis | 0:45496a70a8a5 | 790 | |
mluis | 0:45496a70a8a5 | 791 | AppData[0] = 4; |
mluis | 0:45496a70a8a5 | 792 | for( uint8_t i = 1; i < AppDataSize; i++ ) |
mluis | 0:45496a70a8a5 | 793 | { |
mluis | 3:3152aa75c58d | 794 | AppData[i] = mcpsIndication->Buffer[i] + 1; |
mluis | 0:45496a70a8a5 | 795 | } |
mluis | 0:45496a70a8a5 | 796 | break; |
mluis | 0:45496a70a8a5 | 797 | case 5: // (viii) |
mluis | 0:45496a70a8a5 | 798 | { |
mluis | 0:45496a70a8a5 | 799 | MlmeReq_t mlmeReq; |
mluis | 0:45496a70a8a5 | 800 | mlmeReq.Type = MLME_LINK_CHECK; |
mluis | 0:45496a70a8a5 | 801 | LoRaMacMlmeRequest( &mlmeReq ); |
mluis | 0:45496a70a8a5 | 802 | } |
mluis | 0:45496a70a8a5 | 803 | break; |
mluis | 5:62862ef9480b | 804 | case 6: // (ix) |
mluis | 5:62862ef9480b | 805 | { |
mluis | 5:62862ef9480b | 806 | MlmeReq_t mlmeReq; |
mluis | 5:62862ef9480b | 807 | |
mluis | 7:5077515c163b | 808 | // Disable TestMode and revert back to normal operation |
mluis | 7:5077515c163b | 809 | IsTxConfirmed = LORAWAN_CONFIRMED_MSG_ON; |
mluis | 7:5077515c163b | 810 | AppPort = LORAWAN_APP_PORT; |
mluis | 7:5077515c163b | 811 | AppDataSize = LORAWAN_APP_DATA_SIZE; |
mluis | 7:5077515c163b | 812 | ComplianceTest.DownLinkCounter = 0; |
mluis | 7:5077515c163b | 813 | ComplianceTest.Running = false; |
mluis | 7:5077515c163b | 814 | |
mluis | 7:5077515c163b | 815 | MibRequestConfirm_t mibReq; |
mluis | 7:5077515c163b | 816 | mibReq.Type = MIB_ADR; |
mluis | 7:5077515c163b | 817 | mibReq.Param.AdrEnable = LORAWAN_ADR_ON; |
mluis | 7:5077515c163b | 818 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 7:5077515c163b | 819 | #if defined( USE_BAND_868 ) |
mluis | 7:5077515c163b | 820 | LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON ); |
mluis | 7:5077515c163b | 821 | #endif |
mluis | 7:5077515c163b | 822 | |
mluis | 5:62862ef9480b | 823 | mlmeReq.Type = MLME_JOIN; |
mluis | 5:62862ef9480b | 824 | |
mluis | 5:62862ef9480b | 825 | mlmeReq.Req.Join.DevEui = DevEui; |
mluis | 5:62862ef9480b | 826 | mlmeReq.Req.Join.AppEui = AppEui; |
mluis | 5:62862ef9480b | 827 | mlmeReq.Req.Join.AppKey = AppKey; |
mluis | 7:5077515c163b | 828 | mlmeReq.Req.Join.NbTrials = 3; |
mluis | 5:62862ef9480b | 829 | |
mluis | 5:62862ef9480b | 830 | LoRaMacMlmeRequest( &mlmeReq ); |
mluis | 5:62862ef9480b | 831 | DeviceState = DEVICE_STATE_SLEEP; |
mluis | 5:62862ef9480b | 832 | } |
mluis | 5:62862ef9480b | 833 | break; |
mluis | 7:5077515c163b | 834 | case 7: // (x) |
mluis | 7:5077515c163b | 835 | { |
mluis | 7:5077515c163b | 836 | if( mcpsIndication->BufferSize == 3 ) |
mluis | 7:5077515c163b | 837 | { |
mluis | 7:5077515c163b | 838 | MlmeReq_t mlmeReq; |
mluis | 7:5077515c163b | 839 | mlmeReq.Type = MLME_TXCW; |
mluis | 7:5077515c163b | 840 | mlmeReq.Req.TxCw.Timeout = ( uint16_t )( ( mcpsIndication->Buffer[1] << 8 ) | mcpsIndication->Buffer[2] ); |
mluis | 7:5077515c163b | 841 | LoRaMacMlmeRequest( &mlmeReq ); |
mluis | 7:5077515c163b | 842 | } |
mluis | 7:5077515c163b | 843 | else if( mcpsIndication->BufferSize == 7 ) |
mluis | 7:5077515c163b | 844 | { |
mluis | 7:5077515c163b | 845 | MlmeReq_t mlmeReq; |
mluis | 7:5077515c163b | 846 | mlmeReq.Type = MLME_TXCW_1; |
mluis | 7:5077515c163b | 847 | mlmeReq.Req.TxCw.Timeout = ( uint16_t )( ( mcpsIndication->Buffer[1] << 8 ) | mcpsIndication->Buffer[2] ); |
mluis | 7:5077515c163b | 848 | mlmeReq.Req.TxCw.Frequency = ( uint32_t )( ( mcpsIndication->Buffer[3] << 16 ) | ( mcpsIndication->Buffer[4] << 8 ) | mcpsIndication->Buffer[5] ) * 100; |
mluis | 7:5077515c163b | 849 | mlmeReq.Req.TxCw.Power = mcpsIndication->Buffer[6]; |
mluis | 7:5077515c163b | 850 | LoRaMacMlmeRequest( &mlmeReq ); |
mluis | 7:5077515c163b | 851 | } |
mluis | 7:5077515c163b | 852 | ComplianceTest.State = 1; |
mluis | 7:5077515c163b | 853 | } |
mluis | 7:5077515c163b | 854 | break; |
mluis | 0:45496a70a8a5 | 855 | default: |
mluis | 0:45496a70a8a5 | 856 | break; |
mluis | 0:45496a70a8a5 | 857 | } |
mluis | 0:45496a70a8a5 | 858 | } |
mluis | 0:45496a70a8a5 | 859 | break; |
mluis | 0:45496a70a8a5 | 860 | default: |
mluis | 0:45496a70a8a5 | 861 | break; |
mluis | 0:45496a70a8a5 | 862 | } |
mluis | 0:45496a70a8a5 | 863 | } |
mluis | 0:45496a70a8a5 | 864 | |
mluis | 0:45496a70a8a5 | 865 | // Switch LED 2 ON for each received downlink |
mluis | 0:45496a70a8a5 | 866 | Led2State = true; |
mluis | 0:45496a70a8a5 | 867 | Led2StateChanged = true; |
mluis | 0:45496a70a8a5 | 868 | TimerStart( &Led2Timer ); |
mluis | 0:45496a70a8a5 | 869 | DownlinkStatusUpdated = true; |
mluis | 0:45496a70a8a5 | 870 | } |
mluis | 0:45496a70a8a5 | 871 | |
mluis | 0:45496a70a8a5 | 872 | /*! |
mluis | 0:45496a70a8a5 | 873 | * \brief MLME-Confirm event function |
mluis | 0:45496a70a8a5 | 874 | * |
mluis | 3:3152aa75c58d | 875 | * \param [IN] mlmeConfirm - Pointer to the confirm structure, |
mluis | 0:45496a70a8a5 | 876 | * containing confirm attributes. |
mluis | 0:45496a70a8a5 | 877 | */ |
mluis | 3:3152aa75c58d | 878 | static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm ) |
mluis | 0:45496a70a8a5 | 879 | { |
mluis | 7:5077515c163b | 880 | switch( mlmeConfirm->MlmeRequest ) |
mluis | 0:45496a70a8a5 | 881 | { |
mluis | 7:5077515c163b | 882 | case MLME_JOIN: |
mluis | 0:45496a70a8a5 | 883 | { |
mluis | 7:5077515c163b | 884 | if( mlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) |
mluis | 0:45496a70a8a5 | 885 | { |
mluis | 0:45496a70a8a5 | 886 | // Status is OK, node has joined the network |
mluis | 0:45496a70a8a5 | 887 | IsNetworkJoinedStatusUpdate = true; |
mluis | 5:62862ef9480b | 888 | DeviceState = DEVICE_STATE_SEND; |
mluis | 7:5077515c163b | 889 | } |
mluis | 7:5077515c163b | 890 | else |
mluis | 7:5077515c163b | 891 | { |
mluis | 7:5077515c163b | 892 | // Join was not successful. Try to join again |
mluis | 7:5077515c163b | 893 | DeviceState = DEVICE_STATE_JOIN; |
mluis | 0:45496a70a8a5 | 894 | } |
mluis | 7:5077515c163b | 895 | break; |
mluis | 7:5077515c163b | 896 | } |
mluis | 7:5077515c163b | 897 | case MLME_LINK_CHECK: |
mluis | 7:5077515c163b | 898 | { |
mluis | 7:5077515c163b | 899 | if( mlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) |
mluis | 0:45496a70a8a5 | 900 | { |
mluis | 0:45496a70a8a5 | 901 | // Check DemodMargin |
mluis | 0:45496a70a8a5 | 902 | // Check NbGateways |
mluis | 0:45496a70a8a5 | 903 | if( ComplianceTest.Running == true ) |
mluis | 0:45496a70a8a5 | 904 | { |
mluis | 0:45496a70a8a5 | 905 | ComplianceTest.LinkCheck = true; |
mluis | 3:3152aa75c58d | 906 | ComplianceTest.DemodMargin = mlmeConfirm->DemodMargin; |
mluis | 3:3152aa75c58d | 907 | ComplianceTest.NbGateways = mlmeConfirm->NbGateways; |
mluis | 0:45496a70a8a5 | 908 | } |
mluis | 0:45496a70a8a5 | 909 | } |
mluis | 7:5077515c163b | 910 | break; |
mluis | 0:45496a70a8a5 | 911 | } |
mluis | 7:5077515c163b | 912 | default: |
mluis | 7:5077515c163b | 913 | break; |
mluis | 0:45496a70a8a5 | 914 | } |
mluis | 0:45496a70a8a5 | 915 | NextTx = true; |
mluis | 0:45496a70a8a5 | 916 | UplinkStatusUpdated = true; |
mluis | 0:45496a70a8a5 | 917 | } |
mluis | 0:45496a70a8a5 | 918 | |
mluis | 0:45496a70a8a5 | 919 | /** |
mluis | 0:45496a70a8a5 | 920 | * Main application entry point. |
mluis | 0:45496a70a8a5 | 921 | */ |
mluis | 0:45496a70a8a5 | 922 | int main( void ) |
mluis | 0:45496a70a8a5 | 923 | { |
mluis | 0:45496a70a8a5 | 924 | LoRaMacPrimitives_t LoRaMacPrimitives; |
mluis | 0:45496a70a8a5 | 925 | LoRaMacCallback_t LoRaMacCallbacks; |
mluis | 0:45496a70a8a5 | 926 | MibRequestConfirm_t mibReq; |
salvatoregulfo | 8:346c55cb6033 | 927 | |
salvatoregulfo | 8:346c55cb6033 | 928 | //enable sensors |
rschiano | 10:88f1c052f9e9 | 929 | //accelerometer -> enable(); |
rschiano | 10:88f1c052f9e9 | 930 | hum_temp -> enable(); |
rschiano | 10:88f1c052f9e9 | 931 | press_temp -> enable(); |
salvatoregulfo | 8:346c55cb6033 | 932 | // acc_gyro->enable_x(); |
salvatoregulfo | 8:346c55cb6033 | 933 | // acc_gyro->enable_g(); |
salvatoregulfo | 9:85c85c65299a | 934 | usensor.startUpdates(); |
mluis | 0:45496a70a8a5 | 935 | BoardInit( ); |
mluis | 0:45496a70a8a5 | 936 | SerialDisplayInit( ); |
mluis | 0:45496a70a8a5 | 937 | |
mluis | 5:62862ef9480b | 938 | SerialDisplayUpdateEui( 5, DevEui ); |
mluis | 5:62862ef9480b | 939 | SerialDisplayUpdateEui( 6, AppEui ); |
mluis | 5:62862ef9480b | 940 | SerialDisplayUpdateKey( 7, AppKey ); |
salvatoregulfo | 8:346c55cb6033 | 941 | |
salvatoregulfo | 8:346c55cb6033 | 942 | |
salvatoregulfo | 8:346c55cb6033 | 943 | |
mluis | 5:62862ef9480b | 944 | |
mluis | 5:62862ef9480b | 945 | #if( OVER_THE_AIR_ACTIVATION == 0 ) |
mluis | 5:62862ef9480b | 946 | SerialDisplayUpdateNwkId( LORAWAN_NETWORK_ID ); |
mluis | 5:62862ef9480b | 947 | SerialDisplayUpdateDevAddr( DevAddr ); |
mluis | 5:62862ef9480b | 948 | SerialDisplayUpdateKey( 12, NwkSKey ); |
mluis | 5:62862ef9480b | 949 | SerialDisplayUpdateKey( 13, AppSKey ); |
mluis | 5:62862ef9480b | 950 | #endif |
mluis | 5:62862ef9480b | 951 | |
mluis | 0:45496a70a8a5 | 952 | DeviceState = DEVICE_STATE_INIT; |
mluis | 0:45496a70a8a5 | 953 | |
mluis | 0:45496a70a8a5 | 954 | while( 1 ) |
mluis | 0:45496a70a8a5 | 955 | { |
mluis | 0:45496a70a8a5 | 956 | SerialRxProcess( ); |
mluis | 0:45496a70a8a5 | 957 | if( IsNetworkJoinedStatusUpdate == true ) |
mluis | 0:45496a70a8a5 | 958 | { |
mluis | 0:45496a70a8a5 | 959 | IsNetworkJoinedStatusUpdate = false; |
mluis | 0:45496a70a8a5 | 960 | mibReq.Type = MIB_NETWORK_JOINED; |
mluis | 0:45496a70a8a5 | 961 | LoRaMacMibGetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 962 | SerialDisplayUpdateNetworkIsJoined( mibReq.Param.IsNetworkJoined ); |
mluis | 0:45496a70a8a5 | 963 | } |
mluis | 0:45496a70a8a5 | 964 | if( Led1StateChanged == true ) |
mluis | 0:45496a70a8a5 | 965 | { |
mluis | 0:45496a70a8a5 | 966 | Led1StateChanged = false; |
mluis | 0:45496a70a8a5 | 967 | SerialDisplayUpdateLedState( 1, Led1State ); |
mluis | 0:45496a70a8a5 | 968 | } |
mluis | 0:45496a70a8a5 | 969 | if( Led2StateChanged == true ) |
mluis | 0:45496a70a8a5 | 970 | { |
mluis | 0:45496a70a8a5 | 971 | Led2StateChanged = false; |
mluis | 0:45496a70a8a5 | 972 | SerialDisplayUpdateLedState( 2, Led2State ); |
mluis | 0:45496a70a8a5 | 973 | } |
mluis | 0:45496a70a8a5 | 974 | if( Led3StateChanged == true ) |
mluis | 0:45496a70a8a5 | 975 | { |
mluis | 0:45496a70a8a5 | 976 | Led3StateChanged = false; |
mluis | 0:45496a70a8a5 | 977 | SerialDisplayUpdateLedState( 3, AppLedStateOn ); |
mluis | 0:45496a70a8a5 | 978 | } |
mluis | 0:45496a70a8a5 | 979 | if( UplinkStatusUpdated == true ) |
mluis | 0:45496a70a8a5 | 980 | { |
mluis | 0:45496a70a8a5 | 981 | UplinkStatusUpdated = false; |
mluis | 0:45496a70a8a5 | 982 | SerialDisplayUpdateUplink( LoRaMacUplinkStatus.Acked, LoRaMacUplinkStatus.Datarate, LoRaMacUplinkStatus.UplinkCounter, LoRaMacUplinkStatus.Port, LoRaMacUplinkStatus.Buffer, LoRaMacUplinkStatus.BufferSize ); |
mluis | 0:45496a70a8a5 | 983 | } |
mluis | 0:45496a70a8a5 | 984 | if( DownlinkStatusUpdated == true ) |
mluis | 0:45496a70a8a5 | 985 | { |
mluis | 0:45496a70a8a5 | 986 | DownlinkStatusUpdated = false; |
mluis | 0:45496a70a8a5 | 987 | SerialDisplayUpdateLedState( 2, Led2State ); |
mluis | 0:45496a70a8a5 | 988 | SerialDisplayUpdateDownlink( LoRaMacDownlinkStatus.RxData, LoRaMacDownlinkStatus.Rssi, LoRaMacDownlinkStatus.Snr, LoRaMacDownlinkStatus.DownlinkCounter, LoRaMacDownlinkStatus.Port, LoRaMacDownlinkStatus.Buffer, LoRaMacDownlinkStatus.BufferSize ); |
mluis | 0:45496a70a8a5 | 989 | } |
mluis | 0:45496a70a8a5 | 990 | |
mluis | 0:45496a70a8a5 | 991 | switch( DeviceState ) |
mluis | 0:45496a70a8a5 | 992 | { |
mluis | 0:45496a70a8a5 | 993 | case DEVICE_STATE_INIT: |
mluis | 0:45496a70a8a5 | 994 | { |
mluis | 0:45496a70a8a5 | 995 | LoRaMacPrimitives.MacMcpsConfirm = McpsConfirm; |
mluis | 0:45496a70a8a5 | 996 | LoRaMacPrimitives.MacMcpsIndication = McpsIndication; |
mluis | 0:45496a70a8a5 | 997 | LoRaMacPrimitives.MacMlmeConfirm = MlmeConfirm; |
mluis | 0:45496a70a8a5 | 998 | LoRaMacCallbacks.GetBatteryLevel = BoardGetBatteryLevel; |
mluis | 0:45496a70a8a5 | 999 | LoRaMacInitialization( &LoRaMacPrimitives, &LoRaMacCallbacks ); |
mluis | 0:45496a70a8a5 | 1000 | |
mluis | 0:45496a70a8a5 | 1001 | TimerInit( &TxNextPacketTimer, OnTxNextPacketTimerEvent ); |
mluis | 0:45496a70a8a5 | 1002 | |
mluis | 0:45496a70a8a5 | 1003 | TimerInit( &Led1Timer, OnLed1TimerEvent ); |
mluis | 7:5077515c163b | 1004 | TimerSetValue( &Led1Timer, 25 ); |
mluis | 0:45496a70a8a5 | 1005 | |
mluis | 0:45496a70a8a5 | 1006 | TimerInit( &Led2Timer, OnLed2TimerEvent ); |
mluis | 7:5077515c163b | 1007 | TimerSetValue( &Led2Timer, 25 ); |
mluis | 0:45496a70a8a5 | 1008 | |
mluis | 0:45496a70a8a5 | 1009 | mibReq.Type = MIB_ADR; |
mluis | 0:45496a70a8a5 | 1010 | mibReq.Param.AdrEnable = LORAWAN_ADR_ON; |
mluis | 0:45496a70a8a5 | 1011 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 1012 | |
mluis | 0:45496a70a8a5 | 1013 | mibReq.Type = MIB_PUBLIC_NETWORK; |
mluis | 0:45496a70a8a5 | 1014 | mibReq.Param.EnablePublicNetwork = LORAWAN_PUBLIC_NETWORK; |
mluis | 0:45496a70a8a5 | 1015 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 1016 | |
mluis | 0:45496a70a8a5 | 1017 | #if defined( USE_BAND_868 ) |
mluis | 0:45496a70a8a5 | 1018 | LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON ); |
mluis | 0:45496a70a8a5 | 1019 | SerialDisplayUpdateDutyCycle( LORAWAN_DUTYCYCLE_ON ); |
mluis | 3:3152aa75c58d | 1020 | |
mluis | 7:5077515c163b | 1021 | #if( USE_SEMTECH_DEFAULT_CHANNEL_LINEUP == 1 ) |
mluis | 3:3152aa75c58d | 1022 | LoRaMacChannelAdd( 3, ( ChannelParams_t )LC4 ); |
mluis | 3:3152aa75c58d | 1023 | LoRaMacChannelAdd( 4, ( ChannelParams_t )LC5 ); |
mluis | 3:3152aa75c58d | 1024 | LoRaMacChannelAdd( 5, ( ChannelParams_t )LC6 ); |
mluis | 3:3152aa75c58d | 1025 | LoRaMacChannelAdd( 6, ( ChannelParams_t )LC7 ); |
mluis | 3:3152aa75c58d | 1026 | LoRaMacChannelAdd( 7, ( ChannelParams_t )LC8 ); |
mluis | 3:3152aa75c58d | 1027 | LoRaMacChannelAdd( 8, ( ChannelParams_t )LC9 ); |
mluis | 3:3152aa75c58d | 1028 | LoRaMacChannelAdd( 9, ( ChannelParams_t )LC10 ); |
mluis | 5:62862ef9480b | 1029 | |
mluis | 7:5077515c163b | 1030 | mibReq.Type = MIB_RX2_DEFAULT_CHANNEL; |
mluis | 7:5077515c163b | 1031 | mibReq.Param.Rx2DefaultChannel = ( Rx2ChannelParams_t ){ 869525000, DR_3 }; |
mluis | 7:5077515c163b | 1032 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 7:5077515c163b | 1033 | |
mluis | 5:62862ef9480b | 1034 | mibReq.Type = MIB_RX2_CHANNEL; |
mluis | 5:62862ef9480b | 1035 | mibReq.Param.Rx2Channel = ( Rx2ChannelParams_t ){ 869525000, DR_3 }; |
mluis | 5:62862ef9480b | 1036 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 3:3152aa75c58d | 1037 | #endif |
mluis | 3:3152aa75c58d | 1038 | |
mluis | 0:45496a70a8a5 | 1039 | #endif |
mluis | 0:45496a70a8a5 | 1040 | SerialDisplayUpdateActivationMode( OVER_THE_AIR_ACTIVATION ); |
mluis | 0:45496a70a8a5 | 1041 | SerialDisplayUpdateAdr( LORAWAN_ADR_ON ); |
mluis | 0:45496a70a8a5 | 1042 | SerialDisplayUpdatePublicNetwork( LORAWAN_PUBLIC_NETWORK ); |
mluis | 0:45496a70a8a5 | 1043 | |
mluis | 0:45496a70a8a5 | 1044 | LoRaMacDownlinkStatus.DownlinkCounter = 0; |
mluis | 0:45496a70a8a5 | 1045 | |
mluis | 0:45496a70a8a5 | 1046 | DeviceState = DEVICE_STATE_JOIN; |
mluis | 0:45496a70a8a5 | 1047 | break; |
mluis | 0:45496a70a8a5 | 1048 | } |
mluis | 0:45496a70a8a5 | 1049 | case DEVICE_STATE_JOIN: |
mluis | 0:45496a70a8a5 | 1050 | { |
mluis | 0:45496a70a8a5 | 1051 | #if( OVER_THE_AIR_ACTIVATION != 0 ) |
mluis | 0:45496a70a8a5 | 1052 | MlmeReq_t mlmeReq; |
mluis | 0:45496a70a8a5 | 1053 | |
mluis | 0:45496a70a8a5 | 1054 | mlmeReq.Type = MLME_JOIN; |
mluis | 0:45496a70a8a5 | 1055 | |
mluis | 0:45496a70a8a5 | 1056 | mlmeReq.Req.Join.DevEui = DevEui; |
mluis | 0:45496a70a8a5 | 1057 | mlmeReq.Req.Join.AppEui = AppEui; |
mluis | 0:45496a70a8a5 | 1058 | mlmeReq.Req.Join.AppKey = AppKey; |
mluis | 0:45496a70a8a5 | 1059 | |
mluis | 0:45496a70a8a5 | 1060 | if( NextTx == true ) |
mluis | 0:45496a70a8a5 | 1061 | { |
mluis | 0:45496a70a8a5 | 1062 | LoRaMacMlmeRequest( &mlmeReq ); |
mluis | 0:45496a70a8a5 | 1063 | } |
mluis | 5:62862ef9480b | 1064 | DeviceState = DEVICE_STATE_SLEEP; |
mluis | 0:45496a70a8a5 | 1065 | #else |
mluis | 0:45496a70a8a5 | 1066 | mibReq.Type = MIB_NET_ID; |
mluis | 0:45496a70a8a5 | 1067 | mibReq.Param.NetID = LORAWAN_NETWORK_ID; |
mluis | 0:45496a70a8a5 | 1068 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 1069 | |
mluis | 0:45496a70a8a5 | 1070 | mibReq.Type = MIB_DEV_ADDR; |
mluis | 0:45496a70a8a5 | 1071 | mibReq.Param.DevAddr = DevAddr; |
mluis | 0:45496a70a8a5 | 1072 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 1073 | |
mluis | 0:45496a70a8a5 | 1074 | mibReq.Type = MIB_NWK_SKEY; |
mluis | 0:45496a70a8a5 | 1075 | mibReq.Param.NwkSKey = NwkSKey; |
mluis | 0:45496a70a8a5 | 1076 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 1077 | |
mluis | 0:45496a70a8a5 | 1078 | mibReq.Type = MIB_APP_SKEY; |
mluis | 0:45496a70a8a5 | 1079 | mibReq.Param.AppSKey = AppSKey; |
mluis | 0:45496a70a8a5 | 1080 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 1081 | |
mluis | 0:45496a70a8a5 | 1082 | mibReq.Type = MIB_NETWORK_JOINED; |
mluis | 0:45496a70a8a5 | 1083 | mibReq.Param.IsNetworkJoined = true; |
mluis | 0:45496a70a8a5 | 1084 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 1085 | |
mluis | 0:45496a70a8a5 | 1086 | DeviceState = DEVICE_STATE_SEND; |
mluis | 0:45496a70a8a5 | 1087 | #endif |
mluis | 0:45496a70a8a5 | 1088 | IsNetworkJoinedStatusUpdate = true; |
mluis | 0:45496a70a8a5 | 1089 | break; |
mluis | 0:45496a70a8a5 | 1090 | } |
salvatoregulfo | 9:85c85c65299a | 1091 | case DEVICE_STATE_SEND: //send frame |
mluis | 0:45496a70a8a5 | 1092 | { |
mluis | 0:45496a70a8a5 | 1093 | if( NextTx == true ) |
mluis | 0:45496a70a8a5 | 1094 | { |
mluis | 0:45496a70a8a5 | 1095 | SerialDisplayUpdateUplinkAcked( false ); |
mluis | 0:45496a70a8a5 | 1096 | SerialDisplayUpdateDonwlinkRxData( false ); |
mluis | 0:45496a70a8a5 | 1097 | PrepareTxFrame( AppPort ); |
mluis | 0:45496a70a8a5 | 1098 | |
mluis | 0:45496a70a8a5 | 1099 | NextTx = SendFrame( ); |
mluis | 0:45496a70a8a5 | 1100 | } |
mluis | 0:45496a70a8a5 | 1101 | if( ComplianceTest.Running == true ) |
mluis | 0:45496a70a8a5 | 1102 | { |
mluis | 3:3152aa75c58d | 1103 | // Schedule next packet transmission |
mluis | 7:5077515c163b | 1104 | TxDutyCycleTime = 5000; // 5000 ms |
mluis | 0:45496a70a8a5 | 1105 | } |
mluis | 0:45496a70a8a5 | 1106 | else |
mluis | 0:45496a70a8a5 | 1107 | { |
mluis | 0:45496a70a8a5 | 1108 | // Schedule next packet transmission |
mluis | 0:45496a70a8a5 | 1109 | TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND ); |
mluis | 0:45496a70a8a5 | 1110 | } |
mluis | 0:45496a70a8a5 | 1111 | DeviceState = DEVICE_STATE_CYCLE; |
mluis | 0:45496a70a8a5 | 1112 | break; |
mluis | 0:45496a70a8a5 | 1113 | } |
mluis | 0:45496a70a8a5 | 1114 | case DEVICE_STATE_CYCLE: |
mluis | 0:45496a70a8a5 | 1115 | { |
mluis | 3:3152aa75c58d | 1116 | DeviceState = DEVICE_STATE_SLEEP; |
mluis | 3:3152aa75c58d | 1117 | |
mluis | 0:45496a70a8a5 | 1118 | // Schedule next packet transmission |
mluis | 0:45496a70a8a5 | 1119 | TimerSetValue( &TxNextPacketTimer, TxDutyCycleTime ); |
mluis | 0:45496a70a8a5 | 1120 | TimerStart( &TxNextPacketTimer ); |
mluis | 0:45496a70a8a5 | 1121 | break; |
mluis | 0:45496a70a8a5 | 1122 | } |
mluis | 0:45496a70a8a5 | 1123 | case DEVICE_STATE_SLEEP: |
mluis | 0:45496a70a8a5 | 1124 | { |
mluis | 0:45496a70a8a5 | 1125 | // Wake up through events |
mluis | 0:45496a70a8a5 | 1126 | break; |
mluis | 0:45496a70a8a5 | 1127 | } |
mluis | 0:45496a70a8a5 | 1128 | default: |
mluis | 0:45496a70a8a5 | 1129 | { |
mluis | 0:45496a70a8a5 | 1130 | DeviceState = DEVICE_STATE_INIT; |
mluis | 0:45496a70a8a5 | 1131 | break; |
mluis | 0:45496a70a8a5 | 1132 | } |
mluis | 0:45496a70a8a5 | 1133 | } |
mluis | 0:45496a70a8a5 | 1134 | } |
mluis | 0:45496a70a8a5 | 1135 | } |