V03 config RTC+envoie 1 donnée/seconde
Dependencies: mbed LoRaWAN-lib SX1272Lib
app/main.cpp@10:1a85ff06be1a, 2019-01-23 (annotated)
- Committer:
- MGstic
- Date:
- Wed Jan 23 16:28:51 2019 +0000
- Revision:
- 10:1a85ff06be1a
- Parent:
- 9:07c94dd6dc51
V03
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mluis | 0:45496a70a8a5 | 1 | #include "mbed.h" |
mluis | 0:45496a70a8a5 | 2 | #include "board.h" |
mluis | 0:45496a70a8a5 | 3 | #include "radio.h" |
mluis | 0:45496a70a8a5 | 4 | #include "LoRaMac.h" |
mluis | 7:5077515c163b | 5 | #include "Commissioning.h" |
mluis | 0:45496a70a8a5 | 6 | #include "SerialDisplay.h" |
MGstic | 10:1a85ff06be1a | 7 | #include "unixtimestamp.h" |
MGstic | 10:1a85ff06be1a | 8 | #include <stdio.h> |
MGstic | 10:1a85ff06be1a | 9 | #include <time.h> |
mluis | 0:45496a70a8a5 | 10 | |
mluis | 0:45496a70a8a5 | 11 | |
mluis | 0:45496a70a8a5 | 12 | /*! |
MGstic | 10:1a85ff06be1a | 13 | * Defines the application data transmission duty cycle. 1s, value in [ms]. |
mluis | 0:45496a70a8a5 | 14 | */ |
MGstic | 10:1a85ff06be1a | 15 | #define APP_TX_DUTYCYCLE 1000 |
MGstic | 10:1a85ff06be1a | 16 | #define TAB_MAX 10 |
MGstic | 10:1a85ff06be1a | 17 | #define APP_TX_DUTYCYCLE_RND 250 |
mluis | 0:45496a70a8a5 | 18 | |
MGstic | 8:cfe39840b9fb | 19 | #define LORAWAN_DEFAULT_DATARATE DR_5 |
mluis | 0:45496a70a8a5 | 20 | #define LORAWAN_CONFIRMED_MSG_ON true |
mluis | 0:45496a70a8a5 | 21 | |
mluis | 0:45496a70a8a5 | 22 | /*! |
mluis | 0:45496a70a8a5 | 23 | * LoRaWAN Adaptive Data Rate |
mluis | 0:45496a70a8a5 | 24 | * |
mluis | 0:45496a70a8a5 | 25 | * \remark Please note that when ADR is enabled the end-device should be static |
mluis | 0:45496a70a8a5 | 26 | */ |
mluis | 0:45496a70a8a5 | 27 | #define LORAWAN_ADR_ON 1 |
mluis | 0:45496a70a8a5 | 28 | |
mluis | 0:45496a70a8a5 | 29 | #include "LoRaMacTest.h" |
mluis | 0:45496a70a8a5 | 30 | |
mluis | 0:45496a70a8a5 | 31 | /*! |
MGstic | 10:1a85ff06be1a | 32 | * LoRaWAN ETSI European Telecommunications Standards Institute |
MGstic | 10:1a85ff06be1a | 33 | * duty cycle control enable/disable |
MGstic | 10:1a85ff06be1a | 34 | * remark Please note that ETSI mandates duty cycled transmissions. Use only for test purposes |
mluis | 0:45496a70a8a5 | 35 | */ |
mluis | 7:5077515c163b | 36 | #define LORAWAN_DUTYCYCLE_ON false |
mluis | 0:45496a70a8a5 | 37 | |
mluis | 3:3152aa75c58d | 38 | #define USE_SEMTECH_DEFAULT_CHANNEL_LINEUP 1 |
mluis | 3:3152aa75c58d | 39 | |
MGstic | 10:1a85ff06be1a | 40 | //############INITIALISATION LIAISON SERIE#################### |
MGstic | 10:1a85ff06be1a | 41 | |
MGstic | 10:1a85ff06be1a | 42 | void saisie_serie(int tab[6]); |
MGstic | 10:1a85ff06be1a | 43 | int tabd[6]= {0,0,0,1,1,2018}; |
MGstic | 10:1a85ff06be1a | 44 | |
MGstic | 10:1a85ff06be1a | 45 | |
MGstic | 10:1a85ff06be1a | 46 | InterruptIn bouton(USER_BUTTON); // Déclaration de l'interruption extern activée par le bouton utilisateur bleu |
MGstic | 10:1a85ff06be1a | 47 | //Serial pc(USBTX, USBRX); // tx, rx//Serial pc(SERIAL_TX, SERIAL_RX); // Déclaration de entrées pour la liaison série |
MGstic | 10:1a85ff06be1a | 48 | int etat=0; |
MGstic | 10:1a85ff06be1a | 49 | void interruption_extern_bouton(void) |
MGstic | 10:1a85ff06be1a | 50 | { |
MGstic | 10:1a85ff06be1a | 51 | etat = not(etat); // changement d'etat |
MGstic | 10:1a85ff06be1a | 52 | } |
MGstic | 10:1a85ff06be1a | 53 | //############################################################ |
mluis | 3:3152aa75c58d | 54 | |
mluis | 3:3152aa75c58d | 55 | #define LC4 { 867100000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } |
mluis | 3:3152aa75c58d | 56 | #define LC5 { 867300000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } |
mluis | 3:3152aa75c58d | 57 | #define LC6 { 867500000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } |
mluis | 3:3152aa75c58d | 58 | #define LC7 { 867700000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } |
mluis | 3:3152aa75c58d | 59 | #define LC8 { 867900000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } |
mluis | 3:3152aa75c58d | 60 | #define LC9 { 868800000, { ( ( DR_7 << 4 ) | DR_7 ) }, 2 } |
mluis | 3:3152aa75c58d | 61 | #define LC10 { 868300000, { ( ( DR_6 << 4 ) | DR_6 ) }, 1 } |
mluis | 3:3152aa75c58d | 62 | |
mluis | 0:45496a70a8a5 | 63 | /*! |
mluis | 0:45496a70a8a5 | 64 | * LoRaWAN application port |
mluis | 0:45496a70a8a5 | 65 | */ |
mluis | 0:45496a70a8a5 | 66 | #define LORAWAN_APP_PORT 15 |
mluis | 0:45496a70a8a5 | 67 | |
mluis | 0:45496a70a8a5 | 68 | /*! |
mluis | 0:45496a70a8a5 | 69 | * User application data buffer size |
mluis | 0:45496a70a8a5 | 70 | */ |
MGstic | 10:1a85ff06be1a | 71 | #define LORAWAN_APP_DATA_SIZE 24 |
mluis | 0:45496a70a8a5 | 72 | |
mluis | 0:45496a70a8a5 | 73 | static uint8_t DevEui[] = LORAWAN_DEVICE_EUI; |
mluis | 0:45496a70a8a5 | 74 | static uint8_t AppEui[] = LORAWAN_APPLICATION_EUI; |
mluis | 0:45496a70a8a5 | 75 | static uint8_t AppKey[] = LORAWAN_APPLICATION_KEY; |
mluis | 0:45496a70a8a5 | 76 | static uint8_t NwkSKey[] = LORAWAN_NWKSKEY; |
mluis | 0:45496a70a8a5 | 77 | static uint8_t AppSKey[] = LORAWAN_APPSKEY; |
mluis | 0:45496a70a8a5 | 78 | |
mluis | 0:45496a70a8a5 | 79 | /*! |
mluis | 0:45496a70a8a5 | 80 | * Device address |
mluis | 0:45496a70a8a5 | 81 | */ |
mluis | 0:45496a70a8a5 | 82 | static uint32_t DevAddr = LORAWAN_DEVICE_ADDRESS; |
mluis | 0:45496a70a8a5 | 83 | |
mluis | 0:45496a70a8a5 | 84 | /*! |
mluis | 0:45496a70a8a5 | 85 | * Application port |
mluis | 0:45496a70a8a5 | 86 | */ |
mluis | 0:45496a70a8a5 | 87 | static uint8_t AppPort = LORAWAN_APP_PORT; |
mluis | 0:45496a70a8a5 | 88 | |
mluis | 0:45496a70a8a5 | 89 | /*! |
mluis | 0:45496a70a8a5 | 90 | * User application data size |
mluis | 0:45496a70a8a5 | 91 | */ |
mluis | 0:45496a70a8a5 | 92 | static uint8_t AppDataSize = LORAWAN_APP_DATA_SIZE; |
mluis | 0:45496a70a8a5 | 93 | |
mluis | 0:45496a70a8a5 | 94 | /*! |
mluis | 0:45496a70a8a5 | 95 | * User application data buffer size |
mluis | 0:45496a70a8a5 | 96 | */ |
mluis | 0:45496a70a8a5 | 97 | #define LORAWAN_APP_DATA_MAX_SIZE 64 |
mluis | 0:45496a70a8a5 | 98 | |
mluis | 0:45496a70a8a5 | 99 | /*! |
mluis | 0:45496a70a8a5 | 100 | * User application data |
mluis | 0:45496a70a8a5 | 101 | */ |
mluis | 0:45496a70a8a5 | 102 | static uint8_t AppData[LORAWAN_APP_DATA_MAX_SIZE]; |
mluis | 0:45496a70a8a5 | 103 | |
mluis | 0:45496a70a8a5 | 104 | /*! |
mluis | 0:45496a70a8a5 | 105 | * Indicates if the node is sending confirmed or unconfirmed messages |
mluis | 0:45496a70a8a5 | 106 | */ |
mluis | 0:45496a70a8a5 | 107 | static uint8_t IsTxConfirmed = LORAWAN_CONFIRMED_MSG_ON; |
mluis | 0:45496a70a8a5 | 108 | |
mluis | 0:45496a70a8a5 | 109 | /*! |
mluis | 0:45496a70a8a5 | 110 | * Defines the application data transmission duty cycle |
mluis | 0:45496a70a8a5 | 111 | */ |
mluis | 0:45496a70a8a5 | 112 | static uint32_t TxDutyCycleTime; |
mluis | 0:45496a70a8a5 | 113 | |
mluis | 0:45496a70a8a5 | 114 | /*! |
mluis | 0:45496a70a8a5 | 115 | * Timer to handle the application data transmission duty cycle |
mluis | 0:45496a70a8a5 | 116 | */ |
mluis | 0:45496a70a8a5 | 117 | static TimerEvent_t TxNextPacketTimer; |
mluis | 0:45496a70a8a5 | 118 | |
MGstic | 10:1a85ff06be1a | 119 | /* |
mluis | 0:45496a70a8a5 | 120 | * Indicates if a new packet can be sent |
mluis | 0:45496a70a8a5 | 121 | */ |
mluis | 0:45496a70a8a5 | 122 | static bool NextTx = true; |
mluis | 0:45496a70a8a5 | 123 | |
mluis | 0:45496a70a8a5 | 124 | /*! |
mluis | 0:45496a70a8a5 | 125 | * Device states |
mluis | 0:45496a70a8a5 | 126 | */ |
mluis | 7:5077515c163b | 127 | static enum eDeviceState |
mluis | 0:45496a70a8a5 | 128 | { |
mluis | 0:45496a70a8a5 | 129 | DEVICE_STATE_INIT, |
mluis | 0:45496a70a8a5 | 130 | DEVICE_STATE_JOIN, |
mluis | 0:45496a70a8a5 | 131 | DEVICE_STATE_SEND, |
mluis | 0:45496a70a8a5 | 132 | DEVICE_STATE_CYCLE, |
mluis | 0:45496a70a8a5 | 133 | DEVICE_STATE_SLEEP |
mluis | 0:45496a70a8a5 | 134 | }DeviceState; |
mluis | 0:45496a70a8a5 | 135 | |
mluis | 0:45496a70a8a5 | 136 | /*! |
mluis | 0:45496a70a8a5 | 137 | * LoRaWAN compliance tests support data |
mluis | 0:45496a70a8a5 | 138 | */ |
mluis | 0:45496a70a8a5 | 139 | struct ComplianceTest_s |
mluis | 0:45496a70a8a5 | 140 | { |
mluis | 0:45496a70a8a5 | 141 | bool Running; |
mluis | 0:45496a70a8a5 | 142 | uint8_t State; |
mluis | 0:45496a70a8a5 | 143 | bool IsTxConfirmed; |
mluis | 0:45496a70a8a5 | 144 | uint8_t AppPort; |
mluis | 0:45496a70a8a5 | 145 | uint8_t AppDataSize; |
mluis | 0:45496a70a8a5 | 146 | uint8_t *AppDataBuffer; |
mluis | 0:45496a70a8a5 | 147 | uint16_t DownLinkCounter; |
mluis | 0:45496a70a8a5 | 148 | bool LinkCheck; |
mluis | 0:45496a70a8a5 | 149 | uint8_t DemodMargin; |
mluis | 0:45496a70a8a5 | 150 | uint8_t NbGateways; |
mluis | 0:45496a70a8a5 | 151 | }ComplianceTest; |
mluis | 0:45496a70a8a5 | 152 | |
mluis | 0:45496a70a8a5 | 153 | /*! |
mluis | 0:45496a70a8a5 | 154 | * Indicates if the MAC layer network join status has changed. |
mluis | 0:45496a70a8a5 | 155 | */ |
mluis | 0:45496a70a8a5 | 156 | static bool IsNetworkJoinedStatusUpdate = false; |
mluis | 0:45496a70a8a5 | 157 | |
mluis | 0:45496a70a8a5 | 158 | /*! |
mluis | 0:45496a70a8a5 | 159 | * Strucure containing the Uplink status |
mluis | 0:45496a70a8a5 | 160 | */ |
mluis | 0:45496a70a8a5 | 161 | struct sLoRaMacUplinkStatus |
mluis | 0:45496a70a8a5 | 162 | { |
mluis | 0:45496a70a8a5 | 163 | uint8_t Acked; |
mluis | 0:45496a70a8a5 | 164 | int8_t Datarate; |
mluis | 0:45496a70a8a5 | 165 | uint16_t UplinkCounter; |
mluis | 0:45496a70a8a5 | 166 | uint8_t Port; |
mluis | 0:45496a70a8a5 | 167 | uint8_t *Buffer; |
mluis | 0:45496a70a8a5 | 168 | uint8_t BufferSize; |
mluis | 0:45496a70a8a5 | 169 | }LoRaMacUplinkStatus; |
mluis | 0:45496a70a8a5 | 170 | volatile bool UplinkStatusUpdated = false; |
mluis | 0:45496a70a8a5 | 171 | |
mluis | 0:45496a70a8a5 | 172 | /*! |
mluis | 0:45496a70a8a5 | 173 | * Strucure containing the Downlink status |
mluis | 0:45496a70a8a5 | 174 | */ |
mluis | 0:45496a70a8a5 | 175 | struct sLoRaMacDownlinkStatus |
mluis | 0:45496a70a8a5 | 176 | { |
mluis | 0:45496a70a8a5 | 177 | int16_t Rssi; |
mluis | 0:45496a70a8a5 | 178 | int8_t Snr; |
mluis | 0:45496a70a8a5 | 179 | uint16_t DownlinkCounter; |
mluis | 0:45496a70a8a5 | 180 | bool RxData; |
mluis | 0:45496a70a8a5 | 181 | uint8_t Port; |
mluis | 0:45496a70a8a5 | 182 | uint8_t *Buffer; |
mluis | 0:45496a70a8a5 | 183 | uint8_t BufferSize; |
mluis | 0:45496a70a8a5 | 184 | }LoRaMacDownlinkStatus; |
mluis | 0:45496a70a8a5 | 185 | volatile bool DownlinkStatusUpdated = false; |
mluis | 0:45496a70a8a5 | 186 | |
mluis | 0:45496a70a8a5 | 187 | void SerialDisplayRefresh( void ) |
mluis | 0:45496a70a8a5 | 188 | { |
mluis | 0:45496a70a8a5 | 189 | MibRequestConfirm_t mibReq; |
mluis | 0:45496a70a8a5 | 190 | |
mluis | 0:45496a70a8a5 | 191 | SerialDisplayInit( ); |
mluis | 0:45496a70a8a5 | 192 | SerialDisplayUpdateActivationMode( OVER_THE_AIR_ACTIVATION ); |
mluis | 0:45496a70a8a5 | 193 | |
mluis | 0:45496a70a8a5 | 194 | SerialDisplayUpdateNwkId( LORAWAN_NETWORK_ID ); |
mluis | 0:45496a70a8a5 | 195 | SerialDisplayUpdateDevAddr( DevAddr ); |
mluis | 0:45496a70a8a5 | 196 | SerialDisplayUpdateKey( 12, NwkSKey ); |
mluis | 0:45496a70a8a5 | 197 | SerialDisplayUpdateKey( 13, AppSKey ); |
mluis | 0:45496a70a8a5 | 198 | SerialDisplayUpdateEui( 5, DevEui ); |
mluis | 0:45496a70a8a5 | 199 | SerialDisplayUpdateEui( 6, AppEui ); |
mluis | 0:45496a70a8a5 | 200 | SerialDisplayUpdateKey( 7, AppKey ); |
mluis | 0:45496a70a8a5 | 201 | |
mluis | 0:45496a70a8a5 | 202 | mibReq.Type = MIB_NETWORK_JOINED; |
mluis | 0:45496a70a8a5 | 203 | LoRaMacMibGetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 204 | SerialDisplayUpdateNetworkIsJoined( mibReq.Param.IsNetworkJoined ); |
mluis | 0:45496a70a8a5 | 205 | |
mluis | 0:45496a70a8a5 | 206 | SerialDisplayUpdateAdr( LORAWAN_ADR_ON ); |
mluis | 0:45496a70a8a5 | 207 | SerialDisplayUpdateDutyCycle( LORAWAN_DUTYCYCLE_ON ); |
MGstic | 10:1a85ff06be1a | 208 | SerialDisplayUpdatePublicNetwork( LORAWAN_PUBLIC_NETWORK ); |
MGstic | 10:1a85ff06be1a | 209 | SerialDisplayRTCactive(etat); |
MGstic | 10:1a85ff06be1a | 210 | SerialDisplayTIME(tabd); |
MGstic | 10:1a85ff06be1a | 211 | |
MGstic | 10:1a85ff06be1a | 212 | //SerialDisplayUpdateLedState( 3, AppLedStateOn ); |
mluis | 0:45496a70a8a5 | 213 | } |
mluis | 0:45496a70a8a5 | 214 | |
mluis | 0:45496a70a8a5 | 215 | void SerialRxProcess( void ) |
mluis | 0:45496a70a8a5 | 216 | { |
mluis | 0:45496a70a8a5 | 217 | if( SerialDisplayReadable( ) == true ) |
mluis | 0:45496a70a8a5 | 218 | { |
mluis | 0:45496a70a8a5 | 219 | switch( SerialDisplayGetChar( ) ) |
mluis | 0:45496a70a8a5 | 220 | { |
mluis | 0:45496a70a8a5 | 221 | case 'R': |
mluis | 0:45496a70a8a5 | 222 | case 'r': |
mluis | 0:45496a70a8a5 | 223 | // Refresh Serial screen |
mluis | 0:45496a70a8a5 | 224 | SerialDisplayRefresh( ); |
mluis | 0:45496a70a8a5 | 225 | break; |
mluis | 0:45496a70a8a5 | 226 | default: |
mluis | 0:45496a70a8a5 | 227 | break; |
mluis | 0:45496a70a8a5 | 228 | } |
mluis | 0:45496a70a8a5 | 229 | } |
mluis | 0:45496a70a8a5 | 230 | } |
mluis | 0:45496a70a8a5 | 231 | |
mluis | 0:45496a70a8a5 | 232 | /*! |
mluis | 0:45496a70a8a5 | 233 | * \brief Prepares the payload of the frame |
mluis | 0:45496a70a8a5 | 234 | */ |
MGstic | 10:1a85ff06be1a | 235 | |
MGstic | 10:1a85ff06be1a | 236 | uint8_t poidstest=34; |
MGstic | 10:1a85ff06be1a | 237 | uint8_t heuretest=0; |
MGstic | 10:1a85ff06be1a | 238 | |
MGstic | 10:1a85ff06be1a | 239 | typedef struct { |
MGstic | 10:1a85ff06be1a | 240 | uint8_t heure;//[8]; // Augmentation taille prog. Solution : heure = pointeur vers malloc (26 ou sizeof ctime)=1bit |
MGstic | 10:1a85ff06be1a | 241 | uint8_t masse;//[8]; |
MGstic | 10:1a85ff06be1a | 242 | } data; |
MGstic | 10:1a85ff06be1a | 243 | data data_packet[TAB_MAX]; |
MGstic | 10:1a85ff06be1a | 244 | |
MGstic | 10:1a85ff06be1a | 245 | //################################### |
MGstic | 10:1a85ff06be1a | 246 | |
MGstic | 10:1a85ff06be1a | 247 | void copy_time(int data_packet[8],time_t seconds) |
mluis | 0:45496a70a8a5 | 248 | { |
MGstic | 10:1a85ff06be1a | 249 | char temp[32]; |
MGstic | 10:1a85ff06be1a | 250 | int tempp; |
MGstic | 10:1a85ff06be1a | 251 | //printf("=>%s\n",ctime(&seconds)); |
MGstic | 10:1a85ff06be1a | 252 | //printf("%d\r\n",seconds); |
MGstic | 10:1a85ff06be1a | 253 | sprintf(temp,"%d",(int)seconds);// copie de la valeur de la RTC en cours dans le tableau de structure data_packet |
MGstic | 10:1a85ff06be1a | 254 | tempp=atoi(temp); |
MGstic | 10:1a85ff06be1a | 255 | Whex_buffer(tempp,data_packet); |
MGstic | 10:1a85ff06be1a | 256 | } |
MGstic | 10:1a85ff06be1a | 257 | //################################## |
MGstic | 10:1a85ff06be1a | 258 | |
MGstic | 10:1a85ff06be1a | 259 | static void PrepareTxFrame( uint8_t port,data datat )//, 2EME PARAMETRE TABLEAU DONNEE INIT=>APPDATA DANS FONCION fournir 1 case tableau data_packet |
MGstic | 10:1a85ff06be1a | 260 | { |
MGstic | 10:1a85ff06be1a | 261 | int dpacket[8]; |
MGstic | 10:1a85ff06be1a | 262 | time_t seconds=time(NULL); |
mluis | 0:45496a70a8a5 | 263 | switch( port ) |
mluis | 0:45496a70a8a5 | 264 | { |
mluis | 0:45496a70a8a5 | 265 | case 15: |
mluis | 0:45496a70a8a5 | 266 | { |
MGstic | 10:1a85ff06be1a | 267 | //printf("%d\r\n",seconds); |
MGstic | 10:1a85ff06be1a | 268 | copy_time(dpacket,seconds); |
MGstic | 10:1a85ff06be1a | 269 | /*for(int k=0;k<8;k++) |
MGstic | 10:1a85ff06be1a | 270 | { |
MGstic | 10:1a85ff06be1a | 271 | printf("%X",dpacket[k]); |
MGstic | 10:1a85ff06be1a | 272 | } |
MGstic | 10:1a85ff06be1a | 273 | printf("\n\r");*/ |
MGstic | 10:1a85ff06be1a | 274 | for(int h=0;h<8;h++) |
MGstic | 10:1a85ff06be1a | 275 | { |
MGstic | 9:07c94dd6dc51 | 276 | |
MGstic | 10:1a85ff06be1a | 277 | |
MGstic | 10:1a85ff06be1a | 278 | AppData[h]=dpacket[h]; |
MGstic | 10:1a85ff06be1a | 279 | //AppData[h]=datat.heure; |
MGstic | 10:1a85ff06be1a | 280 | //printf(" ||H:%d|\n\r",AppData[0]); |
MGstic | 10:1a85ff06be1a | 281 | |
MGstic | 10:1a85ff06be1a | 282 | //printf(" ||P:%d|\n\r",AppData[16]); |
MGstic | 10:1a85ff06be1a | 283 | } |
MGstic | 10:1a85ff06be1a | 284 | |
MGstic | 10:1a85ff06be1a | 285 | AppData[16]=datat.masse; |
mluis | 0:45496a70a8a5 | 286 | } |
mluis | 0:45496a70a8a5 | 287 | break; |
mluis | 0:45496a70a8a5 | 288 | case 224: |
mluis | 0:45496a70a8a5 | 289 | if( ComplianceTest.LinkCheck == true ) |
mluis | 0:45496a70a8a5 | 290 | { |
mluis | 0:45496a70a8a5 | 291 | ComplianceTest.LinkCheck = false; |
mluis | 0:45496a70a8a5 | 292 | AppDataSize = 3; |
mluis | 0:45496a70a8a5 | 293 | AppData[0] = 5; |
mluis | 0:45496a70a8a5 | 294 | AppData[1] = ComplianceTest.DemodMargin; |
mluis | 0:45496a70a8a5 | 295 | AppData[2] = ComplianceTest.NbGateways; |
mluis | 0:45496a70a8a5 | 296 | ComplianceTest.State = 1; |
mluis | 0:45496a70a8a5 | 297 | } |
mluis | 0:45496a70a8a5 | 298 | else |
mluis | 0:45496a70a8a5 | 299 | { |
mluis | 0:45496a70a8a5 | 300 | switch( ComplianceTest.State ) |
mluis | 0:45496a70a8a5 | 301 | { |
mluis | 0:45496a70a8a5 | 302 | case 4: |
mluis | 0:45496a70a8a5 | 303 | ComplianceTest.State = 1; |
mluis | 0:45496a70a8a5 | 304 | break; |
mluis | 0:45496a70a8a5 | 305 | case 1: |
mluis | 0:45496a70a8a5 | 306 | AppDataSize = 2; |
mluis | 0:45496a70a8a5 | 307 | AppData[0] = ComplianceTest.DownLinkCounter >> 8; |
mluis | 0:45496a70a8a5 | 308 | AppData[1] = ComplianceTest.DownLinkCounter; |
mluis | 0:45496a70a8a5 | 309 | break; |
mluis | 0:45496a70a8a5 | 310 | } |
mluis | 0:45496a70a8a5 | 311 | } |
mluis | 0:45496a70a8a5 | 312 | break; |
mluis | 0:45496a70a8a5 | 313 | default: |
mluis | 0:45496a70a8a5 | 314 | break; |
mluis | 0:45496a70a8a5 | 315 | } |
mluis | 0:45496a70a8a5 | 316 | } |
mluis | 0:45496a70a8a5 | 317 | |
mluis | 0:45496a70a8a5 | 318 | /*! |
mluis | 0:45496a70a8a5 | 319 | * \brief Prepares the payload of the frame |
mluis | 0:45496a70a8a5 | 320 | * |
mluis | 0:45496a70a8a5 | 321 | * \retval [0: frame could be send, 1: error] |
mluis | 0:45496a70a8a5 | 322 | */ |
mluis | 0:45496a70a8a5 | 323 | static bool SendFrame( void ) |
mluis | 0:45496a70a8a5 | 324 | { |
mluis | 0:45496a70a8a5 | 325 | McpsReq_t mcpsReq; |
mluis | 0:45496a70a8a5 | 326 | LoRaMacTxInfo_t txInfo; |
mluis | 7:5077515c163b | 327 | |
mluis | 0:45496a70a8a5 | 328 | if( LoRaMacQueryTxPossible( AppDataSize, &txInfo ) != LORAMAC_STATUS_OK ) |
mluis | 0:45496a70a8a5 | 329 | { |
mluis | 0:45496a70a8a5 | 330 | // Send empty frame in order to flush MAC commands |
mluis | 0:45496a70a8a5 | 331 | mcpsReq.Type = MCPS_UNCONFIRMED; |
mluis | 0:45496a70a8a5 | 332 | mcpsReq.Req.Unconfirmed.fBuffer = NULL; |
mluis | 0:45496a70a8a5 | 333 | mcpsReq.Req.Unconfirmed.fBufferSize = 0; |
mluis | 0:45496a70a8a5 | 334 | mcpsReq.Req.Unconfirmed.Datarate = LORAWAN_DEFAULT_DATARATE; |
mluis | 3:3152aa75c58d | 335 | |
mluis | 0:45496a70a8a5 | 336 | LoRaMacUplinkStatus.Acked = false; |
mluis | 0:45496a70a8a5 | 337 | LoRaMacUplinkStatus.Port = 0; |
mluis | 0:45496a70a8a5 | 338 | LoRaMacUplinkStatus.Buffer = NULL; |
mluis | 0:45496a70a8a5 | 339 | LoRaMacUplinkStatus.BufferSize = 0; |
mluis | 0:45496a70a8a5 | 340 | SerialDisplayUpdateFrameType( false ); |
mluis | 0:45496a70a8a5 | 341 | } |
mluis | 0:45496a70a8a5 | 342 | else |
mluis | 0:45496a70a8a5 | 343 | { |
mluis | 0:45496a70a8a5 | 344 | LoRaMacUplinkStatus.Acked = false; |
mluis | 0:45496a70a8a5 | 345 | LoRaMacUplinkStatus.Port = AppPort; |
mluis | 0:45496a70a8a5 | 346 | LoRaMacUplinkStatus.Buffer = AppData; |
mluis | 0:45496a70a8a5 | 347 | LoRaMacUplinkStatus.BufferSize = AppDataSize; |
mluis | 0:45496a70a8a5 | 348 | SerialDisplayUpdateFrameType( IsTxConfirmed ); |
mluis | 0:45496a70a8a5 | 349 | |
mluis | 0:45496a70a8a5 | 350 | if( IsTxConfirmed == false ) |
mluis | 0:45496a70a8a5 | 351 | { |
mluis | 0:45496a70a8a5 | 352 | mcpsReq.Type = MCPS_UNCONFIRMED; |
mluis | 0:45496a70a8a5 | 353 | mcpsReq.Req.Unconfirmed.fPort = AppPort; |
mluis | 0:45496a70a8a5 | 354 | mcpsReq.Req.Unconfirmed.fBuffer = AppData; |
mluis | 0:45496a70a8a5 | 355 | mcpsReq.Req.Unconfirmed.fBufferSize = AppDataSize; |
mluis | 0:45496a70a8a5 | 356 | mcpsReq.Req.Unconfirmed.Datarate = LORAWAN_DEFAULT_DATARATE; |
mluis | 0:45496a70a8a5 | 357 | } |
mluis | 0:45496a70a8a5 | 358 | else |
mluis | 0:45496a70a8a5 | 359 | { |
mluis | 0:45496a70a8a5 | 360 | mcpsReq.Type = MCPS_CONFIRMED; |
mluis | 0:45496a70a8a5 | 361 | mcpsReq.Req.Confirmed.fPort = AppPort; |
mluis | 0:45496a70a8a5 | 362 | mcpsReq.Req.Confirmed.fBuffer = AppData; |
mluis | 0:45496a70a8a5 | 363 | mcpsReq.Req.Confirmed.fBufferSize = AppDataSize; |
mluis | 2:2eeaeae2c725 | 364 | mcpsReq.Req.Confirmed.NbTrials = 8; |
mluis | 0:45496a70a8a5 | 365 | mcpsReq.Req.Confirmed.Datarate = LORAWAN_DEFAULT_DATARATE; |
mluis | 0:45496a70a8a5 | 366 | } |
mluis | 0:45496a70a8a5 | 367 | } |
mluis | 0:45496a70a8a5 | 368 | |
mluis | 0:45496a70a8a5 | 369 | if( LoRaMacMcpsRequest( &mcpsReq ) == LORAMAC_STATUS_OK ) |
mluis | 0:45496a70a8a5 | 370 | { |
mluis | 0:45496a70a8a5 | 371 | return false; |
mluis | 0:45496a70a8a5 | 372 | } |
mluis | 0:45496a70a8a5 | 373 | return true; |
mluis | 0:45496a70a8a5 | 374 | } |
mluis | 0:45496a70a8a5 | 375 | |
mluis | 0:45496a70a8a5 | 376 | /*! |
mluis | 0:45496a70a8a5 | 377 | * \brief Function executed on TxNextPacket Timeout event |
mluis | 0:45496a70a8a5 | 378 | */ |
mluis | 0:45496a70a8a5 | 379 | static void OnTxNextPacketTimerEvent( void ) |
mluis | 0:45496a70a8a5 | 380 | { |
mluis | 0:45496a70a8a5 | 381 | MibRequestConfirm_t mibReq; |
mluis | 0:45496a70a8a5 | 382 | LoRaMacStatus_t status; |
mluis | 0:45496a70a8a5 | 383 | |
mluis | 0:45496a70a8a5 | 384 | TimerStop( &TxNextPacketTimer ); |
mluis | 0:45496a70a8a5 | 385 | |
mluis | 0:45496a70a8a5 | 386 | mibReq.Type = MIB_NETWORK_JOINED; |
mluis | 0:45496a70a8a5 | 387 | status = LoRaMacMibGetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 388 | |
mluis | 0:45496a70a8a5 | 389 | if( status == LORAMAC_STATUS_OK ) |
mluis | 0:45496a70a8a5 | 390 | { |
mluis | 0:45496a70a8a5 | 391 | if( mibReq.Param.IsNetworkJoined == true ) |
mluis | 0:45496a70a8a5 | 392 | { |
mluis | 0:45496a70a8a5 | 393 | DeviceState = DEVICE_STATE_SEND; |
mluis | 0:45496a70a8a5 | 394 | NextTx = true; |
mluis | 0:45496a70a8a5 | 395 | } |
mluis | 0:45496a70a8a5 | 396 | else |
mluis | 0:45496a70a8a5 | 397 | { |
mluis | 0:45496a70a8a5 | 398 | DeviceState = DEVICE_STATE_JOIN; |
mluis | 0:45496a70a8a5 | 399 | } |
mluis | 0:45496a70a8a5 | 400 | } |
mluis | 0:45496a70a8a5 | 401 | } |
mluis | 0:45496a70a8a5 | 402 | |
MGstic | 10:1a85ff06be1a | 403 | /* |
mluis | 0:45496a70a8a5 | 404 | * \brief MCPS-Confirm event function |
mluis | 0:45496a70a8a5 | 405 | * |
mluis | 3:3152aa75c58d | 406 | * \param [IN] mcpsConfirm - Pointer to the confirm structure, |
mluis | 0:45496a70a8a5 | 407 | * containing confirm attributes. |
mluis | 0:45496a70a8a5 | 408 | */ |
MGstic | 10:1a85ff06be1a | 409 | |
mluis | 3:3152aa75c58d | 410 | static void McpsConfirm( McpsConfirm_t *mcpsConfirm ) |
mluis | 0:45496a70a8a5 | 411 | { |
mluis | 3:3152aa75c58d | 412 | if( mcpsConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) |
mluis | 0:45496a70a8a5 | 413 | { |
mluis | 3:3152aa75c58d | 414 | switch( mcpsConfirm->McpsRequest ) |
mluis | 0:45496a70a8a5 | 415 | { |
mluis | 0:45496a70a8a5 | 416 | case MCPS_UNCONFIRMED: |
mluis | 0:45496a70a8a5 | 417 | { |
mluis | 0:45496a70a8a5 | 418 | // Check Datarate |
mluis | 0:45496a70a8a5 | 419 | // Check TxPower |
mluis | 0:45496a70a8a5 | 420 | break; |
mluis | 0:45496a70a8a5 | 421 | } |
mluis | 0:45496a70a8a5 | 422 | case MCPS_CONFIRMED: |
mluis | 0:45496a70a8a5 | 423 | { |
mluis | 0:45496a70a8a5 | 424 | // Check Datarate |
mluis | 0:45496a70a8a5 | 425 | // Check TxPower |
mluis | 0:45496a70a8a5 | 426 | // Check AckReceived |
mluis | 3:3152aa75c58d | 427 | // Check NbTrials |
mluis | 3:3152aa75c58d | 428 | LoRaMacUplinkStatus.Acked = mcpsConfirm->AckReceived; |
mluis | 0:45496a70a8a5 | 429 | break; |
mluis | 0:45496a70a8a5 | 430 | } |
mluis | 0:45496a70a8a5 | 431 | case MCPS_PROPRIETARY: |
mluis | 0:45496a70a8a5 | 432 | { |
mluis | 0:45496a70a8a5 | 433 | break; |
mluis | 0:45496a70a8a5 | 434 | } |
mluis | 0:45496a70a8a5 | 435 | default: |
mluis | 0:45496a70a8a5 | 436 | break; |
mluis | 0:45496a70a8a5 | 437 | } |
mluis | 3:3152aa75c58d | 438 | LoRaMacUplinkStatus.Datarate = mcpsConfirm->Datarate; |
mluis | 3:3152aa75c58d | 439 | LoRaMacUplinkStatus.UplinkCounter = mcpsConfirm->UpLinkCounter; |
mluis | 3:3152aa75c58d | 440 | |
MGstic | 10:1a85ff06be1a | 441 | /* Switch LED 1 ON |
mluis | 5:62862ef9480b | 442 | Led1State = true; |
mluis | 5:62862ef9480b | 443 | Led1StateChanged = true; |
MGstic | 10:1a85ff06be1a | 444 | TimerStart( &Led1Timer );*/ |
mluis | 5:62862ef9480b | 445 | |
mluis | 0:45496a70a8a5 | 446 | UplinkStatusUpdated = true; |
mluis | 0:45496a70a8a5 | 447 | } |
mluis | 0:45496a70a8a5 | 448 | NextTx = true; |
mluis | 0:45496a70a8a5 | 449 | } |
mluis | 0:45496a70a8a5 | 450 | |
mluis | 0:45496a70a8a5 | 451 | /*! |
mluis | 0:45496a70a8a5 | 452 | * \brief MCPS-Indication event function |
mluis | 0:45496a70a8a5 | 453 | * |
mluis | 3:3152aa75c58d | 454 | * \param [IN] mcpsIndication - Pointer to the indication structure, |
mluis | 0:45496a70a8a5 | 455 | * containing indication attributes. |
mluis | 0:45496a70a8a5 | 456 | */ |
mluis | 3:3152aa75c58d | 457 | static void McpsIndication( McpsIndication_t *mcpsIndication ) |
mluis | 0:45496a70a8a5 | 458 | { |
mluis | 3:3152aa75c58d | 459 | if( mcpsIndication->Status != LORAMAC_EVENT_INFO_STATUS_OK ) |
mluis | 0:45496a70a8a5 | 460 | { |
mluis | 0:45496a70a8a5 | 461 | return; |
mluis | 0:45496a70a8a5 | 462 | } |
mluis | 0:45496a70a8a5 | 463 | |
mluis | 3:3152aa75c58d | 464 | switch( mcpsIndication->McpsIndication ) |
mluis | 0:45496a70a8a5 | 465 | { |
mluis | 0:45496a70a8a5 | 466 | case MCPS_UNCONFIRMED: |
mluis | 0:45496a70a8a5 | 467 | { |
mluis | 0:45496a70a8a5 | 468 | break; |
mluis | 0:45496a70a8a5 | 469 | } |
mluis | 0:45496a70a8a5 | 470 | case MCPS_CONFIRMED: |
mluis | 0:45496a70a8a5 | 471 | { |
mluis | 0:45496a70a8a5 | 472 | break; |
mluis | 0:45496a70a8a5 | 473 | } |
mluis | 0:45496a70a8a5 | 474 | case MCPS_PROPRIETARY: |
mluis | 0:45496a70a8a5 | 475 | { |
mluis | 0:45496a70a8a5 | 476 | break; |
mluis | 0:45496a70a8a5 | 477 | } |
mluis | 0:45496a70a8a5 | 478 | case MCPS_MULTICAST: |
mluis | 0:45496a70a8a5 | 479 | { |
mluis | 0:45496a70a8a5 | 480 | break; |
mluis | 0:45496a70a8a5 | 481 | } |
mluis | 0:45496a70a8a5 | 482 | default: |
mluis | 0:45496a70a8a5 | 483 | break; |
mluis | 0:45496a70a8a5 | 484 | } |
mluis | 0:45496a70a8a5 | 485 | |
mluis | 0:45496a70a8a5 | 486 | // Check Multicast |
mluis | 0:45496a70a8a5 | 487 | // Check Port |
mluis | 0:45496a70a8a5 | 488 | // Check Datarate |
mluis | 0:45496a70a8a5 | 489 | // Check FramePending |
mluis | 0:45496a70a8a5 | 490 | // Check Buffer |
mluis | 0:45496a70a8a5 | 491 | // Check BufferSize |
mluis | 0:45496a70a8a5 | 492 | // Check Rssi |
mluis | 0:45496a70a8a5 | 493 | // Check Snr |
mluis | 0:45496a70a8a5 | 494 | // Check RxSlot |
mluis | 3:3152aa75c58d | 495 | LoRaMacDownlinkStatus.Rssi = mcpsIndication->Rssi; |
mluis | 3:3152aa75c58d | 496 | if( mcpsIndication->Snr & 0x80 ) // The SNR sign bit is 1 |
mluis | 0:45496a70a8a5 | 497 | { |
mluis | 0:45496a70a8a5 | 498 | // Invert and divide by 4 |
mluis | 3:3152aa75c58d | 499 | LoRaMacDownlinkStatus.Snr = ( ( ~mcpsIndication->Snr + 1 ) & 0xFF ) >> 2; |
mluis | 0:45496a70a8a5 | 500 | LoRaMacDownlinkStatus.Snr = -LoRaMacDownlinkStatus.Snr; |
mluis | 0:45496a70a8a5 | 501 | } |
mluis | 0:45496a70a8a5 | 502 | else |
mluis | 0:45496a70a8a5 | 503 | { |
mluis | 0:45496a70a8a5 | 504 | // Divide by 4 |
mluis | 3:3152aa75c58d | 505 | LoRaMacDownlinkStatus.Snr = ( mcpsIndication->Snr & 0xFF ) >> 2; |
mluis | 0:45496a70a8a5 | 506 | } |
mluis | 0:45496a70a8a5 | 507 | LoRaMacDownlinkStatus.DownlinkCounter++; |
mluis | 3:3152aa75c58d | 508 | LoRaMacDownlinkStatus.RxData = mcpsIndication->RxData; |
mluis | 3:3152aa75c58d | 509 | LoRaMacDownlinkStatus.Port = mcpsIndication->Port; |
mluis | 3:3152aa75c58d | 510 | LoRaMacDownlinkStatus.Buffer = mcpsIndication->Buffer; |
mluis | 3:3152aa75c58d | 511 | LoRaMacDownlinkStatus.BufferSize = mcpsIndication->BufferSize; |
mluis | 0:45496a70a8a5 | 512 | |
mluis | 0:45496a70a8a5 | 513 | if( ComplianceTest.Running == true ) |
mluis | 0:45496a70a8a5 | 514 | { |
mluis | 0:45496a70a8a5 | 515 | ComplianceTest.DownLinkCounter++; |
mluis | 0:45496a70a8a5 | 516 | } |
mluis | 0:45496a70a8a5 | 517 | |
mluis | 3:3152aa75c58d | 518 | if( mcpsIndication->RxData == true ) |
mluis | 0:45496a70a8a5 | 519 | { |
mluis | 3:3152aa75c58d | 520 | switch( mcpsIndication->Port ) |
mluis | 0:45496a70a8a5 | 521 | { |
mluis | 0:45496a70a8a5 | 522 | case 1: // The application LED can be controlled on port 1 or 2 |
mluis | 0:45496a70a8a5 | 523 | case 2: |
MGstic | 10:1a85ff06be1a | 524 | /*if( mcpsIndication->BufferSize == 1 ) |
mluis | 0:45496a70a8a5 | 525 | { |
mluis | 3:3152aa75c58d | 526 | AppLedStateOn = mcpsIndication->Buffer[0] & 0x01; |
mluis | 0:45496a70a8a5 | 527 | Led3StateChanged = true; |
MGstic | 10:1a85ff06be1a | 528 | }*/ |
mluis | 0:45496a70a8a5 | 529 | break; |
mluis | 0:45496a70a8a5 | 530 | case 224: |
mluis | 0:45496a70a8a5 | 531 | if( ComplianceTest.Running == false ) |
mluis | 0:45496a70a8a5 | 532 | { |
mluis | 0:45496a70a8a5 | 533 | // Check compliance test enable command (i) |
mluis | 3:3152aa75c58d | 534 | if( ( mcpsIndication->BufferSize == 4 ) && |
mluis | 3:3152aa75c58d | 535 | ( mcpsIndication->Buffer[0] == 0x01 ) && |
mluis | 3:3152aa75c58d | 536 | ( mcpsIndication->Buffer[1] == 0x01 ) && |
mluis | 3:3152aa75c58d | 537 | ( mcpsIndication->Buffer[2] == 0x01 ) && |
mluis | 3:3152aa75c58d | 538 | ( mcpsIndication->Buffer[3] == 0x01 ) ) |
mluis | 0:45496a70a8a5 | 539 | { |
mluis | 0:45496a70a8a5 | 540 | IsTxConfirmed = false; |
mluis | 0:45496a70a8a5 | 541 | AppPort = 224; |
mluis | 0:45496a70a8a5 | 542 | AppDataSize = 2; |
mluis | 0:45496a70a8a5 | 543 | ComplianceTest.DownLinkCounter = 0; |
mluis | 0:45496a70a8a5 | 544 | ComplianceTest.LinkCheck = false; |
mluis | 0:45496a70a8a5 | 545 | ComplianceTest.DemodMargin = 0; |
mluis | 0:45496a70a8a5 | 546 | ComplianceTest.NbGateways = 0; |
mluis | 0:45496a70a8a5 | 547 | ComplianceTest.Running = true; |
mluis | 0:45496a70a8a5 | 548 | ComplianceTest.State = 1; |
mluis | 7:5077515c163b | 549 | |
mluis | 0:45496a70a8a5 | 550 | MibRequestConfirm_t mibReq; |
mluis | 0:45496a70a8a5 | 551 | mibReq.Type = MIB_ADR; |
mluis | 0:45496a70a8a5 | 552 | mibReq.Param.AdrEnable = true; |
mluis | 0:45496a70a8a5 | 553 | LoRaMacMibSetRequestConfirm( &mibReq ); |
MGstic | 10:1a85ff06be1a | 554 | LoRaMacTestSetDutyCycleOn( false ); |
mluis | 0:45496a70a8a5 | 555 | |
mluis | 0:45496a70a8a5 | 556 | } |
mluis | 0:45496a70a8a5 | 557 | } |
mluis | 0:45496a70a8a5 | 558 | else |
mluis | 0:45496a70a8a5 | 559 | { |
mluis | 3:3152aa75c58d | 560 | ComplianceTest.State = mcpsIndication->Buffer[0]; |
mluis | 0:45496a70a8a5 | 561 | switch( ComplianceTest.State ) |
mluis | 0:45496a70a8a5 | 562 | { |
mluis | 0:45496a70a8a5 | 563 | case 0: // Check compliance test disable command (ii) |
mluis | 0:45496a70a8a5 | 564 | IsTxConfirmed = LORAWAN_CONFIRMED_MSG_ON; |
mluis | 0:45496a70a8a5 | 565 | AppPort = LORAWAN_APP_PORT; |
mluis | 0:45496a70a8a5 | 566 | AppDataSize = LORAWAN_APP_DATA_SIZE; |
mluis | 0:45496a70a8a5 | 567 | ComplianceTest.DownLinkCounter = 0; |
mluis | 0:45496a70a8a5 | 568 | ComplianceTest.Running = false; |
mluis | 7:5077515c163b | 569 | |
mluis | 0:45496a70a8a5 | 570 | MibRequestConfirm_t mibReq; |
mluis | 0:45496a70a8a5 | 571 | mibReq.Type = MIB_ADR; |
mluis | 0:45496a70a8a5 | 572 | mibReq.Param.AdrEnable = LORAWAN_ADR_ON; |
mluis | 0:45496a70a8a5 | 573 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 574 | LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON ); |
MGstic | 10:1a85ff06be1a | 575 | |
mluis | 0:45496a70a8a5 | 576 | break; |
mluis | 0:45496a70a8a5 | 577 | case 1: // (iii, iv) |
mluis | 0:45496a70a8a5 | 578 | AppDataSize = 2; |
mluis | 0:45496a70a8a5 | 579 | break; |
mluis | 0:45496a70a8a5 | 580 | case 2: // Enable confirmed messages (v) |
mluis | 0:45496a70a8a5 | 581 | IsTxConfirmed = true; |
mluis | 0:45496a70a8a5 | 582 | ComplianceTest.State = 1; |
mluis | 0:45496a70a8a5 | 583 | break; |
mluis | 0:45496a70a8a5 | 584 | case 3: // Disable confirmed messages (vi) |
mluis | 0:45496a70a8a5 | 585 | IsTxConfirmed = false; |
mluis | 0:45496a70a8a5 | 586 | ComplianceTest.State = 1; |
mluis | 0:45496a70a8a5 | 587 | break; |
mluis | 0:45496a70a8a5 | 588 | case 4: // (vii) |
mluis | 3:3152aa75c58d | 589 | AppDataSize = mcpsIndication->BufferSize; |
mluis | 0:45496a70a8a5 | 590 | |
mluis | 0:45496a70a8a5 | 591 | AppData[0] = 4; |
mluis | 0:45496a70a8a5 | 592 | for( uint8_t i = 1; i < AppDataSize; i++ ) |
mluis | 0:45496a70a8a5 | 593 | { |
mluis | 3:3152aa75c58d | 594 | AppData[i] = mcpsIndication->Buffer[i] + 1; |
mluis | 0:45496a70a8a5 | 595 | } |
mluis | 0:45496a70a8a5 | 596 | break; |
mluis | 0:45496a70a8a5 | 597 | case 5: // (viii) |
mluis | 0:45496a70a8a5 | 598 | { |
mluis | 0:45496a70a8a5 | 599 | MlmeReq_t mlmeReq; |
mluis | 0:45496a70a8a5 | 600 | mlmeReq.Type = MLME_LINK_CHECK; |
mluis | 0:45496a70a8a5 | 601 | LoRaMacMlmeRequest( &mlmeReq ); |
mluis | 0:45496a70a8a5 | 602 | } |
mluis | 0:45496a70a8a5 | 603 | break; |
mluis | 5:62862ef9480b | 604 | case 6: // (ix) |
mluis | 5:62862ef9480b | 605 | { |
mluis | 5:62862ef9480b | 606 | MlmeReq_t mlmeReq; |
mluis | 5:62862ef9480b | 607 | |
mluis | 7:5077515c163b | 608 | // Disable TestMode and revert back to normal operation |
mluis | 7:5077515c163b | 609 | IsTxConfirmed = LORAWAN_CONFIRMED_MSG_ON; |
mluis | 7:5077515c163b | 610 | AppPort = LORAWAN_APP_PORT; |
mluis | 7:5077515c163b | 611 | AppDataSize = LORAWAN_APP_DATA_SIZE; |
mluis | 7:5077515c163b | 612 | ComplianceTest.DownLinkCounter = 0; |
mluis | 7:5077515c163b | 613 | ComplianceTest.Running = false; |
mluis | 7:5077515c163b | 614 | |
mluis | 7:5077515c163b | 615 | MibRequestConfirm_t mibReq; |
mluis | 7:5077515c163b | 616 | mibReq.Type = MIB_ADR; |
mluis | 7:5077515c163b | 617 | mibReq.Param.AdrEnable = LORAWAN_ADR_ON; |
mluis | 7:5077515c163b | 618 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 7:5077515c163b | 619 | LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON ); |
mluis | 5:62862ef9480b | 620 | mlmeReq.Type = MLME_JOIN; |
mluis | 5:62862ef9480b | 621 | mlmeReq.Req.Join.DevEui = DevEui; |
mluis | 5:62862ef9480b | 622 | mlmeReq.Req.Join.AppEui = AppEui; |
mluis | 5:62862ef9480b | 623 | mlmeReq.Req.Join.AppKey = AppKey; |
mluis | 7:5077515c163b | 624 | mlmeReq.Req.Join.NbTrials = 3; |
mluis | 5:62862ef9480b | 625 | LoRaMacMlmeRequest( &mlmeReq ); |
mluis | 5:62862ef9480b | 626 | DeviceState = DEVICE_STATE_SLEEP; |
mluis | 5:62862ef9480b | 627 | } |
mluis | 5:62862ef9480b | 628 | break; |
mluis | 7:5077515c163b | 629 | case 7: // (x) |
mluis | 7:5077515c163b | 630 | { |
mluis | 7:5077515c163b | 631 | if( mcpsIndication->BufferSize == 3 ) |
mluis | 7:5077515c163b | 632 | { |
mluis | 7:5077515c163b | 633 | MlmeReq_t mlmeReq; |
mluis | 7:5077515c163b | 634 | mlmeReq.Type = MLME_TXCW; |
mluis | 7:5077515c163b | 635 | mlmeReq.Req.TxCw.Timeout = ( uint16_t )( ( mcpsIndication->Buffer[1] << 8 ) | mcpsIndication->Buffer[2] ); |
mluis | 7:5077515c163b | 636 | LoRaMacMlmeRequest( &mlmeReq ); |
mluis | 7:5077515c163b | 637 | } |
mluis | 7:5077515c163b | 638 | else if( mcpsIndication->BufferSize == 7 ) |
mluis | 7:5077515c163b | 639 | { |
mluis | 7:5077515c163b | 640 | MlmeReq_t mlmeReq; |
mluis | 7:5077515c163b | 641 | mlmeReq.Type = MLME_TXCW_1; |
mluis | 7:5077515c163b | 642 | mlmeReq.Req.TxCw.Timeout = ( uint16_t )( ( mcpsIndication->Buffer[1] << 8 ) | mcpsIndication->Buffer[2] ); |
mluis | 7:5077515c163b | 643 | mlmeReq.Req.TxCw.Frequency = ( uint32_t )( ( mcpsIndication->Buffer[3] << 16 ) | ( mcpsIndication->Buffer[4] << 8 ) | mcpsIndication->Buffer[5] ) * 100; |
mluis | 7:5077515c163b | 644 | mlmeReq.Req.TxCw.Power = mcpsIndication->Buffer[6]; |
mluis | 7:5077515c163b | 645 | LoRaMacMlmeRequest( &mlmeReq ); |
mluis | 7:5077515c163b | 646 | } |
mluis | 7:5077515c163b | 647 | ComplianceTest.State = 1; |
mluis | 7:5077515c163b | 648 | } |
mluis | 7:5077515c163b | 649 | break; |
mluis | 0:45496a70a8a5 | 650 | default: |
mluis | 0:45496a70a8a5 | 651 | break; |
mluis | 0:45496a70a8a5 | 652 | } |
mluis | 0:45496a70a8a5 | 653 | } |
mluis | 0:45496a70a8a5 | 654 | break; |
mluis | 0:45496a70a8a5 | 655 | default: |
mluis | 0:45496a70a8a5 | 656 | break; |
mluis | 0:45496a70a8a5 | 657 | } |
mluis | 0:45496a70a8a5 | 658 | } |
mluis | 0:45496a70a8a5 | 659 | |
mluis | 0:45496a70a8a5 | 660 | // Switch LED 2 ON for each received downlink |
MGstic | 10:1a85ff06be1a | 661 | //Led2State = true; |
MGstic | 10:1a85ff06be1a | 662 | //Led2StateChanged = true; |
MGstic | 10:1a85ff06be1a | 663 | //TimerStart( &Led2Timer ); |
mluis | 0:45496a70a8a5 | 664 | DownlinkStatusUpdated = true; |
mluis | 0:45496a70a8a5 | 665 | } |
mluis | 0:45496a70a8a5 | 666 | |
mluis | 0:45496a70a8a5 | 667 | /*! |
mluis | 0:45496a70a8a5 | 668 | * \brief MLME-Confirm event function |
mluis | 0:45496a70a8a5 | 669 | * |
mluis | 3:3152aa75c58d | 670 | * \param [IN] mlmeConfirm - Pointer to the confirm structure, |
mluis | 0:45496a70a8a5 | 671 | * containing confirm attributes. |
mluis | 0:45496a70a8a5 | 672 | */ |
mluis | 3:3152aa75c58d | 673 | static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm ) |
mluis | 0:45496a70a8a5 | 674 | { |
mluis | 7:5077515c163b | 675 | switch( mlmeConfirm->MlmeRequest ) |
mluis | 0:45496a70a8a5 | 676 | { |
mluis | 7:5077515c163b | 677 | case MLME_JOIN: |
mluis | 0:45496a70a8a5 | 678 | { |
mluis | 7:5077515c163b | 679 | if( mlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) |
mluis | 0:45496a70a8a5 | 680 | { |
mluis | 0:45496a70a8a5 | 681 | // Status is OK, node has joined the network |
mluis | 0:45496a70a8a5 | 682 | IsNetworkJoinedStatusUpdate = true; |
mluis | 5:62862ef9480b | 683 | DeviceState = DEVICE_STATE_SEND; |
mluis | 7:5077515c163b | 684 | } |
mluis | 7:5077515c163b | 685 | else |
mluis | 7:5077515c163b | 686 | { |
mluis | 7:5077515c163b | 687 | // Join was not successful. Try to join again |
mluis | 7:5077515c163b | 688 | DeviceState = DEVICE_STATE_JOIN; |
mluis | 0:45496a70a8a5 | 689 | } |
mluis | 7:5077515c163b | 690 | break; |
mluis | 7:5077515c163b | 691 | } |
mluis | 7:5077515c163b | 692 | case MLME_LINK_CHECK: |
mluis | 7:5077515c163b | 693 | { |
mluis | 7:5077515c163b | 694 | if( mlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) |
mluis | 0:45496a70a8a5 | 695 | { |
mluis | 0:45496a70a8a5 | 696 | // Check DemodMargin |
mluis | 0:45496a70a8a5 | 697 | // Check NbGateways |
mluis | 0:45496a70a8a5 | 698 | if( ComplianceTest.Running == true ) |
mluis | 0:45496a70a8a5 | 699 | { |
mluis | 0:45496a70a8a5 | 700 | ComplianceTest.LinkCheck = true; |
mluis | 3:3152aa75c58d | 701 | ComplianceTest.DemodMargin = mlmeConfirm->DemodMargin; |
mluis | 3:3152aa75c58d | 702 | ComplianceTest.NbGateways = mlmeConfirm->NbGateways; |
mluis | 0:45496a70a8a5 | 703 | } |
mluis | 0:45496a70a8a5 | 704 | } |
mluis | 7:5077515c163b | 705 | break; |
mluis | 0:45496a70a8a5 | 706 | } |
mluis | 7:5077515c163b | 707 | default: |
mluis | 7:5077515c163b | 708 | break; |
mluis | 0:45496a70a8a5 | 709 | } |
mluis | 0:45496a70a8a5 | 710 | NextTx = true; |
mluis | 0:45496a70a8a5 | 711 | UplinkStatusUpdated = true; |
mluis | 0:45496a70a8a5 | 712 | } |
mluis | 0:45496a70a8a5 | 713 | |
MGstic | 10:1a85ff06be1a | 714 | /*###################################################################### |
mluis | 0:45496a70a8a5 | 715 | * Main application entry point. |
mluis | 0:45496a70a8a5 | 716 | */ |
MGstic | 10:1a85ff06be1a | 717 | |
MGstic | 10:1a85ff06be1a | 718 | |
MGstic | 10:1a85ff06be1a | 719 | |
mluis | 0:45496a70a8a5 | 720 | int main( void ) |
mluis | 0:45496a70a8a5 | 721 | { |
MGstic | 10:1a85ff06be1a | 722 | //####### INITIALISATION MODULE LORA ############ |
mluis | 0:45496a70a8a5 | 723 | LoRaMacPrimitives_t LoRaMacPrimitives; |
mluis | 0:45496a70a8a5 | 724 | LoRaMacCallback_t LoRaMacCallbacks; |
mluis | 0:45496a70a8a5 | 725 | MibRequestConfirm_t mibReq; |
mluis | 0:45496a70a8a5 | 726 | BoardInit( ); |
mluis | 0:45496a70a8a5 | 727 | SerialDisplayInit( ); |
mluis | 5:62862ef9480b | 728 | SerialDisplayUpdateEui( 5, DevEui ); |
mluis | 5:62862ef9480b | 729 | SerialDisplayUpdateEui( 6, AppEui ); |
mluis | 5:62862ef9480b | 730 | SerialDisplayUpdateKey( 7, AppKey ); |
mluis | 5:62862ef9480b | 731 | SerialDisplayUpdateNwkId( LORAWAN_NETWORK_ID ); |
mluis | 5:62862ef9480b | 732 | SerialDisplayUpdateDevAddr( DevAddr ); |
mluis | 5:62862ef9480b | 733 | SerialDisplayUpdateKey( 12, NwkSKey ); |
mluis | 5:62862ef9480b | 734 | SerialDisplayUpdateKey( 13, AppSKey ); |
MGstic | 10:1a85ff06be1a | 735 | DeviceState = DEVICE_STATE_INIT; |
MGstic | 10:1a85ff06be1a | 736 | |
MGstic | 10:1a85ff06be1a | 737 | //####### LIAISON SERIE ######## |
MGstic | 10:1a85ff06be1a | 738 | |
MGstic | 10:1a85ff06be1a | 739 | /*pc.baud(9600);// vitesse liaison série |
MGstic | 10:1a85ff06be1a | 740 | pc.format(8, SerialBase::None, 1); // format de la liaison*/ |
MGstic | 10:1a85ff06be1a | 741 | bouton.rise(&interruption_extern_bouton); //initialisation de l'interruption extern sur le bouton user |
MGstic | 10:1a85ff06be1a | 742 | |
MGstic | 10:1a85ff06be1a | 743 | //####### RTC INIT ######## |
MGstic | 10:1a85ff06be1a | 744 | set_time(1514764800); |
MGstic | 10:1a85ff06be1a | 745 | int config_s=0; |
mluis | 5:62862ef9480b | 746 | |
MGstic | 10:1a85ff06be1a | 747 | //####### VARIABLES ######## |
MGstic | 10:1a85ff06be1a | 748 | uint8_t compt=0; |
MGstic | 10:1a85ff06be1a | 749 | uint8_t c_send=TAB_MAX; |
mluis | 0:45496a70a8a5 | 750 | |
mluis | 0:45496a70a8a5 | 751 | while( 1 ) |
mluis | 0:45496a70a8a5 | 752 | { |
MGstic | 10:1a85ff06be1a | 753 | if(1) |
mluis | 0:45496a70a8a5 | 754 | { |
MGstic | 10:1a85ff06be1a | 755 | SerialRxProcess( ); |
MGstic | 10:1a85ff06be1a | 756 | if( IsNetworkJoinedStatusUpdate == true ) |
MGstic | 10:1a85ff06be1a | 757 | { |
MGstic | 10:1a85ff06be1a | 758 | IsNetworkJoinedStatusUpdate = false; |
MGstic | 10:1a85ff06be1a | 759 | mibReq.Type = MIB_NETWORK_JOINED; |
MGstic | 10:1a85ff06be1a | 760 | LoRaMacMibGetRequestConfirm( &mibReq ); |
MGstic | 10:1a85ff06be1a | 761 | SerialDisplayUpdateNetworkIsJoined( mibReq.Param.IsNetworkJoined ); |
MGstic | 10:1a85ff06be1a | 762 | } |
MGstic | 10:1a85ff06be1a | 763 | |
MGstic | 10:1a85ff06be1a | 764 | if( UplinkStatusUpdated == true ) |
MGstic | 10:1a85ff06be1a | 765 | { |
MGstic | 10:1a85ff06be1a | 766 | UplinkStatusUpdated = false; |
MGstic | 10:1a85ff06be1a | 767 | SerialDisplayUpdateUplink( LoRaMacUplinkStatus.Acked, LoRaMacUplinkStatus.Datarate, LoRaMacUplinkStatus.UplinkCounter, LoRaMacUplinkStatus.Port, LoRaMacUplinkStatus.Buffer, LoRaMacUplinkStatus.BufferSize ); |
MGstic | 10:1a85ff06be1a | 768 | } |
MGstic | 10:1a85ff06be1a | 769 | if( DownlinkStatusUpdated == true ) |
MGstic | 10:1a85ff06be1a | 770 | { |
MGstic | 10:1a85ff06be1a | 771 | DownlinkStatusUpdated = false; |
MGstic | 10:1a85ff06be1a | 772 | //SerialDisplayUpdateLedState( 2, Led2State ); |
MGstic | 10:1a85ff06be1a | 773 | SerialDisplayUpdateDownlink( LoRaMacDownlinkStatus.RxData, LoRaMacDownlinkStatus.Rssi, LoRaMacDownlinkStatus.Snr, LoRaMacDownlinkStatus.DownlinkCounter, LoRaMacDownlinkStatus.Port, LoRaMacDownlinkStatus.Buffer, LoRaMacDownlinkStatus.BufferSize ); |
MGstic | 10:1a85ff06be1a | 774 | } |
MGstic | 10:1a85ff06be1a | 775 | |
mluis | 0:45496a70a8a5 | 776 | } |
MGstic | 10:1a85ff06be1a | 777 | |
MGstic | 10:1a85ff06be1a | 778 | //time_t seconds = time(NULL); |
MGstic | 10:1a85ff06be1a | 779 | //sprintf(data_packet[compt].heure,"%s",ctime(&seconds));// copie de la valeur de la RTC en cours dans le tableau de structure data_packet |
MGstic | 10:1a85ff06be1a | 780 | |
MGstic | 10:1a85ff06be1a | 781 | data_packet[0].heure=heuretest; |
MGstic | 10:1a85ff06be1a | 782 | data_packet[0].masse=poidstest; |
MGstic | 10:1a85ff06be1a | 783 | poidstest++; |
MGstic | 10:1a85ff06be1a | 784 | heuretest++; |
MGstic | 10:1a85ff06be1a | 785 | |
MGstic | 10:1a85ff06be1a | 786 | //printf("%d\r\n",compt); |
mluis | 0:45496a70a8a5 | 787 | |
MGstic | 10:1a85ff06be1a | 788 | wait(1); |
MGstic | 10:1a85ff06be1a | 789 | switch (etat) |
MGstic | 10:1a85ff06be1a | 790 | { |
MGstic | 10:1a85ff06be1a | 791 | |
MGstic | 10:1a85ff06be1a | 792 | case 0: //bouton non enclenché |
MGstic | 10:1a85ff06be1a | 793 | { |
MGstic | 10:1a85ff06be1a | 794 | SerialDisplayRTCactive(etat); |
MGstic | 10:1a85ff06be1a | 795 | SerialDisplayTIME(tabd); |
MGstic | 10:1a85ff06be1a | 796 | time_t seconds = time(NULL); |
MGstic | 10:1a85ff06be1a | 797 | switch( DeviceState ) |
MGstic | 10:1a85ff06be1a | 798 | { |
mluis | 0:45496a70a8a5 | 799 | |
MGstic | 10:1a85ff06be1a | 800 | case DEVICE_STATE_INIT: |
MGstic | 10:1a85ff06be1a | 801 | { |
MGstic | 10:1a85ff06be1a | 802 | LoRaMacPrimitives.MacMcpsConfirm = McpsConfirm; |
MGstic | 10:1a85ff06be1a | 803 | LoRaMacPrimitives.MacMcpsIndication = McpsIndication; |
MGstic | 10:1a85ff06be1a | 804 | LoRaMacPrimitives.MacMlmeConfirm = MlmeConfirm; |
MGstic | 10:1a85ff06be1a | 805 | LoRaMacCallbacks.GetBatteryLevel = BoardGetBatteryLevel; |
MGstic | 10:1a85ff06be1a | 806 | LoRaMacInitialization( &LoRaMacPrimitives, &LoRaMacCallbacks ); |
MGstic | 10:1a85ff06be1a | 807 | TimerInit( &TxNextPacketTimer, OnTxNextPacketTimerEvent ); |
mluis | 3:3152aa75c58d | 808 | |
MGstic | 10:1a85ff06be1a | 809 | mibReq.Type = MIB_ADR; |
MGstic | 10:1a85ff06be1a | 810 | mibReq.Param.AdrEnable = LORAWAN_ADR_ON; |
MGstic | 10:1a85ff06be1a | 811 | LoRaMacMibSetRequestConfirm( &mibReq ); |
MGstic | 10:1a85ff06be1a | 812 | mibReq.Type = MIB_PUBLIC_NETWORK; |
MGstic | 10:1a85ff06be1a | 813 | mibReq.Param.EnablePublicNetwork = LORAWAN_PUBLIC_NETWORK; |
MGstic | 10:1a85ff06be1a | 814 | LoRaMacMibSetRequestConfirm( &mibReq ); |
MGstic | 10:1a85ff06be1a | 815 | LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON ); |
MGstic | 10:1a85ff06be1a | 816 | SerialDisplayUpdateDutyCycle( LORAWAN_DUTYCYCLE_ON ); |
MGstic | 10:1a85ff06be1a | 817 | |
mluis | 5:62862ef9480b | 818 | |
MGstic | 10:1a85ff06be1a | 819 | LoRaMacChannelAdd( 3, ( ChannelParams_t )LC4 ); |
MGstic | 10:1a85ff06be1a | 820 | LoRaMacChannelAdd( 4, ( ChannelParams_t )LC5 ); |
MGstic | 10:1a85ff06be1a | 821 | LoRaMacChannelAdd( 5, ( ChannelParams_t )LC6 ); |
MGstic | 10:1a85ff06be1a | 822 | LoRaMacChannelAdd( 6, ( ChannelParams_t )LC7 ); |
MGstic | 10:1a85ff06be1a | 823 | LoRaMacChannelAdd( 7, ( ChannelParams_t )LC8 ); |
MGstic | 10:1a85ff06be1a | 824 | LoRaMacChannelAdd( 8, ( ChannelParams_t )LC9 ); |
MGstic | 10:1a85ff06be1a | 825 | LoRaMacChannelAdd( 9, ( ChannelParams_t )LC10 ); |
mluis | 7:5077515c163b | 826 | |
MGstic | 10:1a85ff06be1a | 827 | mibReq.Type = MIB_RX2_DEFAULT_CHANNEL; |
MGstic | 10:1a85ff06be1a | 828 | mibReq.Param.Rx2DefaultChannel = ( Rx2ChannelParams_t ){ 869525000, DR_3 }; |
MGstic | 10:1a85ff06be1a | 829 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 3:3152aa75c58d | 830 | |
MGstic | 10:1a85ff06be1a | 831 | mibReq.Type = MIB_RX2_CHANNEL; |
MGstic | 10:1a85ff06be1a | 832 | mibReq.Param.Rx2Channel = ( Rx2ChannelParams_t ){ 869525000, DR_3 }; |
MGstic | 10:1a85ff06be1a | 833 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 834 | |
MGstic | 10:1a85ff06be1a | 835 | SerialDisplayUpdateActivationMode( OVER_THE_AIR_ACTIVATION ); |
MGstic | 10:1a85ff06be1a | 836 | SerialDisplayUpdateAdr( LORAWAN_ADR_ON ); |
MGstic | 10:1a85ff06be1a | 837 | SerialDisplayUpdatePublicNetwork( LORAWAN_PUBLIC_NETWORK ); |
MGstic | 10:1a85ff06be1a | 838 | |
MGstic | 10:1a85ff06be1a | 839 | LoRaMacDownlinkStatus.DownlinkCounter = 0; |
mluis | 0:45496a70a8a5 | 840 | |
MGstic | 10:1a85ff06be1a | 841 | DeviceState = DEVICE_STATE_JOIN; |
MGstic | 10:1a85ff06be1a | 842 | break; |
MGstic | 10:1a85ff06be1a | 843 | } |
MGstic | 10:1a85ff06be1a | 844 | case DEVICE_STATE_JOIN: |
MGstic | 10:1a85ff06be1a | 845 | { |
MGstic | 10:1a85ff06be1a | 846 | mibReq.Type = MIB_NET_ID; |
MGstic | 10:1a85ff06be1a | 847 | mibReq.Param.NetID = LORAWAN_NETWORK_ID; |
MGstic | 10:1a85ff06be1a | 848 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 849 | |
MGstic | 10:1a85ff06be1a | 850 | mibReq.Type = MIB_DEV_ADDR; |
MGstic | 10:1a85ff06be1a | 851 | mibReq.Param.DevAddr = DevAddr; |
MGstic | 10:1a85ff06be1a | 852 | LoRaMacMibSetRequestConfirm( &mibReq ); |
MGstic | 10:1a85ff06be1a | 853 | |
MGstic | 10:1a85ff06be1a | 854 | mibReq.Type = MIB_NWK_SKEY; |
MGstic | 10:1a85ff06be1a | 855 | mibReq.Param.NwkSKey = NwkSKey; |
MGstic | 10:1a85ff06be1a | 856 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 857 | |
MGstic | 10:1a85ff06be1a | 858 | mibReq.Type = MIB_APP_SKEY; |
MGstic | 10:1a85ff06be1a | 859 | mibReq.Param.AppSKey = AppSKey; |
MGstic | 10:1a85ff06be1a | 860 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 861 | |
MGstic | 10:1a85ff06be1a | 862 | mibReq.Type = MIB_NETWORK_JOINED; |
MGstic | 10:1a85ff06be1a | 863 | mibReq.Param.IsNetworkJoined = true; |
MGstic | 10:1a85ff06be1a | 864 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 0:45496a70a8a5 | 865 | |
MGstic | 10:1a85ff06be1a | 866 | DeviceState = DEVICE_STATE_SEND; |
MGstic | 10:1a85ff06be1a | 867 | IsNetworkJoinedStatusUpdate = true; |
MGstic | 10:1a85ff06be1a | 868 | break; |
MGstic | 10:1a85ff06be1a | 869 | } |
MGstic | 10:1a85ff06be1a | 870 | case DEVICE_STATE_SEND: |
MGstic | 10:1a85ff06be1a | 871 | { |
MGstic | 10:1a85ff06be1a | 872 | if( NextTx == true ) |
MGstic | 10:1a85ff06be1a | 873 | { |
MGstic | 10:1a85ff06be1a | 874 | SerialDisplayUpdateUplinkAcked( false ); |
MGstic | 10:1a85ff06be1a | 875 | SerialDisplayUpdateDonwlinkRxData( false ); |
MGstic | 10:1a85ff06be1a | 876 | |
MGstic | 10:1a85ff06be1a | 877 | ///prepare tx |
MGstic | 10:1a85ff06be1a | 878 | PrepareTxFrame( AppPort,data_packet[0] ); |
MGstic | 10:1a85ff06be1a | 879 | NextTx = SendFrame( ); |
MGstic | 10:1a85ff06be1a | 880 | |
MGstic | 10:1a85ff06be1a | 881 | |
MGstic | 10:1a85ff06be1a | 882 | } |
MGstic | 10:1a85ff06be1a | 883 | if( ComplianceTest.Running == true ) |
MGstic | 10:1a85ff06be1a | 884 | { |
MGstic | 10:1a85ff06be1a | 885 | // Schedule next packet transmission |
MGstic | 10:1a85ff06be1a | 886 | TxDutyCycleTime = 1000; // 5000 ms |
MGstic | 10:1a85ff06be1a | 887 | } |
MGstic | 10:1a85ff06be1a | 888 | else |
MGstic | 10:1a85ff06be1a | 889 | { |
MGstic | 10:1a85ff06be1a | 890 | // Schedule next packet transmission |
MGstic | 10:1a85ff06be1a | 891 | TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND ); |
MGstic | 10:1a85ff06be1a | 892 | } |
MGstic | 10:1a85ff06be1a | 893 | DeviceState = DEVICE_STATE_CYCLE; |
MGstic | 10:1a85ff06be1a | 894 | break; |
MGstic | 10:1a85ff06be1a | 895 | } |
MGstic | 10:1a85ff06be1a | 896 | case DEVICE_STATE_CYCLE: |
MGstic | 10:1a85ff06be1a | 897 | { |
MGstic | 10:1a85ff06be1a | 898 | DeviceState = DEVICE_STATE_SLEEP; |
MGstic | 10:1a85ff06be1a | 899 | // Schedule next packet transmission |
MGstic | 10:1a85ff06be1a | 900 | TimerSetValue( &TxNextPacketTimer, TxDutyCycleTime ); |
MGstic | 10:1a85ff06be1a | 901 | TimerStart( &TxNextPacketTimer ); |
MGstic | 10:1a85ff06be1a | 902 | break; |
MGstic | 10:1a85ff06be1a | 903 | } |
MGstic | 10:1a85ff06be1a | 904 | case DEVICE_STATE_SLEEP: |
MGstic | 10:1a85ff06be1a | 905 | { |
MGstic | 10:1a85ff06be1a | 906 | |
MGstic | 10:1a85ff06be1a | 907 | // Wake up through events |
MGstic | 10:1a85ff06be1a | 908 | break; |
MGstic | 10:1a85ff06be1a | 909 | } |
MGstic | 10:1a85ff06be1a | 910 | default: |
MGstic | 10:1a85ff06be1a | 911 | { |
MGstic | 10:1a85ff06be1a | 912 | DeviceState = DEVICE_STATE_INIT; |
MGstic | 10:1a85ff06be1a | 913 | break; |
MGstic | 10:1a85ff06be1a | 914 | } |
MGstic | 10:1a85ff06be1a | 915 | |
MGstic | 10:1a85ff06be1a | 916 | } |
MGstic | 10:1a85ff06be1a | 917 | break; |
MGstic | 10:1a85ff06be1a | 918 | } |
MGstic | 10:1a85ff06be1a | 919 | case 1 : //bouton enclenché |
MGstic | 10:1a85ff06be1a | 920 | { |
MGstic | 10:1a85ff06be1a | 921 | SerialDisplayRTCactive(etat); |
MGstic | 10:1a85ff06be1a | 922 | saisie_serie(tabd); |
MGstic | 10:1a85ff06be1a | 923 | SerialDisplayTIME(tabd); |
MGstic | 10:1a85ff06be1a | 924 | config_s=unix_timestamp(tabd); |
MGstic | 10:1a85ff06be1a | 925 | set_time(config_s); |
MGstic | 10:1a85ff06be1a | 926 | //printf( "%d\r\n",etat); |
MGstic | 10:1a85ff06be1a | 927 | etat=0; |
MGstic | 10:1a85ff06be1a | 928 | break; |
MGstic | 10:1a85ff06be1a | 929 | } |
mluis | 0:45496a70a8a5 | 930 | } |
MGstic | 10:1a85ff06be1a | 931 | |
MGstic | 10:1a85ff06be1a | 932 | |
MGstic | 10:1a85ff06be1a | 933 | |
mluis | 0:45496a70a8a5 | 934 | } |
mluis | 0:45496a70a8a5 | 935 | } |
MGstic | 10:1a85ff06be1a | 936 |