mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-12-13 19:13:14 +00:00
Multi Config
This commit is contained in:
179
Multiprotocol/Multi_Config.ino
Normal file
179
Multiprotocol/Multi_Config.ino
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
This project is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Multiprotocol is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if defined(MULTI_CONFIG_INO)
|
||||
|
||||
#ifdef CYRF6936_INSTALLED
|
||||
#include "iface_cyrf6936.h"
|
||||
#endif
|
||||
|
||||
void CONFIG_write_ID(uint32_t id)
|
||||
{
|
||||
for(uint8_t i=0;i<4;i++)
|
||||
eeprom_write_byte((EE_ADDR)EEPROM_ID_OFFSET+i,id >> (i*8));
|
||||
eeprom_write_byte((EE_ADDR)(EEPROM_ID_OFFSET+10),0xf0);
|
||||
}
|
||||
|
||||
uint16_t CONFIG_callback()
|
||||
{
|
||||
static uint8_t line=0, page=0;
|
||||
uint32_t id=0;
|
||||
// [0] = page<<4|line number
|
||||
// [1..6] = max 6 bytes
|
||||
if(CONFIG_SerialRX)
|
||||
{
|
||||
debug("config");
|
||||
for(uint8_t i=0; i<7; i++)
|
||||
debug("%02X ",CONFIG_SerialRX_val[i]);
|
||||
debugln("");
|
||||
CONFIG_SerialRX = false;
|
||||
switch(CONFIG_SerialRX_val[0]&0x0F)
|
||||
{
|
||||
//case 0:
|
||||
// Page change
|
||||
// break;
|
||||
case 1:
|
||||
for(uint8_t i=0; i<4; i++)
|
||||
{
|
||||
id <<= 8;
|
||||
id |= CONFIG_SerialRX_val[i+1];
|
||||
}
|
||||
debugln("Update ID to %lx", id);
|
||||
CONFIG_write_ID(id);
|
||||
break;
|
||||
case 2:
|
||||
if(CONFIG_SerialRX_val[1]==0xAA)
|
||||
{
|
||||
#define STM32_UUID ((uint32_t *)0x1FFFF7E8)
|
||||
id = STM32_UUID[0] ^ STM32_UUID[1] ^ STM32_UUID[2];
|
||||
debugln("Reset GID to %lx", id);
|
||||
CONFIG_write_ID(id);
|
||||
}
|
||||
break;
|
||||
#ifdef CYRF6936_INSTALLED
|
||||
case 4:
|
||||
debug("Update CID to ");
|
||||
for(uint8_t i=0; i<6; i++)
|
||||
debug("%02X ",CONFIG_SerialRX_val[i+1]);
|
||||
debugln("");
|
||||
case 5:
|
||||
if(CONFIG_SerialRX_val[1]==0xAA)
|
||||
{
|
||||
uint8_t data[6];
|
||||
CYRF_WriteRegister(CYRF_25_MFG_ID, 0xFF); /* Fuses power on */
|
||||
CYRF_ReadRegisterMulti(CYRF_25_MFG_ID, data, 6);
|
||||
CYRF_WriteRegister(CYRF_25_MFG_ID, 0x00); /* Fuses power off */
|
||||
debug("Reset CID to ");
|
||||
for(uint8_t i=0; i<6; i++)
|
||||
debug("%02X ",data[i]);
|
||||
debugln("");
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case 7:
|
||||
if(CONFIG_SerialRX_val[1]==0xAA)
|
||||
{
|
||||
debugln("Format EE");
|
||||
EEPROM.format();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( telemetry_link )
|
||||
return 10000;
|
||||
// [0] = page<<4|line number
|
||||
// line=0: VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, VERSION_PATCH_LEVEL, Channel order:RUDDER<<6|THROTTLE<<4|ELEVATOR<<2|AILERON
|
||||
// [1..21] = max 20 characters, any displayable chars followed by:
|
||||
// 0x00 : end of line
|
||||
// 0x80+len: selectable text to follow
|
||||
// 0x90+len: selectable text to follow with "Are you sure?"
|
||||
// 0xA0+len: not editable dec value
|
||||
// 0xB0+len: editable dec value
|
||||
// 0xC0+len: not editable hex value
|
||||
// 0xD0+len: editable hex value
|
||||
memset(&packet_in[1],0,20);
|
||||
do
|
||||
{
|
||||
packet_in[0] = (page<<4) | line;
|
||||
switch(line)
|
||||
{
|
||||
case 0:
|
||||
packet_in[1]=VERSION_MAJOR;
|
||||
packet_in[2]=VERSION_MINOR;
|
||||
packet_in[3]=VERSION_REVISION;
|
||||
packet_in[4]=VERSION_PATCH_LEVEL;
|
||||
packet_in[5]=RUDDER<<6|THROTTLE<<4|ELEVATOR<<2|AILERON;
|
||||
break;
|
||||
case 1:
|
||||
//Global ID
|
||||
#ifndef FORCE_GLOBAL_ID
|
||||
memcpy(&packet_in[1],"Global ID",9);
|
||||
packet_in[10] = 0xD0 + 4;
|
||||
#else
|
||||
memcpy(&packet_in[1],"Fixed ID ",9);
|
||||
packet_in[10] = 0xC0 + 4;
|
||||
#endif
|
||||
MProtocol_id_master = random_id(EEPROM_ID_OFFSET,false);
|
||||
set_rx_tx_addr(MProtocol_id_master);
|
||||
for(uint8_t i=0; i<4; i++)
|
||||
packet_in[11+i]=rx_tx_addr[i];
|
||||
break;
|
||||
#if defined(STM32_BOARD) && not defined(FORCE_GLOBAL_ID)
|
||||
case 2:
|
||||
//Reset global ID
|
||||
packet_in[1] = 0x90+9;
|
||||
memcpy(&packet_in[2],"Reset GID",9);
|
||||
break;
|
||||
#endif
|
||||
#ifdef CYRF6936_INSTALLED
|
||||
case 4:
|
||||
//Cyrf ID
|
||||
#ifndef FORCE_CYRF_ID
|
||||
memcpy(&packet_in[1],"Cyrf ID",7);
|
||||
packet_in[8] = 0xD0 + 6;
|
||||
CYRF_GetMfgData(&packet_in[9]);
|
||||
#else
|
||||
memcpy(&packet_in[1],"Fixed CID",9);
|
||||
packet_in[10] = 0xC0 + 6;
|
||||
CYRF_GetMfgData(&packet_in[11]);
|
||||
#endif
|
||||
break;
|
||||
#ifndef FORCE_CYRF_ID
|
||||
case 5:
|
||||
//Reset Cyrf ID
|
||||
packet_in[1] = 0x90+9;
|
||||
memcpy(&packet_in[2],"Reset CID",9);
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
case 7:
|
||||
packet_in[1] = 0x90+13;
|
||||
memcpy(&packet_in[2],"Format EEPROM",13);
|
||||
break;
|
||||
}
|
||||
line++;
|
||||
line %= 8;
|
||||
}
|
||||
while(packet_in[1]==0); // next line if empty
|
||||
telemetry_link = 1;
|
||||
return 10000;
|
||||
}
|
||||
|
||||
void CONFIG_init()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -98,6 +98,7 @@ const char STR_E010R5[] ="E010r5";
|
||||
const char STR_LOLI[] ="LOLI";
|
||||
const char STR_E129[] ="E129";
|
||||
const char STR_E016H[] ="E016H";
|
||||
const char STR_CONFIG[] ="Config";
|
||||
|
||||
const char STR_SUBTYPE_FLYSKY[] = "\x04""Std\0""V9x9""V6x6""V912""CX20";
|
||||
const char STR_SUBTYPE_HUBSAN[] = "\x04""H107""H301""H501";
|
||||
@@ -187,6 +188,7 @@ enum
|
||||
const mm_protocol_definition multi_protocols[] = {
|
||||
// Protocol number, Protocol String, Sub_protocol strings, Number of sub_protocols, Option type, Failsafe, ChMap, RF switch, Init, Callback
|
||||
#if defined(MULTI_CONFIG_INO)
|
||||
{0x00, STR_CONFIG, NO_SUBTYPE, 0, OPTION_NONE, 0, 0, 0, CONFIG_init, CONFIG_callback },
|
||||
{PROTO_CONFIG, STR_CONFIG, NO_SUBTYPE, 0, OPTION_NONE, 0, 0, 0, CONFIG_init, CONFIG_callback },
|
||||
#endif
|
||||
#if defined(ASSAN_NRF24L01_INO)
|
||||
@@ -449,5 +451,5 @@ const mm_protocol_definition multi_protocols[] = {
|
||||
#if defined(NANORF_NRF24L01_INO)
|
||||
{PROTO_NANORF, STR_NANORF, NO_SUBTYPE, 0, OPTION_NONE, 0, 0, SW_NRF, NANORF_init, NANORF_callback },
|
||||
#endif
|
||||
{0x00, nullptr, nullptr, 0, 0, 0, 0, 0, nullptr, nullptr }
|
||||
{0xFF, nullptr, nullptr, 0, 0, 0, 0, 0, nullptr, nullptr }
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#define VERSION_MAJOR 1
|
||||
#define VERSION_MINOR 3
|
||||
#define VERSION_REVISION 2
|
||||
#define VERSION_PATCH_LEVEL 62
|
||||
#define VERSION_PATCH_LEVEL 63
|
||||
|
||||
#define MODE_SERIAL 0
|
||||
|
||||
@@ -113,6 +113,7 @@ enum PROTOCOLS
|
||||
PROTO_E129 = 83, // =>CYRF6936
|
||||
PROTO_JOYSWAY = 84, // =>A7105
|
||||
PROTO_E016H = 85, // =>NRF24L01
|
||||
PROTO_CONFIG = 86, // Module config
|
||||
|
||||
PROTO_NANORF = 126, // =>NRF24L01
|
||||
PROTO_TEST = 127, // =>CC2500
|
||||
@@ -1258,4 +1259,8 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
|
||||
data[1] = TX_LQI
|
||||
data[2] = telem_type
|
||||
data[3-9] = data
|
||||
|
||||
Type 0x10 Config telemetry
|
||||
length: 22
|
||||
data[0..21] = Config data
|
||||
*/
|
||||
|
||||
@@ -1191,7 +1191,7 @@ static void protocol_init()
|
||||
#if defined(FRSKYX_CC2500_INO) && defined(EU_MODULE)
|
||||
if( ! ( (protocol == PROTO_FRSKYX || protocol == PROTO_FRSKYX2) && sub_protocol < 2 ) )
|
||||
#endif
|
||||
while(multi_protocols[index].protocol != 0)
|
||||
while(multi_protocols[index].protocol != 0xFF)
|
||||
{
|
||||
if(multi_protocols[index].protocol==protocol)
|
||||
{
|
||||
@@ -1831,7 +1831,7 @@ static uint32_t random_id(uint16_t address, uint8_t create_new)
|
||||
}
|
||||
if(id!=0x2AD141A7) //ID with seed=0
|
||||
{
|
||||
debugln("Read ID from EEPROM");
|
||||
//debugln("Read ID from EEPROM");
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,11 +188,11 @@ static void multi_send_status()
|
||||
else
|
||||
{
|
||||
// Protocol next/prev
|
||||
if(multi_protocols[multi_protocols_index+1].protocol != 0)
|
||||
if(multi_protocols[multi_protocols_index+1].protocol != 0xFF)
|
||||
{
|
||||
if(multi_protocols[multi_protocols_index+1].protocol == PROTO_SCANNER)
|
||||
{// if next is scanner
|
||||
if(multi_protocols[multi_protocols_index+2].protocol != 0)
|
||||
if(multi_protocols[multi_protocols_index+2].protocol != 0xFF)
|
||||
Serial_write(multi_protocols[multi_protocols_index+2].protocol); // skip to next protocol number
|
||||
else
|
||||
Serial_write(multi_protocols[multi_protocols_index].protocol); // or end of list
|
||||
@@ -202,7 +202,7 @@ static void multi_send_status()
|
||||
}
|
||||
else
|
||||
Serial_write(multi_protocols[multi_protocols_index].protocol); // end of list
|
||||
if(multi_protocols_index>0)
|
||||
if(multi_protocols_index>0 && multi_protocols[multi_protocols_index-1].protocol != 0)
|
||||
{
|
||||
if(multi_protocols[multi_protocols_index-1].protocol==PROTO_SCANNER)
|
||||
{// if prev is scanner
|
||||
@@ -241,8 +241,8 @@ static void multi_send_status()
|
||||
#ifdef MULTI_CONFIG_INO
|
||||
void CONFIG_frame()
|
||||
{
|
||||
multi_send_header(MULTI_TELEMETRY_CONFIG, packet_in[0]);
|
||||
for (uint8_t i = 1; i <= packet_in[0]; i++) // config data
|
||||
multi_send_header(MULTI_TELEMETRY_CONFIG, 21);
|
||||
for (uint8_t i = 0; i < 21; i++) // Config data
|
||||
Serial_write(packet_in[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user