|
@ -1,3 +1,8 @@ |
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
// 2023 Ahoy, https://ahoydtu.de
|
|
|
|
|
|
// Creative Commons - https://creativecommons.org/licenses/by-nc-sa/4.0/deed
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
#ifndef __PUB_MQTT_IV_DATA_H__ |
|
|
#ifndef __PUB_MQTT_IV_DATA_H__ |
|
|
#define __PUB_MQTT_IV_DATA_H__ |
|
|
#define __PUB_MQTT_IV_DATA_H__ |
|
|
|
|
|
|
|
@ -10,12 +15,14 @@ typedef std::function<void(const char *subTopic, const char *payload, bool retai |
|
|
template<class HMSYSTEM> |
|
|
template<class HMSYSTEM> |
|
|
class PubMqttIvData { |
|
|
class PubMqttIvData { |
|
|
public: |
|
|
public: |
|
|
void setup(HMSYSTEM *sys, uint32_t *utcTs) { |
|
|
void setup(HMSYSTEM *sys, uint32_t *utcTs, std::queue<uint8_t> *sendList) { |
|
|
mSys = sys; |
|
|
mSys = sys; |
|
|
mUtcTimestamp = utcTs; |
|
|
mUtcTimestamp = utcTs; |
|
|
|
|
|
mSendList = sendList; |
|
|
mState = IDLE; |
|
|
mState = IDLE; |
|
|
|
|
|
|
|
|
memset(mIvLastRTRpub, 0, MAX_NUM_INVERTERS * 4); |
|
|
memset(mIvLastRTRpub, 0, MAX_NUM_INVERTERS * 4); |
|
|
|
|
|
mRTRDataHasBeenSent = false; |
|
|
|
|
|
|
|
|
mTable[IDLE] = &PubMqttIvData::stateIdle; |
|
|
mTable[IDLE] = &PubMqttIvData::stateIdle; |
|
|
mTable[START] = &PubMqttIvData::stateStart; |
|
|
mTable[START] = &PubMqttIvData::stateStart; |
|
@ -29,11 +36,11 @@ class PubMqttIvData { |
|
|
yield(); |
|
|
yield(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool start(uint8_t cmd) { |
|
|
bool start(void) { |
|
|
if(IDLE != mState) |
|
|
if(IDLE != mState) |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
|
mCmd = cmd; |
|
|
mRTRDataHasBeenSent = false; |
|
|
mState = START; |
|
|
mState = START; |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
@ -52,10 +59,17 @@ class PubMqttIvData { |
|
|
|
|
|
|
|
|
void stateStart() { |
|
|
void stateStart() { |
|
|
mLastIvId = 0; |
|
|
mLastIvId = 0; |
|
|
|
|
|
if(!mSendList->empty()) { |
|
|
|
|
|
mCmd = mSendList->front(); |
|
|
|
|
|
|
|
|
|
|
|
if((RealTimeRunData_Debug != mCmd) || !mRTRDataHasBeenSent) { |
|
|
mSendTotals = (RealTimeRunData_Debug == mCmd); |
|
|
mSendTotals = (RealTimeRunData_Debug == mCmd); |
|
|
memset(mTotal, 0, sizeof(float) * 4); |
|
|
memset(mTotal, 0, sizeof(float) * 4); |
|
|
|
|
|
|
|
|
mState = FIND_NXT_IV; |
|
|
mState = FIND_NXT_IV; |
|
|
|
|
|
} else |
|
|
|
|
|
mSendList->pop(); |
|
|
|
|
|
} else |
|
|
|
|
|
mState = IDLE; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void stateFindNxtIv() { |
|
|
void stateFindNxtIv() { |
|
@ -159,10 +173,12 @@ class PubMqttIvData { |
|
|
snprintf(mVal, 40, "%g", ah::round3(mTotal[mPos])); |
|
|
snprintf(mVal, 40, "%g", ah::round3(mTotal[mPos])); |
|
|
mPublish(mSubTopic, mVal, retained); |
|
|
mPublish(mSubTopic, mVal, retained); |
|
|
mPos++; |
|
|
mPos++; |
|
|
} else |
|
|
} else { |
|
|
mState = IDLE; |
|
|
mSendList->pop(); |
|
|
|
|
|
mState = START; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
RTRDataHasBeenSent = true; |
|
|
mRTRDataHasBeenSent = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
HMSYSTEM *mSys; |
|
|
HMSYSTEM *mSys; |
|
@ -179,9 +195,12 @@ class PubMqttIvData { |
|
|
Inverter<> *mIv; |
|
|
Inverter<> *mIv; |
|
|
uint8_t mPos; |
|
|
uint8_t mPos; |
|
|
uint32_t mIvLastRTRpub[MAX_NUM_INVERTERS]; |
|
|
uint32_t mIvLastRTRpub[MAX_NUM_INVERTERS]; |
|
|
|
|
|
bool mRTRDataHasBeenSent; |
|
|
|
|
|
|
|
|
char mSubTopic[32 + MAX_NAME_LENGTH + 1]; |
|
|
char mSubTopic[32 + MAX_NAME_LENGTH + 1]; |
|
|
char mVal[40]; |
|
|
char mVal[40]; |
|
|
|
|
|
|
|
|
|
|
|
std::queue<uint8_t> *mSendList; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
#endif /*__PUB_MQTT_IV_DATA_H__*/ |
|
|
#endif /*__PUB_MQTT_IV_DATA_H__*/ |
|
|