diff --git a/main/lorawan.h b/main/lorawan.h index a546e81..adfc609 100644 --- a/main/lorawan.h +++ b/main/lorawan.h @@ -64,21 +64,25 @@ class LoRaWANnode // uint8_t TxMAC[16]; // uint8_t TxMACs; - static const size_t MaxPacketSize = 64; // [bytes] + static const size_t MaxPacketSize = 63; // [bytes] uint8_t Packet[MaxPacketSize]; // generic packet for storage/processing + uint8_t TxBattLevel; // battery level to be transmitted in the DevStatusAns + uint8_t TxOptLen; + uint8_t TxOpt[15]; // MAC commands/options to be transmitted + public: - LoRaWANnode() { Reset(); } + LoRaWANnode() { Reset(); TxOptLen=0; TxBattLevel=0xFF; } void Reset(void) { State=0; DevNonce=0; JoinNonce=0; LastTx=0; TxCount=0; LastRx=0; RxCount=0; RxSilent=0; Flags=0; LastSaved=0; setCRC(); } - void Reset(uint64_t MAC, uint8_t *AppKey=0) + void Reset(uint64_t MAC, uint8_t *NewKey=0) { AppEUI=0x70B3D57ED0035895; // set OGN application DevEUI=MAC; // set DevEUI from MAC - if(AppKey) memcpy(this->AppKey, AppKey, 16); // set the AppKey + if(NewKey) memcpy(AppKey, NewKey, 16); // set the AppKey Reset(); } // reset to not-joined state void Disconnect(void) @@ -155,8 +159,8 @@ class LoRaWANnode int procJoinAccept(const RFM_LoRa_RxPacket &RxPacket) { int Ret=procJoinAccept(RxPacket.Byte, RxPacket.Len); if(Ret<0) return Ret; - RxSNR = RxPacket.SNR; - RxRSSI = RxPacket.RSSI; + RxSNR = RxPacket.SNR; // store the SNR of the join-accept + RxRSSI = RxPacket.RSSI; // store the RSSI return Ret; } int procJoinAccept(const uint8_t *PktData, int PktLen) // process Join-Accept packet (5sec after Join-Request) @@ -175,7 +179,8 @@ class LoRaWANnode RxDelay = Packet[12]; State = 2; // State = accepted on network UpCount = 0; - DnCount = 0; + DnCount = 0xFFFFFFFF; + TxOptLen = 0; #ifdef WITH_PRINTF printf("Accept[%d] ", PktLen-4); for(int Idx=0; Idx>5; if(Type!=3 && Type!=5) return -1; // Frame Type: 3=unconfirmed data downlink, 5=confirmed data downlink + uint8_t Type = PktData[0]>>5; // Frame Type + if(Type!=3 && Type!=5) return -1; // Frame Type: 3=unconfirmed data downlink, 5=confirmed data downlink uint32_t Addr=readInt(PktData+1, 4); // device address if(Addr!=DevAddr) return 0; // check if packet is for us (it could be for somebody else) uint8_t Ctrl = PktData[5]; // Frame Control: ADR | RFU | ACK | FPending | FOptLen[4] @@ -253,12 +262,34 @@ class LoRaWANnode // } return DataLen; } - void procRxOpt(const uint8_t *Opt, uint8_t Len) // process the options - { } - // { Format_String(CONS_UART_Write, "LoRaWAN Opt: "); - // for(uint8_t Idx=0; Idx>2)&0x3F; // Rx SNR + continue; } + break; } +// #ifdef WITH_PRINTF + printf("RxOpt: [%d] ", OptLen); + for(int Idx=0; Idx [%d] ", TxOptLen); + for(int Idx=0; Idx