alan broad
/
carbon_v5_arm_studio
arm studio build
Revision 11:77fe4f18a81b, committed 2018-10-18
- Comitter:
- alan1974
- Date:
- Thu Oct 18 17:17:26 2018 +0000
- Parent:
- 10:061fab1195e7
- Child:
- 12:7944e4dbe853
- Commit message:
- Rev 0308 first commit
Changed in this revision
--- a/inc/RadioEvent.h Wed Aug 15 13:51:13 2018 +0000 +++ b/inc/RadioEvent.h Thu Oct 18 17:17:26 2018 +0000 @@ -4,7 +4,9 @@ #include "dot_util.h" #include "mDotEvent.h" -//extern bool downstream_packet_received; +extern bool bRxDone; //true if callback function RxDone() triggered +extern bool bDownLinkCntrFail; //true if callback function RxDone() triggered and bad downlink frame count + class RadioEvent : public mDotEvent { @@ -30,15 +32,40 @@ return downstream_packet_received; } + + /** + * 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); + } + + /*! * 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. this is a test. Bits.Rx = %d\r\n", flags->Bits.Rx); + virtual void MacEvent(LoRaMacEventFlags* flags, LoRaMacEventInfo* info) { + //printf("DRT DRT DRT DRT. this is a test. Bits.Rx = %d\r\n", flags->Bits.Rx); if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) { std::string msg = "OK";
--- a/inc/global.h Wed Aug 15 13:51:13 2018 +0000 +++ b/inc/global.h Thu Oct 18 17:17:26 2018 +0000 @@ -2,8 +2,9 @@ #define _GLOBAL_H_ #include "mbed.h" - - +//additonal wbit err code returned to proc, standard xdot errs are 0->-13 +#define XDOT_ERR_FRAME_CNT -2047 +#define XDOT_ERR_I2C_CHKSUM -2048 //struc to set radio parameters typedef struct {
--- a/inc/history.h Wed Aug 15 13:51:13 2018 +0000 +++ b/inc/history.h Thu Oct 18 17:17:26 2018 +0000 @@ -1,5 +1,7 @@ #ifdef COMMENTS_ONLY Data: Rev: API: Comments: +10Oct2018 0008 003 - added check for bad downlink frame counters due to spurious downlink cntr reset + either by Loriot or xdot bug. If bad value detected return xdot err code 26July2018 0007 003 - added new radio commands. - removed update_network_link_check_config(3, 5), replaced with setLinkCheckCount(); - added link check count parameter to radio configuration proc cmd.
--- a/src/main.cpp Wed Aug 15 13:51:13 2018 +0000 +++ b/src/main.cpp Thu Oct 18 17:17:26 2018 +0000 @@ -7,6 +7,9 @@ #include "RadioEvent.h" #include "Lora.h" +bool bRxDone = false; //true if callback function RxDone() triggered +bool bDownLinkCntrFail = false; //true if callback function RxDone() triggered and bad downlink frame count + //nvm storage params nvm nvmData; nvm *pNvmData = &nvmData; @@ -26,7 +29,7 @@ //api_level: proc code will not run if api level (last two bytess) greater than what it expects //======================================================================================================= uint8_t api_level[4] = { 0x00, 0x00, 0x00, 0x03 }; //api-level, determines if xdot code works with proc code -uint8_t ver_level[4] = { 0x00, 0x00, 0x00, 0x07 }; //updated for every code check-in +uint8_t ver_level[4] = { 0x00, 0x00, 0x00, 0x08 }; //updated for every code check-in //======================================================================================================= //configuring mbed pinsa; https://docs.mbed.com/docs/mbed-os-api-reference/en/latest/APIs/io/DigitalInOut/ @@ -126,10 +129,7 @@ public_network = bPublic; frequency_sub_band =sub_band; // start from a well-known state - logInfo("defaulting Dot configuration"); - //dot->resetConfig(); //reset config to factory default not used for v0307 - // test dot->resetNetworkSession(); //Reset current network session, essentially disconnecting from the network - + logInfo("defaulting Dot configuration"); if (dot->getJoinMode() != mDot::OTA) { // update configuration if necessary logInfo("changing network join mode to OTA"); if (dot->setJoinMode(mDot::OTA) != mDot::MDOT_OK) { @@ -140,7 +140,6 @@ // in OTA and AUTO_OTA join modes, the credentials can be passed to the library as a name and passphrase or an ID and KEY // only one method or the other should be used! if (public_network){ - // update_ota_config_id_key(network_id, network_key, frequency_sub_band, public_network, ack); update_ota_config_id_key(nvmData.network_id,nvmData.network_key, frequency_sub_band, public_network, ack); logInfo("-------------- network configured for public access -----------------------------"); } @@ -152,21 +151,8 @@ // declares the Dot disconnected if no acks received within link_check_treshold transmits //update_network_link_check_config(3, 5); dot->setLinkCheckThreshold(link_check_treshold); - - - -/* done thru radio cmds -// save changes to configuration - logInfo("saving configuration"); - if (!dot->saveConfig()) { - logError("failed to save configuration"); - return false; - } - display_config(); -*/ - return true; + return true; } - //================================================================================================= //main() // main() runs in its own thread in the OS @@ -182,8 +168,8 @@ gpio1.output(); gpio1 =0; #endif - pc.baud(115200); + pc.printf("\r\n**********************************************************\r\n"); pc.printf("\r\n XDOT BOOT\r\n"); pc.printf("COMM api_level = <HEX> %x.%x.%x.%x\r\n",api_level[0],api_level[1],api_level[2],api_level[3]); @@ -199,19 +185,12 @@ if (pNvmData->bLogOutputOn == 0){ pc.printf("\r\nDISABLING TERMINAL OUTPUT\r\n"); dot->setLogLevel(mts::MTSLog::NONE_LEVEL); //doesn't work - //dot->setLogLevel((true) ? mts::MTSLog::INFO_LEVEL : mts::MTSLog::INFO_LEVEL); //!!!!!!!!!!!! this works - //dot->setLogLevel((true) ? mts::MTSLog::TRACE_LEVEL : mts::MTSLog::TRACE_LEVEL); //!!!!!!!!!!!! this works verbose = false; } else{ printNmvData(pNvmData); dot->setLogLevel((verbose) ? mts::MTSLog::TRACE_LEVEL : mts::MTSLog::TRACE_LEVEL); // TRACE_LEVEL , INFO_LEVEL } -//restore defaults after xdot reset - // dot->resetConfig(); //TEST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! must upload new cfg after each xdot reset if use this ! - // dot->setFrequencySubBand(frequency_sub_band); //set default freq band - // dot->setAdr(1); //test - // getStandbyFlag() should return the state of the standby flag directly from the processor // Standby flag: This bit is set by hardware and cleared only by a POR/PDR (power on reset/power down reset) or by setting the CSBF bit in the PWR power control register (PWR_CR) @@ -296,20 +275,18 @@ if(pUp->chksum != chksum){ if(verbose)pc.printf(" chksum err, aborting xmit"); pAck->bXmitAttempted = 0; - pAck->mdot_ret = -2048; //wbit rtn code? - pAck->chksum_err = 1; - break; + // pAck->mdot_ret = -2048; //wbit rtn code? + pAck->mdot_ret = XDOT_ERR_I2C_CHKSUM; + pAck->chksum_err = 1; + break; } //rev 0307 parameters if(verbose)pc.printf("\n\r setting application port %d ",pUp->appPort); //appPort not used in rev < 0307 dot->setAppPort(pUp->appPort); uint8_t linkThresholdCnt = pUp->linkThreshCnt; - if(verbose)pc.printf("\r\n linkThreshCnt %d\r\n",linkThresholdCnt); - //if (pUp->bResetLinkCCounter){ - //dot->setLinkFailCount(0); + if(verbose)pc.printf("\r\n linkThreshCnt %d\r\n",linkThresholdCnt); dot->setLinkCheckThreshold(linkThresholdCnt); - // if(verbose)pc.printf("\r\n reset link fail threshold to zero"); - //} + if (pUp->dataLen == 0){ //datalen non zero? pAck->bXmitAttempted = 0; break; @@ -338,14 +315,19 @@ if (!joined) if(verbose)pc.printf("\r\n----------- FAILED TO JOIN...GIVING UP\r\n"); // join network if not joined } - if (joined){ + if (joined) + { pAck->bJoined = 1; //we are joined to the network packets_sent++; + bRxDone = false; //true if callback function RxDone() triggered + bDownLinkCntrFail = false; //true if callback function RxDone() triggered and bad downlink frame count + //send packet //return code indicates results, send return code back to proc Dec14,2017 pAck->mdot_ret = dot->send(upstream_packet); //xmit the pkt in blocking mode, return false if no ack if (verbose)printf("\n\rdata->send() return code: %d\r\n",pAck->mdot_ret); - if (pAck->mdot_ret == mDot::MDOT_OK){ + if (pAck->mdot_ret == mDot::MDOT_OK) + { acks_rcvd++; pAck->bAck = 1; //we got a Rx1 or Rx2 ack mDot::rssi_stats rssiStats = dot->getRssiStats(); //rssi stat @@ -372,11 +354,17 @@ } } //if downstream data rcvd else{ - if (verbose)printf("\n\revents.is_packet_received ()= false => ack rcvd but no data\r\n"); - } + if (verbose)printf("\n\r ack rcvd without data\r\n"); + } //else } //send() - else{ - if (verbose)printf("\n\rdata->send()= false => no ack\r\n"); //could be some other error +//rev 0308 parameters + else + { + if (verbose)printf("\n\r no ack rcvd \r\n"); //could be some other error + if ((pAck->mdot_ret != 0) && bRxDone) //chk if callback function triggered + { + if (bDownLinkCntrFail)pAck->mdot_ret = XDOT_ERR_FRAME_CNT; //bad downlink frame count return err code + } } }//if joined break;