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(); clearRxFragmentBuffer();
radio->enqueTransaction(&payload); radio->enqueTransaction(&payload);
setLastRequest(RequestType::Stats);
return true; return true;
} }

View File

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

View File

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