From 9db9539cd4e3e77c2f27405abf4e27d252095fd2 Mon Sep 17 00:00:00 2001 From: XdoctorwhoZ Date: Sun, 29 Dec 2024 07:05:04 +0100 Subject: [PATCH] minor updates --- firmware/Cargo.toml | 4 ++-- firmware/src/api_dio.rs | 28 +++++++++++++-------------- firmware/src/dio_request_processor.rs | 22 ++++++++++++++++++--- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/firmware/Cargo.toml b/firmware/Cargo.toml index 15801a9..a06fc2d 100644 --- a/firmware/Cargo.toml +++ b/firmware/Cargo.toml @@ -32,7 +32,7 @@ irq = "0.2.3" # no_proto = "0.9.60" # protobuf-codegen = "3.5.0" -femtopb = "0.4.5" +femtopb = "0.6.0" serial-line-ip = { git = "https://github.com/Panduza/serial-line-ip-rs", branch = "stream_buffer_feature" } fugit = "0.3.7" @@ -40,7 +40,7 @@ fugit = "0.3.7" rp2040-flash = "0.5.1" [build-dependencies] -femtopb-build = "0.4.5" +femtopb-build = "0.6.0" # cargo build/run [profile.dev] diff --git a/firmware/src/api_dio.rs b/firmware/src/api_dio.rs index d835cf5..b402587 100644 --- a/firmware/src/api_dio.rs +++ b/firmware/src/api_dio.rs @@ -1,5 +1,4 @@ -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::femtopb::Message)] +#[derive(Clone, Copy, PartialEq, ::femtopb::Message)] pub struct PicohaDioRequest<'a> { #[femtopb(enumeration, tag = 1)] pub r#type: ::femtopb::enumeration::EnumValue, @@ -10,7 +9,6 @@ pub struct PicohaDioRequest<'a> { #[femtopb(unknown_fields)] pub unknown_fields: femtopb::UnknownFields<'a>, } -#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::femtopb::Message)] pub struct PicohaDioAnswer<'a> { #[femtopb(enumeration, tag = 1)] @@ -50,11 +48,11 @@ impl RequestType { /// (if the ProtoBuf definition does not change) and safe for programmatic use. pub fn as_str_name(&self) -> &'static str { match self { - RequestType::Ping => "PING", - RequestType::SetPinDirection => "SET_PIN_DIRECTION", - RequestType::SetPinValue => "SET_PIN_VALUE", - RequestType::GetPinDirection => "GET_PIN_DIRECTION", - RequestType::GetPinValue => "GET_PIN_VALUE", + Self::Ping => "PING", + Self::SetPinDirection => "SET_PIN_DIRECTION", + Self::SetPinValue => "SET_PIN_VALUE", + Self::GetPinDirection => "GET_PIN_DIRECTION", + Self::GetPinValue => "GET_PIN_VALUE", } } /// Creates an enum from field names used in the ProtoBuf definition. @@ -69,6 +67,8 @@ impl RequestType { } } } +/// This structure should be splitted +/// 1 for values and 1 for directions #[derive( Clone, Copy, @@ -96,10 +96,10 @@ impl PinValue { /// (if the ProtoBuf definition does not change) and safe for programmatic use. pub fn as_str_name(&self) -> &'static str { match self { - PinValue::Low => "LOW", - PinValue::High => "HIGH", - PinValue::Input => "INPUT", - PinValue::Output => "OUTPUT", + Self::Low => "LOW", + Self::High => "HIGH", + Self::Input => "INPUT", + Self::Output => "OUTPUT", } } /// Creates an enum from field names used in the ProtoBuf definition. @@ -138,8 +138,8 @@ impl AnswerType { /// (if the ProtoBuf definition does not change) and safe for programmatic use. pub fn as_str_name(&self) -> &'static str { match self { - AnswerType::Success => "SUCCESS", - AnswerType::Failure => "FAILURE", + Self::Success => "SUCCESS", + Self::Failure => "FAILURE", } } /// Creates an enum from field names used in the ProtoBuf definition. diff --git a/firmware/src/dio_request_processor.rs b/firmware/src/dio_request_processor.rs index 4d04393..14f5eb5 100644 --- a/firmware/src/dio_request_processor.rs +++ b/firmware/src/dio_request_processor.rs @@ -230,15 +230,19 @@ impl DioRequestProcessor { Ok(()) } - /// + /// Process a request, main entry point /// pub fn process_request( &mut self, serial: &mut SerialPort, request: PicohaDioRequest, ) { + // + // Debug log print_debug_message!("+ processing request: {:?}", request); + // + // Choose the correct process function match request.r#type { femtopb::EnumValue::Known(k) => match k { crate::api_dio::RequestType::Ping => Self::process_request_ping(serial), @@ -300,7 +304,12 @@ impl DioRequestProcessor { serial: &mut SerialPort, request: PicohaDioRequest, ) { + // + // Debug log print_debug_message!(b"\tprocessing request: SET_PIN_VALUE\r\n"); + + // + // Process the request let r = match request.value { femtopb::EnumValue::Known(v) => match v { crate::api_dio::PinValue::Low => self.set_pin_low(request.pin_num), @@ -372,11 +381,17 @@ impl DioRequestProcessor { serial: &mut SerialPort, request: PicohaDioRequest, ) { + // + // Debug log print_debug_message!(b" * processing request: GET_PIN_VALUE\r\n"); + + // + // Prepare a default answer let mut answer = PicohaDioAnswer::default(); answer.r#type = femtopb::EnumValue::Known(crate::api_dio::AnswerType::Success); - + // + // Fill the return message match self.get_internal_pin_value(request.pin_num as usize) { Some(val) => { answer.r#type = femtopb::EnumValue::Known(crate::api_dio::AnswerType::Success); @@ -396,7 +411,8 @@ impl DioRequestProcessor { }, } - + // + // Send back the message Self::send_answer(serial, answer); }