Skip to content

Commit 5fe0592

Browse files
committed
Add support for Q-walk_by to Wireless-MBus
1 parent ce56acc commit 5fe0592

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/devices/m_bus.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ typedef struct {
155155
uint8_t l_npci;
156156
uint8_t tpci;
157157
uint8_t apci;
158+
/* Q-walk_by */
159+
uint32_t q_total;
160+
uint32_t q_lastyear;
161+
uint32_t q_lastmonth;
158162
} m_bus_block2_t;
159163

160164
// Data structure for block 1
@@ -760,6 +764,36 @@ static int parse_block2(const m_bus_data_t *in, m_bus_block1_t *block1)
760764
b2->CW = b[4]<<8 | b[3];
761765
b2->pl_offset = BLOCK1A_SIZE-2 + 5;
762766
}
767+
768+
/* Q-walk_by */
769+
/* based on leaked infos */
770+
/* 000: CI:120 */
771+
/* 000: 0x780dff5f Magic for QUNDIS walk_by */
772+
/* 004: 0x35 L:53 Length of walk_by field (under investigation) */
773+
/* 005: 0x00 ST:0 Status 0= No Error */
774+
/* 006: 0x82 unknown */
775+
/* 007: AC AccessNumber */
776+
/* 008: 0x0000 CW:0 no encryption */
777+
/* 018: 0x00000000 V:total BCD LSB first */
778+
/* 024: 0x00000000 V:lastyear */
779+
/* 036: 0x00000000 V:lastmonth */
780+
/* timestamps following */
781+
u_int32_t ci_magic = ((uint32_t)b[0] << 24) | (b[1] << 16) | (b[2] << 8) | (b[3]);
782+
if (ci_magic == 0x780dff5f) {
783+
b2->AC = b[7];
784+
b2->ST = b[5];
785+
b2->CW = (b[9] << 8) | (b[8]);
786+
b2->pl_offset = BLOCK1A_SIZE - 2 + 8;
787+
b2->q_total = ((uint32_t)b[20] << 24) | (b[19] << 16) | (b[18] << 8) | (b[17]);
788+
b2->q_lastyear = ((uint32_t)b[26] << 24) | (b[25] << 16) | (b[24] << 8) | (b[23]);
789+
b2->q_lastmonth = ((uint32_t)b[38] << 24) | (b[37] << 16) | (b[36] << 8) | (b[35]);
790+
if (block1->A_DevType == 6) {
791+
/* WarmWater */
792+
}
793+
if (block1->A_DevType == 8) {
794+
// snprintf(extra, sizeof(extra), "%02x%02x%02x%02x%02x", b[6], b[7], b[8], b[9], b[10]);
795+
}
796+
}
763797
// fprintf(stderr, "Instantaneous Value: %02x%02x : %f\n",b[9],b[10],((b[10]<<8)|b[9])*0.01);
764798
}
765799
return 0;
@@ -900,6 +934,9 @@ static int m_bus_output_data(r_device *decoder, bitbuffer_t *bitbuffer, const m_
900934
// "L", "Length", DATA_INT, block1->L,
901935
"data_length", "Data Length", DATA_INT, out->length,
902936
"data", "Data", DATA_STRING, str_buf,
937+
"Q_total", "Q_total", DATA_COND, block1->block2.CI == 0x78, DATA_FORMAT, "%d m3", DATA_INT, block1->block2.q_total,
938+
"Q_lastyear", "Q_lastyear", DATA_COND, block1->block2.CI == 0x78, DATA_FORMAT, "%d m3", DATA_INT, block1->block2.q_lastyear,
939+
"Q_lastmonth", "Q_lastmonth", DATA_COND, block1->block2.CI == 0x78, DATA_FORMAT, "%d m3", DATA_INT, block1->block2.q_lastmonth,
903940
"mic", "Integrity", DATA_STRING, "CRC",
904941
NULL);
905942
/* clang-format on */

0 commit comments

Comments
 (0)