Skip to content

Commit

Permalink
add known devices without product-id or version-info #174
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Nov 3, 2021
1 parent 7a079d8 commit 0e480bb
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/device_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@
{157, DeviceType::THERMOSTAT, F("RC200/CW100"), DeviceFlags::EMS_DEVICE_FLAG_RC100}, // 0x18
{158, DeviceType::THERMOSTAT, F("RC300/RC310/Moduline 3000/1010H/CW400/Sense II"), DeviceFlags::EMS_DEVICE_FLAG_RC300}, // 0x10
{165, DeviceType::THERMOSTAT, F("RC100/Moduline 1000/1010"), DeviceFlags::EMS_DEVICE_FLAG_RC100}, // 0x18, 0x38
{216, DeviceType::THERMOSTAT, F("CRF200S"), DeviceFlags::EMS_DEVICE_FLAG_CRF | DeviceFlags::EMS_DEVICE_FLAG_NO_WRITE}, // 0x18
{172, DeviceType::THERMOSTAT, F("Rego 2000/3000"), DeviceFlags::EMS_DEVICE_FLAG_RC300}, // 0x10
{216, DeviceType::THERMOSTAT, F("CRF200S"), DeviceFlags::EMS_DEVICE_FLAG_CRF | DeviceFlags::EMS_DEVICE_FLAG_NO_WRITE}, // 0x18

// Thermostat - Sieger - 0x10 / 0x17
{ 66, DeviceType::THERMOSTAT, F("ES72/RC20"), DeviceFlags::EMS_DEVICE_FLAG_RC20_N}, // 0x17 or remote
{ 76, DeviceType::THERMOSTAT, F("ES73"), DeviceFlags::EMS_DEVICE_FLAG_RC35}, // 0x10
{ 76, DeviceType::THERMOSTAT, F("ES73"), DeviceFlags::EMS_DEVICE_FLAG_RC30_N}, // 0x10
{113, DeviceType::THERMOSTAT, F("ES72/RC20"), DeviceFlags::EMS_DEVICE_FLAG_RC20_N}, // 0x17

// Thermostat - Junkers - 0x10
Expand Down Expand Up @@ -125,12 +125,17 @@
{171, DeviceType::CONNECT, F("OpenTherm Converter"), DeviceFlags::EMS_DEVICE_FLAG_NONE},
{205, DeviceType::CONNECT, F("Moduline Easy Connect"), DeviceFlags::EMS_DEVICE_FLAG_NONE},
{206, DeviceType::CONNECT, F("Easy Connect"), DeviceFlags::EMS_DEVICE_FLAG_NONE},

// wireless sensor base- 0x50
{236, DeviceType::CONNECT, F("Wireless sensor base"), DeviceFlags::EMS_DEVICE_FLAG_NONE},

// Switches - 0x11
{ 71, DeviceType::SWITCH, F("WM10"), DeviceFlags::EMS_DEVICE_FLAG_NONE},

// Gateways - 0x48
{189, DeviceType::GATEWAY, F("KM200/MB LAN 2"), DeviceFlags::EMS_DEVICE_FLAG_NONE}
{189, DeviceType::GATEWAY, F("KM200/MB LAN 2"), DeviceFlags::EMS_DEVICE_FLAG_NONE},

// generic - 0x40 or other with no product-id and no version
{0, DeviceType::GENERIC, F("unknown"), DeviceFlags::EMS_DEVICE_FLAG_NONE}

// clang-format on
36 changes: 35 additions & 1 deletion src/emsesp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,11 @@ void EMSESP::process_UBADevices(std::shared_ptr<const Telegram> telegram) {
void EMSESP::process_version(std::shared_ptr<const Telegram> telegram) {
// check for valid telegram, just in case
if (telegram->message_length < 3) {
// for empty telegram add device with empty product, version and brand
if (!telegram->message_length) {
std::string version = "00.00";
(void)add_device(telegram->src, 0, version, 0);
}
return;
}

Expand Down Expand Up @@ -852,7 +857,7 @@ bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
LOG_NOTICE(F("%s"), pretty_telegram(telegram).c_str());
}
if (first_scan_done_ && !knowndevice && (telegram->src != EMSbus::ems_bus_id()) && (telegram->src != 0x0B) && (telegram->src != 0x0C)
&& (telegram->src != 0x0D)) {
&& (telegram->src != 0x0D) && (telegram->message_length > 0)) {
send_read_request(EMSdevice::EMS_TYPE_VERSION, telegram->src);
}
}
Expand Down Expand Up @@ -978,6 +983,35 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, std::
auto name = uuid::read_flash_string(device_p->name);
auto device_type = device_p->device_type;
auto flags = device_p->flags;

// empty reply to version, read a generic device from database
if (product_id == 0) {
// check for known device IDs
if (device_id == 0x40) {
name = "rf room temperature sensor";
} else if (device_id == 0x17) {
name = "generic thermostat";
device_type = DeviceType::THERMOSTAT;
flags = DeviceFlags::EMS_DEVICE_FLAG_RC10 | DeviceFlags::EMS_DEVICE_FLAG_NO_WRITE;
} else if (device_id == 0x04) {
name = "RS232";
device_type = DeviceType::CONNECT;
} else if (device_id == 0x0A) {
name = "terminal";
device_type = DeviceType::CONNECT;
} else if (device_id == 0x0B) {
name = "service key";
device_type = DeviceType::CONNECT;
} else if (device_id == 0x0D) {
name = "modem";
device_type = DeviceType::CONNECT;
} else if (device_id == 0x0E) {
name = "converter";
} else {
return false;
}
}

LOG_DEBUG(F("Adding new device %s (device ID 0x%02X, product ID %d, version %s)"), name.c_str(), device_id, product_id, version.c_str());
emsdevices.push_back(EMSFactory::add(device_type, device_id, product_id, version, name, flags, brand));
emsdevices.back()->unique_id(++unique_id_count_);
Expand Down
16 changes: 14 additions & 2 deletions src/telegram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ void RxService::add(uint8_t * data, uint8_t length) {
rx_telegrams_.emplace_back(rx_telegram_id_++, std::move(telegram)); // add to queue
}

// add empty telegram to rx-queue
void RxService::add_empty(const uint8_t src, const uint8_t dest, const uint16_t type_id) {
auto telegram = std::make_shared<Telegram>(Telegram::Operation::RX, src, dest, type_id, 0, nullptr, 0);
// only if queue is not full
if (rx_telegrams_.size() < MAX_RX_TELEGRAMS) {
rx_telegrams_.emplace_back(rx_telegram_id_++, std::move(telegram)); // add to queue
}
}

// start and initialize Tx
// send out request to EMS bus for all devices
void TxService::start() {
Expand Down Expand Up @@ -543,14 +552,14 @@ void TxService::send_raw(const char * telegram_data) {

// get first value, which should be the src
if ((p = strtok(telegram, " ,"))) { // delimiter
strlcpy(value, p, 10);
strlcpy(value, p, sizeof(value));
data[0] = (uint8_t)strtol(value, 0, 16);
}

// and iterate until end
while (p != 0) {
if ((p = strtok(nullptr, " ,"))) {
strlcpy(value, p, 10);
strlcpy(value, p, sizeof(value));
uint8_t val = (uint8_t)strtol(value, 0, 16);
data[++count] = val;
}
Expand All @@ -576,6 +585,9 @@ void TxService::retry_tx(const uint8_t operation, const uint8_t * data, const ui
(operation == Telegram::Operation::TX_WRITE) ? F("Write") : F("Read"),
MAXIMUM_TX_RETRIES,
telegram_last_->to_string().c_str());
if (operation == Telegram::Operation::TX_READ) {
EMSESP::rxservice_.add_empty(telegram_last_->dest, telegram_last_->src, telegram_last_->type_id);
}
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/telegram.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class RxService : public EMSbus {

void loop();
void add(uint8_t * data, uint8_t length);
void add_empty(const uint8_t src, const uint8_t dst, const uint16_t type_id);

uint32_t telegram_count() const {
return telegram_count_;
Expand Down

0 comments on commit 0e480bb

Please sign in to comment.