OpenDTU-old/include/PowerMeterSml.h
Bernhard Kirchen 75c07c17f2 powermeter refactor: SML lib: replace double by float
avoid additional conversions and avoid double for the fact that
calculations on type double are implemented in software, whereas
float is handled in hardware on ESP32.
2024-06-26 20:51:56 +02:00

41 lines
1.0 KiB
C++

// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <list>
#include <mutex>
#include <stdint.h>
#include <Arduino.h>
#include <HTTPClient.h>
#include "Configuration.h"
#include "PowerMeterProvider.h"
#include "sml.h"
class PowerMeterSml : public PowerMeterProvider {
public:
float getPowerTotal() const final;
void doMqttPublish() const final;
protected:
void processSmlByte(uint8_t byte);
private:
mutable std::mutex _mutex;
float _activePower = 0.0;
float _energyImport = 0.0;
float _energyExport = 0.0;
typedef struct {
uint8_t const OBIS[6];
void (*decoder)(float&);
float* target;
char const* name;
} OBISHandler;
const std::list<OBISHandler> smlHandlerList{
{{0x01, 0x00, 0x10, 0x07, 0x00, 0xff}, &smlOBISW, &_activePower, "active power"},
{{0x01, 0x00, 0x01, 0x08, 0x00, 0xff}, &smlOBISWh, &_energyImport, "energy import"},
{{0x01, 0x00, 0x02, 0x08, 0x00, 0xff}, &smlOBISWh, &_energyExport, "energy export"}
};
};