Skip to content

gengoscript/gengo-mbus

Repository files navigation

gengo-mbus

M-Bus / Meter-Bus (EN 13757) frame and telegram decoder for Gengo.

gengo-mbus accepts raw M-Bus frames as hex strings and returns structured decode results. It is transport-agnostic: serial, TCP, radio gateway, and file input are all outside the decoder itself.

The implementation is currently a single Gengo module in mbus.gengo, with a small CLI and a test corpus.

Status

Current capabilities:

  • frame decoding for ACK, short, control, and long frames
  • checksum and CRC-16 validation
  • variable data telegram decoding
  • fixed data telegram decoding
  • compact data and format data identification with partial body export
  • JSON and flat-map export helpers
  • CLI for decoding a single hex payload from stdin

Current limitations:

  • compact data telegrams are identified, but not expanded without a matching format template
  • format data telegrams expose descriptor parsing, not full compact-template application
  • encrypted / manufacturer-specific payload handling is limited

Quick Start

Decode a frame from a Gengo script:

mbus := import("./mbus")
std := import("std")

hex_str := "683D3D68080B7221000000B05C021B120000000C784904006402750A0001FD711E2F2F0A6620020AFB1A310502FD971D00002F2F2F2F2F2F2F2F2F2F2F2F2F2F2FDD16"

result := mbus.decode(hex_str)
std.io.println("ok:", result.ok)

if result.telegram != null {
    std.io.println(mbus.telegram_to_json(result.telegram))
}

Run the CLI:

echo "683D3D68080B7221000000B05C021B120000000C784904006402750A0001FD711E2F2F0A6620020AFB1A310502FD971D00002F2F2F2F2F2F2F2F2F2F2F2F2F2F2FDD16" | ../gengo/zig-out/bin/gengo cli.gengo

Public API

Main entrypoints in mbus.gengo:

  • decode(hex_str string) DecodeResult
  • decode_one(hex_str string) ?Telegram
  • decode_frame(hex_str string) Frame
  • decode_telegram(frame Frame) Telegram

Export helpers:

  • telegram_to_json(t Telegram) string
  • frame_to_json(f Frame) string
  • decode_result_to_json(r DecodeResult) string
  • telegram_to_map(t Telegram) map[string]string

Utilities:

  • crc16_en13757(hex_str string) ?int
  • decode_status_flags(status_byte int) StatusFlags

Testing

Run all test suites:

./run_tests.sh

run_tests.sh uses GENGO_BIN if set. Otherwise it falls back to a local ../gengo/zig-out/bin/gengo binary when present, then to gengo on PATH.

Important test files:

Documentation

Project Layout

gengo-mbus/
  mbus.gengo
  cli.gengo
  test_all.gengo
  test_decode.gengo
  test_fixed_data.gengo
  test_crc16.gengo
  test_edge_cases.gengo
  test_export.gengo
  test_corpus2.gengo
  run_tests.sh
  README.md
  USAGE.md
  ARCHITECTURE.md

Releases

No releases published

Packages

 
 
 

Contributors

Languages