mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2026-12-06 15:47:35 +00:00
S.Port: no broken packets when the radio pushes too fast, no stalls after a full buffer (#1224)
* S.Port: drop a radio packet when the downlink buffer is full SportQueue() wrote the stuffed packet without checking for room: a radio pushing faster than the RF link drains (8 bytes per frame) wrapped the 64-byte SportData ring over the bytes not sent yet, and the receivers got broken S.Port frames. Now the whole new packet is dropped when it doesn't fit (stuffed length 9 + 1 per 7D/7E byte). The buffer low flag is set as before, and also on a drop. * S.Port: report the downlink buffer state once, also when it has room The buffer low flag was cleared silently, so the radio only learnt at the next periodic status (up to 500 ms) and held its packets with the buffer empty: 442 B/s instead of ~1150 B/s with the flag honoured (4-in-1 and MPM v2 benches). Send the status as soon as the flag clears. While the flag is set, the status is no longer forced again on every packet: only when the flag gets set, the periodic status repeats it. --------- Co-authored-by: Raphael Coeffic <1050031+raphaelcoeffic@users.noreply.github.com>
This commit is contained in:
1 parent
fd08975a03
commit
1056d13dad
2 files changed
+31
-34
No files matched your search
@@ -449,9 +449,10 @@ void Frsky_init_clone(void)
|
||||
used += MAX_SPORT_BUFFER - SportHead ;
|
||||
else
|
||||
used -= SportHead ;
|
||||
if ( used < (MAX_SPORT_BUFFER>>1) )
|
||||
{
|
||||
if ( used < (MAX_SPORT_BUFFER>>1) && IS_DATA_BUFFER_LOW_on )
|
||||
{// The status at once: the radio sends again
|
||||
DATA_BUFFER_LOW_off;
|
||||
SEND_MULTI_STATUS_on;
|
||||
debugln("Ok buf:%d",used);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -701,43 +701,39 @@ void SportQueue(const uint8_t *b)
|
||||
#define BYTE_STUFF 0x7D
|
||||
#define STUFF_MASK 0x20
|
||||
//debug("SPort_in: ");
|
||||
boolean sport_valid=false;
|
||||
//Stuffed packet: 7E, physical ID, 7 bytes, 1 more per 7D/7E
|
||||
uint8_t pkt[16], len=2, nz=0;
|
||||
pkt[0]=0x7E;
|
||||
pkt[1]=b[0]&0x1F;
|
||||
for(uint8_t i=1;i<8;i++)
|
||||
if(b[i]!=0) sport_valid=true; //Check that the payload is not full of 0
|
||||
if((b[0]&0x1F) > 0x1B) //Check 1st byte validity
|
||||
sport_valid=false;
|
||||
if(sport_valid)
|
||||
{
|
||||
SportData[SportTail]=0x7E;
|
||||
SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1);
|
||||
SportData[SportTail]=b[0]&0x1F;
|
||||
SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1);
|
||||
for(uint8_t i=1;i<8;i++)
|
||||
uint8_t c=b[i];
|
||||
nz|=c;
|
||||
if( (c==BYTE_STUFF) || (c==0x7E) )
|
||||
{//stuff
|
||||
pkt[len++]=BYTE_STUFF;
|
||||
c^=STUFF_MASK;
|
||||
}
|
||||
pkt[len++]=c;
|
||||
}
|
||||
if(nz==0 || pkt[1] > 0x1B)
|
||||
return; //Payload full of 0 or bad 1st byte
|
||||
uint8_t used = (SportTail - SportHead) & (MAX_SPORT_BUFFER-1);
|
||||
if(used + len < MAX_SPORT_BUFFER)
|
||||
{//Room for it, else the whole packet is dropped: never overwrite the bytes not sent yet
|
||||
for(uint8_t i=0;i<len;i++)
|
||||
{
|
||||
if( (b[i]==BYTE_STUFF) || (b[i]==0x7E) )
|
||||
{//stuff
|
||||
SportData[SportTail]=BYTE_STUFF;
|
||||
SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1);
|
||||
SportData[SportTail]=b[i]^STUFF_MASK;
|
||||
}
|
||||
else
|
||||
SportData[SportTail]=b[i];
|
||||
//debug("%02X ",SportData[SportTail]);
|
||||
SportData[SportTail]=pkt[i];
|
||||
SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1);
|
||||
}
|
||||
uint8_t used = SportTail;
|
||||
if ( SportHead > SportTail )
|
||||
used += MAX_SPORT_BUFFER - SportHead ;
|
||||
else
|
||||
used -= SportHead ;
|
||||
if ( used >= MAX_SPORT_BUFFER-(MAX_SPORT_BUFFER>>2) )
|
||||
{
|
||||
DATA_BUFFER_LOW_on;
|
||||
//Send Multi Status ASAP to inform the TX
|
||||
SEND_MULTI_STATUS_on;
|
||||
Update_Telem();
|
||||
debugln("Low buf=%d,h=%d,t=%d",used,SportHead,SportTail);
|
||||
}
|
||||
used += len;
|
||||
}
|
||||
if ( used >= MAX_SPORT_BUFFER-(MAX_SPORT_BUFFER>>2) && IS_DATA_BUFFER_LOW_off )
|
||||
{
|
||||
DATA_BUFFER_LOW_on;
|
||||
//Send Multi Status ASAP to inform the TX (Update_All() calls Update_Telem() next)
|
||||
SEND_MULTI_STATUS_on;
|
||||
debugln("Low buf=%d,h=%d,t=%d",used,SportHead,SportTail);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user