Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added second key for izar watermeters #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions driver_izar.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

struct Izar: Driver
{
// the method Driver::processContent(Telegram *t) in driver_izar.cc
// (https://github.com/wmbusmeters/wmbusmeters/blob/master/src/driver_izar.cc:187)
// uses two different keys:
const uint32_t keys[3] = {0xb71f0ae8, 0xdfd109e8, 0x0};

Izar(std::string key = "") : Driver(std::string("izar"), key) {};
virtual esphome::optional<std::map<std::string, double>> get_values(std::vector<unsigned char> &telegram) override {
std::map<std::string, double> ret_val{};
Expand Down Expand Up @@ -137,15 +142,21 @@ struct Izar: Driver
return 0;
}

uint32_t key = 0xdfd109e8;
key ^= uintFromBytes(encoded + 2);
key ^= uintFromBytes(encoded + 6);
key ^= uintFromBytes(encoded + 10);

const uint8_t size = len - 15;
for (uint8_t i = 0; i < size; i++) {
key = hashShiftKey(key);
decoded[i] = encoded[i + 15] ^ (key & 0xFF);
const uint8_t size = len - 15;
for (uint32_t key: keys) {
if (!key) {
return 0;
}
key ^= uintFromBytes(encoded + 2);
key ^= uintFromBytes(encoded + 6);
key ^= uintFromBytes(encoded + 10);

for (uint8_t i = 0; i < size; i++) {
key = hashShiftKey(key);
decoded[i] = encoded[i + 15] ^ (key & 0xFF);
}
if (decoded[0] == 0x4B)
break;
}

if (decoded[0] != 0x4B) {
Expand All @@ -154,4 +165,4 @@ struct Izar: Driver

return size;
}
};
};