Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrMuellerluedenscheid committed Jan 10, 2025
1 parent babe7c3 commit 47ca918
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 57 deletions.
6 changes: 3 additions & 3 deletions src/at_command/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ impl AtRequest for At {
fn parse_response(&self, data: &[u8]) -> Result<AtResponse, AtError> {
#[cfg(feature = "defmt")]
info!("parse_response {=[u8]:a}", data);
let (matready, cfun) = at_commands::parser::CommandParser::parse(data)
let (_matready, _cfun) = at_commands::parser::CommandParser::parse(data)
.expect_identifier(b"AT\r\r\n")
.expect_raw_string()
.expect_identifier(b"\r\n\r\n")
.expect_raw_string()
.expect_identifier(b"\r\nAT\r\r\nOK\r")
.finish()
.inspect_err(|e| {
.inspect_err(|_e| {
#[cfg(feature = "defmt")]
error!("Failed to parse response: {=[u8]:a}", data);
})?;
#[cfg(feature = "defmt")]
info!("matready: {} | cfun: {}", matready, cfun);
info!("matready: {} | cfun: {}", _matready, _cfun);
Ok(AtResponse::Ok)
}
}
2 changes: 1 addition & 1 deletion src/at_command/ate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::at_command::{AtRequest, AtResponse, BufferType};
use crate::at_command::{AtRequest, BufferType};
use crate::AtError;

#[cfg_attr(feature = "defmt", derive(defmt::Format))]
Expand Down
9 changes: 6 additions & 3 deletions src/at_command/battery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use crate::at_command::{AtRequest, AtResponse, BufferType};
use crate::AtError;
use at_commands::parser::CommandParser;

#[allow(dead_code)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct BatteryChargeStatus{
pub struct BatteryChargeStatus {
capacity_percent: i32,
voltage_millivolt: i32,
}


#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct BatteryCharge;

Expand All @@ -28,7 +28,10 @@ impl AtRequest for BatteryCharge {
.expect_int_parameter()
.expect_identifier(b"\r\n\r\nOK")
.finish()?;
let status = BatteryChargeStatus{capacity_percent, voltage_millivolt};
let status = BatteryChargeStatus {
capacity_percent,
voltage_millivolt,
};
Ok(AtResponse::BatteryCharge(status))
}
}
5 changes: 2 additions & 3 deletions src/at_command/ceer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::at_command::{AtRequest, AtResponse, BufferType};
use crate::AtError;
use at_commands::parser::CommandParser;

#[cfg(feature = "defmt")]
use defmt::info;
Expand All @@ -17,9 +16,9 @@ impl AtRequest for ExtendedErrorReport {
.finish()
}

fn parse_response(&self, data: &[u8]) -> Result<AtResponse, AtError> {
fn parse_response(&self, _data: &[u8]) -> Result<AtResponse, AtError> {
#[cfg(feature = "defmt")]
info!("error report response: {=[u8]:a}", data);
info!("error report response: {=[u8]:a}", _data);
Ok(AtResponse::Ok)
}
}
6 changes: 0 additions & 6 deletions src/at_command/cmee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,4 @@ impl AtRequest for SetReportMobileEquipmentError {
.with_int_parameter(setting)
.finish()
}

fn parse_response(&self, data: &[u8]) -> Result<AtResponse, AtError> {
#[cfg(feature = "defmt")]
info!("error report response write: {=[u8]:a}", data);
Ok(AtResponse::Ok)
}
}
28 changes: 14 additions & 14 deletions src/at_command/flow_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ use at_commands::parser::CommandParser;
use defmt::info;

#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum FlowControl {
pub enum ControlFlowStatus {
No,
Software,
Hardware,
}

#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct SetFlowControl {
pub(crate) ta_to_te: FlowControl,
pub(crate) te_to_ta: FlowControl,
pub(crate) ta_to_te: ControlFlowStatus,
pub(crate) te_to_ta: ControlFlowStatus,
}

impl FlowControl {
impl ControlFlowStatus {
fn to_int(&self) -> i32 {
match self {
FlowControl::No => 0,
FlowControl::Software => 1,
FlowControl::Hardware => 2,
ControlFlowStatus::No => 0,
ControlFlowStatus::Software => 1,
ControlFlowStatus::Hardware => 2,
}
}
}
Expand Down Expand Up @@ -65,19 +65,19 @@ impl AtRequest for GetFlowControl {
.expect_raw_string()
.finish()?;
let dce_by_dte = match dce_by_dte {
0 => FlowControl::No,
1 => FlowControl::Software,
2 => FlowControl::Hardware,
0 => ControlFlowStatus::No,
1 => ControlFlowStatus::Software,
2 => ControlFlowStatus::Hardware,
_ => panic!("Invalid dce-by-dte parameter returned"),
};
let dte_by_dce = match dte_by_dce {
0 => FlowControl::No,
1 => FlowControl::Software,
2 => FlowControl::Hardware,
0 => ControlFlowStatus::No,
1 => ControlFlowStatus::Software,
2 => ControlFlowStatus::Hardware,
_ => panic!("Invalid dce-by-dte parameter returned"),
};
#[cfg(feature = "defmt")]
info!("parity {}, {}", dce_by_dte, dte_by_dce);
Ok(AtResponse::Ok {})
Ok(AtResponse::ControlFlow(dce_by_dte, dte_by_dce))
}
}
6 changes: 0 additions & 6 deletions src/at_command/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ impl AtRequest for HttpConnect {
.with_int_parameter(self.client_id)
.finish()
}

fn parse_response(&self, data: &[u8]) -> Result<AtResponse, AtError> {
#[cfg(feature = "defmt")]
info!("parsing {=[u8]:a}", data);
Ok(AtResponse::Ok)
}
}

/// Disconnect from a server
Expand Down
6 changes: 4 additions & 2 deletions src/at_command/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::at_command::at_cgatt::GPRSServiceState;
use crate::at_command::battery::BatteryChargeStatus;
use crate::at_command::flow_control::ControlFlowStatus;
use crate::at_command::mqtt::UsedState;
use crate::at_command::network_information::{NetworkFormat, NetworkMode, NetworkOperator};
use crate::at_command::network_registration_status::{
Expand All @@ -10,7 +12,6 @@ use crate::at_command::sleep_indication::SleepIndication;
use crate::{AtError, BUFFER_SIZE};
#[cfg(feature = "defmt")]
use defmt::debug;
use crate::at_command::battery::BatteryChargeStatus;

pub mod at;
pub mod at_cgatt;
Expand All @@ -20,6 +21,7 @@ pub mod at_csq;
pub mod at_cstt;
pub mod ate;
pub mod ati;
pub mod battery;
pub mod ceer;
pub mod cgcontrdp;
pub mod clock;
Expand All @@ -34,7 +36,6 @@ pub mod ntp;
pub mod pdp_context;
pub mod power_saving_mode;
pub mod sleep_indication;
pub mod battery;

type BufferType = [u8; BUFFER_SIZE];

Expand All @@ -58,6 +59,7 @@ pub enum AtResponse {
SleepIndication(SleepIndication),
PowerSavingMode(PowerSavingModeState),
BatteryCharge(BatteryChargeStatus),
ControlFlow(ControlFlowStatus, ControlFlowStatus),
}

pub trait AtRequest {
Expand Down
2 changes: 1 addition & 1 deletion src/at_command/model_identification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl AtRequest for ModelIdentification {
.expect_raw_string()
.expect_identifier(b"\r\n\r\nOK")
.finish()
.inspect(|e| {
.inspect(|_e| {
#[cfg(feature = "defmt")]
error!("Failed to parse response: {=[u8]:a}", data);
})?;
Expand Down
12 changes: 6 additions & 6 deletions src/at_command/mqtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ impl MQTTSessionWrapper {
match self {
Disconnected(session) => match session.create_session(modem, session_settings) {
Ok(session) => Ok(Self::Connected(session)),
Err(err) => {
Err(_e) => {
#[cfg(feature = "defmt")]
error!("{:?}", err);
error!("{:?}", _e);
Err(MQTTError::Disconnected)
}
},
Expand All @@ -130,9 +130,9 @@ impl MQTTSessionWrapper {
MQTTSessionWrapper::Connected(session) => {
match session.connect(modem, connection_settings) {
Ok(session) => Ok(Self::ConnectedGood(session)),
Err(err) => {
Err(_e) => {
#[cfg(feature = "defmt")]
error!("{:?}", err);
error!("{:?}", _e);
Err(MQTTError::Disconnected)
}
}
Expand Down Expand Up @@ -193,9 +193,9 @@ impl<'a> MQTTSession<StateDisconnected> {
Ok(AtResponse::MQTTSessionCreated(mqtt_connection_id)) => Ok(MQTTSession {
state: StateConnected { mqtt_connection_id },
}),
Ok(response) => {
Ok(_response) => {
#[cfg(feature = "defmt")]
error!("unexpected response from mqtt modem: {:?}", response);
error!("unexpected response from mqtt modem: {:?}", _response);
Err(AtError::ErrorReply(0))
}
Err(e) => Err(e),
Expand Down
1 change: 1 addition & 0 deletions src/at_command/network_information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use at_commands::parser::CommandParser;
#[cfg(feature = "defmt")]
use defmt::info;

#[allow(dead_code)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct NetworkOperator([u8; 10]);

Expand Down
2 changes: 1 addition & 1 deletion src/at_command/power_saving_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl AtRequest for SetPowerSavingMode {
}

fn parse_response(&self, data: &[u8]) -> Result<AtResponse, AtError> {
let (state, context) = CommandParser::parse(data)
let (state, _context) = CommandParser::parse(data)
.expect_identifier(b"\r\n+CPSMS: ")
.expect_int_parameter()
.expect_int_parameter()
Expand Down
22 changes: 11 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ pub mod at_command;
pub mod nonblocking;

use crate::at_command::cmee::ReportMobileEquipmentErrorSetting;
use crate::at_command::flow_control::FlowControl;
use crate::at_command::flow_control::ControlFlowStatus;
use crate::at_command::http::HttpClient;
use at_command::AtRequest;
use at_command::AtResponse;
use at_commands::parser::ParseError;
use core::ptr::read;
#[cfg(feature = "defmt")]
use defmt::*;
use embedded_io::{Error, ErrorKind};
pub use embedded_io::{ErrorType, Read, Write};
#[cfg(feature = "defmt")]
use embedded_io::Error;
pub use embedded_io::{Read, Write};

const BUFFER_SIZE: usize = 512;
const LF: u8 = 10; // n
Expand Down Expand Up @@ -80,8 +80,8 @@ impl<'a, T: Write, U: Read> Modem<'a, T, U> {

pub fn set_flow_control(&mut self) -> Result<(), AtError> {
self.send_and_wait_reply(&at_command::flow_control::SetFlowControl {
ta_to_te: FlowControl::Software,
te_to_ta: FlowControl::Software,
ta_to_te: ControlFlowStatus::Software,
te_to_ta: ControlFlowStatus::Software,
})
.expect("TODO: panic message");
Ok(())
Expand All @@ -104,18 +104,18 @@ impl<'a, T: Write, U: Read> Modem<'a, T, U> {

#[cfg(feature = "defmt")]
debug!("sending command: {=[u8]:a}", data);
self.writer.write(&data).map_err(|e| AtError::IOError)?;
self.writer.write(&data).map_err(|_e| AtError::IOError)?;

let mut read_buffer = [0; BUFFER_SIZE];
let response_size = self.read_response(&mut read_buffer)?;
let response = payload.parse_response(&read_buffer[..response_size]);
match response {
Ok(response) => Ok(response),
Err(e) => {
Err(_e) => {
#[cfg(feature = "defmt")]
error!(
"{}\nparse response failed on request: {=[u8]:a}\n response: {=[u8]:a}",
e,
_e,
&data,
&read_buffer[..response_size]
);
Expand Down Expand Up @@ -175,9 +175,9 @@ impl<'a, T: Write, U: Read> Modem<'a, T, U> {
offset += num_bytes;
}

Err(e) => {
Err(_e) => {
#[cfg(feature = "defmt")]
error!("uart error {}", e.kind());
error!("uart error {}", _e.kind());
return Err(AtError::NotReady);
}
}
Expand Down

0 comments on commit 47ca918

Please sign in to comment.