Multi module config support (#8438)
* Multi module configuration Co-authored-by: Pascal Langer <pascal_langer@yahoo.fr>
This commit is contained in:
@@ -123,7 +123,7 @@ bool menuRadioTools(event_t event)
|
||||
#elif defined(INTERNAL_MODULE_MULTI)
|
||||
addRadioModuleTool(index++, STR_SPECTRUM_ANALYSER_INT, menuRadioSpectrumAnalyser, INTERNAL_MODULE);
|
||||
#endif
|
||||
#if defined(PXX2)|| defined(MULTIMODULE)
|
||||
#if defined(PXX2) || defined(MULTIMODULE)
|
||||
if (isPXX2ModuleOptionAvailable(reusableBuffer.hardwareAndSettings.modules[EXTERNAL_MODULE].information.modelID, MODULE_OPTION_SPECTRUM_ANALYSER) || isModuleMultimodule(EXTERNAL_MODULE))
|
||||
addRadioModuleTool(index++, STR_SPECTRUM_ANALYSER_EXT, menuRadioSpectrumAnalyser, EXTERNAL_MODULE);
|
||||
#endif
|
||||
|
||||
@@ -120,11 +120,11 @@ Get RF module parameters
|
||||
* `channelsCount` (number) number of channels sent to module
|
||||
* `Type` (number) module type
|
||||
* if the module type is Multi additional information are available
|
||||
* `protocol` (number) protocol number
|
||||
* `subProtocol` (number) sub-protocol number
|
||||
* `channelsOrder` (number) first 4 channels expected order
|
||||
* `protocol` (number) protocol number (Multi only)
|
||||
* `subProtocol` (number) sub-protocol number (Multi only)
|
||||
* `channelsOrder` (number) first 4 channels expected order (Multi only)
|
||||
|
||||
@status current Introduced in TODO
|
||||
@status current Introduced in 2.2.0
|
||||
*/
|
||||
static int luaModelGetModule(lua_State *L)
|
||||
{
|
||||
@@ -174,13 +174,16 @@ Set RF module parameters
|
||||
@notice If a parameter is missing from the value, then
|
||||
that parameter remains unchanged.
|
||||
|
||||
@status current Introduced in TODO
|
||||
@status current Introduced in 2.2.0, modified in 2.3.12 (proto/subproto)
|
||||
*/
|
||||
static int luaModelSetModule(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
|
||||
if (idx < NUM_MODULES) {
|
||||
int protocol = -1;
|
||||
int subprotocol = -1;
|
||||
|
||||
ModuleData & module = g_model.moduleData[idx];
|
||||
luaL_checktype(L, -1, LUA_TTABLE);
|
||||
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
|
||||
@@ -201,7 +204,22 @@ static int luaModelSetModule(lua_State *L)
|
||||
else if (!strcmp(key, "channelsCount")) {
|
||||
module.channelsCount = luaL_checkinteger(L, -1) - 8;
|
||||
}
|
||||
#if defined(MULTIMODULE)
|
||||
if (!strcmp(key, "protocol")) {
|
||||
protocol = luaL_checkinteger(L, -1);
|
||||
}
|
||||
if (!strcmp(key, "subProtocol")) {
|
||||
subprotocol = luaL_checkinteger(L, -1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#if defined(MULTIMODULE)
|
||||
if (protocol > 0 && subprotocol >= 0) { // Both are needed to compute otx protocol
|
||||
convertMultiProtocolToOtx(&protocol, &subprotocol);
|
||||
g_model.moduleData[idx].setMultiProtocol(protocol - 1);
|
||||
g_model.moduleData[idx].subType = subprotocol;
|
||||
}
|
||||
#endif
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -177,12 +177,17 @@ enum ModuleSubtypeMulti {
|
||||
MODULE_SUBTYPE_MULTI_ELRS,
|
||||
MODULE_SUBTYPE_MULTI_REALACC,
|
||||
MODULE_SUBTYPE_MULTI_OMP,
|
||||
MODULE_SUBTYPE_MULTI_MLINK, //75
|
||||
MODULE_SUBTYPE_MULTI_MLINK, //75
|
||||
MODULE_SUBTYPE_MULTI_WFLY2,
|
||||
MODULE_SUBTYPE_MULTI_E016HV2,
|
||||
MODULE_SUBTYPE_MULTI_LAST = MODULE_SUBTYPE_MULTI_E016HV2
|
||||
MODULE_SUBTYPE_MULTI_E010R5,
|
||||
MODULE_SUBTYPE_MULTI_LOLI,
|
||||
MODULE_SUBTYPE_MULTI_E129, //80
|
||||
MODULE_SUBTYPE_MULTI_JOYSWAY,
|
||||
MODULE_SUBTYPE_MULTI_E016H,
|
||||
MODULE_SUBTYPE_MULTI_CONFIG,
|
||||
MODULE_SUBTYPE_MULTI_LAST = MODULE_SUBTYPE_MULTI_CONFIG
|
||||
};
|
||||
#define MODULE_SUBTYPE_MULTI_XN297DP 63-3
|
||||
|
||||
enum MMDSM2Subtypes {
|
||||
MM_RF_DSM2_SUBTYPE_DSM2_22,
|
||||
|
||||
@@ -669,7 +669,7 @@ inline void getMultiOptionValues(int8_t multi_proto, int8_t & min, int8_t & max)
|
||||
min = 0;
|
||||
max = 70;
|
||||
break;
|
||||
case MODULE_SUBTYPE_MULTI_XN297DP:
|
||||
case MODULE_SUBTYPE_MULTI_XN297DUMP:
|
||||
min = -1;
|
||||
max = 84;
|
||||
break;
|
||||
|
||||
@@ -42,6 +42,7 @@ static void sendD16BindOption(uint8_t moduleIdx);
|
||||
#if defined(LUA)
|
||||
static void sendSport(uint8_t moduleIdx);
|
||||
static void sendHott(uint8_t moduleIdx);
|
||||
static void sendConfig(uint8_t moduleIdx);
|
||||
static void sendDSM(uint8_t moduleIdx);
|
||||
#endif
|
||||
|
||||
@@ -190,11 +191,14 @@ void setupPulsesMulti(uint8_t moduleIdx)
|
||||
#if defined(LUA)
|
||||
// SPort send
|
||||
if (IS_D16_MULTI(moduleIdx) && outputTelemetryBuffer.destination == TELEMETRY_ENDPOINT_SPORT && outputTelemetryBuffer.size) {
|
||||
sendSport(moduleIdx); //8 bytes of additional data
|
||||
sendSport(moduleIdx); //8 bytes of additional data
|
||||
}
|
||||
else if (IS_HOTT_MULTI(moduleIdx)) {
|
||||
sendHott(moduleIdx); //1 byte of additional data
|
||||
}
|
||||
else if (IS_CONFIG_MULTI(moduleIdx)) {
|
||||
sendConfig(moduleIdx); //7 bytes of additional data
|
||||
}
|
||||
else if (IS_DSM_MULTI(moduleIdx)) {
|
||||
sendDSM(moduleIdx); //7 bytes of additional data
|
||||
}
|
||||
@@ -251,10 +255,54 @@ void sendChannels(uint8_t moduleIdx)
|
||||
}
|
||||
}
|
||||
|
||||
void convertMultiProtocolToOtx(int *protocol, int *subprotocol)
|
||||
{
|
||||
if (*protocol == 3 and *subprotocol == 0) {
|
||||
*protocol = MODULE_SUBTYPE_MULTI_FRSKY + 1;
|
||||
*subprotocol = MM_RF_FRSKY_SUBTYPE_D8;
|
||||
return;
|
||||
}
|
||||
|
||||
if (*protocol == 3 and *subprotocol == 1) {
|
||||
*protocol = MODULE_SUBTYPE_MULTI_FRSKY + 1;
|
||||
*subprotocol = MM_RF_FRSKY_SUBTYPE_D8_CLONED;
|
||||
return;
|
||||
}
|
||||
|
||||
if (*protocol == 25) {
|
||||
*protocol = MODULE_SUBTYPE_MULTI_FRSKY + 1;
|
||||
*subprotocol = MM_RF_FRSKY_SUBTYPE_V8;
|
||||
return;
|
||||
}
|
||||
|
||||
if (*protocol == 15) {
|
||||
*protocol = MODULE_SUBTYPE_MULTI_FRSKY + 1;
|
||||
|
||||
if (*subprotocol == 0)
|
||||
*subprotocol = MM_RF_FRSKY_SUBTYPE_D16;
|
||||
else if (*subprotocol == 1)
|
||||
*subprotocol = MM_RF_FRSKY_SUBTYPE_D16_8CH;
|
||||
else if (*subprotocol == 2)
|
||||
*subprotocol = MM_RF_FRSKY_SUBTYPE_D16_LBT;
|
||||
else if (*subprotocol == 3)
|
||||
*subprotocol = MM_RF_FRSKY_SUBTYPE_D16_LBT_8CH;
|
||||
else if (*subprotocol == 4)
|
||||
*subprotocol = MM_RF_FRSKY_SUBTYPE_D16_CLONED;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (*protocol >= 25)
|
||||
*protocol -= 1;
|
||||
|
||||
if (*protocol >= 16)
|
||||
*protocol -= 1;
|
||||
}
|
||||
|
||||
void convertOtxProtocolToMulti(int *protocol, int *subprotocol)
|
||||
{
|
||||
// Special treatment for the FrSky entry...
|
||||
if (*protocol == MODULE_SUBTYPE_MULTI_FRSKY +1) {
|
||||
if (*protocol == MODULE_SUBTYPE_MULTI_FRSKY + 1) {
|
||||
if (*subprotocol == MM_RF_FRSKY_SUBTYPE_D8) {
|
||||
//D8
|
||||
*protocol = 3;
|
||||
@@ -288,10 +336,10 @@ void convertOtxProtocolToMulti(int *protocol, int *subprotocol)
|
||||
// 15 for Multimodule is FrskyX or D16 which we map as a protocol of 3 (FrSky)
|
||||
// all protos > frskyx are therefore also off by one
|
||||
if (*protocol >= 15)
|
||||
*protocol = *protocol + 1;
|
||||
*protocol += 1;
|
||||
// 25 is again a FrSky *protocol (FrskyV) so shift again
|
||||
if (*protocol >= 25)
|
||||
*protocol = *protocol + 1;
|
||||
*protocol += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,6 +452,23 @@ void sendHott(uint8_t moduleIdx)
|
||||
}
|
||||
}
|
||||
|
||||
void sendConfig(uint8_t moduleIdx)
|
||||
{
|
||||
// Multi_Buffer[0..3]=="Conf" -> Lua script is running
|
||||
// Multi_Buffer[4]==0x01 -> TX to Module data ready to be sent
|
||||
// Multi_Buffer[4]==0xFF -> Clear buffer data
|
||||
// Multi_Buffer[5..11]=7 bytes of TX to Module data
|
||||
// Multi_Buffer[12] -> Current page
|
||||
// Multi_Buffer[13..172]=8*20=160 bytes of Module to TX data
|
||||
if (Multi_Buffer && memcmp(Multi_Buffer, "Conf", 4) == 0 && Multi_Buffer[4] == 0x01) {
|
||||
// Config Lua script is running and sending
|
||||
for (uint8_t i = 0; i < 7; i++) {
|
||||
sendMulti(moduleIdx, Multi_Buffer[5 + i]);
|
||||
}
|
||||
Multi_Buffer[4] = 0x00; // Send data only once
|
||||
}
|
||||
}
|
||||
|
||||
void sendDSM(uint8_t moduleIdx)
|
||||
{
|
||||
// Multi_Buffer[0..2]=="DSM" -> Lua script is running
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
void multiPatchCustom(uint8_t moduleIdx);
|
||||
void convertOtxProtocolToMulti(int *protocol, int *subprotocol);
|
||||
void convertMultiProtocolToOtx(int *protocol, int *subprotocol);
|
||||
|
||||
class UartMultiPulses: public DataBuffer<uint8_t, 64>
|
||||
{
|
||||
|
||||
@@ -42,7 +42,8 @@ enum MultiPacketTypes : uint8_t
|
||||
FlyskyIBusTelemetryAC,
|
||||
MultiRxChannels,
|
||||
HottTelemetry,
|
||||
MLinkTelemetry
|
||||
MLinkTelemetry,
|
||||
ConfigTelemetry
|
||||
};
|
||||
|
||||
enum MultiBufferState : uint8_t
|
||||
@@ -291,6 +292,31 @@ static void processMultiRxChannels(const uint8_t * data, uint8_t len)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LUA)
|
||||
|
||||
static void processConfigPacket(const uint8_t * packet, uint8_t len)
|
||||
{
|
||||
// Multi_Buffer[0..3]=="Conf" -> Lua script is running
|
||||
// Multi_Buffer[4]==0x01 -> TX to Module data ready to be sent
|
||||
// Multi_Buffer[4]==0xFF -> Clear buffer data
|
||||
// Multi_Buffer[5..11]=7 bytes of TX to Module data
|
||||
// Multi_Buffer[12] -> Current page
|
||||
// Multi_Buffer[13..172]=8*20=160 bytes of Module to TX data
|
||||
if (Multi_Buffer && memcmp(Multi_Buffer, "Conf", 4) == 0) {
|
||||
// HoTT Lua script is running
|
||||
if (Multi_Buffer[4] == 0xFF) {
|
||||
// Init
|
||||
memset(&Multi_Buffer[4], 0x00, 1 + 7 + 1 + 160); // Clear the buffer
|
||||
}
|
||||
if ((packet[0] >> 4) != Multi_Buffer[12]) {// page change
|
||||
memset(&Multi_Buffer[13], 0x00, 160); // Clear the buffer
|
||||
Multi_Buffer[12] = (packet[0] >> 4); //Save the page number
|
||||
}
|
||||
memcpy(&Multi_Buffer[13 + (packet[0] & 0x0F) * 20], &packet[1], 20); // Store the received page in the buffer
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void processMultiTelemetryPaket(const uint8_t * packet, uint8_t module)
|
||||
{
|
||||
uint8_t type = packet[0];
|
||||
@@ -363,9 +389,18 @@ static void processMultiTelemetryPaket(const uint8_t * packet, uint8_t module)
|
||||
if (len > 6)
|
||||
processMLinkPacket(data);
|
||||
else
|
||||
TRACE("[MP] Received M-Link telemetry len %d < 6", len);
|
||||
TRACE("[MP] Received M-Link telemetry len %d <= 6", len);
|
||||
break;
|
||||
|
||||
#if defined(LUA)
|
||||
case ConfigTelemetry:
|
||||
if (len >= 21)
|
||||
processConfigPacket(data, len);
|
||||
else
|
||||
TRACE("[MP] Received Config telemetry len %d < 20", len);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case FrSkyHubTelemetry:
|
||||
if (len >= 4)
|
||||
frskyDProcessPacket(data);
|
||||
|
||||
@@ -118,6 +118,7 @@ extern uint8_t telemetryProtocol;
|
||||
|| (g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_FRSKYX2))
|
||||
#define IS_R9_MULTI(module) (g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_FRSKY_R9)
|
||||
#define IS_HOTT_MULTI(module) (g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_HOTT)
|
||||
#define IS_CONFIG_MULTI(module) (g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_CONFIG)
|
||||
#define IS_DSM_MULTI(module) (g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_DSM2)
|
||||
#define IS_RX_MULTI(module) ((g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_AFHDS2A_RX) || (g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_FRSKYX_RX) \
|
||||
|| (g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_BAYANG_RX) || (g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_DSM_RX))
|
||||
@@ -130,6 +131,7 @@ extern uint8_t telemetryProtocol;
|
||||
#define IS_D16_MULTI(module) false
|
||||
#define IS_R9_MULTI(module) false
|
||||
#define IS_HOTT_MULTI(module) false
|
||||
#define IS_CONFIG_MULTI(module) false
|
||||
#define IS_DSM_MULTI(module) false
|
||||
#define IS_FRSKY_SPORT_PROTOCOL() (telemetryProtocol == PROTOCOL_TELEMETRY_FRSKY_SPORT)
|
||||
#define IS_RX_MULTI(module) false
|
||||
|
||||
@@ -131,7 +131,7 @@
|
||||
#define TR_DSM_PROTOCOLS "LP45""DSM2""DSMX"
|
||||
|
||||
#define LEN_MULTI_PROTOCOLS "\007"
|
||||
#define TR_MULTI_PROTOCOLS "FlySky\0""Hubsan\0""FrSky\0 ""Hisky\0 ""V2x2\0 ""DSM\0 ""Devo\0 ""YD717\0 ""KN\0 ""SymaX\0 ""SLT\0 ""CX10\0 ""CG023\0 ""Bayang\0""ESky\0 ""MT99XX\0""MJXq\0 ""Shenqi\0""FY326\0 ""Futaba\0""J6 Pro\0""FQ777\0 ""Assan\0 ""Hontai\0""OpenLrs""FlSky2A""Q2x2\0 ""Walkera""Q303\0 ""GW008\0 ""DM002\0 ""Cabell\0""Esky150""H8 3D\0 ""Corona\0""CFlie\0 ""Hitec\0 ""WFly\0 ""Bugs\0 ""BugMini""Traxxas""NCC1701""E01X\0 ""V911S\0 ""GD00X\0 ""V761\0 ""KF606\0 ""Redpine""Potensi""ZSX\0 ""Height\0""Scanner""FrSkyRX""FS2A_RX""HoTT\0 ""FX816\0 ""BayanRX""Pelikan""Tiger\0 ""XK\0 ""XN297DU""FrSkyX2""FrSkyR9""Propel\0""FrSkyL\0""Skyartc""ESky-v2""DSM RX\0""JJRC345""Q90C\0 ""Kyosho\0""RadLink""ExpLRS\0""Realacc""OMP\0 ""M-Link\0""Wfly 2\0""E016Hv2"
|
||||
#define TR_MULTI_PROTOCOLS "FlySky\0""Hubsan\0""FrSky\0 ""Hisky\0 ""V2x2\0 ""DSM\0 ""Devo\0 ""YD717\0 ""KN\0 ""SymaX\0 ""SLT\0 ""CX10\0 ""CG023\0 ""Bayang\0""ESky\0 ""MT99XX\0""MJXq\0 ""Shenqi\0""FY326\0 ""Futaba\0""J6 Pro\0""FQ777\0 ""Assan\0 ""Hontai\0""OpenLrs""FlSky2A""Q2x2\0 ""Walkera""Q303\0 ""GW008\0 ""DM002\0 ""Cabell\0""Esky150""H8 3D\0 ""Corona\0""CFlie\0 ""Hitec\0 ""WFly\0 ""Bugs\0 ""BugMini""Traxxas""NCC1701""E01X\0 ""V911S\0 ""GD00X\0 ""V761\0 ""KF606\0 ""Redpine""Potensi""ZSX\0 ""Height\0""Scanner""FrSkyRX""FS2A_RX""HoTT\0 ""FX816\0 ""BayanRX""Pelikan""Tiger\0 ""XK\0 ""XN297DU""FrSkyX2""FrSkyR9""Propel\0""FrSkyL\0""Skyartc""ESky-v2""DSM RX\0""JJRC345""Q90C\0 ""Kyosho\0""RadLink""ExpLRS\0""Realacc""OMP\0 ""M-Link\0""Wfly 2\0""E016Hv2""E010r5 ""LOLI\0 ""E129\0 ""JOYSWAY""E016H\0 ""Config\0"
|
||||
|
||||
#define LEN_MULTI_POWER "\005"
|
||||
#define TR_MULTI_POWER "1.6mW""2.0mW""2.5mW""3.2mW""4.0mW""5.0mW""6.3mW""7.9mW""10mW\0""13mW\0""16mW\0""20mW\0""25mW\0""32mW\0""40mW\0""50mW\0"
|
||||
|
||||
Reference in New Issue
Block a user