Set MaxChannel Power on startup and in webapi

This commit is contained in:
Thomas Basler 2022-06-22 21:12:45 +02:00
parent 10974ade3e
commit 746aa087ac
4 changed files with 24 additions and 4 deletions

View File

@ -136,8 +136,14 @@ uint8_t InverterAbstract::getChannelCount()
uint16_t InverterAbstract::getChannelMaxPower(uint8_t channel)
{
// todo;
return 0;
return _chanMaxPower[channel];
}
void InverterAbstract::setChannelMaxPower(uint8_t channel, uint16_t power)
{
if (channel < CH4) {
_chanMaxPower[channel] = power;
}
}
uint8_t InverterAbstract::getAssignIdxByChannelField(uint8_t channel, uint8_t fieldId)

View File

@ -99,6 +99,7 @@ public:
virtual const uint8_t getAssignmentCount() = 0;
uint8_t getChannelCount();
uint16_t getChannelMaxPower(uint8_t channel);
void setChannelMaxPower(uint8_t channel, uint16_t power);
void clearRxFragmentBuffer();
void addRxFragment(uint8_t fragment[], uint8_t len);
@ -122,4 +123,5 @@ private:
uint8_t _payloadStats[MAX_RF_FRAGMENT_COUNT * MAX_RF_PAYLOAD_SIZE];
uint32_t _lastStatsUpdate = 0;
uint16_t _chanMaxPower[CH4];
};

View File

@ -130,7 +130,11 @@ void WebApiInverterClass::onInverterAdd(AsyncWebServerRequest* request)
response->setLength();
request->send(response);
Hoymiles.addInverter(inverter->Name, inverter->Serial);
auto inv = Hoymiles.addInverter(inverter->Name, inverter->Serial);
for (uint8_t c = 0; c < INV_MAX_CHAN_COUNT; c++) {
inv->setChannelMaxPower(c, inverter->MaxChannelPower[c]);
}
}
void WebApiInverterClass::onInverterEdit(AsyncWebServerRequest* request)
@ -210,6 +214,10 @@ void WebApiInverterClass::onInverterEdit(AsyncWebServerRequest* request)
std::shared_ptr<InverterAbstract> inv = Hoymiles.getInverterByPos(root[F("id")].as<uint64_t>());
inv->setName(inverter.Name);
inv->setSerial(inverter.Serial);
for (uint8_t c = 0; c < INV_MAX_CHAN_COUNT; c++) {
inv->setChannelMaxPower(c, inverter.MaxChannelPower[c]);
}
}
void WebApiInverterClass::onInverterDelete(AsyncWebServerRequest* request)

View File

@ -80,9 +80,13 @@ void setup()
for (uint8_t i = 0; i < INV_MAX_COUNT; i++) {
if (config.Inverter[i].Serial > 0) {
Hoymiles.addInverter(
auto inv = Hoymiles.addInverter(
config.Inverter[i].Name,
config.Inverter[i].Serial);
for (uint8_t c = 0; c < INV_MAX_CHAN_COUNT; c++) {
inv->setChannelMaxPower(c, config.Inverter[i].MaxChannelPower[c]);
}
}
}
Serial.println(F("done"));