alan broad
/
carbon_v5_arm_studio
arm studio build
Diff: src/main.cpp
- Revision:
- 7:fba1e8fc7693
- Parent:
- 6:b2039a285d7f
- Child:
- 8:a5316708e51d
--- a/src/main.cpp Tue Aug 07 17:56:23 2018 +0000 +++ b/src/main.cpp Fri Aug 10 19:17:43 2018 +0000 @@ -146,7 +146,7 @@ // start from a well-known state logInfo("defaulting Dot configuration"); //dot->resetConfig(); //reset config to factory default not used for v0307 - dot->resetNetworkSession(); //Reset current network session, essentially disconnecting from the network + // test dot->resetNetworkSession(); //Reset current network session, essentially disconnecting from the network if (dot->getJoinMode() != mDot::OTA) { // update configuration if necessary logInfo("changing network join mode to OTA"); @@ -218,15 +218,22 @@ //pNvmData->bLogOutputOn = 1; // TEST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if (pNvmData->bLogOutputOn == 0){ pc.printf("\r\nDISABLING TERMINAL OUTPUT\r\n"); - dot->setLogLevel(mts::MTSLog::NONE_LEVEL); - verbose = false; +// dot->setLogLevel(mts::MTSLog::NONE_LEVEL); //doesn't work + //dot->setLogLevel((true) ? mts::MTSLog::WARNING_LEVEL : mts::MTSLog::WARNING_LEVEL); //!!!!!!!!!!!! deosn'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 = true; //TEST !!!!!!!!!!!!!!!!!!!!!!!!! } else{ printNmvData(pNvmData); dot->setLogLevel((verbose) ? mts::MTSLog::TRACE_LEVEL : mts::MTSLog::TRACE_LEVEL); // TRACE_LEVEL , INFO_LEVEL } - // dot->resetConfig(); //TEST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - +//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) // 0: Device has not been in Standby mode @@ -278,32 +285,33 @@ if(verbose)pc.printf("\n\r ***************************** "); switch (i2c_proc_comm()){ - case I2C_WRITE: //xdot ack ->proc + case I2C_WRITE: //xdot ack ->proc 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; - if(verbose)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; switch (buf_rcv[0]) { case XDOT_CMD_XMIT_PKT: - pkt_upstrm *pUp= (pkt_upstrm*)&buf_rcv[0]; - pkt_ack *pAck = (pkt_ack*)&buf_xmt[0]; + pkt_upstrm *pUp= (pkt_upstrm*)&buf_rcv[0]; + for (i=0; i < sizeof(buf_xmt);i++)buf_xmt[i] = 0xff; //bfr fill + pkt_ack *pAck = (pkt_ack*)&buf_xmt[0]; pAck->ack = I2C_ACK_PROC; pAck->cmd = XDOT_CMD_XMIT_PKT; - pAck->dataLen = pUp->dataLen; //data len of xmitted pkt - if(verbose)pc.printf("\r\npkt to xmit data len: %d\r\n",pAck->dataLen); + pAck->dataLen = pUp->dataLen; //data len of xmitted pkt + 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); + if(verbose)pc.printf("\r\nI2C chksum rcvd/computer: %d/%d ",pUp->chksum,chksum); pAck->bXmitAttempted = 1; pAck->chksum_err = 0; if(pUp->chksum != chksum){ - /* if(verbose)*/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; @@ -327,7 +335,7 @@ for (i=0; i< pUp->dataLen;i++) upstream_packet.push_back(pUp->txData[i]); if(verbose){ - pc.printf("\r\n[TEST],Upstream Packet Received"); // no \r\n because it comes below + pc.printf("\r\n[TEST],Upstream Packet Received"); 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. @@ -336,7 +344,8 @@ pAck->joinAttempts = 0; //no attempts made yet to join pAck->bAck = 0; //won't know if we receive a lorawan ack until after xmit pAck->bAckdata = 0; //won't know if we receive a lorawan ack downstream data until after xmit - pAck->rssi = 0; //if not rx1/rx2 then no RSSI value + pAck->rssi = 0; //if not rx1/rx2 then no RSSI value + pAck->snr = 0; //if not rx1/rx2 then no SNR value if(!joined) { //if not previously joined, then need to join now pAck->bJoined = 0; if(verbose)pc.printf("\r\n----------- NETWORK NOT JOINED YET, WILL TRY TO JOIN %d TIMES\r\n",pUp->joinAttemps); @@ -352,14 +361,21 @@ //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 (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 + mDot::rssi_stats rssiStats = dot->getRssiStats(); //rssi stat pAck->rssi = (int8_t)rssiStats.last; - 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? + mDot::snr_stats snrStats = dot->getSnrStats(); //snr stat + pAck->snr = (int8_t)snrStats.last; + +//test + pAck->rsvd[0] = 0x55; + pAck->rsvd[1] = 0xAA; + + if (verbose)printf("\n\rdata->send()=true; ack:%d, rssi:%d snr:%d\r\n",pAck->bAck,pAck->rssi,pAck->snr); + if (events.is_packet_received()){ //downstream data from the Rx1/Rx2 pkt? if (verbose)printf("\n\revents.is_packet_received = true\r\n"); pAck->bAckdata = 1; upstream_packet.clear(); @@ -380,7 +396,7 @@ else{ if (verbose)printf("\n\revents.is_packet_received ()= false => ack rcvd but no data\r\n"); } - } //send() returns K + } //send() else{ if (verbose)printf("\n\rdata->send()= false => no ack\r\n"); //could be some other error } @@ -394,12 +410,18 @@ pDwnRadio->cmd = XDOT_CMD_SET_RADIO; if (pUpRadio->bSetParams){ - 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 radio params"); + if(verbose)pc.printf("\n\r setting adr to %d ",pUpRadio->params.aDR); + if (pUpRadio->params.aDR == 1) dot->setAdr(true); //test for adr problem + else dot->setAdr(false); + dot->setAdr((uint8_t)pUpRadio->params.aDR); // enable or disable Adaptive Data Rate if(verbose)pc.printf("\n\r setting subband to %d ",pUpRadio->params.sub_band); cfg_network(false,true,(uint8_t)pUpRadio->params.sub_band); - 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 + + if(verbose)pc.printf("\n\r setting public/private network to %d ",pUpRadio->params.public_network); + //public_network = (bool)pUpRadio->params.public_network; + dot->setPublicNetwork((bool)pUpRadio->params.public_network); + if(verbose)pc.printf("\n\r setting antenna gain to %d ",pUpRadio->params.antennaGaindBi); dot->setAntennaGain(pUpRadio->params.antennaGaindBi); if(verbose)pc.printf("\n\r setting radio tx power to %d ",pUpRadio->params.txPowerdBm); @@ -413,11 +435,13 @@ 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); + dot->setJoinDelay(pUpRadio->params.join_delay); if(verbose)pc.printf("\n\r saving configuration"); if (!dot->saveConfig())logError("failed to save configuration"); + display_config(); } + if(verbose)pc.printf("\n\r reading radio params"); pDwnRadio->params.public_network = public_network; pDwnRadio->params.sub_band = dot->getFrequencySubBand(); pDwnRadio->params.join_delay = dot->getJoinDelay(); @@ -430,7 +454,8 @@ pDwnRadio->params.aDR = dot->getAdr(); pDwnRadio->params.antennaGaindBi = dot->getAntennaGain(); pDwnRadio->params.txPowerdBm = dot->getTxPower(); - pDwnRadio->params.dataRate = dot->getTxDataRate();// + pDwnRadio->params.dataRate = dot->getTxDataRate(); + pDwnRadio->params.dataRateCurrent = dot->getSessionDataRate(); break; case XDOT_CMD_GET_EUI: //0307: modified to include radio parameter settings if(verbose)pc.printf("\n\r proc cmd: get EUI"); @@ -444,7 +469,11 @@ 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 - if(verbose)pc.printf("\n\r eui data length: %d",peui->dataLen); + if(verbose)pc.printf("\n\r eui data length: %d",peui->dataLen); + + pc.printf("\n\r eui waiting min len: %d",I2C_MIN_WAIT_DELAY); + wait_ms(I2C_MIN_WAIT_DELAY); //TEST + break; case XDOT_CMD_SET_NTWKSESS: //read or write network seesion to xdot flash bool bWriteSession = (bool)buf_rcv[1]; @@ -474,7 +503,7 @@ printNmvData(&pDwnNvm->nvmData); break; case XDOT_CMD_SET_KEY_X: - if(verbose)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: 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;