Ghost MSP support
This commit is contained in:
committed by
Peter Feerick
parent
4b93686a40
commit
8c6bc67f18
@@ -812,6 +812,113 @@ static int luaCrossfireTelemetryPush(lua_State * L)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(GHOST)
|
||||||
|
/*luadoc
|
||||||
|
@function ghostTelemetryPop()
|
||||||
|
|
||||||
|
Pops a received Ghost Telemetry packet from the queue.
|
||||||
|
|
||||||
|
@retval nil queue does not contain any (or enough) bytes to form a whole packet
|
||||||
|
|
||||||
|
@retval multiple returns 2 values:
|
||||||
|
* type (number)
|
||||||
|
* packet (table) data bytes
|
||||||
|
|
||||||
|
@status current Introduced in 2.7.0
|
||||||
|
*/
|
||||||
|
static int luaGhostTelemetryPop(lua_State * L)
|
||||||
|
{
|
||||||
|
if (!luaInputTelemetryFifo) {
|
||||||
|
luaInputTelemetryFifo = new Fifo<uint8_t, LUA_TELEMETRY_INPUT_FIFO_SIZE>();
|
||||||
|
if (!luaInputTelemetryFifo) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t length = 0, data = 0;
|
||||||
|
if (luaInputTelemetryFifo->probe(length) && luaInputTelemetryFifo->size() >= uint32_t(length)) {
|
||||||
|
// length value includes type(1B), payload, crc(1B)
|
||||||
|
luaInputTelemetryFifo->pop(length);
|
||||||
|
luaInputTelemetryFifo->pop(data); // type
|
||||||
|
lua_pushnumber(L, data); // return type
|
||||||
|
lua_newtable(L);
|
||||||
|
for (uint8_t i=0; i<length-2; i++) {
|
||||||
|
luaInputTelemetryFifo->pop(data);
|
||||||
|
lua_pushinteger(L, i+1);
|
||||||
|
lua_pushinteger(L, data);
|
||||||
|
lua_settable(L, -3);
|
||||||
|
}
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*luadoc
|
||||||
|
@function ghostTelemetryPush()
|
||||||
|
|
||||||
|
This functions allows for sending telemetry data toward the Ghost link.
|
||||||
|
|
||||||
|
When called without parameters, it will only return the status of the output buffer without sending anything.
|
||||||
|
|
||||||
|
@param command command
|
||||||
|
|
||||||
|
@param data table of data bytes
|
||||||
|
|
||||||
|
@retval boolean data queued in output buffer or not.
|
||||||
|
|
||||||
|
@retval nil incorrect telemetry protocol.
|
||||||
|
|
||||||
|
@status current Introduced in 2.7.0
|
||||||
|
*/
|
||||||
|
static int luaGhostTelemetryPush(lua_State * L)
|
||||||
|
{
|
||||||
|
bool sport = (telemetryProtocol == PROTOCOL_TELEMETRY_GHOST);
|
||||||
|
|
||||||
|
if (!sport) {
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lua_gettop(L) == 0) {
|
||||||
|
lua_pushboolean(L, outputTelemetryBuffer.isAvailable());
|
||||||
|
}
|
||||||
|
else if (lua_gettop(L) > TELEMETRY_OUTPUT_BUFFER_SIZE ) {
|
||||||
|
lua_pushboolean(L, false);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if (outputTelemetryBuffer.isAvailable()) {
|
||||||
|
uint8_t type = luaL_checkunsigned(L, 1);
|
||||||
|
luaL_checktype(L, 2, LUA_TTABLE);
|
||||||
|
uint8_t length = luaL_len(L, 2); // payload length
|
||||||
|
|
||||||
|
if( length > 10 ) { // max 10B payload
|
||||||
|
lua_pushboolean(L, false);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ghost frames are fixed 14B
|
||||||
|
outputTelemetryBuffer.pushByte(getGhostModuleAddr()); // addr (1B)
|
||||||
|
outputTelemetryBuffer.pushByte(12); // len = payload length(10B) + type(1B) + crc(1B)
|
||||||
|
outputTelemetryBuffer.pushByte(type); // type (1B)
|
||||||
|
for (int i=0; i<length; i++) { // data, max 10B
|
||||||
|
lua_rawgeti(L, 2, i+1);
|
||||||
|
outputTelemetryBuffer.pushByte(luaL_checkunsigned(L, -1));
|
||||||
|
}
|
||||||
|
for (int i=0; i<10-length; i++) { // fill zeroes to frame size
|
||||||
|
outputTelemetryBuffer.pushByte(0);
|
||||||
|
}
|
||||||
|
outputTelemetryBuffer.pushByte(crc8(outputTelemetryBuffer.data + 2, 11 )); // Start at type, CRC over type (1B) + payload (10B)
|
||||||
|
outputTelemetryBuffer.setDestination(TELEMETRY_ENDPOINT_SPORT);
|
||||||
|
lua_pushboolean(L, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lua_pushboolean(L, false);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*luadoc
|
/*luadoc
|
||||||
@function getFieldInfo(source)
|
@function getFieldInfo(source)
|
||||||
|
|
||||||
@@ -2293,6 +2400,10 @@ const luaL_Reg opentxLib[] = {
|
|||||||
{ "crossfireTelemetryPop", luaCrossfireTelemetryPop },
|
{ "crossfireTelemetryPop", luaCrossfireTelemetryPop },
|
||||||
{ "crossfireTelemetryPush", luaCrossfireTelemetryPush },
|
{ "crossfireTelemetryPush", luaCrossfireTelemetryPush },
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(GHOST)
|
||||||
|
{ "ghostTelemetryPop", luaGhostTelemetryPop },
|
||||||
|
{ "ghostTelemetryPush", luaGhostTelemetryPush },
|
||||||
|
#endif
|
||||||
#if defined(MULTIMODULE)
|
#if defined(MULTIMODULE)
|
||||||
{ "multiBuffer", luaMultiBuffer },
|
{ "multiBuffer", luaMultiBuffer },
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -121,12 +121,21 @@ uint8_t createGhostChannelsFrame(uint8_t * frame, int16_t * pulses, bool raw12bi
|
|||||||
void setupPulsesGhost()
|
void setupPulsesGhost()
|
||||||
{
|
{
|
||||||
if (telemetryProtocol == PROTOCOL_TELEMETRY_GHOST) {
|
if (telemetryProtocol == PROTOCOL_TELEMETRY_GHOST) {
|
||||||
uint8_t * pulses = extmodulePulsesData.ghost.pulses;
|
|
||||||
auto & module = g_model.moduleData[EXTERNAL_MODULE];
|
auto &module = g_model.moduleData[EXTERNAL_MODULE];
|
||||||
|
auto *p_data = &extmodulePulsesData.ghost;
|
||||||
|
|
||||||
|
#if defined(LUA)
|
||||||
|
if (outputTelemetryBuffer.destination == TELEMETRY_ENDPOINT_SPORT) {
|
||||||
|
memcpy(p_data->pulses, outputTelemetryBuffer.data, outputTelemetryBuffer.size);
|
||||||
|
p_data->length = outputTelemetryBuffer.size;
|
||||||
|
outputTelemetryBuffer.reset();
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
if (moduleState[EXTERNAL_MODULE].counter == GHST_MENU_CONTROL) {
|
if (moduleState[EXTERNAL_MODULE].counter == GHST_MENU_CONTROL) {
|
||||||
extmodulePulsesData.ghost.length = createGhostMenuControlFrame(pulses, &channelOutputs[module.channelsStart]);
|
p_data->length = createGhostMenuControlFrame(p_data->pulses, &channelOutputs[module.channelsStart]);
|
||||||
} else {
|
} else {
|
||||||
extmodulePulsesData.ghost.length = createGhostChannelsFrame(pulses, &channelOutputs[module.channelsStart], module.ghost.raw12bits);
|
p_data->length = createGhostChannelsFrame(p_data->pulses, &channelOutputs[module.channelsStart], module.ghost.raw12bits);
|
||||||
}
|
}
|
||||||
moduleState[EXTERNAL_MODULE].counter = GHST_FRAME_CHANNEL;
|
moduleState[EXTERNAL_MODULE].counter = GHST_FRAME_CHANNEL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -302,6 +302,20 @@ void processGhostTelemetryFrame()
|
|||||||
processGhostTelemetryValue(GHOST_ID_GPS_SATS, telemetryRxBuffer[7]);
|
processGhostTelemetryValue(GHOST_ID_GPS_SATS, telemetryRxBuffer[7]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case GHST_DL_MAGBARO: {
|
||||||
|
// Not implemented yet
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#if defined(LUA)
|
||||||
|
default:
|
||||||
|
if (luaInputTelemetryFifo && luaInputTelemetryFifo->hasSpace(telemetryRxBufferCount-2) ) {
|
||||||
|
for (uint8_t i=1; i<telemetryRxBufferCount-1; i++) {
|
||||||
|
// destination address and CRC are skipped
|
||||||
|
luaInputTelemetryFifo->push(telemetryRxBuffer[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,8 @@
|
|||||||
#define GHST_DL_MENU_DESC 0x24
|
#define GHST_DL_MENU_DESC 0x24
|
||||||
#define GHST_DL_GPS_PRIMARY 0x25
|
#define GHST_DL_GPS_PRIMARY 0x25
|
||||||
#define GHST_DL_GPS_SECONDARY 0x26
|
#define GHST_DL_GPS_SECONDARY 0x26
|
||||||
|
#define GHST_DL_MAGBARO 0x27
|
||||||
|
#define GHST_DL_MSP_RESP 0x28
|
||||||
|
|
||||||
#define GHST_RC_CTR_VAL_12BIT 0x7C0 // 0x3e0 << 1
|
#define GHST_RC_CTR_VAL_12BIT 0x7C0 // 0x3e0 << 1
|
||||||
#define GHST_RC_CTR_VAL_8BIT 0x7C
|
#define GHST_RC_CTR_VAL_8BIT 0x7C
|
||||||
|
|||||||
Reference in New Issue
Block a user