void rLevel1_t::ITask() { while(true) { #if 0 // Demo // if(App.Mode == 0b0001) { // RX // int8_t Rssi; // Color_t Clr; // uint8_t RxRslt = CC.ReceiveSync(RX_T_MS, &Pkt, &Rssi); // if(RxRslt == OK) { // Uart.Printf("\rRssi=%d", Rssi); // Clr = clWhite; // if (Rssi < -100) Clr = clRed; // else if(Rssi < -90) Clr = clYellow; // else if(Rssi < -80) Clr = clGreen; // else if(Rssi < -70) Clr = clCyan; // else if(Rssi < -60) Clr = clBlue; // else if(Rssi < -50) Clr = clMagenta; // } // else Clr = clBlack; // Led.SetColor(Clr); chThdSleepMilliseconds(99); // } // else { // TX // DBG1_SET(); // CC.TransmitSync(&Pkt); // DBG1_CLR(); //// chThdSleepMilliseconds(99); // } #else // ==== Transmitter ==== if(App.IsTransmitter) { Pkt.DWord = TESTWORD; Pkt.Brightness = App.Brightness; DBG1_SET(); CC.TransmitSync(&Pkt); DBG1_CLR(); } // ==== Receiver ==== else { DBG2_SET(); int8_t Rssi; uint8_t RxRslt = CC.ReceiveSync(RX_T_MS, &Pkt, &Rssi); if(RxRslt == OK and Pkt.DWord == TESTWORD) { Uart.Printf("\rRssi=%d; Brt=%u", Rssi, Pkt.Brightness); App.Brightness = Pkt.Brightness; App.SignalEvt(EVTMSK_NEW_BRT); } DBG2_CLR(); } #endif } // while true }
void radio_t::ITask() { while(true) { // New cycle begins CC.Recalibrate(); // Recalibrate manually every cycle, as auto recalibration disabled #ifdef TX // Transmit DBG1_SET(); CC.TransmitSync(&PktTx); DBG1_CLR(); chThdSleepMilliseconds(99); #elif defined RX uint8_t RxRslt = CC.ReceiveSync(306, &PktRx); if(RxRslt == OK) { Uart.Printf("%d\r", PktRx.RSSI); } #else //IterateEmanators(); // Uart.Printf("%d\r", Damage); chThdSleepMilliseconds(45); #endif } // while true }
__NORETURN void rLevel1_t::ITask() { __unused uint8_t OldID = 0; while(true) { int8_t Rssi; // Led2.SetLo(); uint8_t RxRslt = CC.ReceiveSync(RX_T_MS, &Pkt, &Rssi); if(RxRslt == OK) { // Led2.SetHi(); // Uart.Printf("\rRssi=%d", Rssi); #if USB_ENABLED UsbCDC.Printf("%05u ", Pkt.Time); for(uint8_t i=0; i<9; i++) UsbCDC.Printf("%03d ", Pkt.SnsData[i]); UsbCDC.Printf("\r\n"); #endif } #if 0 // Demo if(App.Mode == 0b0001) { // RX int8_t Rssi; Color_t Clr; uint8_t RxRslt = CC.ReceiveSync(RX_T_MS, &Pkt, &Rssi); if(RxRslt == OK) { Uart.Printf("\rRssi=%d", Rssi); Clr = clWhite; if (Rssi < -100) Clr = clRed; else if(Rssi < -90) Clr = clYellow; else if(Rssi < -80) Clr = clGreen; else if(Rssi < -70) Clr = clCyan; else if(Rssi < -60) Clr = clBlue; else if(Rssi < -50) Clr = clMagenta; } else Clr = clBlack; Led.SetColor(Clr); chThdSleepMilliseconds(99); } else { // TX DBG1_SET(); CC.TransmitSync(&Pkt); DBG1_CLR(); // chThdSleepMilliseconds(99); } //#else #endif #if 0 // ==== Transmitter ==== if(App.MustTransmit) { if(App.ID != OldID) { OldID = App.ID; CC.SetChannel(ID2RCHNL(App.ID)); Pkt.DWord = App.ID; } DBG1_SET(); CC.TransmitSync(&Pkt); DBG1_CLR(); } // ==== Receiver ==== else { DBG2_SET(); // Listen if nobody found, and do not if found int8_t Rssi; // Iterate channels for(int32_t i = ID_MIN; i <= ID_MAX; i++) { if(i == App.ID) continue; // Do not listen self CC.SetChannel(ID2RCHNL(i)); uint8_t RxRslt = CC.ReceiveSync(RX_T_MS, &Pkt, &Rssi); if(RxRslt == OK) { // Uart.Printf("\rCh=%d; Rssi=%d", i, Rssi); App.SignalEvt(EVTMSK_SOMEONE_NEAR); break; // No need to listen anymore if someone already found } } // for CC.SetChannel(ID2RCHNL(App.ID)); // Set self channel back DBG2_CLR(); TryToSleep(RX_SLEEP_T_MS); } #endif } // while true }