cargo fmt + max size of a payload at send
This commit is contained in:
@@ -10,9 +10,8 @@ use embassy_stm32::gpio::{Output, Pull};
|
|||||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||||
use embassy_sync::channel::Channel;
|
use embassy_sync::channel::Channel;
|
||||||
use embassy_time::Duration;
|
use embassy_time::Duration;
|
||||||
use semestralka2::receive::bit_receive_and_decode;
|
|
||||||
use semestralka2::level_for_bit;
|
use semestralka2::level_for_bit;
|
||||||
use semestralka2::send::Tx;
|
use semestralka2::receive::bit_receive_and_decode;
|
||||||
use semestralka2::send::{bit_send, msg_encode};
|
use semestralka2::send::{bit_send, msg_encode};
|
||||||
|
|
||||||
use {defmt_rtt as _, panic_probe as _};
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ use embassy_sync::{
|
|||||||
};
|
};
|
||||||
use embassy_time::{Duration, Ticker};
|
use embassy_time::{Duration, Ticker};
|
||||||
|
|
||||||
use crate::{level_for_bit, Encoding};
|
use crate::{Encoding, level_for_bit};
|
||||||
|
|
||||||
const START: u8 = 0x7E;
|
const START: u8 = 0x7E;
|
||||||
const STOP: u8 = 0x81;
|
const STOP: u8 = 0x81;
|
||||||
|
const MAX_PAYLOAD: usize = 64;
|
||||||
const BIT_PERIOD: Duration = Duration::from_millis(10);
|
const BIT_PERIOD: Duration = Duration::from_millis(10);
|
||||||
|
|
||||||
pub type Tx = Sender<'static, CriticalSectionRawMutex, u8, 128>;
|
pub type Tx = Sender<'static, CriticalSectionRawMutex, u8, 128>;
|
||||||
@@ -26,7 +27,11 @@ async fn send_byte(byte: u8, tx: &Tx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// [START] [LEN] [PAYLOAD ...] [CRC] [P] [STOP]
|
/// [START] [LEN] [PAYLOAD ...] [CRC] [P] [STOP]
|
||||||
pub async fn msg_encode(payload: &[u8], tx: &Tx) {
|
pub async fn msg_encode(payload: &[u8], tx: &Tx) -> Result<(), ()> {
|
||||||
|
if payload.len() > MAX_PAYLOAD {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
|
||||||
// start
|
// start
|
||||||
send_byte(START, tx).await;
|
send_byte(START, tx).await;
|
||||||
|
|
||||||
@@ -54,6 +59,8 @@ pub async fn msg_encode(payload: &[u8], tx: &Tx) {
|
|||||||
|
|
||||||
// idle
|
// idle
|
||||||
tx.send(1).await;
|
tx.send(1).await;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn crc8(crc: u8, byte: u8) -> u8 {
|
fn crc8(crc: u8, byte: u8) -> u8 {
|
||||||
|
|||||||
Reference in New Issue
Block a user