alan broad
/
carbon_v5_arm_studio
arm studio build
Revision 17:74d60177c6b6, committed 2019-01-25
- Comitter:
- alan1974
- Date:
- Fri Jan 25 01:46:26 2019 +0000
- Parent:
- 16:5cc10d804d49
- Child:
- 18:d95e1a2c4303
- Commit message:
- success full mcast of blestack code to xdot (but no xfr to proc yet)
Changed in this revision
--- a/inc/RadioEvent.h Sun Jan 20 15:19:57 2019 +0000 +++ b/inc/RadioEvent.h Fri Jan 25 01:46:26 2019 +0000 @@ -34,37 +34,38 @@ } - /** - * Fired when radio has received a packet, packet is not validated - * chk's if downlink counter is >= getDownLinkCounter() => if not, something has reset the donwnlink frame counter -> should not happen! - * @param payload received bytes - * @param size number of received bytes - * @param rssi of received packet - * @param snr of received packet - * @param ctrl Downlink control field of packet - * @param slot rx window packet was received - * payload bytes 6-7 are downlink counter - */ - virtual void RxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot){ - int i; - int32_t fCntDown = 0; - uint32_t downlinkcounter = dot->getDownLinkCounter(); //save frame counters before switching - bRxDone = true; //callback entered - printf("RxDone payload:"); - for (i=0; i< size;i++)printf(" %x",payload[i]); - - fCntDown = (payload[7] << 8) + payload[6]; - if (fCntDown < dot->getDownLinkCounter())bDownLinkCntrFail = true;; - printf(" Downlink counter %d DownLinkCntFail: %x\n\r",fCntDown,bDownLinkCntrFail); - } +/** + * Fired when radio has received a packet, packet is not validated + * chk's if downlink counter is >= getDownLinkCounter() => if not, something has reset the donwnlink frame counter -> should not happen! + * @param payload received bytes + * @param size number of received bytes + * @param rssi of received packet + * @param snr of received packet + * @param ctrl Downlink control field of packet + * @param slot rx window packet was received + * payload bytes 6-7 are downlink counter + */ + virtual void RxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot){ + int i; + int32_t fCntDown = 0; + uint32_t downlinkcounter = dot->getDownLinkCounter(); + bRxDone = true; //callback entered + fCntDown = (payload[7] << 8) + payload[6]; + if (fCntDown < downlinkcounter){ + printf("\r\nRX FRAME ERR: RxDone payload:"); + for (i=0; i< size;i++)printf(" %x",payload[i]); + bDownLinkCntrFail = true;; + printf(" Downlink counter:%d DownLinkCntFail:%d\n\r",downlinkcounter,fCntDown); + } + } + - - /*! - * MAC layer event callback prototype. - * - * \param [IN] flags Bit field indicating the MAC events occurred - * \param [IN] info Details about MAC events occurred - */ +/*! + * MAC layer event callback prototype. + * + * \param [IN] flags Bit field indicating the MAC events occurred + * \param [IN] info Details about MAC events occurred +*/ virtual void MacEvent(LoRaMacEventFlags* flags, LoRaMacEventInfo* info) { //printf("DRT DRT DRT DRT. this is a test. Bits.Rx = %d\r\n", flags->Bits.Rx); @@ -120,12 +121,9 @@ { // printf("Rx Data %d = %x\r\n", i, info->RxBuffer[i]); received_packet.push_back(info->RxBuffer[i]); - } + } + printf(" Rx incoming data: %s\r\n", mts::Text::bin2hexString(info->RxBuffer,info->RxBufferSize).c_str()); downstream_packet_received = true; - //printf(" ----------------------------downstream_packet_received %d\n\r",downstream_packet_received); - // print RX data as string - //std::string rx((const char*)info->RxBuffer, info->RxBufferSize); - //printf("Rx data: %s\r\n", rx.c_str()); port = info->RxPort; } // if info->RxBufferSize >
--- a/inc/commI2C.h Sun Jan 20 15:19:57 2019 +0000 +++ b/inc/commI2C.h Fri Jan 25 01:46:26 2019 +0000 @@ -134,6 +134,7 @@ //-------------------------------------------------------------------------- //nvm ptks for ABP creds ---> REMOVE ??????????? //-------------------------------------------------------------------------- +/* //upstream pkt struc typedef struct { uint8_t cmd; //cmd received from proc @@ -141,6 +142,7 @@ uint8_t nvm_option; //read,write,restore nvmABP nvmData; }pkt_setnvmABPup; + //dwnstream pkt struc typedef struct { uint8_t ack; //ack header response @@ -149,7 +151,7 @@ uint8_t bChkSumOK; nvmABP nvmData; }pkt_setnvmABPdwn; - +*/ //-------------------------------------------------------------------------- //ptks for class A/B radio change //-------------------------------------------------------------------------- @@ -200,7 +202,7 @@ void i2c_proc_init(); -void i2c_wait4wake_lo(void); +//void i2c_wait4wake_lo(void); void i2c_pulse_wake(void); I2C_XFR_TYPE i2c_proc_comm();
--- a/inc/global.h Sun Jan 20 15:19:57 2019 +0000 +++ b/inc/global.h Fri Jan 25 01:46:26 2019 +0000 @@ -37,23 +37,16 @@ bool bLogOutputOn; //true if log output on uint8_t chksum; //chk to make sure nvm memory ok }nvm; -//NOT USED !!!!!!!!!! REMOVE -//struc to set nvm params for multicast ABP -----> NOT USED ????? -typedef struct { - bool bClassC; //true if switch from class C from A, else A from C - uint8_t key_nsk[16]; //ABP network seesion key - uint8_t key_aps[16]; //ABP application session key - uint8_t devAdr[4]; //device address - uint8_t chksum; //chk to make sure nvm memory ok - }nvmABP; typedef struct { - bool bClassC; //true if switch from class C from A, else A from C + bool bClassC; //true: switch from class C from A, else A from C + bool bListen4Multicast; //if enable xdot listen only for multicast + uint16_t maxMulticastSessionTime; //maximum time to listen for multicast pkts before going back to class A uint8_t key_nsk[16]; //ABP network seesion key uint8_t key_aps[16]; //ABP application session key uint8_t devAdr[4]; //device address - }class_switch; +}class_switch; #endif \ No newline at end of file
--- a/inc/wbit_util.h Sun Jan 20 15:19:57 2019 +0000 +++ b/inc/wbit_util.h Fri Jan 25 01:46:26 2019 +0000 @@ -5,14 +5,14 @@ void printRadioCfg(); void printNmvData(nvm *pNvm); -void printNvmABPData(nvmABP *pNvmABP); +//void printNvmABPData(nvmABP *pNvmABP); bool nvmWrite(nvm *pNvm); bool nvmRestore(nvm *pNvm); bool nvmRead(nvm *pNvm); -bool nvmReadABP(nvmABP *pNvmABP); -bool nvmWriteABP(nvmABP *pNvmABP); +//bool nvmReadABP(nvmABP *pNvmABP); +//bool nvmWriteABP(nvmABP *pNvmABP); uint8_t join_network_attempts_wbit(); bool join_network_wbit(uint8_t nmbAttempts); //waterbit specific because Multitech doesn't seem to know what a forever loop will do to power consumption
--- a/src/commI2C.cpp Sun Jan 20 15:19:57 2019 +0000 +++ b/src/commI2C.cpp Fri Jan 25 01:46:26 2019 +0000 @@ -11,7 +11,6 @@ extern bool verbose; //#define TEST - //============================================================================== // i2c_proc_init // - init i2c comm to proc @@ -20,17 +19,16 @@ { slave.frequency(100000); // added DRT NOT NEEDED BY SLAVE????,asb, need this ???? uint8_t slave_address = 0xA0; //PROC code uses 7bit address shifted by one so 0xA0 (xdot) => 0x50 (PROC) - slave.address(slave_address); - //set wake hi - + slave.address(slave_address); return; } //============================================================================== // i2c_wait4wake_lo // - wait for the wake signal from proc to go low // NEEDS TO BE CORRECTED, THIS WAITS FOR A HI THEN A LOW !!!! -//============================================================================== -#ifdef NOT_USED +//============================================================================== +/* +//#ifdef NOT_USED void i2c_wait4wake_lo(void){ wake.input(); // if(verbose)pc.printf("\n\r waiting for wake to go hi %d",wake); @@ -54,7 +52,8 @@ return; } -#endif +//#endif +*/ //============================================================================== // i2c_pulse_wake // - pulse the wake signal to tell proc that xdot ready for i2c xfr
--- a/src/main.cpp Sun Jan 20 15:19:57 2019 +0000 +++ b/src/main.cpp Fri Jan 25 01:46:26 2019 +0000 @@ -9,14 +9,14 @@ #include "ChannelPlans.h" #include "Lora.h" -bool verbose = true; -bool bRxDone = false; //true if callback function RxDone() triggered -bool bDownLinkCntrFail = false; //true if callback function RxDone() triggered and bad downlink frame count -bool bClassA = true; //false => Class C multicast mode - +bool verbose = true; +bool bRxDone = false; //true if callback function RxDone() triggered +bool bDownLinkCntrFail = false; //true if callback function RxDone() triggered and bad downlink frame count +bool bListen4Multicast; +uint16_t maxMulticastSessionTime = 0; //nvm storage params -nvm nvmData; -nvm *pNvmData = &nvmData; +nvm nvmData; +nvm *pNvmData = &nvmData; @@ -194,7 +194,7 @@ } else{ printNmvData(pNvmData); - dot->setLogLevel((verbose) ? mts::MTSLog::TRACE_LEVEL : mts::MTSLog::TRACE_LEVEL); // TRACE_LEVEL , INFO_LEVEL + //dot->setLogLevel((verbose) ? mts::MTSLog::TRACE_LEVEL : mts::MTSLog::TRACE_LEVEL); // TRACE_LEVEL , INFO_LEVEL } // getStandbyFlag() should return the state of the standby flag directly from the processor @@ -255,15 +255,17 @@ gpio1 =0; #endif wait_us(wait_before_sleep_usec); //wait for i2c to complete data transfer before sleeping -//#ifdef NOTYET - if (!bClassA){ - if(verbose)pc.printf("\n\r changed to class C, LISTEN ONLY \r\n"); - wait(1800); // CLASS C MODE LISTEN ONLY !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - } -//#endif - else{ - sleep_wake_interrupt_only(deep_sleep); //sleep until rising edge of wake signal from proc - } + + if (bListen4Multicast){ //in ClassC and receiving multicst pkt, stay here until timeout or unitl ????? + if(verbose)pc.printf("\n\r changed to class C, LISTEN ONLY,for max sec:%d\r\n",maxMulticastSessionTime); + uint16_t wait_cnt = maxMulticastSessionTime; + while(wait_cnt > 0){ + wait_cnt--; + wait(1); + } + } + sleep_wake_interrupt_only(deep_sleep); //sleep until rising edge of wake signal from proc + #ifdef GPIO_ENABLE gpio1 =1; @@ -325,12 +327,13 @@ joined = join_network_wbit(pUp->joinAttemps); //try joinAttemps times to join network pAck->joinAttempts = join_network_attempts_wbit(); //# of join attemps made pAck->mdot_ret = dot->send(upstream_packet); //<--------------------------------------- extra xmit ??????????????? + save_OTAA_session_keys(); if (!joined) if(verbose)pc.printf("\r\n----------- FAILED TO JOIN...GIVING UP\r\n"); // join network if not joined - else { - save_OTAA_session_keys(); - plan.SetRx2DatarateIndex(8); //LORIOT FIX FOR RX2 & OTA !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ---> doesn't work here???? - } + //else { + // save_OTAA_session_keys(); + // plan.SetRx2DatarateIndex(8); //LORIOT FIX FOR RX2 & OTA !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ---> doesn't work here???? + //} } if (joined) { @@ -458,7 +461,7 @@ for (i=0; i< 4;i++) peui->verLvlData[i] = ver_level[i]; peui->dataLen = sizeof(pkt_eui)-3; //size of struc minus first 3 bytes if(verbose)pc.printf("\n\r eui data length: %d",peui->dataLen); - break; + break; case XDOT_CMD_NVM: if(verbose)pc.printf("\n\r proc cmd: NVM OTAA"); pkt_setnvmup *pUpNvm = (pkt_setnvmup*)&buf_rcv[0]; @@ -473,37 +476,24 @@ if (nvmRead(&pDwnNvm->nvmData)) pDwnNvm->bChkSumOK = 1; printNmvData(&pDwnNvm->nvmData); - break; - case XDOT_CMD_NVM_ABP: - if(verbose)pc.printf("\n\r proc cmd: NVM ABP"); - pkt_setnvmABPup *pUpNvmABP = (pkt_setnvmABPup*)&buf_rcv[0]; - pkt_setnvmABPdwn *pDwnNvmABP= (pkt_setnvmABPdwn*)&buf_xmt[0]; - pDwnNvmABP->ack = I2C_ACK_PROC; - pDwnNvmABP->cmd = XDOT_CMD_NVM_ABP; - pDwnNvmABP->dataLen = sizeof(nvmABP)-2; - if (pUpNvmABP->nvm_option == XDOT_NVM_SET) nvmWriteABP(&pUpNvmABP->nvmData); - - pDwnNvmABP->bChkSumOK = 0; - if (nvmReadABP(&pDwnNvmABP->nvmData)) - pDwnNvmABP->bChkSumOK = 1; - printNvmABPData(&pDwnNvmABP->nvmData); - - break; - + break; case XDOT_CMD_SET_RADIO_CLASS: //multicast_change_class A or C (change only after a join!) if(verbose)pc.printf("\n\r proc cmd: change radio class\r\n"); pkt_setClassUp *pUpSetClass = (pkt_setClassUp*)&buf_rcv[0]; pkt_setClassDwn *pDwnSetClass = (pkt_setClassDwn*)&buf_xmt[0]; pDwnSetClass->ack = I2C_ACK_PROC; pDwnSetClass->cmd = XDOT_CMD_SET_RADIO_CLASS; - pDwnSetClass->dataLen = sizeof(class_switch)-2; - bool bOk = multicast_change_class(&pUpSetClass->classData); - if (bOk && pUpSetClass->classData.bClassC) bClassA = false; + pDwnSetClass->dataLen = sizeof(class_switch)-2; + bool bOk = multicast_change_class(&pUpSetClass->classData); + if (bOk && pUpSetClass->classData.bListen4Multicast){ //go into listen only mode for multicast pkts? + bListen4Multicast = true;; + maxMulticastSessionTime = pUpSetClass->classData.maxMulticastSessionTime; + } pDwnSetClass->bSwitched = bOk; break; - case XDOT_CMD_SET_NTWKSESS: //read or write network seesion to xdot flash + case XDOT_CMD_SET_NTWKSESS: //read or write network session to xdot flash bool bWriteSession = (bool)buf_rcv[1]; if (bWriteSession){ if(verbose)pc.printf("\n\r proc cmd writing network sesion to flash"); @@ -518,12 +508,14 @@ pktwrk->cmd = XDOT_CMD_SET_NTWKSESS; pktwrk->bSetNetwrk = (uint8_t)bWriteSession; break; +/* case XDOT_CMD_SET_KEY_X: if(verbose)pc.printf("\n\r proc cmd: this command not used\r\n"); wait_ms(I2C_MIN_WAIT_DELAY); buf_xmt[0] = I2C_ACK_PROC; buf_xmt[1] = XDOT_CMD_SET_KEY_X; break; +*/ case XDOT_CMD_GATEWAY_PING: if(verbose)pc.printf("\n\r proc cmd: xmit gateway ping\r\n"); pkt_ping *pPing = (pkt_ping*)&buf_xmt[0];
--- a/src/multicast.cpp Sun Jan 20 15:19:57 2019 +0000 +++ b/src/multicast.cpp Fri Jan 25 01:46:26 2019 +0000 @@ -26,11 +26,11 @@ uint8_t frags_size = 0; //size of each frag to be sent uint32_t frag_missd = 0; //======================================================================================================== -//save_OTAA_session -// save OTAA session parameters +// save_OTAA_session session parameters //======================================================================================================== void save_OTAA_session_keys() { + printf("\r\n saving OTAA session keys --------------------------------- \r\n"); netwrk_address_OTAA = dot->getNetworkAddress(); logInfo(" OTAA devAddr %s", mts::Text::bin2hexString(netwrk_address_OTAA).c_str()); netwrk_session_key_OTAA = dot->getNetworkSessionKey(); @@ -54,10 +54,12 @@ printf("\r\n cannot change radio class unless already joined"); return false; //don't switch if not joined } + printf("\r\n switching to class C \r\n"); downcounter_OTAA = dot->getDownLinkCounter(); //save frame counters before switching upcounter_OTAA = dot->getUpLinkCounter(); - dot->setDownLinkCounter(0);//do all nodes need to reset, else reject packts with high DownlinkCounter values? + dot->setUpLinkCounter(0); + dot->setDownLinkCounter(0); //load ABP keys into arrays std::vector<uint8_t> dev_adr; @@ -98,6 +100,7 @@ } } //if Class C else{ //change back to OTAA + printf("\r\n switching to class A \r\n"); printf("\r\nchanging network address to OTAA device address %s\r\n", mts::Text::bin2hexString(netwrk_address_OTAA).c_str()); if (dot->setNetworkAddress(netwrk_address_OTAA) != mDot::MDOT_OK) { printf("\r\nfailed to set network device address to %s", mts::Text::bin2hexString(netwrk_address_OTAA).c_str());
--- a/src/wbit_util.cpp Sun Jan 20 15:19:57 2019 +0000 +++ b/src/wbit_util.cpp Fri Jan 25 01:46:26 2019 +0000 @@ -71,8 +71,9 @@ if(verbose)pc.printf("\r\n************************************************************\r\n"); } //============================================================================== -//printNvmABPData +//printNvmABPData --- OLD CODE //============================================================================== +/* void printNvmABPData(nvmABP *pNvmABP){ uint8_t i; if(verbose){ @@ -89,7 +90,8 @@ pc.printf(" %x",pNvmABP->devAdr[i]); } if(verbose)pc.printf("\r\n************************************************************\r\n"); -} +} +*/ //============================================================================== //getChkSum //compute chksum @@ -142,6 +144,7 @@ printNmvData(pNvm); return dot->nvmWrite(NVM_ADDR_OTAA,pNvm,sizeof(nvm)); } +/* //============================================================================== //nvmWriteABP //write nvmABPData struc to nvm memory TODO: WRITE PROCEDUREES @@ -154,6 +157,7 @@ printNvmABPData(pNvmABP); return dot->nvmWrite(NVM_ADDR_ABP,pNvmABP,sizeof(nvmABP)); } +*/ //============================================================================== //nvmRestorekeys //restore OTAA hard coded keys to nvm and also logdisplay enable/disable @@ -192,10 +196,11 @@ } //============================================================================== -//nvmReadABP +//nvmReadABP ------------ OLD CODE //- read nvmDataABP struc from nvm memory //- if bad chksum then default to hard code network keys //============================================================================== +/* bool nvmReadABP(nvmABP *pNvmABP){ dot->nvmRead(NVM_ADDR_ABP,pNvmABP,sizeof(nvmABP)); //uint8_t chksum = getNvmABPChkSum(pNvmABP); @@ -208,6 +213,7 @@ } return false; } +*/ //============================================================================ uint8_t join_network_attempts_wbit() {