mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
add remotetemp to RC3xx
This commit is contained in:
@@ -24,26 +24,62 @@ namespace emsesp {
|
||||
bool Roomctrl::switch_off_[HCS] = {false, false, false, false};
|
||||
uint32_t Roomctrl::rc_time_[HCS] = {0, 0, 0, 0};
|
||||
int16_t Roomctrl::remotetemp_[HCS] = {EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET};
|
||||
int16_t Roomctrl::remotehum_[HCS] = {EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET};
|
||||
uint8_t Roomctrl::sendcnt[] = {0, 0, 0, 0};
|
||||
uint8_t Roomctrl::type_ = RC20;
|
||||
|
||||
/**
|
||||
* set the temperature,
|
||||
*/
|
||||
void Roomctrl::set_remotetemp(const uint8_t hc, const int16_t temp) {
|
||||
if (hc >= HCS) {
|
||||
void Roomctrl::set_remotetemp(const uint8_t type, const uint8_t hc, const int16_t temp) {
|
||||
if (hc >= HCS || (type != RC20 && type != FB10 && type != RC100H && type != SENSOR)) {
|
||||
return;
|
||||
}
|
||||
type_ = type;
|
||||
if (remotetemp_[hc] != EMS_VALUE_SHORT_NOTSET && temp == EMS_VALUE_SHORT_NOTSET) {
|
||||
switch_off_[hc] = true;
|
||||
}
|
||||
if (remotetemp_[hc] != temp) {
|
||||
rc_time_[hc] = uuid::get_uptime() - SEND_INTERVAL; // send now
|
||||
sendcnt[hc] = 0;
|
||||
}
|
||||
remotetemp_[hc] = temp;
|
||||
}
|
||||
|
||||
void Roomctrl::set_remotehum(const uint8_t type, const uint8_t hc, const int16_t hum) {
|
||||
if (hc >= HCS || (type != RC20 && type != FB10 && type != RC100H && type != SENSOR)) {
|
||||
return;
|
||||
}
|
||||
type_ = type;
|
||||
if (remotehum_[hc] != EMS_VALUE_SHORT_NOTSET && hum == EMS_VALUE_SHORT_NOTSET) {
|
||||
switch_off_[hc] = true;
|
||||
}
|
||||
if (remotehum_[hc] != hum) {
|
||||
rc_time_[hc] = uuid::get_uptime() - SEND_INTERVAL; // send now
|
||||
sendcnt[hc] = 1;
|
||||
}
|
||||
remotehum_[hc] = hum;
|
||||
}
|
||||
|
||||
uint8_t Roomctrl::get_hc(uint8_t addr) {
|
||||
switch (type_) {
|
||||
case SENSOR:
|
||||
return addr - 0x40;
|
||||
case RC100H:
|
||||
return addr - 0x38;
|
||||
case FB10:
|
||||
case RC20:
|
||||
default:
|
||||
return addr - 0x18;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* if remote control is active send the temperature every minute
|
||||
*/
|
||||
void Roomctrl::send(const uint8_t addr) {
|
||||
uint8_t hc = addr - ADDR;
|
||||
// check address, reply only on addresses 0x18..0x1B
|
||||
uint8_t hc = get_hc(addr);
|
||||
// check address, reply only on addresses 0x18..0x1B or 0x40..0x43
|
||||
if (hc >= HCS) {
|
||||
return;
|
||||
}
|
||||
@@ -53,9 +89,26 @@ void Roomctrl::send(const uint8_t addr) {
|
||||
}
|
||||
|
||||
if (uuid::get_uptime() - rc_time_[hc] > SEND_INTERVAL) { // send every minute
|
||||
rc_time_[hc] = uuid::get_uptime(); // use EMS-ESP's millis() to prevent overhead
|
||||
temperature(addr, 0x00); // send to all
|
||||
switch_off_[hc] = false;
|
||||
if (type_ == FB10 || type_ == RC100H) {
|
||||
if (sendcnt[hc] == 1) {
|
||||
rc_time_[hc] = uuid::get_uptime();
|
||||
humidity(addr, 0x10, hc);
|
||||
sendcnt[hc] = 0;
|
||||
} else {
|
||||
if (remotehum_[hc] != EMS_VALUE_SHORT_NOTSET) {
|
||||
sendcnt[hc] = 1;
|
||||
} else {
|
||||
rc_time_[hc] = uuid::get_uptime();
|
||||
}
|
||||
temperature(addr, 0x10, hc); // send to master-thermostat (https://github.com/emsesp/EMS-ESP32/issues/336)
|
||||
}
|
||||
} else {
|
||||
rc_time_[hc] = uuid::get_uptime();
|
||||
temperature(addr, 0x00, hc); // send to all
|
||||
}
|
||||
if (remotehum_[hc] == EMS_VALUE_SHORT_NOTSET) {
|
||||
switch_off_[hc] = false;
|
||||
}
|
||||
} else {
|
||||
// acknowledge every poll, otherwise the master shows error A22-816
|
||||
EMSuart::send_poll(addr);
|
||||
@@ -66,7 +119,7 @@ void Roomctrl::send(const uint8_t addr) {
|
||||
* check if there is a message for the remote room controller
|
||||
*/
|
||||
void Roomctrl::check(const uint8_t addr, const uint8_t * data) {
|
||||
uint8_t hc = (addr & 0x7F) - ADDR;
|
||||
uint8_t hc = get_hc(addr & 0x7F);
|
||||
|
||||
// check address, reply only on addresses 0x18..0x1B
|
||||
if (hc >= HCS) {
|
||||
@@ -83,12 +136,18 @@ void Roomctrl::check(const uint8_t addr, const uint8_t * data) {
|
||||
}
|
||||
// reads: for now we only reply to version and remote temperature
|
||||
// empty message back if temperature not set or unknown message type
|
||||
if (data[2] == 0x02) {
|
||||
if (data[2] == EMSdevice::EMS_TYPE_VERSION) {
|
||||
version(addr, data[0]);
|
||||
} else if (remotetemp_[hc] == EMS_VALUE_SHORT_NOTSET) {
|
||||
unknown(addr, data[0], data[2], data[3]);
|
||||
} else if (data[2] == 0xAF && data[3] == 0) {
|
||||
temperature(addr, data[0]);
|
||||
temperature(addr, data[0], hc);
|
||||
} else if (data[2] == 0xFF && data[3] == 0 && data[5] == 0 && data[6] == 0x23) { // Junkers
|
||||
temperature(addr, data[0], hc);
|
||||
} else if (data[2] == 0xFF && data[3] == 0 && data[5] == 3 && data[6] == 0x2B) { // EMS+ temperature
|
||||
temperature(addr, data[0], hc);
|
||||
} else if (data[2] == 0xFF && data[3] == 0 && data[5] == 3 && data[6] == 0x7B && remotehum_[hc] != EMS_VALUE_SHORT_NOTSET) { // EMS+ humidity
|
||||
humidity(addr, data[0], hc);
|
||||
} else {
|
||||
unknown(addr, data[0], data[2], data[3]);
|
||||
}
|
||||
@@ -103,9 +162,9 @@ void Roomctrl::version(uint8_t addr, uint8_t dst) {
|
||||
data[1] = dst;
|
||||
data[2] = 0x02;
|
||||
data[3] = 0;
|
||||
data[4] = 113; // set RC20 id 113, Ver 02.01
|
||||
data[5] = 0x02;
|
||||
data[6] = 0x01;
|
||||
data[4] = type_; // set RC20 id 113, Ver 02.01 or Junkers FB10 id 109, Ver 16.05, RC100H id 200 ver 40.04
|
||||
data[5] = type_ == RC20 ? 2 : type_ == FB10 ? 16 : 40;
|
||||
data[6] = type_ == RC20 ? 1 : type_ == FB10 ? 5 : 4;
|
||||
data[7] = EMSbus::calculate_crc(data, 7); // apppend CRC
|
||||
EMSuart::transmit(data, 8);
|
||||
}
|
||||
@@ -126,19 +185,64 @@ void Roomctrl::unknown(uint8_t addr, uint8_t dst, uint8_t type, uint8_t offset)
|
||||
/**
|
||||
* send the room temperature in message 0xAF
|
||||
*/
|
||||
void Roomctrl::temperature(uint8_t addr, uint8_t dst) {
|
||||
void Roomctrl::temperature(uint8_t addr, uint8_t dst, uint8_t hc) {
|
||||
uint8_t data[10];
|
||||
uint8_t hc = addr - ADDR;
|
||||
data[0] = addr;
|
||||
data[1] = dst;
|
||||
data[2] = 0xAF;
|
||||
data[3] = 0;
|
||||
data[4] = (uint8_t)(remotetemp_[hc] >> 8);
|
||||
data[5] = (uint8_t)(remotetemp_[hc] & 0xFF);
|
||||
data[6] = 0;
|
||||
data[7] = EMSbus::calculate_crc(data, 7); // apppend CRC
|
||||
EMSuart::transmit(data, 8);
|
||||
data[0] = addr;
|
||||
data[1] = dst;
|
||||
if (type_ == RC20) { // RC20, telegram 0xAF
|
||||
data[2] = 0xAF;
|
||||
data[3] = 0;
|
||||
data[4] = (uint8_t)(remotetemp_[hc] >> 8);
|
||||
data[5] = (uint8_t)(remotetemp_[hc] & 0xFF);
|
||||
data[6] = 0;
|
||||
data[7] = EMSbus::calculate_crc(data, 7); // apppend CRC
|
||||
EMSuart::transmit(data, 8);
|
||||
} else if (type_ == FB10) { // Junkers FB10, telegram 0x0123
|
||||
data[2] = 0xFF;
|
||||
data[3] = 0;
|
||||
data[4] = 0;
|
||||
data[5] = 0x23; // is this always 0x23 or count with hc?
|
||||
data[6] = (uint8_t)(remotetemp_[hc] >> 8);
|
||||
data[7] = (uint8_t)(remotetemp_[hc] & 0xFF);
|
||||
data[8] = EMSbus::calculate_crc(data, 8); // apppend CRC
|
||||
EMSuart::transmit(data, 9);
|
||||
} else if (type_ == RC100H) { // RC100H, telegram 42B
|
||||
data[2] = 0xFF;
|
||||
data[3] = 0;
|
||||
data[4] = 3;
|
||||
data[5] = 0x2B;
|
||||
data[6] = (uint8_t)(remotetemp_[hc] >> 8);
|
||||
data[7] = (uint8_t)(remotetemp_[hc] & 0xFF);
|
||||
data[8] = EMSbus::calculate_crc(data, 8); // apppend CRC
|
||||
EMSuart::transmit(data, 9);
|
||||
} else if (type_ == SENSOR) { // wireless sensor, broadcast id 435
|
||||
data[2] = 0xFF;
|
||||
data[3] = 0;
|
||||
data[4] = 3;
|
||||
data[5] = 0x35;
|
||||
data[6] = (uint8_t)(remotetemp_[hc] >> 8);
|
||||
data[7] = (uint8_t)(remotetemp_[hc] & 0xFF);
|
||||
data[8] = EMSbus::calculate_crc(data, 8); // apppend CRC
|
||||
EMSuart::transmit(data, 9);
|
||||
}
|
||||
}
|
||||
|
||||
void Roomctrl::humidity(uint8_t addr, uint8_t dst, uint8_t hc) {
|
||||
uint8_t data[10];
|
||||
data[0] = addr;
|
||||
data[1] = dst;
|
||||
if (type_ == RC100H) { // RC100H, telegram 47B
|
||||
data[2] = 0xFF;
|
||||
data[3] = 0;
|
||||
data[4] = 3;
|
||||
data[5] = 0x7B;
|
||||
data[6] = (uint8_t)(remotehum_[hc] >> 8);
|
||||
data[7] = (uint8_t)(remotehum_[hc] & 0xFF);
|
||||
data[8] = EMSbus::calculate_crc(data, 8); // apppend CRC
|
||||
EMSuart::transmit(data, 9);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* send a nack if someone want to write to us.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user