Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ and the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed
- **Techem meters not recognised.** Several Techem MVT rows had the
version and type bytes swapped relative to wmbusmeters
(`mvt = TCH,<version>,<type>`), so MK-Radio 3/4/3a water, Compact V
heat, Vario 451 heat and TSD2 smoke frames fell through to the
generic walker. Rows now match wmbusmeters `drivers/src/*.xmq`.
- **Vario 451 kWh 100× too high.** The MJ→kWh conversion used
`raw × 250 / 9` instead of `raw / 3.6`.
- Vario 451 MID (v0x17) and Vario 411 (v0x28) send OMS DIF/VIF
records and now use the generic walker instead of the compact decoder.

### Added
- Techem MK-Radio water version 0x52 (seen in the field, same layout
as MK-Radio 3).
- Water titles show warm/cold water; MK-Radio 4 shows billing dates.
- TSD2 smoke detector status (OK / SMOKE / DEFECT) and billing date.
- Host tests `tests/test_techem_water.c` and `tests/test_techem_other.c`
using wmbusmeters test vectors.

## [1.1.1] — 2026-05-01

### Fixed
Expand Down
6 changes: 6 additions & 0 deletions drivers/engine/registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
extern const WmbusDriver wmbus_drv_techem_fhkv;
extern const WmbusDriver wmbus_drv_techem_mkradio3;
extern const WmbusDriver wmbus_drv_techem_mkradio4;
extern const WmbusDriver wmbus_drv_techem_mkradio4a;
extern const WmbusDriver wmbus_drv_techem_compact5;
extern const WmbusDriver wmbus_drv_techem_vario;
extern const WmbusDriver wmbus_drv_techem_vario_oms;
extern const WmbusDriver wmbus_drv_techem_smoke;
extern const WmbusDriver wmbus_drv_techem_tsd2;

/* === HCA drivers with custom 12-byte preamble === */
extern const WmbusDriver wmbus_drv_qundis_hca;
Expand Down Expand Up @@ -146,9 +149,12 @@ const WmbusDriver* const wmbus_engine_registry[] = {
&wmbus_drv_techem_fhkv,
&wmbus_drv_techem_mkradio3,
&wmbus_drv_techem_mkradio4,
&wmbus_drv_techem_mkradio4a,
&wmbus_drv_techem_compact5,
&wmbus_drv_techem_vario,
&wmbus_drv_techem_vario_oms,
&wmbus_drv_techem_smoke,
&wmbus_drv_techem_tsd2,
&wmbus_drv_qundis_hca,
&wmbus_drv_ista_hca,
&wmbus_drv_brunata_hca,
Expand Down
5 changes: 2 additions & 3 deletions drivers/europe/techem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ right decoder.

## Known limitations

- The Vario heat decoder uses an integer GJ→kWh approximation
(raw × 250 / 9). The largest possible 16-bit raw value rounds
to within ±0.06 kWh of the IEEE-double calculation.
- The Vario heat decoder converts MJ to kWh with integer math
(raw × 5 / 18, i.e. raw / 3.6), rounded to the nearest kWh.
- Smoke alarm bit semantics are not public; we surface the
status byte verbatim so a non-zero value flags an event.
36 changes: 25 additions & 11 deletions drivers/europe/techem/_compact.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ size_t techem_decode_fhkv(uint8_t version,
return pos;
}

size_t techem_decode_water(bool with_dates,
size_t techem_decode_water(const char* title, bool with_dates,
const uint8_t* a, size_t l,
char* o, size_t cap) {
if(l < 9) return techem_hex_dump(a, l, o, cap, "Techem water short");
Expand All @@ -111,7 +111,7 @@ size_t techem_decode_water(bool with_dates,
uint32_t total_dl = (uint32_t)prev + curr;

size_t pos = 0;
pos += append(o, cap, pos, "Techem water\n");
pos += append(o, cap, pos, "%s\n", title ? title : "Techem water");
pos += append(o, cap, pos, "Now %lu.%lu m3\n",
(unsigned long)(total_dl / 10), (unsigned long)(total_dl % 10));
pos += append(o, cap, pos, "Period %u.%u m3\n",
Expand All @@ -129,7 +129,7 @@ size_t techem_decode_water(bool with_dates,
techem_curr_date(curr_date_w, yr_prev, day_prev, mon_prev,
dcurr, sizeof(dcurr));
pos += append(o, cap, pos, "Reset %s\n", dprev);
pos += append(o, cap, pos, "Ends %s\n", dcurr);
pos += append(o, cap, pos, "Read %s\n", dcurr);
}
return pos;
}
Expand All @@ -152,16 +152,14 @@ size_t techem_decode_compact5(const uint8_t* a, size_t l,
size_t techem_decode_vario(const uint8_t* a, size_t l,
char* o, size_t cap) {
if(l < 9) return techem_hex_dump(a, l, o, cap, "Vario heat short");
/* Raw u16 = "GJ × 1000". Convert to kWh via integer math:
* 1 GJ = 1e9 J = 1e9 / 3600 Wh ≈ 277.778 kWh
* raw / 1000 GJ × (1000 × 1000 / 3600) kWh/GJ
* = raw × (1000 / 3600) / 1
* = raw × 250 / 9 (exact rational form)
* Width: raw ≤ 65535 → kWh ≤ 1820972. Fits in u32. */
/* Raw u16 = "GJ × 1000" (MJ). 1 GJ = 277.78 kWh, so
* kWh = raw / 1000 × 277.78 = raw / 3.6 = raw × 5 / 18
* which matches wmbusmeters vario451.xmq (`raw / 3.6 * 1 kwh`).
* Rounded to the nearest kWh. */
uint16_t prev_raw = (uint16_t)(a[3] | (a[4] << 8));
uint16_t curr_raw = (uint16_t)(a[7] | (a[8] << 8));
uint32_t prev_kwh = (uint32_t)((uint64_t)prev_raw * 250 / 9);
uint32_t curr_kwh = (uint32_t)((uint64_t)curr_raw * 250 / 9);
uint32_t prev_kwh = ((uint32_t)prev_raw * 5 + 9) / 18;
uint32_t curr_kwh = ((uint32_t)curr_raw * 5 + 9) / 18;

/* GJ to two decimals: raw / 1000 GJ → raw / 10 in centi-GJ. */
uint32_t prev_gj_x100 = (uint32_t)prev_raw / 10;
Expand All @@ -185,6 +183,22 @@ size_t techem_decode_vario(const uint8_t* a, size_t l,
return pos;
}

size_t techem_decode_tsd2(const uint8_t* a, size_t l,
char* o, size_t cap) {
if(l < 3) return techem_hex_dump(a, l, o, cap, "Techem TSD2 short");
const char* st = a[0] == 0x00 ? "OK" :
a[0] == 0x01 ? "SMOKE" :
a[0] == 0x80 ? "DEFECT" : NULL;
char dprev[16];
techem_prev_date((uint16_t)(a[1] | (a[2] << 8)), dprev, sizeof(dprev), NULL);
size_t pos = 0;
pos += append(o, cap, pos, "Techem TSD2 smoke\n");
if(st) pos += append(o, cap, pos, "Status %s\n", st);
else pos += append(o, cap, pos, "Status 0x%02X\n", a[0]);
pos += append(o, cap, pos, "Reset %s\n", dprev);
return pos;
}

size_t techem_decode_smoke(const uint8_t* a, size_t l,
char* o, size_t cap) {
size_t pos = 0;
Expand Down
12 changes: 8 additions & 4 deletions drivers/europe/techem/_compact.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ size_t techem_decode_fhkv(uint8_t version,
const uint8_t* a, size_t l,
char* o, size_t cap);

/* Decode an MK-Radio water frame. `with_dates` enables the
* billing-period date fields (mkradio3 has them, mkradio4 ships
* zero-filled date bytes that aren't worth showing). */
size_t techem_decode_water(bool with_dates,
/* Decode an MK-Radio water frame. `title` is the first output line
* (e.g. "Techem warm water"). `with_dates` enables the billing-period
* date fields; invalid dates render as "-". */
size_t techem_decode_water(const char* title, bool with_dates,
const uint8_t* a, size_t l,
char* o, size_t cap);

Expand All @@ -46,3 +46,7 @@ size_t techem_decode_vario(const uint8_t* a, size_t l,
* is not public; we surface status + flag bytes verbatim. */
size_t techem_decode_smoke(const uint8_t* a, size_t l,
char* o, size_t cap);

/* Decode a TSD2 smoke detector frame: status + previous billing date. */
size_t techem_decode_tsd2(const uint8_t* a, size_t l,
char* o, size_t cap);
11 changes: 6 additions & 5 deletions drivers/europe/techem/compact5_heat.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
#include "../../engine/driver.h"
#include "_compact.h"

/* (version, type) per wmbusmeters `drivers/src/compact5.xmq`. */
static const WmbusMVT k_mvt[] = {
{"TCH", 0x04, 0x45},
{"TCH", 0xC3, 0x45},
{"TCH", 0x43, 0x45},
{"TCH", 0x43, 0x39},
{"TCH", 0x43, 0x22},
{"TCH", 0x45, 0x04},
{"TCH", 0x45, 0xC3},
{"TCH", 0x22, 0x43},
{"TCH", 0x45, 0x43},
{"TCH", 0x39, 0x43},
{ {0}, 0, 0 }
};

Expand Down
5 changes: 0 additions & 5 deletions drivers/europe/techem/fhkv_hca.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ static const WmbusMVT k_mvt[] = {
{"TCH", 0x69, 0x80},
{"TCH", 0x94, 0x08},
{"TCH", 0x94, 0x80},
/* Some Techem firmwares ship the version / medium bytes swapped in
* the link header — wmbusmeters lists both orderings under the same
* `fhkvdataiii` driver. */
{"TCH", 0x80, 0x69},
{"TCH", 0x80, 0x94},
{ {0}, 0, 0 }
};

Expand Down
3 changes: 2 additions & 1 deletion drivers/europe/techem/mkradio3a.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ static size_t decode_mk3a(uint16_t m, uint8_t v, uint8_t med,
return pos;
}

/* wmbusmeters: mvt = TCH,50,72 (version 0x50, type 0x72). */
static const WmbusMVT k_mvt[] = {
{"TCH", 0x72, 0x50},
{"TCH", 0x50, 0x72},
{ {0}, 0, 0 }
};
const WmbusDriver wmbus_drv_techem_mkradio3a = {
Expand Down
69 changes: 50 additions & 19 deletions drivers/europe/techem/mkradio_water.c
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
/* Techem MK-Radio 3 / 4 / 4a water meter.
*
* MK-Radio 3 telegrams carry billing-period date fields; MK-Radio
* 4 and 4a omit them (the bytes are zero-filled). MVT lists are
* mirrored from wmbusmeters `src/driver_mkradio3.cc`,
* `src/driver_mkradio4.cc`, and `drivers/src/mkradio4a.xmq`. */
* MVT lists mirror wmbusmeters `drivers/src/mkradio3.xmq`,
* `mkradio4.xmq` and `mkradio4a.xmq`. Their `mvt = TCH,<ver>,<type>`
* lines are (manufacturer, version, type) — the same order as our
* WmbusMVT struct. Techem uses type 0x62 for warm water and 0x72 for
* cold water.
*
* Payload (bytes after CI 0xA2):
* [0] status
* [1..2] previous billing date (day bits 0-4, month 5-8, year 9-14)
* [3..4] volume at previous billing date, 0.1 m3
* [5..6] current date (day bits 4-8, month 9-12)
* [7..8] volume since previous billing date, 0.1 m3 */

#include "../../engine/driver.h"
#include "_compact.h"

/* MK-Radio 3 — version 0x62/0x72 + medium 0x74. */
static const char* water_title(uint8_t med) {
if(med == 0x62) return "Techem warm water";
if(med == 0x72) return "Techem cold water";
return "Techem water";
}

/* MK-Radio 3 — version 0x74 (wmbusmeters mkradio3).
* Version 0x52 is not in wmbusmeters; it was seen in the field with
* the same layout and valid billing dates, so it is decoded the same way. */
static const WmbusMVT k_mvt_mk3[] = {
{"TCH", 0x62, 0x74},
{"TCH", 0x72, 0x74},
{"TCH", 0x74, 0x62},
{"TCH", 0x74, 0x72},
{"TCH", 0x52, 0x62},
{"TCH", 0x52, 0x72},
{ {0}, 0, 0 }
};
static size_t decode_mk3(uint16_t m, uint8_t v, uint8_t med,
const uint8_t* a, size_t l, char* o, size_t cap) {
(void)m; (void)v; (void)med;
return techem_decode_water(/* with_dates */ true, a, l, o, cap);
(void)m; (void)v;
return techem_decode_water(water_title(med), /* with_dates */ true, a, l, o, cap);
}
const WmbusDriver wmbus_drv_techem_mkradio3 = {
.id = "techem-mkradio3",
Expand All @@ -26,25 +44,38 @@ const WmbusDriver wmbus_drv_techem_mkradio3 = {
.decode = decode_mk3,
};

/* MK-Radio 4 / 4a — versions 0x62/0x72/0x95 + mediums 0x70/0x95/0x37. */
/* MK-Radio 4 — versions 0x95 / 0x70 (wmbusmeters mkradio4).
* wmbusmeters ignores the date bytes, but field captures of 0x95
* carry valid billing dates, so they are shown (invalid ones render "-"). */
static const WmbusMVT k_mvt_mk4[] = {
{"TCH", 0x62, 0x70},
{"TCH", 0x72, 0x70},
{"TCH", 0x62, 0x95},
{"TCH", 0x72, 0x95},
{"TCH", 0x95, 0x37},
{"TCH", 0x72, 0x50}, /* MK Radio 3a — wmbusmeters mkradio3a */
{"HYD", 0xFE, 0x06}, /* mkradio4a OEM rebadge */
{"TCH", 0x95, 0x62},
{"TCH", 0x95, 0x72},
{"TCH", 0x70, 0x62},
{"TCH", 0x70, 0x72},
{ {0}, 0, 0 }
};
static size_t decode_mk4(uint16_t m, uint8_t v, uint8_t med,
const uint8_t* a, size_t l, char* o, size_t cap) {
(void)m; (void)v; (void)med;
return techem_decode_water(/* with_dates */ false, a, l, o, cap);
(void)m; (void)v;
return techem_decode_water(water_title(med), /* with_dates */ true, a, l, o, cap);
}
const WmbusDriver wmbus_drv_techem_mkradio4 = {
.id = "techem-mkradio4",
.title = "Techem MK-Radio4 water",
.mvt = k_mvt_mk4,
.decode = decode_mk4,
};

/* MK-Radio 4a — wmbusmeters mkradio4a. This one is a standard OMS
* frame (DIF/VIF), so it goes through the generic walker. */
static const WmbusMVT k_mvt_mk4a[] = {
{"TCH", 0x95, 0x37},
{"HYD", 0xFE, 0x06},
{ {0}, 0, 0 }
};
const WmbusDriver wmbus_drv_techem_mkradio4a = {
.id = "techem-mkradio4a",
.title = "Techem MK-Radio4a water",
.mvt = k_mvt_mk4a,
.decode = NULL,
};
24 changes: 20 additions & 4 deletions drivers/europe/techem/smoke.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
#include "_compact.h"

static const WmbusMVT k_mvt[] = {
/* Wildcard medium 0x1A covers OMS-canonical smoke-detector
* frames; the second tuple is the Techem-private medium. */
/* Wildcard version, OMS smoke-detector type 0x1A. */
{"TCH", 0xFF, 0x1A},
{"TCH", 0x00, 0x76}, /* legacy code seen in older Techem stock */
{"TCH", 0xF0, 0x76}, /* TSD2 — wmbusmeters tsd2 driver */
{ {0}, 0, 0 }
};

Expand All @@ -26,3 +23,22 @@ const WmbusDriver wmbus_drv_techem_smoke = {
.mvt = k_mvt,
.decode = decode,
};

/* TSD2 — wmbusmeters `drivers/src/tsd2.xmq`: version 0x76, type 0xF0.
* Payload [0] status (0x00 OK, 0x01 smoke, 0x80 defect),
* [1..2] previous billing date. */
static const WmbusMVT k_mvt_tsd2[] = {
{"TCH", 0x76, 0xF0},
{ {0}, 0, 0 }
};
static size_t decode_tsd2(uint16_t m, uint8_t v, uint8_t med,
const uint8_t* a, size_t l, char* o, size_t cap) {
(void)m; (void)v; (void)med;
return techem_decode_tsd2(a, l, o, cap);
}
const WmbusDriver wmbus_drv_techem_tsd2 = {
.id = "techem-tsd2",
.title = "Techem TSD2 smoke",
.mvt = k_mvt_tsd2,
.decode = decode_tsd2,
};
27 changes: 18 additions & 9 deletions drivers/europe/techem/vario_heat.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@
#include "../../engine/driver.h"
#include "_compact.h"

/* (version, type) per wmbusmeters `drivers/src/vario451.xmq`. */
static const WmbusMVT k_mvt[] = {
{"TCH", 0x04, 0x27},
{"TCH", 0xC3, 0x27},
/* The MID-certified Vario 451 ships under (TCH, 0x17, 0x04)
* per the wmbusmeters declarative driver `vario451mid.xmq`. */
{"TCH", 0x17, 0x04},
/* Vario 411 (older heat meter) — ver 0x28, med 0x04. The
* billing-period offsets are identical, so the Vario decoder
* applies. */
{"TCH", 0x28, 0x04},
{"TCH", 0x27, 0x04},
{"TCH", 0x27, 0xC3},
{ {0}, 0, 0 }
};

Expand All @@ -31,3 +25,18 @@ const WmbusDriver wmbus_drv_techem_vario = {
.mvt = k_mvt,
.decode = decode,
};

/* Vario 451 MID (0x17) and Vario 411 (0x28) send standard OMS
* DIF/VIF records (wmbusmeters `vario451mid.xmq`, `vario411.xmq`),
* not the compact layout, so they use the generic walker. */
static const WmbusMVT k_mvt_oms[] = {
{"TCH", 0x17, 0x04},
{"TCH", 0x28, 0x04},
{ {0}, 0, 0 }
};
const WmbusDriver wmbus_drv_techem_vario_oms = {
.id = "techem-vario-oms",
.title = "Techem Vario heat",
.mvt = k_mvt_oms,
.decode = NULL,
};
Loading