mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2026-08-12 10:23:16 +00:00
SLT/SLT6X new subprotocol
This commit is contained in:
@@ -28,6 +28,9 @@
|
||||
#define SLT_NFREQCHANNELS 15
|
||||
#define SLT_TXID_SIZE 4
|
||||
#define SLT_BIND_CHANNEL 0x50
|
||||
#define SLT6_CH_MIN 182 // 10-bit AETR minimum (captures: 180-185, symmetric around 512)
|
||||
#define SLT6_CH_MAX 842 // 10-bit AETR maximum (captures: 829-843, symmetric around 512)
|
||||
#define SLT6_SW_THRESHOLD 273 // ~33% of half-range (820/3) for 3-position switch zones
|
||||
|
||||
enum{
|
||||
// flags going to packet[6] (Q200)
|
||||
@@ -54,9 +57,32 @@ enum {
|
||||
SLT_BIND2,
|
||||
};
|
||||
|
||||
// SLT6 sub-cycle states: 3 sub-cycles per triple, each with 2 copies
|
||||
enum {
|
||||
SLT6_BUILD_A=0, // Build packet, configure for 7B sub-cycle
|
||||
SLT6_DATA_A1, // Send 7B copy 1
|
||||
SLT6_DATA_A2, // Send 7B copy 2, configure for 6B sub-cycle
|
||||
SLT6_DATA_B1, // Send 6B copy 1
|
||||
SLT6_DATA_B2, // Send 6B copy 2, configure for 5B sub-cycle
|
||||
SLT6_DATA_C1, // Send 5B copy 1
|
||||
SLT6_DATA_C2, // Send 5B copy 2
|
||||
SLT6_BIND, // Send bind packet
|
||||
};
|
||||
|
||||
// SLT6 address XOR values for the 3 sub-cycles
|
||||
#define SLT6_ADDR_XOR_A 0x00 // 7B sub-cycle: base address
|
||||
#define SLT6_ADDR_XOR_B 0x06 // 6B sub-cycle: byte[0] XOR 0x06
|
||||
#define SLT6_ADDR_XOR_C 0x09 // 5B sub-cycle: byte[0] XOR 0x09
|
||||
|
||||
// SLT6 timing (from capture 12b, in microseconds)
|
||||
#define SLT6_TIMING_SUBCYCLE 5994 // ~6000us between sub-cycle starts
|
||||
#define SLT6_TIMING_PAIR 1633 // ~1633us between the two copies within a sub-cycle
|
||||
#define SLT6_TIMING_BUILD 1000 // Build+config time at start of each triple
|
||||
#define SLT6_TIMING_TRIPLE (3 * SLT6_TIMING_SUBCYCLE) // ~18ms triple period
|
||||
|
||||
static void __attribute__((unused)) SLT_RF_init()
|
||||
{
|
||||
NRF250K_Init();
|
||||
NRF250K_Init(option == 0); // SLT: option==0 uses NRF24L01, option!=0 uses CC2500 with freq tuning
|
||||
NRF250K_SetTXAddr(rx_tx_addr, SLT_TXID_SIZE);
|
||||
}
|
||||
|
||||
@@ -152,8 +178,6 @@ static void __attribute__((unused)) SLT_build_packet()
|
||||
packet[5] = convert_channel_8b(CH5);
|
||||
packet[6] = convert_channel_8b(CH6);
|
||||
|
||||
//->V1 stops here
|
||||
|
||||
if(sub_protocol == Q200)
|
||||
packet[6] = GET_FLAG(CH9_SW , FLAG_Q200_FMODE)
|
||||
|GET_FLAG(CH10_SW, FLAG_Q200_FLIP)
|
||||
@@ -188,6 +212,47 @@ static void __attribute__((unused)) SLT_build_packet()
|
||||
calib_counter = 0;
|
||||
}
|
||||
|
||||
// SLT6: build 7-byte data packet from current channel values
|
||||
static void __attribute__((unused)) SLT6_build_packet()
|
||||
{
|
||||
// aileron, elevator, throttle, rudder (10-bit, limited range)
|
||||
uint8_t e = 0;
|
||||
for (uint8_t i = 0; i < 4; ++i)
|
||||
{
|
||||
uint16_t v = convert_channel_16b_limit(CH_AETR[i], SLT6_CH_MIN, SLT6_CH_MAX);
|
||||
packet[i] = v;
|
||||
e = (e >> 2) | (uint8_t) ((v >> 2) & 0xC0);
|
||||
}
|
||||
packet[4] = e;
|
||||
|
||||
// Flight mode: 3 positions at ~33% each
|
||||
if(Channel_data[CH5] > CHANNEL_MID + SLT6_SW_THRESHOLD)
|
||||
packet[5] = 0xD0;
|
||||
else if(Channel_data[CH5] < CHANNEL_MID - SLT6_SW_THRESHOLD)
|
||||
packet[5] = 0x30;
|
||||
else
|
||||
packet[5] = 0x80;
|
||||
|
||||
// Panic: only active when CH6 is below -33%, center and up = no panic
|
||||
if(Channel_data[CH6] < CHANNEL_MID - SLT6_SW_THRESHOLD)
|
||||
packet[6] = 0x30;
|
||||
else
|
||||
packet[6] = 0xD0;
|
||||
}
|
||||
|
||||
// SLT6: configure radio for a sub-cycle (set address and channel)
|
||||
static void __attribute__((unused)) SLT6_configure_radio(uint8_t addr_xor, uint8_t hop_offset)
|
||||
{
|
||||
SLT_wait_radio();
|
||||
// Set TX address with XOR on byte[0]
|
||||
uint8_t addr[SLT_TXID_SIZE];
|
||||
memcpy(addr, rx_tx_addr, SLT_TXID_SIZE);
|
||||
addr[0] ^= addr_xor;
|
||||
NRF250K_SetTXAddr(addr, SLT_TXID_SIZE);
|
||||
// Set RF channel
|
||||
NRF250K_Hopping((hopping_frequency_no + hop_offset) % SLT_NFREQCHANNELS);
|
||||
}
|
||||
|
||||
static void __attribute__((unused)) SLT_send_bind_packet()
|
||||
{
|
||||
SLT_wait_radio();
|
||||
@@ -197,7 +262,7 @@ static void __attribute__((unused)) SLT_send_bind_packet()
|
||||
BIND_DONE;
|
||||
NRF250K_SetTXAddr((uint8_t *)"\x7E\xB8\x63\xA9", SLT_TXID_SIZE);
|
||||
memcpy((void*)packet, (void*)rx_tx_addr, SLT_TXID_SIZE);
|
||||
if(phase == SLT_BIND2)
|
||||
if(phase == SLT_BIND2 || phase == SLT6_BIND)
|
||||
SLT_send_packet(SLT_TXID_SIZE);
|
||||
else // SLT_BIND1
|
||||
SLT_send_packet(SLT_PAYLOADSIZE_V2);
|
||||
@@ -210,8 +275,71 @@ static void __attribute__((unused)) SLT_send_bind_packet()
|
||||
#define SLT_V1_TIMING_BIND2 1000
|
||||
#define SLT_V2_TIMING_BIND1 6507
|
||||
#define SLT_V2_TIMING_BIND2 2112
|
||||
|
||||
// SLT6 callback: triple-address state machine
|
||||
// Each triple: 3 sub-cycles (7B, 6B, 5B), each sent twice, with different addresses and channels
|
||||
static uint16_t __attribute__((unused)) SLT6_callback()
|
||||
{
|
||||
switch (phase)
|
||||
{
|
||||
case SLT6_BUILD_A:
|
||||
#ifdef MULTI_SYNC
|
||||
telemetry_set_input_sync(SLT6_TIMING_TRIPLE);
|
||||
#endif
|
||||
SLT6_build_packet();
|
||||
NRF250K_SetPower();
|
||||
SLT6_configure_radio(SLT6_ADDR_XOR_A, 0); // 7B sub-cycle: base address, hop+0
|
||||
phase = SLT6_DATA_A1;
|
||||
return SLT6_TIMING_BUILD;
|
||||
case SLT6_DATA_A1:
|
||||
SLT_send_packet(7);
|
||||
phase = SLT6_DATA_A2;
|
||||
return SLT6_TIMING_PAIR; // 1633us between copies
|
||||
case SLT6_DATA_A2:
|
||||
SLT_send_packet(7);
|
||||
SLT6_configure_radio(SLT6_ADDR_XOR_B, 3); // 6B sub-cycle: XOR 0x06 address, hop+3
|
||||
phase = SLT6_DATA_B1;
|
||||
return SLT6_TIMING_SUBCYCLE - SLT6_TIMING_PAIR; // 4361us to next sub-cycle TX
|
||||
case SLT6_DATA_B1:
|
||||
SLT_send_packet(6);
|
||||
phase = SLT6_DATA_B2;
|
||||
return SLT6_TIMING_PAIR;
|
||||
case SLT6_DATA_B2:
|
||||
SLT_send_packet(6);
|
||||
SLT6_configure_radio(SLT6_ADDR_XOR_C, 6); // 5B sub-cycle: XOR 0x09 address, hop+6
|
||||
phase = SLT6_DATA_C1;
|
||||
return SLT6_TIMING_SUBCYCLE - SLT6_TIMING_PAIR; // 4361us
|
||||
case SLT6_DATA_C1:
|
||||
SLT_send_packet(5);
|
||||
phase = SLT6_DATA_C2;
|
||||
return SLT6_TIMING_PAIR;
|
||||
case SLT6_DATA_C2:
|
||||
SLT_send_packet(5);
|
||||
// Advance hopping for next triple
|
||||
if (++hopping_frequency_no >= SLT_NFREQCHANNELS)
|
||||
hopping_frequency_no = 0;
|
||||
if (++packet_count >= 100)
|
||||
{// Send bind packet periodically
|
||||
packet_count = 0;
|
||||
phase = SLT6_BIND;
|
||||
return SLT_V1_TIMING_BIND2;
|
||||
}
|
||||
phase = SLT6_BUILD_A;
|
||||
return SLT6_TIMING_SUBCYCLE - SLT6_TIMING_PAIR - SLT6_TIMING_BUILD; // Gap before next build
|
||||
case SLT6_BIND:
|
||||
SLT_send_bind_packet();
|
||||
phase = SLT6_BUILD_A;
|
||||
return SLT6_TIMING_SUBCYCLE - SLT6_TIMING_PAIR - SLT6_TIMING_BUILD;
|
||||
}
|
||||
return SLT6_TIMING_TRIPLE;
|
||||
}
|
||||
|
||||
uint16_t SLT_callback()
|
||||
{
|
||||
// SLT6 has its own state machine
|
||||
if(sub_protocol == SLT6TX)
|
||||
return SLT6_callback();
|
||||
|
||||
switch (phase)
|
||||
{
|
||||
case SLT_BUILD:
|
||||
@@ -285,7 +413,15 @@ void SLT_init()
|
||||
packet_sent = 0;
|
||||
hopping_frequency_no = 0;
|
||||
|
||||
if(sub_protocol == SLT_V1)
|
||||
if(sub_protocol == SLT6TX)
|
||||
{
|
||||
hopping_frequency_no = 1; // SLT6 starts hopping at index 1 (verified from captures)
|
||||
// packet_length not used for SLT6 (lengths vary per sub-cycle)
|
||||
#ifdef MULTI_SYNC
|
||||
packet_period = SLT6_TIMING_TRIPLE;
|
||||
#endif
|
||||
}
|
||||
else if(sub_protocol == SLT_V1)
|
||||
{
|
||||
packet_length = SLT_PAYLOADSIZE_V1;
|
||||
#ifdef MULTI_SYNC
|
||||
@@ -326,7 +462,10 @@ void SLT_init()
|
||||
SLT_RF_init();
|
||||
SLT_set_freq();
|
||||
|
||||
phase = SLT_BUILD;
|
||||
if(sub_protocol == SLT6TX)
|
||||
phase = SLT6_BUILD_A;
|
||||
else
|
||||
phase = SLT_BUILD;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user