Domotique/WifiControlSensor/Teleinfo.ino

75 lines
1.6 KiB
C++

#ifdef CONFIG_ENABLE_TELEINFO
#include "Teleinfo.h"
#include <LibTeleinfo.h>
#define TELESerial Serial
TInfo tinfo;
int TeleinfoSetup()
{
TELESerial.begin(1200, SERIAL_7E1);
tinfo.init();
return 0;
}
int TeleinfoProcess(std::vector<struct mqttInfo> &batchInfo)
{
int c;
while ((c = TELESerial.read()) >= 0) {
tinfo.process(c);
}
ValueList *me = tinfo.getList();
if (me)
me = me->next;
while (me) {
if (strcmp(me->name, "IINST") == 0) {
float val = atof(me->value);
batchInfo.push_back({val, TELEINFO_IINST_FEED_FORMAT, 0, 0});
}
if (strcmp(me->name, "PAPP") == 0) {
float val = atof(me->value);
batchInfo.push_back({val, TELEINFO_PAPP_FEED_FORMAT, 0, 0});
}
if (strcmp(me->name, "BASE") == 0) {
float val = atof(me->value);
batchInfo.push_back({val, TELEINFO_BASE_FEED_FORMAT, 0, 0});
}
me = me->next;
}
return 0;
}
int TeleinfoProcess(float &iinst, float &papp, float &base,
std::vector<struct mqttInfo> &batchInfo)
{
int c;
while ((c = TELESerial.read()) >= 0) {
tinfo.process(c);
}
ValueList *me = tinfo.getList();
if (me)
me = me->next;
while (me) {
if (strcmp(me->name, "IINST") == 0) {
iinst = atof(me->value);
batchInfo.push_back({iinst, TELEINFO_IINST_FEED_FORMAT, 0, 0});
}
if (strcmp(me->name, "PAPP") == 0) {
papp = atof(me->value);
batchInfo.push_back({papp, TELEINFO_PAPP_FEED_FORMAT, 0, 0});
}
if (strcmp(me->name, "BASE") == 0) {
base = atof(me->value);
batchInfo.push_back({base, TELEINFO_BASE_FEED_FORMAT, 0, 0});
}
me = me->next;
}
return 0;
}
#endif