mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-02-04 22:48:12 +00:00
Data Buffer signaling
This commit is contained in:
parent
bf61295b76
commit
431808286b
@ -27,7 +27,7 @@ uint8_t FrSkyX_RX_Seq ;
|
|||||||
struct t_FrSkyX_TX_Frame
|
struct t_FrSkyX_TX_Frame
|
||||||
{
|
{
|
||||||
uint8_t count;
|
uint8_t count;
|
||||||
uint8_t payload[6];
|
uint8_t payload[8];
|
||||||
} ;
|
} ;
|
||||||
// Store FrskyX telemetry
|
// Store FrskyX telemetry
|
||||||
struct t_FrSkyX_TX_Frame FrSkyX_TX_Frames[4] ;
|
struct t_FrSkyX_TX_Frame FrSkyX_TX_Frames[4] ;
|
||||||
@ -196,46 +196,58 @@ static void __attribute__((unused)) FrSkyX_build_packet()
|
|||||||
#ifdef SPORT_SEND
|
#ifdef SPORT_SEND
|
||||||
if (FrSkyX_TX_IN_Seq!=0xFF)
|
if (FrSkyX_TX_IN_Seq!=0xFF)
|
||||||
{//RX has replied at least once
|
{//RX has replied at least once
|
||||||
debugln("R:%X,T:%X",FrSkyX_TX_IN_Seq,FrSkyX_TX_Seq);
|
|
||||||
if (FrSkyX_TX_IN_Seq & 0x08)
|
if (FrSkyX_TX_IN_Seq & 0x08)
|
||||||
{//Request init
|
{//Request init
|
||||||
debugln("Init");
|
//debugln("Init");
|
||||||
FrSkyX_TX_Seq = 0 ;
|
FrSkyX_TX_Seq = 0 ;
|
||||||
for(uint8_t i=0;i<4;i++)
|
for(uint8_t i=0;i<4;i++)
|
||||||
FrSkyX_TX_Frames[i].count=0; // discard frames in current output buffer
|
FrSkyX_TX_Frames[i].count=0; // discard frames in current output buffer
|
||||||
}
|
}
|
||||||
else if (FrSkyX_TX_IN_Seq & 0x04)
|
else if (FrSkyX_TX_IN_Seq & 0x04)
|
||||||
{//Retransmit the requested packet
|
{//Retransmit the requested packet
|
||||||
debugln("Retr:%d",FrSkyX_TX_IN_Seq&0x03);
|
debugln("Retry:%d",FrSkyX_TX_IN_Seq&0x03);
|
||||||
|
packet[21] |= FrSkyX_TX_IN_Seq&0x03;
|
||||||
|
packet[22] = FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq&0x03].count;
|
||||||
for (uint8_t i=23;i<23+FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq&0x03].count;i++)
|
for (uint8_t i=23;i<23+FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq&0x03].count;i++)
|
||||||
packet[i] = FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq&0x03].payload[i];
|
packet[i] = FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq&0x03].payload[i];
|
||||||
packet[22] = FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq&0x03].count;
|
|
||||||
packet[21] |= FrSkyX_TX_IN_Seq&0x03;
|
|
||||||
}
|
}
|
||||||
else if ( FrSkyX_TX_Seq != 0x08 )
|
else if ( FrSkyX_TX_Seq != 0x08 )
|
||||||
{
|
{
|
||||||
if(FrSkyX_TX_IN_Seq==FrSkyX_TX_Seq)
|
if(FrSkyX_TX_Seq==FrSkyX_TX_IN_Seq)
|
||||||
{//Send packet from the incoming radio buffer
|
{//Send packet from the incoming radio buffer
|
||||||
|
//debugln("Send:%d",FrSkyX_TX_Seq);
|
||||||
|
packet[21] |= FrSkyX_TX_Seq;
|
||||||
uint8_t nbr_bytes=0;
|
uint8_t nbr_bytes=0;
|
||||||
for (uint8_t i=23;i<limit;i++)
|
for (uint8_t i=23;i<limit;i++)
|
||||||
{
|
{
|
||||||
if(SportHead==SportTail)
|
if(SportHead==SportTail)
|
||||||
break; //buffer empty
|
break; //buffer empty
|
||||||
FrSkyX_TX_Frames[FrSkyX_TX_Seq].payload[i-23]=packet[i]=SportData[SportHead];
|
packet[i]=SportData[SportHead];
|
||||||
|
FrSkyX_TX_Frames[FrSkyX_TX_Seq].payload[i-23]=SportData[SportHead];
|
||||||
SportHead=(SportHead+1) & (MAX_SPORT_BUFFER-1);
|
SportHead=(SportHead+1) & (MAX_SPORT_BUFFER-1);
|
||||||
nbr_bytes++;
|
nbr_bytes++;
|
||||||
}
|
}
|
||||||
FrSkyX_TX_Frames[FrSkyX_TX_Seq].count=packet[22]=nbr_bytes;
|
packet[22]=nbr_bytes;
|
||||||
packet[21] |= FrSkyX_TX_Seq;
|
FrSkyX_TX_Frames[FrSkyX_TX_Seq].count=nbr_bytes;
|
||||||
|
if(nbr_bytes)
|
||||||
|
{//Check the buffer status
|
||||||
|
uint8_t used = SportTail;
|
||||||
|
if ( SportHead >= SportTail )
|
||||||
|
used += MAX_SPORT_BUFFER - SportHead ;
|
||||||
|
else
|
||||||
|
used -= SportHead ;
|
||||||
|
if ( used < (MAX_SPORT_BUFFER>>1) )
|
||||||
|
DATA_BUFFER_LOW_off;
|
||||||
|
}
|
||||||
FrSkyX_TX_Seq = ( FrSkyX_TX_Seq + 1 ) & 0x03 ; // Next iteration send next packet
|
FrSkyX_TX_Seq = ( FrSkyX_TX_Seq + 1 ) & 0x03 ; // Next iteration send next packet
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{//Retransmit the last packet
|
{//Not in sequence somehow, transmit what the receiver wants but why not asking for retransmit...
|
||||||
debugln("Retr:%d",FrSkyX_TX_IN_Seq);
|
debugln("RX_Seq:%d,TX:%d",FrSkyX_TX_IN_Seq,FrSkyX_TX_Seq);
|
||||||
for (uint8_t i=23;i<23+FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq].count;i++)
|
|
||||||
packet[i] = FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq].payload[i];
|
|
||||||
packet[22] = FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq].count;
|
|
||||||
packet[21] |= FrSkyX_TX_IN_Seq;
|
packet[21] |= FrSkyX_TX_IN_Seq;
|
||||||
|
packet[22] = FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq].count;
|
||||||
|
for (uint8_t i=23;i<23+FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq].count;i++)
|
||||||
|
packet[i] = FrSkyX_TX_Frames[FrSkyX_TX_IN_Seq].payload[i-23];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -243,7 +255,7 @@ static void __attribute__((unused)) FrSkyX_build_packet()
|
|||||||
}
|
}
|
||||||
if(packet[22])
|
if(packet[22])
|
||||||
{//Debug
|
{//Debug
|
||||||
debug("SPort_out: ");
|
debug("SP: ");
|
||||||
for(uint8_t i=0;i<packet[22];i++)
|
for(uint8_t i=0;i<packet[22];i++)
|
||||||
debug("%02X ",packet[23+i]);
|
debug("%02X ",packet[23+i]);
|
||||||
debugln("");
|
debugln("");
|
||||||
@ -373,6 +385,7 @@ uint16_t initFrSkyX()
|
|||||||
#ifdef SPORT_SEND
|
#ifdef SPORT_SEND
|
||||||
for(uint8_t i=0;i<4;i++)
|
for(uint8_t i=0;i<4;i++)
|
||||||
FrSkyX_TX_Frames[i].count=0; // discard frames in current output buffer
|
FrSkyX_TX_Frames[i].count=0; // discard frames in current output buffer
|
||||||
|
SportHead=SportTail=0; // empty data buffer
|
||||||
#endif
|
#endif
|
||||||
FrSkyX_RX_Seq = 0 ; // Seq 0 to start with
|
FrSkyX_RX_Seq = 0 ; // Seq 0 to start with
|
||||||
return 10000;
|
return 10000;
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
#define VERSION_MAJOR 1
|
#define VERSION_MAJOR 1
|
||||||
#define VERSION_MINOR 3
|
#define VERSION_MINOR 3
|
||||||
#define VERSION_REVISION 0
|
#define VERSION_REVISION 0
|
||||||
#define VERSION_PATCH_LEVEL 5
|
#define VERSION_PATCH_LEVEL 6
|
||||||
|
|
||||||
//******************
|
//******************
|
||||||
// Protocols
|
// Protocols
|
||||||
@ -405,6 +405,15 @@ enum MultiPacketTypes
|
|||||||
#define WAIT_BIND_on protocol_flags2 |= _BV(7)
|
#define WAIT_BIND_on protocol_flags2 |= _BV(7)
|
||||||
#define IS_WAIT_BIND_on ( ( protocol_flags2 & _BV(7) ) !=0 )
|
#define IS_WAIT_BIND_on ( ( protocol_flags2 & _BV(7) ) !=0 )
|
||||||
#define IS_WAIT_BIND_off ( ( protocol_flags2 & _BV(7) ) ==0 )
|
#define IS_WAIT_BIND_off ( ( protocol_flags2 & _BV(7) ) ==0 )
|
||||||
|
//Incoming telemetry data buffer
|
||||||
|
#define DATA_BUFFER_LOW_off protocol_flags3 &= ~_BV(0)
|
||||||
|
#define DATA_BUFFER_LOW_on protocol_flags3 |= _BV(0)
|
||||||
|
#define IS_DATA_BUFFER_LOW_on ( ( protocol_flags3 & _BV(0) ) !=0 )
|
||||||
|
#define IS_DATA_BUFFER_LOW_off ( ( protocol_flags3 & _BV(0) ) ==0 )
|
||||||
|
#define SEND_MULTI_STATUS_off protocol_flags3 &= ~_BV(1)
|
||||||
|
#define SEND_MULTI_STATUS_on protocol_flags3 |= _BV(1)
|
||||||
|
#define IS_SEND_MULTI_STATUS_on ( ( protocol_flags3 & _BV(1) ) !=0 )
|
||||||
|
#define IS_SEND_MULTI_STATUS_off ( ( protocol_flags3 & _BV(1) ) ==0 )
|
||||||
|
|
||||||
// Failsafe
|
// Failsafe
|
||||||
#define FAILSAFE_CHANNEL_HOLD 2047
|
#define FAILSAFE_CHANNEL_HOLD 2047
|
||||||
@ -597,7 +606,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
|
|||||||
Stream[0] = 0x56 sub_protocol values are 32..63 Stream contains failsafe
|
Stream[0] = 0x56 sub_protocol values are 32..63 Stream contains failsafe
|
||||||
Stream[0] = 0x53 sub_protocol values are 64..95 Stream contains failsafe
|
Stream[0] = 0x53 sub_protocol values are 64..95 Stream contains failsafe
|
||||||
Stream[0] = 0x52 sub_protocol values are 96..127 Stream contains failsafe
|
Stream[0] = 0x52 sub_protocol values are 96..127 Stream contains failsafe
|
||||||
Stream[0] |= 0x20 any of the above + 8 additional bytes at the end of the stream available for the current sub_protocol
|
Stream[0] |= 0x20 any of the above + 8 additional data bytes at the end of the stream available for the current sub_protocol
|
||||||
header
|
header
|
||||||
Stream[1] = sub_protocol|BindBit|RangeCheckBit|AutoBindBit;
|
Stream[1] = sub_protocol|BindBit|RangeCheckBit|AutoBindBit;
|
||||||
sub_protocol is 0..31 (bits 0..4), value should be added with 32 if Stream[0] = 0x54 | 0x56
|
sub_protocol is 0..31 (bits 0..4), value should be added with 32 if Stream[0] = 0x54 | 0x56
|
||||||
@ -834,7 +843,8 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
|
|||||||
0x04 = Protocol is valid
|
0x04 = Protocol is valid
|
||||||
0x08 = Module is in binding mode
|
0x08 = Module is in binding mode
|
||||||
0x10 = Module waits a bind event to load the protocol
|
0x10 = Module waits a bind event to load the protocol
|
||||||
0x20 = Failsafe supported by currently running protocol
|
0x20 = Current protocol supports failsafe
|
||||||
|
0x80 = Data buffer is almost full
|
||||||
[3] major
|
[3] major
|
||||||
[4] minor
|
[4] minor
|
||||||
[5] revision
|
[5] revision
|
||||||
@ -868,10 +878,11 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
|
|||||||
[4] Flags
|
[4] Flags
|
||||||
0x01 = Input signal detected
|
0x01 = Input signal detected
|
||||||
0x02 = Serial mode enabled
|
0x02 = Serial mode enabled
|
||||||
0x04 = protocol is valid
|
0x04 = Protocol is valid
|
||||||
0x08 = module is in binding mode
|
0x08 = Module is in binding mode
|
||||||
0x10 = module waits a bind event to load the protocol
|
0x10 = Module waits a bind event to load the protocol
|
||||||
0x20 = current protocol supports failsafe
|
0x20 = Current protocol supports failsafe
|
||||||
|
0x80 = Data buffer is almost full
|
||||||
[5] major
|
[5] major
|
||||||
[6] minor
|
[6] minor
|
||||||
[7] revision
|
[7] revision
|
||||||
|
@ -137,7 +137,7 @@ const uint8_t CH_EATR[]={ELEVATOR, AILERON, THROTTLE, RUDDER, CH5, CH6, CH7, CH8
|
|||||||
|
|
||||||
// Mode_select variables
|
// Mode_select variables
|
||||||
uint8_t mode_select;
|
uint8_t mode_select;
|
||||||
uint8_t protocol_flags=0,protocol_flags2=0;
|
uint8_t protocol_flags=0,protocol_flags2=0,protocol_flags3=0;
|
||||||
|
|
||||||
#ifdef ENABLE_PPM
|
#ifdef ENABLE_PPM
|
||||||
// PPM variable
|
// PPM variable
|
||||||
@ -954,6 +954,7 @@ static void protocol_init()
|
|||||||
#ifdef FAILSAFE_ENABLE
|
#ifdef FAILSAFE_ENABLE
|
||||||
FAILSAFE_VALUES_off;
|
FAILSAFE_VALUES_off;
|
||||||
#endif
|
#endif
|
||||||
|
DATA_BUFFER_LOW_off;
|
||||||
|
|
||||||
blink=millis();
|
blink=millis();
|
||||||
|
|
||||||
@ -1568,7 +1569,17 @@ void update_serial_data()
|
|||||||
//debug("%02X ",SportData[SportTail]);
|
//debug("%02X ",SportData[SportTail]);
|
||||||
SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1);
|
SportTail = (SportTail+1) & (MAX_SPORT_BUFFER-1);
|
||||||
}
|
}
|
||||||
//debugln("");
|
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_on; //Send Multi Status ASAP to inform the TX
|
||||||
|
debugln("Low buf=%d,h=%d,t=%d",used,SportHead,SportTail);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,8 @@ static void multi_send_status()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if(IS_DATA_BUFFER_LOW_on)
|
||||||
|
flags |= 0x80;
|
||||||
}
|
}
|
||||||
Serial_write(flags);
|
Serial_write(flags);
|
||||||
|
|
||||||
@ -353,7 +355,6 @@ void frsky_check_telemetry(uint8_t *packet_in,uint8_t len)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{//Not in sequence
|
{//Not in sequence
|
||||||
debugln("NS");
|
|
||||||
struct t_FrSkyX_RX_Frame *q ;
|
struct t_FrSkyX_RX_Frame *q ;
|
||||||
uint8_t count ;
|
uint8_t count ;
|
||||||
// packet_in[4] RSSI
|
// packet_in[4] RSSI
|
||||||
@ -725,9 +726,10 @@ void TelemetryUpdate()
|
|||||||
#if ( defined(MULTI_TELEMETRY) || defined(MULTI_STATUS) )
|
#if ( defined(MULTI_TELEMETRY) || defined(MULTI_STATUS) )
|
||||||
{
|
{
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
if ((now - lastMulti) > MULTI_TIME)
|
if (IS_SEND_MULTI_STATUS_on || (now - lastMulti) > MULTI_TIME)
|
||||||
{
|
{
|
||||||
multi_send_status();
|
multi_send_status();
|
||||||
|
SEND_MULTI_STATUS_off;
|
||||||
lastMulti = now;
|
lastMulti = now;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user