From bb6c6d6e2d96026b5c6c8d1c14f61ff68c930a5d Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 26 Jun 2022 09:26:47 +0200 Subject: [PATCH] WiP PoC AFHDS3 internal module --- radio/src/datastructs_private.h | 24 +- radio/src/gui/colorlcd/flysky_settings.cpp | 103 +- radio/src/pulses/afhds3.cpp | 1096 ++++++++++++++--- radio/src/pulses/afhds3.h | 584 +-------- radio/src/pulses/afhds3_transport.cpp | 128 ++ radio/src/pulses/afhds3_transport.h | 88 ++ radio/src/pulses/modules_helpers.h | 26 +- radio/src/pulses/pulses.cpp | 16 +- radio/src/pulses/pulses.h | 6 +- .../storage/yaml/yaml_datastructs_nv14.cpp | 12 +- .../src/storage/yaml/yaml_datastructs_t12.cpp | 12 +- .../src/storage/yaml/yaml_datastructs_t8.cpp | 12 +- .../storage/yaml/yaml_datastructs_tlite.cpp | 12 +- .../storage/yaml/yaml_datastructs_tpro.cpp | 12 +- .../storage/yaml/yaml_datastructs_tx12.cpp | 12 +- .../storage/yaml/yaml_datastructs_tx12mk2.cpp | 12 +- .../src/storage/yaml/yaml_datastructs_x10.cpp | 12 +- .../storage/yaml/yaml_datastructs_x12s.cpp | 12 +- .../src/storage/yaml/yaml_datastructs_x7.cpp | 12 +- .../src/storage/yaml/yaml_datastructs_x9d.cpp | 12 +- .../src/storage/yaml/yaml_datastructs_x9e.cpp | 12 +- .../storage/yaml/yaml_datastructs_x9lite.cpp | 12 +- .../storage/yaml/yaml_datastructs_x9lites.cpp | 12 +- .../storage/yaml/yaml_datastructs_xlite.cpp | 12 +- .../storage/yaml/yaml_datastructs_xlites.cpp | 12 +- .../storage/yaml/yaml_datastructs_zorro.cpp | 12 +- radio/src/targets/common/arm/CMakeLists.txt | 13 +- radio/src/targets/horus/hal.h | 1 + radio/src/targets/nv14/board.h | 7 +- radio/src/telemetry/telemetry.cpp | 7 +- 30 files changed, 1313 insertions(+), 990 deletions(-) create mode 100644 radio/src/pulses/afhds3_transport.cpp create mode 100644 radio/src/pulses/afhds3_transport.h diff --git a/radio/src/datastructs_private.h b/radio/src/datastructs_private.h index 5cc753797..e4578c6db 100644 --- a/radio/src/datastructs_private.h +++ b/radio/src/datastructs_private.h @@ -510,26 +510,12 @@ PACK(struct ModuleData { rx_freq[1] = 0; } } flysky); - NOBACKUP(PACK(struct { - uint8_t bindPower:3; - uint8_t runPower:3; - uint8_t emi:1; + NOBACKUP(struct { + uint8_t emi:2; uint8_t telemetry:1; - uint16_t failsafeTimeout; - uint8_t rx_freq[2]; - uint8_t mode:2; - uint8_t reserved:6; - uint16_t rxFreq() - { - return (uint16_t)rx_freq[0] | (((uint16_t)rx_freq[1]) << 8); - } - - void setRxFreq(uint16_t value) - { - rx_freq[0] = value & 0xFF; - rx_freq[1] = value >> 8; - } - } afhds3)); + uint8_t phyMode:3; + uint8_t reserved:2; + } afhds3); NOBACKUP(struct { uint8_t raw12bits:1; uint8_t telemetryBaudrate:3; diff --git a/radio/src/gui/colorlcd/flysky_settings.cpp b/radio/src/gui/colorlcd/flysky_settings.cpp index 4c5ff7556..946698fc2 100644 --- a/radio/src/gui/colorlcd/flysky_settings.cpp +++ b/radio/src/gui/colorlcd/flysky_settings.cpp @@ -23,9 +23,22 @@ #include "opentx.h" #include "pulses/flysky.h" +#include "pulses/afhds3.h" #define SET_DIRTY() storageDirty(EE_MODEL) +static const char* _afhds3_region[] = { "CE", "FCC" }; + +static const char* _afhds3_phy_mode[] = { + // V0 + "Classic 18ch", + "Classic 10ch", + // V1 + "Routine 18ch", + "Fast 8ch", + "Lora 12ch", +}; + class FSProtoOpts : public FormGroup { std::function _getMode; @@ -104,19 +117,6 @@ void FlySkySettings::update() #endif #if defined(AFHDS3) if (isModuleAFHDS3(moduleIdx)) { - new FSProtoOpts( - line, [=]() { return md->afhds3.mode; }, - [=](uint8_t v) { md->afhds3.mode = v; }); - - // TYPE - line = newLine(&grid); - new StaticText(line, rect_t{}, STR_TYPE, 0, COLOR_THEME_PRIMARY1); - - // This is chosen when binding (menu? see stdlcd/model_setup_afhds3.cpp) - new StaticText(line, rect_t{}, - md->afhds3.telemetry ? STR_AFHDS3_ONE_TO_ONE_TELEMETRY - : TR_AFHDS3_ONE_TO_MANY, - 0, COLOR_THEME_PRIMARY1); // Status line = newLine(&grid); @@ -127,42 +127,55 @@ void FlySkySettings::update() return std::string(msg); }); - // Power source + // TYPE line = newLine(&grid); - new StaticText(line, rect_t{}, STR_AFHDS3_POWER_SOURCE, 0, - COLOR_THEME_PRIMARY1); - new DynamicText(line, rect_t{}, [=] { - char msg[64] = ""; - getModuleSyncStatusString(moduleIdx, msg); - return std::string(msg); - }); + new StaticText(line, rect_t{}, STR_TYPE, 0, COLOR_THEME_PRIMARY1); - // RX Freq - line = newLine(&grid); - new StaticText(line, rect_t{}, STR_AFHDS3_RX_FREQ, 0, COLOR_THEME_PRIMARY1); - auto edit = new NumberEdit(line, rect_t{}, MIN_FREQ, MAX_FREQ, - GET_DEFAULT(md->afhds3.rxFreq())); - edit->setSetValueHandler( - [=](int32_t newValue) { md->afhds3.setRxFreq((uint16_t)newValue); }); - edit->setSuffix(STR_HZ); + auto box = new FormGroup(line, rect_t{}); + box->setFlexLayout(LV_FLEX_FLOW_ROW); - // Module actual power - line = newLine(&grid); - new StaticText(line, rect_t{}, STR_AFHDS3_ACTUAL_POWER, 0, - COLOR_THEME_PRIMARY1); - new DynamicText(line, rect_t{}, [=] { - char msg[64] = ""; - getStringAtIndex(msg, STR_AFHDS3_POWERS, actualAfhdsRunPower(moduleIdx)); - return std::string(msg); - }); + new Choice(box, rect_t{}, _afhds3_region, 1, afhds3::LNK_ES_FCC, + GET_SET_DEFAULT(md->afhds3.emi)); - // Module power - line = newLine(&grid); - new StaticText(line, rect_t{}, STR_RF_POWER, 0, COLOR_THEME_PRIMARY1); - new Choice(line, rect_t{}, STR_AFHDS3_POWERS, - afhds3::RUN_POWER::RUN_POWER_FIRST, - afhds3::RUN_POWER::RUN_POWER_LAST, - GET_SET_DEFAULT(md->afhds3.runPower)); + new Choice(box, rect_t{}, _afhds3_phy_mode, 0, afhds3::PHYMODE_MAX, + GET_SET_DEFAULT(md->afhds3.phyMode)); + + // // Power source + // line = newLine(&grid); + // new StaticText(line, rect_t{}, STR_AFHDS3_POWER_SOURCE, 0, + // COLOR_THEME_PRIMARY1); + // new DynamicText(line, rect_t{}, [=] { + // char msg[64] = ""; + // getModuleSyncStatusString(moduleIdx, msg); + // return std::string(msg); + // }); + + // // RX Freq + // line = newLine(&grid); + // new StaticText(line, rect_t{}, STR_AFHDS3_RX_FREQ, 0, COLOR_THEME_PRIMARY1); + // auto edit = new NumberEdit(line, rect_t{}, AFHDS3_MIN_FREQ, AFHDS3_MAX_FREQ, + // GET_DEFAULT(md->afhds3.rxFreq())); + // edit->setSetValueHandler( + // [=](int32_t newValue) { md->afhds3.setRxFreq((uint16_t)newValue); }); + // edit->setSuffix(STR_HZ); + + // // Module actual power + // line = newLine(&grid); + // new StaticText(line, rect_t{}, STR_AFHDS3_ACTUAL_POWER, 0, + // COLOR_THEME_PRIMARY1); + // new DynamicText(line, rect_t{}, [=] { + // char msg[64] = ""; + // getStringAtIndex(msg, STR_AFHDS3_POWERS, actualAfhdsRunPower(moduleIdx)); + // return std::string(msg); + // }); + + // // Module power + // line = newLine(&grid); + // new StaticText(line, rect_t{}, STR_RF_POWER, 0, COLOR_THEME_PRIMARY1); + // new Choice(line, rect_t{}, STR_AFHDS3_POWERS, + // afhds3::RUN_POWER::RUN_POWER_FIRST, + // afhds3::RUN_POWER::RUN_POWER_LAST, + // GET_SET_DEFAULT(md->afhds3.runPower)); } #endif } diff --git a/radio/src/pulses/afhds3.cpp b/radio/src/pulses/afhds3.cpp index acd39f920..027811cea 100644 --- a/radio/src/pulses/afhds3.cpp +++ b/radio/src/pulses/afhds3.cpp @@ -33,7 +33,7 @@ #include "intmodule_serial_driver.h" #endif -#if defined(EXTMODULE_USART) && defined(EXTMODULE_TX_INVERT_GPIO) +#if defined(AFHDS3_EXT_UART) #include "extmodule_serial_driver.h" #else #include "extmodule_driver.h" @@ -41,13 +41,530 @@ #define FAILSAFE_HOLD 1 #define FAILSAFE_CUSTOM 2 + +#define FAILSAFE_KEEP_LAST 0x8000 + #define MAX_RETRIES_AFHDS3 5 -extern void processFlySkySensor(const uint8_t * packet, uint8_t type); +//get channel value outside of afhds3 namespace +int32_t getChannelValue(uint8_t channel); + +void processFlySkySensor(const uint8_t * packet, uint8_t type); namespace afhds3 { +static uint8_t _phyMode_channels[] = { + 18, // CLASSIC_FLCR1_18CH + 10, // CLASSIC_FLCR6_10CH + 18, // ROUTINE_FLCR1_18CH + 8, // ROUTINE_FLCR6_8CH + 12, // ROUTINE_LORA_12CH +}; + +enum AfhdsSpecialChars { + END = 0xC0, // Frame end + START = END, + ESC_END = 0xDC, // Escaped frame end - in case END occurs in fame then ESC + // ESC_END must be used + ESC = 0xDB, // Escaping character + ESC_ESC = 0xDD, // Escaping character in case ESC occurs in fame then ESC + // ESC_ESC must be used +}; + +enum DeviceAddress +{ + TRANSMITTER = 0x01, + // MODULE = 0x03, + MODULE = 0x05, +}; + +enum FRAME_TYPE: uint8_t +{ + REQUEST_GET_DATA = 0x01, //Get data response: ACK + DATA + REQUEST_SET_EXPECT_DATA = 0x02, //Set data response: ACK + DATA + REQUEST_SET_EXPECT_ACK = 0x03, //Set data response: ACK + REQUEST_SET_NO_RESP = 0x05, //Set data response: none + RESPONSE_DATA = 0x10, //Response ACK + DATA + RESPONSE_ACK = 0x20, //Response ACK + NOT_USED = 0xff +}; + +enum COMMAND: uint8_t +{ + MODULE_READY = 0x01, + MODULE_STATE = 0x02, + MODULE_MODE = 0x03, + MODULE_SET_CONFIG = 0x04, + MODULE_GET_CONFIG = 0x06, + CHANNELS_FAILSAFE_DATA = 0x07, + TELEMETRY_DATA = 0x09, + SEND_COMMAND = 0x0C, + COMMAND_RESULT = 0x0D, + // MODULE_POWER_STATUS = 0x0F, + // MODULE_VERSION = 0x1F, + MODULE_VERSION = 0x20, + VIRTUAL_FAILSAFE = 0x99, // virtual command used to trigger failsafe + UNDEFINED = 0xFF +}; + +enum COMMAND_DIRECTION +{ + RADIO_TO_MODULE = 0, + MODULE_TO_RADIO = 1 +}; + +enum DATA_TYPE +{ + READY_DT, // 8 bytes 0x01 Not ready 0x02 Ready + STATE_DT, // See MODULE_STATE + MODE_DT, + MOD_CONFIG_DT, + CHANNELS_DT, + TELEMETRY_DT, + MODULE_POWER_DT, + MODULE_VERSION_DT, + EMPTY_DT, +}; + +//enum used by command response -> translate to ModuleState +enum MODULE_READY_E +{ + MODULE_STATUS_UNKNOWN = 0x00, + MODULE_STATUS_NOT_READY = 0x01, + MODULE_STATUS_READY = 0x02 +}; + +enum ModuleState +{ + STATE_NOT_READY = 0x00, //virtual + STATE_HW_ERROR = 0x01, + STATE_BINDING = 0x02, + STATE_SYNC_RUNNING = 0x03, + STATE_SYNC_DONE = 0x04, + STATE_STANDBY = 0x05, + STATE_UPDATING_WAIT = 0x06, + STATE_UPDATING_MOD = 0x07, + STATE_UPDATING_RX = 0x08, + STATE_UPDATING_RX_FAILED = 0x09, + STATE_RF_TESTING = 0x0a, + STATE_READY = 0x0b, //virtual + STATE_HW_TEST = 0xff, +}; + +// used for set command +enum MODULE_MODE_E { + STANDBY = 0x01, + BIND = 0x02, // after bind module will enter run mode + RUN = 0x03, + RX_UPDATE = 0x04, // after successful update module will enter standby mode, + // otherwise hw error will be raised + MODULE_MODE_UNKNOWN = 0xFF +}; + +enum CMD_RESULT +{ + FAILURE = 0x01, + SUCCESS = 0x02, +}; + +enum BIND_POWER +{ + MIN_16dBm = 0x00, + BIND_POWER_FIRST = MIN_16dBm, + MIN_5dBm = 0x01, + MIN_0dbm = 0x02, + PLUS_5dBm = 0x03, + PLUS_14dBm = 0x04, + BIND_POWER_LAST = PLUS_14dBm, +}; + +// enum EMI_STANDARD +// { +// FCC = 0x00, +// CE = 0x01 +// }; + +enum TELEMETRY +{ + TELEMETRY_DISABLED = 0x00, + TELEMETRY_ENABLED = 0x01 +}; + +enum PULSE_MODE +{ + PWM_MODE = 0x00, + PPM_MODE = 0x01, +}; + +enum SERIAL_MODE +{ + IBUS = 0x00, + SBUS_MODE = 0x02 +}; + +// Old format for FRM302 +// PACK(struct Config_s { +// uint8_t bindPower; +// uint8_t runPower; +// uint8_t emiStandard; +// uint8_t telemetry; +// uint16_t pwmFreq; +// uint8_t pulseMode; +// uint8_t serialMode; +// uint8_t channelCount; +// uint16_t failSafeTimout; +// int16_t failSafeMode[AFHDS3_MAX_CHANNELS]; +// }); + +PACK(struct sSES_PWMFrequencyV0 { + uint16_t Frequency : 15; // From 50 to 400Hz + uint16_t Synchronized : 1; // 1=Synchronize the PWM output to the RF cycle + // (lower latency but unstable frequency) +}); + +enum eSES_PA_SetAnalogOutput { + SES_ANALOG_OUTPUT_PWM = 0, + SES_ANALOG_OUTPUT_PPM +}; + +enum eEB_BusType { + EB_BT_IBUS1=0, + EB_BT_IBUS2, + EB_BT_SBUS1 +}; + +// 48 bytes +PACK(struct sDATA_ConfigV0 { + uint8_t Version; // =0 + uint8_t EMIStandard; // eLNK_EMIStandard + uint8_t IsTwoWay; + uint8_t PhyMode; // eDATA_PHYMODE + uint8_t SignalStrengthRCChannelNb; // 0xFF if not used, 0`18 + uint16_t FailsafeTimeout; // in unit of ms + int16_t FailSafe[AFHDS3_MAX_CHANNELS]; + uint8_t FailsafeOutputMode; //TRUE Or FALSE + sSES_PWMFrequencyV0 PWMFrequency; + uint8_t AnalogOutput; // eSES_PA_SetAnalogOutput + uint8_t ExternalBusType; // eEB_BusType +}); + +#define SES_NB_MAX_CHANNELS (32) +#define SES_NPT_NB_MAX_PORTS (4) + +enum eSES_NewPortType { + SES_NPT_PWM, + SES_NPT_PPM, + SES_NPT_SBUS, + SES_NPT_IBUS1_IN, + SES_NPT_IBUS1_OUT, + SES_NPT_IBUS2, + SES_NPT_IBUS2_HUB_PORT, + SES_NPT_WSTX, + SES_NPT_WSRX, + SES_NPT_NONE=0xFF +}; + +PACK(struct sSES_PWMFrequenciesAPPV1 { + // One unsigned short per + // channel, From 50 to 400Hz, + // 1:1000Hz,2:833Hz + uint16_t PWMFrequencies[SES_NB_MAX_CHANNELS]; + + // 1 bit per channel, 32 channels total + uint32_t Synchronized; +}); + +// 116 bytes +PACK(struct sDATA_ConfigV1 { + uint8_t Version; // =1 + uint8_t EMIStandard; // eLNK_EMIStandard + uint8_t IsTwoWay; + uint8_t PhyMode; // eDATA_PHYMODE + uint8_t SignalStrengthRCChannelNb; // 0xFF if not used , 0`18 + uint16_t FailsafeTimeout; // in unit of ms + int16_t FailSafe[AFHDS3_MAX_CHANNELS]; + uint8_t FailsafeOutputMode; // TRUE Or FALSE + uint8_t NewPortTypes[SES_NPT_NB_MAX_PORTS]; // eSES_NewPortType + sSES_PWMFrequenciesAPPV1 PWMFrequenciesV1; +}); + +union Config_u +{ + uint8_t version; + sDATA_ConfigV0 v0; + sDATA_ConfigV1 v1; + uint8_t buffer[sizeof(sDATA_ConfigV1)]; +}; + +enum CHANNELS_DATA_MODE +{ + CHANNELS = 0x01, + FAIL_SAFE = 0x02, +}; + +PACK(struct ChannelsData { + uint8_t mode; + uint8_t channelsNumber; + int16_t data[AFHDS3_MAX_CHANNELS]; +}); + +union ChannelsData_u +{ + ChannelsData data; + uint8_t buffer[sizeof(ChannelsData)]; +}; + +PACK(struct TelemetryData +{ + uint8_t sensorType; + uint8_t length; + uint8_t type; + uint8_t semsorID; + uint8_t data[8]; +}); + +enum MODULE_POWER_SOURCE +{ + INTERNAL = 0x01, + EXTERNAL = 0x02, +}; + +PACK(struct ModuleVersion +{ + uint32_t productNumber; + uint32_t hardwereVersion; + uint32_t bootloaderVersion; + uint32_t firmwareVersion; + uint32_t rfVersion; +}); + +PACK(struct CommandResult_s +{ + uint16_t command; + uint8_t result; + uint8_t respLen; +}); + +union AfhdsFrameData +{ + uint8_t value; + // Config_s Config; + ChannelsData Channels; + TelemetryData Telemetry; + ModuleVersion Version; + CommandResult_s CommandResult; +}; + +PACK(struct AfhdsFrame +{ + uint8_t startByte; + uint8_t address; + uint8_t frameNumber; + uint8_t frameType; + uint8_t command; + uint8_t value; + + AfhdsFrameData * GetData() + { + return reinterpret_cast(&value); + } +}); + +#define FRM302_STATUS 0x56 + +enum State +{ + UNKNOWN = 0, + SENDING_COMMAND, + AWAITING_RESPONSE, + IDLE +}; + +// one byte frames for request queue +struct Frame +{ + enum COMMAND command; + enum FRAME_TYPE frameType; + uint8_t payload; + uint8_t frameNumber; + bool useFrameNumber; + uint8_t payloadSize; +}; + +// simple fifo implementation because Pulses is used as member of union and can not be non trivial type +struct CommandFifo +{ + Frame commandFifo[8]; + volatile uint32_t setIndex; + volatile uint32_t getIndex; + + void clearCommandFifo(); + + inline uint32_t nextIndex(uint32_t idx) const + { + return (idx + 1) & (sizeof(commandFifo) / sizeof(commandFifo[0]) - 1); + } + + inline uint32_t prevIndex(uint32_t idx) const + { + if (idx == 0) + { + return (sizeof(commandFifo) / sizeof(commandFifo[0]) - 1); + } + return (idx - 1); + } + + inline bool isEmpty() const + { + return (getIndex == setIndex); + } + + inline void skip() + { + getIndex = nextIndex(getIndex); + } + + void enqueueACK(COMMAND command, uint8_t frameNumber); + + void enqueue(COMMAND command, FRAME_TYPE frameType, bool useData = false, uint8_t byteContent = 0); + +}; + +class ProtoState: public CommandFifo +{ + public: + /** + * Initialize class for operation + * @param moduleIndex index of module one of INTERNAL_MODULE, EXTERNAL_MODULE + * @param resetFrameCount flag if current frame count should be reseted + */ + + void init(uint8_t moduleIndex, bool resetFrameCount = true); + + /** + * Fills DMA buffers with frame to be send depending on actual state + */ + void setupFrame(); + + uint8_t* getBuffer(); + uint32_t getBufferSize(); + + /** + * Gets actual module status into provided buffer + * @param statusText target buffer for status + */ + void getStatusString(char * statusText) const; + + /** + * Gets actual power source and voltage + */ + void getPowerStatus(char* buffer) const; + + RUN_POWER actualRunPower() const; + + /** + * Sends stop command to prevent any further module operations + */ + void stop(); + + protected: + + void setConfigFromModel(); + + private: + + inline void sendByte(uint8_t b); + + inline void putBytes(uint8_t* data, int length); + + inline void putFrame(COMMAND command, FRAME_TYPE frameType, uint8_t* data = nullptr, uint8_t dataLength = 0, uint8_t* frame_index = nullptr); + + void parseData(uint8_t* rxBuffer, uint8_t rxBufferCount); + + void setState(uint8_t state); + + bool syncSettings(); + + void requestInfoAndRun(bool send = false); + + uint8_t setFailSafe(int16_t* target); + + inline int16_t convert(int channelValue); + + void sendChannelsData(); + + void clearFrameData(); + + void processTelemetryData(uint8_t byte, uint8_t* rxBuffer, uint8_t& rxBufferCount, uint8_t maxSize); + + //friendship declaration - use for passing telemetry + friend void processTelemetryData(uint8_t data, uint8_t module); + + /** + * Returns max power that currently can be set - use it to validate before synchronization of settings + */ + RUN_POWER getMaxRunPower() const; + + RUN_POWER getRunPower() const; + + bool isConnectedUnicast(); + + bool isConnectedMulticast(); + + Transport trsp; + void* trsp_buffer; + uint8_t frame_index; + uint8_t crc; + uint8_t state; + uint8_t timeout; + uint8_t esc_state; + + /** + * Index of the module + */ + uint8_t module_index; + /** + * Target mode to be set to the module one of MODULE_MODE_E + */ + uint8_t requestedModuleMode; + /** + * Internal operation state one of UNKNOWN, SENDING_COMMAND, AWAITING_RESPONSE, IDLE + * Used to avoid sending commands when not allowed to + */ + State operationState; + /** + * Actual repeat count for requested command/operation - incremented by every attempt sending anything + */ + uint16_t repeatCount; + /** + * Command count used for counting actual number of commands sent in run mode + */ + uint32_t cmdCount; + /** + * Command index of command to be send when cmdCount reached necessary value + */ + uint32_t cmdIndex; + /** + * Actual power source of the module - should be requested time to time + * Currently requested once + */ + enum MODULE_POWER_SOURCE powerSource; + /** + * Pointer to module config - it is making operations easier and faster + */ + ModuleData* moduleData; + /** + * Actual module configuration - must be requested from module + */ + Config_u cfg; + + /** + * Actual module version - must be requested from module + */ + ModuleVersion version; +}; + static const char* const moduleStateText[] = { "Not ready", @@ -75,7 +592,7 @@ static const char* const powerSourceText[] = static const COMMAND periodicRequestCommands[] = { COMMAND::MODULE_STATE, - COMMAND::MODULE_POWER_STATUS, + // COMMAND::MODULE_POWER_STATUS, COMMAND::MODULE_GET_CONFIG, COMMAND::VIRTUAL_FAILSAFE }; @@ -84,7 +601,23 @@ static const COMMAND periodicRequestCommands[] = const uint8_t FrameAddress = DeviceAddress::TRANSMITTER | (DeviceAddress::MODULE << 4); //Static collection of afhds3 object instances by module -PulsesData* AFHDS3PulsesData[EXTERNAL_MODULE + 1] = { nullptr, nullptr }; +static ProtoState protoState[NUM_MODULES]; + +void getStatusString(uint8_t module, char* buffer) +{ + return protoState[module].getStatusString(buffer); +} + +void getPowerStatus(uint8_t module, char* buffer) +{ + return protoState[module].getPowerStatus(buffer); +} + +RUN_POWER getActualRunPower(uint8_t module) +{ + // return protoState[module].actualRunPower(); + return (RUN_POWER)0; +} //friends function that can access telemetry parsing method void processTelemetryData(uint8_t data, uint8_t module) @@ -93,10 +626,8 @@ void processTelemetryData(uint8_t data, uint8_t module) uint8_t& rxBufferCount = getTelemetryRxBufferCount(module); uint8_t maxSize = TELEMETRY_RX_PACKET_SIZE; - if (AFHDS3PulsesData[module]) { - AFHDS3PulsesData[module]->processTelemetryData(data, rxBuffer, - rxBufferCount, maxSize); - } + protoState[module].processTelemetryData(data, rxBuffer, rxBufferCount, + maxSize); } void CommandFifo::clearCommandFifo() @@ -133,17 +664,18 @@ void CommandFifo::enqueue(COMMAND command, FRAME_TYPE frameType, bool useData, u } } -void PulsesData::getStatusString(char * buffer) const +void ProtoState::getStatusString(char* buffer) const { - strcpy(buffer, this->state <= ModuleState::STATE_READY ? moduleStateText[this->state] : "Unknown"); + strcpy(buffer, state <= ModuleState::STATE_READY ? moduleStateText[state] + : "Unknown"); } -void PulsesData::getPowerStatus(char* buffer) const +void ProtoState::getPowerStatus(char* buffer) const { strcpy(buffer, this->powerSource <= MODULE_POWER_SOURCE::EXTERNAL ? powerSourceText[this->powerSource] : "Unknown"); } -void PulsesData::processTelemetryData(uint8_t byte, uint8_t* rxBuffer, uint8_t& rxBufferCount, uint8_t maxSize) +void ProtoState::processTelemetryData(uint8_t byte, uint8_t* rxBuffer, uint8_t& rxBufferCount, uint8_t maxSize) { if (rxBufferCount == 0 && byte != AfhdsSpecialChars::START) { TRACE("AFHDS3 [SKIP] %02X", byte); @@ -179,17 +711,20 @@ void PulsesData::processTelemetryData(uint8_t byte, uint8_t* rxBuffer, uint8_t& rxBuffer[rxBufferCount++] = byte; } -bool PulsesData::isConnectedUnicast() +bool ProtoState::isConnectedUnicast() { - return cfg.config.telemetry == TELEMETRY::TELEMETRY_ENABLED && this->state == ModuleState::STATE_SYNC_DONE; + // return cfg.config.telemetry == TELEMETRY::TELEMETRY_ENABLED && + return this->state == ModuleState::STATE_SYNC_DONE; } -bool PulsesData::isConnectedMulticast() +bool ProtoState::isConnectedMulticast() { - return cfg.config.telemetry == TELEMETRY::TELEMETRY_DISABLED && this->state == ModuleState::STATE_SYNC_RUNNING; + // return cfg.config.telemetry == TELEMETRY::TELEMETRY_DISABLED && + // this->state == ModuleState::STATE_SYNC_RUNNING; + return false; } -void PulsesData::setupFrame() +void ProtoState::setupFrame() { if (operationState == State::AWAITING_RESPONSE) { if (repeatCount++ < MAX_RETRIES_AFHDS3) { @@ -206,61 +741,88 @@ void PulsesData::setupFrame() this->state = ModuleState::STATE_NOT_READY; } repeatCount = 0; + if (this->state == ModuleState::STATE_NOT_READY) { TRACE("AFHDS3 [GET MODULE READY]"); putFrame(COMMAND::MODULE_READY, FRAME_TYPE::REQUEST_GET_DATA); return; } - //check waiting commands + // check waiting commands if (!isEmpty()) { Frame f = commandFifo[getIndex]; - putFrame(f.command, f.frameType, &f.payload, f.payloadSize, f.useFrameNumber ? &f.frameNumber : &frame_index); + putFrame(f.command, f.frameType, &f.payload, f.payloadSize, + f.useFrameNumber ? &f.frameNumber : &frame_index); getIndex = nextIndex(getIndex); - TRACE("AFHDS3 [CMD QUEUE] cmd: %d frameType %d, useFrameNumber %d frame Number %d size %d", f.command, f.frameType, f.useFrameNumber, f.frameNumber, f.payloadSize); + TRACE( + "AFHDS3 [CMD QUEUE] cmd: 0x%02x frameType 0x%02x, useFrameNumber %d " + "frame Number %d size %d", + f.command, f.frameType, f.useFrameNumber, f.frameNumber, f.payloadSize); return; } - //config should be loaded already - if (syncSettings()) { - return; - } - - //if module is ready but not started - if (this->state == ModuleState::STATE_READY || this->state == ModuleState::STATE_STANDBY) { - cmdCount = 0; - repeatCount = 0; - requestInfoAndRun(true); - return; - } + // config should be loaded already + if (syncSettings()) { return; } ::ModuleSettingsMode moduleMode = getModuleMode(module_index); if (moduleMode == ::ModuleSettingsMode::MODULE_MODE_BIND) { - if (state != STATE_BINDING) { - TRACE("AFHDS3 [BIND]"); - setConfigFromModel(); - putFrame(COMMAND::MODULE_SET_CONFIG, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, cfg.buffer, sizeof(cfg.buffer)); - requestedModuleMode = MODULE_MODE_E::BIND; - enqueue(COMMAND::MODULE_MODE, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, true, requestedModuleMode); - return; + switch (state) { + case STATE_BINDING: + // TODO: poll status? handle timeout? + // requestedModuleMode = MODULE_MODE_E::BIND; + // putFrame(COMMAND::MODULE_MODE, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, + // &requestedModuleMode, 1); + // return; + break; + + default: + // case STATE_STANDBY: + TRACE("AFHDS3 [BIND]"); + setConfigFromModel(); + + putFrame(COMMAND::MODULE_SET_CONFIG, + FRAME_TYPE::REQUEST_SET_EXPECT_DATA, cfg.buffer, + cfg.version == 0 ? sizeof(cfg.v0) : sizeof(cfg.v1)); + + requestedModuleMode = MODULE_MODE_E::BIND; + enqueue(COMMAND::MODULE_MODE, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, true, + requestedModuleMode); + return; + + // default: + // // switch to standby mode first + // stop(); + // return; } } - else if (moduleMode == ::ModuleSettingsMode::MODULE_MODE_RANGECHECK) { - if (cfg.config.runPower != RUN_POWER::RUN_POWER_FIRST) { - TRACE("AFHDS3 [RANGE CHECK]"); - cfg.config.runPower = RUN_POWER::RUN_POWER_FIRST; - uint8_t data[] = { 0x13, 0x20, 0x02, cfg.config.runPower, 0 }; - TRACE("AFHDS3 SET TX POWER %d", moduleData->afhds3.runPower); - putFrame(COMMAND::SEND_COMMAND, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, data, sizeof(data)); + // else if (moduleMode == ::ModuleSettingsMode::MODULE_MODE_RANGECHECK) { + // if (cfg.config.runPower != RUN_POWER::RUN_POWER_FIRST) { + // TRACE("AFHDS3 [RANGE CHECK]"); + // cfg.config.runPower = RUN_POWER::RUN_POWER_FIRST; + // uint8_t data[] = { 0x13, 0x20, 0x02, cfg.config.runPower, 0 }; + // TRACE("AFHDS3 SET TX POWER %d", moduleData->afhds3.runPower); + // putFrame(COMMAND::SEND_COMMAND, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, + // data, sizeof(data)); + // return; + // } + // } + else if (moduleMode == ::ModuleSettingsMode::MODULE_MODE_NORMAL) { + // if module is ready but not started + if (this->state == ModuleState::STATE_READY || + this->state == ModuleState::STATE_STANDBY) { + cmdCount = 0; + repeatCount = 0; + requestInfoAndRun(true); return; } - } - else if (moduleMode == ::ModuleSettingsMode::MODULE_MODE_NORMAL) { //exit bind + + // exit bind if (state == STATE_BINDING) { TRACE("AFHDS3 [EXIT BIND]"); requestedModuleMode = MODULE_MODE_E::RUN; - putFrame(COMMAND::MODULE_MODE, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, &requestedModuleMode, 1); + putFrame(COMMAND::MODULE_MODE, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, + &requestedModuleMode, 1); return; } } @@ -278,39 +840,62 @@ void PulsesData::setupFrame() if (isConnected) { if (isConnectedMulticast()) { TRACE("AFHDS ONE WAY FAILSAFE"); - uint16_t failSafe[MAX_CHANNELS + 1] = { ((MAX_CHANNELS << 8) | CHANNELS_DATA_MODE::FAIL_SAFE), 0 }; - setFailSafe((int16_t*) (&failSafe[1])); - putFrame(COMMAND::CHANNELS_FAILSAFE_DATA, FRAME_TYPE::REQUEST_SET_NO_RESP, (uint8_t*) failSafe, MAX_CHANNELS * 2 + 2); - } - else { + uint16_t failSafe[AFHDS3_MAX_CHANNELS + 1] = { + ((AFHDS3_MAX_CHANNELS << 8) | CHANNELS_DATA_MODE::FAIL_SAFE), 0}; + setFailSafe((int16_t*)(&failSafe[1])); + putFrame(COMMAND::CHANNELS_FAILSAFE_DATA, + FRAME_TYPE::REQUEST_SET_NO_RESP, (uint8_t*)failSafe, + AFHDS3_MAX_CHANNELS * 2 + 2); + } else { TRACE("AFHDS TWO WAYS FAILSAFE"); - uint8_t failSafe[3 + MAX_CHANNELS * 2] = { 0x11, 0x60, MAX_CHANNELS * 2 }; - setFailSafe((int16_t*) (failSafe + 3)); - putFrame(COMMAND::SEND_COMMAND, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, failSafe, 3 + MAX_CHANNELS * 2); + uint8_t failSafe[3 + AFHDS3_MAX_CHANNELS * 2] = { + 0x11, 0x60, AFHDS3_MAX_CHANNELS * 2}; + setFailSafe((int16_t*)(failSafe + 3)); + putFrame(COMMAND::SEND_COMMAND, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, + failSafe, 3 + AFHDS3_MAX_CHANNELS * 2); } - } - else { + } else { putFrame(COMMAND::MODULE_STATE, FRAME_TYPE::REQUEST_GET_DATA); } - } - else - { + } else { putFrame(cmd, FRAME_TYPE::REQUEST_GET_DATA); } - } - else if (isConnected) { + } else if (isConnected) { sendChannelsData(); - } - else { + } else { //default frame - request state putFrame(MODULE_STATE, FRAME_TYPE::REQUEST_GET_DATA); } } -void PulsesData::init(uint8_t moduleIndex, bool resetFrameCount) +uint8_t* ProtoState::getBuffer() +{ + return (uint8_t*)trsp_buffer; +} + +uint32_t ProtoState::getBufferSize() +{ + return trsp.getSize(trsp_buffer); +} + +void ProtoState::init(uint8_t moduleIndex, bool resetFrameCount) { module_index = moduleIndex; - AFHDS3PulsesData[module_index] = this; +#if defined(INTERNAL_MODULE_AFHDS3) + if (moduleIndex == INTERNAL_MODULE) { + trsp_buffer = &intmodulePulsesData.afhds3; + trsp.init(Transport::Serial); + } else +#endif + { + trsp_buffer = &extmodulePulsesData.afhds3; +#if defined(AFHDS3_EXT_UART) + trsp.init(Transport::Serial); +#else + trsp.init(Transport::Pulses); +#endif + } + //clear local vars because it is member of union moduleData = &g_model.moduleData[module_index]; operationState = State::UNKNOWN; @@ -318,24 +903,29 @@ void PulsesData::init(uint8_t moduleIndex, bool resetFrameCount) clearFrameData(); } -void PulsesData::clearFrameData() +void ProtoState::clearFrameData() { TRACE("AFHDS3 clearFrameData"); - reset(); + trsp.reset(trsp_buffer); clearCommandFifo(); repeatCount = 0; cmdCount = 0; cmdIndex = 0; - this->frame_index = 1; - this->timeout = 0; - this->esc_state = 0; + frame_index = 1; + timeout = 0; + esc_state = 0; } -void PulsesData::putBytes(uint8_t* data, int length) +void ProtoState::sendByte(uint8_t b) +{ + trsp.sendByte(trsp_buffer, b); +} + +void ProtoState::putBytes(uint8_t* data, int length) { for (int i = 0; i < length; i++) { uint8_t byte = data[i]; - this->crc += byte; + crc += byte; if (END == byte) { sendByte(ESC); sendByte(ESC_END); @@ -350,15 +940,15 @@ void PulsesData::putBytes(uint8_t* data, int length) } } -void PulsesData::putFrame(COMMAND command, FRAME_TYPE frame, uint8_t* data, uint8_t dataLength, uint8_t* frameIndex) +void ProtoState::putFrame(COMMAND command, FRAME_TYPE frame, uint8_t* data, uint8_t dataLength, uint8_t* frameIndex) { //header operationState = State::SENDING_COMMAND; - reset(); - this->crc = 0; + trsp.reset(trsp_buffer); + crc = 0; sendByte(START); if (frameIndex == nullptr) { - frameIndex = &this->frame_index; + frameIndex = &frame_index; } uint8_t buffer[] = {FrameAddress, *frameIndex, frame, command}; putBytes(buffer, 4); @@ -368,7 +958,7 @@ void PulsesData::putFrame(COMMAND command, FRAME_TYPE frame, uint8_t* data, uint putBytes(data, dataLength); } //footer - uint8_t crcValue = this->crc ^ 0xff; + uint8_t crcValue = crc ^ 0xff; putBytes(&crcValue, 1); sendByte(END); *frameIndex = *frameIndex + 1; @@ -383,7 +973,7 @@ void PulsesData::putFrame(COMMAND command, FRAME_TYPE frame, uint8_t* data, uint operationState = State::IDLE; } - flush(); + trsp.flush(trsp_buffer); } bool checkCRC(const uint8_t* data, uint8_t size) @@ -405,7 +995,7 @@ bool containsData(enum FRAME_TYPE frameType) frameType == FRAME_TYPE::REQUEST_SET_NO_RESP); } -void PulsesData::setState(uint8_t state) +void ProtoState::setState(uint8_t state) { if (state == this->state) { return; @@ -420,22 +1010,25 @@ void PulsesData::setState(uint8_t state) } } -void PulsesData::requestInfoAndRun(bool send) +void ProtoState::requestInfoAndRun(bool send) { if (!send) { enqueue(COMMAND::MODULE_VERSION, FRAME_TYPE::REQUEST_GET_DATA); } - enqueue(COMMAND::MODULE_POWER_STATUS, FRAME_TYPE::REQUEST_GET_DATA); + + // enqueue(COMMAND::MODULE_POWER_STATUS, FRAME_TYPE::REQUEST_GET_DATA); + requestedModuleMode = MODULE_MODE_E::RUN; - enqueue(COMMAND::MODULE_MODE, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, true, (uint8_t) MODULE_MODE_E::RUN); + enqueue(COMMAND::MODULE_MODE, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, true, + (uint8_t)requestedModuleMode); + if (send) { putFrame(COMMAND::MODULE_VERSION, FRAME_TYPE::REQUEST_GET_DATA); } } -void PulsesData::parseData(uint8_t* rxBuffer, uint8_t rxBufferCount) +void ProtoState::parseData(uint8_t* rxBuffer, uint8_t rxBufferCount) { - if (!checkCRC(rxBuffer, rxBufferCount - 2)) { TRACE("AFHDS3 [INVALID CRC]"); return; @@ -455,16 +1048,22 @@ void PulsesData::parseData(uint8_t* rxBuffer, uint8_t rxBufferCount) break; case COMMAND::MODULE_GET_CONFIG: std::memcpy((void*) cfg.buffer, &responseFrame->value, sizeof(cfg.buffer)); - TRACE("AFHDS3 [MODULE_GET_CONFIG] bind power %d run power %d mode %d pwm/ppm %d ibus/sbus %d", cfg.config.bindPower, cfg.config.runPower, cfg.config.telemetry, cfg.config.pulseMode, cfg.config.serialMode); + // TRACE( + // "AFHDS3 [MODULE_GET_CONFIG] bind power %d run power %d mode %d " + // "pwm/ppm %d ibus/sbus %d", + // cfg.config.bindPower, cfg.config.runPower, cfg.config.telemetry, + // cfg.config.pulseMode, cfg.config.serialMode); break; case COMMAND::MODULE_VERSION: std::memcpy((void*) &version, &responseFrame->value, sizeof(version)); - TRACE("AFHDS3 [MODULE_VERSION] Product %d, HW %d, BOOT %d, FW %d", version.productNumber, version.hardwereVersion, version.bootloaderVersion, version.firmwareVersion); - break; - case COMMAND::MODULE_POWER_STATUS: - powerSource = (enum MODULE_POWER_SOURCE) responseFrame->value; - TRACE("AFHDS3 [MODULE_POWER_STATUS], %d", powerSource); + TRACE("AFHDS3 [MODULE_VERSION] Product %d, HW %d, BOOT %d, FW %d", + version.productNumber, version.hardwereVersion, + version.bootloaderVersion, version.firmwareVersion); break; + // case COMMAND::MODULE_POWER_STATUS: + // powerSource = (enum MODULE_POWER_SOURCE) responseFrame->value; + // TRACE("AFHDS3 [MODULE_POWER_STATUS], %d", powerSource); + // break; case COMMAND::MODULE_STATE: TRACE("AFHDS3 [MODULE_STATE] %02X", responseFrame->value); setState(responseFrame->value); @@ -553,6 +1152,7 @@ void PulsesData::parseData(uint8_t* rxBuffer, uint8_t rxBufferCount) } TRACE("AFHDS3 [QUEUE ACK] cmd %02X type %02X number %02X", responseFrame->command, responseFrame->frameType, responseFrame->frameNumber); enqueueACK((enum COMMAND) responseFrame->command, responseFrame->frameNumber); + // TODO: send ACK immediately !!! } else if (responseFrame->frameType == FRAME_TYPE::RESPONSE_DATA || responseFrame->frameType == FRAME_TYPE::RESPONSE_ACK) { if (operationState == State::AWAITING_RESPONSE) { @@ -571,7 +1171,7 @@ inline bool isPWM(uint8_t mode) return !(mode & 2); } -RUN_POWER PulsesData::getMaxRunPower() const +RUN_POWER ProtoState::getMaxRunPower() const { if (powerSource == MODULE_POWER_SOURCE::EXTERNAL) { return RUN_POWER::PLUS_33dBm; @@ -580,121 +1180,204 @@ RUN_POWER PulsesData::getMaxRunPower() const return RUN_POWER::PLUS_27dbm; } -RUN_POWER PulsesData::actualRunPower() const +RUN_POWER ProtoState::actualRunPower() const { - uint8_t actualRfPower = cfg.config.runPower; - if (getMaxRunPower() < actualRfPower) { - actualRfPower = getMaxRunPower(); - } - return (RUN_POWER) actualRfPower; + // uint8_t actualRfPower = cfg.config.runPower; + // if (getMaxRunPower() < actualRfPower) { + // actualRfPower = getMaxRunPower(); + // } + // return (RUN_POWER) actualRfPower; + return (RUN_POWER)0; } -RUN_POWER PulsesData::getRunPower() const +RUN_POWER ProtoState::getRunPower() const { - RUN_POWER targetPower = (RUN_POWER) moduleData->afhds3.runPower; - if (getMaxRunPower() < targetPower) { - targetPower = getMaxRunPower(); - } - return targetPower; + // RUN_POWER targetPower = (RUN_POWER) moduleData->afhds3.runPower; + // if (getMaxRunPower() < targetPower) { + // targetPower = getMaxRunPower(); + // } + // return targetPower; + return (RUN_POWER)0; } -bool PulsesData::syncSettings() +bool ProtoState::syncSettings() { - RUN_POWER targetPower = getRunPower(); + // RUN_POWER targetPower = getRunPower(); - /*not sure if we need to prevent them in bind mode*/ - if (getModuleMode(module_index) != ::ModuleSettingsMode::MODULE_MODE_BIND && targetPower != cfg.config.runPower) { - cfg.config.runPower = moduleData->afhds3.runPower; - uint8_t data[] = { 0x13, 0x20, 0x02, moduleData->afhds3.runPower, 0 }; - TRACE("AFHDS3 SET TX POWER %d", moduleData->afhds3.runPower); - putFrame(COMMAND::SEND_COMMAND, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, data, sizeof(data)); - return true; - } + // /*not sure if we need to prevent them in bind mode*/ + // if (getModuleMode(module_index) != ::ModuleSettingsMode::MODULE_MODE_BIND && + // targetPower != cfg.config.runPower) { + // cfg.config.runPower = moduleData->afhds3.runPower; + // uint8_t data[] = {0x13, 0x20, 0x02, moduleData->afhds3.runPower, 0}; + // TRACE("AFHDS3 SET TX POWER %d", moduleData->afhds3.runPower); + // putFrame(COMMAND::SEND_COMMAND, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, data, + // sizeof(data)); + // return true; + // } - //other settings only in 2 way mode (state must be synchronized) - if (this->state != ModuleState::STATE_SYNC_DONE) { - return false; - } + // // other settings only in 2 way mode (state must be synchronized) + // if (this->state != ModuleState::STATE_SYNC_DONE) { + // return false; + // } - if (moduleData->afhds3.rxFreq() != cfg.config.pwmFreq) { - cfg.config.pwmFreq = moduleData->afhds3.rxFreq(); - uint8_t data[] = { 0x17, 0x70, 0x02, (uint8_t) (moduleData->afhds3.rxFreq() & 0xFF), (uint8_t) (moduleData->afhds3.rxFreq() >> 8) }; - TRACE("AFHDS3 SET RX FREQ"); - putFrame(COMMAND::SEND_COMMAND, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, data, sizeof(data)); - return true; - } - PULSE_MODE modelPulseMode = isPWM(moduleData->afhds3.mode) - ? PULSE_MODE::PWM_MODE - : PULSE_MODE::PPM_MODE; - if (modelPulseMode != cfg.config.pulseMode) { - cfg.config.pulseMode = modelPulseMode; - TRACE("AFHDS3 PWM/PPM %d", modelPulseMode); - uint8_t data[] = { 0x16, 0x70, 0x01, (uint8_t) (modelPulseMode) }; - putFrame(COMMAND::SEND_COMMAND, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, data, sizeof(data)); - return true; - } + // if (moduleData->afhds3.rxFreq() != cfg.config.pwmFreq) { + // cfg.config.pwmFreq = moduleData->afhds3.rxFreq(); + // uint8_t data[] = {0x17, 0x70, 0x02, + // (uint8_t)(moduleData->afhds3.rxFreq() & 0xFF), + // (uint8_t)(moduleData->afhds3.rxFreq() >> 8)}; + // TRACE("AFHDS3 SET RX FREQ"); + // putFrame(COMMAND::SEND_COMMAND, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, data, + // sizeof(data)); + // return true; + // } - SERIAL_MODE modelSerialMode = isSbus(moduleData->afhds3.mode) - ? SERIAL_MODE::SBUS_MODE - : SERIAL_MODE::IBUS; - if (modelSerialMode != cfg.config.serialMode) { - cfg.config.serialMode = modelSerialMode; - TRACE("AFHDS3 IBUS/SBUS %d", modelSerialMode); - uint8_t data[] = { 0x18, 0x70, 0x01, (uint8_t) (modelSerialMode) }; - putFrame(COMMAND::SEND_COMMAND, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, data, sizeof(data)); - return true; - } + // PULSE_MODE modelPulseMode = isPWM(moduleData->afhds3.mode) + // ? PULSE_MODE::PWM_MODE + // : PULSE_MODE::PPM_MODE; + // if (modelPulseMode != cfg.config.pulseMode) { + // cfg.config.pulseMode = modelPulseMode; + // TRACE("AFHDS3 PWM/PPM %d", modelPulseMode); + // uint8_t data[] = {0x16, 0x70, 0x01, (uint8_t)(modelPulseMode)}; + // putFrame(COMMAND::SEND_COMMAND, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, data, + // sizeof(data)); + // return true; + // } + + // SERIAL_MODE modelSerialMode = isSbus(moduleData->afhds3.mode) + // ? SERIAL_MODE::SBUS_MODE + // : SERIAL_MODE::IBUS; + // if (modelSerialMode != cfg.config.serialMode) { + // cfg.config.serialMode = modelSerialMode; + // TRACE("AFHDS3 IBUS/SBUS %d", modelSerialMode); + // uint8_t data[] = {0x18, 0x70, 0x01, (uint8_t)(modelSerialMode)}; + // putFrame(COMMAND::SEND_COMMAND, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, data, + // sizeof(data)); + // return true; + // } + + // if (moduleData->afhds3.failsafeTimeout != cfg.config.failSafeTimout) { + // moduleData->afhds3.failsafeTimeout = cfg.config.failSafeTimout; + // uint8_t data[] = {0x12, 0x60, 0x02, + // (uint8_t)(moduleData->afhds3.failsafeTimeout & 0xFF), + // (uint8_t)(moduleData->afhds3.failsafeTimeout >> 8)}; + // putFrame(COMMAND::SEND_COMMAND, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, data, + // sizeof(data)); + // TRACE("AFHDS3 FAILSAFE TMEOUT, %d", moduleData->afhds3.failsafeTimeout); + // return true; + // } - if (moduleData->afhds3.failsafeTimeout != cfg.config.failSafeTimout) { - moduleData->afhds3.failsafeTimeout = cfg.config.failSafeTimout; - uint8_t data[] = { 0x12, 0x60, 0x02, (uint8_t) (moduleData->afhds3.failsafeTimeout & 0xFF), (uint8_t) (moduleData->afhds3.failsafeTimeout >> 8) }; - putFrame(COMMAND::SEND_COMMAND, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, data, sizeof(data)); - TRACE("AFHDS3 FAILSAFE TMEOUT, %d", moduleData->afhds3.failsafeTimeout); - return true; - } return false; } -void PulsesData::sendChannelsData() +void ProtoState::sendChannelsData() { uint8_t channels_start = moduleData->channelsStart; uint8_t channelsCount = 8 + moduleData->channelsCount; uint8_t channels_last = channels_start + channelsCount; - int16_t buffer[MAX_CHANNELS + 1] = { ((MAX_CHANNELS << 8) | CHANNELS_DATA_MODE::CHANNELS), 0 }; - for (uint8_t channel = channels_start, index = 1; channel < channels_last; channel++, index++) { + int16_t buffer[AFHDS3_MAX_CHANNELS + 1] = {0}; + + uint8_t* header = (uint8_t*)buffer; + header[0] = CHANNELS_DATA_MODE::CHANNELS; + + uint8_t channels = _phyMode_channels[cfg.v0.PhyMode]; + header[1] = channels; + + for (uint8_t channel = channels_start, index = 1; channel < channels_last; + channel++, index++) { int16_t channelValue = convert(::getChannelValue(channel)); buffer[index] = channelValue; } - putFrame(COMMAND::CHANNELS_FAILSAFE_DATA, FRAME_TYPE::REQUEST_SET_NO_RESP, (uint8_t*) buffer, sizeof(buffer)); + + putFrame(COMMAND::CHANNELS_FAILSAFE_DATA, FRAME_TYPE::REQUEST_SET_NO_RESP, + (uint8_t*)buffer, (channels + 1) * 2); } -void PulsesData::stop() +void ProtoState::stop() { TRACE("AFHDS3 STOP"); requestedModuleMode = MODULE_MODE_E::STANDBY; - putFrame(COMMAND::MODULE_MODE, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, &requestedModuleMode, 1); + putFrame(COMMAND::MODULE_MODE, FRAME_TYPE::REQUEST_SET_EXPECT_DATA, + &requestedModuleMode, 1); } -void PulsesData::setConfigFromModel() +void ProtoState::setConfigFromModel() { - cfg.config.bindPower = moduleData->afhds3.bindPower; - cfg.config.runPower = getRunPower(); - cfg.config.emiStandard = EMI_STANDARD::FCC; - cfg.config.telemetry = moduleData->afhds3.telemetry; //always use bidirectional mode - cfg.config.pwmFreq = moduleData->afhds3.rxFreq(); - cfg.config.serialMode = isSbus(moduleData->afhds3.mode) - ? SERIAL_MODE::SBUS_MODE - : SERIAL_MODE::IBUS; - cfg.config.pulseMode = isPWM(moduleData->afhds3.mode) ? PULSE_MODE::PWM_MODE - : PULSE_MODE::PPM_MODE; - // use max channels - because channel count can not be changed after bind - cfg.config.channelCount = MAX_CHANNELS; - cfg.config.failSafeTimout = moduleData->afhds3.failsafeTimeout; - setFailSafe(cfg.config.failSafeMode); + // cfg.config.bindPower = moduleData->afhds3.bindPower; + // cfg.config.runPower = getRunPower(); + // cfg.config.emiStandard = EMI_STANDARD::FCC; + // cfg.config.telemetry = moduleData->afhds3.telemetry; //always use bidirectional mode + // cfg.config.pwmFreq = moduleData->afhds3.rxFreq(); + // cfg.config.serialMode = isSbus(moduleData->afhds3.mode) + // ? SERIAL_MODE::SBUS_MODE + // : SERIAL_MODE::IBUS; + // cfg.config.pulseMode = isPWM(moduleData->afhds3.mode) ? PULSE_MODE::PWM_MODE + // : PULSE_MODE::PPM_MODE; + // // use max channels - because channel count can not be changed after bind + // cfg.config.channelCount = AFHDS3_MAX_CHANNELS; + // cfg.config.failSafeTimout = moduleData->afhds3.failsafeTimeout; + // setFailSafe(cfg.config.failSafeMode); + + if (moduleData->afhds3.phyMode < ROUTINE_FLCR1_18CH) { + cfg.version = 0; + } else { + cfg.version = 1; + } + + if (cfg.version == 1) { + cfg.v1.EMIStandard = moduleData->afhds3.emi; + cfg.v1.IsTwoWay = moduleData->afhds3.telemetry; + cfg.v1.PhyMode = moduleData->afhds3.phyMode; + cfg.v1.SignalStrengthRCChannelNb = 0xFF; + + // Failsafe + cfg.v1.FailsafeTimeout = 500; + setFailSafe(cfg.v1.FailSafe); + + if (moduleData->failsafeMode != FAILSAFE_NOPULSES) { + cfg.v1.FailsafeOutputMode = true; + } else { + cfg.v1.FailsafeOutputMode = false; + } + + // Serial output + memclear(&cfg.v1.NewPortTypes, sizeof(cfg.v1.NewPortTypes)); + + // PWM settings + for (int i = 0; i < SES_NB_MAX_CHANNELS; i++) + cfg.v1.PWMFrequenciesV1.PWMFrequencies[i] = 50; + + cfg.v1.PWMFrequenciesV1.Synchronized = 0; + + } else { + cfg.v0.EMIStandard = moduleData->afhds3.emi; + cfg.v0.IsTwoWay = moduleData->afhds3.telemetry; + cfg.v0.PhyMode = moduleData->afhds3.phyMode; + cfg.v0.SignalStrengthRCChannelNb = 0xFF; + + // Failsafe + cfg.v0.FailsafeTimeout = 500; + setFailSafe(cfg.v0.FailSafe); + + if (moduleData->failsafeMode != FAILSAFE_NOPULSES) { + cfg.v0.FailsafeOutputMode = true; + } else { + cfg.v0.FailsafeOutputMode = false; + } + + // PWM settings + cfg.v0.PWMFrequency.Frequency = 50; + cfg.v0.PWMFrequency.Synchronized = 0; + + // PWM/PPM + cfg.v0.AnalogOutput = 0; + + // iBUS/SBUS + cfg.v0.ExternalBusType = EB_BT_IBUS1; + } } -inline int16_t PulsesData::convert(int channelValue) +inline int16_t ProtoState::convert(int channelValue) { //pulseValue = limit(0, 988 + ((channelValue + 1024) / 2), 0xfff); //988 - 750 = 238 @@ -704,10 +1387,10 @@ inline int16_t PulsesData::convert(int channelValue) // 988 ---- 2012 //-10240 ---- 10240 //-1024 ---- 1024 - return ::limit(FAILSAFE_MIN, channelValue * 10, FAILSAFE_MAX); + return ::limit(AFHDS3_FAILSAFE_MIN, channelValue * 10, AFHDS3_FAILSAFE_MAX); } -uint8_t PulsesData::setFailSafe(int16_t* target) +uint8_t ProtoState::setFailSafe(int16_t* target) { int16_t pulseValue = 0; uint8_t channels_start = moduleData->channelsStart; @@ -726,13 +1409,13 @@ uint8_t PulsesData::setFailSafe(int16_t* target) target[channel - channels_start] = pulseValue; } //return max channels because channel count can not be change after bind - return (uint8_t) (MAX_CHANNELS); + return (uint8_t) (AFHDS3_MAX_CHANNELS); } -#if defined(EXTMODULE_USART) && defined(EXTMODULE_TX_INVERT_GPIO) +#if defined(AFHDS3_EXT_UART) static const etx_serial_init extmoduleUsartParams = { - .baudrate = AFHDS3_BAUDRATE, + .baudrate = AFHDS3_UART_BAUDRATE, .parity = ETX_Parity_None, .stop_bits = ETX_StopBits_One, .word_length = ETX_WordLength_8, @@ -741,13 +1424,15 @@ static const etx_serial_init extmoduleUsartParams = { static void* initExternal(uint8_t module) { - extmodulePulsesData.afhds3.init(module); - ExtmoduleSerialDriver.init(&extmoduleUsartParams); + auto p_state = &protoState[module]; - mixerSchedulerSetPeriod(module, AFHDS3_COMMAND_TIMEOUT * 1000 /* us */); + p_state->init(module); + void* ctx = ExtmoduleSerialDriver.init(&extmoduleUsartParams); + + mixerSchedulerSetPeriod(module, AFHDS3_UART_COMMAND_TIMEOUT * 1000 /* us */); EXTERNAL_MODULE_ON(); - return nullptr; + return ctx; } static void deinitExternal(void* context) @@ -759,18 +1444,20 @@ static void deinitExternal(void* context) static void sendPulsesExternal(void* context) { - ExtmoduleSerialDriver.sendBuffer(context, extmodulePulsesData.afhds3.getData(), - extmodulePulsesData.afhds3.getSize()); + auto p_state = &protoState[EXTERNAL_MODULE]; + ExtmoduleSerialDriver.sendBuffer(context, p_state->getBuffer(), p_state->getBufferSize()); } -#else // !defined(EXTMODULE_USART) || !defined(EXTMODULE_TX_INVERT_GPIO) +#else // !defined(AFHDS3_USART) static void* initExternal(uint8_t module) { - extmodulePulsesData.afhds3.init(module); + auto p_state = &protoState[module]; + + p_state->init(module); extmoduleSerialStart(); - mixerSchedulerSetPeriod(module, AFHDS3_COMMAND_TIMEOUT * 1000 /* us */); + mixerSchedulerSetPeriod(module, AFHDS3_SOFTSERIAL_COMMAND_TIMEOUT * 1000 /* us */); return nullptr; } @@ -784,9 +1471,8 @@ static void deinitExternal(void* context) static void sendPulsesExternal(void* context) { (void)context; - extmoduleSendNextFrameSoftSerial(extmodulePulsesData.afhds3.getData(), - extmodulePulsesData.afhds3.getSize(), - false); + auto p_state = &protoState[EXTERNAL_MODULE]; + extmoduleSendNextFrameSoftSerial(p_state->getBuffer(), p_state->getBufferSize(), false); } #endif @@ -796,7 +1482,9 @@ static void setupPulsesExternal(void* context, int16_t* channels, uint8_t nChann (void)context; (void)channels; (void)nChannels; - extmodulePulsesData.afhds3.setupFrame(); + + auto p_state = &protoState[EXTERNAL_MODULE]; + p_state->setupFrame(); } etx_module_driver_t externalDriver = { @@ -810,7 +1498,7 @@ etx_module_driver_t externalDriver = { #if defined(INTERNAL_MODULE_AFHDS3) static const etx_serial_init intmoduleUsartParams = { - .baudrate = 1500000, + .baudrate = AFHDS3_UART_BAUDRATE, .parity = ETX_Parity_None, .stop_bits = ETX_StopBits_One, .word_length = ETX_WordLength_8, @@ -819,12 +1507,12 @@ static const etx_serial_init intmoduleUsartParams = { static void* initInternal(uint8_t module) { - (void)module; + auto p_state = &protoState[module]; - // serial port setup - intmodulePulsesData.afhds3.init(module); - void * ctx = IntmoduleSerialDriver.init(&intmoduleUsartParams); - mixerSchedulerSetPeriod(module, AFHDS3_COMMAND_TIMEOUT * 1000 /* us */); + p_state->init(module); + void* ctx = IntmoduleSerialDriver.init(&intmoduleUsartParams); + + mixerSchedulerSetPeriod(module, AFHDS3_UART_COMMAND_TIMEOUT * 1000 /* us */); INTERNAL_MODULE_ON(); return ctx; @@ -844,13 +1532,15 @@ static void setupPulsesInternal(void* context, int16_t* channels, uint8_t nChann (void)context; (void)channels; (void)nChannels; - intmodulePulsesData.afhds3.setupFrame(); + + auto p_state = &protoState[INTERNAL_MODULE]; + p_state->setupFrame(); } static void sendPulsesInternal(void* context) { - IntmoduleSerialDriver.sendBuffer(context, intmodulePulsesData.afhds3.getData(), - intmodulePulsesData.afhds3.getSize()); + auto p_state = &protoState[INTERNAL_MODULE]; + IntmoduleSerialDriver.sendBuffer(context, p_state->getBuffer(), p_state->getBufferSize()); } static int getByteInternal(void* context, uint8_t* data) diff --git a/radio/src/pulses/afhds3.h b/radio/src/pulses/afhds3.h index 055d49236..46e5ce281 100644 --- a/radio/src/pulses/afhds3.h +++ b/radio/src/pulses/afhds3.h @@ -32,260 +32,50 @@ #include "fifo.h" #include "hal/module_driver.h" +#include "afhds3_transport.h" -#define AFHDS_MAX_PULSES 72 -//max number of transitions measured so far 290 + 10% -#define AFHDS_MAX_PULSES_TRANSITIONS 320 -//#define AFHDS3_SLOW +#define AFHDS3_MIN_FREQ 50 +#define AFHDS3_MAX_FREQ 400 +#define AFHDS3_MAX_CHANNELS 18 +#define AFHDS3_FAILSAFE_MIN -15000 +#define AFHDS3_FAILSAFE_MAX 15000 -#if defined(EXTMODULE_USART) && defined(EXTMODULE_TX_INVERT_GPIO) -#define AFHDS3_BAUDRATE 1500000 -#define AFHDS3_COMMAND_TIMEOUT 5 -#elif !defined(AFHDS3_SLOW) -// 1s = 1 000 000 us -// 1000000/115200 = 8,68 us -// actual timer is ticking in 0,5 us = 8,68*2 = 17,36 because it must be integer take 17 -// difference 1000000 / x = 8.5 --> x = 117 647 = difference = 1.2 % -// allowed half a bit difference on the last bit -- should be fine -#define AFHDS3_BAUDRATE 115200 -//Because timer is ticking with 0.5us -#define BITLEN_AFHDS (17) - -#define AFHDS3_COMMAND_TIMEOUT 15 -#else -// 1000000/57600 = 17,36 us -#define AFHDS3_BAUDRATE 57600 -// 64* 86 = 11 110 -#define AFHDS3_COMMAND_TIMEOUT 20 -#define BITLEN_AFHDS (35) -#endif - -#define AFHDS3_FRAME_HALF_US AFHDS3_COMMAND_TIMEOUT * 2000 - -//get channel value outside of afhds3 namespace -int32_t getChannelValue(uint8_t channel); - -//use uint16_t instead of pulse_duration_t namespace afhds3 { -enum AfhdsSpecialChars -{ - END = 0xC0, //Frame end - START = END, - ESC_END = 0xDC, //Escaped frame end - in case END occurs in fame then ESC ESC_END must be used - ESC = 0xDB, //Escaping character - ESC_ESC = 0xDD, //Escaping character in case ESC occurs in fame then ESC ESC_ESC must be used + +enum eLNK_EMIStandard { + LNK_ES_FREE = 0, + LNK_ES_CE, + LNK_ES_FCC, }; -struct Data -{ -#if defined(EXTMODULE_USART) && defined(EXTMODULE_TX_INVERT_GPIO) - uint8_t pulses[AFHDS_MAX_PULSES]; - uint8_t * ptr; +enum eDATA_PHYMODE { + // V0 + CLASSIC_FLCR1_18CH=0, + CLASSIC_FLCR6_10CH, + // V1 + ROUTINE_FLCR1_18CH, + ROUTINE_FLCR6_8CH, + ROUTINE_LORA_12CH, + // must be last + PHYMODE_MAX = ROUTINE_LORA_12CH +}; + +#if defined(AFHDS3_EXT_UART) +typedef SerialData ExtmoduleData; #else - uint32_t pulsesSize; - uint16_t pulses[AFHDS_MAX_PULSES_TRANSITIONS]; - uint32_t total; +typedef PulsesData ExtmoduleData; #endif - uint8_t frame_index; - uint8_t crc; - uint8_t state; - uint8_t timeout; - uint8_t esc_state; - - void reset() - { -#if defined(EXTMODULE_USART) && defined(EXTMODULE_TX_INVERT_GPIO) - ptr = pulses; -#else - pulsesSize = 0; -#endif - } - -#if defined(EXTMODULE_USART) && defined(EXTMODULE_TX_INVERT_GPIO) - void sendByte(uint8_t b) - { -#if !defined(SIMU) - *ptr++ = b; -#endif - } - - const uint8_t* getData() - { - return pulses; - } - - void flush() - { - } -#else - inline void _send_level(uint16_t v) - { - if (pulsesSize >= AFHDS_MAX_PULSES_TRANSITIONS) { - return; - } - pulses[pulsesSize++] = v; - } - void sendByte(uint8_t b) - { - if (pulsesSize >= AFHDS_MAX_PULSES_TRANSITIONS) { - return; - } - //use 8n1 - //parity: If the parity is enabled, then the MSB bit of the data to be transmitted is changed by the parity bit - //start is always 0 - bool level = 0; - uint16_t length = BITLEN_AFHDS; //start bit - for (uint8_t i = 0; i <= 8; i++) - { //8 data bits + Stop=1 - bool next_level = b & 1; - if (level == next_level) { - length += BITLEN_AFHDS; - } - else { - _send_level(length); - length = BITLEN_AFHDS; - level = next_level; - } - b = (b >> 1) | 0x80; // shift left to get next bit, fill msb with stop bit - needed just once - } - _send_level(length); //last bit (stop) - - } - //add remaining time of frame - void flush() - { - pulses[pulsesSize - 1] = 60000; - } - - const uint16_t * getData() - { - return pulses; - } +#if defined(INTERNAL_MODULE_AFHDS3) +typedef SerialData IntmoduleData; #endif - uint32_t getSize() const - { -#if defined(EXTMODULE_USART) && defined(EXTMODULE_TX_INVERT_GPIO) - return ptr - pulses; -#else - return pulsesSize; +extern etx_module_driver_t externalDriver; + +#if defined(INTERNAL_MODULE_AFHDS3) +extern etx_module_driver_t internalDriver; #endif - } -}; - -enum DeviceAddress -{ - TRANSMITTER = 0x01, - MODULE = 0x03, -}; - -enum FRAME_TYPE: uint8_t -{ - REQUEST_GET_DATA = 0x01, //Get data response: ACK + DATA - REQUEST_SET_EXPECT_DATA = 0x02, //Set data response: ACK + DATA - REQUEST_SET_EXPECT_ACK = 0x03, //Set data response: ACK - REQUEST_SET_NO_RESP = 0x05, //Set data response: none - RESPONSE_DATA = 0x10, //Response ACK + DATA - RESPONSE_ACK = 0x20, //Response ACK - NOT_USED = 0xff -}; - -enum COMMAND: uint8_t -{ - MODULE_READY = 0x01, - MODULE_STATE = 0x02, - MODULE_MODE = 0x03, - MODULE_SET_CONFIG = 0x04, - MODULE_GET_CONFIG = 0x06, - CHANNELS_FAILSAFE_DATA = 0x07, - TELEMETRY_DATA = 0x09, - SEND_COMMAND = 0x0C, - COMMAND_RESULT = 0x0D, - MODULE_POWER_STATUS = 0x0F, - MODULE_VERSION = 0x1F, - VIRTUAL_FAILSAFE = 0x99, // virtual command used to trigger failsafe - UNDEFINED = 0xFF -}; - -enum COMMAND_DIRECTION -{ - RADIO_TO_MODULE = 0, - MODULE_TO_RADIO = 1 -}; - -enum DATA_TYPE -{ - READY_DT, // 8 bytes 0x01 Not ready 0x02 Ready - STATE_DT, // See MODULE_STATE - MODE_DT, - MOD_CONFIG_DT, - CHANNELS_DT, - TELEMETRY_DT, - MODULE_POWER_DT, - MODULE_VERSION_DT, - EMPTY_DT, -}; - -//enum used by command response -> translate to ModuleState -enum MODULE_READY_E -{ - MODULE_STATUS_UNKNOWN = 0x00, - MODULE_STATUS_NOT_READY = 0x01, - MODULE_STATUS_READY = 0x02 -}; - -enum ModuleState -{ - STATE_NOT_READY = 0x00, //virtual - STATE_HW_ERROR = 0x01, - STATE_BINDING = 0x02, - STATE_SYNC_RUNNING = 0x03, - STATE_SYNC_DONE = 0x04, - STATE_STANDBY = 0x05, - STATE_UPDATING_WAIT = 0x06, - STATE_UPDATING_MOD = 0x07, - STATE_UPDATING_RX = 0x08, - STATE_UPDATING_RX_FAILED = 0x09, - STATE_RF_TESTING = 0x0a, - STATE_READY = 0x0b, //virtual - STATE_HW_TEST = 0xff, -}; - -//used for set command -enum MODULE_MODE_E -{ - STANDBY = 0x01, - BIND = 0x02, //after bind module will enter run mode - RUN = 0x03, - RX_UPDATE = 0x04, //after successful update module will enter standby mode, otherwise hw error will be raised - MODULE_MODE_UNKNOWN = 0xFF -}; - -enum CMD_RESULT -{ - FAILURE = 0x01, - SUCCESS = 0x02, -}; - -#define MIN_FREQ 50 -#define MAX_FREQ 400 -#define MAX_CHANNELS 18 -#define FAILSAFE_KEEP_LAST 0x8000 -#define FAILSAFE_MIN -15000 -#define FAILSAFE_MAX 15000 - -enum BIND_POWER -{ - MIN_16dBm = 0x00, - BIND_POWER_FIRST = MIN_16dBm, - MIN_5dBm = 0x01, - MIN_0dbm = 0x02, - PLUS_5dBm = 0x03, - PLUS_14dBm = 0x04, - BIND_POWER_LAST = PLUS_14dBm, -}; enum RUN_POWER { @@ -298,311 +88,11 @@ enum RUN_POWER RUN_POWER_LAST = PLUS_33dBm, }; -enum EMI_STANDARD -{ - FCC = 0x00, - CE = 0x01 -}; +void getStatusString(uint8_t module, char* buffer); +void getPowerStatus(uint8_t module, char* buffer); -enum TELEMETRY -{ - TELEMETRY_DISABLED = 0x00, - TELEMETRY_ENABLED = 0x01 -}; +RUN_POWER getActualRunPower(uint8_t module); -enum PULSE_MODE -{ - PWM_MODE = 0x00, - PPM_MODE = 0x01, -}; - -enum SERIAL_MODE -{ - IBUS = 0x00, - SBUS_MODE = 0x02 -}; - -PACK(struct Config_s { - uint8_t bindPower; - uint8_t runPower; - uint8_t emiStandard; - uint8_t telemetry; - uint16_t pwmFreq; - uint8_t pulseMode; - uint8_t serialMode; - uint8_t channelCount; - uint16_t failSafeTimout; - int16_t failSafeMode[MAX_CHANNELS]; -}); - -union Config_u -{ - Config_s config; - uint8_t buffer[sizeof(Config_s)]; -}; - -enum CHANNELS_DATA_MODE -{ - CHANNELS = 0x01, - FAIL_SAFE = 0x02, -}; - -PACK(struct ChannelsData { - uint8_t mode; - uint8_t channelsNumber; - int16_t data[MAX_CHANNELS]; -}); - -union ChannelsData_u -{ - ChannelsData data; - uint8_t buffer[sizeof(ChannelsData)]; -}; - -PACK(struct TelemetryData -{ - uint8_t sensorType; - uint8_t length; - uint8_t type; - uint8_t semsorID; - uint8_t data[8]; -}); - -enum MODULE_POWER_SOURCE -{ - INTERNAL = 0x01, - EXTERNAL = 0x02, -}; - -PACK(struct ModuleVersion -{ - uint32_t productNumber; - uint32_t hardwereVersion; - uint32_t bootloaderVersion; - uint32_t firmwareVersion; - uint32_t rfVersion; -}); - -PACK(struct CommandResult_s -{ - uint16_t command; - uint8_t result; - uint8_t respLen; -}); - -union AfhdsFrameData -{ - uint8_t value; - Config_s Config; - ChannelsData Channels; - TelemetryData Telemetry; - ModuleVersion Version; - CommandResult_s CommandResult; -}; - -PACK(struct AfhdsFrame -{ - uint8_t startByte; - uint8_t address; - uint8_t frameNumber; - uint8_t frameType; - uint8_t command; - uint8_t value; - - AfhdsFrameData * GetData() - { - return reinterpret_cast(&value); - } -}); - -#define FRM302_STATUS 0x56 - -enum State -{ - UNKNOWN = 0, - SENDING_COMMAND, - AWAITING_RESPONSE, - IDLE -}; - -// one byte frames for request queue -struct Frame -{ - enum COMMAND command; - enum FRAME_TYPE frameType; - uint8_t payload; - uint8_t frameNumber; - bool useFrameNumber; - uint8_t payloadSize; -}; - -// simple fifo implementation because Pulses is used as member of union and can not be non trivial type -struct CommandFifo -{ - Frame commandFifo[8]; - volatile uint32_t setIndex; - volatile uint32_t getIndex; - - void clearCommandFifo(); - - inline uint32_t nextIndex(uint32_t idx) const - { - return (idx + 1) & (sizeof(commandFifo) / sizeof(commandFifo[0]) - 1); - } - - inline uint32_t prevIndex(uint32_t idx) const - { - if (idx == 0) - { - return (sizeof(commandFifo) / sizeof(commandFifo[0]) - 1); - } - return (idx - 1); - } - - inline bool isEmpty() const - { - return (getIndex == setIndex); - } - - inline void skip() - { - getIndex = nextIndex(getIndex); - } - - void enqueueACK(COMMAND command, uint8_t frameNumber); - - void enqueue(COMMAND command, FRAME_TYPE frameType, bool useData = false, uint8_t byteContent = 0); - -}; - -void processTelemetryData(uint8_t date, uint8_t module); - -class PulsesData: public Data, CommandFifo -{ - public: - /** - * Initialize class for operation - * @param moduleIndex index of module one of INTERNAL_MODULE, EXTERNAL_MODULE - * @param resetFrameCount flag if current frame count should be reseted - */ - - void init(uint8_t moduleIndex, bool resetFrameCount = true); - - /** - * Fills DMA buffers with frame to be send depending on actual state - */ - void setupFrame(); - - /** - * Gets actual module status into provided buffer - * @param statusText target buffer for status - */ - void getStatusString(char * statusText) const; - - /** - * Gets actual power source and voltage - */ - void getPowerStatus(char* buffer) const; - - RUN_POWER actualRunPower() const; - - /** - * Sends stop command to prevent any further module operations - */ - void stop(); - - protected: - - void setConfigFromModel(); - - private: - - inline void putBytes(uint8_t* data, int length); - - inline void putFrame(COMMAND command, FRAME_TYPE frameType, uint8_t* data = nullptr, uint8_t dataLength = 0, uint8_t* frame_index = nullptr); - - void parseData(uint8_t* rxBuffer, uint8_t rxBufferCount); - - void setState(uint8_t state); - - bool syncSettings(); - - void requestInfoAndRun(bool send = false); - - uint8_t setFailSafe(int16_t* target); - - inline int16_t convert(int channelValue); - - void sendChannelsData(); - - void clearFrameData(); - - void processTelemetryData(uint8_t byte, uint8_t* rxBuffer, uint8_t& rxBufferCount, uint8_t maxSize); - - //friendship declaration - use for passing telemetry - friend void processTelemetryData(uint8_t data, uint8_t module); - - /** - * Returns max power that currently can be set - use it to validate before synchronization of settings - */ - RUN_POWER getMaxRunPower() const; - - RUN_POWER getRunPower() const; - - bool isConnectedUnicast(); - - bool isConnectedMulticast(); - - /** - * Index of the module - */ - uint8_t module_index; - /** - * Target mode to be set to the module one of MODULE_MODE_E - */ - uint8_t requestedModuleMode; - /** - * Internal operation state one of UNKNOWN, SENDING_COMMAND, AWAITING_RESPONSE, IDLE - * Used to avoid sending commands when not allowed to - */ - State operationState; - /** - * Actual repeat count for requested command/operation - incremented by every attempt sending anything - */ - uint16_t repeatCount; - /** - * Command count used for counting actual number of commands sent in run mode - */ - uint32_t cmdCount; - /** - * Command index of command to be send when cmdCount reached necessary value - */ - uint32_t cmdIndex; - /** - * Actual power source of the module - should be requested time to time - * Currently requested once - */ - enum MODULE_POWER_SOURCE powerSource; - /** - * Pointer to module config - it is making operations easier and faster - */ - ModuleData* moduleData; - /** - * Actual module configuration - must be requested from module - */ - Config_u cfg; - - /** - * Actual module version - must be requested from module - */ - ModuleVersion version; -}; - -extern etx_module_driver_t externalDriver; - -#if defined(INTERNAL_MODULE_AFHDS3) -extern etx_module_driver_t internalDriver; -#endif - -} /* Namespace ahfds3 */ +void processTelemetryData(uint8_t data, uint8_t module); +} // namespace afhds3 diff --git a/radio/src/pulses/afhds3_transport.cpp b/radio/src/pulses/afhds3_transport.cpp new file mode 100644 index 000000000..e5d1e4081 --- /dev/null +++ b/radio/src/pulses/afhds3_transport.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (C) EdgeTX + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * 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 "afhds3_transport.h" + +// timer is 2 MHz +#if defined(AFHDS3_SLOW) + // 1000000/57600 = 17,36 us + #define BITLEN_AFHDS (35) +#else + // 1000000/115200 = 8,68 us + #define BITLEN_AFHDS (17) +#endif + +namespace afhds3 +{ + +static void _serial_reset(void* buffer) +{ + auto data = (SerialData*)buffer; + data->ptr = data->pulses; +} + +static void _serial_sendByte(void* buffer, uint8_t b) +{ + auto data = (SerialData*)buffer; + *(data->ptr++) = b; +} + +static void _serial_flush(void*) {} + +uint32_t _serial_getSize(void* buffer) +{ + auto data = (SerialData*)buffer; + return data->ptr - data->pulses; +} + +static void _pulses_reset(void* buffer) +{ + auto data = (PulsesData*)buffer; + data->ptr = data->pulses; +} + +static inline void _pulses_send_level(PulsesData* data, uint16_t v) +{ + uint32_t size = data->ptr - data->pulses; + if (size >= AFHDS_MAX_PULSES_TRANSITIONS) return; + *(data->ptr)++ = v; +} + +static void _pulses_sendByte(void* buffer, uint8_t b) +{ + auto data = (PulsesData*)buffer; + uint32_t size = data->ptr - data->pulses; + if (size >= AFHDS_MAX_PULSES_TRANSITIONS) return; + + // use 8n1 + // parity: If the parity is enabled, then the MSB bit of the data to be + // transmitted is changed by the parity bit start is always 0 + bool level = 0; + uint16_t length = BITLEN_AFHDS; // start bit + for (uint8_t i = 0; i <= 8; i++) { // 8 data bits + Stop=1 + bool next_level = b & 1; + if (level == next_level) { + length += BITLEN_AFHDS; + } else { + _pulses_send_level(data, length); + length = BITLEN_AFHDS; + level = next_level; + } + b = (b >> 1) | 0x80; // shift left to get next bit, fill msb with stop + // bit - needed just once + } + _pulses_send_level(data, length); // last bit (stop) +} + +static void _pulses_flush(void* buffer) +{ + // TODO: use less, as the new driver can handle it + auto data = (PulsesData*)buffer; + *data->ptr = 60000; +} + +uint32_t _pulses_getSize(void* buffer) +{ + auto data = (PulsesData*)buffer; + return data->ptr - data->pulses; +} + +void Transport::init(Type t) +{ + if (t == Serial) { + reset = _serial_reset; + sendByte = _serial_sendByte; + flush = _serial_flush; + getSize = _serial_getSize; + } else if (t == Pulses) { + reset = _pulses_reset; + sendByte = _pulses_sendByte; + flush = _pulses_flush; + getSize = _pulses_getSize; + } else { + reset = nullptr; + sendByte = nullptr; + flush = nullptr; + getSize = nullptr; + } +} + +}; diff --git a/radio/src/pulses/afhds3_transport.h b/radio/src/pulses/afhds3_transport.h new file mode 100644 index 000000000..715b6be77 --- /dev/null +++ b/radio/src/pulses/afhds3_transport.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) EdgeTX + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * 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. + */ + +#pragma once + +#include +#include "hal.h" + +#define AFHDS_MAX_PULSES 128 + +// max number of transitions measured so far 290 + 10% +// TODO: define as a function of MAX_PULSES +#define AFHDS_MAX_PULSES_TRANSITIONS 320 + +#if defined(EXTMODULE_USART) && defined(EXTMODULE_TX_INVERT_GPIO) + #define AFHDS3_EXT_UART +#else + #define AFHDS3_EXT_SOFTSERIAL +#endif + +#define AFHDS3_UART_BAUDRATE 1500000 +#define AFHDS3_UART_COMMAND_TIMEOUT 5 + +#if defined(AFHDS3_SLOW) + #define AFHDS3_SOFTSERIAL_BAUDRATE 57600 + #define AFHDS3_SOFTSERIAL_COMMAND_TIMEOUT 20 +#else + #define AFHDS3_SOFTSERIAL_BAUDRATE 115200 + #define AFHDS3_SOFTSERIAL_COMMAND_TIMEOUT 15 +#endif + +namespace afhds3 +{ + +struct SerialData { + uint8_t pulses[AFHDS_MAX_PULSES]; + uint8_t* ptr; +}; + +struct PulsesData { + uint16_t pulses[AFHDS_MAX_PULSES_TRANSITIONS]; + uint16_t* ptr; +}; + +#if defined(EXTMODULE_USART) && defined(EXTMODULE_TX_INVERT_GPIO) +typedef SerialData ExtmoduleData; +#else +typedef PulsesData ExtmoduleData; +#endif + +#if defined(INTERNAL_MODULE_AFHDS3) +typedef SerialData IntmoduleData; +#endif + +struct Transport { + + enum Type { + Serial, + Pulses + }; + + void (*reset)(void* buffer); + void (*sendByte)(void* buffer, uint8_t b); + void (*flush)(void* buffer); + uint32_t (*getSize)(void* buffer); + + void init(Type t); +}; + +}; diff --git a/radio/src/pulses/modules_helpers.h b/radio/src/pulses/modules_helpers.h index f6d520c9f..7b357bc6e 100644 --- a/radio/src/pulses/modules_helpers.h +++ b/radio/src/pulses/modules_helpers.h @@ -784,26 +784,17 @@ inline void resetAccessAuthenticationCount() #endif } -inline void resetAfhds3Options(uint8_t moduleIdx) +inline void resetAfhdsOptions(uint8_t moduleIdx) { auto & data = g_model.moduleData[moduleIdx]; - //data.rfProtocol = 0; - data.subType = 0; #if defined(AFHDS3) - data.afhds3.bindPower = 0; - data.afhds3.runPower = 0; - data.afhds3.emi = 0; + data.subType = FLYSKY_SUBTYPE_AFHDS3; + data.afhds3.emi = 2; // FCC data.afhds3.telemetry = 1; - data.afhds3.rx_freq[0] = 50; - data.afhds3.rx_freq[1] = 0; - data.afhds3.failsafeTimeout = 1000; - data.channelsCount = 14 - 8; - data.failsafeMode = 1; - //" PWM+i"" PWM+s"" PPM+i"" PPM+s" - data.subType = 0; - for (uint8_t channel = 0; channel < MAX_OUTPUT_CHANNELS; channel++) { - g_model.failsafeChannels[channel] = 0; - } + data.afhds3.phyMode = 0; +#elif defined(AFHDS2A) + data.subType = FLYSKY_SUBTYPE_AFHDS2A; + data.flysky.setDefault(); #endif } @@ -819,8 +810,7 @@ inline void setModuleType(uint8_t moduleIdx, uint8_t moduleType) else if (moduleData.type == MODULE_TYPE_PPM) setDefaultPpmFrameLength(moduleIdx); else if (moduleData.type == MODULE_TYPE_FLYSKY) { - // TODO: what if AFHDS2A - resetAfhds3Options(moduleIdx); + resetAfhdsOptions(moduleIdx); } else resetAccessAuthenticationCount(); diff --git a/radio/src/pulses/pulses.cpp b/radio/src/pulses/pulses.cpp index b2732257c..dd7adc1de 100755 --- a/radio/src/pulses/pulses.cpp +++ b/radio/src/pulses/pulses.cpp @@ -52,6 +52,10 @@ #include "pulses/afhds2.h" #endif +#if defined(AFHDS3) +#include "pulses/afhds3.h" +#endif + uint8_t s_pulses_paused = 0; ModuleState moduleState[NUM_MODULES]; InternalModulePulsesData intmodulePulsesData __DMA; @@ -174,8 +178,8 @@ void getModuleStatusString(uint8_t moduleIdx, char * statusText) } #endif #if defined(AFHDS3) - if (moduleIdx == EXTERNAL_MODULE && isModuleAFHDS3(moduleIdx)) { - extmodulePulsesData.afhds3.getStatusString(statusText); + if (isModuleAFHDS3(moduleIdx)) { + afhds3::getStatusString(moduleIdx, statusText); } #endif } @@ -189,8 +193,8 @@ void getModuleSyncStatusString(uint8_t moduleIdx, char * statusText) } #endif #if defined(AFHDS3) - if (moduleIdx == EXTERNAL_MODULE && isModuleAFHDS3(moduleIdx)) { - extmodulePulsesData.afhds3.getPowerStatus(statusText); + if (isModuleAFHDS3(moduleIdx)) { + afhds3::getPowerStatus(moduleIdx, statusText); } #endif } @@ -198,8 +202,8 @@ void getModuleSyncStatusString(uint8_t moduleIdx, char * statusText) #if defined(AFHDS3) uint8_t actualAfhdsRunPower(int moduleIndex) { - if (moduleIndex == EXTERNAL_MODULE && isModuleAFHDS3(moduleIndex)) { - return (uint8_t)extmodulePulsesData.afhds3.actualRunPower(); + if (isModuleAFHDS3(moduleIndex)) { + return (uint8_t)afhds3::getActualRunPower(moduleIndex); } return 0; } diff --git a/radio/src/pulses/pulses.h b/radio/src/pulses/pulses.h index 384747fb5..592e45bfd 100644 --- a/radio/src/pulses/pulses.h +++ b/radio/src/pulses/pulses.h @@ -28,8 +28,8 @@ #include "pxx1.h" #include "pxx2.h" #include "multi.h" -#include "afhds3.h" #include "afhds2.h" +#include "afhds3_transport.h" #include "modules_helpers.h" #include "ff.h" #include "hal/module_driver.h" @@ -173,7 +173,7 @@ union InternalModulePulsesData { #endif #if defined(INTERNAL_MODULE_AFHDS3) - afhds3::PulsesData afhds3; + afhds3::IntmoduleData afhds3; #endif #if defined(INTERNAL_MODULE_PPM) @@ -199,7 +199,7 @@ union ExternalModulePulsesData { #endif #if defined(AFHDS3) - afhds3::PulsesData afhds3; + afhds3::ExtmoduleData afhds3; #endif PpmPulsesData ppm; diff --git a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp index 00c19e20b..28c49f31c 100644 --- a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp @@ -660,14 +660,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -692,7 +688,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_t12.cpp b/radio/src/storage/yaml/yaml_datastructs_t12.cpp index cb3bb2012..795342ab8 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t12.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t12.cpp @@ -628,14 +628,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -660,7 +656,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_t8.cpp b/radio/src/storage/yaml/yaml_datastructs_t8.cpp index 2e28dd40a..aaab3f771 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t8.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t8.cpp @@ -628,14 +628,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -660,7 +656,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_tlite.cpp b/radio/src/storage/yaml/yaml_datastructs_tlite.cpp index 2e28dd40a..aaab3f771 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tlite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tlite.cpp @@ -628,14 +628,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -660,7 +656,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_tpro.cpp b/radio/src/storage/yaml/yaml_datastructs_tpro.cpp index 8930c312e..cfc074e5c 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tpro.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tpro.cpp @@ -634,14 +634,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -666,7 +662,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_tx12.cpp b/radio/src/storage/yaml/yaml_datastructs_tx12.cpp index 423440318..efd9145af 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tx12.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tx12.cpp @@ -628,14 +628,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -660,7 +656,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_tx12mk2.cpp b/radio/src/storage/yaml/yaml_datastructs_tx12mk2.cpp index b7d662a1d..fea5586b9 100755 --- a/radio/src/storage/yaml/yaml_datastructs_tx12mk2.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tx12mk2.cpp @@ -628,14 +628,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -660,7 +656,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/yaml/yaml_datastructs_x10.cpp index f0559f16f..f6f5f0286 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x10.cpp @@ -685,14 +685,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -717,7 +713,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp index 4d3350269..853d84457 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp @@ -683,14 +683,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -715,7 +711,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_x7.cpp b/radio/src/storage/yaml/yaml_datastructs_x7.cpp index 2e28dd40a..aaab3f771 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x7.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x7.cpp @@ -628,14 +628,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -660,7 +656,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp index 955051bc6..074edef05 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp @@ -636,14 +636,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -668,7 +664,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp index 85758f60d..6cf360546 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp @@ -675,14 +675,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -707,7 +703,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp index 6989cae15..1b7e0be4d 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp @@ -613,14 +613,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -645,7 +641,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp index c314e4ea1..a0367a0ec 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp @@ -623,14 +623,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -655,7 +651,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_xlite.cpp b/radio/src/storage/yaml/yaml_datastructs_xlite.cpp index 9af3a866d..5062527fc 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlite.cpp @@ -620,14 +620,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -652,7 +648,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp index 05756c45a..f6932433e 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp @@ -624,14 +624,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -656,7 +652,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_zorro.cpp b/radio/src/storage/yaml/yaml_datastructs_zorro.cpp index b7d662a1d..fea5586b9 100644 --- a/radio/src/storage/yaml/yaml_datastructs_zorro.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_zorro.cpp @@ -628,14 +628,10 @@ static const struct YamlNode struct_anonymous_9[] = { YAML_END }; static const struct YamlNode struct_anonymous_10[] = { - YAML_UNSIGNED( "bindPower", 3 ), - YAML_UNSIGNED( "runPower", 3 ), - YAML_UNSIGNED( "emi", 1 ), + YAML_UNSIGNED( "emi", 2 ), YAML_UNSIGNED( "telemetry", 1 ), - YAML_UNSIGNED( "failsafeTimeout", 16 ), - YAML_ARRAY("rx_freq", 8, 2, struct_unsigned_8, NULL), - YAML_UNSIGNED( "mode", 2 ), - YAML_UNSIGNED( "reserved", 6 ), + YAML_UNSIGNED( "phyMode", 3 ), + YAML_UNSIGNED( "reserved", 2 ), YAML_END }; static const struct YamlNode struct_anonymous_11[] = { @@ -660,7 +656,7 @@ static const struct YamlNode union_anonymous_4_elmts[] = { YAML_STRUCT("sbus", 16, struct_anonymous_7, NULL), YAML_STRUCT("pxx2", 200, struct_anonymous_8, NULL), YAML_STRUCT("flysky", 56, struct_anonymous_9, NULL), - YAML_STRUCT("afhds3", 64, struct_anonymous_10, NULL), + YAML_STRUCT("afhds3", 8, struct_anonymous_10, NULL), YAML_STRUCT("ghost", 8, struct_anonymous_11, NULL), YAML_STRUCT("crsf", 8, struct_anonymous_12, NULL), YAML_STRUCT("dsmp", 8, struct_anonymous_13, NULL), diff --git a/radio/src/targets/common/arm/CMakeLists.txt b/radio/src/targets/common/arm/CMakeLists.txt index 9b12c6e0a..431734857 100644 --- a/radio/src/targets/common/arm/CMakeLists.txt +++ b/radio/src/targets/common/arm/CMakeLists.txt @@ -235,6 +235,11 @@ endif() if(AFHDS3) add_definitions(-DAFHDS3) + set(PULSES_SRC + ${PULSES_SRC} + afhds3.cpp + afhds3_transport.cpp + ) endif() if(CROSSFIRE) @@ -249,14 +254,6 @@ if(CROSSFIRE) ) endif() -if(AFHDS3) - add_definitions(-DAFHDS3) - set(PULSES_SRC - ${PULSES_SRC} - afhds3.cpp - ) -endif() - if(MULTIMODULE OR AFHDS3) set(SRC ${SRC} telemetry/flysky_ibus.cpp ) endif() diff --git a/radio/src/targets/horus/hal.h b/radio/src/targets/horus/hal.h index 5c42a40a7..88a8d17de 100644 --- a/radio/src/targets/horus/hal.h +++ b/radio/src/targets/horus/hal.h @@ -830,6 +830,7 @@ #define INTMODULE_DMA_STREAM_IRQHandler DMA2_Stream7_IRQHandler #define INTMODULE_DMA_FLAG_TC DMA_FLAG_TCIF7 #define INTMODULE_DMA_CHANNEL DMA_Channel_4 +// RX DMA: DMA2_Stream2 - Channel 4 #if defined(PCBX12S) #define INTMODULE_BOOTCMD_GPIO GPIOC #define INTMODULE_BOOTCMD_GPIO_PIN GPIO_Pin_2 // PC.02 diff --git a/radio/src/targets/nv14/board.h b/radio/src/targets/nv14/board.h index 877cd2536..2552a5a03 100644 --- a/radio/src/targets/nv14/board.h +++ b/radio/src/targets/nv14/board.h @@ -103,8 +103,11 @@ void SDRAM_Init(); #if !defined(SIMU) -#define INTERNAL_MODULE_OFF() GPIO_SetBits(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN) -#define INTERNAL_MODULE_ON() GPIO_ResetBits(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN) +// #define INTERNAL_MODULE_OFF() GPIO_SetBits(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN) +// #define INTERNAL_MODULE_ON() GPIO_ResetBits(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN) +#define INTERNAL_MODULE_OFF() GPIO_ResetBits(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN) +#define INTERNAL_MODULE_ON() GPIO_SetBits(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN) + void EXTERNAL_MODULE_ON(); void EXTERNAL_MODULE_OFF(); #define BLUETOOTH_MODULE_ON() GPIO_ResetBits(BLUETOOTH_ON_GPIO, BLUETOOTH_ON_GPIO_PIN) diff --git a/radio/src/telemetry/telemetry.cpp b/radio/src/telemetry/telemetry.cpp index bd4a7a8c1..342eabf08 100644 --- a/radio/src/telemetry/telemetry.cpp +++ b/radio/src/telemetry/telemetry.cpp @@ -154,7 +154,7 @@ void telemetryStart() { if (!telemetryTimer) { telemetryTimer = - xTimerCreateStatic("Telem", 4 / RTOS_MS_PER_TICK, pdTRUE, (void*)0, + xTimerCreateStatic("Telem", 2 / RTOS_MS_PER_TICK, pdTRUE, (void*)0, telemetryTimerCb, &telemetryTimerBuffer); } @@ -576,8 +576,9 @@ void telemetryInit(uint8_t protocol) #if defined(AFHDS3) else if (protocol == PROTOCOL_TELEMETRY_AFHDS3) { - telemetryPortInvertedInit(AFHDS3_BAUDRATE); - telemetryPortSetDirectionInput(); + // TODO: + // telemetryPortInvertedInit(AFHDS3_BAUDRATE); + // telemetryPortSetDirectionInput(); } #endif