Move the whole stats request into the inverter class
This enables in future releases so send multiple requests for e.g. MI inverters
This commit is contained in:
parent
7a0394151a
commit
ab6261da92
@ -26,8 +26,7 @@ void HoymilesClass::loop()
|
|||||||
Serial.print(F("Fetch inverter: "));
|
Serial.print(F("Fetch inverter: "));
|
||||||
Serial.println(iv->serial());
|
Serial.println(iv->serial());
|
||||||
|
|
||||||
iv->clearRxFragmentBuffer();
|
iv->sendStatsRequest(_radio.get());
|
||||||
_radio->sendTimePacket(iv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++inverterPos >= getNumInverters()) {
|
if (++inverterPos >= getNumInverters()) {
|
||||||
|
|||||||
@ -273,14 +273,6 @@ bool HoymilesRadio::enqueTransaction(inverter_transaction_t* transaction)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HoymilesRadio::sendTimePacket(std::shared_ptr<InverterAbstract> iv)
|
|
||||||
{
|
|
||||||
inverter_transaction_t payload;
|
|
||||||
if (iv->getStatsRequest(&payload)) {
|
|
||||||
enqueTransaction(&payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HoymilesRadio::sendRetransmitPacket(uint8_t fragment_id)
|
void HoymilesRadio::sendRetransmitPacket(uint8_t fragment_id)
|
||||||
{
|
{
|
||||||
sendEsbPacket(_activeSerial, currentTransaction.mainCmd, (uint8_t)(0x80 + fragment_id), 0, 0, 60);
|
sendEsbPacket(_activeSerial, currentTransaction.mainCmd, (uint8_t)(0x80 + fragment_id), 0, 0, 60);
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include "CircularBuffer.h"
|
#include "CircularBuffer.h"
|
||||||
#include "TimeoutHelper.h"
|
#include "TimeoutHelper.h"
|
||||||
#include "inverters/InverterAbstract.h"
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include <RF24.h>
|
#include <RF24.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -26,7 +25,6 @@ public:
|
|||||||
|
|
||||||
bool isIdle();
|
bool isIdle();
|
||||||
void sendEsbPacket(serial_u target, uint8_t mainCmd, uint8_t subCmd, uint8_t payload[], uint8_t len, uint32_t timeout, bool resend = false);
|
void sendEsbPacket(serial_u target, uint8_t mainCmd, uint8_t subCmd, uint8_t payload[], uint8_t len, uint32_t timeout, bool resend = false);
|
||||||
void sendTimePacket(std::shared_ptr<InverterAbstract> iv);
|
|
||||||
void sendRetransmitPacket(uint8_t fragment_id);
|
void sendRetransmitPacket(uint8_t fragment_id);
|
||||||
void sendLastPacketAgain();
|
void sendLastPacketAgain();
|
||||||
bool enqueTransaction(inverter_transaction_t* transaction);
|
bool enqueTransaction(inverter_transaction_t* transaction);
|
||||||
|
|||||||
@ -5,28 +5,36 @@
|
|||||||
HM_Abstract::HM_Abstract(uint64_t serial)
|
HM_Abstract::HM_Abstract(uint64_t serial)
|
||||||
: InverterAbstract(serial) {};
|
: InverterAbstract(serial) {};
|
||||||
|
|
||||||
bool HM_Abstract::getStatsRequest(inverter_transaction_t* payload)
|
bool HM_Abstract::sendStatsRequest(HoymilesRadio* radio)
|
||||||
{
|
{
|
||||||
time_t now;
|
time_t now;
|
||||||
time(&now);
|
time(&now);
|
||||||
|
|
||||||
memset(payload->payload, 0, MAX_RF_PAYLOAD_SIZE);
|
inverter_transaction_t payload;
|
||||||
|
|
||||||
payload->target.u64 = serial();
|
memset(payload.payload, 0, MAX_RF_PAYLOAD_SIZE);
|
||||||
payload->mainCmd = 0x15;
|
|
||||||
payload->subCmd = 0x80;
|
|
||||||
payload->timeout = 200;
|
|
||||||
payload->len = 16;
|
|
||||||
|
|
||||||
payload->payload[0] = 0x0b;
|
payload.target.u64 = serial();
|
||||||
payload->payload[1] = 0x00;
|
payload.mainCmd = 0x15;
|
||||||
|
payload.subCmd = 0x80;
|
||||||
|
payload.timeout = 200;
|
||||||
|
payload.len = 16;
|
||||||
|
|
||||||
HoymilesRadio::u32CpyLittleEndian(&payload->payload[2], now); // sets the 4 following elements {2, 3, 4, 5}
|
payload.payload[0] = 0x0b;
|
||||||
payload->payload[9] = 0x05;
|
payload.payload[1] = 0x00;
|
||||||
|
|
||||||
uint16_t crc = crc16(&payload->payload[0], 14);
|
HoymilesRadio::u32CpyLittleEndian(&payload.payload[2], now); // sets the 4 following elements {2, 3, 4, 5}
|
||||||
payload->payload[14] = (crc >> 8) & 0xff;
|
payload.payload[9] = 0x05;
|
||||||
payload->payload[15] = (crc)&0xff;
|
|
||||||
|
|
||||||
return now > 0;
|
uint16_t crc = crc16(&payload.payload[0], 14);
|
||||||
|
payload.payload[14] = (crc >> 8) & 0xff;
|
||||||
|
payload.payload[15] = (crc)&0xff;
|
||||||
|
|
||||||
|
if (now > 0) {
|
||||||
|
clearRxFragmentBuffer();
|
||||||
|
radio->enqueTransaction(&payload);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
@ -5,5 +5,5 @@
|
|||||||
class HM_Abstract : public InverterAbstract {
|
class HM_Abstract : public InverterAbstract {
|
||||||
public:
|
public:
|
||||||
HM_Abstract(uint64_t serial);
|
HM_Abstract(uint64_t serial);
|
||||||
bool getStatsRequest(inverter_transaction_t* payload);
|
bool sendStatsRequest(HoymilesRadio* radio);
|
||||||
};
|
};
|
||||||
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "HoymilesRadio.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@ -111,7 +112,7 @@ public:
|
|||||||
const char* getChannelFieldUnit(uint8_t channel, uint8_t fieldId);
|
const char* getChannelFieldUnit(uint8_t channel, uint8_t fieldId);
|
||||||
const char* getChannelFieldName(uint8_t channel, uint8_t fieldId);
|
const char* getChannelFieldName(uint8_t channel, uint8_t fieldId);
|
||||||
|
|
||||||
virtual bool getStatsRequest(inverter_transaction_t* payload) = 0;
|
virtual bool sendStatsRequest(HoymilesRadio* radio) = 0;
|
||||||
uint32_t getLastStatsUpdate();
|
uint32_t getLastStatsUpdate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user