Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- New `xml` output format that reproduces the legacy rSCADA/libmbus
`mbus_frame_data_xml_normalized()` output byte for byte, as a drop-in
replacement for consumers of libmbus's normalized XML. Available through
`serialize_mbus_data(hex, "xml", None)`, the CLI (`-t xml`), and the Python
bindings.
- Parity test (`tests/rscada_xml.rs`) diffing the `xml` output against the
reference `.norm.xml` files in `tests/rscada`.

### Fixed

- VIF plaintext extension chains are now walked from the correct offset when
the plaintext VIF precedes the VIFE bytes (`plaintext-before-extension`),
so records that previously aborted with `InvalidValueInformation` now parse.
- A 6-byte data field carrying a date/time VIF (0x6D) is now decoded as a
type I (CP48) timestamp instead of type F, matching EN 13757-3.

## [0.2.0]

Breaking changes for JSON/YAML consumers:
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ An open-source parser (decoder/deserializer) for the **wired** and **wireless**
## Features

- Parses **wired M-Bus** (EN 13757-2/-3) and **wireless M-Bus** (wMBus) frames
- **Five output formats**: `table`, `json`, `yaml`, `csv`, `mermaid`
- **Six output formats**: `table`, `json`, `yaml`, `csv`, `mermaid`, `xml`
- **AES-128 decryption** for encrypted wMBus frames (mode 5 / mode 7)
- **`no_std` compatible** — runs on embedded targets (manufacturer lookup and output formats require `std`)
- Available as a **Rust library**, **CLI**, **WebAssembly (npm)** and **Python bindings**
Expand Down Expand Up @@ -69,7 +69,7 @@ m-bus-parser-cli parse [OPTIONS]
Options:
-d, --data <DATA> Raw M-Bus frame as a hex string
-f, --file <FILE> File containing a hex frame
-t, --format <FORMAT> Output format: table (default), json, yaml, csv, mermaid
-t, --format <FORMAT> Output format: table (default), json, yaml, csv, mermaid, xml
-k, --key <KEY> AES-128 decryption key (32 hex characters)
```

Expand Down Expand Up @@ -144,6 +144,9 @@ m-bus-parser-cli parse -d "..." -t csv
# Mermaid diagram source (renders in the web app)
m-bus-parser-cli parse -d "..." -t mermaid

# Legacy libmbus normalized XML (drop-in for rSCADA/libmbus consumers)
m-bus-parser-cli parse -d "..." -t xml

# With AES-128 decryption key
m-bus-parser-cli parse -d "..." -k "000102030405060708090A0B0C0D0E0F"
```
Expand Down Expand Up @@ -211,6 +214,7 @@ let json = serialize_mbus_data(hex, "json", None);
let yaml = serialize_mbus_data(hex, "yaml", None);
let csv = serialize_mbus_data(hex, "csv", None);
let mermaid = serialize_mbus_data(hex, "mermaid", None);
let xml = serialize_mbus_data(hex, "xml", None);

// With decryption key
let key: [u8; 16] = [0x00, 0x01, ..., 0x0F];
Expand Down Expand Up @@ -239,6 +243,7 @@ An embedded example (Cortex-M) is in [`examples/cortex-m/`](./examples/cortex-m)
| `yaml` | `-t yaml` | YAML |
| `csv` | `-t csv` | Comma-separated values |
| `mermaid` | `-t mermaid` | Mermaid flowchart source (renders in web app)|
| `xml` | `-t xml` | Legacy libmbus normalized XML (rSCADA-compatible)|

---

Expand Down
1 change: 1 addition & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum Command {
#[arg(short = 'd', long)]
data: Option<String>,

/// Output format: table (default), json, yaml, csv, mermaid, xml
#[arg(short = 't', long)]
format: Option<String>,

Expand Down
8 changes: 7 additions & 1 deletion crates/m-bus-application-layer/src/data_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,13 @@ impl TryFrom<&RawDataRecordHeader<'_>> for ProcessedDataRecordHeader {
if v.labels.contains(&ValueLabel::Date) {
d.data_field_coding = DataFieldCoding::DateTypeG;
} else if v.labels.contains(&ValueLabel::DateTime) {
d.data_field_coding = DataFieldCoding::DateTimeTypeF;
// VIF 0x6D with a 6-byte data field is a type I date and time
// (EN 13757-3), only the 4-byte variant is type F.
d.data_field_coding = if d.data_field_coding == DataFieldCoding::Integer48Bit {
DataFieldCoding::DateTimeTypeI
} else {
DataFieldCoding::DateTimeTypeF
};
} else if v.labels.contains(&ValueLabel::Time) {
d.data_field_coding = DataFieldCoding::DateTimeTypeJ;
} else if v.labels.contains(&ValueLabel::DateTimeWithSeconds) {
Expand Down
7 changes: 6 additions & 1 deletion crates/m-bus-application-layer/src/value_information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ impl TryFrom<&[u8]> for ValueInformationBlock {
}

if vif.has_extension() {
let mut offset = 1;
// When the plaintext VIF precedes the extensions, the VIFE chain
// starts after the ASCII length byte and string, not at offset 1.
let mut offset = match &plaintext_vife {
Some(chars) if !standard_plaintex_vib => 1 + 1 + chars.len(),
_ => 1,
};
while offset < data.len() {
let vife_data = *data.get(offset).ok_or(DataInformationError::DataTooShort)?;
let current_vife = ValueInformationFieldExtension { data: vife_data };
Expand Down
10 changes: 8 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ <h1>Online M-Bus Parser <span class="parser-version" id="parser-version"></span>
<input id="parse_table" type="button" value="Parse to Table" />
<input id="parse_csv" type="button" value="Parse to CSV" />
<input id="parse_mermaid" type="button" value="Parse to Diagram" />
<input id="parse_xml" type="button" value="Parse to XML" />
<input id="parse_hexview" type="button" value="Hex View" />
</form>
<div id="output-container">
Expand All @@ -688,7 +689,7 @@ <h1>Online M-Bus Parser <span class="parser-version" id="parser-version"></span>
<pre id="output"></pre>
</div>
<script type="module">
import init, { m_bus_parse, m_bus_parse_with_key, version } from "./m_bus_parser_wasm_pack.js?v=0.1.3";
import init, { m_bus_parse, m_bus_parse_with_key, version } from "./m_bus_parser_wasm_pack.js?v=0.2.0";

let currentFormat = "json"; // Keep track of the last used format

Expand Down Expand Up @@ -731,7 +732,7 @@ <h1>Online M-Bus Parser <span class="parser-version" id="parser-version"></span>
}
});

await init(new URL("./m_bus_parser_wasm_pack_bg.wasm?v=0.1.3", import.meta.url));
await init(new URL("./m_bus_parser_wasm_pack_bg.wasm?v=0.2.0", import.meta.url));
document.getElementById('parser-version').textContent = 'v' + version();

// Load data and format from URL params and auto-parse if present
Expand Down Expand Up @@ -763,6 +764,10 @@ <h1>Online M-Bus Parser <span class="parser-version" id="parser-version"></span>
parseInput("mermaid");
});

document.getElementById('parse_xml').addEventListener('click', () => {
parseInput("xml");
});

document.getElementById('parse_hexview').addEventListener('click', () => {
parseInput("hexview");
});
Expand Down Expand Up @@ -826,6 +831,7 @@ <h1>Online M-Bus Parser <span class="parser-version" id="parser-version"></span>
else if (format === 'csv') { extension = 'csv'; mimeType = 'text/csv'; }
else if (format === 'table_format') { lang = 'plaintext'; extension = 'txt'; }
else if (format === 'mermaid') { extension = 'mmd'; mimeType = 'text/plain'; }
else if (format === 'xml') { lang = 'xml'; extension = 'xml'; mimeType = 'application/xml'; }

outputContainer.style.background = '';
outputContainer.style.whiteSpace = '';
Expand Down
Loading
Loading