mirror of
https://github.com/lumapu/ahoy.git
synced 2025-06-15 09:01:38 +02:00
added CmtRadio to app
This commit is contained in:
parent
6cbd256c1f
commit
5525d25e4b
3 changed files with 37 additions and 8 deletions
28
src/app.cpp
28
src/app.cpp
|
@ -40,6 +40,12 @@ void app::setup() {
|
||||||
mNrfRadio.setup(mConfig->nrf.amplifierPower, mConfig->nrf.pinIrq, mConfig->nrf.pinCe, mConfig->nrf.pinCs);
|
mNrfRadio.setup(mConfig->nrf.amplifierPower, mConfig->nrf.pinIrq, mConfig->nrf.pinCe, mConfig->nrf.pinCs);
|
||||||
mNrfRadio.enableDebug();
|
mNrfRadio.enableDebug();
|
||||||
}
|
}
|
||||||
|
#if defined(ESP32)
|
||||||
|
if(mConfig->cmt.enabled) {
|
||||||
|
mCmtRadio.setup();
|
||||||
|
mCmtRadio.enableDebug();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(AP_ONLY)
|
#if defined(AP_ONLY)
|
||||||
mInnerLoopCb = std::bind(&app::loopStandard, this);
|
mInnerLoopCb = std::bind(&app::loopStandard, this);
|
||||||
|
@ -67,7 +73,7 @@ void app::setup() {
|
||||||
DBGPRINTLN(String(ESP.getHeapFragmentation()));
|
DBGPRINTLN(String(ESP.getHeapFragmentation()));
|
||||||
DBGPRINTLN(String(ESP.getMaxFreeBlockSize()));*/
|
DBGPRINTLN(String(ESP.getMaxFreeBlockSize()));*/
|
||||||
|
|
||||||
if(!mNrfRadio.isChipConnected())
|
if(!mNrfRadio.isChipConnected() && mConfig->nrf.enabled)
|
||||||
DPRINTLN(DBG_WARN, F("WARNING! your NRF24 module can't be reached, check the wiring"));
|
DPRINTLN(DBG_WARN, F("WARNING! your NRF24 module can't be reached, check the wiring"));
|
||||||
|
|
||||||
// when WiFi is in client mode, then enable mqtt broker
|
// when WiFi is in client mode, then enable mqtt broker
|
||||||
|
@ -137,6 +143,22 @@ void app::loopStandard(void) {
|
||||||
mPayload.process(true);
|
mPayload.process(true);
|
||||||
mMiPayload.process(true);
|
mMiPayload.process(true);
|
||||||
}
|
}
|
||||||
|
#if defined(ESP32)
|
||||||
|
if (mCmtRadio.loop()) {
|
||||||
|
while (!mCmtRadio.mBufCtrl.empty()) {
|
||||||
|
hmsPacket_t *p = &mCmtRadio.mBufCtrl.front();
|
||||||
|
if (mConfig->serial.debug) {
|
||||||
|
DPRINT(DBG_INFO, F("RX "));
|
||||||
|
DBGPRINT(String(p->data[0]));
|
||||||
|
DBGPRINT(F("RSSI "));
|
||||||
|
DBGPRINT(String(p->rssi));
|
||||||
|
DBGPRINT(F("dBm | "));
|
||||||
|
ah::dumpBuf(&p->data[1], p->data[0]);
|
||||||
|
}
|
||||||
|
mCmtRadio.mBufCtrl.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
mPayload.loop();
|
mPayload.loop();
|
||||||
mMiPayload.loop();
|
mMiPayload.loop();
|
||||||
|
|
||||||
|
@ -158,6 +180,10 @@ void app::onWifi(bool gotIp) {
|
||||||
if (gotIp) {
|
if (gotIp) {
|
||||||
mInnerLoopCb = std::bind(&app::loopStandard, this);
|
mInnerLoopCb = std::bind(&app::loopStandard, this);
|
||||||
every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval, "tSend");
|
every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval, "tSend");
|
||||||
|
#if defined(ESP32)
|
||||||
|
if(mConfig->cmt.enabled)
|
||||||
|
everySec(std::bind(&CmtRadioType::tickSecond, mCmtRadio), "tsCmt");
|
||||||
|
#endif
|
||||||
mMqttReconnect = true;
|
mMqttReconnect = true;
|
||||||
mSunrise = 0; // needs to be set to 0, to reinstall sunrise and ivComm tickers!
|
mSunrise = 0; // needs to be set to 0, to reinstall sunrise and ivComm tickers!
|
||||||
once(std::bind(&app::tickNtpUpdate, this), 2, "ntp2");
|
once(std::bind(&app::tickNtpUpdate, this), 2, "ntp2");
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#define ASIN(x) (degrees(asin(x)))
|
#define ASIN(x) (degrees(asin(x)))
|
||||||
#define ACOS(x) (degrees(acos(x)))
|
#define ACOS(x) (degrees(acos(x)))
|
||||||
|
|
||||||
|
typedef CmtRadio<esp32_3wSpi<>> CmtRadioType;
|
||||||
typedef HmSystem<MAX_NUM_INVERTERS> HmSystemType;
|
typedef HmSystem<MAX_NUM_INVERTERS> HmSystemType;
|
||||||
typedef HmPayload<HmSystemType, HmRadio<>> PayloadType;
|
typedef HmPayload<HmSystemType, HmRadio<>> PayloadType;
|
||||||
typedef MiPayload<HmSystemType, HmRadio<>> MiPayloadType;
|
typedef MiPayload<HmSystemType, HmRadio<>> MiPayloadType;
|
||||||
|
@ -67,7 +68,7 @@ class app : public IApp, public ah::Scheduler {
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleHmsIntr(void) {
|
void handleHmsIntr(void) {
|
||||||
//mSys.Radio.handleHmsIntr();
|
mCmtRadio.handleIntr();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getUptime() {
|
uint32_t getUptime() {
|
||||||
|
@ -213,6 +214,7 @@ class app : public IApp, public ah::Scheduler {
|
||||||
|
|
||||||
HmSystemType mSys;
|
HmSystemType mSys;
|
||||||
HmRadio<> mNrfRadio;
|
HmRadio<> mNrfRadio;
|
||||||
|
CmtRadioType mCmtRadio;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::function<void()> innerLoopCb;
|
typedef std::function<void()> innerLoopCb;
|
||||||
|
|
|
@ -20,18 +20,18 @@ typedef struct {
|
||||||
#define U32_B0(val) ((uint8_t)((val ) & 0xff))
|
#define U32_B0(val) ((uint8_t)((val ) & 0xff))
|
||||||
|
|
||||||
template<class SPI, uint32_t DTU_SN = 0x87654321>
|
template<class SPI, uint32_t DTU_SN = 0x87654321>
|
||||||
class HmsRadio {
|
class CmtRadio {
|
||||||
typedef SPI SpiType;
|
typedef SPI SpiType;
|
||||||
typedef Cmt2300a<SpiType> CmtType;
|
typedef Cmt2300a<SpiType> CmtType;
|
||||||
public:
|
public:
|
||||||
HmsRadio() {
|
CmtRadio() {
|
||||||
mDtuSn = DTU_SN;
|
mDtuSn = DTU_SN;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup(bool genDtuSn = true) {
|
void setup(bool genDtuSn = true) {
|
||||||
if(genDtuSn)
|
if(genDtuSn)
|
||||||
generateDtuSn();
|
generateDtuSn();
|
||||||
if(!mCmt.resetCMT())
|
if(!mCmt.reset())
|
||||||
DPRINTLN(DBG_WARN, F("Initializing CMT2300A failed!"));
|
DPRINTLN(DBG_WARN, F("Initializing CMT2300A failed!"));
|
||||||
else
|
else
|
||||||
mCmt.goRx();
|
mCmt.goRx();
|
||||||
|
@ -43,13 +43,14 @@ class HmsRadio {
|
||||||
mIrqRcvd = false;
|
mIrqRcvd = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
bool loop() {
|
||||||
mCmt.loop();
|
mCmt.loop();
|
||||||
if(!mIrqRcvd)
|
if(!mIrqRcvd)
|
||||||
return;
|
return false;
|
||||||
mIrqRcvd = false;
|
mIrqRcvd = false;
|
||||||
getRx();
|
getRx();
|
||||||
mCmt.goRx();
|
mCmt.goRx();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tickSecond() {
|
void tickSecond() {
|
||||||
|
@ -57,7 +58,7 @@ class HmsRadio {
|
||||||
prepareSwitchChannelCmd(mIvIdChannelSet);
|
prepareSwitchChannelCmd(mIvIdChannelSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handeIntr(void) {
|
void handleIntr(void) {
|
||||||
mIrqRcvd = true;
|
mIrqRcvd = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue