From 89c00e8f174edbff17ea99c1fd436d7263c038ea Mon Sep 17 00:00:00 2001 From: Pascal Langer Date: Fri, 5 Feb 2021 12:28:35 +0100 Subject: [PATCH] Initial M-LINK release --- Multiprotocol/MLINK_cyrf6936.ino | 155 +++++++++++++++---------------- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/Validate.h | 5 +- Multiprotocol/_Config.h | 2 + Protocols_Details.md | 14 ++- 5 files changed, 96 insertions(+), 82 deletions(-) diff --git a/Multiprotocol/MLINK_cyrf6936.ino b/Multiprotocol/MLINK_cyrf6936.ino index c25c081..b50dd6a 100644 --- a/Multiprotocol/MLINK_cyrf6936.ino +++ b/Multiprotocol/MLINK_cyrf6936.ino @@ -17,9 +17,7 @@ #include "iface_cyrf6936.h" -#undef MLINK_HUB_TELEMETRY - -#define MLINK_FORCE_ID +//#define MLINK_FORCE_ID #define MLINK_BIND_COUNT 696 // around 20s #define MLINK_NUM_FREQ 78 #define MLINK_BIND_CHANNEL 0x01 @@ -31,13 +29,13 @@ enum { MLINK_BIND_RX, MLINK_PREP_DATA, MLINK_SEND1, - MLINK_CHECK1, + MLINK_BUILD1, MLINK_SEND2, - MLINK_CHECK2, + MLINK_BUILD2, MLINK_SEND3, - MLINK_CHECK3, + MLINK_BUILD3, MLINK_RX, - MLINK_CHECK4, + MLINK_BUILD4, }; uint8_t MLINK_Data_Code[16], MLINK_CRC_Init, MLINK_Unk_6_2; @@ -80,7 +78,7 @@ static void __attribute__((unused)) MLINK_cyrf_config() CYRF_SetTxRxMode(TX_EN); } -static void __attribute__((unused)) MLINK_send_bind_data_packet() +static void __attribute__((unused)) MLINK_send_bind_packet() { uint8_t p_c=packet_count>>1; @@ -146,7 +144,7 @@ static void __attribute__((unused)) MLINK_send_bind_data_packet() packet[7] = bit_reverse(crc8); // CRC reflected out //Debug - #if 1 + #if 0 debug("P(%02d):",p_c); for(uint8_t i=0;i<8;i++) debug(" %02X",packet[i]); @@ -218,19 +216,27 @@ static void __attribute__((unused)) MLINK_build_data_packet() #ifdef MLINK_HUB_TELEMETRY static void __attribute__((unused)) MLINK_Send_Telemetry() - { - if(packet[0]==0x03) - {//Basic telemetry + { // not sure how MLINK telemetry works, the 2 RXs I have are sending something completly different... + RX_RSSI = TX_LQI; + + if(packet_in[0]==0x13) + { // RX-9-DR : 13 1A C8 00 01 64 00 + v_lipo1 = packet_in[5*2]; // Rx_Batt*20 + } + + if(packet_in[0]==0x03) + { // RX-5 : 03 15 23 00 00 01 02 //Incoming packet values - RX_RSSI = packet_in[2*2]; // Looks to be the RX RSSI value + RX_RSSI = packet_in[2*2]<<1; // Looks to be the RX RSSI value RX_LQI = packet_in[5*2]; // Looks to be connection lost } // Read TX RSSI TX_RSSI = CYRF_ReadRegister(CYRF_13_RSSI)&0x1F; - telemetry_counter++; // TX LQI counter + telemetry_counter++; // TX LQI counter telemetry_link = 1; + if(telemetry_lost) { telemetry_lost = 0; @@ -243,9 +249,7 @@ static void __attribute__((unused)) MLINK_build_data_packet() uint16_t ReadMLINK() { uint8_t status;//,len,sum=0,check=0; - uint8_t start; - //uint16_t sum=0; - //static uint8_t retry; + uint16_t start; switch(phase) { @@ -300,7 +304,7 @@ uint16_t ReadMLINK() phase=MLINK_PREP_DATA; return 22720; } - MLINK_send_bind_data_packet(); + MLINK_send_bind_packet(); if(packet_count == 0 || packet_count > 0x19*2) { phase++; // MLINK_BIND_PREP_RX @@ -312,12 +316,14 @@ uint16_t ReadMLINK() return 22720; case MLINK_BIND_PREP_RX: start=micros(); - while ((uint8_t)((uint8_t)micros()-(uint8_t)start) < 200) // Wait max 200µs for TX to finish + while ((uint16_t)((uint16_t)micros()-(uint16_t)start) < 200) // Wait max 200µs for TX to finish if((CYRF_ReadRegister(CYRF_02_TX_CTRL) & 0x80) == 0x00) break; // Packet transmission complete CYRF_SetTxRxMode(RX_EN); // Receive mode CYRF_WriteRegister(CYRF_05_RX_CTRL, 0x82); // Prepare to receive phase++; //MLINK_BIND_RX + if(packet_count > 0x19*2) + return 28712; // Give more time to the RX to confirm that the bind is ok... return 28712-4700; @@ -332,56 +338,39 @@ uint16_t ReadMLINK() telemetry_lost = 1; #endif phase++; - case MLINK_SEND1: MLINK_build_data_packet(); + + + case MLINK_SEND1: CYRF_WriteRegister(CYRF_02_TX_CTRL, 0x40); CYRF_WriteRegisterMulti(CYRF_20_TX_BUFFER, packet, MLINK_PACKET_SIZE); CYRF_WriteRegister(CYRF_02_TX_CTRL, 0x82); phase++; return 4880; - case MLINK_CHECK1: - status=CYRF_ReadRegister(CYRF_04_TX_IRQ_STATUS); - //debugln("C1:%02X",status); - CYRF_WriteRegister(CYRF_02_TX_CTRL, 0x00); + case MLINK_BUILD1: phase++; + MLINK_build_data_packet(); return 1111; case MLINK_SEND2: - MLINK_build_data_packet(); CYRF_WriteRegister(CYRF_02_TX_CTRL, 0x40); CYRF_WriteRegisterMulti(CYRF_20_TX_BUFFER, packet, MLINK_PACKET_SIZE); CYRF_WriteRegister(CYRF_02_TX_CTRL, 0x82); phase++; return 4617; - case MLINK_CHECK2: - status=CYRF_ReadRegister(CYRF_04_TX_IRQ_STATUS); - //debugln("C2:%02X",status); - CYRF_WriteRegister(CYRF_02_TX_CTRL, 0x00); + case MLINK_BUILD2: phase++; + MLINK_build_data_packet(); if(hopping_frequency_no%5==0) return 1017; return 1422; case MLINK_SEND3: - MLINK_build_data_packet(); CYRF_WriteRegister(CYRF_02_TX_CTRL, 0x40); CYRF_WriteRegisterMulti(CYRF_20_TX_BUFFER, packet, MLINK_PACKET_SIZE); CYRF_WriteRegister(CYRF_02_TX_CTRL, 0x82); phase++; return 4611; - case MLINK_CHECK3: - status=CYRF_ReadRegister(CYRF_04_TX_IRQ_STATUS); - //debugln("C3:%02X",status); - CYRF_WriteRegister(CYRF_02_TX_CTRL, 0x00); - - //check RX but there is nothing to check... - status=CYRF_ReadRegister(CYRF_05_RX_CTRL); - //debugln("CTRL:%02X",status); - len=CYRF_ReadRegister(CYRF_09_RX_COUNT); - //debugln("L=%02X",len) - if( len && len<=8 ) - CYRF_ReadDataPacketLen(packet, len*2); - CYRF_WriteRegister(CYRF_05_RX_CTRL,0x00); - - //Next channel + case MLINK_BUILD3: + //Switch to next channel hopping_frequency_no++; if(hopping_frequency_no>=MLINK_NUM_FREQ) hopping_frequency_no=0; @@ -393,11 +382,12 @@ uint16_t ReadMLINK() CYRF_SetTxRxMode(RX_EN); // Receive mode CYRF_WriteRegister(CYRF_05_RX_CTRL, 0x82); // Prepare to receive phase++; //MLINK_RX - return 8038; + return 8038+2434+410-1000; } else CYRF_SetPower(0x38); phase=MLINK_SEND1; + MLINK_build_data_packet(); return 4470; case MLINK_RX: #ifdef MLINK_HUB_TELEMETRY @@ -414,27 +404,28 @@ uint16_t ReadMLINK() #endif status=CYRF_ReadRegister(CYRF_05_RX_CTRL);//CYRF_07_RX_IRQ_STATUS); debug("T(%02X):",status); - //status=CYRF_ReadRegister(CYRF_05_RX_CTRL); - //if( (status&0x80) == 0 ) + if( (status&0x80) == 0 ) {//Packet received len=CYRF_ReadRegister(CYRF_09_RX_COUNT); debug("(%X)",len) - if( len && len<=8 ) + if( len && len <= MLINK_PACKET_SIZE ) { CYRF_ReadDataPacketLen(packet_in, len*2); #ifdef MLINK_HUB_TELEMETRY - if(len==8) + if(len==MLINK_PACKET_SIZE) { + for(uint8_t i=0;i<8;i++) //Check CRC crc8=bit_reverse(MLINK_CRC_Init); for(uint8_t i=0;i normal Bayang protocol -Option=1 -> enable telemetry with [Silverxxx firmware](https://github.com/silver13/H101-acro/tree/master). Value returned to the TX using FrSkyD Hub are RX RSSI, TX RSSI, A1=uncompensated battery voltage (set the ratio to 5.0 and adjust with offset), A2=compensated battery voltage (set the ratio to 5.0 and adjust with offset) and if supported AccX=P, AccY=I, ACCZ=D +Option=1 -> enable telemetry with [Silverxxx firmware](https://github.com/silver13/H101-acro/tree/master). Value returned to the TX using FrSkyD Hub are RX RSSI, TX RSSI, A1=uncompensated battery voltage (set the ratio to 5.0 and adjust with offset), A2=compensated battery voltage (set the ratio to 5.0 and adjust with offset) and if supported AccX=P, AccY=I, ACCZ=D (which you can rename after the sensors discovery) Option=2 -> enable analog aux channels with [NFE Silverware firmware](https://github.com/NotFastEnuf/NFE_Silverware). Two otherwise static bytes in the protocol overridden to add two 'analog' (non-binary) auxiliary channels.