Add very simple method differ between requests

The last request is required to use the right parser for the received payload as the package type is not encoded in the received data
This commit is contained in:
Thomas Basler 2022-06-30 21:14:58 +02:00
parent b2271373a4
commit c4e911cecf
3 changed files with 30 additions and 8 deletions

View File

@ -37,5 +37,6 @@ bool HM_Abstract::sendStatsRequest(HoymilesRadio* radio)
clearRxFragmentBuffer();
radio->enqueTransaction(&payload);
setLastRequest(RequestType::Stats);
return true;
}

View File

@ -104,15 +104,16 @@ uint8_t InverterAbstract::verifyAllFragments()
return FRAGMENT_CRC_ERROR;
}
// todo: hier muss noch ein check bzgl. packet type usw rein (ist ja nicht alles statistik)
// Move all fragments into target buffer
memset(_payloadStats, 0, MAX_RF_FRAGMENT_COUNT * MAX_RF_PAYLOAD_SIZE);
uint8_t offs = 0;
for (uint8_t i = 0; i < _rxFragmentMaxPacketId; i++) {
memcpy(&_payloadStats[offs], _rxFragmentBuffer[i].fragment, _rxFragmentBuffer[i].len);
offs += (_rxFragmentBuffer[i].len);
if (getLastRequest() == RequestType::Stats) {
// Move all fragments into target buffer
memset(_payloadStats, 0, MAX_RF_FRAGMENT_COUNT * MAX_RF_PAYLOAD_SIZE);
uint8_t offs = 0;
for (uint8_t i = 0; i < _rxFragmentMaxPacketId; i++) {
memcpy(&_payloadStats[offs], _rxFragmentBuffer[i].fragment, _rxFragmentBuffer[i].len);
offs += (_rxFragmentBuffer[i].len);
}
_lastStatsUpdate = millis();
}
_lastStatsUpdate = millis();
return FRAGMENT_OK;
}
@ -122,6 +123,16 @@ uint32_t InverterAbstract::getLastStatsUpdate()
return _lastStatsUpdate;
}
void InverterAbstract::setLastRequest(RequestType request)
{
_lastRequest = request;
}
RequestType InverterAbstract::getLastRequest()
{
return _lastRequest;
}
uint8_t InverterAbstract::getChannelCount()
{
const byteAssign_t* b = getByteAssignment();

View File

@ -66,6 +66,10 @@ enum {
FRAGMENT_OK = 0
};
enum class RequestType {
Stats
};
typedef struct {
uint8_t fieldId; // field id
uint8_t unitId; // uint id
@ -130,6 +134,10 @@ public:
virtual bool sendStatsRequest(HoymilesRadio* radio) = 0;
uint32_t getLastStatsUpdate();
protected:
void setLastRequest(RequestType request);
RequestType getLastRequest();
private:
serial_u _serial;
char _name[MAX_NAME_LENGTH];
@ -141,4 +149,6 @@ private:
uint8_t _payloadStats[MAX_RF_FRAGMENT_COUNT * MAX_RF_PAYLOAD_SIZE];
uint32_t _lastStatsUpdate = 0;
uint16_t _chanMaxPower[CH4];
RequestType _lastRequest;
};