Coder Social home page Coder Social logo

maebli / m-bus-parser Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 2.0 3.95 MB

A modern, open source parser for wired m-bus portocol EN 13757-2 link layer, EN 13757-3 application layer of m-bus

License: MIT License

Rust 100.00%
mbus mbus-master mbus-reader

m-bus-parser's Introduction

m-bus-parser (wired)

Discord Crates.io Downloads License Documentation Build Status

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

npm npm

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

Crates.io Downloads

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.

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

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]);
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.