#rtos #zephyr #message-format #codec #request-response #smp #mcumgr

mcumgr-smp

An implementation of the smp protocol for microcontrollers in pure rust

1 unstable release

0.6.0 Dec 7, 2023

#343 in Embedded development

Download history 207/week @ 2023-12-17 30/week @ 2023-12-31 39/week @ 2024-01-07 231/week @ 2024-01-21 400/week @ 2024-01-28 560/week @ 2024-02-04 637/week @ 2024-02-11 247/week @ 2024-02-18 459/week @ 2024-02-25 482/week @ 2024-03-03 234/week @ 2024-03-10 174/week @ 2024-03-17 206/week @ 2024-03-24 107/week @ 2024-03-31

724 downloads per month

MIT/Apache

23KB
522 lines

mcumgr-smp

An implementation of the SMP protocol.

This library defines the SMP message format and methods to encode and decode bytes.

Additionally, common request and response objects with a CBOR payload for groups Application Management, OS Management, and Shell Management are provided.
Feel free to contribute additional message definitions.

Custom messages are fully supported by creating SMPFrames manually. You can even use a payload encoding other than CBOR.

Example

Echo

// build an echo SMP message
let smp_frame: mcumgr_smp::SMPFrame = mcumgr_smp::os_management::echo(42, "Hello World");
// get frame as bytes
let data: Vec<u8> = smp_frame.encode_with_cbor();
// send frame and get response
// ...
let response_data = [3, 0, 0, 16, 0, 0, 66, 0, 191, 97, 114, 107, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 255];
let response: SMPFrame<EchoResult> = mcumgr_smp::SMPFrame::decode_with_cbor(&response_data).expect("decoding error");

println!("response payload: {:?}", response.data);

You can also create a frame manually:

let data = todo!(); // cbor payload of command, in this case a firmware chunk
let smp_frame = SMPFrame::new(
    mcumgr_smp::OpCode::WriteRequest,
    69,
    mcumgr_smp::Group::ApplicationManagement,
    mcumgr_smp::ApplicationManagementCommand::Upload as u8,
    data,
);

Copyright (c) 2023 Gessler GmbH.

Dependencies

~0.3–1MB
~23K SLoC