Added base classes for SystemConfigPara
This commit is contained in:
parent
6e251bf50a
commit
c28a532bf1
28
lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp
Normal file
28
lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include "SystemConfigParaCommand.h"
|
||||
#include "inverters/InverterAbstract.h"
|
||||
|
||||
SystemConfigParaCommand::SystemConfigParaCommand(uint64_t target_address, uint64_t router_address, time_t time)
|
||||
: MultiDataCommand(target_address, router_address)
|
||||
{
|
||||
setTime(time);
|
||||
setDataType(0x05);
|
||||
setTimeout(200);
|
||||
}
|
||||
|
||||
bool SystemConfigParaCommand::handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id)
|
||||
{
|
||||
// Check CRC of whole payload
|
||||
if (!MultiDataCommand::handleResponse(inverter, fragment, max_fragment_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Move all fragments into target buffer
|
||||
uint8_t offs = 0;
|
||||
inverter->SystemConfigPara()->clearBuffer();
|
||||
for (uint8_t i = 0; i < max_fragment_id; i++) {
|
||||
inverter->SystemConfigPara()->appendFragment(offs, fragment[i].fragment, fragment[i].len);
|
||||
offs += (fragment[i].len);
|
||||
}
|
||||
inverter->SystemConfigPara()->setLastUpdate(millis());
|
||||
return true;
|
||||
}
|
||||
10
lib/Hoymiles/src/commands/SystemConfigParaCommand.h
Normal file
10
lib/Hoymiles/src/commands/SystemConfigParaCommand.h
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "MultiDataCommand.h"
|
||||
|
||||
class SystemConfigParaCommand : public MultiDataCommand {
|
||||
public:
|
||||
SystemConfigParaCommand(uint64_t target_address = 0, uint64_t router_address = 0, time_t time = 0);
|
||||
|
||||
virtual bool handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id);
|
||||
};
|
||||
@ -4,6 +4,7 @@
|
||||
#include "commands/DevInfoAllCommand.h"
|
||||
#include "commands/DevInfoSampleCommand.h"
|
||||
#include "commands/RealTimeRunDataCommand.h"
|
||||
#include "commands/SystemConfigParaCommand.h"
|
||||
|
||||
HM_Abstract::HM_Abstract(uint64_t serial)
|
||||
: InverterAbstract(serial) {};
|
||||
@ -68,5 +69,22 @@ bool HM_Abstract::sendDevInfoRequest(HoymilesRadio* radio)
|
||||
cmdSample->setTime(now);
|
||||
cmdSample->setTargetAddress(serial());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HM_Abstract::sendSystemConfigParaRequest(HoymilesRadio* radio)
|
||||
{
|
||||
struct tm timeinfo;
|
||||
if (!getLocalTime(&timeinfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
time_t now;
|
||||
time(&now);
|
||||
|
||||
SystemConfigParaCommand* cmd = radio->enqueCommand<SystemConfigParaCommand>();
|
||||
cmd->setTime(now);
|
||||
cmd->setTargetAddress(serial());
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -8,6 +8,7 @@ public:
|
||||
bool sendStatsRequest(HoymilesRadio* radio);
|
||||
bool sendAlarmLogRequest(HoymilesRadio* radio);
|
||||
bool sendDevInfoRequest(HoymilesRadio* radio);
|
||||
bool sendSystemConfigParaRequest(HoymilesRadio* radio);
|
||||
|
||||
private:
|
||||
uint8_t _lastAlarmLogCnt = 0;
|
||||
|
||||
@ -8,6 +8,7 @@ InverterAbstract::InverterAbstract(uint64_t serial)
|
||||
_alarmLogParser.reset(new AlarmLogParser());
|
||||
_devInfoParser.reset(new DevInfoParser());
|
||||
_statisticsParser.reset(new StatisticsParser());
|
||||
_systemConfigParaParser.reset(new SystemConfigParaParser());
|
||||
}
|
||||
|
||||
void InverterAbstract::init()
|
||||
@ -54,6 +55,11 @@ StatisticsParser* InverterAbstract::Statistics()
|
||||
return _statisticsParser.get();
|
||||
}
|
||||
|
||||
SystemConfigParaParser* InverterAbstract::SystemConfigPara()
|
||||
{
|
||||
return _systemConfigParaParser.get();
|
||||
}
|
||||
|
||||
void InverterAbstract::clearRxFragmentBuffer()
|
||||
{
|
||||
memset(_rxFragmentBuffer, 0, MAX_RF_FRAGMENT_COUNT * sizeof(fragment_t));
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "../parser/AlarmLogParser.h"
|
||||
#include "../parser/StatisticsParser.h"
|
||||
#include "../parser/DevInfoParser.h"
|
||||
#include "../parser/StatisticsParser.h"
|
||||
#include "../parser/SystemConfigParaParser.h"
|
||||
#include "HoymilesRadio.h"
|
||||
#include "types.h"
|
||||
#include <Arduino.h>
|
||||
@ -44,6 +45,7 @@ public:
|
||||
AlarmLogParser* EventLog();
|
||||
DevInfoParser* DevInfo();
|
||||
StatisticsParser* Statistics();
|
||||
SystemConfigParaParser* SystemConfigPara();
|
||||
|
||||
private:
|
||||
serial_u _serial;
|
||||
@ -56,4 +58,5 @@ private:
|
||||
std::unique_ptr<AlarmLogParser> _alarmLogParser;
|
||||
std::unique_ptr<DevInfoParser> _devInfoParser;
|
||||
std::unique_ptr<StatisticsParser> _statisticsParser;
|
||||
std::unique_ptr<SystemConfigParaParser> _systemConfigParaParser;
|
||||
};
|
||||
23
lib/Hoymiles/src/parser/SystemConfigParaParser.cpp
Normal file
23
lib/Hoymiles/src/parser/SystemConfigParaParser.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "SystemConfigParaParser.h"
|
||||
#include <cstring>
|
||||
|
||||
void SystemConfigParaParser::clearBuffer()
|
||||
{
|
||||
memset(_payload, 0, SYSTEM_CONFIG_PARA_SIZE);
|
||||
_payloadLength = 0;
|
||||
}
|
||||
|
||||
void SystemConfigParaParser::appendFragment(uint8_t offset, uint8_t* payload, uint8_t len)
|
||||
{
|
||||
if (offset + len > (SYSTEM_CONFIG_PARA_SIZE)) {
|
||||
Serial.printf("FATAL: (%s, %d) stats packet too large for buffer\n", __FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
memcpy(&_payload[offset], payload, len);
|
||||
_payloadLength += len;
|
||||
}
|
||||
|
||||
float SystemConfigParaParser::getLimitPercent()
|
||||
{
|
||||
return ((((uint16_t)_payload[2]) << 8) | _payload[3]) / 10;
|
||||
}
|
||||
17
lib/Hoymiles/src/parser/SystemConfigParaParser.h
Normal file
17
lib/Hoymiles/src/parser/SystemConfigParaParser.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "Parser.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
#define SYSTEM_CONFIG_PARA_SIZE 16
|
||||
|
||||
class SystemConfigParaParser : public Parser {
|
||||
public:
|
||||
void clearBuffer();
|
||||
void appendFragment(uint8_t offset, uint8_t* payload, uint8_t len);
|
||||
|
||||
float getLimitPercent();
|
||||
|
||||
private:
|
||||
uint8_t _payload[SYSTEM_CONFIG_PARA_SIZE];
|
||||
uint8_t _payloadLength;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user