Skip to content

Commit dfa10b2

Browse files
committed
no alloc maybe
1 parent 9831faf commit dfa10b2

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

src/cc253x.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use crate::{
2-
coordinator::{Coordinator, CoordinatorError, LedStatus, ResetType},
2+
coordinator::{AddressMode, Coordinator, CoordinatorError, LedStatus, ResetType},
33
unpi::{
44
commands::{get_command_by_name, ParameterValue},
55
LenTypeInfo, MessageType, Subsystem, UnpiPacket, MAX_FRAME_SIZE,
66
},
7-
AddressMode,
87
};
98
use serialport::SerialPort;
109
use std::{path::PathBuf, time::Duration};
@@ -22,7 +21,7 @@ impl CC2531X {
2221
let serial = serialport::new(path.to_str().unwrap(), baud_rate)
2322
.timeout(Duration::from_millis(10))
2423
.open()
25-
.map_err(|e| CoordinatorError::SerialOpen(e.to_string()))?;
24+
.map_err(|_e| CoordinatorError::SerialOpen)?;
2625
Ok(Self {
2726
serial,
2827
_supports_led: None,
@@ -34,7 +33,6 @@ impl CC2531X {
3433
name: &str,
3534
message_type: MessageType,
3635
subsystem: Subsystem,
37-
command: u8,
3836
_timeout: Option<std::time::Duration>,
3937
) -> Result<(), CoordinatorError> {
4038
let command =
@@ -43,7 +41,7 @@ impl CC2531X {
4341
let len = self
4442
.serial
4543
.read(&mut buffer)
46-
.map_err(|e| CoordinatorError::Io(e.to_string()))?;
44+
.map_err(|_e| CoordinatorError::Io)?;
4745
let packet = UnpiPacket::from_payload(
4846
(&buffer[..len], LenTypeInfo::OneByte),
4947
(message_type, subsystem),
@@ -52,7 +50,7 @@ impl CC2531X {
5250
if packet.type_subsystem == (message_type, subsystem) && packet.command == command.id {
5351
Ok(())
5452
} else {
55-
Err(CoordinatorError::Io("Unexpected message".to_string()))
53+
Err(CoordinatorError::Io)
5654
}
5755
}
5856
}

src/coordinator.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ pub trait Coordinator {
4040
) -> impl Future<Output = Result<Option<Self::ZclPayload<'static>>, CoordinatorError>>;
4141
}
4242

43+
pub enum AddressMode {
44+
AddrNotPresent = 0,
45+
AddrGroup = 1,
46+
Addr16bit = 2,
47+
Addr64bit = 3,
48+
AddrBroadcast = 15,
49+
}
50+
4351
#[derive(Debug, Copy, Clone)]
4452
pub enum LedStatus {
4553
Disable,
@@ -55,10 +63,10 @@ pub enum ResetType {
5563

5664
#[derive(Debug)]
5765
pub enum CoordinatorError {
58-
SerialOpen(String),
59-
SerialWrite(String),
66+
SerialOpen,
67+
SerialWrite,
6068
NoCommandWithName,
61-
Io(String),
69+
Io,
6270
Parameter(ParameterError),
6371
InvalidChannel,
6472
RequestMismatch,
@@ -67,8 +75,8 @@ pub enum CoordinatorError {
6775
}
6876

6977
impl From<std::io::Error> for CoordinatorError {
70-
fn from(e: std::io::Error) -> Self {
71-
CoordinatorError::Io(e.to_string())
78+
fn from(_e: std::io::Error) -> Self {
79+
CoordinatorError::Io
7280
}
7381
}
7482

src/lib.rs

-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ pub mod utils;
55
pub mod cc253x;
66
pub mod serial;
77

8-
pub enum AddressMode {
9-
AddrNotPresent = 0,
10-
AddrGroup = 1,
11-
Addr16bit = 2,
12-
Addr64bit = 3,
13-
AddrBroadcast = 15,
14-
}
158

169
#[cfg(test)]
1710
mod tests {

src/serial.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl<'a> UnpiPacket<'a> {
1919
let written = self.to_bytes(&mut unpi_packet_buffer)?;
2020
serial
2121
.write_all(&unpi_packet_buffer[0..written])
22-
.map_err(|e| CoordinatorError::SerialWrite(e.to_string()))?;
22+
.map_err(|_e| CoordinatorError::SerialWrite)?;
2323
Ok(())
2424
}
2525

0 commit comments

Comments
 (0)