Skip to content

Commit

Permalink
Fix HCA output
Browse files Browse the repository at this point in the history
  • Loading branch information
zuckschwerdt committed Jul 15, 2024
1 parent 53a1a3f commit 7f11af4
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/devices/m_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,18 +773,20 @@ static int parse_block2(const m_bus_data_t *in, m_bus_block1_t *block1)
}

/* 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 */
/* 015: 0xffff V:total key */
/* 017: 0x00000000 V:total - BCD LSB first */
/* 021: 0xff2c V:lastyear key */
/* 023: 0x00000000 V:lastyear - BCD LSB first */
/* 027: 0x1e36 V:lastmonth key */
/* 029: 0x00000000 V:lastmonth - BCD LSB first */
/* timestamps following */
/* timestamps follow */
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];
Expand All @@ -798,14 +800,14 @@ static int parse_block2(const m_bus_data_t *in, m_bus_block1_t *block1)
if (block1->A_DevType == 6) {
/* WarmWater */
// Value factor is 0.001, e.g. 123.456 m3
b2->q_total_m3 = b2->q_total / 1000.0f;
b2->q_lastyear_m3 = b2->q_lastyear / 1000.0f;
b2->q_lastmonth_m3 = b2->q_lastmonth / 1000.0f;
b2->q_total_m3 = b2->q_total * 0.001f;
b2->q_lastyear_m3 = b2->q_lastyear * 0.001f;
b2->q_lastmonth_m3 = b2->q_lastmonth * 0.001f;
b2->q_mode = QDS_WW;
}
if (block1->A_DevType == 8) {
/* Heat Cost Allocator */
// Value factor is 1, e.g. 123456 m3
// Value factor is K (from an invoice), e.g. 123456*K kW/h
b2->q_mode = QDS_HCA;
}
}
Expand Down Expand Up @@ -952,9 +954,9 @@ static int m_bus_output_data(r_device *decoder, bitbuffer_t *bitbuffer, const m_
"Q_total_m3", "Q_total_m3", DATA_COND, block1->block2.q_mode == QDS_WW, DATA_FORMAT, "%.3f m3", DATA_DOUBLE, block1->block2.q_total_m3,
"Q_lastyear_m3", "Q_lastyear_m3", DATA_COND, block1->block2.q_mode == QDS_WW, DATA_FORMAT, "%.3f m3", DATA_DOUBLE, block1->block2.q_lastyear_m3,
"Q_lastmonth_m3", "Q_lastmonth_m3", DATA_COND, block1->block2.q_mode == QDS_WW, DATA_FORMAT, "%.3f m3", DATA_DOUBLE, block1->block2.q_lastmonth_m3,
"Q_total", "Q_total", DATA_COND, block1->block2.q_mode == QDS_HCA, DATA_DOUBLE, block1->block2.q_total,
"Q_lastyear", "Q_lastyear", DATA_COND, block1->block2.q_mode == QDS_HCA, DATA_DOUBLE, block1->block2.q_lastyear,
"Q_lastmonth", "Q_lastmonth", DATA_COND, block1->block2.q_mode == QDS_HCA, DATA_DOUBLE, block1->block2.q_lastmonth,
"Q_total", "Q_total", DATA_COND, block1->block2.q_mode == QDS_HCA, DATA_INT, block1->block2.q_total,
"Q_lastyear", "Q_lastyear", DATA_COND, block1->block2.q_mode == QDS_HCA, DATA_INT, block1->block2.q_lastyear,
"Q_lastmonth", "Q_lastmonth", DATA_COND, block1->block2.q_mode == QDS_HCA, DATA_INT, block1->block2.q_lastmonth,
"mic", "Integrity", DATA_STRING, "CRC",
NULL);
/* clang-format on */
Expand All @@ -963,7 +965,7 @@ static int m_bus_output_data(r_device *decoder, bitbuffer_t *bitbuffer, const m_
/* clang-format off */
data = data_int(data, "CI", "Control Info", "0x%02X", block1->block2.CI);
data = data_int(data, "AC", "Access number", "0x%02X", block1->block2.AC);
data = data_int(data, "ST", "Device Type", "0x%02X", block1->block2.ST);
data = data_int(data, "ST", "Status", "0x%02X", block1->block2.ST);
data = data_int(data, "CW", "Configuration Word", "0x%04X", block1->block2.CW);
/* clang-format on */
}
Expand Down

0 comments on commit 7f11af4

Please sign in to comment.