fix: negative dew point calculation (emulated RC100H) #3134

This commit is contained in:
proddy
2026-06-25 21:23:49 +02:00
parent d21f5f9ab6
commit 2a6b436b2e

View File

@@ -16,27 +16,27 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "roomcontrol.h" #include "roomcontrol.h"
namespace emsesp { namespace emsesp {
// init statics // init statics
bool Roomctrl::switch_off_[HCS] = {false, false, false, false}; bool Roomctrl::switch_off_[HCS] = {false, false, false, false};
uint32_t Roomctrl::send_time_[HCS] = {0, 0, 0, 0}; uint32_t Roomctrl::send_time_[HCS] = {0, 0, 0, 0};
uint32_t Roomctrl::receive_time_[HCS] = {0, 0, 0, 0}; uint32_t Roomctrl::receive_time_[HCS] = {0, 0, 0, 0};
int16_t Roomctrl::remotetemp_[HCS] = {EMS_VALUE_INT16_NOTSET, EMS_VALUE_INT16_NOTSET, EMS_VALUE_INT16_NOTSET, EMS_VALUE_INT16_NOTSET}; int16_t Roomctrl::remotetemp_[HCS] = {EMS_VALUE_INT16_NOTSET, EMS_VALUE_INT16_NOTSET, EMS_VALUE_INT16_NOTSET, EMS_VALUE_INT16_NOTSET};
uint8_t Roomctrl::remotehum_[HCS] = {EMS_VALUE_UINT8_NOTSET, EMS_VALUE_UINT8_NOTSET, EMS_VALUE_UINT8_NOTSET, EMS_VALUE_UINT8_NOTSET}; uint8_t Roomctrl::remotehum_[HCS] = {EMS_VALUE_UINT8_NOTSET, EMS_VALUE_UINT8_NOTSET, EMS_VALUE_UINT8_NOTSET, EMS_VALUE_UINT8_NOTSET};
uint8_t Roomctrl::sendtype_[HCS] = {SendType::TEMP, SendType::TEMP, SendType::TEMP, SendType::TEMP}; uint8_t Roomctrl::sendtype_[HCS] = {SendType::TEMP, SendType::TEMP, SendType::TEMP, SendType::TEMP};
uint8_t Roomctrl::type_[HCS] = {RemoteType::NONE, RemoteType::NONE, RemoteType::NONE, RemoteType::NONE}; uint8_t Roomctrl::type_[HCS] = {RemoteType::NONE, RemoteType::NONE, RemoteType::NONE, RemoteType::NONE};
uint32_t Roomctrl::timeout_ = 0; uint32_t Roomctrl::timeout_ = 0;
/** /**
* set the temperature, * set the temperature,
*/ */
void Roomctrl::set_timeout(uint8_t t) { void Roomctrl::set_timeout(uint8_t t) {
timeout_ = t * 3600000; // ms timeout_ = t * 3600000; // ms
} }
void Roomctrl::set_remotetemp(const uint8_t type, const uint8_t hc, const int16_t temp) { void Roomctrl::set_remotetemp(const uint8_t type, const uint8_t hc, const int16_t temp) {
if (!type_[hc] && !type) { if (!type_[hc] && !type) {
return; return;
} }
@@ -57,10 +57,10 @@ void Roomctrl::set_remotetemp(const uint8_t type, const uint8_t hc, const int16_
type_[hc] = type; type_[hc] = type;
remotetemp_[hc] = temp; remotetemp_[hc] = temp;
receive_time_[hc] = uuid::get_uptime(); receive_time_[hc] = uuid::get_uptime();
} }
// set humidity for RC100H emulation // set humidity for RC100H emulation
void Roomctrl::set_remotehum(const uint8_t type, const uint8_t hc, const int8_t hum) { void Roomctrl::set_remotehum(const uint8_t type, const uint8_t hc, const int8_t hum) {
if (hc >= HCS || type != type_[hc]) { if (hc >= HCS || type != type_[hc]) {
return; return;
} }
@@ -69,9 +69,9 @@ void Roomctrl::set_remotehum(const uint8_t type, const uint8_t hc, const int8_t
sendtype_[hc] = SendType::HUMI; sendtype_[hc] = SendType::HUMI;
} }
remotehum_[hc] = hum; remotehum_[hc] = hum;
} }
uint8_t Roomctrl::get_hc(uint8_t addr) { uint8_t Roomctrl::get_hc(uint8_t addr) {
addr &= 0x7F; addr &= 0x7F;
if (addr >= 0x40 && addr <= 0x44 && type_[addr - 0x40] == SENSOR) { if (addr >= 0x40 && addr <= 0x44 && type_[addr - 0x40] == SENSOR) {
return addr - 0x40; // SENSOR return addr - 0x40; // SENSOR
@@ -83,12 +83,12 @@ uint8_t Roomctrl::get_hc(uint8_t addr) {
return addr - 0x18; // RC20, FB10 return addr - 0x18; // RC20, FB10
} }
return 0xFF; // invalid return 0xFF; // invalid
} }
/** /**
* if remote control is active send the temperature every 15 seconds * if remote control is active send the temperature every 15 seconds
*/ */
void Roomctrl::send(uint8_t addr) { void Roomctrl::send(uint8_t addr) {
if ((addr & 0x80) || EMSESP::system_.readonly_mode()) { if ((addr & 0x80) || EMSESP::system_.readonly_mode()) {
return; return;
} }
@@ -140,12 +140,12 @@ void Roomctrl::send(uint8_t addr) {
// acknowledge every poll // acknowledge every poll
EMSuart::send_poll(addr | EMSbus::ems_mask()); EMSuart::send_poll(addr | EMSbus::ems_mask());
} }
} }
/** /**
* check if there is a message for the remote room controller * check if there is a message for the remote room controller
*/ */
void Roomctrl::check(uint8_t addr, const uint8_t * data, const uint8_t length) { void Roomctrl::check(uint8_t addr, const uint8_t * data, const uint8_t length) {
if (EMSESP::system_.readonly_mode()) { if (EMSESP::system_.readonly_mode()) {
return; return;
} }
@@ -187,12 +187,12 @@ void Roomctrl::check(uint8_t addr, const uint8_t * data, const uint8_t length) {
} else if (length == 8) { } else if (length == 8) {
unknown(addr, data[0], data[3], data[5], data[6]); unknown(addr, data[0], data[3], data[5], data[6]);
} }
} }
/** /**
* send version info * send version info
*/ */
void Roomctrl::version(uint8_t addr, uint8_t dst, uint8_t hc) { void Roomctrl::version(uint8_t addr, uint8_t dst, uint8_t hc) {
uint8_t data[20]; uint8_t data[20];
data[0] = addr | EMSbus::ems_mask(); data[0] = addr | EMSbus::ems_mask();
data[1] = dst & 0x7F; data[1] = dst & 0x7F;
@@ -262,12 +262,12 @@ void Roomctrl::version(uint8_t addr, uint8_t dst, uint8_t hc) {
EMSuart::transmit(data, 10); EMSuart::transmit(data, 10);
return; return;
} }
} }
/** /**
* unknown message id, we reply with empty message * unknown message id, we reply with empty message
*/ */
void Roomctrl::unknown(uint8_t addr, uint8_t dst, uint8_t type, uint8_t offset) { void Roomctrl::unknown(uint8_t addr, uint8_t dst, uint8_t type, uint8_t offset) {
uint8_t data[10]; uint8_t data[10];
data[0] = addr | EMSbus::ems_mask(); data[0] = addr | EMSbus::ems_mask();
data[1] = dst & 0x7F; data[1] = dst & 0x7F;
@@ -275,9 +275,9 @@ void Roomctrl::unknown(uint8_t addr, uint8_t dst, uint8_t type, uint8_t offset)
data[3] = offset; data[3] = offset;
data[4] = EMSbus::calculate_crc(data, 4); // append CRC data[4] = EMSbus::calculate_crc(data, 4); // append CRC
EMSuart::transmit(data, 5); EMSuart::transmit(data, 5);
} }
void Roomctrl::unknown(uint8_t addr, uint8_t dst, uint8_t offset, uint8_t typeh, uint8_t typel) { void Roomctrl::unknown(uint8_t addr, uint8_t dst, uint8_t offset, uint8_t typeh, uint8_t typel) {
uint8_t data[10]; uint8_t data[10];
data[0] = addr | EMSbus::ems_mask(); data[0] = addr | EMSbus::ems_mask();
data[1] = dst & 0x7F; data[1] = dst & 0x7F;
@@ -287,12 +287,12 @@ void Roomctrl::unknown(uint8_t addr, uint8_t dst, uint8_t offset, uint8_t typeh,
data[5] = typel; data[5] = typel;
data[6] = EMSbus::calculate_crc(data, 6); // append CRC data[6] = EMSbus::calculate_crc(data, 6); // append CRC
EMSuart::transmit(data, 7); EMSuart::transmit(data, 7);
} }
/** /**
* send the room temperature in message 0xAF * send the room temperature in message 0xAF
*/ */
void Roomctrl::temperature(uint8_t addr, uint8_t dst, uint8_t hc) { void Roomctrl::temperature(uint8_t addr, uint8_t dst, uint8_t hc) {
uint8_t data[14]; uint8_t data[14];
data[0] = addr | EMSbus::ems_mask(); data[0] = addr | EMSbus::ems_mask();
data[1] = dst & 0x7F; data[1] = dst & 0x7F;
@@ -373,45 +373,49 @@ void Roomctrl::temperature(uint8_t addr, uint8_t dst, uint8_t hc) {
data[12] = EMSbus::calculate_crc(data, 12); // append CRC data[12] = EMSbus::calculate_crc(data, 12); // append CRC
EMSuart::transmit(data, 13); EMSuart::transmit(data, 13);
} }
} }
// send telegram 0x047B only for RC100H // send telegram 0x047B only for RC100H
void Roomctrl::humidity(uint8_t addr, uint8_t dst, uint8_t hc) { void Roomctrl::humidity(uint8_t addr, uint8_t dst, uint8_t hc) {
int16_t dew = calc_dew(remotetemp_[hc], remotehum_[hc]);
int8_t dew8 = EMS_VALUE_INT8_NOTSET;
if (dew != EMS_VALUE_INT16_NOTSET) {
dew8 = static_cast<int8_t>((dew >= 0 ? dew + 5 : dew - 5) / 10);
}
uint8_t data[11]; uint8_t data[11];
data[0] = addr | EMSbus::ems_mask(); data[0] = addr | EMSbus::ems_mask();
data[1] = dst & 0x7F; data[1] = dst & 0x7F;
uint16_t dew = calc_dew(remotetemp_[hc], remotehum_[hc]);
data[2] = 0xFF; data[2] = 0xFF;
data[3] = 0; data[3] = 0;
data[4] = 3; data[4] = 3;
data[5] = 0x7B + hc; data[5] = 0x7B + hc;
data[6] = dew == EMS_VALUE_INT16_NOTSET ? EMS_VALUE_INT8_NOTSET : (uint8_t)((dew + 5) / 10); data[6] = static_cast<uint8_t>(dew8);
data[7] = remotehum_[hc]; data[7] = remotehum_[hc];
data[8] = (uint8_t)(dew << 8); data[8] = static_cast<uint8_t>(static_cast<uint16_t>(dew) >> 8);
data[9] = (uint8_t)(dew & 0xFF); data[9] = static_cast<uint8_t>(static_cast<uint16_t>(dew) & 0xFF);
data[10] = EMSbus::calculate_crc(data, 10); // append CRC data[10] = EMSbus::calculate_crc(data, 10); // append CRC
EMSuart::transmit(data, 11); EMSuart::transmit(data, 11);
} }
/** /**
* send a nack if someone want to write to us. * send a nack if someone want to write to us.
*/ */
void Roomctrl::nack_write() { void Roomctrl::nack_write() {
uint8_t data[1]; uint8_t data[1];
data[0] = TxService::TX_WRITE_FAIL; data[0] = TxService::TX_WRITE_FAIL;
EMSuart::transmit(data, 1); EMSuart::transmit(data, 1);
} }
/** /**
* send a ack if someone want to write to us. * send a ack if someone want to write to us.
*/ */
void Roomctrl::ack_write() { void Roomctrl::ack_write() {
uint8_t data[1]; uint8_t data[1];
data[0] = TxService::TX_WRITE_SUCCESS; data[0] = TxService::TX_WRITE_SUCCESS;
EMSuart::transmit(data, 1); EMSuart::transmit(data, 1);
} }
void Roomctrl::replyF7(uint8_t addr, uint8_t dst, uint8_t offset, uint8_t typehh, uint8_t typeh, uint8_t typel, uint8_t hc) { void Roomctrl::replyF7(uint8_t addr, uint8_t dst, uint8_t offset, uint8_t typehh, uint8_t typeh, uint8_t typel, uint8_t hc) {
uint8_t data[12]; uint8_t data[12];
data[0] = addr | EMSbus::ems_mask(); data[0] = addr | EMSbus::ems_mask();
data[1] = dst & 0x7F; data[1] = dst & 0x7F;
@@ -434,9 +438,9 @@ void Roomctrl::replyF7(uint8_t addr, uint8_t dst, uint8_t offset, uint8_t typehh
} }
data[9] = EMSbus::calculate_crc(data, 9); // append CRC data[9] = EMSbus::calculate_crc(data, 9); // append CRC
EMSuart::transmit(data, 10); EMSuart::transmit(data, 10);
} }
int16_t Roomctrl::calc_dew(int16_t temp, uint8_t humi) { int16_t Roomctrl::calc_dew(int16_t temp, uint8_t humi) {
if (humi == EMS_VALUE_UINT8_NOTSET || temp == EMS_VALUE_INT16_NOTSET) { if (humi == EMS_VALUE_UINT8_NOTSET || temp == EMS_VALUE_INT16_NOTSET) {
return EMS_VALUE_INT16_NOTSET; return EMS_VALUE_INT16_NOTSET;
} }
@@ -446,7 +450,7 @@ int16_t Roomctrl::calc_dew(int16_t temp, uint8_t humi) {
const float h = (float)humi / 100; const float h = (float)humi / 100;
int16_t dt = (10 * k3 * (((k2 * t) / (k3 + t)) + log(h)) / (((k2 * k3) / (k3 + t)) - log(h))); int16_t dt = (10 * k3 * (((k2 * t) / (k3 + t)) + log(h)) / (((k2 * k3) / (k3 + t)) - log(h)));
return dt; return dt;
} }
} // namespace emsesp } // namespace emsesp