#mbus #parser #parse

no-std m-bus-parser

A library for parsing M-Bus frames

4 releases

0.0.3 Mar 26, 2024
0.0.2 Mar 22, 2024
0.0.1 Mar 21, 2024
0.0.0 Mar 9, 2024

#75 in #parse

Download history 171/week @ 2024-03-07 12/week @ 2024-03-14 334/week @ 2024-03-21 43/week @ 2024-03-28 13/week @ 2024-04-04

390 downloads per month

MIT license

425KB
1.5K SLoC

m-bus-parser (wired)

Discord Crates.io Downloads License Documentation Build Status

Introduction

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 implementationso the specification.

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#, or tmbus written in javascript.

Visualization of Library Function

Visualization of Serialized Application Layer

The searlized application layer above can be further broken into parsable parts.

Aim

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:

  1. 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.2–2MB
~40K SLoC