Added basic hostsoftware
This commit is contained in:
parent
833e4d5a56
commit
e84e1a64b5
|
@ -2,7 +2,9 @@
|
|||
resolver = "2"
|
||||
|
||||
members = [
|
||||
"firmware", "protocol",
|
||||
"hostsoftware",
|
||||
"firmware",
|
||||
"protocol",
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -378,7 +378,7 @@ mod app {
|
|||
loop {
|
||||
if let Some((msg, rest)) = buffer.split_once(|&x| x == 0) {
|
||||
let mut message = [0u8; 128];
|
||||
message.clone_from_slice(msg);
|
||||
message[0..msg.len()].clone_from_slice(msg);
|
||||
let host_msg = from_bytes_cobs::<HostMessage>(&mut message);
|
||||
|
||||
match host_msg {
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "controller"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
cheapsdo-protocol = { path = "../protocol" }
|
||||
postcard = {version = "1.0.8", features = ["use-std"]}
|
||||
serialport = "4.3.0"
|
|
@ -0,0 +1,38 @@
|
|||
use std::io;
|
||||
use std::{io::Write, thread};
|
||||
use std::time::Duration;
|
||||
|
||||
use cheapsdo_protocol::*;
|
||||
use postcard::{to_stdvec_cobs, from_bytes_cobs};
|
||||
|
||||
fn main() {
|
||||
let mut port = serialport::new("/dev/ttyACM1", 115_200)
|
||||
.timeout(Duration::from_millis(10))
|
||||
.open().expect("Failed to open port");
|
||||
|
||||
|
||||
|
||||
loop {
|
||||
let host_msg = HostMessage::RequestStatus;
|
||||
let msg_bytes = to_stdvec_cobs(&host_msg).unwrap();
|
||||
|
||||
port.write_all(&msg_bytes).unwrap();
|
||||
|
||||
let mut serial_buf: Vec<u8> = vec![0; 128];
|
||||
match port.read(serial_buf.as_mut_slice()) {
|
||||
Ok(t) => {
|
||||
serial_buf.truncate(t);
|
||||
println!("Data: {:?}", serial_buf);
|
||||
|
||||
let dev_msg = from_bytes_cobs::<DeviceMessage>(&mut serial_buf).unwrap();
|
||||
println!("Message: {:?}", dev_msg);
|
||||
}
|
||||
Err(ref e) if e.kind() == io::ErrorKind::TimedOut => (),
|
||||
Err(e) => eprintln!("{:?}", e),
|
||||
}
|
||||
|
||||
|
||||
thread::sleep(Duration::from_millis(1000));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue