mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-07-13 02:07:53 +00:00
Changes to Hubsan protocol to match with goebish - deviaiton 45b5f7d date Dec 20th, 2016
This commit is contained in:
parent
e80fb904ce
commit
fd936be4ef
@ -31,12 +31,44 @@ enum{
|
|||||||
HUBSAN_FLAG_HEADLESS = 0x08, // headless mode
|
HUBSAN_FLAG_HEADLESS = 0x08, // headless mode
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum{
|
||||||
|
// flags going to packet[9] (H301)
|
||||||
|
HUBSAN_FLAG_H301_VIDEO = 0x01,
|
||||||
|
HUBSAN_FLAG_H301_STAB = 0x02,
|
||||||
|
HUBSAN_FLAG_H301_LED = 0x10,
|
||||||
|
HUBSAN_FLAG_H301_RTH = 0x40,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
enum{
|
enum{
|
||||||
// flags going to packet[13] (Plus series)
|
// flags going to packet[13] (Plus series)
|
||||||
HUBSAN_FLAG_SNAPSHOT = 0x01,
|
HUBSAN_FLAG_SNAPSHOT = 0x01,
|
||||||
HUBSAN_FLAG_FLIP_PLUS = 0x80,
|
HUBSAN_FLAG_FLIP_PLUS = 0x80,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum{
|
||||||
|
// flags going to packet[9] (H501S)
|
||||||
|
HUBSAN_FLAG_H501_VIDEO = 0x01,
|
||||||
|
HUBSAN_FLAG_H501_LED = 0x04,
|
||||||
|
HUBSAN_FLAG_H501_RTH = 0x20,
|
||||||
|
HUBSAN_FLAG_H501_HEADLESS1 = 0x40,
|
||||||
|
HUBSAN_FLAG_H501_GPS_HOLD = 0x80,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
HUBSAN_FORMAT_H107 = 0,
|
||||||
|
HUBSAN_FORMAT_H301,
|
||||||
|
HUBSAN_FORMAT_H501,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum{
|
||||||
|
// flags going to packet[13] (H501S)
|
||||||
|
HUBSAN_FLAG_H501_SNAPSHOT = 0x01,
|
||||||
|
HUBSAN_FLAG_H501_HEADLESS2 = 0x02,
|
||||||
|
HUBSAN_FLAG_H501_ALT_HOLD = 0x08,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
uint32_t sessionid,id_data;
|
uint32_t sessionid,id_data;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -76,7 +108,7 @@ static void __attribute__((unused)) hubsan_build_bind_packet(uint8_t bind_state)
|
|||||||
packet[3] = (sessionid >> 16) & 0xFF;
|
packet[3] = (sessionid >> 16) & 0xFF;
|
||||||
packet[4] = (sessionid >> 8) & 0xFF;
|
packet[4] = (sessionid >> 8) & 0xFF;
|
||||||
packet[5] = (sessionid >> 0) & 0xFF;
|
packet[5] = (sessionid >> 0) & 0xFF;
|
||||||
if(id_data == ID_NORMAL)
|
if(id_data == ID_NORMAL && (sub_protocol != HUBSAN_FORMAT_H501))
|
||||||
{
|
{
|
||||||
packet[6] = 0x08;
|
packet[6] = 0x08;
|
||||||
packet[7] = 0xe4;
|
packet[7] = 0xe4;
|
||||||
@ -89,8 +121,8 @@ static void __attribute__((unused)) hubsan_build_bind_packet(uint8_t bind_state)
|
|||||||
packet[13] = 0x26;
|
packet[13] = 0x26;
|
||||||
packet[14] = 0x79;
|
packet[14] = 0x79;
|
||||||
}
|
}
|
||||||
else
|
else if(id_data == ID_PLUS || (sub_protocol == HUBSAN_FORMAT_H501))
|
||||||
{ //ID_PLUS
|
{ //ID_PLUS or H501
|
||||||
if(phase >= BIND_3)
|
if(phase >= BIND_3)
|
||||||
{
|
{
|
||||||
packet[7] = 0x62;
|
packet[7] = 0x62;
|
||||||
@ -108,6 +140,7 @@ static void __attribute__((unused)) hubsan_build_bind_packet(uint8_t bind_state)
|
|||||||
//ii : aileron observed range: 0x45 - 0xc3 (smaller is right)69-195-50%
|
//ii : aileron observed range: 0x45 - 0xc3 (smaller is right)69-195-50%
|
||||||
static void __attribute__((unused)) hubsan_build_packet()
|
static void __attribute__((unused)) hubsan_build_packet()
|
||||||
{
|
{
|
||||||
|
static uint32_t h501_packet = 0;
|
||||||
static uint8_t vtx_freq = 0;
|
static uint8_t vtx_freq = 0;
|
||||||
memset(packet, 0, 16);
|
memset(packet, 0, 16);
|
||||||
if(vtx_freq != option || packet_count==100) // set vTX frequency (H107D)
|
if(vtx_freq != option || packet_count==100) // set vTX frequency (H107D)
|
||||||
@ -118,6 +151,7 @@ static void __attribute__((unused)) hubsan_build_packet()
|
|||||||
packet[2] = vtx_freq+0x0D; // 5645 - 5900 MHz
|
packet[2] = vtx_freq+0x0D; // 5645 - 5900 MHz
|
||||||
packet[3] = 0x82;
|
packet[3] = 0x82;
|
||||||
packet_count++;
|
packet_count++;
|
||||||
|
h501_packet = 0;
|
||||||
}
|
}
|
||||||
else //20 00 00 00 80 00 7d 00 84 02 64 db 04 26 79 7b
|
else //20 00 00 00 80 00 7d 00 84 02 64 db 04 26 79 7b
|
||||||
{
|
{
|
||||||
@ -127,7 +161,7 @@ static void __attribute__((unused)) hubsan_build_packet()
|
|||||||
packet[4] = 0xFF - convert_channel_8b(RUDDER); //Rudder is reversed
|
packet[4] = 0xFF - convert_channel_8b(RUDDER); //Rudder is reversed
|
||||||
packet[6] = 0xFF - convert_channel_8b(ELEVATOR); //Elevator is reversed
|
packet[6] = 0xFF - convert_channel_8b(ELEVATOR); //Elevator is reversed
|
||||||
packet[8] = convert_channel_8b(AILERON); //Aileron
|
packet[8] = convert_channel_8b(AILERON); //Aileron
|
||||||
if(id_data == ID_NORMAL)
|
if(id_data == ID_NORMAL && (sub_protocol == HUBSAN_FORMAT_H107)) // H107/L/C/D, H102D
|
||||||
{
|
{
|
||||||
if( packet_count < 100)
|
if( packet_count < 100)
|
||||||
{
|
{
|
||||||
@ -151,21 +185,52 @@ static void __attribute__((unused)) hubsan_build_packet()
|
|||||||
packet[13] = 0x26;
|
packet[13] = 0x26;
|
||||||
packet[14] = 0x79;
|
packet[14] = 0x79;
|
||||||
}
|
}
|
||||||
|
else if(sub_protocol == HUBSAN_FORMAT_H301)
|
||||||
|
{
|
||||||
|
if(packet_count < 100)
|
||||||
|
{
|
||||||
|
packet[9] = HUBSAN_FLAG_H301_STAB;
|
||||||
|
packet_count++;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{ //ID_PLUS
|
{
|
||||||
packet[3] = 0x64;
|
packet[9] = HUBSAN_FLAG_H301_LED;
|
||||||
packet[5] = 0x64;
|
if(Servo_AUX1) packet[9] |= HUBSAN_FLAG_H301_STAB; // channel 6
|
||||||
packet[7] = 0x64;
|
if(Servo_AUX4) packet[9] |= HUBSAN_FLAG_H301_VIDEO; // channel 8
|
||||||
|
if(Servo_AUX6) packet[9] |= HUBSAN_FLAG_H301_RTH; // channel 10
|
||||||
|
}
|
||||||
|
packet[10] = 0x18; // ?
|
||||||
|
packet[12] = 0x5c; // ?
|
||||||
|
packet[14] = 0xf6; // ?
|
||||||
|
} // 364
|
||||||
|
else if(id_data == ID_PLUS || (sub_protocol == HUBSAN_FORMAT_H501))
|
||||||
|
{
|
||||||
|
packet[3] = sub_protocol == HUBSAN_FORMAT_H501 ? 0x00 : 0x64;
|
||||||
|
packet[5] = sub_protocol == HUBSAN_FORMAT_H501 ? 0x00 : 0x64;
|
||||||
|
packet[7] = sub_protocol == HUBSAN_FORMAT_H501 ? 0x00 : 0x64;
|
||||||
|
if( sub_protocol == HUBSAN_FORMAT_H501)
|
||||||
|
{ // H501S
|
||||||
|
packet[9] = 0x02;
|
||||||
|
if(Servo_AUX1) packet[9] |= HUBSAN_FLAG_H501_LED; // channel 5
|
||||||
|
if(Servo_AUX4) packet[9] |= HUBSAN_FLAG_H501_VIDEO; // channel 8
|
||||||
|
if(Servo_AUX6) packet[9] |= HUBSAN_FLAG_H501_RTH; // channel 10
|
||||||
|
if(Servo_AUX7) packet[9] |= HUBSAN_FLAG_H501_GPS_HOLD; // channel 11
|
||||||
|
if(Servo_AUX5) packet[9] |= HUBSAN_FLAG_H501_HEADLESS1; // channel 9
|
||||||
|
packet[13] = HUBSAN_FLAG_H501_HEADLESS2; // channel 9
|
||||||
|
if(Servo_AUX2) packet[13] |= HUBSAN_FLAG_H501_ALT_HOLD; // channel 6
|
||||||
|
if(Servo_AUX3) packet[13] |= HUBSAN_FLAG_H501_SNAPSHOT; // channel 7
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // H107P / C+ / D+
|
||||||
packet[9] = 0x06;
|
packet[9] = 0x06;
|
||||||
//FLIP|LIGHT|PICTURE|VIDEO|HEADLESS
|
if(Servo_AUX4) packet[9] |= HUBSAN_FLAG_VIDEO; // channel 8
|
||||||
if(Servo_AUX4) packet[9] |= HUBSAN_FLAG_VIDEO;
|
if(Servo_AUX5) packet[9] |= HUBSAN_FLAG_HEADLESS; // channel 9
|
||||||
if(Servo_AUX5) packet[9] |= HUBSAN_FLAG_HEADLESS;
|
packet[10] = sub_protocol == HUBSAN_FORMAT_H501 ? 0x1a : 0x19;
|
||||||
packet[10]= 0x19;
|
|
||||||
packet[12] = 0x5C; // ghost channel ?
|
packet[12] = 0x5C; // ghost channel ?
|
||||||
packet[13] = 0;
|
packet[13] = HUBSAN_FLAG_SNAPSHOT; // channel 7
|
||||||
if(Servo_AUX3) packet[13] = HUBSAN_FLAG_SNAPSHOT;
|
if(Servo_AUX2) packet[13] |= HUBSAN_FLAG_FLIP_PLUS; // channel 6
|
||||||
if(Servo_AUX1) packet[13] |= HUBSAN_FLAG_FLIP_PLUS;
|
|
||||||
packet[14] = 0x49; // ghost channel ?
|
packet[14] = 0x49; // ghost channel ?
|
||||||
|
}
|
||||||
if(packet_count < 100)
|
if(packet_count < 100)
|
||||||
{ // set channels to neutral for first 100 packets
|
{ // set channels to neutral for first 100 packets
|
||||||
packet[2] = 0x80; // throttle neutral is at mid stick on plus series
|
packet[2] = 0x80; // throttle neutral is at mid stick on plus series
|
||||||
@ -176,9 +241,24 @@ static void __attribute__((unused)) hubsan_build_packet()
|
|||||||
packet[13]= 0x00;
|
packet[13]= 0x00;
|
||||||
packet_count++;
|
packet_count++;
|
||||||
}
|
}
|
||||||
|
if(sub_protocol == HUBSAN_FORMAT_H501)
|
||||||
|
{
|
||||||
|
h501_packet++;
|
||||||
|
if(h501_packet == 10)
|
||||||
|
{
|
||||||
|
memset(packet, 0, 16);
|
||||||
|
packet[0] = 0xe8;
|
||||||
|
}
|
||||||
|
else if(h501_packet == 20)
|
||||||
|
{
|
||||||
|
memset(packet, 0, 16);
|
||||||
|
packet[0] = 0xe9;
|
||||||
|
}
|
||||||
|
if(h501_packet >= 20) h501_packet = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
hubsan_update_crc();
|
hubsan_update_crc();
|
||||||
}
|
} // 414
|
||||||
|
|
||||||
#ifdef HUBSAN_HUB_TELEMETRY
|
#ifdef HUBSAN_HUB_TELEMETRY
|
||||||
static uint8_t __attribute__((unused)) hubsan_check_integrity()
|
static uint8_t __attribute__((unused)) hubsan_check_integrity()
|
||||||
@ -192,6 +272,7 @@ static uint8_t __attribute__((unused)) hubsan_check_integrity()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// 440
|
||||||
uint16_t ReadHubsan()
|
uint16_t ReadHubsan()
|
||||||
{
|
{
|
||||||
#ifdef HUBSAN_HUB_TELEMETRY
|
#ifdef HUBSAN_HUB_TELEMETRY
|
||||||
@ -205,7 +286,7 @@ uint16_t ReadHubsan()
|
|||||||
switch(phase) {
|
switch(phase) {
|
||||||
case BIND_1:
|
case BIND_1:
|
||||||
bind_count++;
|
bind_count++;
|
||||||
if(bind_count >= 20)
|
if(bind_count == 20 &&sub_protocol != HUBSAN_FORMAT_H501)
|
||||||
{
|
{
|
||||||
if(id_data == ID_NORMAL)
|
if(id_data == ID_NORMAL)
|
||||||
id_data = ID_PLUS;
|
id_data = ID_PLUS;
|
||||||
@ -340,6 +421,7 @@ uint16_t ReadHubsan()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 577
|
||||||
uint16_t initHubsan() {
|
uint16_t initHubsan() {
|
||||||
const uint8_t allowed_ch[] = {0x14, 0x1e, 0x28, 0x32, 0x3c, 0x46, 0x50, 0x5a, 0x64, 0x6e, 0x78, 0x82};
|
const uint8_t allowed_ch[] = {0x14, 0x1e, 0x28, 0x32, 0x3c, 0x46, 0x50, 0x5a, 0x64, 0x6e, 0x78, 0x82};
|
||||||
A7105_Init();
|
A7105_Init();
|
||||||
@ -351,10 +433,13 @@ uint16_t initHubsan() {
|
|||||||
phase = BIND_1;
|
phase = BIND_1;
|
||||||
packet_count=0;
|
packet_count=0;
|
||||||
id_data=ID_NORMAL;
|
id_data=ID_NORMAL;
|
||||||
|
// 605 - 613 left out on purpose
|
||||||
#ifdef HUBSAN_HUB_TELEMETRY
|
#ifdef HUBSAN_HUB_TELEMETRY
|
||||||
init_hub_telemetry();
|
init_hub_telemetry();
|
||||||
#endif
|
#endif
|
||||||
return 10000;
|
return 10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user