mirror of https://github.com/lumapu/ahoy.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
2.0 KiB
53 lines
2.0 KiB
//-----------------------------------------------------------------------------
|
|
// 2024 Ahoy, https://github.com/lumpapu/ahoy
|
|
// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/4.0/deed
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#ifndef __PUB_SERIAL_H__
|
|
#define __PUB_SERIAL_H__
|
|
|
|
#include "../utils/dbg.h"
|
|
#include "../config/settings.h"
|
|
#include "../hm/hmSystem.h"
|
|
|
|
template<class HMSYSTEM>
|
|
class PubSerial {
|
|
public:
|
|
void setup(settings_t *cfg, HMSYSTEM *sys, uint32_t *utcTs) {
|
|
mCfg = cfg;
|
|
mSys = sys;
|
|
mUtcTimestamp = utcTs;
|
|
}
|
|
|
|
void tick(void) {
|
|
if (mCfg->serial.showIv) {
|
|
char topic[32 + MAX_NAME_LENGTH], val[40];
|
|
for (uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
|
Inverter<> *iv = mSys->getInverterByPos(id);
|
|
if (NULL != iv) {
|
|
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
|
if (iv->isAvailable()) {
|
|
DPRINTLN(DBG_INFO, "Iv: " + String(id));
|
|
for (uint8_t i = 0; i < rec->length; i++) {
|
|
if (0.0f != iv->getValue(i, rec)) {
|
|
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/ch%d/%s", iv->config->name, rec->assign[i].ch, iv->getFieldName(i, rec));
|
|
snprintf(val, 40, "%.3f %s", iv->getValue(i, rec), iv->getUnit(i, rec));
|
|
DPRINTLN(DBG_INFO, String(topic) + ": " + String(val));
|
|
}
|
|
yield();
|
|
}
|
|
DPRINTLN(DBG_INFO, "");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private:
|
|
settings_t *mCfg = nullptr;
|
|
HMSYSTEM *mSys = nullptr;
|
|
uint32_t *mUtcTimestamp = nullptr;
|
|
};
|
|
|
|
|
|
#endif /*__PUB_SERIAL_H__*/
|
|
|