mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-14 04:04:28 +05:00
refactor: minor changes
This commit is contained in:
@@ -70,50 +70,89 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sendBoilerReset() {
|
inline auto sendBoilerReset() {
|
||||||
unsigned int data = 1;
|
return this->sendRequestCode(1);
|
||||||
data <<= 8;
|
|
||||||
unsigned long response = this->sendRequest(buildRequest(
|
|
||||||
OpenThermMessageType::WRITE_DATA,
|
|
||||||
OpenThermMessageID::RemoteRequest,
|
|
||||||
data
|
|
||||||
));
|
|
||||||
|
|
||||||
return isValidResponse(response) && isValidResponseId(response, OpenThermMessageID::RemoteRequest);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sendServiceReset() {
|
inline auto sendServiceReset() {
|
||||||
unsigned int data = 10;
|
return this->sendRequestCode(10);
|
||||||
data <<= 8;
|
|
||||||
unsigned long response = this->sendRequest(buildRequest(
|
|
||||||
OpenThermMessageType::WRITE_DATA,
|
|
||||||
OpenThermMessageID::RemoteRequest,
|
|
||||||
data
|
|
||||||
));
|
|
||||||
|
|
||||||
return isValidResponse(response) && isValidResponseId(response, OpenThermMessageID::RemoteRequest);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sendWaterFilling() {
|
inline auto sendWaterFilling() {
|
||||||
unsigned int data = 2;
|
return this->sendRequestCode(2);
|
||||||
data <<= 8;
|
}
|
||||||
|
|
||||||
|
bool sendRequestCode(const uint8_t requestCode) {
|
||||||
unsigned long response = this->sendRequest(buildRequest(
|
unsigned long response = this->sendRequest(buildRequest(
|
||||||
OpenThermMessageType::WRITE_DATA,
|
OpenThermMessageType::WRITE_DATA,
|
||||||
OpenThermMessageID::RemoteRequest,
|
OpenThermMessageID::RemoteRequest,
|
||||||
data
|
static_cast<unsigned int>(requestCode) << 8
|
||||||
));
|
));
|
||||||
|
|
||||||
return isValidResponse(response) && isValidResponseId(response, OpenThermMessageID::RemoteRequest);
|
if (!isValidResponse(response) || !isValidResponseId(response, OpenThermMessageID::RemoteRequest)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t responseRequestCode = (response & 0xFFFF) >> 8;
|
||||||
|
const uint8_t responseCode = response & 0xFF;
|
||||||
|
if (responseRequestCode != requestCode || responseCode < 128) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset
|
||||||
|
this->sendRequest(buildRequest(
|
||||||
|
OpenThermMessageType::WRITE_DATA,
|
||||||
|
OpenThermMessageID::RemoteRequest,
|
||||||
|
0u << 8
|
||||||
|
));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getStr(OpenThermMessageID id, char* buffer, uint16_t length = 50) {
|
||||||
|
if (buffer == nullptr || length == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long response;
|
||||||
|
uint8_t index = 0;
|
||||||
|
uint8_t maxIndex = 255;
|
||||||
|
|
||||||
|
while (index <= maxIndex && index < length) {
|
||||||
|
response = this->sendRequest(buildRequest(
|
||||||
|
OpenThermMessageType::READ_DATA,
|
||||||
|
id,
|
||||||
|
static_cast<unsigned int>(index) << 8
|
||||||
|
));
|
||||||
|
|
||||||
|
if (!isValidResponse(response) || !isValidResponseId(response, id)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t character = response & 0xFF;
|
||||||
|
if (character == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index == 0) {
|
||||||
|
maxIndex = (response & 0xFFFF) >> 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[index++] = static_cast<char>(character);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[index] = '\0';
|
||||||
|
return index > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isCh2Active(unsigned long response) {
|
static bool isCh2Active(unsigned long response) {
|
||||||
return response & 0x20;
|
return response & 0x20;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isValidResponseId(unsigned long response, OpenThermMessageID id) {
|
static bool isValidResponseId(unsigned long response, OpenThermMessageID id) {
|
||||||
uint8_t responseId = (response >> 16) & 0xFF;
|
const uint8_t responseId = (response >> 16) & 0xFF;
|
||||||
|
|
||||||
return (uint8_t)id == responseId;
|
return static_cast<uint8_t>(id) == responseId;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t getResponseMessageTypeId(unsigned long response) {
|
static uint8_t getResponseMessageTypeId(unsigned long response) {
|
||||||
@@ -124,10 +163,10 @@ public:
|
|||||||
uint8_t msgType = getResponseMessageTypeId(response);
|
uint8_t msgType = getResponseMessageTypeId(response);
|
||||||
|
|
||||||
switch (msgType) {
|
switch (msgType) {
|
||||||
case (uint8_t) OpenThermMessageType::READ_ACK:
|
case static_cast<uint8_t>(OpenThermMessageType::READ_ACK):
|
||||||
case (uint8_t) OpenThermMessageType::WRITE_ACK:
|
case static_cast<uint8_t>(OpenThermMessageType::WRITE_ACK):
|
||||||
case (uint8_t) OpenThermMessageType::DATA_INVALID:
|
case static_cast<uint8_t>(OpenThermMessageType::DATA_INVALID):
|
||||||
case (uint8_t) OpenThermMessageType::UNKNOWN_DATA_ID:
|
case static_cast<uint8_t>(OpenThermMessageType::UNKNOWN_DATA_ID):
|
||||||
return CustomOpenTherm::messageTypeToString(
|
return CustomOpenTherm::messageTypeToString(
|
||||||
static_cast<OpenThermMessageType>(msgType)
|
static_cast<OpenThermMessageType>(msgType)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -808,7 +808,7 @@ protected:
|
|||||||
bool result = this->updateDhwTemp();
|
bool result = this->updateDhwTemp();
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
float convertedDhwTemp = convertTemp(
|
const float convertedDhwTemp = convertTemp(
|
||||||
vars.slave.dhw.currentTemp,
|
vars.slave.dhw.currentTemp,
|
||||||
settings.opentherm.unitSystem,
|
settings.opentherm.unitSystem,
|
||||||
settings.system.unitSystem
|
settings.system.unitSystem
|
||||||
@@ -832,7 +832,7 @@ protected:
|
|||||||
// Update DHW temp 2
|
// Update DHW temp 2
|
||||||
if (settings.opentherm.options.dhwSupport && Sensors::getAmountByType(Sensors::Type::OT_DHW_TEMP2, true)) {
|
if (settings.opentherm.options.dhwSupport && Sensors::getAmountByType(Sensors::Type::OT_DHW_TEMP2, true)) {
|
||||||
if (this->updateDhwTemp2()) {
|
if (this->updateDhwTemp2()) {
|
||||||
float convertedDhwTemp2 = convertTemp(
|
const float convertedDhwTemp2 = convertTemp(
|
||||||
vars.slave.dhw.currentTemp2,
|
vars.slave.dhw.currentTemp2,
|
||||||
settings.opentherm.unitSystem,
|
settings.opentherm.unitSystem,
|
||||||
settings.system.unitSystem
|
settings.system.unitSystem
|
||||||
@@ -856,7 +856,7 @@ protected:
|
|||||||
// Update DHW flow rate
|
// Update DHW flow rate
|
||||||
if (settings.opentherm.options.dhwSupport && Sensors::getAmountByType(Sensors::Type::OT_DHW_FLOW_RATE, true)) {
|
if (settings.opentherm.options.dhwSupport && Sensors::getAmountByType(Sensors::Type::OT_DHW_FLOW_RATE, true)) {
|
||||||
if (this->updateDhwFlowRate()) {
|
if (this->updateDhwFlowRate()) {
|
||||||
float convertedDhwFlowRate = convertVolume(
|
const float convertedDhwFlowRate = convertVolume(
|
||||||
vars.slave.dhw.flowRate,
|
vars.slave.dhw.flowRate,
|
||||||
settings.opentherm.unitSystem,
|
settings.opentherm.unitSystem,
|
||||||
settings.system.unitSystem
|
settings.system.unitSystem
|
||||||
@@ -880,7 +880,7 @@ protected:
|
|||||||
// Update heating temp
|
// Update heating temp
|
||||||
if (Sensors::getAmountByType(Sensors::Type::OT_HEATING_TEMP, true)) {
|
if (Sensors::getAmountByType(Sensors::Type::OT_HEATING_TEMP, true)) {
|
||||||
if (this->updateHeatingTemp()) {
|
if (this->updateHeatingTemp()) {
|
||||||
float convertedHeatingTemp = convertTemp(
|
const float convertedHeatingTemp = convertTemp(
|
||||||
vars.slave.heating.currentTemp,
|
vars.slave.heating.currentTemp,
|
||||||
settings.opentherm.unitSystem,
|
settings.opentherm.unitSystem,
|
||||||
settings.system.unitSystem
|
settings.system.unitSystem
|
||||||
@@ -904,7 +904,7 @@ protected:
|
|||||||
// Update heating return temp
|
// Update heating return temp
|
||||||
if (Sensors::getAmountByType(Sensors::Type::OT_HEATING_RETURN_TEMP, true)) {
|
if (Sensors::getAmountByType(Sensors::Type::OT_HEATING_RETURN_TEMP, true)) {
|
||||||
if (this->updateHeatingReturnTemp()) {
|
if (this->updateHeatingReturnTemp()) {
|
||||||
float convertedHeatingReturnTemp = convertTemp(
|
const float convertedHeatingReturnTemp = convertTemp(
|
||||||
vars.slave.heating.returnTemp,
|
vars.slave.heating.returnTemp,
|
||||||
settings.opentherm.unitSystem,
|
settings.opentherm.unitSystem,
|
||||||
settings.system.unitSystem
|
settings.system.unitSystem
|
||||||
@@ -929,7 +929,7 @@ protected:
|
|||||||
if (Sensors::getAmountByType(Sensors::Type::OT_CH2_TEMP, true)) {
|
if (Sensors::getAmountByType(Sensors::Type::OT_CH2_TEMP, true)) {
|
||||||
if (vars.master.ch2.enabled && !settings.opentherm.options.nativeOTC) {
|
if (vars.master.ch2.enabled && !settings.opentherm.options.nativeOTC) {
|
||||||
if (this->updateCh2Temp()) {
|
if (this->updateCh2Temp()) {
|
||||||
float convertedCh2Temp = convertTemp(
|
const float convertedCh2Temp = convertTemp(
|
||||||
vars.slave.ch2.currentTemp,
|
vars.slave.ch2.currentTemp,
|
||||||
settings.opentherm.unitSystem,
|
settings.opentherm.unitSystem,
|
||||||
settings.system.unitSystem
|
settings.system.unitSystem
|
||||||
@@ -954,7 +954,7 @@ protected:
|
|||||||
// Update exhaust temp
|
// Update exhaust temp
|
||||||
if (Sensors::getAmountByType(Sensors::Type::OT_EXHAUST_TEMP, true)) {
|
if (Sensors::getAmountByType(Sensors::Type::OT_EXHAUST_TEMP, true)) {
|
||||||
if (this->updateExhaustTemp()) {
|
if (this->updateExhaustTemp()) {
|
||||||
float convertedExhaustTemp = convertTemp(
|
const float convertedExhaustTemp = convertTemp(
|
||||||
vars.slave.exhaust.temp,
|
vars.slave.exhaust.temp,
|
||||||
settings.opentherm.unitSystem,
|
settings.opentherm.unitSystem,
|
||||||
settings.system.unitSystem
|
settings.system.unitSystem
|
||||||
@@ -978,7 +978,7 @@ protected:
|
|||||||
// Update heat exchanger temp
|
// Update heat exchanger temp
|
||||||
if (Sensors::getAmountByType(Sensors::Type::OT_HEAT_EXCHANGER_TEMP, true)) {
|
if (Sensors::getAmountByType(Sensors::Type::OT_HEAT_EXCHANGER_TEMP, true)) {
|
||||||
if (this->updateHeatExchangerTemp()) {
|
if (this->updateHeatExchangerTemp()) {
|
||||||
float convertedHeatExchTemp = convertTemp(
|
const float convertedHeatExchTemp = convertTemp(
|
||||||
vars.slave.heatExchangerTemp,
|
vars.slave.heatExchangerTemp,
|
||||||
settings.opentherm.unitSystem,
|
settings.opentherm.unitSystem,
|
||||||
settings.system.unitSystem
|
settings.system.unitSystem
|
||||||
@@ -1002,7 +1002,7 @@ protected:
|
|||||||
// Update outdoor temp
|
// Update outdoor temp
|
||||||
if (Sensors::getAmountByType(Sensors::Type::OT_OUTDOOR_TEMP, true)) {
|
if (Sensors::getAmountByType(Sensors::Type::OT_OUTDOOR_TEMP, true)) {
|
||||||
if (this->updateOutdoorTemp()) {
|
if (this->updateOutdoorTemp()) {
|
||||||
float convertedOutdoorTemp = convertTemp(
|
const float convertedOutdoorTemp = convertTemp(
|
||||||
vars.slave.heating.outdoorTemp,
|
vars.slave.heating.outdoorTemp,
|
||||||
settings.opentherm.unitSystem,
|
settings.opentherm.unitSystem,
|
||||||
settings.system.unitSystem
|
settings.system.unitSystem
|
||||||
@@ -1026,7 +1026,7 @@ protected:
|
|||||||
// Update solar storage temp
|
// Update solar storage temp
|
||||||
if (Sensors::getAmountByType(Sensors::Type::OT_SOLAR_STORAGE_TEMP, true)) {
|
if (Sensors::getAmountByType(Sensors::Type::OT_SOLAR_STORAGE_TEMP, true)) {
|
||||||
if (this->updateSolarStorageTemp()) {
|
if (this->updateSolarStorageTemp()) {
|
||||||
float convertedSolarStorageTemp = convertTemp(
|
const float convertedSolarStorageTemp = convertTemp(
|
||||||
vars.slave.solar.storage,
|
vars.slave.solar.storage,
|
||||||
settings.opentherm.unitSystem,
|
settings.opentherm.unitSystem,
|
||||||
settings.system.unitSystem
|
settings.system.unitSystem
|
||||||
@@ -1050,7 +1050,7 @@ protected:
|
|||||||
// Update solar collector temp
|
// Update solar collector temp
|
||||||
if (Sensors::getAmountByType(Sensors::Type::OT_SOLAR_COLLECTOR_TEMP, true)) {
|
if (Sensors::getAmountByType(Sensors::Type::OT_SOLAR_COLLECTOR_TEMP, true)) {
|
||||||
if (this->updateSolarCollectorTemp()) {
|
if (this->updateSolarCollectorTemp()) {
|
||||||
float convertedSolarCollectorTemp = convertTemp(
|
const float convertedSolarCollectorTemp = convertTemp(
|
||||||
vars.slave.solar.collector,
|
vars.slave.solar.collector,
|
||||||
settings.opentherm.unitSystem,
|
settings.opentherm.unitSystem,
|
||||||
settings.system.unitSystem
|
settings.system.unitSystem
|
||||||
@@ -1096,7 +1096,7 @@ protected:
|
|||||||
// Update pressure
|
// Update pressure
|
||||||
if (Sensors::getAmountByType(Sensors::Type::OT_PRESSURE, true)) {
|
if (Sensors::getAmountByType(Sensors::Type::OT_PRESSURE, true)) {
|
||||||
if (this->updatePressure()) {
|
if (this->updatePressure()) {
|
||||||
float convertedPressure = convertPressure(
|
const float convertedPressure = convertPressure(
|
||||||
vars.slave.pressure,
|
vars.slave.pressure,
|
||||||
settings.opentherm.unitSystem,
|
settings.opentherm.unitSystem,
|
||||||
settings.system.unitSystem
|
settings.system.unitSystem
|
||||||
@@ -1357,7 +1357,7 @@ protected:
|
|||||||
|
|
||||||
// Heating overheat control
|
// Heating overheat control
|
||||||
if (settings.heating.overheatProtection.highTemp > 0 && settings.heating.overheatProtection.lowTemp > 0) {
|
if (settings.heating.overheatProtection.highTemp > 0 && settings.heating.overheatProtection.lowTemp > 0) {
|
||||||
float highTemp = convertTemp(
|
const float highTemp = convertTemp(
|
||||||
max({
|
max({
|
||||||
vars.slave.heating.currentTemp,
|
vars.slave.heating.currentTemp,
|
||||||
vars.slave.heating.returnTemp,
|
vars.slave.heating.returnTemp,
|
||||||
@@ -1394,7 +1394,7 @@ protected:
|
|||||||
|
|
||||||
// DHW overheat control
|
// DHW overheat control
|
||||||
if (settings.dhw.overheatProtection.highTemp > 0 && settings.dhw.overheatProtection.lowTemp > 0) {
|
if (settings.dhw.overheatProtection.highTemp > 0 && settings.dhw.overheatProtection.lowTemp > 0) {
|
||||||
float highTemp = convertTemp(
|
const float highTemp = convertTemp(
|
||||||
max({
|
max({
|
||||||
vars.slave.heating.currentTemp,
|
vars.slave.heating.currentTemp,
|
||||||
vars.slave.heating.returnTemp,
|
vars.slave.heating.returnTemp,
|
||||||
@@ -1488,6 +1488,19 @@ protected:
|
|||||||
} else {
|
} else {
|
||||||
Log.swarningln(FPSTR(L_OT), F("Failed set master config"));
|
Log.swarningln(FPSTR(L_OT), F("Failed set master config"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*char buf[100];
|
||||||
|
if (this->instance->getStr(OpenThermMessageID::Brand, buf, sizeof(buf) - 1)) {
|
||||||
|
Log.snoticeln(FPSTR(L_OT), F("Slave brand: %s"), buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->instance->getStr(OpenThermMessageID::BrandVersion, buf, sizeof(buf) - 1)) {
|
||||||
|
Log.snoticeln(FPSTR(L_OT), F("Slave brand version: %s"), buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->instance->getStr(OpenThermMessageID::BrandSerialNumber, buf, sizeof(buf) - 1)) {
|
||||||
|
Log.snoticeln(FPSTR(L_OT), F("Slave brand s/n: %s"), buf);
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isReady() {
|
bool isReady() {
|
||||||
@@ -1665,7 +1678,7 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool setRoomTemp(float temperature) {
|
bool setRoomTemp(const float temperature) {
|
||||||
const unsigned int request = CustomOpenTherm::temperatureToData(temperature);
|
const unsigned int request = CustomOpenTherm::temperatureToData(temperature);
|
||||||
const unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
const unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
||||||
OpenThermMessageType::WRITE_DATA,
|
OpenThermMessageType::WRITE_DATA,
|
||||||
@@ -1685,7 +1698,7 @@ protected:
|
|||||||
return CustomOpenTherm::getUInt(response) == request;
|
return CustomOpenTherm::getUInt(response) == request;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool setRoomTempCh2(float temperature) {
|
bool setRoomTempCh2(const float temperature) {
|
||||||
const unsigned int request = CustomOpenTherm::temperatureToData(temperature);
|
const unsigned int request = CustomOpenTherm::temperatureToData(temperature);
|
||||||
const unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
const unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest(
|
||||||
OpenThermMessageType::WRITE_DATA,
|
OpenThermMessageType::WRITE_DATA,
|
||||||
@@ -2220,7 +2233,7 @@ protected:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
float value = CustomOpenTherm::getFloat(response);
|
const float value = CustomOpenTherm::getFloat(response);
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2244,7 +2257,7 @@ protected:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
float value = CustomOpenTherm::getFloat(response);
|
const float value = CustomOpenTherm::getFloat(response);
|
||||||
if (value <= 0) {
|
if (value <= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2268,7 +2281,7 @@ protected:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
float value = CustomOpenTherm::getFloat(response);
|
const float value = CustomOpenTherm::getFloat(response);
|
||||||
if (value <= 0) {
|
if (value <= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2322,7 +2335,7 @@ protected:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
float value = CustomOpenTherm::getFloat(response);
|
const float value = CustomOpenTherm::getFloat(response);
|
||||||
if (value <= 0) {
|
if (value <= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2386,7 +2399,7 @@ protected:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
float value = (float) CustomOpenTherm::getInt(response);
|
const float value = (float) CustomOpenTherm::getInt(response);
|
||||||
if (!isValidTemp(value, settings.opentherm.unitSystem, -40, 500)) {
|
if (!isValidTemp(value, settings.opentherm.unitSystem, -40, 500)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2410,7 +2423,7 @@ protected:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
float value = (float) CustomOpenTherm::getInt(response);
|
const float value = (float) CustomOpenTherm::getInt(response);
|
||||||
if (value <= 0) {
|
if (value <= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2511,7 +2524,7 @@ protected:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
float value = CustomOpenTherm::getFloat(response);
|
const float value = CustomOpenTherm::getFloat(response);
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user