From 2748efb3a7475027b9cab31e54718d0c2cfe1805 Mon Sep 17 00:00:00 2001 From: XdoctorwhoZ Date: Sun, 21 Jul 2024 06:04:41 +0100 Subject: [PATCH] up --- src/app_dio.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/app_dio.rs b/src/app_dio.rs index a55ba37..b7ac0a1 100644 --- a/src/app_dio.rs +++ b/src/app_dio.rs @@ -2,6 +2,9 @@ use crate::{api_dio::PicohaDioRequest, print_debug_message}; use core::fmt::Write; +// Message deserialization support +use femtopb::Message; + // USB Communications Class Device support use usbd_serial::SerialPort; @@ -43,10 +46,24 @@ impl AppDio { /// Try to decode a request from the incoming data buffer /// - fn try_to_decode_request(&self) -> Option { + fn try_to_decode_request(&mut self) -> Option { let mut slip_decoder = serial_line_ip::Decoder::new(); - // match slip_decoder.decode(&cmd_buf[..cmd_buf_size], &mut decoded_buffer) { + slip_decoder + .decode(&self.in_buf[..self.in_buf_size], &mut self.decode_buffer) + .map(|(input_bytes_processed, output_slice, is_end_of_packet)| { + match PicohaDioRequest::decode(output_slice) { + Ok(ppp) => { + print_debug_message!("deco {:?}", ppp.pin_num); + Some(ppp) + } + Err(e) => { + print_debug_message!("error deco {:?}", e); + None + } + } + }); + // Ok((input_bytes_processed, output_slice, is_end_of_packet)) => { None