diff --git a/src/hm/hmPayload.h b/src/hm/hmPayload.h index aa8fdfe6..14f8da75 100644 --- a/src/hm/hmPayload.h +++ b/src/hm/hmPayload.h @@ -12,6 +12,8 @@ #include "hmRadio.h" #include +#define HMS_TIMEOUT_SEC 30 + typedef struct { uint8_t txCmd; uint8_t txId; diff --git a/src/hm/hmRadio.h b/src/hm/hmRadio.h index 870ef457..cde5cba0 100644 --- a/src/hm/hmRadio.h +++ b/src/hm/hmRadio.h @@ -3,24 +3,20 @@ // Creative Commons - http://creativecommons.org/licenses/by-nc-sa/4.0/deed //----------------------------------------------------------------------------- -#ifndef __RADIO_H__ -#define __RADIO_H__ +#ifndef __HM_RADIO_H__ +#define __HM_RADIO_H__ #include "../utils/dbg.h" #include #include "../utils/crc.h" #include "../config/config.h" #include "SPI.h" +#include "radio.h" #define SPI_SPEED 1000000 #define RF_CHANNELS 5 -#define TX_REQ_INFO 0x15 -#define TX_REQ_DEVCONTROL 0x51 -#define ALL_FRAMES 0x80 -#define SINGLE_FRAME 0x81 - const char* const rf24AmpPowerNames[] = {"MIN", "LOW", "HIGH", "MAX"}; @@ -28,7 +24,7 @@ const char* const rf24AmpPowerNames[] = {"MIN", "LOW", "HIGH", "MAX"}; // HM Radio class //----------------------------------------------------------------------------- template -class HmRadio { +class HmRadio : public Radio { public: HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) { if(mSerialDebug) { @@ -349,4 +345,4 @@ class HmRadio { statistics_t *mStat; }; -#endif /*__RADIO_H__*/ +#endif /*__HM_RADIO_H__*/ diff --git a/src/hm/radio.h b/src/hm/radio.h new file mode 100644 index 00000000..0eb2df5f --- /dev/null +++ b/src/hm/radio.h @@ -0,0 +1,22 @@ +//----------------------------------------------------------------------------- +// 2023 Ahoy, https://github.com/lumpapu/ahoy +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/4.0/deed +//----------------------------------------------------------------------------- + +#ifndef __RADIO_H__ +#define __RADIO_H__ + +#define TX_REQ_INFO 0x15 +#define TX_REQ_DEVCONTROL 0x51 +#define ALL_FRAMES 0x80 +#define SINGLE_FRAME 0x81 + +// abstract radio interface +class Radio { + public: + virtual void sendControlPacket(uint64_t invId, uint8_t cmd, uint16_t *data, bool isRetransmit, bool isNoMI = true, bool is4chMI = false) = 0; + virtual void prepareDevInformCmd(uint64_t invId, uint8_t cmd, uint32_t ts, uint16_t alarmMesId, bool isRetransmit, uint8_t reqfld=TX_REQ_INFO) = 0; + virtual void sendCmdPacket(uint64_t invId, uint8_t mid, uint8_t pid, bool isRetransmit, bool appendCrc16=true) = 0; +}; + +#endif /*__RADIO_H__*/ diff --git a/src/hms/hmsPayload.h b/src/hms/hmsPayload.h index f63f38e4..d6f1232e 100644 --- a/src/hms/hmsPayload.h +++ b/src/hms/hmsPayload.h @@ -11,7 +11,7 @@ #include "../config/config.h" #include -#define HMS_TIMEOUT_SEC 30 // 30s * 1000 +#define HMS_TIMEOUT_SEC 30 typedef struct { uint8_t txCmd; @@ -103,9 +103,6 @@ class HmsPayload { } void ivSend(Inverter<> *iv, bool highPrio = false) { - if ((IV_HMS != iv->ivGen) && (IV_HMT != iv->ivGen)) // only process HMS inverters - return; - if(!highPrio) { if (mPayload[iv->id].requested) { if (!mPayload[iv->id].complete) @@ -237,9 +234,6 @@ class HmsPayload { if (NULL == iv) continue; // skip to next inverter - if ((IV_HMS != iv->ivGen) && (IV_HMT != iv->ivGen)) // only process HMS inverters - continue; // skip to next inverter - if ((mPayload[iv->id].txId != (TX_REQ_INFO + ALL_FRAMES)) && (0 != mPayload[iv->id].txId)) { // no processing needed if txId is not 0x95 mPayload[iv->id].complete = true; diff --git a/src/hms/hmsRadio.h b/src/hms/hmsRadio.h index 29f23236..c8cf480c 100644 --- a/src/hms/hmsRadio.h +++ b/src/hms/hmsRadio.h @@ -8,14 +8,10 @@ #include "../utils/dbg.h" #include "cmt2300a.h" - -#define U32_B3(val) ((uint8_t)((val >> 24) & 0xff)) -#define U32_B2(val) ((uint8_t)((val >> 16) & 0xff)) -#define U32_B1(val) ((uint8_t)((val >> 8) & 0xff)) -#define U32_B0(val) ((uint8_t)((val ) & 0xff)) +#include "../hm/radio.h" template -class CmtRadio { +class CmtRadio : public Radio { typedef SPI SpiType; typedef Cmt2300a CmtType; public: @@ -64,7 +60,7 @@ class CmtRadio { return mCmtAvail; } - void sendControlPacket(uint64_t ivId, uint8_t cmd, uint16_t *data, bool isRetransmit) { + void sendControlPacket(uint64_t ivId, uint8_t cmd, uint16_t *data, bool isRetransmit, bool isNoMI = true, bool is4chMI = false) { DPRINT(DBG_INFO, F("sendControlPacket cmd: 0x")); DBGHEXLN(cmd); initPacket(ivId, TX_REQ_DEVCONTROL, SINGLE_FRAME); @@ -106,7 +102,7 @@ class CmtRadio { sendPacket(24, isRetransmit); } - void sendCmdPacket(uint64_t ivId, uint8_t mid, uint8_t pid, bool isRetransmit) { + void sendCmdPacket(uint64_t ivId, uint8_t mid, uint8_t pid, bool isRetransmit, bool appendCrc16=true) { initPacket(ivId, mid, pid); sendPacket(10, isRetransmit); }