1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-25 09:15:38 +03:00

S.PORT Push with PXX2 (still not tested)

This commit is contained in:
Bertrand Songis 2019-03-20 17:04:23 +01:00
parent 04ba9e5c68
commit 7d2f3dff5a
5 changed files with 71 additions and 6 deletions

View file

@ -20,7 +20,7 @@
#include "opentx.h"
bool isSportOutputBufferAvailable()
bool isTelemetryOutputBufferAvailable()
{
return (outputTelemetryBuffer.size == 0 && outputTelemetryBuffer.trigger == 0x7E);
}
@ -36,7 +36,6 @@ void sportOutputPushByte(uint8_t byte)
}
}
// TODO merge it with S.PORT update function when finished
void sportOutputPushPacket(SportTelemetryPacket * packet)
{
uint16_t crc = 0;

View file

@ -35,7 +35,7 @@ PACK(union SportTelemetryPacket
uint8_t raw[8];
});
bool isSportOutputBufferAvailable();
bool isTelemetryOutputBufferAvailable();
void sportOutputPushPacket(SportTelemetryPacket * packet);
#endif

View file

@ -422,9 +422,9 @@ When called without parameters, it will only return the status of the output buf
static int luaSportTelemetryPush(lua_State * L)
{
if (lua_gettop(L) == 0) {
lua_pushboolean(L, isSportOutputBufferAvailable());
lua_pushboolean(L, isTelemetryOutputBufferAvailable());
}
else if (isSportOutputBufferAvailable()) {
else if (isTelemetryOutputBufferAvailable()) {
SportTelemetryPacket packet;
packet.physicalId = getDataId(luaL_checkunsigned(L, 1));
packet.primId = luaL_checkunsigned(L, 2);
@ -439,6 +439,59 @@ static int luaSportTelemetryPush(lua_State * L)
return 1;
}
/*luadoc
@function pxx2TelemetryPush()
This functions allows for sending SPORT telemetry data toward the receiver,
and more generally, to anything connected SPORT bus on the receiver or transmitter.
When called without parameters, it will only return the status of the output buffer without sending anything.
@param module module index
@param receiver receiver index
@param sensorId physical sensor ID
@param frameId frame ID
@param dataId data ID
@param value value
@retval boolean data queued in output buffer or not.
@status current Introduced in 2.3.0
*/
static int luaPXX2TelemetryPush(lua_State * L)
{
if (lua_gettop(L) == 0) {
lua_pushboolean(L, isTelemetryOutputBufferAvailable());
}
else if (isTelemetryOutputBufferAvailable()) {
SportTelemetryPacket packet;
uint8_t module = getDataId(luaL_checkunsigned(L, 1));
uint8_t receiver = getDataId(luaL_checkunsigned(L, 2));
uint8_t rx_uid = g_model.moduleData[module].pxx2.getReceiverSlot(receiver);
if (rx_uid > 0) {
// TODO add more controls (module started, module = PXX2, etc.)
packet.physicalId = getDataId(luaL_checkunsigned(L, 3));
packet.primId = luaL_checkunsigned(L, 4);
packet.dataId = luaL_checkunsigned(L, 5);
packet.value = luaL_checkunsigned(L, 6);
pushPXX2TelemetryPacket(module, rx_uid - 1, &packet);
lua_pushboolean(L, true);
}
else {
lua_pushboolean(L, false);
}
}
else {
lua_pushboolean(L, false);
}
return 1;
}
#if defined(CROSSFIRE)
/*luadoc
@function crossfireTelemetryPop()

View file

@ -238,3 +238,16 @@ void processPXX2TelemetryFrame(uint8_t module, uint8_t * frame)
break;
}
}
void pushPXX2TelemetryPacket(uint8_t module, uint8_t rx_uid, SportTelemetryPacket * packet)
{
// Flag0
outputTelemetryBuffer.push(rx_uid);
for (uint8_t i=1; i<sizeof(SportTelemetryPacket); i++) {
uint8_t byte = packet->raw[i];
outputTelemetryBuffer.push(byte);
}
outputTelemetryBuffer.setDestination(module);
}

View file

@ -197,6 +197,6 @@ extern Fifo<uint8_t, LUA_TELEMETRY_INPUT_FIFO_SIZE> * luaInputTelemetryFifo;
#endif
void processPXX2TelemetryFrame(uint8_t module, uint8_t * frame);
void pushPXX2TelemetryPacket(uint8_t module, uint8_t rx_uid, SportTelemetryPacket * packet);
#endif // _TELEMETRY_H_