Add: Telemetry display for Hubsan TX RSSI

This commit is contained in:
pascallanger 2016-01-28 17:25:15 +01:00
parent c74de12ceb
commit 85548d6e8e
3 changed files with 29 additions and 21 deletions

View File

@ -181,14 +181,16 @@ static void __attribute__((unused)) hubsan_build_packet()
} }
#if defined(TELEMETRY) #if defined(TELEMETRY)
/*static uint8_t hubsan_check_integrity() static __attribute__((unused)) uint8_t hubsan_check_integrity()
{ {
int sum = 0; if( (packet[0]&0xFE) != 0xE0 )
return 0;
return 1;
uint8_t sum = 0;
for(uint8_t i = 0; i < 15; i++) for(uint8_t i = 0; i < 15; i++)
sum += packet[i]; sum += packet[i];
return packet[15] == ((256 - (sum % 256)) & 0xFF); return ( packet[15] == (uint8_t)(-sum) );
} }
*/
#endif #endif
uint16_t ReadHubsan() uint16_t ReadHubsan()
@ -295,7 +297,8 @@ uint16_t ReadHubsan()
} }
else { else {
#if defined(TELEMETRY) #if defined(TELEMETRY)
if( rfMode == A7105_TX) {// switch to rx mode 3ms after packet sent if( rfMode == A7105_TX)
{// switch to rx mode 3ms after packet sent
for( i=0; i<10; i++) for( i=0; i<10; i++)
{ {
if( !(A7105_ReadReg(A7105_00_MODE) & 0x01)) {// wait for tx completion if( !(A7105_ReadReg(A7105_00_MODE) & 0x01)) {// wait for tx completion
@ -306,15 +309,23 @@ uint16_t ReadHubsan()
} }
} }
} }
if( rfMode == A7105_RX) { // check for telemetry frame if( rfMode == A7105_RX)
for( i=0; i<10; i++) { { // check for telemetry frame
if( !(A7105_ReadReg(A7105_00_MODE) & 0x01)) { // data received for( i=0; i<10; i++)
{
if( !(A7105_ReadReg(A7105_00_MODE) & 0x01))
{ // data received
A7105_ReadData(); A7105_ReadData();
if( !(A7105_ReadReg(A7105_00_MODE) & 0x01)){ // data received if( hubsan_check_integrity() )
v_lipo=packet[13];// hubsan lipo voltage 8bits the real value is h_lipo/10(0x2A=42-4.2V) {
v_lipo=packet[13];// hubsan lipo voltage 8bits the real value is h_lipo/10(0x2A=42 -> 4.2V)
telemetry_link=1; telemetry_link=1;
} }
A7105_Strobe(A7105_RX); A7105_Strobe(A7105_RX);
// Read TX RSSI
RSSI_dBm=256-(A7105_ReadReg(A7105_1D_RSSI_THOLD)*8)/5; // value from A7105 is between 8 for maximum signal strength to 160 or less
if(RSSI_dBm<0) RSSI_dBm=0;
else if(RSSI_dBm>255) RSSI_dBm=255;
break; break;
} }
} }
@ -344,7 +355,6 @@ uint16_t initHubsan() {
packet_count=0; packet_count=0;
id_data=ID_NORMAL; id_data=ID_NORMAL;
#if defined(TELEMETRY) #if defined(TELEMETRY)
v_lipo=0;
telemetry_link=0; telemetry_link=0;
#endif #endif
return 10000; return 10000;

View File

@ -29,7 +29,6 @@
#include "_Config.h" #include "_Config.h"
//Global constants/variables //Global constants/variables
uint32_t MProtocol_id;//tx id, uint32_t MProtocol_id;//tx id,
uint32_t MProtocol_id_master; uint32_t MProtocol_id_master;
uint32_t Model_fixed_id=0; uint32_t Model_fixed_id=0;
@ -558,11 +557,11 @@ uint16_t limit_channel_100(uint8_t ch)
#if defined(TELEMETRY) #if defined(TELEMETRY)
void Serial_write(uint8_t data) void Serial_write(uint8_t data)
{ {
uint8_t t=tx_head; cli(); // disable global int
if(++t>=TXBUFFER_SIZE) if(++tx_head>=TXBUFFER_SIZE)
t=0; tx_head=0;
tx_buff[t]=data; tx_buff[tx_head]=data;
tx_head=t; sei(); // enable global int
UCSR0B |= (1<<UDRIE0);//enable UDRE interrupt UCSR0B |= (1<<UDRIE0);//enable UDRE interrupt
} }
#endif #endif

View File

@ -47,17 +47,16 @@ void frsky_link_frame()
frame[2] = pktt[4]; frame[2] = pktt[4];
frame[3] = (uint8_t)RSSI_dBm; frame[3] = (uint8_t)RSSI_dBm;
frame[4] = pktt[5]*2; frame[4] = pktt[5]*2;
frame[5] = frame[6] = frame[7] = frame[8] = 0;
} }
else else
if ((cur_protocol[0]&0x1F)==MODE_HUBSAN) if ((cur_protocol[0]&0x1F)==MODE_HUBSAN)
{ {
frame[1] = v_lipo*2; //v_lipo; common 0x2A=42/10=4.2V frame[1] = v_lipo*2; //v_lipo; common 0x2A=42/10=4.2V
frame[2] = frame[1]; frame[2] = frame[1];
frame[3] =0X6e; frame[3] = 0x00;
frame[4] =2*0x6e; frame[4] = (uint8_t)RSSI_dBm;
frame[5] = frame[6] = frame[7] = frame[8] = 0;
} }
frame[5] = frame[6] = frame[7] = frame[8] = 0;
frskySendStuffed(); frskySendStuffed();
} }