Skip to content

Commit

Permalink
compiler was right i was wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Tsatsanis committed Apr 23, 2024
1 parent da9c35e commit b04bd6b
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 33 deletions.
1 change: 1 addition & 0 deletions app/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 0 additions & 2 deletions app/build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions app/build/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions app/build/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
24 changes: 7 additions & 17 deletions app/src/core/communication/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(_) => {
Expand Down
8 changes: 4 additions & 4 deletions app/src/core/communication/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion app/src/core/controllers/can_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
14 changes: 13 additions & 1 deletion app/src/pconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
}
}
}

0 comments on commit b04bd6b

Please sign in to comment.