@@ -25,7 +25,7 @@ for further processing by an Application layer (outside this program).
25
25
// Convert two BCD encoded nibbles to an integer
26
26
static unsigned bcd2int (uint8_t bcd )
27
27
{
28
- return 10 * (bcd >> 4 ) + (bcd & 0xF );
28
+ return 10 * (bcd >> 4 ) + (bcd & 0xf );
29
29
}
30
30
31
31
// Mapping from 6 bits to 4 bits. "3of6" coding used for Mode T
@@ -156,9 +156,9 @@ typedef struct {
156
156
uint8_t tpci ;
157
157
uint8_t apci ;
158
158
/* Q-walk_by */
159
- uint32_t q_total ;
160
- uint32_t q_lastyear ;
161
- uint32_t q_lastmonth ;
159
+ float q_total ;
160
+ float q_lastyear ;
161
+ float q_lastmonth ;
162
162
} m_bus_block2_t ;
163
163
164
164
// Data structure for block 1
@@ -785,15 +785,19 @@ static int parse_block2(const m_bus_data_t *in, m_bus_block1_t *block1)
785
785
b2 -> CW = (b [9 ] << 8 ) | (b [8 ]);
786
786
b2 -> pl_offset = BLOCK1A_SIZE - 2 + 8 ;
787
787
// Note the offsets to skip block CRCs
788
- b2 -> q_total = (( uint32_t ) b [20 + 2 ] << 24 ) | (b [19 + 2 ] << 16 ) | (b [18 + 2 ] << 8 ) | (b [17 + 2 ]);
789
- b2 -> q_lastyear = (( uint32_t ) b [26 + 2 ] << 24 ) | (b [25 + 2 ] << 16 ) | (b [24 + 2 ] << 8 ) | (b [23 + 2 ]);
790
- b2 -> q_lastmonth = (( uint32_t ) b [32 + 4 ] << 24 ) | (b [31 + 2 ] << 16 ) | (b [30 + 2 ] << 8 ) | (b [29 + 2 ]);
788
+ b2 -> q_total = bcd2int ( b [20 + 2 ]) * 1000000 + bcd2int (b [19 + 2 ]) * 10000 + bcd2int (b [18 + 2 ]) * 100 + bcd2int (b [17 + 2 ]);
789
+ b2 -> q_lastyear = bcd2int ( b [26 + 2 ]) * 1000000 + bcd2int (b [25 + 2 ]) * 10000 + bcd2int (b [24 + 2 ]) * 100 + bcd2int (b [23 + 2 ]);
790
+ b2 -> q_lastmonth = bcd2int ( b [32 + 4 ]) * 1000000 + bcd2int (b [31 + 2 ]) * 10000 + bcd2int (b [30 + 2 ]) * 100 + bcd2int (b [29 + 2 ]);
791
791
if (block1 -> A_DevType == 6 ) {
792
792
/* WarmWater */
793
+ // Value factor is 0.001, e.g. 123.456 m3
794
+ b2 -> q_total /= 1000.0f ;
795
+ b2 -> q_lastyear /= 1000.0f ;
796
+ b2 -> q_lastmonth /= 1000.0f ;
793
797
}
794
798
if (block1 -> A_DevType == 8 ) {
795
799
/* Heat Cost Allocator */
796
- // snprintf(extra, sizeof(extra), "%02x%02x%02x%02x%02x", b[6], b[7], b[8], b[9], b[10]);
800
+ // Value factor is 1, e.g. 123456 m3
797
801
}
798
802
}
799
803
// fprintf(stderr, "Instantaneous Value: %02x%02x : %f\n",b[9],b[10],((b[10]<<8)|b[9])*0.01);
@@ -936,9 +940,9 @@ static int m_bus_output_data(r_device *decoder, bitbuffer_t *bitbuffer, const m_
936
940
// "L", "Length", DATA_INT, block1->L,
937
941
"data_length" , "Data Length" , DATA_INT , out -> length ,
938
942
"data" , "Data" , DATA_STRING , str_buf ,
939
- "Q_total" , "Q_total" , DATA_COND , block1 -> block2 .CI == 0x78 , DATA_FORMAT , "%x m3" , DATA_INT , block1 -> block2 .q_total ,
940
- "Q_lastyear" , "Q_lastyear" , DATA_COND , block1 -> block2 .CI == 0x78 , DATA_FORMAT , "%x m3" , DATA_INT , block1 -> block2 .q_lastyear ,
941
- "Q_lastmonth" , "Q_lastmonth" , DATA_COND , block1 -> block2 .CI == 0x78 , DATA_FORMAT , "%x m3" , DATA_INT , block1 -> block2 .q_lastmonth ,
943
+ "Q_total" , "Q_total" , DATA_COND , block1 -> block2 .CI == 0x78 , DATA_FORMAT , "%.3f m3" , DATA_DOUBLE , block1 -> block2 .q_total ,
944
+ "Q_lastyear" , "Q_lastyear" , DATA_COND , block1 -> block2 .CI == 0x78 , DATA_FORMAT , "%.3f m3" , DATA_DOUBLE , block1 -> block2 .q_lastyear ,
945
+ "Q_lastmonth" , "Q_lastmonth" , DATA_COND , block1 -> block2 .CI == 0x78 , DATA_FORMAT , "%.3f m3" , DATA_DOUBLE , block1 -> block2 .q_lastmonth ,
942
946
"mic" , "Integrity" , DATA_STRING , "CRC" ,
943
947
NULL );
944
948
/* clang-format on */
0 commit comments