mcumgr_dart 0.4.0
mcumgr_dart: ^0.4.0 copied to clipboard
Pure-Dart client for the SMP / MCUmgr protocol (OS, Image/DFU and Filesystem groups) on Zephyr and MCUboot devices. Bring your own transport; no Flutter.
Changelog #
0.4.0 #
Two fixes for MCUboot DFU and for links shared with another SMP client.
McuImageInfo: read the MCUboot image hash from the image. MCUboot identifies an image by the SHA-256 TLV imgtool stores in its trailer. That hash covers the header, payload and protected TLVs, not the whole file.image statereports it, andImgMgmt.test()/confirm()must be given it. The README example used to passupload()'s return value, which is the SHA-256 of the whole file. A slot never matches that hash, and on a real devicetest()fails withHASH_NOT_FOUND.McuImageInfo.parse()reads the header (version, sizes, flags) and every TLV, skips a protected TLV area correctly, andverifyHash()checks the stored hash against the content before a long upload.McuImageVersionorders versions the way MCUboot's downgrade prevention does, ignoring the build number. Theupload()return value is unchanged and is now documented as the file hash.SmpClientmatches replies on seq, group and id. It used to match onseqalone. When another client shares the link with its own sequence counter, as a raw writer for a custom group might, that client's reply could complete an unrelated pending request. A frame that agrees only onseqis now ignored and counted inunmatchedFrames. A device that answers correctly sees no difference.
0.3.0 #
Serial and other byte-stream transports no longer have to reimplement Zephyr's
framing. Purely additive — no breaking changes, no new dependencies, and the
package stays platform-agnostic (the codec is dart:convert + dart:typed_data
only, so Web support is unaffected).
-
uart_mcumgrencapsulation (UartMcumgrCodec/UartMcumgrDecoder). On BLE the bytes on the characteristic are the SMP frame, soSmpTransportneeds nothing else. A byte stream has no packet boundaries, and Zephyr'suart_mcumgrwraps each frame in a length prefix, a CRC-16/XMODEM and base64 lines marked0x06 0x09/0x04 0x14.UartMcumgrCodec.encode()produces those lines andUartMcumgrDecoder.add()recovers whole SMP frames from arbitrary chunk boundaries, leaving a serial or TCP transport with nothing to do but move bytes.The decoder is deliberately forgiving, because a device's console log usually shares the pipe: unmarked lines are skipped, and a packet failing its length or CRC check is dropped rather than thrown, so one bad packet cannot wedge the stream. Both are counted in
badFrames.encode()emits a single line by default and splits across continuation lines when given amaxLineLength.Accumulation is bounded by
maxPacketBytes(default 4096). A device that emits a start marker and then never completes the packet — wedged mid-transmission, or a console line that happens to open with the marker bytes — would otherwise grow the buffer without limit. An oversized packet is discarded, counted, and the decoder resumes at the next start marker.
0.2.0 #
Adds the two remaining read/write management groups from stock Zephyr, both requested in #1. Purely additive — no breaking changes.
-
Statistics group (2) —
StatMgmt.list()enumerates the groups a device exposes,show()reads one group's counters,showAll()does both. Results come back asStatGroup, whosefieldsare the entries that decoded as integers and whoserawFieldspreserves everything as received, so a non-stock stats implementation loses nothing silently. Read-only, because MCUmgr is: there is no command to reset a counter. -
Settings group (3) —
SettingsMgmtcovers read/write (id 0), delete (1), commit (2) and load/save (3).save({name})saves one subtree when named and the whole tree when not; an empty name is rejected locally, since Zephyr answersEINVALfor it.Values are opaque bytes both ways — the settings subsystem carries no type information, so the API does not invent any.
SettingValueoffersasInt,asBoolandasStringfor the common cases with their assumptions stated (little-endian, caller-known width), andwriteInt/writeBool/writeStringencode the same way.Truncation is handled explicitly: a device that hits
CONFIG_MCUMGR_GRP_SETTINGS_VALUE_LENreturns a short value in an ordinary success response, flagged only by an extramax_sizekey.SettingValue.truncatedsurfaces it, andasIntrefuses to decode a truncated value — a short integer is a different number, not a partial one. -
Group-specific error names for groups 2 and 3, so
SmpExceptionreadssettings: key not found (rc=3)rather thangroup 3 rc=3. Previously only the image group had a table. -
FakeTransportmoved totest/fake_transport.dartand is shared by the suite; both new groups are covered without hardware.
0.1.0 #
Initial release. Extracted from the ProtoCentral OpenView 3 / HealthyPi Move apps as a standalone, pure-Dart library.
- SMP core —
SmpMessage(8-byte header + CBOR, SMP v1rc/ v2errnormalisation and error labels),SmpTransport(abstract byte transport),SmpClient(rollingseqrequest/response matching, fragment reassembly, per-request timeout). - OS group (
OsMgmt, group 0) — echo, mcumgr params, task stat, datetime get/set, reset. - Image group (
ImgMgmt, group 1) — list, chunked/hashed/resumableupload, test, confirm, erase (the DFU flow). - FS group (
FsMgmt, group 8) — stat, download, upload by path.