Crates.io | coe |
lib.rs | coe |
version | 0.2.2 |
source | src |
created_at | 2024-09-18 15:55:31.705887 |
updated_at | 2024-09-21 18:22:07.934999 |
description | coe is a full implementation of the CoEv2 protocol by Technische Alternative |
homepage | |
repository | https://github.com/curatorsigma/coe-rs |
max_upload_size | |
id | 1379394 |
size | 133,245 |
coe-rs
is an implementation of the full CAN-over-Ethernet spec by Technische Alternative, written in 100% safe Rust.
It allows safe (De-)serialization of COE packets from(into) bytes.
We use std
by default, but there is a no_std + alloc
version (with almost the same functionality) and a fully no_alloc
version available, which depends only on core
.
coe-rs
is as small as possible and only handles (De-)serialization of CoE packets.
To use the protocol over a network, consider this minimal example:
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut test_packet = Packet::new();
// send to CAN-ID 58, at offset 1 (shows up as 2 in the GUI)
test_packet.try_push(Payload::new(58, 1, coe::COEValue::Analogue(AnalogueCOEValue::LiterPerPulse_Tens(123))))?;
let socket = UdpSocket::bind("0.0.0.0:34215").await?;
let mut buf = [0_u8; 252];
test_packet.try_serialize_into(&mut buf).expect("252 bytes is always large enough to fit a
CoE Packet");
// connect to the IP of your CMI
socket.connect("192.168.1.123:5442").await?;
socket.send(&buf).await?;
Ok(())
}
You can receive packets like this:
async fn listener() -> Result<(), Box<dyn Error>> {
let socket = UdpSocket::bind("0.0.0.0:5442").await?;
// the largest possible COE packet is 256 byte long, so this is always safe
let mut buf = [0_u8; 256];
loop {
let (length, _) = socket.recv_from(&mut buf).await?;
let parsed = TryInto::<coe::Packet>::try_into(&buf[0..length])?;
dbg!(&parsed);
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let listen_handle = tokio::spawn(async { listener().await });
let (res,) = tokio::join!(listen_handle);
Ok(())
}
You can find a real-world application of coe-rs
in churchtools-ta-sync.
Where we continually push data from an sqlite database to CMIs.
The CoE Protocol is intellectual property of Technische Alternative RT GmbH
.
While the Protocol overview is given here, THE PROTOCOL ITSELF IS EXPLICITLY NOT COVERED BY THIS REPOSITORIES LICENSE.
A CoE packet consists of a 4-byte Header and up to 31 8-byte Payload fields.
Consists of these values, in order, starting from the 1st byte of the packet.
There is no padding between the header and the first payload field.
Consists of these values, in order, starting from the 1st byte of the Payload.
output index
of the transmitted Value. Unsigned 8-bit integer.
coe-rs
DOES NOT add this offset. The calling application is responsible for handling the offset if required.AnalogueCOEValue
coe-rs
in its current state is (apart from potential bugs I have not found yet) fully compliant to the CoEv2.0 Spec.
CoEv1 is not currently implemented. If you need that protocol, consider opening a PR.
I promise the following SemVer while pre-1.0:
Minimum supported Rust version is rustc 1.80.1
. Earlier versions of rustc may work, but they have not been tested.
This project is licensed under MIT-0 (MIT No Attribution). By contributing to this repositry, you agree that your code will be licensed as MIT-0.
For my rationale for using MIT-0 instead of another more common license, please see https://copy.church/objections/attribution/#why-not-require-attribution .