void Transceiver::printCycle(){ DBGINFO("[[cycle:"); DBGINFO(timer.Cycle() % _cycledata); DBGINFO("%"); DBGINFO(_cycleshift); DBGINFO("]]"); }
bool Transceiver::ResponseHello(IMFrame & frame) { DBGINFO("(("); DBGINFO(_knocked); DBGINFO(":"); DBGINFO(_helloCycle); DBGINFO(")) "); _knocked++; byte xr; if (Connected()){ //if (_knocked % (TimerHelloCycle*_cycledata)) { if (timer.Cycle()<_helloCycle) { //last call hasn't success DBGINFO("notsendHello "); return false; } //} _helloCycle=timer.Cycle() +3; //if not success bypass cycle xr=random(100)+60; } else { if (timer.Cycle()<_helloCycle) return false; xr=random(60); _helloCycle=timer.Cycle() +(xr & 1); } DBGINFO("[["); DBGINFO(xr); DBGINFO("]] "); delaySleepT2(xr); IMFrameSetup *sp=frame.Setup(); IMFrame _frame; hostMAC=sp->MAC; serverMAC=sp->MAC2; myHop=sp->address; myHop++; _cycleshift=1; hostId=frame.Header.SourceId; HostChannel=sp->hostchannel; buffer->setChannel(HostChannel); IMFrameSetup * setup=_frame.Setup(); _frame.Reset(); _frame.Header.SourceId=myId; //if not registerred then myId==0 _frame.Header.Function=IMF_HELLO ; _frame.Header.ReceiverId=frame.Header.SenderId; _frame.Header.DestinationId=frame.Header.SourceId; _frame.Header.Sequence=frame.Header.Sequence; PrepareSetup(*setup); setup->rssi=hostRssiListen; Send(_frame); return true; //changed channel }
bool IMBuffer::Received() { bool b=(rSize>0); if (b) { b= TestFrame(); } rSize=0; if (!b){ DBGINFO("["); DBGINFO(state); DBGINFO(":EE:"); DBGINFO(millis()); DBGINFO("] "); } return b; }
void Transceiver::ListenBroadcast() { if (Connected()){ if (timer.Cycle()<_helloCycle) return; // long xKC=(timer.Cycle()-_KnockCycle); //if (xKC< 7) //return; } else { if ((timer.Cycle() & 0x4) ==0) return; } DBGINFO("listenBroad "); DBGINFO(_KnockCycle); Wakeup(); DoListenBroadcast(); }
void Transceiver::Transmit() { if (RetryData()) { DBGINFO("Retry"); } delaySleepT2(1); ListenData(); }
void IMBuffer::printReceive() { for (unsigned short i=0;i<RX_buffer.len ;i++) { DBGINFO2(((uint8_t*)&RX_buffer)[i],HEX); DBGWRITE(" "); } DBGINFO("-> "); }
bool Transceiver::ParseFrame(IMFrame & rxFrame) { if (rxFrame.Knock()) { DBGINFO("\r\n receiveKnock "); if (ReceiveKnock(rxFrame)) { DBGINFO(" sendHello "); } DBGINFO(" \r\n"); return true; } else if (rxFrame.Hello()) { DBGINFO("HELLO"); if (ForwardHello(rxFrame)) DBGINFO(" FORW "); } else if (rxFrame.Welcome()) { if (ReceiveWelcome(rxFrame)) { DBGINFO(" Welcome "); return true; } } else if (Onward(rxFrame)) { DBGINFO(" Onward "); } else if (rxFrame.ACK()) { ReceiveACK(rxFrame); DBGINFO(" ACK "); } else { DBGINFO(" tue "); if (rxFrame.NeedACK()) SendACK(rxFrame); return false; } buffer->StartReceive(); return true; }
bool Transceiver::ReceiveWelcome(IMFrame & frame) { IMFrameSetup * setup =frame.Setup(); // DBGINFO("\r\n%MAC"); // DBGINFO(setup->MAC); // DBGINFO(":"); // DBGINFO(setup->MAC2); if (setup->MAC!=myMAC) { DBGINFO("*****NOT FORME "); DBGINFO(myMAC); BackwardWelcome(frame); return false; } //_helloed=_knocked +200; //we can wait on next connection timer.Watchdog(); serverId=frame.Header.SourceId; myId=setup->address; myChannel=setup->slavechannel; hostRssiSend=setup->rssi; router.myId=myId; HostChannel=0; myChannel=0; _calibrateshift=0; _connected=1; TimerSetup((myId &16)*10); // BroadcastEnable=(setup->mode && IMS_TRANSCEIVER); setupMode(setup->mode); if (myHop==2) { _calibrateshift=200; DBGINFO("C200SHIFT"); } _cycleshift=(timer.Cycle()+myId) % _cycledata; _helloCycle=timer.Cycle()+TimerHelloCycle*_cycledata;//setup next Hello DBGINFO(myId); DBGINFO("CONNECT%"); StopListenBroadcast(); // no listen until data stage return true; }
bool Transceiver::Forward(IMFrame & frame) { IMFrame _frame; _frame=frame; DBGINFO("FORWARD"); buffer->setChannel(HostChannel); _frame.Header.Function=frame.Header.Function | IMF_FORWARD; _frame.Header.ReceiverId=hostId; return Send(_frame); }
bool Transceiver::Backward(IMFrame & frame) { IMFrame _frame; _frame=frame; DBGINFO("BACKWARD"); _frame.Header.Function=frame.Header.Function | IMF_FORWARD; _frame.Header.ReceiverId=router.Repeater(frame.Header.DestinationId); buffer->setChannel(router.getChannel(_frame.Header.ReceiverId)); //get proper channel form router return Send(_frame); }
void Transceiver::Wakeup() { if (_inSleep){ _inSleep=false; power_spi_enable(); buffer->Wakeup(); DBGPINHIGH(); DBGINFO("wakeup"); } }
void Transceiver::Idle() { if (!_inSleep){ _inSleep=true; buffer->Sleep(); timer.setStage(IMTimer::IDDLESTAGE); power_spi_disable(); DBGPINLOW(); DBGINFO("idle"); } }
bool Transceiver::Send(IMFrame & frame) { if(NoRadio) return false; Prepare(frame); buffer->TX_buffer.packet=frame; // PrepareTransmit(); DBGINFO("Send<"); // printTime(); // buffer->printSend(); return buffer->Send(); }
bool Transceiver::GetFrame(IMFrame& frame) { // if (GetData()) { frame=buffer->RX_buffer.packet; bool io =( (frame.Header.ReceiverId==myId) || (frame.Header.ReceiverId==0)); if (!io) { DBGERR("Address"); DBGERR(frame.Header.ReceiverId); }; // if (io){ io= frame.checkCRC(); // } if (!io) { DBGERR("!!CRC "); DBGERR(frame.CRC()); }; DBGINFO(" RSSI: "); DBGINFO(Rssi()); DBGINFO("dBm "); return io; }
bool Transceiver::ReceiveKnock(IMFrame & frame) { IMFrameSetup *sp=frame.Setup(); if (Connected()) { if (myHost(frame)){ if (sp->salt!=_salt){ //host reboot Deconnect(); DBGINFO("HOST REBOOT"); } else { // timer.Calibrate(millis()-BroadcastDelay-100); } } else { DBGINFO(" alien host "); if (sp->salt==0) { //received invalid knock DBGINFO(" invalid "); } return false; } timer.Calibrate(millisT2()-BroadcastDelay-knockShift); } if (sp->salt==0) { //received invalid knock DBGINFO(" invalid "); return false; } _KnockCycle=timer.Cycle()+60; _salt=sp->salt; //accept new value hostRssiListen=buffer->rssiH; if (ResponseHello(frame)){ DoListenBroadcast(); //return to broadcas channel (wait to WELCOME) return true; } StopListenBroadcast(); // no listen until data stage return false; }
void Transceiver::StopListen() { if (Connected()){ if (timer.Cycle()<(_helloCycle+20)) //check 1min Idle(); if (timer.Cycle()>_helloCycle+100) //after 5min without knock Deconnect(); } else { if (timer.Cycle() >(_KnockCycle+60)){ // check 3 min DBGINFO("StopListen"); Idle(); } } }
void InitWillhabentracker::init() { DBGINIT(std::cerr, Logger::INFO | Logger::ERRO | Logger::VERB | Logger::DEBU) std::string config_filename = "/Users/minhdt/Documents/softwares/willhabentracker/config.cfg"; DBGINFO("Read config") ConfigurationWillhabentracker* config = ConfigurationWillhabentracker::instance(); config->readConfig(config_filename); if (!exists(config->pathDatabase())) createDir(config->pathDatabase()); }
/** ***************************************************************************** * @ingroup icp_hal * * @description * * @param * * @retval * * *****************************************************************************/ int halAe_checkAes(icp_firml_handle_t *handle, unsigned int aeMask) { unsigned int cnt, pre_cnt; unsigned char ae; int times = MAX_RETRY_TIMES; unsigned int stat = HALAE_SUCCESS; for(ae = 0; ae < MAX_AE; ae++) { if(!(aeMask & (1<<ae))) { continue; } times = MAX_RETRY_TIMES; stat = getAeCsr(handle, ae, PROFILE_COUNT, (unsigned int *)&cnt); if(stat != HALAE_SUCCESS) { PRINTF("AE%d CSR is unaccessible!!\n", ae); return HALAE_FAIL; } pre_cnt = cnt & 0xffff; do { stat = getAeCsr(handle, ae, PROFILE_COUNT, (unsigned int *)&cnt); if(stat != HALAE_SUCCESS) { PRINTF("AE%d CSR is unaccessible!!\n", ae); return HALAE_FAIL; } cnt &= 0xffff; if(cnt == pre_cnt) { times --; DBGINFO(("times=%d\n", times)); } else { break; } if(times <= 0) { PRINTF("AE%d is useless!!\n", ae); return HALAE_FAIL; } } while(1); } return HALAE_SUCCESS; }
void Transceiver::Knock() { if (timer.Watchdog(1200)) //1hour { DBGINFO("WATCHDOG"); Deconnect(); buffer->Reboot(); } if (Connected()) { if (BroadcastEnable){ if ((timer.Cycle() % TimerKnockCycle)==0){ DBGINFO("Knock "); SendKnock(false); DBGINFO("\r\n"); return; } ListenData(); } StopListenBroadcast(); } else { if ((timer.Cycle() % (TimerKnockCycle))==0){ if (_cycleshift){ //hello sended _cycleshift=0; }else{ // ERRFLASH(); DBGINFO("InvalidKnock "); SendKnock(true); DoListenBroadcast(); DBGINFO("\r\n"); // ERRFLASH(); } // timer.Watchdog(); } } }
/** * form factor of a mass fractal consisting of spheres with a radius R, a * fractal dimesnion of D, a cut-off length of xi and a scattering length * density eta */ scalar sasfit_sq_MassFractalGaussianCutOff(scalar q, sasfit_param * param) { scalar P16, r0, xi, D; int status; gsl_sf_result pFq_1F1; SASFIT_ASSERT_PTR( param ); sasfit_get_param(param, 3, &r0, &xi, &D); gsl_set_error_handler_off(); SASFIT_CHECK_COND1((q < 0.0), param, "q(%lg) < 0",q); SASFIT_CHECK_COND1((r0 <= 0.0), param, "r0(%lg) <= 0",r0); SASFIT_CHECK_COND2((xi < r0), param, "xi(%lg) < r0(%lg)",xi,r0); SASFIT_CHECK_COND1((D <= 1.0), param, "D(%lg) <= 1",D); if ((xi == 0) || (r0 == 0)) { return 1.0; } P16 = gsl_sf_gamma(D/2.)*D/2.; P16 = P16*pow(xi/r0,D); status = gsl_sf_hyperg_1F1_e(D/2.,1.5,-0.25*pow(q*xi,2.),&pFq_1F1); if (status && (q*xi >= 10)) { pFq_1F1.val = (sqrt(M_PI)*(pow(2.,D)/(pow(q,D)*pow(pow(xi,2),D/2.)*gsl_sf_gamma(1.5 - D/2.)) + (pow(4,1.5 - D/2.)*pow(q,-3 + D)*pow(-pow(xi,2),-1.5 + D/2.))/ (exp((pow(q,2)*pow(xi,2))/4.)*gsl_sf_gamma(D/2.))))/2. ; // gsl_sf_gamma(1.5)/gsl_sf_gamma(1.5-D/2.0)*pow(0.25*pow(q*xi,2.),D/2.); } else if (status && (q*xi < 10)) { sasfit_param_set_err(param, DBGINFO("%s,q=%lf"), gsl_strerror(status), q); return SASFIT_RETURNVAL_ON_ERROR; } else { return 1.0+P16*pFq_1F1.val; } return P16; }
/** ***************************************************************************** * @ingroup icp_hal * * @description * Enable eSram auto initialization * * @assumptions * None * @sideEffects * None * @blocking * No * @reentrant * No * @threadSafe * Yes * * @param handle - IN * * @retval HALAE_SUCCESS Operation was successful * @retval HALAE_FAIL Operation failed * * *****************************************************************************/ int halAe_enableAutoInitSram(icp_firml_handle_t *handle, unsigned int aeMask) { int status = HALAE_SUCCESS; unsigned int debugB = 0, csr = ESRAM_DEBUGB; int times = SRAMAUTO_INIT_TIMES; int ae; /* if on BEK, just return, no secure RAM in Roslin */ if ((handle->sysMemInfo.deviceId == ICP_ACCELCOMP_B_PCIE_DEVICE_ID_AC) || (handle->sysMemInfo.deviceId == ICP_ACCELCOMP_RS_PCIE_DEVICE_ID_AC)) { return HALAE_SUCCESS; } if (handle->sysMemInfo.deviceId == ICP_ACCELCOMP_C_PCIE_DEVICE_ID_AC) { csr = ESRAM_DEBUGB_ACCELCOMP_C; } /* return if init is done */ debugB = READ_LWORD(handle->Hal_ep_csr_virtAddr + csr); if ((debugB & DEBUGB_SRAMAUTO_TINIT) && (debugB & DEBUGB_SRAMAUTO_TINITDONE)) { return HALAE_SUCCESS; } /* get an available AE */ for (ae=0; ae<MAX_AE; ae++) { if(((1<<ae)& aeMask) && (halAe_GetAeState(handle, (unsigned char)ae) == HALAE_CLR_RST)) { break; } } if (ae>=MAX_AE) { PRINTF("could not find right ae\n"); return (HALAE_FAIL); } /* enable eSram Auto Initialization */ debugB = READ_LWORD(handle->Hal_ep_csr_virtAddr + csr); debugB |= DEBUGB_SRAMAUTO_TINIT; WRITE_LWORD(handle->Hal_ep_csr_virtAddr + csr, debugB); /* check if eSram auto initialization is done */ do { /* All 4 SRAM are initialized in parallel * and take 8200 p_clk (~10 usecs) */ waitNumCycles(handle, (unsigned char)ae, SRAMAUTO_INIT_USECS, 0); debugB = READ_LWORD(handle->Hal_ep_csr_virtAddr + csr); times --; DBGINFO(("times=%d, debugB=0x%x\n", times, debugB)); } while(!(debugB & DEBUGB_SRAMAUTO_TINITDONE) && (times>0)); if((times == 0) && (!(debugB & DEBUGB_SRAMAUTO_TINITDONE))) { PRINTF("Fail to enable eSram auto initialization!!\n"); status = HALAE_FAIL; } return status; }
void Transceiver::printStatus() { DBGINFO(" RSSI "); DBGINFO(RssiListen()); DBGINFO(" "); DBGINFO(RssiSend()); DBGINFO(" dBm "); DBGINFO(" Deviation "); DBGINFO(timer.DeviationPlus); DBGINFO(" "); DBGINFO(timer.DeviationMinus); DBGINFO(" "); DBGINFO(_calibrate); DBGINFO(" cykl: "); DBGINFO(timer.Cycle()); DBGINFO(" "); DBGINFO(_cycleshift); DBGINFO(" > "); DBGINFO(_cycledata); }