2021-02-18 15:51:49 +01:00
|
|
|
#ifdef CONFIG_ENABLE_TELEINFO
|
|
|
|
#include "Teleinfo.h"
|
|
|
|
#include <LibTeleinfo.h>
|
2022-09-10 21:53:06 +02:00
|
|
|
#define TELESerial Serial
|
2021-02-18 15:51:49 +01:00
|
|
|
TInfo tinfo;
|
|
|
|
|
2021-02-18 23:50:54 +01:00
|
|
|
int TeleinfoSetup()
|
|
|
|
{
|
2022-09-10 21:53:06 +02:00
|
|
|
TELESerial.begin(1200, SERIAL_7E1);
|
2021-02-18 15:51:49 +01:00
|
|
|
|
|
|
|
tinfo.init();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-02-18 23:50:54 +01:00
|
|
|
int TeleinfoProcess(std::vector<struct mqttInfo> &batchInfo)
|
|
|
|
{
|
2021-02-18 15:51:49 +01:00
|
|
|
int c;
|
|
|
|
|
2022-09-10 21:53:06 +02:00
|
|
|
while ((c = TELESerial.read()) >= 0) {
|
2021-02-18 15:51:49 +01:00
|
|
|
tinfo.process(c);
|
|
|
|
}
|
2021-02-18 23:50:54 +01:00
|
|
|
ValueList *me = tinfo.getList();
|
|
|
|
if (me)
|
|
|
|
me = me->next;
|
2021-02-18 15:51:49 +01:00
|
|
|
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});
|
|
|
|
}
|
2021-02-18 23:50:54 +01:00
|
|
|
if (strcmp(me->name, "BASE") == 0) {
|
|
|
|
float val = atof(me->value);
|
|
|
|
batchInfo.push_back({val, TELEINFO_BASE_FEED_FORMAT, 0, 0});
|
|
|
|
}
|
2021-02-18 15:51:49 +01:00
|
|
|
me = me->next;
|
|
|
|
}
|
2022-09-10 21:53:06 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TeleinfoProcess(float &iinst, float &papp, float &base )
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
if (strcmp(me->name, "PAPP") == 0) {
|
|
|
|
papp = atof(me->value);
|
|
|
|
}
|
|
|
|
if (strcmp(me->name, "BASE") == 0) {
|
|
|
|
base = atof(me->value);
|
|
|
|
}
|
|
|
|
me = me->next;
|
|
|
|
}
|
2021-02-18 15:51:49 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|