Skip to content

Commit

Permalink
Update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
flosse committed Mar 19, 2024
1 parent 8a753ed commit b917b4c
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/codec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<'r> TryFrom<&'r [u8]> for Request<'r> {
return Err(Error::ByteCount(write_count));
}
let data = Data {
quantity: write_quantity as usize,
quantity: write_quantity,
data: &bytes[10..10 + write_count as usize],
};
ReadWriteMultipleRegisters(read_address, read_quantity, write_address, data)
Expand Down
7 changes: 3 additions & 4 deletions src/codec/rtu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ pub fn decode(
Response => "response",
};
if drop_cnt + 1 >= MAX_FRAME_LEN {
error!(
"Giving up to decode frame after dropping {} byte(s): {:X?}",
drop_cnt,
log::error!(
"Giving up to decode frame after dropping {drop_cnt} byte(s): {:X?}",
&buf[0..drop_cnt]
);
return Err(err);
}
warn!("Failed to decode {} frame: {}", pdu_type, err);
log::warn!("Failed to decode {pdu_type} frame: {err}");
drop_cnt += 1;
retry = true;
Ok(None)
Expand Down
2 changes: 1 addition & 1 deletion src/codec/rtu/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn decode_request(buf: &[u8]) -> Result<Option<RequestAdu>> {
.map(|pdu| Some(RequestAdu { hdr, pdu }))
.map_err(|err| {
// Unrecoverable error
error!("Failed to decode request PDU: {}", err);
log::error!("Failed to decode request PDU: {err}");
err
})
} else {
Expand Down
7 changes: 3 additions & 4 deletions src/codec/tcp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,13 @@ pub fn decode(
Response => "response",
};
if drop_cnt + 1 >= MAX_FRAME_LEN {
error!(
"Giving up to decode frame after dropping {} byte(s): {:X?}",
drop_cnt,
log::error!(
"Giving up to decode frame after dropping {drop_cnt} byte(s): {:X?}",
&buf[0..drop_cnt]
);
return Err(err);
}
warn!("Failed to decode {} frame: {}", pdu_type, err);
log::warn!("Failed to decode {pdu_type} frame: {err}");
drop_cnt += 1;
retry = true;
Ok(None)
Expand Down
4 changes: 2 additions & 2 deletions src/codec/tcp/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn decode_request(buf: &[u8]) -> Result<Option<RequestAdu>> {
.map(|pdu| Some(RequestAdu { hdr, pdu }))
.map_err(|err| {
// Unrecoverable error
error!("Failed to decode request PDU: {}", err);
log::error!("Failed to decode request PDU: {err}");
err
})
} else {
Expand Down Expand Up @@ -62,7 +62,7 @@ pub fn decode_response(buf: &[u8]) -> Result<Option<ResponseAdu>> {
.map(|pdu| Some(ResponseAdu { hdr, pdu }))
.map_err(|err| {
// Unrecoverable error
error!("Failed to decode response PDU: {}", err);
log::error!("Failed to decode response PDU: {err}");
err
})
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/frame/coils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub fn pack_coils(coils: &[Coil], bytes: &mut [u8]) -> Result<usize, Error> {
}
coils.iter().enumerate().for_each(|(i, b)| {
let v = if *b { 0b1 } else { 0b0 };
bytes[(i / 8) as usize] |= v << (i % 8);
bytes[i / 8] |= v << (i % 8);
});
Ok(packed_size)
}
Expand Down Expand Up @@ -238,8 +238,8 @@ mod tests {

#[test]
fn convert_coil_to_bool() {
assert_eq!(u16_coil_to_bool(0xFF00).unwrap(), true);
assert_eq!(u16_coil_to_bool(0x0000).unwrap(), false);
assert!(u16_coil_to_bool(0xFF00).unwrap());
assert!(!u16_coil_to_bool(0x0000).unwrap());
assert_eq!(
u16_coil_to_bool(0x1234).err().unwrap(),
Error::CoilValue(0x1234)
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#![doc = include_str!("../README.md")]
#![no_std]

#[macro_use]
extern crate log;

mod codec;
mod error;
mod frame;
Expand Down

0 comments on commit b917b4c

Please sign in to comment.