LR Initial Publish
Dependencies: X_NUCLEO_IKS01A2 driver_mbed_TH02 mbed LoRaWAN-lib-v1_0_1 SX1272Lib
Fork of Training-Aug2018-SX1272-X-NUCLEO-IKS01A2 by
app/LoRaEventProc.cpp@0:6cc76d70e2a1, 2017-04-06 (annotated)
- Committer:
- ubhat
- Date:
- Thu Apr 06 21:59:50 2017 +0000
- Revision:
- 0:6cc76d70e2a1
- Child:
- 2:19dd7bfcacf7
LoRaWAN SX1272 Application
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ubhat | 0:6cc76d70e2a1 | 1 | /* |
ubhat | 0:6cc76d70e2a1 | 2 | / _____) _ | | |
ubhat | 0:6cc76d70e2a1 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
ubhat | 0:6cc76d70e2a1 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
ubhat | 0:6cc76d70e2a1 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
ubhat | 0:6cc76d70e2a1 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
ubhat | 0:6cc76d70e2a1 | 7 | (C)2015 Semtech |
ubhat | 0:6cc76d70e2a1 | 8 | |
ubhat | 0:6cc76d70e2a1 | 9 | Description: Define events during Join, Tx & Rx |
ubhat | 0:6cc76d70e2a1 | 10 | Prepare TX packet by appending with appropriate application data |
ubhat | 0:6cc76d70e2a1 | 11 | |
ubhat | 0:6cc76d70e2a1 | 12 | License: Revised BSD License, see LICENSE.TXT file include in the project |
ubhat | 0:6cc76d70e2a1 | 13 | |
ubhat | 0:6cc76d70e2a1 | 14 | Maintainer: Uttam Bhat |
ubhat | 0:6cc76d70e2a1 | 15 | */ |
ubhat | 0:6cc76d70e2a1 | 16 | |
ubhat | 0:6cc76d70e2a1 | 17 | #include "LoRaEventProc.h" |
ubhat | 0:6cc76d70e2a1 | 18 | |
ubhat | 0:6cc76d70e2a1 | 19 | /*! |
ubhat | 0:6cc76d70e2a1 | 20 | * Defines the application data transmission duty cycle |
ubhat | 0:6cc76d70e2a1 | 21 | */ |
ubhat | 0:6cc76d70e2a1 | 22 | uint32_t TxDutyCycleTime = APP_TX_DUTYCYCLE; |
ubhat | 0:6cc76d70e2a1 | 23 | |
ubhat | 0:6cc76d70e2a1 | 24 | bool AppLed = 0; |
ubhat | 0:6cc76d70e2a1 | 25 | |
ubhat | 0:6cc76d70e2a1 | 26 | uint8_t AppCase = 0; |
ubhat | 0:6cc76d70e2a1 | 27 | |
ubhat | 0:6cc76d70e2a1 | 28 | /*! |
ubhat | 0:6cc76d70e2a1 | 29 | * \brief Prepares the payload of the frame based on application port |
ubhat | 0:6cc76d70e2a1 | 30 | */ |
ubhat | 0:6cc76d70e2a1 | 31 | void PrepareLoRaFrame( uint8_t port ) |
ubhat | 0:6cc76d70e2a1 | 32 | { |
ubhat | 0:6cc76d70e2a1 | 33 | |
ubhat | 0:6cc76d70e2a1 | 34 | switch( port ) |
ubhat | 0:6cc76d70e2a1 | 35 | { |
ubhat | 0:6cc76d70e2a1 | 36 | case 5: |
ubhat | 0:6cc76d70e2a1 | 37 | { |
ubhat | 0:6cc76d70e2a1 | 38 | uint8_t tmp; |
ubhat | 0:6cc76d70e2a1 | 39 | uint8_t tmpLength; |
ubhat | 0:6cc76d70e2a1 | 40 | uint8_t ptrIndex = 0; |
ubhat | 0:6cc76d70e2a1 | 41 | |
ubhat | 0:6cc76d70e2a1 | 42 | // Point the pointer to position index of Tx Buffer |
ubhat | 0:6cc76d70e2a1 | 43 | LoRaApp.ApplicationPtrPos( ptrIndex ); |
ubhat | 0:6cc76d70e2a1 | 44 | |
ubhat | 0:6cc76d70e2a1 | 45 | tmp = ( AppLed != 0 ) ? 0x0F : 0x00; |
ubhat | 0:6cc76d70e2a1 | 46 | tmpLength = 1; |
ubhat | 0:6cc76d70e2a1 | 47 | |
ubhat | 0:6cc76d70e2a1 | 48 | LoRaApp.ApplicationAppendData( &tmp, tmpLength ); // Populate lower nibble of 0th Byte with LED state |
ubhat | 0:6cc76d70e2a1 | 49 | |
ubhat | 0:6cc76d70e2a1 | 50 | /*! |
ubhat | 0:6cc76d70e2a1 | 51 | * Generate Ramp data bytes |
ubhat | 0:6cc76d70e2a1 | 52 | * Appends incremental values of 1 Byte each to TX buffer until Full |
ubhat | 0:6cc76d70e2a1 | 53 | */ |
ubhat | 0:6cc76d70e2a1 | 54 | LoRaApp.ApplicationCall( AppRamp ); |
ubhat | 0:6cc76d70e2a1 | 55 | |
ubhat | 0:6cc76d70e2a1 | 56 | break; |
ubhat | 0:6cc76d70e2a1 | 57 | } |
ubhat | 0:6cc76d70e2a1 | 58 | |
ubhat | 0:6cc76d70e2a1 | 59 | case 8: |
ubhat | 0:6cc76d70e2a1 | 60 | { |
ubhat | 0:6cc76d70e2a1 | 61 | uint8_t ptrIndex = 0; |
ubhat | 0:6cc76d70e2a1 | 62 | |
ubhat | 0:6cc76d70e2a1 | 63 | //Point the pointer to position index of Tx Buffer |
ubhat | 0:6cc76d70e2a1 | 64 | LoRaApp.ApplicationPtrPos( ptrIndex ); |
ubhat | 0:6cc76d70e2a1 | 65 | |
ubhat | 0:6cc76d70e2a1 | 66 | /*! |
ubhat | 0:6cc76d70e2a1 | 67 | * Read Pressure |
ubhat | 0:6cc76d70e2a1 | 68 | * Appends 2 Bytes to TX buffer |
ubhat | 0:6cc76d70e2a1 | 69 | */ |
ubhat | 0:6cc76d70e2a1 | 70 | LoRaApp.ApplicationCall( AppPressr ); |
ubhat | 0:6cc76d70e2a1 | 71 | |
ubhat | 0:6cc76d70e2a1 | 72 | /*! |
ubhat | 0:6cc76d70e2a1 | 73 | * Read Temperature |
ubhat | 0:6cc76d70e2a1 | 74 | * Appends 1 Byte to TX buffer |
ubhat | 0:6cc76d70e2a1 | 75 | */ |
ubhat | 0:6cc76d70e2a1 | 76 | LoRaApp.ApplicationCall( AppTemp ); |
ubhat | 0:6cc76d70e2a1 | 77 | |
ubhat | 0:6cc76d70e2a1 | 78 | /*! |
ubhat | 0:6cc76d70e2a1 | 79 | * Read Humidity |
ubhat | 0:6cc76d70e2a1 | 80 | * Appends 1 Byte to TX buffer |
ubhat | 0:6cc76d70e2a1 | 81 | */ |
ubhat | 0:6cc76d70e2a1 | 82 | LoRaApp.ApplicationCall( AppHumid ); |
ubhat | 0:6cc76d70e2a1 | 83 | |
ubhat | 0:6cc76d70e2a1 | 84 | /*! |
ubhat | 0:6cc76d70e2a1 | 85 | * Read Accelerometer |
ubhat | 0:6cc76d70e2a1 | 86 | * Appends 2 Bytes to TX buffer |
ubhat | 0:6cc76d70e2a1 | 87 | * Value Orientation |
ubhat | 0:6cc76d70e2a1 | 88 | * 0x99 0x00 horizontal + faceup |
ubhat | 0:6cc76d70e2a1 | 89 | * 0x66 0x00 horizontal + facedown |
ubhat | 0:6cc76d70e2a1 | 90 | * 0x00 0x11 vertical |
ubhat | 0:6cc76d70e2a1 | 91 | */ |
ubhat | 0:6cc76d70e2a1 | 92 | LoRaApp.ApplicationCall( AppAccl ); // Generate Accelerometer data bytes |
ubhat | 0:6cc76d70e2a1 | 93 | |
ubhat | 0:6cc76d70e2a1 | 94 | |
ubhat | 0:6cc76d70e2a1 | 95 | break; |
ubhat | 0:6cc76d70e2a1 | 96 | } |
ubhat | 0:6cc76d70e2a1 | 97 | |
ubhat | 0:6cc76d70e2a1 | 98 | // IKAS sensor using Cayenne Payload Format |
ubhat | 0:6cc76d70e2a1 | 99 | case 9: |
ubhat | 0:6cc76d70e2a1 | 100 | { |
ubhat | 0:6cc76d70e2a1 | 101 | #ifdef USE_CAYENNE_LPP |
ubhat | 0:6cc76d70e2a1 | 102 | uint8_t ptrIndex = 0; |
ubhat | 0:6cc76d70e2a1 | 103 | |
ubhat | 0:6cc76d70e2a1 | 104 | uint16_t AppSize = 0; |
ubhat | 0:6cc76d70e2a1 | 105 | |
ubhat | 0:6cc76d70e2a1 | 106 | uint8_t tmp[2] = {0}; |
ubhat | 0:6cc76d70e2a1 | 107 | |
ubhat | 0:6cc76d70e2a1 | 108 | //Point the pointer to position index of Tx Buffer |
ubhat | 0:6cc76d70e2a1 | 109 | LoRaApp.ApplicationPtrPos( ptrIndex ); |
ubhat | 0:6cc76d70e2a1 | 110 | |
ubhat | 0:6cc76d70e2a1 | 111 | AppCase = AppCase > 3 ? 0 : AppCase; |
ubhat | 0:6cc76d70e2a1 | 112 | |
ubhat | 0:6cc76d70e2a1 | 113 | while( 1 ) |
ubhat | 0:6cc76d70e2a1 | 114 | { |
ubhat | 0:6cc76d70e2a1 | 115 | switch( AppCase ) |
ubhat | 0:6cc76d70e2a1 | 116 | { |
ubhat | 0:6cc76d70e2a1 | 117 | case 0: |
ubhat | 0:6cc76d70e2a1 | 118 | { |
ubhat | 0:6cc76d70e2a1 | 119 | tmp[0] = 0; |
ubhat | 0:6cc76d70e2a1 | 120 | tmp[1] = 115; // Data Type PRESSURE: 115 |
ubhat | 0:6cc76d70e2a1 | 121 | LoRaApp.ApplicationAppendData( tmp, 2 ); |
ubhat | 0:6cc76d70e2a1 | 122 | |
ubhat | 0:6cc76d70e2a1 | 123 | /*! |
ubhat | 0:6cc76d70e2a1 | 124 | * Read Pressure |
ubhat | 0:6cc76d70e2a1 | 125 | * Appends 2 Bytes to TX buffer |
ubhat | 0:6cc76d70e2a1 | 126 | */ |
ubhat | 0:6cc76d70e2a1 | 127 | LoRaApp.ApplicationCall( AppPressr ); |
ubhat | 0:6cc76d70e2a1 | 128 | |
ubhat | 0:6cc76d70e2a1 | 129 | AppSize += maxLPPsize[AppCase]; |
ubhat | 0:6cc76d70e2a1 | 130 | |
ubhat | 0:6cc76d70e2a1 | 131 | break; |
ubhat | 0:6cc76d70e2a1 | 132 | } |
ubhat | 0:6cc76d70e2a1 | 133 | |
ubhat | 0:6cc76d70e2a1 | 134 | case 1: |
ubhat | 0:6cc76d70e2a1 | 135 | { |
ubhat | 0:6cc76d70e2a1 | 136 | tmp[0] = 1; |
ubhat | 0:6cc76d70e2a1 | 137 | tmp[1] = 103; // Data Type TEMP: 103 |
ubhat | 0:6cc76d70e2a1 | 138 | LoRaApp.ApplicationAppendData( tmp, 2 ); |
ubhat | 0:6cc76d70e2a1 | 139 | |
ubhat | 0:6cc76d70e2a1 | 140 | /*! |
ubhat | 0:6cc76d70e2a1 | 141 | * Read Temperature |
ubhat | 0:6cc76d70e2a1 | 142 | * Appends 1 Byte to TX buffer |
ubhat | 0:6cc76d70e2a1 | 143 | */ |
ubhat | 0:6cc76d70e2a1 | 144 | LoRaApp.ApplicationCall( AppTemp ); |
ubhat | 0:6cc76d70e2a1 | 145 | |
ubhat | 0:6cc76d70e2a1 | 146 | AppSize += maxLPPsize[AppCase]; |
ubhat | 0:6cc76d70e2a1 | 147 | |
ubhat | 0:6cc76d70e2a1 | 148 | break; |
ubhat | 0:6cc76d70e2a1 | 149 | } |
ubhat | 0:6cc76d70e2a1 | 150 | |
ubhat | 0:6cc76d70e2a1 | 151 | case 2: |
ubhat | 0:6cc76d70e2a1 | 152 | { |
ubhat | 0:6cc76d70e2a1 | 153 | tmp[0] = 2; |
ubhat | 0:6cc76d70e2a1 | 154 | tmp[1] = 104; // Data Type HUMIDITY: 103 |
ubhat | 0:6cc76d70e2a1 | 155 | LoRaApp.ApplicationAppendData( tmp, 2 ); |
ubhat | 0:6cc76d70e2a1 | 156 | |
ubhat | 0:6cc76d70e2a1 | 157 | /*! |
ubhat | 0:6cc76d70e2a1 | 158 | * Read Humidity |
ubhat | 0:6cc76d70e2a1 | 159 | * Appends 1 Byte to TX buffer |
ubhat | 0:6cc76d70e2a1 | 160 | */ |
ubhat | 0:6cc76d70e2a1 | 161 | LoRaApp.ApplicationCall( AppHumid ); |
ubhat | 0:6cc76d70e2a1 | 162 | |
ubhat | 0:6cc76d70e2a1 | 163 | AppSize += maxLPPsize[AppCase]; |
ubhat | 0:6cc76d70e2a1 | 164 | |
ubhat | 0:6cc76d70e2a1 | 165 | break; |
ubhat | 0:6cc76d70e2a1 | 166 | } |
ubhat | 0:6cc76d70e2a1 | 167 | |
ubhat | 0:6cc76d70e2a1 | 168 | case 3: |
ubhat | 0:6cc76d70e2a1 | 169 | { |
ubhat | 0:6cc76d70e2a1 | 170 | tmp[0] = 3; |
ubhat | 0:6cc76d70e2a1 | 171 | tmp[1] = 113; // Data Type Accl: 113 |
ubhat | 0:6cc76d70e2a1 | 172 | LoRaApp.ApplicationAppendData( tmp, 2 ); |
ubhat | 0:6cc76d70e2a1 | 173 | /*! |
ubhat | 0:6cc76d70e2a1 | 174 | * Read Accelerometer |
ubhat | 0:6cc76d70e2a1 | 175 | */ |
ubhat | 0:6cc76d70e2a1 | 176 | LoRaApp.ApplicationCall( AppAccl ); // Generate Accelerometer data bytes |
ubhat | 0:6cc76d70e2a1 | 177 | |
ubhat | 0:6cc76d70e2a1 | 178 | AppSize += maxLPPsize[AppCase]; |
ubhat | 0:6cc76d70e2a1 | 179 | |
ubhat | 0:6cc76d70e2a1 | 180 | break; |
ubhat | 0:6cc76d70e2a1 | 181 | } |
ubhat | 0:6cc76d70e2a1 | 182 | } |
ubhat | 0:6cc76d70e2a1 | 183 | |
ubhat | 0:6cc76d70e2a1 | 184 | AppCase++; |
ubhat | 0:6cc76d70e2a1 | 185 | |
ubhat | 0:6cc76d70e2a1 | 186 | if( AppSize + maxLPPsize[AppCase] > LORAWAN_APP_DATA_SIZE ) |
ubhat | 0:6cc76d70e2a1 | 187 | { |
ubhat | 0:6cc76d70e2a1 | 188 | break; |
ubhat | 0:6cc76d70e2a1 | 189 | } |
ubhat | 0:6cc76d70e2a1 | 190 | } |
ubhat | 0:6cc76d70e2a1 | 191 | |
ubhat | 0:6cc76d70e2a1 | 192 | AppDataSize = AppSize; |
ubhat | 0:6cc76d70e2a1 | 193 | #endif |
ubhat | 0:6cc76d70e2a1 | 194 | break; |
ubhat | 0:6cc76d70e2a1 | 195 | } |
ubhat | 0:6cc76d70e2a1 | 196 | |
ubhat | 0:6cc76d70e2a1 | 197 | // Push-Button Demo |
ubhat | 0:6cc76d70e2a1 | 198 | case 11: |
ubhat | 0:6cc76d70e2a1 | 199 | { |
ubhat | 0:6cc76d70e2a1 | 200 | uint8_t ptrIndex = 0; |
ubhat | 0:6cc76d70e2a1 | 201 | |
ubhat | 0:6cc76d70e2a1 | 202 | //Point the pointer to position index of Tx Buffer |
ubhat | 0:6cc76d70e2a1 | 203 | LoRaApp.ApplicationPtrPos( ptrIndex ); |
ubhat | 0:6cc76d70e2a1 | 204 | |
ubhat | 0:6cc76d70e2a1 | 205 | LoRaApp.ApplicationCall( AppPushButton ); // Transmit uplink counter |
ubhat | 0:6cc76d70e2a1 | 206 | |
ubhat | 0:6cc76d70e2a1 | 207 | break; |
ubhat | 0:6cc76d70e2a1 | 208 | } |
ubhat | 0:6cc76d70e2a1 | 209 | |
ubhat | 0:6cc76d70e2a1 | 210 | default: |
ubhat | 0:6cc76d70e2a1 | 211 | break; |
ubhat | 0:6cc76d70e2a1 | 212 | } |
ubhat | 0:6cc76d70e2a1 | 213 | } |
ubhat | 0:6cc76d70e2a1 | 214 | |
ubhat | 0:6cc76d70e2a1 | 215 | |
ubhat | 0:6cc76d70e2a1 | 216 | /*! |
ubhat | 0:6cc76d70e2a1 | 217 | * \brief Sets Interrupt for next payload transmission |
ubhat | 0:6cc76d70e2a1 | 218 | */ |
ubhat | 0:6cc76d70e2a1 | 219 | void InitNextTxInterrupt( uint8_t port ) |
ubhat | 0:6cc76d70e2a1 | 220 | { |
ubhat | 0:6cc76d70e2a1 | 221 | switch( port ) |
ubhat | 0:6cc76d70e2a1 | 222 | { |
ubhat | 0:6cc76d70e2a1 | 223 | /* GPS Application Demo |
ubhat | 0:6cc76d70e2a1 | 224 | Set Timer interrupt for next uplink |
ubhat | 0:6cc76d70e2a1 | 225 | */ |
ubhat | 0:6cc76d70e2a1 | 226 | case 5: |
ubhat | 0:6cc76d70e2a1 | 227 | { |
ubhat | 0:6cc76d70e2a1 | 228 | } |
ubhat | 0:6cc76d70e2a1 | 229 | |
ubhat | 0:6cc76d70e2a1 | 230 | /* Senet + M2X demo |
ubhat | 0:6cc76d70e2a1 | 231 | Set Timer interrupt for next uplink |
ubhat | 0:6cc76d70e2a1 | 232 | */ |
ubhat | 0:6cc76d70e2a1 | 233 | case 6: |
ubhat | 0:6cc76d70e2a1 | 234 | { |
ubhat | 0:6cc76d70e2a1 | 235 | |
ubhat | 0:6cc76d70e2a1 | 236 | } |
ubhat | 0:6cc76d70e2a1 | 237 | |
ubhat | 0:6cc76d70e2a1 | 238 | /* Senet GPS Demo |
ubhat | 0:6cc76d70e2a1 | 239 | Set Timer interrupt for next uplink |
ubhat | 0:6cc76d70e2a1 | 240 | */ |
ubhat | 0:6cc76d70e2a1 | 241 | case 7: |
ubhat | 0:6cc76d70e2a1 | 242 | { |
ubhat | 0:6cc76d70e2a1 | 243 | // Schedule next packet transmission |
ubhat | 0:6cc76d70e2a1 | 244 | TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND ); |
ubhat | 0:6cc76d70e2a1 | 245 | TimerSetValue( &TxNextPacketTimer, TxDutyCycleTime ); |
ubhat | 0:6cc76d70e2a1 | 246 | TimerStart( &TxNextPacketTimer ); |
ubhat | 0:6cc76d70e2a1 | 247 | break; |
ubhat | 0:6cc76d70e2a1 | 248 | } |
ubhat | 0:6cc76d70e2a1 | 249 | |
ubhat | 0:6cc76d70e2a1 | 250 | /* Push Button Demo |
ubhat | 0:6cc76d70e2a1 | 251 | Send Packet Immedietly if PC0 = GND |
ubhat | 0:6cc76d70e2a1 | 252 | */ |
ubhat | 0:6cc76d70e2a1 | 253 | case 11: |
ubhat | 0:6cc76d70e2a1 | 254 | { |
ubhat | 0:6cc76d70e2a1 | 255 | volatile bool PushButtonStatus; |
ubhat | 0:6cc76d70e2a1 | 256 | |
ubhat | 0:6cc76d70e2a1 | 257 | PushButtonStatus = UsrButton; |
ubhat | 0:6cc76d70e2a1 | 258 | |
ubhat | 0:6cc76d70e2a1 | 259 | if(PushButtonStatus == 0) |
ubhat | 0:6cc76d70e2a1 | 260 | { |
ubhat | 0:6cc76d70e2a1 | 261 | // Send Pkt immedietly if PC = GND |
ubhat | 0:6cc76d70e2a1 | 262 | DeviceState = DEVICE_STATE_SEND; |
ubhat | 0:6cc76d70e2a1 | 263 | NextTx = true; |
ubhat | 0:6cc76d70e2a1 | 264 | } |
ubhat | 0:6cc76d70e2a1 | 265 | else |
ubhat | 0:6cc76d70e2a1 | 266 | { |
ubhat | 0:6cc76d70e2a1 | 267 | // Keep polling |
ubhat | 0:6cc76d70e2a1 | 268 | IsTxIntUpdate = true; |
ubhat | 0:6cc76d70e2a1 | 269 | } |
ubhat | 0:6cc76d70e2a1 | 270 | |
ubhat | 0:6cc76d70e2a1 | 271 | break; |
ubhat | 0:6cc76d70e2a1 | 272 | } |
ubhat | 0:6cc76d70e2a1 | 273 | |
ubhat | 0:6cc76d70e2a1 | 274 | /* Orientation Demo |
ubhat | 0:6cc76d70e2a1 | 275 | Send Packet Immedietly if Mote is Vertical |
ubhat | 0:6cc76d70e2a1 | 276 | */ |
ubhat | 0:6cc76d70e2a1 | 277 | case 12: |
ubhat | 0:6cc76d70e2a1 | 278 | { |
ubhat | 0:6cc76d70e2a1 | 279 | CheckOrientation( ); |
ubhat | 0:6cc76d70e2a1 | 280 | |
ubhat | 0:6cc76d70e2a1 | 281 | if(VerticalStatus == true) |
ubhat | 0:6cc76d70e2a1 | 282 | { |
ubhat | 0:6cc76d70e2a1 | 283 | // Send Pkt immedietly if PC = GND |
ubhat | 0:6cc76d70e2a1 | 284 | DeviceState = DEVICE_STATE_SEND; |
ubhat | 0:6cc76d70e2a1 | 285 | NextTx = true; |
ubhat | 0:6cc76d70e2a1 | 286 | } |
ubhat | 0:6cc76d70e2a1 | 287 | else |
ubhat | 0:6cc76d70e2a1 | 288 | { |
ubhat | 0:6cc76d70e2a1 | 289 | // Keep polling |
ubhat | 0:6cc76d70e2a1 | 290 | IsTxIntUpdate = true; |
ubhat | 0:6cc76d70e2a1 | 291 | } |
ubhat | 0:6cc76d70e2a1 | 292 | break; |
ubhat | 0:6cc76d70e2a1 | 293 | } |
ubhat | 0:6cc76d70e2a1 | 294 | |
ubhat | 0:6cc76d70e2a1 | 295 | /* Compliance Test |
ubhat | 0:6cc76d70e2a1 | 296 | Set Timer interrupt for next uplink |
ubhat | 0:6cc76d70e2a1 | 297 | */ |
ubhat | 0:6cc76d70e2a1 | 298 | case 224: |
ubhat | 0:6cc76d70e2a1 | 299 | { |
ubhat | 0:6cc76d70e2a1 | 300 | // Schedule next packet transmission |
ubhat | 0:6cc76d70e2a1 | 301 | TimerSetValue( &TxNextPacketTimer, COMPLIANCE_TX_DUTYCYCLE ); |
ubhat | 0:6cc76d70e2a1 | 302 | TimerStart( &TxNextPacketTimer ); |
ubhat | 0:6cc76d70e2a1 | 303 | break; |
ubhat | 0:6cc76d70e2a1 | 304 | } |
ubhat | 0:6cc76d70e2a1 | 305 | |
ubhat | 0:6cc76d70e2a1 | 306 | default: |
ubhat | 0:6cc76d70e2a1 | 307 | { |
ubhat | 0:6cc76d70e2a1 | 308 | // Schedule next packet transmission |
ubhat | 0:6cc76d70e2a1 | 309 | TimerSetValue( &TxNextPacketTimer, TxDutyCycleTime ); |
ubhat | 0:6cc76d70e2a1 | 310 | TimerStart( &TxNextPacketTimer ); |
ubhat | 0:6cc76d70e2a1 | 311 | break; |
ubhat | 0:6cc76d70e2a1 | 312 | } |
ubhat | 0:6cc76d70e2a1 | 313 | } |
ubhat | 0:6cc76d70e2a1 | 314 | |
ubhat | 0:6cc76d70e2a1 | 315 | } |
ubhat | 0:6cc76d70e2a1 | 316 | |
ubhat | 0:6cc76d70e2a1 | 317 | /*! |
ubhat | 0:6cc76d70e2a1 | 318 | * \brief What to do during JOIN process ? blink/toggle LED etc. |
ubhat | 0:6cc76d70e2a1 | 319 | */ |
ubhat | 0:6cc76d70e2a1 | 320 | void JoinEvent( void ) |
ubhat | 0:6cc76d70e2a1 | 321 | { |
ubhat | 0:6cc76d70e2a1 | 322 | // CtrlLED is defined in LoRaBoardAppIf.h |
ubhat | 0:6cc76d70e2a1 | 323 | // param 1: LED color (Red, Yellow or Green) |
ubhat | 0:6cc76d70e2a1 | 324 | // param 2: LED_ON or LED_OFF |
ubhat | 0:6cc76d70e2a1 | 325 | //CtrlLED( Red, LED_ON ); |
ubhat | 0:6cc76d70e2a1 | 326 | } |
ubhat | 0:6cc76d70e2a1 | 327 | |
ubhat | 0:6cc76d70e2a1 | 328 | |
ubhat | 0:6cc76d70e2a1 | 329 | /*! |
ubhat | 0:6cc76d70e2a1 | 330 | * \brief What to do during TX ? blink/toggle LED etc. |
ubhat | 0:6cc76d70e2a1 | 331 | */ |
ubhat | 0:6cc76d70e2a1 | 332 | void TxEvent( void ) |
ubhat | 0:6cc76d70e2a1 | 333 | { |
ubhat | 0:6cc76d70e2a1 | 334 | int blinkTime = 25000; |
ubhat | 0:6cc76d70e2a1 | 335 | |
ubhat | 0:6cc76d70e2a1 | 336 | // Blink Red LED for 25msec |
ubhat | 0:6cc76d70e2a1 | 337 | //BlinkLED( Red, blinkTime ); |
ubhat | 0:6cc76d70e2a1 | 338 | } |
ubhat | 0:6cc76d70e2a1 | 339 | |
ubhat | 0:6cc76d70e2a1 | 340 | void RxEvent() |
ubhat | 0:6cc76d70e2a1 | 341 | { |
ubhat | 0:6cc76d70e2a1 | 342 | // Toggle yellow LED |
ubhat | 0:6cc76d70e2a1 | 343 | //ToggleLED( Yellow ); |
ubhat | 0:6cc76d70e2a1 | 344 | |
ubhat | 0:6cc76d70e2a1 | 345 | // If Rx Data is 0x01 turn on Green LED else if 0x0 Turn Green LED off |
ubhat | 0:6cc76d70e2a1 | 346 | if( LoRaMacDownlinkStatus.BufferSize == 1 ) |
ubhat | 0:6cc76d70e2a1 | 347 | { |
ubhat | 0:6cc76d70e2a1 | 348 | if( LoRaMacDownlinkStatus.Buffer[0] == 0x01 ) |
ubhat | 0:6cc76d70e2a1 | 349 | { |
ubhat | 0:6cc76d70e2a1 | 350 | AppLed = 1; |
ubhat | 0:6cc76d70e2a1 | 351 | } |
ubhat | 0:6cc76d70e2a1 | 352 | else |
ubhat | 0:6cc76d70e2a1 | 353 | { |
ubhat | 0:6cc76d70e2a1 | 354 | if( LoRaMacDownlinkStatus.Buffer[0] == 0x00 ) |
ubhat | 0:6cc76d70e2a1 | 355 | { |
ubhat | 0:6cc76d70e2a1 | 356 | AppLed = 0; |
ubhat | 0:6cc76d70e2a1 | 357 | } |
ubhat | 0:6cc76d70e2a1 | 358 | } |
ubhat | 0:6cc76d70e2a1 | 359 | } |
ubhat | 0:6cc76d70e2a1 | 360 | |
ubhat | 0:6cc76d70e2a1 | 361 | if( AppLed != 0 ) |
ubhat | 0:6cc76d70e2a1 | 362 | { |
ubhat | 0:6cc76d70e2a1 | 363 | // Turn USR_LED ON |
ubhat | 0:6cc76d70e2a1 | 364 | //UsrLED = 3.3; |
ubhat | 0:6cc76d70e2a1 | 365 | } |
ubhat | 0:6cc76d70e2a1 | 366 | else |
ubhat | 0:6cc76d70e2a1 | 367 | { |
ubhat | 0:6cc76d70e2a1 | 368 | // Turn USR_LED OFF |
ubhat | 0:6cc76d70e2a1 | 369 | //UsrLED = 0; |
ubhat | 0:6cc76d70e2a1 | 370 | } |
ubhat | 0:6cc76d70e2a1 | 371 | } |
ubhat | 0:6cc76d70e2a1 | 372 |