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