diff --git a/radio/src/cli.cpp b/radio/src/cli.cpp index 57bb463b7..6acf5199a 100644 --- a/radio/src/cli.cpp +++ b/radio/src/cli.cpp @@ -28,7 +28,7 @@ OS_TID cliTaskId; TaskStack cliStack; -Fifo<256> cliRxFifo; +Fifo cliRxFifo; uint8_t cliTracesEnabled = true; // char cliLastLine[CLI_COMMAND_MAX_LEN+1]; diff --git a/radio/src/cli.h b/radio/src/cli.h index 29bc56b68..634c37caa 100644 --- a/radio/src/cli.h +++ b/radio/src/cli.h @@ -27,7 +27,7 @@ extern uint8_t cliTracesEnabled; #ifdef __cplusplus #include "fifo.h" -extern Fifo<256> cliRxFifo; +extern Fifo cliRxFifo; #include "tasks_arm.h" #define CLI_STACK_SIZE 1000 extern TaskStack cliStack; diff --git a/radio/src/fifo.h b/radio/src/fifo.h index 0e2329ec6..933a332e6 100644 --- a/radio/src/fifo.h +++ b/radio/src/fifo.h @@ -1,27 +1,27 @@ -/* - * Copyright (C) OpenTX - * - * Based on code named - * th9x - http://code.google.com/p/th9x - * er9x - http://code.google.com/p/er9x - * gruvin9x - http://code.google.com/p/gruvin9x - * - * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program 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. - */ - -#ifndef _FIFO_H_ -#define _FIFO_H_ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program 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. + */ -template +#ifndef _FIFO_H_ +#define _FIFO_H_ + +template class Fifo { public: @@ -36,20 +36,20 @@ class Fifo widx = ridx = 0; } - void push(uint8_t byte) { + void push(T element) { uint32_t next = (widx+1) & (N-1); if (next != ridx) { - fifo[widx] = byte; + fifo[widx] = element; widx = next; } } - bool pop(uint8_t & byte) { + bool pop(T & element) { if (isEmpty()) { return false; } else { - byte = fifo[ridx]; + element = fifo[ridx]; ridx = (ridx+1) & (N-1); return true; } @@ -69,9 +69,9 @@ class Fifo } protected: - uint8_t fifo[N]; + T fifo[N]; volatile uint32_t widx; volatile uint32_t ridx; }; -#endif // _FIFO_H_ +#endif // _FIFO_H_ diff --git a/radio/src/lua/api_general.cpp b/radio/src/lua/api_general.cpp index 534fce7f6..4bf9fee57 100644 --- a/radio/src/lua/api_general.cpp +++ b/radio/src/lua/api_general.cpp @@ -326,6 +326,41 @@ bool luaFindFieldByName(const char * name, LuaField & field, unsigned int flags) return false; // not found } +static int luaTelemetryPop(lua_State *L) +{ + if (!luaInputTelemetryFifo) { + luaInputTelemetryFifo = new Fifo(); + if (!luaInputTelemetryFifo) { + return 0; + } + } + + LuaTelemetryValue value; + if (luaInputTelemetryFifo->pop(value)) { + lua_pushnumber(L, value.id); + lua_pushunsigned(L, value.value); + return 2; + } + + return 0; +} + +static int luaTelemetryPush(lua_State *L) +{ + if (!luaOutputTelemetryFifo) { + luaOutputTelemetryFifo = new Fifo(); + if (!luaOutputTelemetryFifo) { + return 0; + } + } + + unsigned int id = luaL_checkunsigned(L, 1); + unsigned int value = luaL_checkunsigned(L, 2); + + luaOutputTelemetryFifo->push((LuaTelemetryValue){ id, value }); + return 0; +} + /*luadoc @function getFieldInfo(name) @@ -795,6 +830,8 @@ const luaL_Reg opentxLib[] = { #if !defined(COLORLCD) { "GREY", luaGrey }, #endif + { "telemetryPop", luaTelemetryPop }, + { "telemetryPush", luaTelemetryPush }, { NULL, NULL } /* sentinel */ }; diff --git a/radio/src/sbus.cpp b/radio/src/sbus.cpp index 18921b859..57b7d22e5 100644 --- a/radio/src/sbus.cpp +++ b/radio/src/sbus.cpp @@ -33,7 +33,7 @@ #define SBUS_CH_CENTER 0x3E0 -Fifo<32> sbusFifo; +Fifo sbusFifo; uint8_t SbusFrame[SBUS_MAX_FRAME_SIZE]; uint16_t SbusTimer ; uint8_t SbusIndex = 0 ; diff --git a/radio/src/targets/horus/serial2_driver.cpp b/radio/src/targets/horus/serial2_driver.cpp index 489e0e810..c1a17db15 100644 --- a/radio/src/targets/horus/serial2_driver.cpp +++ b/radio/src/targets/horus/serial2_driver.cpp @@ -1,29 +1,29 @@ -/* - * Copyright (C) OpenTX - * - * Based on code named - * th9x - http://code.google.com/p/th9x - * er9x - http://code.google.com/p/er9x - * gruvin9x - http://code.google.com/p/gruvin9x - * - * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program 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. - */ - -#include "../../opentx.h" +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program 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. + */ + +#include "opentx.h" uint8_t serial2Mode = 0; -Fifo<512> serial2TxFifo; -extern Fifo<512> telemetryFifo; -extern Fifo<32> sbusFifo; +Fifo serial2TxFifo; +extern Fifo telemetryFifo; +extern Fifo sbusFifo; void uart3Setup(unsigned int baudrate) { diff --git a/radio/src/targets/horus/telemetry_driver.cpp b/radio/src/targets/horus/telemetry_driver.cpp index db6a2420d..be550df04 100644 --- a/radio/src/targets/horus/telemetry_driver.cpp +++ b/radio/src/targets/horus/telemetry_driver.cpp @@ -20,7 +20,7 @@ #include "../../opentx.h" -extern Fifo<512> telemetryFifo; +extern Fifo telemetryFifo; void telemetryPortInit(uint32_t baudrate) { diff --git a/radio/src/targets/horus/trainer_driver.cpp b/radio/src/targets/horus/trainer_driver.cpp index 858d72b48..c29d28029 100644 --- a/radio/src/targets/horus/trainer_driver.cpp +++ b/radio/src/targets/horus/trainer_driver.cpp @@ -18,9 +18,9 @@ * GNU General Public License for more details. */ -#include "../../opentx.h" +#include "opentx.h" -extern Fifo<32> sbusFifo; +extern Fifo sbusFifo; #define setupTrainerPulses() setupPulsesPPM(TRAINER_MODULE) diff --git a/radio/src/targets/sky9x/serial2_driver.cpp b/radio/src/targets/sky9x/serial2_driver.cpp index a3ed2f523..c351d803e 100644 --- a/radio/src/targets/sky9x/serial2_driver.cpp +++ b/radio/src/targets/sky9x/serial2_driver.cpp @@ -28,7 +28,7 @@ /** Pins description corresponding to Rxd,Txd, (UART pins) */ #define SECOND_SERIAL_PINS {PINS_UART} -Fifo<512> serial2RxFifo; +Fifo serial2RxFifo; #if !defined(SIMU) /* diff --git a/radio/src/targets/taranis/bluetooth_driver.cpp b/radio/src/targets/taranis/bluetooth_driver.cpp index 6bd538450..a53d69283 100644 --- a/radio/src/targets/taranis/bluetooth_driver.cpp +++ b/radio/src/targets/taranis/bluetooth_driver.cpp @@ -20,8 +20,8 @@ #include "../../opentx.h" -Fifo<64> btTxFifo; -Fifo<64> btRxFifo; +Fifo btTxFifo; +Fifo btRxFifo; enum BluetoothState { diff --git a/radio/src/targets/taranis/serial2_driver.cpp b/radio/src/targets/taranis/serial2_driver.cpp index 79df0768f..614e9b9d0 100644 --- a/radio/src/targets/taranis/serial2_driver.cpp +++ b/radio/src/targets/taranis/serial2_driver.cpp @@ -21,9 +21,9 @@ #include "../../opentx.h" uint8_t serial2Mode = 0; -Fifo<512> serial2TxFifo; -extern Fifo<512> telemetryFifo; -extern Fifo<32> sbusFifo; +Fifo serial2TxFifo; +extern Fifo telemetryFifo; +extern Fifo sbusFifo; void uart3Setup(unsigned int baudrate) { diff --git a/radio/src/targets/taranis/telemetry_driver.cpp b/radio/src/targets/taranis/telemetry_driver.cpp index d0b10eb99..3ebfffc64 100644 --- a/radio/src/targets/taranis/telemetry_driver.cpp +++ b/radio/src/targets/taranis/telemetry_driver.cpp @@ -20,7 +20,7 @@ #include "../../opentx.h" -extern Fifo<512> telemetryFifo; +extern Fifo telemetryFifo; void telemetryPortInit(uint32_t baudrate) { diff --git a/radio/src/targets/taranis/trainer_driver.cpp b/radio/src/targets/taranis/trainer_driver.cpp index 65893ff45..7da2b6f4d 100644 --- a/radio/src/targets/taranis/trainer_driver.cpp +++ b/radio/src/targets/taranis/trainer_driver.cpp @@ -20,7 +20,7 @@ #include "../../opentx.h" -extern Fifo<32> sbusFifo; +extern Fifo sbusFifo; #define setupTrainerPulses() setupPulsesPPM(TRAINER_MODULE) diff --git a/radio/src/telemetry/frsky.cpp b/radio/src/telemetry/frsky.cpp index 69a001fc8..96c9b5593 100644 --- a/radio/src/telemetry/frsky.cpp +++ b/radio/src/telemetry/frsky.cpp @@ -44,7 +44,7 @@ uint8_t telemetryState = TELEMETRY_INIT; #endif #if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS) -Fifo<512> telemetryFifo; // TODO should be in the driver +Fifo telemetryFifo; // TODO should be in the driver #endif uint8_t frskyRxBufferCount = 0; @@ -665,3 +665,8 @@ NOINLINE uint8_t getRssiAlarmValue(uint8_t alarm) { return (45 - 3*alarm + g_model.frsky.rssiAlarms[alarm].value); } + +#if defined(LUA) +Fifo * luaInputTelemetryFifo = NULL; +Fifo * luaOutputTelemetryFifo = NULL; +#endif diff --git a/radio/src/telemetry/frsky.h b/radio/src/telemetry/frsky.h index 5efe2dfc9..6b941e532 100644 --- a/radio/src/telemetry/frsky.h +++ b/radio/src/telemetry/frsky.h @@ -139,6 +139,8 @@ #define POWERBOX_STATE_LAST_ID 0x0b2f #define POWERBOX_CNSP_FIRST_ID 0x0b30 #define POWERBOX_CNSP_LAST_ID 0x0b3f +#define DIY_FIRST_ID 0x5000 +#define DIY_LAST_ID 0x50ff #define RSSI_ID 0xf101 #define ADC1_ID 0xf102 #define ADC2_ID 0xf103 @@ -344,7 +346,6 @@ struct FrskyData { }; #endif - #if defined(PCBTARANIS) && defined(REVPLUS) #define IS_VALID_XJT_VERSION() (frskyData.xjtVersion != 0 && frskyData.xjtVersion != 0xff) #else @@ -553,4 +554,15 @@ void processSerialData(uint8_t data); #define MODEL_TELEMETRY_PROTOCOL() g_model.telemetryProtocol #endif +#if defined(LUA) +struct LuaTelemetryValue +{ + uint8_t id; + uint32_t value; +}; + +extern Fifo * luaInputTelemetryFifo; +extern Fifo * luaOutputTelemetryFifo; +#endif + #endif // _FRSKY_H_ diff --git a/radio/src/telemetry/frsky_sport.cpp b/radio/src/telemetry/frsky_sport.cpp index 0a8928421..dfe6440f2 100644 --- a/radio/src/telemetry/frsky_sport.cpp +++ b/radio/src/telemetry/frsky_sport.cpp @@ -269,6 +269,13 @@ void processSportPacket(uint8_t * packet) processSportPacket(id, 6, instance, bool(data & 0x2000000)); processSportPacket(id, 7, instance, bool(data & 0x4000000)); } + else if (id >= DIY_FIRST_ID && id <= DIY_LAST_ID) { +#if defined(LUA) + if (luaInputTelemetryFifo) { + luaInputTelemetryFifo->push((LuaTelemetryValue){(uint8_t)id, data}); + } +#endif + } else { processSportPacket(id, 0, instance, data); } diff --git a/radio/src/telemetry/telemetry.h b/radio/src/telemetry/telemetry.h index e2e5df010..5cb981ccb 100644 --- a/radio/src/telemetry/telemetry.h +++ b/radio/src/telemetry/telemetry.h @@ -21,7 +21,7 @@ #ifndef _TELEMETRY_H_ #define _TELEMETRY_H_ -extern Fifo<512> telemetryFifo; +extern Fifo telemetryFifo; enum TelemetryProtocol {