Skip to content

Commit 7016715

Browse files
authored
MAVLink PR150 rebased
* Merged EdgeTX PR EdgeTX#150 * Added MAVLink YAML elements. * Set fastmavlink to be8b000 and mavlink to 37a6e90.
1 parent 12c6f22 commit 7016715

43 files changed

Lines changed: 7049 additions & 13 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@
88
[submodule "companion/src/thirdparty/yaml-cpp"]
99
path = companion/src/thirdparty/yaml-cpp
1010
url = https://github.com/jbeder/yaml-cpp.git
11+
[submodule "radio/src/thirdparty/Mavlink/mavlink"]
12+
path = radio/src/thirdparty/Mavlink/mavlink
13+
url = https://github.com/mavlink/mavlink.git
14+
[submodule "radio/src/thirdparty/Mavlink/fastmavlink"]
15+
path = radio/src/thirdparty/Mavlink/fastmavlink
16+
url = https://github.com/olliw42/fastmavlink.git

radio/src/dataconstants.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,11 @@ enum UartModes {
248248
UART_MODE_TELEMETRY,
249249
UART_MODE_SBUS_TRAINER,
250250
UART_MODE_LUA,
251-
UART_MODE_COUNT SKIP,
252-
UART_MODE_MAX SKIP = UART_MODE_COUNT-1
251+
#if defined(TELEMETRY_MAVLINK)
252+
UART_MODE_MAVLINK,
253+
#endif
254+
UART_MODE_COUNT,
255+
UART_MODE_MAX = UART_MODE_COUNT-1
253256
};
254257

255258
#if defined(CLI) || defined(DEBUG)

radio/src/datastructs.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,21 @@ static inline void check_struct()
135135
CHKSIZE(ModelData, 6606);
136136
#elif defined(PCBHORUS)
137137
#if defined(PCBX10)
138-
CHKSIZE(RadioData, 921);
139-
CHKSIZE(ModelData, 11026);
138+
#if defined(TELEMETRY_MAVLINK)
139+
CHKSIZE(RadioData, 921+1);
140+
CHKSIZE(ModelData, 11026+2);
141+
#else
142+
CHKSIZE(RadioData, 921);
143+
CHKSIZE(ModelData, 11026);
144+
#endif
140145
#else
141-
CHKSIZE(RadioData, 903);
142-
CHKSIZE(ModelData, 11024);
146+
#if defined(TELEMETRY_MAVLINK)
147+
CHKSIZE(RadioData, 903+1);
148+
CHKSIZE(ModelData, 11024+2);
149+
#else
150+
CHKSIZE(RadioData, 903);
151+
CHKSIZE(ModelData, 11024);
152+
#endif
143153
#endif
144154
#endif
145155

radio/src/datastructs_private.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,17 @@ PACK(struct ModelData {
706706

707707
FUNCTION_SWITCHS_FIELDS
708708

709+
#if defined(TELEMETRY_MAVLINK)
710+
// TODO: use a specific structure
711+
uint8_t mavlinkRssi:1;
712+
uint8_t mavlinkMimicSensors:3; // currently just on/off, but allow in the future e.g. FrSky, CF, FrSky passthrough.
713+
uint8_t mavlinkRcOverride:1;
714+
uint8_t mavlinkSpare:3;
715+
uint8_t mavlinkRssiScale;
716+
// needs to adapt CHKSIZE in datastructs.h
717+
// if not all are used, compiler optiomizes to lowest size, which may raise an error
718+
#endif
719+
709720
bool isTrainerTraineeEnable() const
710721
{
711722
#if defined(PCBNV14)
@@ -919,6 +930,14 @@ PACK(struct RadioData {
919930
GYRO_FIELDS
920931

921932
NOBACKUP(int8_t uartSampleMode:2); // See UartSampleModes
933+
934+
#if defined(TELEMETRY_MAVLINK)
935+
// TODO: use specific structure
936+
uint8_t mavlinkBaudrate:3;
937+
uint8_t mavlinkBaudrate2:3;
938+
uint8_t mavlinkSpare:2;
939+
// needs to adapt to CHKSIZE in datastructs.h
940+
#endif
922941
});
923942

924943
#undef SWITCHES_WARNING_DATA

radio/src/gui/colorlcd/model_setup.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,29 @@ void ModelSetupPage::build(FormWindow * window)
16681668
grid.addWindow(new TrainerModuleWindow(window, {0, grid.getWindowHeight(), LCD_W, 0}));
16691669
}
16701670

1671+
#if defined(TELEMETRY_MAVLINK)
1672+
// Mavlink
1673+
{
1674+
new Subtitle(window, grid.getLineSlot(), STR_MAVLINK);
1675+
grid.nextLine();
1676+
1677+
new StaticText(window, grid.getLabelSlot(true), STR_MAVLINK_RSSI);
1678+
new CheckBox(window, grid.getFieldSlot(), GET_SET_DEFAULT(g_model.mavlinkRssi));
1679+
grid.nextLine();
1680+
1681+
new StaticText(window, grid.getLabelSlot(true), STR_MAVLINK_RSSI_SCALE);
1682+
new NumberEdit(window, grid.getFieldSlot(2,0), 0, 255, GET_SET_DEFAULT(g_model.mavlinkRssiScale));
1683+
grid.nextLine();
1684+
1685+
new StaticText(window, grid.getLabelSlot(true), STR_MAVLINK_SENSOR_MIMICRY);
1686+
new CheckBox(window, grid.getFieldSlot(), GET_SET_DEFAULT(g_model.mavlinkMimicSensors));
1687+
grid.nextLine();
1688+
1689+
new StaticText(window, grid.getLabelSlot(true), STR_MAVLINK_RC_OVERRIDE);
1690+
new CheckBox(window, grid.getFieldSlot(), GET_SET_DEFAULT(g_model.mavlinkRcOverride));
1691+
grid.nextLine();
1692+
}
1693+
#endif
16711694

16721695
window->setInnerHeight(grid.getWindowHeight());
16731696
}

radio/src/gui/colorlcd/radio_hardware.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,28 +374,38 @@ void RadioHardwarePage::build(FormWindow * window)
374374

375375
#if defined(AUX_SERIAL)
376376
new StaticText(window, grid.getLabelSlot(), STR_AUX_SERIAL_MODE, 0, COLOR_THEME_PRIMARY1);
377-
auto aux =
377+
#if defined(TELEMETRY_MAVLINK)
378+
auto aux = new Choice(window, grid.getFieldSlot(2,0), STR_MAVLINK_AUX_SERIAL_MODES, 0, UART_MODE_MAX, GET_SET_DEFAULT(g_eeGeneral.auxSerialMode));
379+
new Choice(window, grid.getFieldSlot(2,1), STR_MAVLINK_AUX_BAUDRATES, 0, 3, GET_SET_DEFAULT(g_eeGeneral.mavlinkBaudrate));
380+
#else
381+
auto aux =
378382
new Choice(window, grid.getFieldSlot(1, 0), STR_AUX_SERIAL_MODES, 0,
379383
UART_MODE_MAX, GET_DEFAULT(g_eeGeneral.auxSerialMode),
380384
[](int value) {
381385
g_eeGeneral.auxSerialMode = value;
382386
auxSerialInit(g_eeGeneral.auxSerialMode, modelTelemetryProtocol());
383387
SET_DIRTY();
384388
});
389+
#endif
385390
aux->setAvailableHandler(isAuxModeAvailable);
386391
grid.nextLine();
387392
#endif
388393

389394
#if defined(AUX2_SERIAL)
390395
new StaticText(window, grid.getLabelSlot(), STR_AUX2_SERIAL_MODE, 0, COLOR_THEME_PRIMARY1);
391-
auto aux2 =
396+
#if defined(TELEMETRY_MAVLINK)
397+
auto aux2 = new Choice(window, grid.getFieldSlot(2,0), STR_MAVLINK_AUX_SERIAL_MODES, 0, UART_MODE_MAX, GET_SET_DEFAULT(g_eeGeneral.aux2SerialMode));
398+
new Choice(window, grid.getFieldSlot(2,1), STR_MAVLINK_AUX_BAUDRATES, 0, 3, GET_SET_DEFAULT(g_eeGeneral.mavlinkBaudrate2));
399+
#else
400+
auto aux2 =
392401
new Choice(window, grid.getFieldSlot(1, 0), STR_AUX_SERIAL_MODES, 0,
393402
UART_MODE_MAX, GET_DEFAULT(g_eeGeneral.aux2SerialMode),
394403
[](int value) {
395404
g_eeGeneral.aux2SerialMode = value;
396405
aux2SerialInit(g_eeGeneral.aux2SerialMode, modelTelemetryProtocol());
397406
SET_DIRTY();
398407
});
408+
#endif
399409
aux2->setAvailableHandler(isAux2ModeAvailable);
400410
grid.nextLine();
401411
#endif

radio/src/gui/gui_common.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,11 @@ bool isAuxModeAvailable(int mode)
372372
#if defined(AUX2_SERIAL)
373373
if (mode == UART_MODE_SBUS_TRAINER)
374374
return g_eeGeneral.aux2SerialMode != UART_MODE_SBUS_TRAINER;
375+
#if defined(TELEMETRY_MAVLINK)
376+
else
377+
if (mode == UART_MODE_MAVLINK)
378+
return true;
379+
#endif
375380
#if defined(RADIO_TX16S)
376381
else
377382
return (g_model.trainerData.mode != TRAINER_MODE_MASTER_BATTERY_COMPARTMENT || g_eeGeneral.aux2SerialMode == UART_MODE_SBUS_TRAINER);
@@ -385,6 +390,11 @@ bool isAux2ModeAvailable(int mode)
385390
#if defined(AUX_SERIAL)
386391
if (mode == UART_MODE_SBUS_TRAINER)
387392
return g_eeGeneral.auxSerialMode != UART_MODE_SBUS_TRAINER;
393+
#if defined(TELEMETRY_MAVLINK)
394+
else
395+
if (mode == UART_MODE_MAVLINK)
396+
return true;
397+
#endif
388398
#if defined(RADIO_TX16S)
389399
else
390400
return (g_model.trainerData.mode != TRAINER_MODE_MASTER_BATTERY_COMPARTMENT || g_eeGeneral.auxSerialMode == UART_MODE_SBUS_TRAINER);

radio/src/lua/api_mavlink.cpp

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
/*
2+
* Copyright (C) EdgeTX
3+
*
4+
* (c) www.olliw.eu, OlliW, OlliW42
5+
*
6+
* Based on code named
7+
* opentx - http://github.com/opentx/opentx
8+
* th9x - http://code.google.com/p/th9x
9+
* er9x - http://code.google.com/p/er9x
10+
* gruvin9x - http://code.google.com/p/gruvin9x
11+
*
12+
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
13+
*
14+
* This program is free software; you can redistribute it and/or modify
15+
* it under the terms of the GNU General Public License version 2 as
16+
* published by the Free Software Foundation.
17+
*
18+
* This program is distributed in the hope that it will be useful,
19+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
* GNU General Public License for more details.
22+
*/
23+
24+
#include <ctype.h>
25+
#include <stdio.h>
26+
#include "opentx.h"
27+
#include "lua_api.h"
28+
#include "telemetry/mavlink/mavlink_telem.h"
29+
#include "thirdparty/Mavlink/edgetx_lua_lib_constants.h"
30+
#include "thirdparty/Mavlink/edgetx_lua_lib_messages.h"
31+
32+
33+
static int luaMavlinkGetVersion(lua_State * L)
34+
{
35+
lua_pushinteger(L, FASTMAVLINK_MAVLINK_VERSION); // this is the version reported also by the heartbeat
36+
return 1;
37+
}
38+
39+
static int luaMavlinkGetChannelStatus(lua_State * L)
40+
{
41+
lua_createtable(L, 0, 6);
42+
lua_pushtableinteger(L, "msg_rx_count", mavlinkTelem.msg_rx_count);
43+
lua_pushtableinteger(L, "msg_rx_per_sec", mavlinkTelem.msg_rx_persec);
44+
lua_pushtableinteger(L, "bytes_rx_per_sec", mavlinkTelem.bytes_rx_persec);
45+
lua_pushtableinteger(L, "msg_tx_count", mavlinkTelem.msg_tx_count);
46+
lua_pushtableinteger(L, "msg_tx_per_sec", mavlinkTelem.msg_tx_persec);
47+
lua_pushtableinteger(L, "bytes_tx_per_sec", mavlinkTelem.bytes_tx_persec);
48+
return 1;
49+
}
50+
51+
//-- mavlink api --
52+
53+
static int luaMavlinkGetSystemId(lua_State *L)
54+
{
55+
lua_pushinteger(L, mavlinkTelem.systemSysId());
56+
return 1;
57+
}
58+
59+
static int luaMavlinkGetAutopilotIds(lua_State *L)
60+
{
61+
lua_pushinteger(L, mavlinkTelem.systemSysId());
62+
lua_pushinteger(L, mavlinkTelem.autopilotCompId());
63+
return 1;
64+
}
65+
66+
static int luaMavlinkGetCameraIds(lua_State *L)
67+
{
68+
lua_pushinteger(L, mavlinkTelem.systemSysId());
69+
lua_pushinteger(L, mavlinkTelem.cameraCompId());
70+
return 1;
71+
}
72+
73+
static int luaMavlinkGetGimbalIds(lua_State *L)
74+
{
75+
lua_pushinteger(L, mavlinkTelem.systemSysId());
76+
lua_pushinteger(L, mavlinkTelem.gimbalCompId());
77+
return 1;
78+
}
79+
80+
static int luaMavlinkGetGimbalManagerIds(lua_State *L)
81+
{
82+
lua_pushinteger(L, mavlinkTelem.systemSysId());
83+
lua_pushinteger(L, mavlinkTelem.gimbalManagerCompId());
84+
return 1;
85+
}
86+
87+
//-- mavlink api, messages --
88+
89+
static int luaMavlinkInEnable(lua_State *L)
90+
{
91+
bool flag = (luaL_checkinteger(L, 1) > 0);
92+
mavlinkTelem.mavapiMsgInEnable(flag);
93+
return 0;
94+
}
95+
96+
static int luaMavlinkInCount(lua_State *L)
97+
{
98+
lua_pushinteger(L, mavlinkTelem.mavapiMsgInCount());
99+
return 1;
100+
}
101+
102+
static int luaMavlinkGetMessage(lua_State *L)
103+
{
104+
int msgid = luaL_checknumber(L, 1);
105+
106+
MavlinkTelem::MavMsg* mavmsg = mavlinkTelem.mavapiMsgInGet(msgid);
107+
if (!mavmsg) {
108+
lua_pushnil(L);
109+
}
110+
else {
111+
luaMavlinkPushMavMsg(L, mavmsg);
112+
mavmsg->updated = false;
113+
}
114+
return 1;
115+
}
116+
117+
static int luaMavlinkGetMessageLast(lua_State *L)
118+
{
119+
MavlinkTelem::MavMsg* mavmsg = mavlinkTelem.mavapiMsgInGetLast();
120+
if (!mavmsg) {
121+
lua_pushnil(L);
122+
}
123+
else {
124+
luaMavlinkPushMavMsg(L, mavmsg);
125+
}
126+
return 1;
127+
}
128+
129+
static int luaMavlinkOutEnable(lua_State *L)
130+
{
131+
bool flag = (luaL_checkinteger(L, 1) > 0);
132+
mavlinkTelem.mavapiMsgOutEnable(flag);
133+
return 0;
134+
}
135+
136+
static int luaMavlinkIsFree(lua_State *L)
137+
{
138+
lua_pushboolean(L, (mavlinkTelem.mavapiMsgOutPtr() != NULL));
139+
return 1;
140+
}
141+
142+
static int luaMavlinkSendMessage(lua_State *L)
143+
{
144+
fmav_message_t* msg_out = mavlinkTelem.mavapiMsgOutPtr();
145+
146+
if (!lua_istable(L, -1) || !msg_out) {
147+
lua_pushnil(L);
148+
}
149+
else if (luaMavlinkCheckMsgOut(L, msg_out)) {
150+
mavlinkTelem.mavapiMsgOutSet();
151+
lua_pushboolean(L, true);
152+
}
153+
else {
154+
lua_pushboolean(L, false);
155+
}
156+
return 1;
157+
}
158+
159+
160+
//------------------------------------------------------------
161+
// mavlink luaL and luaR arrays
162+
//------------------------------------------------------------
163+
164+
const luaL_Reg mavlinkLib[] = {
165+
{ "getVersion", luaMavlinkGetVersion },
166+
{ "getChannelStatus", luaMavlinkGetChannelStatus },
167+
168+
{ "getSystemId", luaMavlinkGetSystemId },
169+
{ "getAutopilotIds", luaMavlinkGetAutopilotIds },
170+
{ "getCameraIds", luaMavlinkGetCameraIds },
171+
{ "getGimbalIds", luaMavlinkGetGimbalIds },
172+
{ "getGimbalManagerIds", luaMavlinkGetGimbalManagerIds },
173+
174+
{ "enableIn", luaMavlinkInEnable },
175+
{ "getInCount", luaMavlinkInCount },
176+
{ "getMessage", luaMavlinkGetMessage },
177+
{ "getMessageLast", luaMavlinkGetMessageLast },
178+
{ "enableOut", luaMavlinkOutEnable },
179+
{ "isFree", luaMavlinkIsFree },
180+
{ "sendMessage", luaMavlinkSendMessage },
181+
182+
{ nullptr, nullptr } /* sentinel */
183+
};
184+
185+
const luaR_value_entry mavlinkConstants[] = {
186+
MAVLINK_LIB_CONSTANTS
187+
188+
{ nullptr, 0 } /* sentinel */
189+
};
190+

0 commit comments

Comments
 (0)