2016-01-27 17:57:33 +01:00
|
|
|
//*************************************
|
|
|
|
// FrSky Telemetry serial code *
|
|
|
|
// By Midelic on RCG *
|
|
|
|
//*************************************
|
2015-12-30 01:41:12 +01:00
|
|
|
|
2016-01-27 17:57:33 +01:00
|
|
|
#if defined TELEMETRY
|
2015-12-30 01:41:12 +01:00
|
|
|
|
2016-01-27 17:57:33 +01:00
|
|
|
#define USER_MAX_BYTES 6
|
|
|
|
#define MAX_PKTX 10
|
|
|
|
uint8_t frame[18];
|
2015-12-30 01:41:12 +01:00
|
|
|
|
2016-01-27 17:57:33 +01:00
|
|
|
void frskySendStuffed()
|
2015-12-30 01:41:12 +01:00
|
|
|
{
|
|
|
|
Serial_write(0x7E);
|
2016-01-27 17:57:33 +01:00
|
|
|
for (uint8_t i = 0; i < 9; i++)
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((frame[i] == 0x7e) || (frame[i] == 0x7d))
|
|
|
|
{
|
2015-12-30 01:41:12 +01:00
|
|
|
Serial_write(0x7D);
|
2016-01-27 17:57:33 +01:00
|
|
|
frame[i] ^= 0x20;
|
2015-12-30 01:41:12 +01:00
|
|
|
}
|
|
|
|
Serial_write(frame[i]);
|
|
|
|
}
|
|
|
|
Serial_write(0x7E);
|
|
|
|
}
|
|
|
|
|
2016-01-27 17:57:33 +01:00
|
|
|
void compute_RSSIdbm(){
|
|
|
|
RSSI_dBm = (((uint16_t)(pktt[len-2])*18)>>5);
|
|
|
|
if(pktt[len-2] >=128)
|
|
|
|
RSSI_dBm -= 82;
|
|
|
|
else
|
|
|
|
RSSI_dBm += 65;
|
|
|
|
}
|
|
|
|
|
|
|
|
void frsky_link_frame()
|
2015-12-30 01:41:12 +01:00
|
|
|
{
|
2016-01-27 17:57:33 +01:00
|
|
|
frame[0] = 0xFE;
|
|
|
|
if ((cur_protocol[0]&0x1F)==MODE_FRSKY)
|
|
|
|
{
|
|
|
|
compute_RSSIdbm();
|
|
|
|
frame[1] = pktt[3];
|
|
|
|
frame[2] = pktt[4];
|
|
|
|
frame[3] = (uint8_t)RSSI_dBm;
|
|
|
|
frame[4] = pktt[5]*2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if ((cur_protocol[0]&0x1F)==MODE_HUBSAN)
|
|
|
|
{
|
|
|
|
frame[1] = v_lipo*2; //v_lipo; common 0x2A=42/10=4.2V
|
|
|
|
frame[2] = frame[1];
|
2016-01-28 17:25:15 +01:00
|
|
|
frame[3] = 0x00;
|
|
|
|
frame[4] = (uint8_t)RSSI_dBm;
|
2015-12-30 01:41:12 +01:00
|
|
|
}
|
2016-01-28 17:25:15 +01:00
|
|
|
frame[5] = frame[6] = frame[7] = frame[8] = 0;
|
2016-01-27 17:57:33 +01:00
|
|
|
frskySendStuffed();
|
2015-12-30 01:41:12 +01:00
|
|
|
}
|
|
|
|
|
2016-01-27 17:57:33 +01:00
|
|
|
#if defined HUB_TELEMETRY
|
|
|
|
void frsky_user_frame()
|
|
|
|
{
|
2016-01-28 18:43:46 +01:00
|
|
|
static uint8_t indexx = 0, pass=0, index, pktx[MAX_PKTX];
|
|
|
|
uint8_t c=0, j=8, n=0, i;
|
2016-01-27 17:57:33 +01:00
|
|
|
|
|
|
|
if(pktt[6]>0 && pktt[6]<=MAX_PKTX)
|
|
|
|
{//only valid hub frames
|
|
|
|
frame[0] = 0xFD;
|
|
|
|
frame[1] = 0;
|
|
|
|
frame[2] = pktt[7];
|
|
|
|
|
|
|
|
switch(pass)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
indexx=pktt[6];
|
|
|
|
for(i=0;i<indexx;i++)
|
|
|
|
{
|
|
|
|
if(pktt[j]==0x5E)
|
|
|
|
{
|
|
|
|
if(c++)
|
|
|
|
{
|
|
|
|
c=0;
|
|
|
|
n++;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pktx[i]=pktt[j++];
|
|
|
|
}
|
|
|
|
indexx = indexx-n;
|
|
|
|
pass=1;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
index=indexx;
|
|
|
|
if(index<USER_MAX_BYTES)
|
|
|
|
{
|
|
|
|
for(i=0;i<index;i++)
|
|
|
|
frame[i+3]=pktx[i];
|
|
|
|
pktt[6]=0;
|
|
|
|
pass=0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
index = USER_MAX_BYTES;
|
|
|
|
for(i=0;i<index;i++)
|
|
|
|
frame[i+3]=pktx[i];
|
|
|
|
pass=2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2016-01-28 18:43:46 +01:00
|
|
|
index = indexx - index;
|
|
|
|
indexx=0;
|
2016-01-27 17:57:33 +01:00
|
|
|
if(index<MAX_PKTX-USER_MAX_BYTES) //10-6=4
|
|
|
|
for(i=0;i<index;i++)
|
|
|
|
frame[i+3]=pktx[USER_MAX_BYTES+i];
|
|
|
|
pass=0;
|
|
|
|
pktt[6]=0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!index)
|
|
|
|
return;
|
|
|
|
frame[1] = index;
|
|
|
|
frskySendStuffed();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pass=0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-12-30 01:41:12 +01:00
|
|
|
void frskyUpdate()
|
|
|
|
{
|
Core and all protocols have been updated
Lot of changes in this new master
ChangeLog:
- Core: LED flashing when an invalid protocol has been selected
- Core: Channels 5 to 12 available as switches for all protocols: code
and size optimization
- Documentation (readme.md): fully updated, all protocols/sub
protocols/channels described, models example, many improvements
- All protocols have been updated in some way, here are some highlights:
* Bayang: added picture, video and inverted channels
* CG023->H8_3D: added light and calibration channels
* CX10: added sub protocols Q282, JC3015_1, JC3015_2, MK33041
* ESky: added new protocol - untested
* Hubsan: added compatibility with the new Hubsan Plus protocol
* KN: fully rewritten protocol: added sub protocols WLTOYS and FEILUN,
11 channels support
New version successfully tested on all my models: Flysky RX/F939/V911
protocol Flysky, Frsky RX protocol Frsky, Hubsan X4 protocol Hubsan,
Hisky HCP100/HCP80 protocol Hisky, HK-3000/HK3100 RX protocol
Hisky/HK310, XINXUN X39 protocol YD717/XINXUN, Symax X5C-1 protocol
SymaX/SYMAX, Cheerson CX-10A protocol CX10/BLUE, Eachine 3D-X4 protocol
CG023.
To access new protocols from er9x/ersky9x, you need to build a version
from this github repository https://github.com/pascallanger/mbtx based
on the latest er9x r820 and ersky9x r218.
2016-01-20 10:50:56 +01:00
|
|
|
if(telemetry_link)
|
|
|
|
{
|
2016-01-27 17:57:33 +01:00
|
|
|
frsky_link_frame();
|
2015-12-30 01:41:12 +01:00
|
|
|
telemetry_link=0;
|
2016-01-27 17:57:33 +01:00
|
|
|
return;
|
2015-12-30 01:41:12 +01:00
|
|
|
}
|
2016-01-27 17:57:33 +01:00
|
|
|
#if defined HUB_TELEMETRY
|
2016-01-28 11:42:56 +01:00
|
|
|
if(!telemetry_link && (cur_protocol[0]&0x1F) != MODE_HUBSAN )
|
2016-01-27 17:57:33 +01:00
|
|
|
frsky_user_frame();
|
|
|
|
#endif
|
2015-12-30 01:41:12 +01:00
|
|
|
}
|
2016-01-27 17:57:33 +01:00
|
|
|
|
|
|
|
#endif
|