Skip to content

Commit

Permalink
improving examples also in doc
Browse files Browse the repository at this point in the history
  • Loading branch information
maebli committed Feb 22, 2024
1 parent d9c5c52 commit 6cc0183
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
11 changes: 4 additions & 7 deletions examples/example_parsing_long_frame.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use m_bus_parser::frames::{parse_frame, FrameType};
use m_bus_parser::frames::{parse_frame, Address, FrameType, Function};


// This is an example of how to use the library to parse a frame.
Expand Down Expand Up @@ -30,12 +30,9 @@ fn main() {

let frame = parse_frame(&example).unwrap();

if let FrameType::LongFrame { function, address, data } = frame {
println!("Function: {:?}", function);
println!("Address: {:?}", address);
println!("Data: {:?}", data);


if let FrameType::LongFrame { function, address, data :_} = frame {
assert_eq!(function, Function::RspUd{acd: false, dfc:false});
assert_eq!(address, Address::Primary(1));
}

}
43 changes: 33 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
//! m-bus-parse
//! Brief summary
//! * is a library for parsing M-Bus frames and user data.
//! * aims to be a modern, open source decoder for wired m-bus portocol decoder for EN 13757-2 physical and link layer, EN 13757-3 application layer of m-bus
//! * was implemented using the publicily available documentation available at https://m-bus.com/
//! * was implemented using the publicily available documentation available at <https://m-bus.com/>
//! # Example
//! ```
//! use m_bus_parser::{frames::{parse_frame, FrameType}, user_data::{parse_user_data, UserDataBlock}};
//! ```rust
//! use m_bus_parser::frames::{parse_frame, Address, FrameType, Function};
//!
//! let example = vec![
//! 0x68, 0x4D, 0x4D, 0x68,
//! 0x08, 0x01, 0x72, 0x01,
//! 0x00, 0x00,0x00, 0x96,
//! 0x15, 0x01, 0x00, 0x18,
//! 0x00, 0x00, 0x00, 0x0C,
//! 0x78, 0x56, 0x00, 0x00,
//! 0x00, 0x01, 0xFD, 0x1B,
//! 0x00, 0x02, 0xFC, 0x03,
//! 0x48, 0x52, 0x25, 0x74,
//! 0x44, 0x0D, 0x22, 0xFC,
//! 0x03, 0x48, 0x52, 0x25,
//! 0x74, 0xF1, 0x0C, 0x12,
//! 0xFC, 0x03, 0x48, 0x52,
//! 0x25, 0x74, 0x63, 0x11,
//! 0x02, 0x65, 0xB4, 0x09,
//! 0x22, 0x65, 0x86, 0x09,
//! 0x12, 0x65, 0xB7, 0x09,
//! 0x01, 0x72, 0x00, 0x72,
//! 0x65, 0x00, 0x00, 0xB2,
//! 0x01, 0x65, 0x00, 0x00,
//! 0x1F, 0xB3, 0x16,
//! ];
//!
//! let frame = vec![0x68, 0x0e, 0x0e, 0x68, 0x08, 0x00, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x16, 0x16];
//! let frame_type = parse_frame(&frame);
//! assert_eq!(frame_type, FrameType::Short);
//! let frame = parse_frame(&example).unwrap();
//!
//! let user_data = vec![0x08, 0x00, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x16];
//! let user_data_block = parse_user_data(&user_data);
//! assert_eq!(user_data_block, UserDataBlock::Short);
//! if let FrameType::LongFrame { function, address, data :_} = frame {
//! assert_eq!(function, Function::RspUd{acd: false, dfc:false});
//! assert_eq!(address, Address::Primary(1));
//! }
//! ```
pub mod frames;
pub mod user_data;

0 comments on commit 6cc0183

Please sign in to comment.