Internal and external module buffers are now private
This commit is contained in:
committed by
Raphael Coeffic
parent
ab6033e4d5
commit
f952c5f7c7
@@ -31,7 +31,7 @@
|
||||
|
||||
static_assert(PXX2_FRAME_MAXLENGTH <= INTMODULE_FIFO_SIZE);
|
||||
|
||||
void processGetHardwareInfoFrame(uint8_t module, const uint8_t * frame)
|
||||
static void processGetHardwareInfoFrame(uint8_t module, const uint8_t * frame)
|
||||
{
|
||||
if (moduleState[module].mode != MODULE_MODE_GET_HARDWARE_INFO) {
|
||||
return;
|
||||
@@ -60,7 +60,7 @@ void processGetHardwareInfoFrame(uint8_t module, const uint8_t * frame)
|
||||
}
|
||||
}
|
||||
|
||||
void processModuleSettingsFrame(uint8_t module, const uint8_t * frame)
|
||||
static void processModuleSettingsFrame(uint8_t module, const uint8_t * frame)
|
||||
{
|
||||
if (moduleState[module].mode != MODULE_MODE_MODULE_SETTINGS) {
|
||||
return;
|
||||
@@ -80,7 +80,7 @@ void processModuleSettingsFrame(uint8_t module, const uint8_t * frame)
|
||||
moduleState[module].mode = MODULE_MODE_NORMAL;
|
||||
}
|
||||
|
||||
void processReceiverSettingsFrame(uint8_t module, const uint8_t * frame)
|
||||
static void processReceiverSettingsFrame(uint8_t module, const uint8_t * frame)
|
||||
{
|
||||
if (moduleState[module].mode != MODULE_MODE_RECEIVER_SETTINGS) {
|
||||
return;
|
||||
@@ -117,7 +117,7 @@ void processReceiverSettingsFrame(uint8_t module, const uint8_t * frame)
|
||||
moduleState[module].mode = MODULE_MODE_NORMAL;
|
||||
}
|
||||
|
||||
void processRegisterFrame(uint8_t module, const uint8_t * frame)
|
||||
static void processRegisterFrame(uint8_t module, const uint8_t * frame)
|
||||
{
|
||||
if (moduleState[module].mode != MODULE_MODE_REGISTER) {
|
||||
return;
|
||||
@@ -153,7 +153,7 @@ void processRegisterFrame(uint8_t module, const uint8_t * frame)
|
||||
}
|
||||
}
|
||||
|
||||
void processBindFrame(uint8_t module, const uint8_t * frame)
|
||||
static void processBindFrame(uint8_t module, const uint8_t * frame)
|
||||
{
|
||||
if (moduleState[module].mode != MODULE_MODE_BIND) {
|
||||
return;
|
||||
@@ -204,7 +204,7 @@ void processBindFrame(uint8_t module, const uint8_t * frame)
|
||||
}
|
||||
}
|
||||
|
||||
void processResetFrame(uint8_t module, const uint8_t * frame)
|
||||
static void processResetFrame(uint8_t module, const uint8_t * frame)
|
||||
{
|
||||
if (moduleState[module].mode != MODULE_MODE_RESET) {
|
||||
return;
|
||||
@@ -217,7 +217,7 @@ void processResetFrame(uint8_t module, const uint8_t * frame)
|
||||
moduleState[module].mode = MODULE_MODE_NORMAL;
|
||||
}
|
||||
|
||||
void processTelemetryFrame(uint8_t module, const uint8_t * frame)
|
||||
static void processTelemetryFrame(uint8_t module, const uint8_t * frame)
|
||||
{
|
||||
for (uint8_t i = 0; i < 1 + frame[0]; i++) {
|
||||
telemetryMirrorSend(frame[i]);
|
||||
@@ -237,7 +237,7 @@ extern "C" {
|
||||
|
||||
volatile int16_t authenticateFrames = 0;
|
||||
|
||||
void processAuthenticationFrame(uint8_t module, const uint8_t * frame)
|
||||
static void processAuthenticationFrame(uint8_t module, const uint8_t * frame)
|
||||
{
|
||||
uint8_t cryptoType = frame[3];
|
||||
uint8_t messageDigest[16] = {0};
|
||||
@@ -280,7 +280,7 @@ void processAuthenticationFrame(uint8_t module, const uint8_t * frame)
|
||||
#define processAuthenticationFrame(module, frame)
|
||||
#endif
|
||||
|
||||
void processSpectrumAnalyserFrame(uint8_t module, const uint8_t * frame)
|
||||
static void processSpectrumAnalyserFrame(uint8_t module, const uint8_t * frame)
|
||||
{
|
||||
if (moduleState[module].mode != MODULE_MODE_SPECTRUM_ANALYSER) {
|
||||
return;
|
||||
@@ -307,7 +307,7 @@ void processSpectrumAnalyserFrame(uint8_t module, const uint8_t * frame)
|
||||
}
|
||||
}
|
||||
|
||||
void processPowerMeterFrame(uint8_t module, const uint8_t * frame)
|
||||
static void processPowerMeterFrame(uint8_t module, const uint8_t * frame)
|
||||
{
|
||||
if (moduleState[module].mode != MODULE_MODE_POWER_METER) {
|
||||
return;
|
||||
@@ -319,7 +319,7 @@ void processPowerMeterFrame(uint8_t module, const uint8_t * frame)
|
||||
}
|
||||
}
|
||||
|
||||
void processOtaUpdateFrame(uint8_t module, const uint8_t * frame)
|
||||
static void processOtaUpdateFrame(uint8_t module, const uint8_t * frame)
|
||||
{
|
||||
if (moduleState[module].mode != MODULE_MODE_OTA_UPDATE) {
|
||||
return;
|
||||
@@ -345,7 +345,7 @@ void processOtaUpdateFrame(uint8_t module, const uint8_t * frame)
|
||||
}
|
||||
}
|
||||
|
||||
void processModuleFrame(uint8_t module, const uint8_t *frame)
|
||||
static void processModuleFrame(uint8_t module, const uint8_t *frame)
|
||||
{
|
||||
switch (frame[2]) {
|
||||
case PXX2_TYPE_ID_HW_INFO:
|
||||
@@ -382,7 +382,7 @@ void processModuleFrame(uint8_t module, const uint8_t *frame)
|
||||
}
|
||||
}
|
||||
|
||||
void processToolsFrame(uint8_t module, const uint8_t * frame)
|
||||
static void processToolsFrame(uint8_t module, const uint8_t * frame)
|
||||
{
|
||||
switch (frame[2]) {
|
||||
case PXX2_TYPE_ID_POWER_METER:
|
||||
@@ -395,7 +395,7 @@ void processToolsFrame(uint8_t module, const uint8_t * frame)
|
||||
}
|
||||
}
|
||||
|
||||
void processPXX2Frame(uint8_t module, const uint8_t * frame)
|
||||
static void processPXX2Frame(uint8_t module, const uint8_t * frame)
|
||||
{
|
||||
LOG_TELEMETRY_WRITE_START();
|
||||
for (uint8_t i = 0; i < 1 + frame[0]; i++) {
|
||||
@@ -419,3 +419,50 @@ void processPXX2Frame(uint8_t module, const uint8_t * frame)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void processPXX2TelemetryData(uint8_t data, uint8_t idx)
|
||||
{
|
||||
uint8_t * rxBuffer = getTelemetryRxBuffer(idx);
|
||||
uint8_t &rxBufferCount = getTelemetryRxBufferCount(idx);
|
||||
|
||||
if (rxBufferCount == 0 && data != START_STOP) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (rxBufferCount == 1 && data > 40) {
|
||||
rxBufferCount = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (rxBufferCount < TELEMETRY_RX_PACKET_SIZE) {
|
||||
rxBuffer[rxBufferCount++] = data;
|
||||
}
|
||||
else {
|
||||
TRACE("[PXX2] array size %d error", rxBufferCount);
|
||||
rxBufferCount = 0;
|
||||
}
|
||||
|
||||
uint8_t len = rxBuffer[1];
|
||||
/* 1 byte start + 2 bytes header + 2 bytes CRC = 5 */
|
||||
if (rxBufferCount < unsigned(len + 5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t crc = 0xFFFF;
|
||||
uint8_t* frame = rxBuffer + 1;
|
||||
|
||||
for (uint32_t i = 1; i <= len; i++) {
|
||||
crc -= frame[i];
|
||||
}
|
||||
|
||||
uint8_t crcHigh = frame[len + 1];
|
||||
uint8_t crcLow = frame[len + 2];
|
||||
|
||||
if (((crc >> 8) != crcHigh) || ((crc & 0xFF) == crcLow)) {
|
||||
TRACE("[PXX2] crc error");
|
||||
rxBufferCount = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
processPXX2Frame(idx, frame);
|
||||
}
|
||||
|
||||
@@ -57,6 +57,10 @@
|
||||
#include "flysky_ibus.h"
|
||||
#endif
|
||||
|
||||
#if defined(INTMODULE_USART)
|
||||
#include "intmodule_serial_driver.h"
|
||||
#endif
|
||||
|
||||
uint8_t telemetryStreaming = 0;
|
||||
uint8_t telemetryRxBuffer[TELEMETRY_RX_PACKET_SIZE]; // Receive buffer. 9 bytes (full packet), worst case 18 bytes with byte-stuffing (+1)
|
||||
uint8_t telemetryRxBufferCount = 0;
|
||||
@@ -236,28 +240,6 @@ inline bool isBadAntennaDetected()
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(INTERNAL_MODULE_PXX2)
|
||||
static void pollIntPXX2()
|
||||
{
|
||||
uint8_t frame[PXX2_FRAME_MAXLENGTH];
|
||||
|
||||
while (intmoduleFifo.getFrame(frame)) {
|
||||
processPXX2Frame(INTERNAL_MODULE, frame);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PXX2) && defined(EXTMODULE_USART)
|
||||
static void pollExtPXX2()
|
||||
{
|
||||
uint8_t frame[PXX2_FRAME_MAXLENGTH];
|
||||
|
||||
while (extmoduleFifo.getFrame(frame)) {
|
||||
processPXX2Frame(EXTERNAL_MODULE, frame);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MULTI_PROTOLIST)
|
||||
static inline void pollMultiProtolist(uint8_t idx)
|
||||
{
|
||||
@@ -268,19 +250,51 @@ static inline void pollMultiProtolist(uint8_t idx)
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void pollIntTelemetry(void (*processData)(uint8_t,uint8_t))
|
||||
static inline void pollIntTelemetry(void (*processData)(uint8_t, uint8_t))
|
||||
{
|
||||
auto drv = getIntModuleDriver();
|
||||
auto ctx = getIntModuleCtx();
|
||||
|
||||
if (!drv || !drv->getByte || !processData) return;
|
||||
|
||||
uint8_t data;
|
||||
if (intmoduleFifo.pop(data)) {
|
||||
if (drv->getByte(ctx, &data) > 0) {
|
||||
LOG_TELEMETRY_WRITE_START();
|
||||
do {
|
||||
telemetryMirrorSend(data);
|
||||
processData(data, INTERNAL_MODULE);
|
||||
LOG_TELEMETRY_WRITE_BYTE(data);
|
||||
} while (intmoduleFifo.pop(data));
|
||||
}
|
||||
} while (drv->getByte(ctx, &data) > 0);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(INTERNAL_MODULE_PXX2)
|
||||
static void pollIntPXX2()
|
||||
{
|
||||
pollIntTelemetry(processPXX2TelemetryData);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PXX2) && defined(EXTMODULE_USART)
|
||||
static void pollExtPXX2()
|
||||
{
|
||||
auto drv = getExtModuleDriver();
|
||||
auto ctx = getExtModuleCtx();
|
||||
|
||||
if (!drv || !drv->getByte) return;
|
||||
|
||||
uint8_t data;
|
||||
if (drv->getByte(ctx, &data) > 0) {
|
||||
LOG_TELEMETRY_WRITE_START();
|
||||
do {
|
||||
telemetryMirrorSend(data);
|
||||
processPXX2TelemetryData(data, EXTERNAL_MODULE);
|
||||
LOG_TELEMETRY_WRITE_BYTE(data);
|
||||
} while (drv->getByte(ctx, &data) > 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(INTERNAL_MODULE_MULTI)
|
||||
static void pollIntMulti()
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@ constexpr uint8_t TELEMETRY_TIMEOUT10ms = 100; // 1 second
|
||||
#define TELEMETRY_SERIAL_8E2 1
|
||||
#define TELEMETRY_SERIAL_WITHOUT_DMA 2
|
||||
|
||||
#if defined(CROSSFIRE) || defined(MULTIMODULE) || defined(AFHDS3)
|
||||
#if defined(CROSSFIRE) || defined(MULTIMODULE) || defined(AFHDS3) || defined(PXX2)
|
||||
#define TELEMETRY_RX_PACKET_SIZE 128
|
||||
// multi module Spektrum telemetry is 18 bytes, FlySky is 37 bytes
|
||||
#else
|
||||
@@ -304,7 +304,7 @@ extern OutputTelemetryBuffer outputTelemetryBuffer __DMA;
|
||||
extern Fifo<uint8_t, LUA_TELEMETRY_INPUT_FIFO_SIZE> * luaInputTelemetryFifo;
|
||||
#endif
|
||||
|
||||
void processPXX2Frame(uint8_t module, const uint8_t *frame);
|
||||
void processPXX2TelemetryData(uint8_t data, uint8_t idx);
|
||||
|
||||
// Module pulse synchronization
|
||||
struct ModuleSyncStatus
|
||||
|
||||
Reference in New Issue
Block a user