alan broad
/
carbon_v5_arm_studio
arm studio build
Revision 5:abfe25f0de33, committed 2018-08-06
- Comitter:
- alan1974
- Date:
- Mon Aug 06 19:11:02 2018 +0000
- Parent:
- 4:d87f8dcf40ef
- Child:
- 6:b2039a285d7f
- Commit message:
- initial
Changed in this revision
--- a/inc/commI2C.h Sat Aug 04 20:26:39 2018 +0000 +++ b/inc/commI2C.h Mon Aug 06 19:11:02 2018 +0000 @@ -121,13 +121,15 @@ typedef struct { uint8_t cmd; //cmd received from proc uint8_t dataLen; //datalen found in pkt + uint8_t bWriteNvm; //if false, just read nvm nvm nvmData; }pkt_setnvmup; //dwnstream pkt struc typedef struct { uint8_t ack; //ack header response - uint8_t cmd; //cmd received from proc + uint8_t cmd; //cmd received from proc uint8_t dataLen; //datalen found in pkt + uint8_t bChkSumOK; nvm nvmData; }pkt_setnvmdwn;
--- a/inc/global.h Sat Aug 04 20:26:39 2018 +0000 +++ b/inc/global.h Mon Aug 06 19:11:02 2018 +0000 @@ -11,13 +11,17 @@ uint8_t maxTxPowerdBm; //max power (read only) uint8_t minTxPowerdBm; //min power (read only) uint8_t public_network; //public = true, private = false; - uint8_t sub_band; //network subband # - bool aDR; //true if ADR enabled + uint8_t join_delay; //join delay (sec) + uint8_t sub_band; //network subband # + bool aDR; //true if ADR enabled int8_t antennaGaindBi; //antenna gain + bool txInverted; //true if tx inverted + bool rxInverted; //true if rx inverted + uint8_t rxDelay; //set rx window delay,sec uint8_t txPowerdBm; //transmit power uint8_t dataRate; //data rate - uint8_t appPort; //app port - uint8_t linkChkCount; //link check count + // uint8_t appPort; //app port .. not used + // uint8_t linkChkCount; //link check count not used }xdot_radio_params; //struc to set nvm params
--- a/inc/wbit_util.h Sat Aug 04 20:26:39 2018 +0000 +++ b/inc/wbit_util.h Mon Aug 06 19:11:02 2018 +0000 @@ -10,6 +10,8 @@ uint8_t chksum; //chk to make sure nvm memory ok }nvm; */ +void printRadioCfg(); +void printNmvData(nvm *pNvm); bool nvmWrite(nvm *pNvm); bool nvmRead(nvm *pNvm);
--- a/src/commI2C.cpp Sat Aug 04 20:26:39 2018 +0000 +++ b/src/commI2C.cpp Mon Aug 06 19:11:02 2018 +0000 @@ -8,6 +8,7 @@ DigitalInOut wake(PA_0); extern Serial pc; +extern bool verbose; //#define TEST @@ -32,22 +33,22 @@ #ifdef NOT_USED void i2c_wait4wake_lo(void){ wake.input(); -// pc.printf("\n\r waiting for wake to go hi %d",wake); +// if(verbose)pc.printf("\n\r waiting for wake to go hi %d",wake); bool wakeHi= false; while(!wakeHi){ wait_ms(10); //need this wait else loop below will block previous printout wakeHi = wake; // state of wake signal } - // pc.printf("\n\r detected wake hi"); + // if(verbose)pc.printf("\n\r detected wake hi"); wait_ms(100); //need this wait else loop below will block previous printout //wake signal hi,wait until it goes back lo => psoc is going to wait for .... - // pc.printf("\n\r waiting for wake to go lo %d",wake); + // if(verbose)pc.printf("\n\r waiting for wake to go lo %d",wake); bool wakeLo = true; while(wakeLo){ wait_ms(10); //need this wait else loop below will block previous printout wakeLo = wake; // state of wake signal } - //pc.printf("\n\r detected wake lo "); + //if(verbose)pc.printf("\n\r detected wake lo "); wait_ms(100); //wait for proc to get ready for i2c comm, proc leave wake in low state @@ -96,7 +97,7 @@ //============================================================================== I2C_XFR_TYPE i2c_proc_comm(void) { - bool verbose = false; + uint32_t timeout = 0x000fffff; //1.1second timeout while(1){ @@ -107,15 +108,16 @@ return I2C_WRITE; case I2CSlave::WriteAddressed: //xdot <- proc slave.read((char *)buf_rcv, BUFFER_SIZE_I2C); +/* if (verbose){ pc.printf("\n\r Incoming buffer(hex): \n\r"); int j; for (j = 0; j < BUFFER_SIZE_I2C; j++){ - pc.printf("%x", buf_rcv[j]); - pc.printf(" "); - } - + pc.printf("%x", buf_rcv[j]); + pc.printf(" "); + } } +*/ return I2C_READ; default: }; //switch
--- a/src/main.cpp Sat Aug 04 20:26:39 2018 +0000 +++ b/src/main.cpp Mon Aug 06 19:11:02 2018 +0000 @@ -11,6 +11,7 @@ nvm nvmData; nvm *pNvmData = &nvmData; +bool verbose = true; //======================================================================================================= // enable some GPIO for scope trigger or led //======================================================================================================= @@ -94,7 +95,7 @@ #ifdef GPIO_ENABLE if (led_enabled) { - pc.printf("LED_test()\r\n"); + if(verbose)pc.printf("LED_test()\r\n"); int test; for (test=0; test<num; test++) { @@ -135,10 +136,10 @@ bool cfg_network(bool bForceCfg,bool bPublic,uint8_t sub_band){ // if bForceCfg false and network parameters haven't changed then just exit if (!bForceCfg){ - pc.printf("no configuration change needed subband the same"); + if(verbose)pc.printf("no configuration change needed subband the same"); if ((public_network ==bPublic) && (frequency_sub_band ==sub_band))return true; } - pc.printf("changing to subband: %d\r\n",sub_band); + if(verbose)pc.printf("changing to subband: %d\r\n",sub_band); // update network settings public_network = bPublic; frequency_sub_band =sub_band; @@ -158,10 +159,7 @@ // 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); - - - + update_ota_config_id_key(nvmData.network_id,nvmData.network_key, frequency_sub_band, public_network, ack); logInfo("-------------- network configured for public access -----------------------------"); } else{ @@ -203,6 +201,7 @@ gpio1 =0; led1 = 1; #endif + pc.baud(115200); pc.printf("\r\n**********************************************************\r\n"); pc.printf("\r\n XDOT BOOT\r\n"); @@ -213,36 +212,20 @@ dot = mDot::getInstance(plan); assert(dot); - //dot->setLogLevel((true) ? mts::MTSLog::TRACE_LEVEL : mts::MTSLog::TRACE_LEVEL); // TRACE_LEVEL , INFO_LEVEL - bool bLogOutput = true; - dot->setLogLevel((bLogOutput) ? mts::MTSLog::TRACE_LEVEL : mts::MTSLog::TRACE_LEVEL); // TRACE_LEVEL , INFO_LEVEL - dot->setEvents(&events); - -//nvm nvmData; -//nvm *pNvmData = &nvmData; - - + dot->setEvents(&events); nvmRead(pNvmData); -/* - pc.printf("****NON-VOLATILE MEMORY TEST*********\r\n"); - - - for (i = 0; i < sizeof(network_id);i++){ - nvmData.network_id[i] = network_id[i]; - } - for (i = 0; i < sizeof(network_key);i++){ - nvmData.network_key[i] = network_key[i]; + + //pNvmData->bLogOutputOn = 1; // TEST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + if (pNvmData->bLogOutputOn == 0){ + pc.printf("\r\nDISABLING TERMINAL OUTPUT\r\n"); + dot->setLogLevel(mts::MTSLog::NONE_LEVEL); + verbose = false; + } + else{ + printNmvData(pNvmData); + dot->setLogLevel((verbose) ? mts::MTSLog::TRACE_LEVEL : mts::MTSLog::TRACE_LEVEL); // TRACE_LEVEL , INFO_LEVEL } - - uint8_t databytesread[128]; - dot->nvmWrite(0,pData,128); - dot->nvmRead(0, databytesread,128); - for (i = 0; i < 64; i++) - pc.printf("databyte %d: %x\r\n",i,databytesread[i]); - - pc.printf("****NON-VOLATILE MEMORY TEST*********\r\n"); -*/ - + dot->resetConfig(); //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) @@ -250,23 +233,10 @@ // 1: Device has been in Standby mode // The xDot should enter standby mode when deep sleep in invoked. So you should see the standby flag set if it came out of deep sleep. if (!dot->getStandbyFlag()) { //if 0 => power-up/reset which should always be the case at this point - logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION); - - pc.printf("\r\n saved configuration: "); - frequency_sub_band = dot->getFrequencySubBand(); - pc.printf("\r\n subband: %d ",frequency_sub_band); - pc.printf("\r\n ADR: %d ",dot->getAdr()); - pc.printf("\r\n antenna gain: %d ",dot->getAntennaGain()); - pc.printf("\r\n transmit max pwr: %d ",dot->getMaxTxPower()); - pc.printf("\r\n transmit min pwr: %d ",dot->getMinTxPower()); - pc.printf("\r\n transmit pwr: %d ",dot->getTxPower()); - pc.printf("\r\n TxDataRate: %d ",dot->getTxDataRate()); - pc.printf("\r\n maxPktLen: %d ",dot->getMaxPacketLength()); -// pc.printf("\r\n port nmb: %d ",dot->getAppPort()); - pc.printf("\r\n link check count: %d ",dot->getLinkCheckThreshold()); - pc.printf("\r\n"); - cfg_network(true,public_network,frequency_sub_band); //force network cfg, - + logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION); + frequency_sub_band = dot->getFrequencySubBand(); + printRadioCfg(); + cfg_network(true,public_network,frequency_sub_band); //force network cfg, } else { // restore the saved session (join OTAA info) if the dot woke from deepsleep mode // useful to use with deepsleep because session info is otherwise lost when the dot enters deepsleep @@ -284,7 +254,7 @@ // logInfo("saving configuration"); eui = mts::Text::bin2hexString(dot->getDeviceId()).c_str(); - pc.printf("\r\nEUI: %s\r\n",eui); + if(verbose)pc.printf("\r\nEUI: %s\r\n",eui); bool joined = false; @@ -305,16 +275,16 @@ bool bPulseLoraWake = false; while(1) { - pc.printf("\n\r ***************************** "); + if(verbose)pc.printf("\n\r ***************************** "); switch (i2c_proc_comm()){ case I2C_WRITE: //xdot ack ->proc - pc.printf("\n\r xdot ack -> proc done,going to sleep\n\r "); + if(verbose)pc.printf("\n\r xdot ack -> proc done,going to sleep\n\r "); bPulseLoraWake = false; // gpio1 =0; sleep_wake_interrupt_only(deep_sleep); //wait for wake // gpio1 =1; - pc.printf("\n\r lora wake detected -> monitoring i2c bus\n\r "); + if(verbose)pc.printf("\n\r lora wake detected -> monitoring i2c bus\n\r "); break; case I2C_READ: //xdot <- proc bPulseLoraWake = true; @@ -324,31 +294,29 @@ pkt_upstrm *pUp= (pkt_upstrm*)&buf_rcv[0]; pkt_ack *pAck = (pkt_ack*)&buf_xmt[0]; pAck->ack = I2C_ACK_PROC; - pAck->cmd = XDOT_CMD_XMIT_PKT; - //pAck->dataLen = buf_rcv[1]; + pAck->cmd = XDOT_CMD_XMIT_PKT; pAck->dataLen = pUp->dataLen; //data len of xmitted pkt - pc.printf("\r\npkt to xmit data len: %d\r\n",pAck->dataLen); - uint8_t chksum = chksum_proc(buf_rcv); - //pc.printf("\r\chksum rcvd: %d, chksum computed: %d\r\n",chksum,pkt_upstrm->chksum); - pc.printf("\r\nI2C chksum rcvd: %d",chksum); - pc.printf(" chksum computed: %d",pUp->chksum); + if(verbose)pc.printf("\r\npkt to xmit data len: %d\r\n",pAck->dataLen); + uint8_t chksum = chksum_proc(buf_rcv); + /*if(verbose)*/pc.printf("\r\nI2C chksum rcvd: %d",chksum); + /*if(verbose)*/pc.printf(" chksum computed: %d",pUp->chksum); pAck->bXmitAttempted = 1; pAck->chksum_err = 0; if(pUp->chksum != chksum){ - pc.printf(" chksum err, aborting xmit"); + /* if(verbose)*/pc.printf(" chksum err, aborting xmit"); pAck->bXmitAttempted = 0; pAck->mdot_ret = -2048; //wbit rtn code? pAck->chksum_err = 1; break; } //rev 0307 parameters - pc.printf("\n\r setting application port %d ",pUp->appPort); //appPort not used in rev < 0307 + if(verbose)pc.printf("\n\r setting application port %d ",pUp->appPort); //appPort not used in rev < 0307 dot->setAppPort(pUp->appPort); uint8_t linkFailcnt = dot->getLinkFailCount(); - pc.printf("\r\n lINK fail count %d\r\n",linkFailcnt); + if(verbose)pc.printf("\r\n lINK fail count %d\r\n",linkFailcnt); if (pUp->bResetLinkCCounter){ dot->setLinkFailCount(0); - pc.printf("\r\n reset link fail threshold to zero"); + if(verbose)pc.printf("\r\n reset link fail threshold to zero"); } if (pUp->dataLen == 0){ //datalen non zero? pAck->bXmitAttempted = 0; @@ -356,10 +324,13 @@ } upstream_packet.clear(); //xfr data from incoming bfr to xmit bfr for (i=0; i< pUp->dataLen;i++) upstream_packet.push_back(pUp->txData[i]); - pc.printf("\r\n[TEST],Upstream Packet Received"); // no \r\n because it comes below - for(std::vector<uint8_t>::iterator it = upstream_packet.begin(); it != upstream_packet.end(); ++it) pc.printf(",0x%x", *it); - pc.printf("\r\n"); // see i told you. + if(verbose){ + pc.printf("\r\n[TEST],Upstream Packet Received"); // no \r\n because it comes below + for(std::vector<uint8_t>::iterator it = upstream_packet.begin(); it != upstream_packet.end(); ++it) + pc.printf(",0x%x", *it); + pc.printf("\r\n"); // see i told you. + } joined = dot->getNetworkJoinStatus(); //are we joined to Lorawan? pAck->joinAttempts = 0; //no attempts made yet to join pAck->bAck = 0; //won't know if we receive a lorawan ack until after xmit @@ -367,92 +338,101 @@ pAck->rssi = 0; //if not rx1/rx2 then no RSSI value if(!joined) { //if not previously joined, then need to join now pAck->bJoined = 0; - pc.printf("\r\n----------- NETWORK NOT JOINED YET, WILL TRY TO JOIN %d TIMES\r\n",pUp->joinAttemps); + if(verbose)pc.printf("\r\n----------- NETWORK NOT JOINED YET, WILL TRY TO JOIN %d TIMES\r\n",pUp->joinAttemps); joined = join_network_wbit(pUp->joinAttemps); pAck->joinAttempts = join_network_attempts_wbit(); pAck->mdot_ret = dot->send(upstream_packet); - if (!joined)pc.printf("\r\n----------- FAILED TO JOIN...GIVING UP\r\n"); // join network if not joined + if (!joined) + if(verbose)pc.printf("\r\n----------- FAILED TO JOIN...GIVING UP\r\n"); // join network if not joined } if (joined){ pAck->bJoined = 1; //we are joined to the network packets_sent++; //send packet //return code indicates results, send return code back to proc Dec14,2017 - pAck->mdot_ret = dot->send(upstream_packet); - printf("\n\rdata->send() return code: %d\r\n",pAck->mdot_ret); - if (pAck->mdot_ret == mDot::MDOT_OK){ //xmit the pkt in blocking mode, return false if no ack - //if (dot->send(upstream_packet) == mDot::MDOT_OK){ //xmit the pkt in blocking mode, return false if no ack + 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){ acks_rcvd++; pAck->bAck = 1; //we got a Rx1 or Rx2 ack mDot::rssi_stats rssiStats = dot->getRssiStats(); //rssi stat pAck->rssi = (int8_t)rssiStats.last; - printf("\n\rdata->send()= true => ack rcvd :ack=: %d, rssi=: %d\r\n",pAck->bAck,pAck->rssi); + if (verbose)printf("\n\rdata->send()= true => ack rcvd :ack=: %d, rssi=: %d\r\n",pAck->bAck,pAck->rssi); if (events.is_packet_received()){ //any downstream data from the Rx1/Rx2 pkt? - printf("\n\revents.is_packet_received = true\r\n"); + if (verbose)printf("\n\revents.is_packet_received = true\r\n"); pAck->bAckdata = 1; upstream_packet.clear(); upstream_packet = events.get_downstream_packet(); pAck->rxLen = upstream_packet.size(); if (pAck->rxLen > I2C_MAX_ACK_DATA){ - pc.printf("\r\n got ack with pkt data too large.. rejected\r\n"); + if(verbose)pc.printf("\r\n got ack with pkt data too large.. rejected\r\n"); break; - } - pc.printf("\r\n pkt data: "); - for (i=0; i< pAck->rxLen;i++) { - pAck->rxData[i]= upstream_packet[i]; - pc.printf(" %x",pAck->rxData[i]); + } + if(verbose){ + pc.printf("\r\n pkt data: "); + for (i=0; i< pAck->rxLen;i++) { + pAck->rxData[i]= upstream_packet[i]; + pc.printf(" %x",pAck->rxData[i]); + } } } //if downstream data rcvd else{ - printf("\n\revents.is_packet_received ()= false => ack rcvd but no data\r\n"); + if (verbose)printf("\n\revents.is_packet_received ()= false => ack rcvd but no data\r\n"); } } //send() returns K else{ - printf("\n\rdata->send()= false => no ack\r\n"); //could be some other error + if (verbose)printf("\n\rdata->send()= false => no ack\r\n"); //could be some other error } }//if joined break; case XDOT_CMD_SET_RADIO: - pc.printf("\n\r proc cmd: CMD_SET_RADIO"); + if(verbose)pc.printf("\n\r proc cmd: CMD_SET_RADIO"); pkt_setradiodwn *pDwnRadio= (pkt_setradiodwn*)&buf_xmt[0]; pkt_setradioup *pUpRadio = (pkt_setradioup*)&buf_rcv[0]; pDwnRadio->ack = I2C_ACK_PROC; pDwnRadio->cmd = XDOT_CMD_SET_RADIO; if (pUpRadio->bSetParams){ - pc.printf("\n\r setting subband to %d ",pUpRadio->params.sub_band); + if (verbose)pc.printf("\n\r setting public/private network to %d ",pUpRadio->params.public_network); + public_network = (bool)pUpRadio->params.public_network; + if(verbose)pc.printf("\n\r setting subband to %d ",pUpRadio->params.sub_band); cfg_network(false,true,(uint8_t)pUpRadio->params.sub_band); - pc.printf("\n\r setting adr to %d ",pUpRadio->params.aDR); + if(verbose)pc.printf("\n\r setting adr to %d ",pUpRadio->params.aDR); dot->setAdr((uint8_t)pUpRadio->params.aDR); // enable or disable Adaptive Data Rate - pc.printf("\n\r setting antenna gain to %d ",pUpRadio->params.antennaGaindBi); + if(verbose)pc.printf("\n\r setting antenna gain to %d ",pUpRadio->params.antennaGaindBi); dot->setAntennaGain(pUpRadio->params.antennaGaindBi); - pc.printf("\n\r setting radio tx power to %d ",pUpRadio->params.txPowerdBm); + if(verbose)pc.printf("\n\r setting radio tx power to %d ",pUpRadio->params.txPowerdBm); dot->setTxPower(pUpRadio->params.txPowerdBm); - pc.printf("\n\r setting tx datarate to %d ",pUpRadio->params.dataRate); + if(verbose)pc.printf("\n\r setting tx datarate to %d ",pUpRadio->params.dataRate); dot->setTxDataRate(pUpRadio->params.dataRate); - // pc.printf("\n\r setting application port %d ",pUpRadio->appPort); - // dot->setAppPort(pUpRadio->appPort); - pc.printf("\n\r setting link check threshold %d ",pUpRadio->params.linkChkCount); - dot->setLinkCheckThreshold(pUpRadio->params.linkChkCount); - pc.printf("\n\r saving configuration"); + if(verbose)pc.printf("\n\r setting tx inverted to %d ",(bool)pUpRadio->params.txInverted); + dot->setTxInverted((bool)pUpRadio->params.txInverted); + if(verbose)pc.printf("\n\r setting rx inverted to %d ",(bool)pUpRadio->params.rxInverted); + dot->setRxInverted((bool)pUpRadio->params.rxInverted); + if(verbose)pc.printf("\n\r setting rx delay to %d ",pUpRadio->params.rxDelay); + dot->setRxDelay(pUpRadio->params.rxDelay); + if(verbose)pc.printf("\n\r setting join delay to %d ",pUpRadio->params.join_delay); + dot->setJoinDelay(pUpRadio->params.join_delay); + if(verbose)pc.printf("\n\r saving configuration"); if (!dot->saveConfig())logError("failed to save configuration"); display_config(); } - pDwnRadio->params.public_network = public_network; pDwnRadio->params.sub_band = dot->getFrequencySubBand(); - pDwnRadio->params.linkChkCount = dot->getLinkCheckThreshold(); + pDwnRadio->params.join_delay = dot->getJoinDelay(); + pDwnRadio->params.txInverted = dot->getTxInverted(); + pDwnRadio->params.rxInverted = dot->getRxInverted(); + pDwnRadio->params.rxDelay = dot->getRxDelay(); pDwnRadio->params.maxDataLen = dot->getMaxPacketLength(); pDwnRadio->params.maxTxPowerdBm = dot->getMaxTxPower(); pDwnRadio->params.minTxPowerdBm = dot->getMinTxPower(); pDwnRadio->params.aDR = dot->getAdr(); pDwnRadio->params.antennaGaindBi = dot->getAntennaGain(); pDwnRadio->params.txPowerdBm = dot->getTxPower(); - pDwnRadio->params.dataRate = dot->getTxDataRate(); -// pDwnRadio->appPort = dot->getAppPort(); + pDwnRadio->params.dataRate = dot->getTxDataRate();// break; case XDOT_CMD_GET_EUI: //0307: modified to include radio parameter settings - pc.printf("\n\r proc cmd: get EUI"); + if(verbose)pc.printf("\n\r proc cmd: get EUI"); pkt_eui *peui = (pkt_eui*)&buf_xmt[0]; peui->ack = I2C_ACK_PROC; peui->cmd = XDOT_CMD_GET_EUI; @@ -463,16 +443,16 @@ for (i=0; i< 4;i++) peui->apiLvlData[i] = api_level[i]; 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 - pc.printf("\n\r eui data length: %d",peui->dataLen); + if(verbose)pc.printf("\n\r eui data length: %d",peui->dataLen); break; case XDOT_CMD_SET_NTWKSESS: //read or write network seesion to xdot flash bool bWriteSession = (bool)buf_rcv[1]; if (bWriteSession){ - pc.printf("\n\r proc cmd writing network sesion to flash"); + if(verbose)pc.printf("\n\r proc cmd writing network sesion to flash"); dot->saveNetworkSession(); } else{ - pc.printf("\n\r reading network session from flash"); + if(verbose)pc.printf("\n\r reading network session from flash"); dot->restoreNetworkSession(); } pkt_ntwrk *pktwrk = (pkt_ntwrk*)&buf_xmt[0]; @@ -484,35 +464,39 @@ pkt_setnvmdwn *pDwnNvm= (pkt_setnvmdwn*)&buf_xmt[0]; pkt_setnvmup *pUpNvm = (pkt_setnvmup*)&buf_rcv[0]; pDwnNvm->ack = I2C_ACK_PROC; - pDwnNvm->cmd = XDOT_CMD_SET_RADIO; - nvmWrite(&pUpNvm->nvmData); - nvmRead(&pDwnNvm->nvmData); + pDwnNvm->cmd = XDOT_CMD_SET_NVM; + if (pUpNvm->bWriteNvm) + nvmWrite(&pUpNvm->nvmData); + pDwnNvm->bChkSumOK = 0; + if (nvmRead(&pDwnNvm->nvmData)) + pDwnNvm->bChkSumOK = 1; + printNmvData(&pDwnNvm->nvmData); break; case XDOT_CMD_SET_KEY_X: - pc.printf("\n\r proc cmd: set a key, simulating minm delay before wake pulse\r\n"); + if(verbose)pc.printf("\n\r proc cmd: set a key, simulating minm delay before wake pulse\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: - pc.printf("\n\r proc cmd: xmit gateway ping\r\n"); + if(verbose)pc.printf("\n\r proc cmd: xmit gateway ping\r\n"); pkt_ping *pPing = (pkt_ping*)&buf_xmt[0]; pPing->ack = I2C_ACK_PROC; pPing->cmd = XDOT_CMD_GATEWAY_PING; pPing->dataLen = 3; //only 3 bytes returned - pc.printf("\r\n----------- SENDING GATEWAY PING \r\n"); + if(verbose)pc.printf("\r\n----------- SENDING GATEWAY PING \r\n"); mDot::ping_response ping_res; ping_res = dot->ping(); pPing->status = (int8_t)ping_res.status; pPing->rssi = (int8_t)ping_res.rssi; pPing->snr = (int8_t)ping_res.snr; if (ping_res.status == 0) - pc.printf("\r\n----------- GATEWAY PING SUCCEEDED \r\n"); + if(verbose)pc.printf("\r\n----------- GATEWAY PING SUCCEEDED \r\n"); else - pc.printf("\r\n----------- GATEWAY PING FAIL \r\n"); + if(verbose)pc.printf("\r\n----------- GATEWAY PING FAIL \r\n"); break; default: - pc.printf("\n\r proc cmd not recognized:%x",buf_rcv[0]); + if(verbose)pc.printf("\n\r proc cmd not recognized:%x",buf_rcv[0]); wait_ms(I2C_MIN_WAIT_DELAY); buf_xmt[0] = I2C_ACK_PROC; buf_xmt[1] = XDOT_CMD_UNDEFINED;
--- a/src/wbit_util.cpp Sat Aug 04 20:26:39 2018 +0000 +++ b/src/wbit_util.cpp Mon Aug 06 19:11:02 2018 +0000 @@ -5,6 +5,7 @@ #include "mbed.h" #include "mDot.h" extern Serial pc; +extern bool verbose; uint8_t j_attempts = 0; //return number of attempts it took to join the network @@ -12,23 +13,46 @@ //these are used as backup keys in case nvm memory is corrupted and we can't read the keys correctly uint8_t network_id[] = { 0x90, 0xF1, 0x47, 0x90, 0x6C, 0x48, 0x1D, 0x29 }; //static id not used anymore but don't comment out uint8_t network_key[] = { 0x0F, 0xF9, 0xA2, 0x90, 0x2E, 0xAA, 0x6B, 0x8C, 0x6A, 0x4E, 0xFD, 0x67, 0xF9, 0xA6, 0xF3, 0xD3 }; //OTAA appkey + +//============================================================================ +// printRadioCfg + +//============================================================================ +void printRadioCfg(){ + if(verbose){ + pc.printf("\r\n************************************************************"); + pc.printf("\r\n saved radio configuration: "); + pc.printf("\r\n public network: %d ",dot->getPublicNetwork()); + pc.printf("\r\n subband: %d ",dot->getFrequencySubBand()); + pc.printf("\n\r join delay %d ",dot->getJoinDelay()); + pc.printf("\r\n ADR: %d ",dot->getAdr()); + pc.printf("\r\n antenna gain: %d ",dot->getAntennaGain()); + pc.printf("\r\n transmit max pwr: %d ",dot->getMaxTxPower()); //not saved in cfg + pc.printf("\r\n transmit min pwr: %d ",dot->getMinTxPower()); //not saved in cfg + pc.printf("\r\n transmit pwr: %d ",dot->getTxPower()); + pc.printf("\n\r tx inverted %d ",dot->getTxInverted()); + pc.printf("\n\r rx inverted %d ",dot->getRxInverted()); + pc.printf("\n\r rx delay %d ",dot->getRxDelay()); + pc.printf("\r\n TxDataRate: %d ",dot->getTxDataRate()); + pc.printf("\r\n maxPktLen: %d ",dot->getMaxPacketLength()); //not saved in cfg + pc.printf("\r\n************************************************************\r\n"); + } +} //============================================================================== //printNmvData //============================================================================== void printNmvData(nvm *pNvm){ - uint8_t i; - pc.printf("\r\nnon-volatile memory (nvm):"); - pc.printf("\r\nnetwork_id:"); + if(verbose)pc.printf("\r\n************************************************************"); + if(verbose)pc.printf("\r\nnon-volatile memory (nvm):"); + if(verbose)pc.printf("\r\nnetwork_id:"); for (i = 0; i < 8;i++) - pc.printf(" %x",pNvm->network_id[i]); - - //for (i = 0 ; i < sizeof(NvmData.network_id);i++) pc.printf(" ,%x",NvmData.network_id[i]); - pc.printf("\r\nnetwork_key:"); - for (i = 0 ; i < 16;i++) pc.printf(" %x",pNvm->network_key[i]); - pc.printf("\r\nbLogOutputOn: %d\r\n",pNvm->bLogOutputOn); - + if(verbose)pc.printf(" %x",pNvm->network_id[i]); + if(verbose)pc.printf("\r\nnetwork_key:"); + for (i = 0 ; i < 16;i++) if(verbose)pc.printf(" %x",pNvm->network_key[i]); + if(verbose)pc.printf("\r\nbLogOutputOn: %d ",pNvm->bLogOutputOn); + if(verbose)pc.printf("\r\n************************************************************\r\n"); } //============================================================================== //getNvmChkSum @@ -61,13 +85,15 @@ uint8_t i; dot->nvmRead(0,pNvm,sizeof(nvm)); uint8_t chksum = getNvmChkSum(pNvm); +/* if (chksum == pNvm->chksum){ logInfo("nvmRead: chksum ok"); - printNmvData(pNvm); + //printNmvData(pNvm); return true; } +*/ //bad chksum, resort to old hard coded keys - pc.printf("nvmRead: bad chksum, using default values"); + if(verbose)pc.printf("nvmRead: bad chksum, using default values"); for (i = 0; i < sizeof(network_id);i++){ pNvm->network_id[i] = network_id[i]; } @@ -75,7 +101,7 @@ pNvm->network_key[i] = network_key[i]; } pNvm->bLogOutputOn = 1; //disable log output - printNmvData(pNvm); + // printNmvData(pNvm); return false; } //============================================================================