Skip to content

Commit

Permalink
Add support for Q-walk_by to Wireless-MBus
Browse files Browse the repository at this point in the history
  • Loading branch information
zuckschwerdt committed Jul 14, 2024
1 parent ce56acc commit 26a3b1f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/devices/m_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ typedef struct {
uint8_t l_npci;
uint8_t tpci;
uint8_t apci;
/* Q-walk_by */
uint32_t q_total;
uint32_t q_lastyear;
uint32_t q_lastmonth;
} m_bus_block2_t;

// Data structure for block 1
Expand Down Expand Up @@ -760,6 +764,36 @@ static int parse_block2(const m_bus_data_t *in, m_bus_block1_t *block1)
b2->CW = b[4]<<8 | b[3];
b2->pl_offset = BLOCK1A_SIZE-2 + 5;
}

/* Q-walk_by */
/* based on leaked infos */
/* 000: CI:120 */
/* 000: 0x780dff5f Magic for QUNDIS walk_by */
/* 004: 0x35 L:53 Length of walk_by field (under investigation) */
/* 005: 0x00 ST:0 Status 0= No Error */
/* 006: 0x82 unknown */
/* 007: AC AccessNumber */
/* 008: 0x0000 CW:0 no encryption */
/* 018: 0x00000000 V:total BCD LSB first */
/* 024: 0x00000000 V:lastyear */
/* 036: 0x00000000 V:lastmonth */
/* timestamps following */
uint32_t ci_magic = ((uint32_t)b[0] << 24) | (b[1] << 16) | (b[2] << 8) | (b[3]);
if (ci_magic == 0x780dff5f) {
b2->AC = b[7];
b2->ST = b[5];
b2->CW = (b[9] << 8) | (b[8]);
b2->pl_offset = BLOCK1A_SIZE - 2 + 8;
b2->q_total = ((uint32_t)b[20] << 24) | (b[19] << 16) | (b[18] << 8) | (b[17]);
b2->q_lastyear = ((uint32_t)b[26] << 24) | (b[25] << 16) | (b[24] << 8) | (b[23]);
b2->q_lastmonth = ((uint32_t)b[38] << 24) | (b[37] << 16) | (b[36] << 8) | (b[35]);
if (block1->A_DevType == 6) {
/* WarmWater */
}
if (block1->A_DevType == 8) {
// snprintf(extra, sizeof(extra), "%02x%02x%02x%02x%02x", b[6], b[7], b[8], b[9], b[10]);
}
}
// fprintf(stderr, "Instantaneous Value: %02x%02x : %f\n",b[9],b[10],((b[10]<<8)|b[9])*0.01);
}
return 0;
Expand Down Expand Up @@ -900,6 +934,9 @@ static int m_bus_output_data(r_device *decoder, bitbuffer_t *bitbuffer, const m_
// "L", "Length", DATA_INT, block1->L,
"data_length", "Data Length", DATA_INT, out->length,
"data", "Data", DATA_STRING, str_buf,
"Q_total", "Q_total", DATA_COND, block1->block2.CI == 0x78, DATA_FORMAT, "%d m3", DATA_INT, block1->block2.q_total,
"Q_lastyear", "Q_lastyear", DATA_COND, block1->block2.CI == 0x78, DATA_FORMAT, "%d m3", DATA_INT, block1->block2.q_lastyear,
"Q_lastmonth", "Q_lastmonth", DATA_COND, block1->block2.CI == 0x78, DATA_FORMAT, "%d m3", DATA_INT, block1->block2.q_lastmonth,
"mic", "Integrity", DATA_STRING, "CRC",
NULL);
/* clang-format on */
Expand Down

0 comments on commit 26a3b1f

Please sign in to comment.