From 8c95b3343d5aef9d2fdd2a7d15922d4e6e28f837 Mon Sep 17 00:00:00 2001 From: Priec Date: Thu, 28 May 2026 07:57:25 +0200 Subject: [PATCH] cargo fmt + max size of a payload at send --- 2sem_sem2/src/bin/main.rs | 3 +-- 2sem_sem2/src/send.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/2sem_sem2/src/bin/main.rs b/2sem_sem2/src/bin/main.rs index c1e2510..d9817b4 100644 --- a/2sem_sem2/src/bin/main.rs +++ b/2sem_sem2/src/bin/main.rs @@ -10,9 +10,8 @@ use embassy_stm32::gpio::{Output, Pull}; use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; use embassy_sync::channel::Channel; use embassy_time::Duration; -use semestralka2::receive::bit_receive_and_decode; use semestralka2::level_for_bit; -use semestralka2::send::Tx; +use semestralka2::receive::bit_receive_and_decode; use semestralka2::send::{bit_send, msg_encode}; use {defmt_rtt as _, panic_probe as _}; diff --git a/2sem_sem2/src/send.rs b/2sem_sem2/src/send.rs index 6867619..aaef132 100644 --- a/2sem_sem2/src/send.rs +++ b/2sem_sem2/src/send.rs @@ -7,10 +7,11 @@ use embassy_sync::{ }; use embassy_time::{Duration, Ticker}; -use crate::{level_for_bit, Encoding}; +use crate::{Encoding, level_for_bit}; const START: u8 = 0x7E; const STOP: u8 = 0x81; +const MAX_PAYLOAD: usize = 64; const BIT_PERIOD: Duration = Duration::from_millis(10); 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] -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 send_byte(START, tx).await; @@ -54,6 +59,8 @@ pub async fn msg_encode(payload: &[u8], tx: &Tx) { // idle tx.send(1).await; + + Ok(()) } fn crc8(crc: u8, byte: u8) -> u8 {