mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-07-12 09:47:54 +00:00
MAJ telemtry BAYANG
This commit is contained in:
parent
a95221200f
commit
8b282dd506
@ -265,11 +265,7 @@ uint16_t BAYANG_callback()
|
||||
#ifdef ENABLE_BAYANG_TELEMETRY
|
||||
if(sub_protocol == BAYANG_TELEM)
|
||||
{
|
||||
Bayang_process();
|
||||
// Return 0 here so that Bayang_process is called as often as possible
|
||||
// to check for the incomming telemetry data. When telemetry is enabled
|
||||
// the packet period is handled in the Bayang_process function.
|
||||
return 0;
|
||||
return Bayang_process();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -317,6 +313,9 @@ uint16_t initBAYANG(void)
|
||||
|
||||
#ifdef ENABLE_BAYANG_TELEMETRY
|
||||
extern float telemetry_voltage;
|
||||
extern uint16_t telemetry_rx_recv_pps;
|
||||
extern uint16_t telemetry_tx_recv_pps;
|
||||
extern uint16_t telemetry_tx_sent_pps;
|
||||
extern uint8_t telemetry_rx_rssi;
|
||||
extern uint8_t telemetry_tx_rssi;
|
||||
extern uint8_t telemetry_datamode;
|
||||
@ -326,13 +325,21 @@ uint16_t initBAYANG(void)
|
||||
extern uint16_t telemetry_flighttime;
|
||||
extern uint8_t telemetry_flightmode;
|
||||
|
||||
uint8_t telemetry_tx_rssi_count;
|
||||
uint8_t telemetry_tx_rssi_next;
|
||||
|
||||
|
||||
uint16_t telemetry_tx_sent_pkt_count;
|
||||
uint32_t telemetry_tx_sent_pps_time;
|
||||
uint16_t telemetry_tx_recv_pkt_count;
|
||||
uint32_t telemetry_tx_recv_pps_time;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static uint32_t bayang_tx_time = 0;
|
||||
uint8_t BAYANG_recv_packet() {
|
||||
uint8_t received = 0;
|
||||
if (NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_RX_DR)) {
|
||||
if (NRF24L01_Strobe(NRF24L01_FF_NOP) & _BV(NRF24L01_07_RX_DR)) {
|
||||
int sum = 0;
|
||||
uint16_t roll, pitch, yaw, throttle;
|
||||
|
||||
@ -357,7 +364,13 @@ uint16_t initBAYANG(void)
|
||||
v.bytes[1] = packet[2];
|
||||
telemetry_voltage = v.v / 100.f;
|
||||
|
||||
telemetry_rx_rssi = packet[3];
|
||||
telemetry_rx_recv_pps = packet[3]*2;
|
||||
telemetry_rx_rssi = (uint8_t)(telemetry_rx_recv_pps*100/telemetry_tx_sent_pps);
|
||||
if (telemetry_rx_rssi > 100)
|
||||
telemetry_rx_rssi = 100;
|
||||
telemetry_tx_rssi = (uint8_t)(telemetry_tx_recv_pps*100/telemetry_rx_recv_pps);
|
||||
if (telemetry_tx_rssi > 100)
|
||||
telemetry_tx_rssi = 100;
|
||||
|
||||
|
||||
v.bytes[0] = packet[4];
|
||||
@ -401,60 +414,83 @@ uint16_t initBAYANG(void)
|
||||
BayangState Bayang_state = BAYANG_STATE_IDLE;
|
||||
uint32_t Bayang_next_send = 0;
|
||||
|
||||
void Bayang_process() {
|
||||
uint16_t Bayang_process() {
|
||||
uint32_t time_micros = micros();
|
||||
|
||||
uint16_t callback_period = 30; // asap
|
||||
if (BAYANG_STATE_TRANSMITTING == Bayang_state) {
|
||||
if (NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_TX_DS)) {
|
||||
if (NRF24L01_Strobe(NRF24L01_FF_NOP) & _BV(NRF24L01_07_TX_DS) || time_micros - bayang_tx_time > 1100) {
|
||||
// send finished, switch to rx to receive telemetry
|
||||
XN297_Configure(_BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP) | _BV(NRF24L01_00_PRIM_RX));
|
||||
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
|
||||
NRF24L01_FlushTx();
|
||||
NRF24L01_FlushRx();
|
||||
|
||||
telemetry_tx_rssi_count++;
|
||||
Bayang_state = BAYANG_STATE_RECEIEVING;
|
||||
|
||||
Bayang_state = BAYANG_STATE_RECEIEVING;
|
||||
callback_period = Bayang_next_send - time_micros - 550; // wait a while for quad to receive then send a packet
|
||||
}
|
||||
}
|
||||
else if (BAYANG_STATE_RECEIEVING == Bayang_state) {
|
||||
uint8_t change_state = 1;
|
||||
// 250us is about the time it takes to read a packet over spi
|
||||
if (time_micros > (Bayang_next_send-250)) {
|
||||
// didnt receive telemetry in time
|
||||
Bayang_state = BAYANG_STATE_IDLE;
|
||||
|
||||
if (time_micros > (Bayang_next_send-250))
|
||||
{
|
||||
// if it's been a while since receiving telemetry data,
|
||||
// stop sending the telemetry data to the transmitter
|
||||
if (millis() - bayang_telemetry_last_rx > 1000)
|
||||
if (time_micros - bayang_telemetry_last_rx > 1000000)
|
||||
telemetry_lost = 1;
|
||||
}
|
||||
else if (BAYANG_recv_packet()) {
|
||||
telemetry_tx_rssi_next++;
|
||||
else if (BAYANG_recv_packet())
|
||||
{
|
||||
telemetry_tx_recv_pkt_count++;
|
||||
// received telemetry packet
|
||||
telemetry_lost = 0;
|
||||
bayang_telemetry_last_rx = millis();
|
||||
bayang_telemetry_last_rx = time_micros;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
change_state = 0;
|
||||
}
|
||||
|
||||
if (100 == telemetry_tx_rssi_count)
|
||||
if (telemetry_tx_recv_pps_time < time_micros)
|
||||
{
|
||||
telemetry_tx_rssi = telemetry_tx_rssi_next;
|
||||
telemetry_tx_rssi_next = 0;
|
||||
telemetry_tx_rssi_count = 0;
|
||||
telemetry_tx_recv_pps = telemetry_tx_recv_pps + telemetry_tx_recv_pkt_count - telemetry_tx_recv_pps/10;
|
||||
telemetry_tx_recv_pkt_count = 0;
|
||||
telemetry_tx_recv_pps_time += 100000;
|
||||
}
|
||||
|
||||
if (change_state)
|
||||
{
|
||||
Bayang_state = BAYANG_STATE_IDLE;
|
||||
XN297_Configure(_BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP));
|
||||
NRF24L01_FlushRx();
|
||||
XN297_Configure(_BV(NRF24L01_00_EN_CRC) | _BV(NRF24L01_00_CRCO) | _BV(NRF24L01_00_PWR_UP));
|
||||
NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70);
|
||||
NRF24L01_FlushRx();
|
||||
}
|
||||
}
|
||||
else if (time_micros > Bayang_next_send) {
|
||||
else if (time_micros > Bayang_next_send)
|
||||
{
|
||||
bayang_tx_time = time_micros;
|
||||
|
||||
BAYANG_send_packet(0);
|
||||
Bayang_state = BAYANG_STATE_TRANSMITTING;
|
||||
Bayang_next_send = time_micros + BAYANG_PACKET_PERIOD_TELEM;
|
||||
callback_period = 600; // takes about 1ms to send(spi transfer + tx send)
|
||||
|
||||
telemetry_tx_sent_pkt_count++;
|
||||
if (telemetry_tx_sent_pps_time < time_micros)
|
||||
{
|
||||
telemetry_tx_sent_pps = telemetry_tx_sent_pps + telemetry_tx_sent_pkt_count - telemetry_tx_sent_pps/10;
|
||||
telemetry_tx_sent_pkt_count = 0;
|
||||
telemetry_tx_sent_pps_time += 100000;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
callback_period = Bayang_next_send - time_micros;
|
||||
}
|
||||
return callback_period;
|
||||
}
|
||||
#endif //ENABLE_BAYANG_TELEMETRY
|
||||
#endif
|
||||
|
@ -196,7 +196,9 @@ uint16_t initFlySky()
|
||||
|
||||
A7105_Init();
|
||||
|
||||
if ((rx_tx_addr[3]&0xF0) > 0x90) // limit offset to 9 as higher values don't work with some RX (ie V912)
|
||||
// limit offset to 9 as higher values don't work with some RX (ie V912)
|
||||
// limit offset to 9 as CX20 repeats the same channels after that
|
||||
if ((rx_tx_addr[3]&0xF0) > 0x90)
|
||||
rx_tx_addr[3]=rx_tx_addr[3]-0x70;
|
||||
|
||||
// Build frequency hop table
|
||||
@ -213,11 +215,18 @@ uint16_t initFlySky()
|
||||
if(i&0x01)
|
||||
temp+=0x50;
|
||||
if(sub_protocol==CX20)
|
||||
{//Might need more dumps to be 100% sure but this is how it looks like to work
|
||||
{
|
||||
if(temp==0x0A)
|
||||
temp+=0x37;
|
||||
if(temp==0xA0)
|
||||
temp-=0x73;
|
||||
{
|
||||
if (chanoffset<4)
|
||||
temp=0x37;
|
||||
else if (chanoffset<9)
|
||||
temp=0x2D;
|
||||
else
|
||||
temp=0x29;
|
||||
}
|
||||
}
|
||||
hopping_frequency[((chanrow&1)?15-i:i)]=temp-chanoffset;
|
||||
}
|
||||
|
@ -420,7 +420,10 @@ void loop()
|
||||
{
|
||||
TX_MAIN_PAUSE_on;
|
||||
tx_pause();
|
||||
next_callback=remote_callback();
|
||||
if(IS_INPUT_SIGNAL_on)
|
||||
next_callback=remote_callback();
|
||||
else
|
||||
next_callback=2000; // No PPM/serial signal check again in 2ms...
|
||||
TX_MAIN_PAUSE_off;
|
||||
tx_resume();
|
||||
while(next_callback>4000)
|
||||
@ -536,8 +539,8 @@ static void update_channels_aux(void)
|
||||
static void update_led_status(void)
|
||||
{
|
||||
if(IS_INPUT_SIGNAL_on)
|
||||
if(millis()-last_signal>50)
|
||||
INPUT_SIGNAL_off; //no valid signal (PPM or Serial) received for 50ms
|
||||
if(millis()-last_signal>70)
|
||||
INPUT_SIGNAL_off; //no valid signal (PPM or Serial) received for 70ms
|
||||
if(blink<millis())
|
||||
{
|
||||
if(IS_INPUT_SIGNAL_off)
|
||||
|
@ -101,11 +101,13 @@ static uint8_t NRF24L01_GetDynamicPayloadSize(void)
|
||||
return res;
|
||||
}
|
||||
|
||||
static void NRF24L01_Strobe(uint8_t state)
|
||||
static uint8_t NRF24L01_Strobe(uint8_t state)
|
||||
{
|
||||
uint8_t result;
|
||||
NRF_CSN_off;
|
||||
SPI_Write(state);
|
||||
result =SPI_Write(state);
|
||||
NRF_CSN_on;
|
||||
return result;
|
||||
}
|
||||
|
||||
void NRF24L01_FlushTx()
|
||||
@ -389,9 +391,17 @@ void XN297_ReadPayload(uint8_t* msg, uint8_t len)
|
||||
NRF24L01_ReadPayload(msg, len);
|
||||
for(uint8_t i=0; i<len; i++)
|
||||
{
|
||||
msg[i] = bit_reverse(msg[i]);
|
||||
if(xn297_scramble_enabled)
|
||||
msg[i] ^= bit_reverse(xn297_scramble[i+xn297_addr_len]);
|
||||
if (protocol == MODE_BAYANG) {
|
||||
if(xn297_scramble_enabled)
|
||||
msg[i] = bit_reverse(msg[i] ^ xn297_scramble[i+xn297_addr_len]);
|
||||
else
|
||||
msg[i] = bit_reverse(msg[i]);
|
||||
}
|
||||
else {
|
||||
msg[i] = bit_reverse(msg[i]);
|
||||
if(xn297_scramble_enabled)
|
||||
msg[i] ^= bit_reverse(xn297_scramble[i+xn297_addr_len]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,10 @@
|
||||
float telemetry_voltage = 0.f;
|
||||
uint8_t telemetry_rx_rssi = 100;
|
||||
#ifdef ENABLE_BAYANG_TELEMETRY
|
||||
uint16_t telemetry_rx_recv_pps = 100;
|
||||
uint8_t telemetry_tx_rssi = 100;
|
||||
uint16_t telemetry_tx_recv_pps = 100;
|
||||
uint16_t telemetry_tx_sent_pps = 100;
|
||||
uint8_t telemetry_datamode = 0;
|
||||
uint8_t telemetry_dataitem = 0;
|
||||
float telemetry_data[3] = {0};
|
||||
@ -51,7 +54,7 @@ uint8_t frame[18];
|
||||
|
||||
#ifdef BASH_SERIAL
|
||||
// For bit-bashed serial output
|
||||
struct t_serial_bash
|
||||
volatile struct t_serial_bash
|
||||
{
|
||||
uint8_t head ;
|
||||
uint8_t tail ;
|
||||
@ -71,12 +74,12 @@ void DSM_frame()
|
||||
#endif
|
||||
|
||||
#if defined AFHDS2A_TELEMETRY
|
||||
void AFHDSA_short_frame()
|
||||
{
|
||||
Serial_write(0xAA); // Telemetry packet
|
||||
for (uint8_t i = 0; i < 29; i++) // RSSI value followed by 4*7 bytes of telemetry data
|
||||
Serial_write(pkt[i]);
|
||||
}
|
||||
void AFHDSA_short_frame()
|
||||
{
|
||||
Serial_write(0xAA); // Telemetry packet
|
||||
for (uint8_t i = 0; i < 29; i++) // RSSI value followed by 4*7 bytes of telemetry data
|
||||
Serial_write(pkt[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
void frskySendStuffed()
|
||||
@ -371,10 +374,7 @@ void sportSendFrame()
|
||||
case 2: //BATT
|
||||
frame[2] = 0x04;
|
||||
frame[3] = 0xf1;
|
||||
if (protocol == MODE_BAYANG)
|
||||
frame[4] = telemetry_voltage/4.f * 255.f/3.3f;//a1;
|
||||
else
|
||||
frame[4] = telemetry_voltage;
|
||||
frame[4] = telemetry_voltage/4.f * 255.f/3.3f;//a1;
|
||||
break;
|
||||
case 3: //FCS VOLTAGE
|
||||
frame[2] = 0x10;
|
||||
@ -447,12 +447,14 @@ void sportSendFrame()
|
||||
case 12: // xjt t1
|
||||
frame[2] = 0x02;
|
||||
frame[3] = 0x00;
|
||||
frame[4] = 0;
|
||||
frame[4] = telemetry_tx_sent_pps >> 1; // divided by 2
|
||||
frame[5] = telemetry_rx_recv_pps >> 1; // divided by 2
|
||||
break;
|
||||
case 13: // xjt t2
|
||||
frame[2] = 0x05;
|
||||
frame[3] = 0x00;
|
||||
frame[4] = 0;
|
||||
frame[4] = telemetry_tx_recv_pps >> 1; // divided by 2
|
||||
frame[5] = 0;
|
||||
break;
|
||||
default:
|
||||
if(sport)
|
||||
@ -963,7 +965,7 @@ ISR(TIMER0_COMPB_vect)
|
||||
else
|
||||
{
|
||||
// prepare next byte and allow for 2 stop bits
|
||||
struct t_serial_bash *ptr = &SerialControl ;
|
||||
volatile struct t_serial_bash *ptr = &SerialControl ;
|
||||
if ( ptr->head != ptr->tail )
|
||||
{
|
||||
GPIOR0 = ptr->data[ptr->tail] ;
|
||||
@ -1014,7 +1016,7 @@ ISR(TIMER0_OVF_vect)
|
||||
if ( --GPIOR1 == 0 )
|
||||
{
|
||||
// prepare next byte
|
||||
struct t_serial_bash *ptr = &SerialControl ;
|
||||
volatile struct t_serial_bash *ptr = &SerialControl ;
|
||||
if ( ptr->head != ptr->tail )
|
||||
{
|
||||
GPIOR0 = ptr->data[ptr->tail] ;
|
||||
|
@ -151,6 +151,7 @@
|
||||
//In this section you can configure the NUNCHUCK.
|
||||
//If you do not plan to use the NUNCHUCK mode comment this line using "//" to save Flash space, you don't need to configure anything below in this case
|
||||
#define ENABLE_NUNCHUCK
|
||||
// pont diviseur VCC --------------- 240K ------------- analogRead(0) -------------- 75K ----------- GND
|
||||
#define VBAT_PIN 3 // for Tx adapters with battery
|
||||
#define VBAT_VAL 340 // for Tx adapters with battery (attention pont divisieur pour avoir 1,1V max ,~=3,404V)
|
||||
#define VBAT_LIM 330 // for Tx adapters with battery (attention pont divisieur pour avoir 1,1V max , ~=3,302V)
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user