Browse Source

add radio interface radio.h

pull/1197/head
lumapu 2 years ago
parent
commit
1d28387d1d
  1. 2
      src/hm/hmPayload.h
  2. 14
      src/hm/hmRadio.h
  3. 22
      src/hm/radio.h
  4. 8
      src/hms/hmsPayload.h
  5. 12
      src/hms/hmsRadio.h

2
src/hm/hmPayload.h

@ -12,6 +12,8 @@
#include "hmRadio.h" #include "hmRadio.h"
#include <Arduino.h> #include <Arduino.h>
#define HMS_TIMEOUT_SEC 30
typedef struct { typedef struct {
uint8_t txCmd; uint8_t txCmd;
uint8_t txId; uint8_t txId;

14
src/hm/hmRadio.h

@ -3,24 +3,20 @@
// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/4.0/deed // Creative Commons - http://creativecommons.org/licenses/by-nc-sa/4.0/deed
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#ifndef __RADIO_H__ #ifndef __HM_RADIO_H__
#define __RADIO_H__ #define __HM_RADIO_H__
#include "../utils/dbg.h" #include "../utils/dbg.h"
#include <RF24.h> #include <RF24.h>
#include "../utils/crc.h" #include "../utils/crc.h"
#include "../config/config.h" #include "../config/config.h"
#include "SPI.h" #include "SPI.h"
#include "radio.h"
#define SPI_SPEED 1000000 #define SPI_SPEED 1000000
#define RF_CHANNELS 5 #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"}; const char* const rf24AmpPowerNames[] = {"MIN", "LOW", "HIGH", "MAX"};
@ -28,7 +24,7 @@ const char* const rf24AmpPowerNames[] = {"MIN", "LOW", "HIGH", "MAX"};
// HM Radio class // HM Radio class
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <uint8_t IRQ_PIN = DEF_NRF_IRQ_PIN, uint8_t CE_PIN = DEF_NRF_CE_PIN, uint8_t CS_PIN = DEF_NRF_CS_PIN, uint8_t AMP_PWR = RF24_PA_LOW, uint8_t SCLK_PIN = DEF_NRF_SCLK_PIN, uint8_t MOSI_PIN = DEF_NRF_MOSI_PIN, uint8_t MISO_PIN = DEF_NRF_MISO_PIN> template <uint8_t IRQ_PIN = DEF_NRF_IRQ_PIN, uint8_t CE_PIN = DEF_NRF_CE_PIN, uint8_t CS_PIN = DEF_NRF_CS_PIN, uint8_t AMP_PWR = RF24_PA_LOW, uint8_t SCLK_PIN = DEF_NRF_SCLK_PIN, uint8_t MOSI_PIN = DEF_NRF_MOSI_PIN, uint8_t MISO_PIN = DEF_NRF_MISO_PIN>
class HmRadio { class HmRadio : public Radio {
public: public:
HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) { HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) {
if(mSerialDebug) { if(mSerialDebug) {
@ -349,4 +345,4 @@ class HmRadio {
statistics_t *mStat; statistics_t *mStat;
}; };
#endif /*__RADIO_H__*/ #endif /*__HM_RADIO_H__*/

22
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__*/

8
src/hms/hmsPayload.h

@ -11,7 +11,7 @@
#include "../config/config.h" #include "../config/config.h"
#include <Arduino.h> #include <Arduino.h>
#define HMS_TIMEOUT_SEC 30 // 30s * 1000 #define HMS_TIMEOUT_SEC 30
typedef struct { typedef struct {
uint8_t txCmd; uint8_t txCmd;
@ -103,9 +103,6 @@ class HmsPayload {
} }
void ivSend(Inverter<> *iv, bool highPrio = false) { void ivSend(Inverter<> *iv, bool highPrio = false) {
if ((IV_HMS != iv->ivGen) && (IV_HMT != iv->ivGen)) // only process HMS inverters
return;
if(!highPrio) { if(!highPrio) {
if (mPayload[iv->id].requested) { if (mPayload[iv->id].requested) {
if (!mPayload[iv->id].complete) if (!mPayload[iv->id].complete)
@ -237,9 +234,6 @@ class HmsPayload {
if (NULL == iv) if (NULL == iv)
continue; // skip to next inverter 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)) { if ((mPayload[iv->id].txId != (TX_REQ_INFO + ALL_FRAMES)) && (0 != mPayload[iv->id].txId)) {
// no processing needed if txId is not 0x95 // no processing needed if txId is not 0x95
mPayload[iv->id].complete = true; mPayload[iv->id].complete = true;

12
src/hms/hmsRadio.h

@ -8,14 +8,10 @@
#include "../utils/dbg.h" #include "../utils/dbg.h"
#include "cmt2300a.h" #include "cmt2300a.h"
#include "../hm/radio.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))
template<class SPI, uint32_t DTU_SN = 0x81001765> template<class SPI, uint32_t DTU_SN = 0x81001765>
class CmtRadio { class CmtRadio : public Radio {
typedef SPI SpiType; typedef SPI SpiType;
typedef Cmt2300a<SpiType> CmtType; typedef Cmt2300a<SpiType> CmtType;
public: public:
@ -64,7 +60,7 @@ class CmtRadio {
return mCmtAvail; 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")); DPRINT(DBG_INFO, F("sendControlPacket cmd: 0x"));
DBGHEXLN(cmd); DBGHEXLN(cmd);
initPacket(ivId, TX_REQ_DEVCONTROL, SINGLE_FRAME); initPacket(ivId, TX_REQ_DEVCONTROL, SINGLE_FRAME);
@ -106,7 +102,7 @@ class CmtRadio {
sendPacket(24, isRetransmit); 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); initPacket(ivId, mid, pid);
sendPacket(10, isRetransmit); sendPacket(10, isRetransmit);
} }

Loading…
Cancel
Save