More regular transmissions, although still randomized

pull/30/head
Pawel Jalocha 2020-12-29 00:01:29 +00:00
rodzic 59063d965f
commit aeec572e1e
3 zmienionych plików z 27 dodań i 18 usunięć

Wyświetl plik

@ -271,7 +271,7 @@ static void ReadStatus(OGN_Packet &Packet)
Line[Len++]=',';
Len+=Format_SignDec(Line+Len, -5*TRX.averRSSI, 2, 1); // average RF level (over all channels)
Line[Len++]=',';
Len+=Format_UnsDec(Line+Len, (uint16_t)TX_Credit);
Len+=Format_SignDec(Line+Len, TX_Credit/100, 2, 1);
Line[Len++]=',';
Len+=Format_SignDec(Line+Len, (int16_t)TRX.chipTemp); // the temperature of the RF chip
Line[Len++]=',';
@ -609,8 +609,11 @@ void vTaskPROC(void* pvParameters)
xSemaphoreGive(CONS_Mutex);
#endif
XorShift32(RX_Random);
if( (AverSpeed>10) || ((RX_Random&0x3)==0) ) // send only some positions if the speed is less than 1m/s
RF_TxFIFO.Write(); // complete the write into the TxFIFO
static uint8_t TxBackOff=0;
if(TxBackOff) TxBackOff--;
else
{ RF_TxFIFO.Write(); // complete the write into the TxFIFO
TxBackOff = AverSpeed>=10 ? 1 : 3+(RX_Random&0x1); }
Position->Sent=1;
#ifdef WITH_FANET
if( (SlotTime&0x07)==(RX_Random&0x07) ) // every 8sec
@ -747,15 +750,16 @@ void vTaskPROC(void* pvParameters)
StatPacket.Packet.Status.Hardware=HARDWARE_ID;
StatPacket.Packet.Status.Firmware=SOFTWARE_ID;
static uint8_t StatTxBackOff = 16;
ReadStatus(StatPacket.Packet); // read status data and put them into the StatPacket
XorShift32(RX_Random); // generate a new random number
if( ((RX_Random&0x0F)==0) && (RF_TxFIFO.Full()<2) ) // decide whether to transmit the status/info packet
if( StatTxBackOff==0 && RF_TxFIFO.Full()<2 ) // decide whether to transmit the status/info packet
{ OGN_TxPacket<OGN_Packet> *StatusPacket = RF_TxFIFO.getWrite(); // ask for space in the Tx queue
uint8_t doTx=1;
if(RX_Random&0x10) // decide to transmit info packet, not status
if(RX_Random&0x10) // decide to transmit info or status packet ?
{ doTx=ReadInfo(StatPacket.Packet); } // and overwrite the StatPacket with the Info data
if(doTx)
{
{ StatTxBackOff=16+(RX_Random%15);
#ifdef WITH_LOG
FlashLog(&StatPacket, PosTime); // log the status packet
#endif
@ -765,6 +769,7 @@ void vTaskPROC(void* pvParameters)
RF_TxFIFO.Write(); // finalize write into the Tx queue
}
}
if(StatTxBackOff) StatTxBackOff--;
while(RF_TxFIFO.Full()<2)
{ OGN_TxPacket<OGN_Packet> *RelayPacket = RF_TxFIFO.getWrite();

Wyświetl plik

@ -41,7 +41,7 @@ static uint32_t RF_SlotTime; // [sec] UTC time which belongs to t
FIFO<FANET_Packet, 4> FNT_TxFIFO;
#endif
uint16_t TX_Credit =0; // counts transmitted packets vs. time to avoid using more than 1% of the time
int32_t TX_Credit = 0; // [ms] counts transmitter time avoid using more than 1%
uint8_t RX_OGN_Packets=0; // [packets] counts received packets
static LowPass2<uint32_t, 4,2,4> RX_RSSI; // low pass filter to average the RX noise
@ -156,8 +156,8 @@ static void TimeSlot(uint8_t TxChan, uint32_t SlotLen, const uint8_t *PacketByte
if( (TxTime==0) || (TxTime>=MaxTxTime) ) TxTime = RX_Random%MaxTxTime; // if TxTime out of limits, setup a random TxTime
TickType_t Tx = Start + TxTime; // Tx = the moment to start transmission
ReceiveUntil(Tx); // listen until this time comes
if( (TX_Credit) && (PacketByte) ) // when packet to transmit is given and there is still TX credit left:
TX_Credit-=Transmit(TxChan, PacketByte, Rx_RSSI, MaxWait); // attempt to transmit the packet
if( (TX_Credit>0) && (PacketByte) ) // when packet to transmit is given and there is still TX credit left:
if(Transmit(TxChan, PacketByte, Rx_RSSI, MaxWait)) TX_Credit-=5; // attempt to transmit the packet
ReceiveUntil(End); // listen till the end of the time-slot
}
@ -402,7 +402,7 @@ extern "C"
} while(TimeSync_msTime()<350); // keep going until 400 ms after PPS
RX_RSSI.Process(RxRssiSum/RxRssiCount); // [-0.5dBm] average noise on channel
TX_Credit+=2; if(TX_Credit>7200) TX_Credit=7200; // count the transmission credit
TX_Credit+=1000; if(TX_Credit>3600000) TX_Credit=3600000; // [ms] count the transmission credit
XorShift32(RX_Random);
uint32_t TxTime = (RX_Random&0x3F)+1; TxTime*=6; TxTime+=50; // random transmission time: (1..64)*6+50 [ms]
@ -478,8 +478,8 @@ extern "C"
uint16_t SlotEnd = 1240;
if(WAN_BackOff) WAN_BackOff--;
else // decide to transmit in this slot
{ if(WANdev.State==0 || WANdev.State==2) //
{ XorShift32(RX_Random); if((RX_Random&0x1F)==0x10) { WANtx=1; SlotEnd=1200; } } // random decision 1/32
{ if(WANdev.State==0 || WANdev.State==2) //
{ WANtx=1; SlotEnd=1200; }
}
TimeSlot(TxChan, SlotEnd-TimeSync_msTime(), TxPktData1, TRX.averRSSI, 0, TxTime);
#else
@ -487,6 +487,7 @@ extern "C"
#endif
#ifdef WITH_PAW
static uint8_t PAWtxBackOff = 4;
#ifdef WITH_LORAWAN
if(!WANtx && TxPkt0)
#else
@ -496,7 +497,7 @@ extern "C"
OGN1_Packet TxPkt = TxPkt0->Packet;
TxPkt.Dewhiten();
XorShift32(RX_Random);
if(!TxPkt.Header.Relay && (RX_Random&0xC0)==0x00 && Packet.Copy(TxPkt) && TxPkt.Position.Time<60)
if(PAWtxBackOff==0 && !TxPkt.Header.Relay && Packet.Copy(TxPkt) && TxPkt.Position.Time<60)
{ TRX.WriteMode(RF_OPMODE_STANDBY);
TRX.PAW_Configure(PAW_SYNC);
TRX.WriteTxPower(Parameters.TxPower+6);
@ -511,8 +512,11 @@ extern "C"
if(Flags&RF_IRQ_PacketSent) Break++;
if(Break>=2) break; }
TRX.WriteMode(RF_OPMODE_STANDBY);
TRX.OGN_Configure(0, OGN_SYNC); }
TRX.OGN_Configure(0, OGN_SYNC);
PAWtxBackOff = 2+(RX_Random%5); XorShift32(RX_Random);
TX_Credit-=8; }
}
if(PAWtxBackOff) PAWtxBackOff--;
#endif
#ifdef WITH_LORAWAN
@ -531,8 +535,8 @@ extern "C"
int TxPktLen=0;
if(WANdev.State==0)
{ uint8_t *TxPacket; TxPktLen=WANdev.getJoinRequest(&TxPacket); // produce Join-Request packet
TRX.LoRa_SendPacket(TxPacket, TxPktLen); RespDelay=5000; // transmit join-request packet
WAN_BackOff=30;
TRX.LoRa_SendPacket(TxPacket, TxPktLen); RespDelay=5000; // transmit join-request packet
WAN_BackOff=48+(RX_Random%21); XorShift32(RX_Random);
} else if(WANdev.State==2)
{ const uint8_t *PktData=TxPktData0;
if(PktData==0) PktData=TxPktData1;
@ -546,7 +550,7 @@ extern "C"
else
{ TxPktLen=WANdev.getDataPacket(&TxPacket, PktData, 20, 1, ((RX_Random>>16)&0xF)==0x8 ); }
TRX.LoRa_SendPacket(TxPacket, TxPktLen); RespDelay=1000;
WAN_BackOff=32; }
WAN_BackOff=50+(RX_Random%21); XorShift32(RX_Random); }
}
if(RespDelay)
{ vTaskDelay(8);

Wyświetl plik

@ -29,7 +29,7 @@
// extern int8_t RF_Temp; // [degC] temperature of the RF chip: uncalibrated
extern RFM_TRX TRX; // RF transceiver
extern FreqPlan RF_FreqPlan; // frequency hopping pattern calculator
extern uint16_t TX_Credit; // counts transmitted packets vs. time to avoid using more than 1% of the time
extern int32_t TX_Credit; // [ms] counts transmitter time to avoid using more than 1%
extern uint16_t RX_OGN_Count64; // counts received packets for the last 64 seconds
extern uint32_t RX_Random; // Random number from LSB of RSSI readouts