M-Bus 协议理解
M-Bus 协议理解
0. 参考文档
协议文档理解基于:
- 《EN 13757-2:2018》: Wired M-Bus Communication
- 《EN 13757-3:2018》: Application Protocols
- 《EN 13757-4:2019》: Wireless M-Bus Communication
- 《CEN/TR 17167:2018》: Accompanying TR to EN 13757-2,-3 and -7, Examples and supplementary information
TR -> Technical Report(技术报告)
1. 应用层
应用层附录
DataRecord 数据格式
Type M: Compound CP_LVAR: Date and time/duration
“数据字段 1101b(变长 LVAR = E2 到 EAh)
此时间格式按协调世界时(UTC)编码。它对应于纪元时间(Epoch time)。此数据类型的长度和分辨率均可调整。”
- DIF 的数据字段编码(低 4 位)= 1101b(=0xD),表示”变长 LVAR”;见 13757-3 6.3.3 数据字段 表 4-数据字段的编码
- LVAR [E2, EA] 属于 LVAR 划定范围的 [E0h ~ EFh],数据类型为二进制数,字节数 = (LVAR - E0h);所以 type M 的数据域是 [2, 10] bytes;LVAR 解释见 13757-3 6.3.3 数据字段 表 5-LVAR 解释
- Epoch time (纪元时间),”自某个固定起点(epoch)起累计的时间”;这里起点是 2013-01-01 UTC 或 1970-01-01 UTC(Unix)
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | Duration since the starting time: |
|---|---|---|---|---|---|---|---|---|
| …… | I(X−8) [0 to (X−9)] <(−2(X−9)+1) to (+2(X−9)−1)> a | |||||||
| X−9 | X−16 | <−2X−9> : signals “invalid” | ||||||
| X−1 | X−2 X−3 | X−4X−8 | Time Offset: I5 [(X−8) to (X−4)] | |||||
| <−16> : relative time (duration)a,b,c <−12 to +14> : offset to UTC in hoursa,b Resolution: B2 [(X−3) to (X−2)] <0> : 2 s <1> : 1 s <2> : 1/256 s <3> : 1/32768 s Starting time: B1 [X−1] <0> : 2013−01−01 at 00:00:00 (UTC)c <1> : 1970−01−01 at 00:00:00 (UNIX-Time) | ||||||||
| a Negative values are in two’s complement. b Other values are reserved for future uses. c In case of relative time the bit Starting time shall be 0. | ||||||||
“Type M 时间格式始终包含协调世界时(UTC)。本地时区相对 UTC 的偏差可在”Time Offset”字段中予以考虑。此时间格式不得使用夏令时。
注: 此格式不支持那些相对 UTC 带有”不足一小时的小数部分”的时区。
时间偏移为 10000b 时,指定一个相对于某参考时间的时间点。此时”Starting time”字段的值无关紧要。若未声明特定参考时间,则应使用传输发生的时间。”
I: Signed Integer 类型;- I5: 5 bit 构成的 int 值;
- 其他地方还有
UI(Unsigned Integer),UI5: 即 5 bit 构成的 unsigned int 值; - 有脚注表示负数以二进制补码形式表示时 (如表中脚注 a),看到的位按补码理解(正数,原码和补码相同)
B: Array of Bits;- 例:B2 -> 两个 bit
X: Number of applied bits as defined in the data field(see Table 4);- bits 数 = data filed 指示字节长度 * 8
例:
B1[X-1],1 个 bit:bit(X-1)- Duration since the starting time:
I(X-8)[0 to (X-9)] <(-2^(X-9)+1) to (+2^(X-9)-1)>^a- 这里是 tick 数,换算多长时间需乘以 resolution;
I(X-8): bit 数 = (字节数 * 8 - 8);[0 to (X-9)]: bit0 ~ bit(X-9) 范围的 X-8 个bit;- 按补码理解的话,范围应是
<(-2^(X-9)) to (+2^(X-9)-1)>^,但这里少了一位(-2^(X-9)),下一行解释了,拿(-2^(X-9))用作特殊含义:tick 数无效;
- Time Offset
- Time Offset 是
[-12, 14]时,表示格式是 DateTime,其 = StartingTime_UTC + (ticks * resolution) + TimeOffset_Hours - Time Offset 是
-16时,表示是 Duration,StartingTime 无关紧要 (bit(X-1) 固定为 0),其 = (ticks * resolution) + TimeOffset_Hours(多半是 0)
- Time Offset 是
This post is licensed under CC BY 4.0 by the author.