{"id":21369019,"url":"https://github.com/stronnag/msp-rs","last_synced_at":"2025-07-13T05:32:47.085Z","repository":{"id":47768013,"uuid":"395772437","full_name":"stronnag/msp-rs","owner":"stronnag","description":"Sample rust code for MSP (inav etc.)","archived":false,"fork":false,"pushed_at":"2024-04-12T14:20:07.000Z","size":147,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-12T22:15:31.282Z","etag":null,"topics":["inav","msp","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stronnag.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-08-13T19:32:27.000Z","updated_at":"2023-11-16T15:19:01.000Z","dependencies_parsed_at":"2023-11-28T23:24:17.943Z","dependency_job_id":"5979c791-c9ca-4f6b-8c35-6c2520422976","html_url":"https://github.com/stronnag/msp-rs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stronnag%2Fmsp-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stronnag%2Fmsp-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stronnag%2Fmsp-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stronnag%2Fmsp-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stronnag","download_url":"https://codeload.github.com/stronnag/msp-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225861396,"owners_count":17535930,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["inav","msp","rust"],"created_at":"2024-11-22T07:29:54.038Z","updated_at":"2024-11-22T07:29:54.743Z","avatar_url":"https://github.com/stronnag.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Using rust for MSP (inav etc.)\n\n## Introduction\n\nIn the unlikely event that you're curious about using rust to communicate with a MSP flight controller (for example [inav](https://github.com/iNavFlight/inav), betaflight, multiwii even), then here's a trivial example of rust asynchronous MSP (using a \"channels\" pattern).\n\nNote that this is (still) about day 4 of the author's on/off rust adventure, it may be non-idiomatic, naive etc. PRs welcome.\n\n## Example\n\nBench test FC, indoors, somewhat random GPS data.\n\n```\n$ msptest /dev/rfcomm1\nSerial port: /dev/rfcomm1\nName: BenchyMcTest\nAPI Version: 2.4\nFirmware: INAV\nFW Version: 3.1.0\nGit revsion: b079efca\nBoard: WINGFC\nExtant waypoints in FC: 16 of 60, valid true\nVoltage: 11.9\nGPS: fix 2, sats 5, lat, lon, alt 50.9***** -1.5***** -1, spd 0.33 cog 7.7 hdop 6.59\n```\n\n## Usage\n\n```\n$ msptest --help\nUsage: msptest [options] [device-node]\nVersion: 0.10.0\n\nOptions:\n    -s, --slow          slow mode\n    -1, --once          Single iteration, then exit\n    -v, --version       Show version\n    -h, --help          print this help menu\n```\n\nOn Linux / Macos / Windows / FreeBSD, if no device is given, the application will make a reasonable attempt to evince any valid serial device; e.g. with `msptest` installed on `$PATH`:\n\n```\n$ msptest\nSerial port: /dev/ttyACM0\nName: BenchyMcTesty\nAPI Version: 2.4\nFirmware: INAV\nFW Version: 6.0.0\nGit revsion: 4bbd2fa5\nBoard: WINGFC\nExtant waypoints in FC: 0 of 120, valid false\nUptime: 550s\nVoltage: 0.00\nGPS: fix 0, sats 0, lat, lon, alt 0.000000 0.000000 0, spd 0.00 cog 0 hdop 99.99\nElapsed 37.25s 2306 messages, rate 61.90/s\n^C\n```\n\n^C to exit.\n\nNote for FreeBSD, only /dev/cuaU* is recognised:\n\nThusly:\n\n```\n# This would be auto-discovered\n# macos\nmsptest /dev/cu.usbmodem0x80000001\n\n# Windows\n# This would be auto-discovered\nmsptest.exe COM17\n```\n\nYou can also use a TCP pseudo-URI (e.g. for use with the SITL):\n\n```\nmsptest tcp://localhost:5767\n```\n\nand on **unix** platforms, UDP:\n\n```\nmsptest udp://localhost:53285\n```\n\n## Makefile\n\nAs a short cut for `cargo` commands / options, there's a Makefile\n\n* `make build`    :  Builds a release target\n* `make install`  :  Builds a release target, installs to ~/.local/bin\n* `make debug`    :  Builds a debug target\n* `make windows`  :  Cross-compiles a Windows executable on sane host OS\n* `make clean`    :  Clean\n\n## Legacy\n\n### MultiWii\n\n```\n$ msptest\nSerial port: /dev/ttyUSB0\nMSP Vers: 241, (protocol v1)\nVoltage: 4.20\nGPS: fix 0, sats 0, 0.000000° 0.000000° 0m, spd 0.00 cog 0\nElapsed 21.64s 1298 messages, rate 59.99/s\n```\n\n### INAV F1 Processor\n\nNote the serial message rate. The changes since 1.7 / 1.8 (increased functionality, changing of task priorities etc.) have not improved serial I/O rates, despite much faster CPUs.\n\n```\n$ msptest /dev/ttyACM1\nSerial port: /dev/ttyACM1\nMSP Vers: 231, (protocol v2)\nName: BV-CC3D\nAPI Version: 2.1\nFirmware: INAV\nFW Version: 1.9.254\nGit revsion: e4510e11\nBoard: CC3D\nExtant waypoints in FC: 0 of 30, valid false\nVoltage: 0.00\nGPS: fix 0, sats 0, 0.000000° 0.000000° 0m, spd 0.00 cog 0 hdop 0.00\nElapsed 14.31s 1427 messages, rate 99.69/s\n```\n\n## TUI Display\n\nThe example has now migrated to a TUI application:\n\n```\n                                  MSP Test Viewer\n                       v0.12.0 on freebsd 13.1-RELEASE x86_64\n\nPort    : /dev/cuaU0\nMW Vers : ---\nName    : BenchyMcTesty\nAPI Vers: 2.4 (MSP v2)\nFC      : INAV\nFC Vers : 6.0.0\nBuild   : Dec 29 2022 12:38:03 (243b867d)\nBoard   : WINGFC\nWP Info : 0 of 120, valid false\nUptime  : 90563s\nPower   : 0.0 volts, 0.11 amps\nGPS     : fix 0, sats 0, 0.000000° 0.000000° 0m, 0m/s 0° hdop 99.99\nArming  : NavUnsafe H/WFail RCLink (0x48800)\nRate    : 5587388 messages in 90358.35s (61.8/s) (unknown: 1, crc 0)\n```\n\nFrom 0.12.0, the rate line includes the count of unknown massages and CRC errors. The CRC count should be zero; the unknown count will vary according to version:\n\n```\nBoard   : MultiWii\nRate    : 1934 messages in 30.9s (62.6/s) (unknown: 649, crc 0)\n\nBoard   : CC3D\nFC Vers : 1.9.254\nRate    : 4072 messages in 40.8s (99.7/s) (unknown: 1016, crc 0)\n\nBoard   : MATEKF405\nFC Vers : 6.0.0\nRate    : 2384 messages in 38.5s (61.9/s) (unknown: 1, crc 0)\n```\n\n* MultiWii: c. 33% unknown\n* Ancient INAV: c. 25% unknown\n* Modern INAV: 1 unknown\n\n## Discussion\n\n### Unsafe (C) serial implementation\n\nThe rust serialport crate is used device enumeration. Prior to version 0.10.0, the serialport crate was also used for I/O; since then a custom implementation is used.\n\nThis example uses an (unsafe) C language implementation for serial I/O, rather than the serialport crate (or even the better serial2 crate):\n\n* serialport did not support RISC-V (at one time)\n* serialport performance on Windows is poor (c. 25% of Linux / FreeBSD / Macos) and unreliable across multiple threads. The embedded implementation is thread safe and the Windows performance is close to that of the POSIX platforms.\n* serial2 requires `Arc()` in order to use a separate reader thread. This rather upsets the current device independent implementation .\n\n### Other\n\nThere is an [similar Golang example](https://github.com/stronnag/msp-go); you may judge which is the cleanest / simplest.\n\n## Licence\n\nMIT, 0BSD or similar.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstronnag%2Fmsp-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstronnag%2Fmsp-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstronnag%2Fmsp-rs/lists"}