16 releases
0.0.15 | Oct 1, 2024 |
---|---|
0.0.14 | Sep 24, 2024 |
0.0.13 | Aug 18, 2024 |
0.0.11 | Jul 7, 2024 |
0.0.3 | Mar 26, 2024 |
#47 in Database implementations
Used in m-bus-parser-cli
175KB
3.5K
SLoC
m-bus-parser (wired)
Introduction
For contributing see CONTRIBUTING.md
m-bus-parser is an open source parser (sometimes also refered to as decoder and/or deserializer) of wired m-bus portocol and is written in rust.
"M-Bus or Meter-Bus is a European standard (EN 13757-2 physical and link layer, EN 13757-3 application layer) for the remote reading of water, gas or electricity meters. M-Bus is also usable for other types of consumption meters, such as heating systems or water meters. The M-Bus interface is made for communication on two wires, making it cost-effective." - Wikipedia
An outdated specification is available freely on the m-bus website. This document is a good starting point for understanding the protocol. There have been many other implementations of the specification.
Furthermore, the Open Metering System (OMS) Group has published a specification for the m-bus protocol. This specification is available for free on the OMS website or more specificially here.
such as a no longer maitained m-bus encoder and decoder by rscada written in c, jMbus written in java,Valley.Net.Protocols.MeterBus written in C#, tmbus written in javascript or pyMeterBus written in python.
Dependants and Deployments
NPM Wasm Package
The parser has been published as an npm package and can be used in the browser. An example of this can be seen under the url https://maebli.github.io/m-bus-parser/.
The source is in the wasm folder in this repos
CLI rust crate
There is a cli, the source is in the sub folder "cli" and is published on crates.io https://crates.io/crates/m-bus-parser-cli.
Python bindings
The are some python bindings, the source is in the sub folder "python" and is published on pypi https://pypi.org/project/pymbusparser/.
Visualization of Library Function
Do not get confused about the different types of frame types. The most important one to understand at first is the LongFrame
which is the most common frame type. The others are for example for searching for a slave or for setting the primary address of a slave. This is not of primary intrest for most users. Visualization was made with the help of the tool excalidraw.
Visualization of Serialized Application Layer
The searlized application layer above can be further broken into parsable parts.
Value Information Block Serialization
Aim
- suitable for embedded targets
no_std
- Follow the Rust API Guideline https://rust-lang.github.io/api-guidelines/
- minimal copy
Development status
The library is currently under development. It is able to parse the link layer but not the application layer. The next goal is to parse the application layer. Once this is achieved the library will be released as v0.1.0
. Further goals, such as decryption, will be set after this milestone is achieved.
Example of current function
Examples taken from https://m-bus.com/documentation-wired/06-application-layer:
- Set the slave to primary address 8 without changing anything else:
INPUT: 68 06 06 68 | 53 FE 51 | 01 7A 08 | 25 16
Parsing the frame using the library (the data is not yet parsable with the lib):
use m_bus_parser::frames::{Address, Frame, Function};
let example = vec![
0x68, 0x06, 0x06, 0x68,
0x53, 0xFE, 0x51,
0x01, 0x7A, 0x08,
0x25, 0x16,
];
let frame = Frame::try_from(example.as_slice()))?;
if let Frame::ControlFrame { function, address, data } = frame {
assert_eq!(address, Address::Broadcast { reply_required: true });
assert_eq!(function, Function::SndUd { fcb: (false)});
assert_eq!(data, &[0x51,0x01, 0x7A, 0x08]);
}
Dependencies
~0.5–10MB
~113K SLoC