mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-12 00:02:53 +00:00
Restructuring to be able to include precompiled kmp lib
This commit is contained in:
parent
4407526d96
commit
8a4efd0047
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
.vs/
|
||||
.idea/
|
||||
[Dd]ebug/
|
||||
[Rr]elease/
|
||||
**/__vm/
|
||||
@ -18,5 +19,3 @@ platformio-user.ini
|
||||
node_modules
|
||||
/gui/dist
|
||||
/scripts/*dev
|
||||
/src/KmpCommunicator.cpp
|
||||
/src/KmpCommunicatorDefs.h
|
||||
|
||||
@ -18,6 +18,8 @@
|
||||
#include "SoftwareSerial.h"
|
||||
#endif
|
||||
|
||||
#include "KmpTalker.h"
|
||||
|
||||
class KmpCommunicator : public PassiveMeterCommunicator {
|
||||
public:
|
||||
#if defined(AMS_REMOTE_DEBUG)
|
||||
@ -25,19 +27,9 @@ public:
|
||||
#else
|
||||
KmpCommunicator(Stream* debugger) : PassiveMeterCommunicator(debugger) {};
|
||||
#endif
|
||||
void configure(MeterConfig&, Timezone*);
|
||||
void configure(MeterConfig&);
|
||||
bool loop();
|
||||
AmsData* getData(AmsData& meterState);
|
||||
|
||||
private:
|
||||
uint64_t lastUpdate = 0;
|
||||
uint8_t batch = 0;
|
||||
AmsData state;
|
||||
|
||||
bool readPacket();
|
||||
int16_t unwrapData(uint8_t *buf, DataParserContext &context);
|
||||
uint8_t stuff(uint8_t* buf, uint8_t len);
|
||||
uint8_t unstuff(uint8_t* buf, uint8_t len);
|
||||
void send(uint8_t* buf, uint8_t len);
|
||||
double convertvalue(uint32_t val, uint8_t unit, uint8_t siex);
|
||||
KmpTalker* talker = NULL;
|
||||
};
|
||||
22
lib/MeterCommunicators/include/KmpTalker.h
Normal file
22
lib/MeterCommunicators/include/KmpTalker.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <Stream.h>
|
||||
|
||||
struct KmpDataHolder {
|
||||
uint32_t activeImportPower = 0, reactiveImportPower = 0, activeExportPower = 0, reactiveExportPower = 0;
|
||||
float l1voltage = 0, l2voltage = 0, l3voltage = 0, l1current = 0, l2current = 0, l3current = 0;
|
||||
uint32_t l1activeImportPower = 0, l2activeImportPower = 0, l3activeImportPower = 0;
|
||||
uint32_t l1activeExportPower = 0, l2activeExportPower = 0, l3activeExportPower = 0;
|
||||
double l1activeImportCounter = 0, l2activeImportCounter = 0, l3activeImportCounter = 0;
|
||||
double l1activeExportCounter = 0, l2activeExportCounter = 0, l3activeExportCounter = 0;
|
||||
float powerFactor = 0, l1PowerFactor = 0, l2PowerFactor = 0, l3PowerFactor = 0;
|
||||
double activeImportCounter = 0, reactiveImportCounter = 0, activeExportCounter = 0, reactiveExportCounter = 0;
|
||||
uint16_t meterId;
|
||||
};
|
||||
|
||||
class KmpTalker {
|
||||
public:
|
||||
KmpTalker(Stream *hanSerial);
|
||||
bool loop();
|
||||
void getData(KmpDataHolder& data);
|
||||
};
|
||||
52
lib/MeterCommunicators/src/KmpCommunicator.cpp
Normal file
52
lib/MeterCommunicators/src/KmpCommunicator.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include "KmpCommunicator.h"
|
||||
#include "Uptime.h"
|
||||
#include "crc.h"
|
||||
#include "OBIScodes.h"
|
||||
|
||||
void KmpCommunicator::configure(MeterConfig& meterConfig) {
|
||||
this->meterConfig = meterConfig;
|
||||
this->configChanged = false;
|
||||
setupHanPort(meterConfig.baud, meterConfig.parity, meterConfig.invert, false);
|
||||
talker = new KmpTalker(hanSerial);
|
||||
}
|
||||
|
||||
bool KmpCommunicator::loop() {
|
||||
uint64_t now = millis64();
|
||||
return talker->loop();
|
||||
}
|
||||
|
||||
AmsData* KmpCommunicator::getData(AmsData& meterState) {
|
||||
KmpDataHolder kmpData;
|
||||
talker->getData(kmpData);
|
||||
AmsData* data = new AmsData();
|
||||
data->apply(OBIS_ACTIVE_IMPORT_COUNT, kmpData.activeImportCounter);
|
||||
data->apply(OBIS_ACTIVE_EXPORT_COUNT, kmpData.activeExportCounter);
|
||||
data->apply(OBIS_REACTIVE_IMPORT_COUNT, kmpData.reactiveImportCounter);
|
||||
data->apply(OBIS_REACTIVE_EXPORT_COUNT, kmpData.reactiveExportCounter);
|
||||
data->apply(OBIS_ACTIVE_IMPORT, kmpData.activeImportPower);
|
||||
data->apply(OBIS_ACTIVE_EXPORT, kmpData.activeExportPower);
|
||||
data->apply(OBIS_REACTIVE_IMPORT, kmpData.reactiveImportPower);
|
||||
data->apply(OBIS_REACTIVE_EXPORT, kmpData.reactiveExportPower);
|
||||
data->apply(OBIS_VOLTAGE_L1, kmpData.l1voltage);
|
||||
data->apply(OBIS_VOLTAGE_L2, kmpData.l2voltage);
|
||||
data->apply(OBIS_VOLTAGE_L3, kmpData.l3voltage);
|
||||
data->apply(OBIS_CURRENT_L1, kmpData.l1current);
|
||||
data->apply(OBIS_CURRENT_L2, kmpData.l2current);
|
||||
data->apply(OBIS_CURRENT_L3, kmpData.l3current);
|
||||
data->apply(OBIS_POWER_FACTOR_L1, kmpData.l1PowerFactor);
|
||||
data->apply(OBIS_POWER_FACTOR_L2, kmpData.l2PowerFactor);
|
||||
data->apply(OBIS_POWER_FACTOR_L3, kmpData.l3PowerFactor);
|
||||
data->apply(OBIS_POWER_FACTOR, kmpData.powerFactor);
|
||||
data->apply(OBIS_ACTIVE_IMPORT_L1, kmpData.l1activeImportPower);
|
||||
data->apply(OBIS_ACTIVE_IMPORT_L2, kmpData.l2activeImportPower);
|
||||
data->apply(OBIS_ACTIVE_IMPORT_L3, kmpData.l3activeImportPower);
|
||||
data->apply(OBIS_ACTIVE_EXPORT_L1, kmpData.l1activeExportPower);
|
||||
data->apply(OBIS_ACTIVE_EXPORT_L2, kmpData.l2activeExportPower);
|
||||
data->apply(OBIS_ACTIVE_EXPORT_L3, kmpData.l3activeExportPower);
|
||||
data->apply(OBIS_ACTIVE_IMPORT_COUNT_L1, kmpData.l1activeImportCounter);
|
||||
data->apply(OBIS_ACTIVE_IMPORT_COUNT_L2, kmpData.l2activeImportCounter);
|
||||
data->apply(OBIS_ACTIVE_IMPORT_COUNT_L3, kmpData.l3activeImportCounter);
|
||||
data->apply(OBIS_METER_ID, kmpData.meterId);
|
||||
data->apply(OBIS_NULL, AmsTypeKamstrup);
|
||||
return data;
|
||||
}
|
||||
12
lib/SvelteUi/app/dist/index.js
vendored
12
lib/SvelteUi/app/dist/index.js
vendored
File diff suppressed because one or more lines are too long
@ -353,6 +353,9 @@
|
||||
<select name="ma" bind:value={configuration.m.a} class="in-s">
|
||||
<option value={0}>{translations.conf?.meter?.comm?.passive ?? "Passive"}</option>
|
||||
<option value={2}>{translations.conf?.meter?.comm?.pulse ?? "Pulse"}</option>
|
||||
{#if sysinfo?.features?.includes('kmp')}
|
||||
<option value={9}>KMP</option>
|
||||
{/if}
|
||||
</select>
|
||||
</div>
|
||||
{#if configuration.m.a === 2}
|
||||
@ -851,7 +854,7 @@
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{#if configuration?.d}
|
||||
{#if configuration?.d && sysinfo?.features?.includes('rdebug')}
|
||||
<div class="cnt">
|
||||
<strong class="text-sm">{translations.conf?.debug?.title ?? "Debugging"}</strong>
|
||||
<a href="https://amsleser.no/blog/post/24-telnet-debug" target="_blank" class="float-right">ⓘ</a>
|
||||
|
||||
@ -64,5 +64,6 @@
|
||||
"p" : %.2f,
|
||||
"i" : %.2f
|
||||
},
|
||||
"clock_offset": %d
|
||||
"clock_offset": %d,
|
||||
"features": [%s]
|
||||
}
|
||||
@ -382,6 +382,15 @@ void AmsWebServer::sysinfoJson() {
|
||||
meterId.replace(F("\\"), F("\\\\"));
|
||||
|
||||
time_t now = time(nullptr);
|
||||
String features = "";
|
||||
#if defined(AMS_REMOTE_DEBUG)
|
||||
if(!features.isEmpty()) features += ",";
|
||||
features += "\"rdebug\"";
|
||||
#endif
|
||||
#if defined(AMS_KMP)
|
||||
if(!features.isEmpty()) features += ",";
|
||||
features += "\"kmp\"";
|
||||
#endif
|
||||
|
||||
int size = snprintf_P(buf, BufferSize, SYSINFO_JSON,
|
||||
FirmwareVersion::VersionString,
|
||||
@ -465,7 +474,8 @@ void AmsWebServer::sysinfoJson() {
|
||||
ea->getCostLastMonth(),
|
||||
ea->getProducedLastMonth(),
|
||||
ea->getIncomeLastMonth(),
|
||||
tz == NULL ? 0 : (tz->toLocal(now)-now)/3600
|
||||
tz == NULL ? 0 : (tz->toLocal(now)-now)/3600,
|
||||
features.c_str()
|
||||
);
|
||||
|
||||
stripNonAscii((uint8_t*) buf, size+1);
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
extra_configs = platformio-user.ini
|
||||
|
||||
[common]
|
||||
lib_deps = EEPROM, LittleFS, DNSServer, 256dpi/MQTT@2.5.2, OneWireNg@0.10.0, DallasTemperature@3.9.1, https://github.com/gskjold/RemoteDebug.git, Time@1.6.1, Timezone@1.2.4, FirmwareVersion, AmsConfiguration, AmsData, AmsDataStorage, HwTools, Uptime, AmsDecoder, PriceService, EnergyAccounting, AmsMqttHandler, RawMqttHandler, JsonMqttHandler, DomoticzMqttHandler, HomeAssistantMqttHandler, RealtimePlot, ConnectionHandler
|
||||
lib_deps = EEPROM, LittleFS, DNSServer, 256dpi/MQTT@2.5.2, OneWireNg@0.10.0, DallasTemperature@3.9.1, https://github.com/gskjold/RemoteDebug.git, Time@1.6.1, Timezone@1.2.4, FirmwareVersion, AmsConfiguration, AmsData, AmsDataStorage, HwTools, Uptime, AmsDecoder, PriceService, EnergyAccounting, AmsMqttHandler, RawMqttHandler, JsonMqttHandler, DomoticzMqttHandler, HomeAssistantMqttHandler, PassthroughMqttHandler, RealtimePlot, ConnectionHandler, MeterCommunicators
|
||||
lib_ignore = OneWire
|
||||
extra_scripts =
|
||||
pre:scripts/addversion.py
|
||||
|
||||
BIN
precompiled/esp32/libKmpTalker.a
Normal file
BIN
precompiled/esp32/libKmpTalker.a
Normal file
Binary file not shown.
BIN
precompiled/esp32c3/libKmpTalker.a
Normal file
BIN
precompiled/esp32c3/libKmpTalker.a
Normal file
Binary file not shown.
BIN
precompiled/esp32s2/libKmpTalker.a
Normal file
BIN
precompiled/esp32s2/libKmpTalker.a
Normal file
Binary file not shown.
BIN
precompiled/esp32s3/libKmpTalker.a
Normal file
BIN
precompiled/esp32s3/libKmpTalker.a
Normal file
Binary file not shown.
BIN
precompiled/esp8266/libKmpTalker.a
Normal file
BIN
precompiled/esp8266/libKmpTalker.a
Normal file
Binary file not shown.
@ -196,6 +196,7 @@ KmpCommunicator* kmpMc = NULL;
|
||||
#endif
|
||||
PulseMeterCommunicator* pulseMc = NULL;
|
||||
|
||||
|
||||
bool networkConnected = false;
|
||||
bool setupMode = false;
|
||||
|
||||
@ -800,7 +801,7 @@ void loop() {
|
||||
if(kmpMc == NULL) {
|
||||
kmpMc = new KmpCommunicator(&Debug);
|
||||
}
|
||||
kmpMc->configure(meterConfig, tz);
|
||||
kmpMc->configure(meterConfig);
|
||||
hwSerial = kmpMc->getHwSerial();
|
||||
mc = kmpMc;
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user