From b04bd6bf1b0d10df1a22cbc42f89b380ada00b69 Mon Sep 17 00:00:00 2001 From: Andreas Tsatsanis Date: Tue, 23 Apr 2024 10:35:29 +0200 Subject: [PATCH] compiler was right i was wrong --- app/Cargo.lock | 1 + app/Cargo.toml | 1 + app/build/build.rs | 2 -- app/build/commands.rs | 4 ---- app/build/events.rs | 4 ---- app/src/core/communication/can.rs | 24 +++++++--------------- app/src/core/communication/tcp.rs | 8 ++++---- app/src/core/controllers/can_controller.rs | 2 +- app/src/pconfig.rs | 14 ++++++++++++- 9 files changed, 27 insertions(+), 33 deletions(-) diff --git a/app/Cargo.lock b/app/Cargo.lock index 0fca3d3b9..1efc0f1ab 100644 --- a/app/Cargo.lock +++ b/app/Cargo.lock @@ -27,6 +27,7 @@ dependencies = [ "embassy-sync", "embassy-time", "embassy-usb", + "embedded-can", "embedded-hal 0.2.7", "embedded-hal-async", "embedded-io-async", diff --git a/app/Cargo.toml b/app/Cargo.toml index 02de9cd53..adff9fd23 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -11,6 +11,7 @@ defmt-rtt = "0.4" cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] } cortex-m-rt = "0.7.3" embedded-hal = "0.2.7" +embedded-can = "0.4.1" embedded-hal-async = { version = "1.0" } embedded-nal-async = { version = "0.7.1" } embedded-io-async = { version = "0.6.1" } diff --git a/app/build/build.rs b/app/build/build.rs index bfd065f42..a6ad5bacc 100644 --- a/app/build/build.rs +++ b/app/build/build.rs @@ -3,12 +3,10 @@ mod commands; mod datatypes; mod events; -mod can; extern crate regex; extern crate serde; -use std::collections::HashSet; use std::env; use std::fs; use std::path::Path; diff --git a/app/build/commands.rs b/app/build/commands.rs index 6fbac4f87..998388ede 100644 --- a/app/build/commands.rs +++ b/app/build/commands.rs @@ -3,13 +3,9 @@ extern crate regex; extern crate serde; -use std::collections::HashSet; -use std::env; use std::fs; -use std::path::Path; use std::sync::Mutex; use serde::Deserialize; -use toml::map::Map; #[derive(Debug, Deserialize)] pub struct Config { diff --git a/app/build/events.rs b/app/build/events.rs index 127192c89..887aa2d06 100644 --- a/app/build/events.rs +++ b/app/build/events.rs @@ -3,11 +3,7 @@ extern crate regex; extern crate serde; -use std::collections::HashSet; -use std::env; -use std::fmt::format; use std::fs; -use std::path::Path; use std::sync::Mutex; use serde::Deserialize; diff --git a/app/src/core/communication/can.rs b/app/src/core/communication/can.rs index 2b22dbb25..b09d3f03a 100644 --- a/app/src/core/communication/can.rs +++ b/app/src/core/communication/can.rs @@ -10,24 +10,13 @@ use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::peripherals::{FDCAN1, FDCAN2}; use embassy_sync::blocking_mutex::raw::NoopRawMutex; use embassy_sync::priority_channel::{Receiver, Sender}; -use embedded_hal::can::Id; +// use embedded_hal::can::Id; use heapless::binary_heap::Max; use heapless::Vec; use crate::{CanReceiver, DATA_IDS, DataReceiver, DataSender, Datatype, Event, EVENT_IDS, EventSender}; use crate::core::communication::Datapoint; -use crate::pconfig::bytes_to_u64; +use crate::pconfig::{bytes_to_u64, id_as_value}; -pub trait Transmittable { - fn id_value(&self) -> u16; -} -impl Transmittable for embedded_hal::can::Id { - fn id_value(&self) -> u16 { - match self { - embedded_hal::can::Id::Standard(x) => *x.as_raw(), - embedded_hal::can::Id::Extended(y) => *y.as_raw() as u16, - } - } -} #[embassy_executor::task] pub async fn can_transmitter( @@ -52,14 +41,15 @@ pub async fn can_receiving_handler( loop { match bus.read().await { Ok((frame, timestamp)) => { - if DATA_IDS.contains(frame.id_value()) { + let id = id_as_value(frame.id()); + if DATA_IDS.contains(&id) { data_sender.send(Datapoint::new( - Datatype::from_id(frame.id_value()), + Datatype::from_id(id), bytes_to_u64(frame.data()), timestamp.as_ticks()) ).await; - } else if EVENT_IDS.contains(frame.id_value()) { - event_sender.send(Event::from_id(frame.id_value())) + } else if EVENT_IDS.contains(&id) { + event_sender.send(Event::from_id(id)).await; } } Err(_) => { diff --git a/app/src/core/communication/tcp.rs b/app/src/core/communication/tcp.rs index 12c59582d..f7e1d7d0c 100644 --- a/app/src/core/communication/tcp.rs +++ b/app/src/core/communication/tcp.rs @@ -95,15 +95,15 @@ pub async fn tcp_connection_handler( event_sender.send(Event::EmergencyBrakeCommand).await; #[cfg(debug_assertions)] info!("[tcp] EmergencyBrake command received!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - socket.flush(); - socket.write_all(b"") + socket.flush().await; + socket.write_all(b"").await; } Command::DefaultCommand(_) => { #[cfg(debug_assertions)] info!("[tcp] DefaultCommand received, unsure what to do with it..."); - socket.flush(); + socket.flush().await; socket.write_all(b"DefaultCommand received, unsure what to do with it...").await; - socket.flush(); + socket.flush().await; } Command::Levitate(_) => { #[cfg(debug_assertions)] diff --git a/app/src/core/controllers/can_controller.rs b/app/src/core/controllers/can_controller.rs index 0c6bf862e..28b3ca45f 100644 --- a/app/src/core/controllers/can_controller.rs +++ b/app/src/core/controllers/can_controller.rs @@ -33,7 +33,7 @@ use embassy_stm32::{can, Peripheral, Peripherals}; use embassy_stm32::gpio::low_level::Pin; use embassy_stm32::peripherals::{FDCAN1, FDCAN2}; use embassy_time::{Duration, Instant, Timer}; -use crate::core::communication::can::{can_one_receiving_handler, can_receiving_handler, can_transmitter, can_two_receiver_handler}; +use crate::core::communication::can::{can_receiving_handler, can_transmitter, can_two_receiver_handler}; use crate::core::controllers::ethernet_controller::EthernetPins; diff --git a/app/src/pconfig.rs b/app/src/pconfig.rs index 236d5c562..43492019b 100644 --- a/app/src/pconfig.rs +++ b/app/src/pconfig.rs @@ -6,7 +6,8 @@ use embassy_stm32::can::config; use embassy_stm32::rcc::Pll; use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; use embassy_stm32::rcc::*; - +// use embedded_hal::can::Id; +use embedded_can::Id; use embedded_nal_async::AddrType::IPv4; #[inline] @@ -66,4 +67,15 @@ pub fn bytes_to_u64(b : &[u8]) -> u64 { x |= (b[i] as u64) << i; } x +} + +pub fn id_as_value(id : &embedded_can::Id) -> u16 { + match id { + Id::Standard(x) => { + x.as_raw() + } + Id::Extended(y) => { + y.as_raw() as u16 + } + } } \ No newline at end of file