mbus

package
v0.783.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package mbus decodes M-Bus (Meter-Bus, EN 13757-2 link layer + EN 13757-3 application layer) frames — the European smart-metering protocol for electricity, gas, water, heat, and warm-water meters. The wired M-Bus link/application layers are shared with Wireless M-Bus (wM-Bus, 868 MHz), which a Flipper Sub-GHz capture can lift off the air; pasting the demodulated bytes here decodes the meter identity and command without a dedicated M-Bus master.

Wrap-vs-native judgement

Native. M-Bus is defined by the public EN 13757 standard. The link layer is one of four fixed framings (single-character ACK, short, control, long), each a byte-counted structure with a trailing checksum and 0x16 stop byte. The application layer's Variable Data Structure carries a fixed header (BCD serial number, FLAG-encoded manufacturer, version, medium/device type, access number, status, signature) before the DIF/VIF data records. Every field is a fixed-format byte stream; dispatch is a set of small lookup tables.

What this package covers

  • Link-layer frame classification: single-character ACK (0xE5), short frame (0x10 ... 0x16), control frame (0x68 L L 0x68 ... 0x16 with L==3), long frame (0x68 L L 0x68 ... 0x16).
  • L-field consistency (the two length bytes must match) and total-length validation against the buffer.
  • Checksum verification (arithmetic sum of C..end-of-user-data mod 256) and the 0x16 stop byte.
  • C-field (Control) function naming (SND_NKE, SND_UD, REQ_UD1, REQ_UD2, RSP_UD, ACK) plus the master↔slave direction bit.
  • A-field (Address) value plus classification (unconfigured / primary / secondary-addressing / broadcast-no-reply / broadcast-all-reply / reserved).
  • CI-field (Control Information) application-selector naming.
  • Variable Data Structure fixed header (CI 0x72 long 12-byte / CI 0x7A short 4-byte): BCD identification (serial) number, FLAG-encoded 3-letter manufacturer, version, medium/device type with a name table, access number, status byte, signature.

What this package does NOT cover (deliberately out of scope)

  • DIF/VIF data-record decoding (the metering values themselves): the DIF data-field-coding × VIF unit/multiplier matrix is a substantial separate walker. The raw data-record bytes are surfaced so the operator can compare against EN 13757-3 §6.
  • wM-Bus radio framing (mode S/T/C, 3-of-6 / Manchester line coding, block-wise CRC): feed already-demodulated/de-coded application bytes here.
  • Encrypted application data (Mode 5 AES-CBC / Mode 7/9/13): the status/configuration field is surfaced but the ciphertext is not decrypted.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Frame

type Frame struct {
	HexInput       string     `json:"hex_input"`
	FrameType      string     `json:"frame_type"`
	LengthField    *int       `json:"length_field,omitempty"`
	CField         *int       `json:"c_field,omitempty"`
	CFieldName     string     `json:"c_field_name,omitempty"`
	Direction      string     `json:"direction,omitempty"`
	AField         *int       `json:"a_field,omitempty"`
	AddressType    string     `json:"address_type,omitempty"`
	CIField        *int       `json:"ci_field,omitempty"`
	CIFieldName    string     `json:"ci_field_name,omitempty"`
	Header         *VDSHeader `json:"variable_data_header,omitempty"`
	DataRecordsHex string     `json:"data_records_hex,omitempty"`
	ChecksumValid  *bool      `json:"checksum_valid,omitempty"`
	Notes          []string   `json:"notes,omitempty"`
}

Frame is the decoded view of an M-Bus telegram.

func Decode

func Decode(hexBlob string) (*Frame, error)

Decode parses a hex-encoded M-Bus telegram.

func DecodeBytes

func DecodeBytes(b []byte) (*Frame, error)

DecodeBytes parses a raw M-Bus telegram.

type VDSHeader

type VDSHeader struct {
	HeaderType     string `json:"header_type"`
	SerialNumber   string `json:"serial_number,omitempty"`
	Manufacturer   string `json:"manufacturer,omitempty"`
	ManufacturerID *int   `json:"manufacturer_id,omitempty"`
	Version        *int   `json:"version,omitempty"`
	Medium         *int   `json:"medium,omitempty"`
	MediumName     string `json:"medium_name,omitempty"`
	AccessNumber   int    `json:"access_number"`
	Status         int    `json:"status"`
	SignatureHex   string `json:"signature_hex,omitempty"`
}

VDSHeader is the fixed header of a Variable Data Structure response (the part before the DIF/VIF data records).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL