Rust wrapping serial communication with ōRouter

Overview

orouter-serial (ōRouter serial protocol)

This crate provides typed messages used for serial communication between host and oRouter. It also contains codecs for different serial HW used in oRouter.

As a wire codec oRouter uses COBS encoding, specifically cobs rust crate but this is completely abstracted from user of this library.

For reading of messages one can use instance of [crate::host::MessageReader] - after it's created it can be fed incoming slices of bytes (u8s) and messages are returned in a [crate::heapless::Vec] when successfully decoded.

Example:

use orouter_serial::host::{
    calculate_cobs_overhead,
    codec::{UsbCodec, MAX_USB_FRAME_LENGTH},
    Message, MessageReader, StatusCode, RAWIQ_DATA_LENGTH,
};

const TEST_DATA: [u8; 4] = [0x03, 0xc5, 0x02, 0x00];

fn main() {
    let mut message_reader =
        MessageReader::<{ calculate_cobs_overhead(RAWIQ_DATA_LENGTH) }, 17>::default();
    // feed the message_reader with test data representing a Status message
    let messages = message_reader.process_bytes::<UsbCodec>(&TEST_DATA[..]).unwrap();
    println!("received messages = {:?}", messages);
    assert_eq!(
        messages.get(0),
        Some(Message::Status { code: StatusCode::FrameReceived}).as_ref()
    );
}

for more complete read example refer to examples/read.rs

For encoding a message for being send over the serial line a method [crate::host::Message::encode] is used. However, if you know a type of serial line you will be using to send a message (USB or BLE) you can use [crate::host::Message::as_frames] method with a specific codec from [crate::host::codec] module to get message bytes framed in a way needed by the particular serial line type.

Example:

use std::str::FromStr;
use orouter_serial::host::{codec::UsbCodec, Message};

fn main() {
    // let's create a configuration message to set oRouter to EU region with spreading factor 7
    let message = Message::from_str("config@1|7").unwrap();
    // for simplicity just output the bytes
    println!("bytes = {:02x?}", message.encode().unwrap().as_slice());

    // now let's get frames for sending over USB
    let _frames = message.as_frames::<UsbCodec>().unwrap();
}

for more complete write example refer to examples/write.rs

Cargo features

  • std - on by default, exposes things which need standard library (e.g. Debug derives)
  • defmt-impl - add [defmt::Format] derive implementations

Dependant internal projects

  • cli host tool
  • node-overline-protocol
  • RTNOrouterProtocols
  • oRouter Desktop App
  • orouter-cli-miner
You might also like...
A lightning fast version of tmux-fingers written in Rust, copy/pasting tmux like vimium/vimperator
A lightning fast version of tmux-fingers written in Rust, copy/pasting tmux like vimium/vimperator

tmux-thumbs A lightning fast version of tmux-fingers written in Rust for copy pasting with vimium/vimperator like hints. Usage Press ( prefix + Space

A command-line tool collection to assist development written in RUST

dtool dtool is a command-line tool collection to assist development Table of Contents Description Usage Tips Installation Description Now dtool suppor

Rust mid-level IR Abstract Interpreter

MIRAI MIRAI is an abstract interpreter for the Rust compiler's mid-level intermediate representation (MIR). It is intended to become a widely used sta

Migrate C code to Rust
Migrate C code to Rust

C2Rust helps you migrate C99-compliant code to Rust. The translator (or transpiler) produces unsafe Rust code that closely mirrors the input C code. T

C to Rust translator

Corrode: Automatic semantics-preserving translation from C to Rust This program reads a C source file and prints an equivalent module in Rust syntax.

Astronomical algorithms in Rust

astro-rust Contents API Docs About Usage Contributing References About astro-rust is a library of advanced astronomical algorithms for the Rust progra

A Rust library for calculating sun positions

sun A rust port of the JS library suncalc. Install Add the following to your Cargo.toml [dependencies] sun = "0.2" Usage pub fn main() { let unixti

Macro for Python-esque comprehensions in Rust

Cute Macro for Python-esque list comprehensions in Rust. The c! macro implements list and hashmap comprehensions similar to those found in Python, all

Language Integrated Query in Rust.

Linq in Rust Language Integrated Query in Rust (created by declarative macros). Inspired by LINQ in .NET. What's LINQ This project is under developmen

Owner
Overline Network
Core contributor open source software for Overline technology.
Overline Network
Create virtual serial ports, connect them to physical serial ports, and create routes between them all.

Virtual Serial Port Router (vsp-router) Create virtual serial ports, connect them to physical serial ports, and create routes between them all. vsp-ro

Rob Donnelly 3 Nov 24, 2022
A cross-platform serial port library in Rust.

Introduction serialport-rs is a general-purpose cross-platform serial port library for Rust. It provides a blocking I/O interface and port enumeration

Bryant Mairs 143 Nov 5, 2021
A cross-platform serial port library in Rust. Provides a blocking I/O interface and port enumeration including USB device information.

Note: This is a fork of the original serialport-rs project on GitLab. Please note there have been some changes to both the supported targets and which

Serialport 128 Jan 4, 2023
Code for connecting an RP2040 to a Bosch BNO055 IMU and having the realtime orientation data be sent to the host machine via serial USB

Code for connecting an RP2040 (via Raspberry Pi Pico) to a Bosch BNO055 IMU (via an Adafruit breakout board) and having the realtime orientation data be sent to the host machine via serial USB.

Gerald Nash 3 Nov 4, 2022
🖥 Simple Arduino Serial Monitor

Born out of the desire to connect to an Arduino without having to run the whole Arduino suite.

Robin Schroer 2 Mar 19, 2022
Log defmt messages over the serial port.

defmt-serial A defmt target for logging over a serial port. Messages can e.g. be read using socat and passed through defmt-print, see example-artemis

Gaute Hope 10 Oct 5, 2022
k-mer counter in Rust using the rust-bio and rayon crates

krust is a k-mer counter written in Rust and run from the command line that will output canonical k-mers and their frequency across the records in a f

null 14 Jan 7, 2023
Experimental Rust tool for generating FFI definitions allowing many other languages to call Rust code

Diplomat is an experimental Rust tool for generating FFI definitions allowing many other languages to call Rust code. With Diplomat, you can simply define Rust APIs to be exposed over FFI and get high-level C, C++, and JavaScript bindings automatically!

null 255 Dec 30, 2022
Aws-sdk-rust - AWS SDK for the Rust Programming Language

The AWS SDK for Rust This repo contains the new AWS SDK for Rust (the SDK) and its public roadmap. Please Note: The SDK is currently released as a dev

Amazon Web Services - Labs 2k Jan 3, 2023
Rust + Yew + Axum + Tauri, full-stack Rust development for Desktop apps.

rust-yew-axum-tauri-desktop template Rust + Yew + Axum + Tauri, full-stack Rust development for Desktop apps. Crates frontend: Yew frontend app for de

Jet Li 54 Dec 23, 2022