Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Jun 9, 2022
1 parent e9aa87d commit 9eb1a41
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ Constructing Packets

Constructing packets happens using the `Builder` variant of the packet, for example:
```
use ublox::{CfgPrtUartBuilder, UartPortId};
use ublox::{CfgPrtUartBuilder, UartPortId, UartMode, DataBits, Parity, StopBits, InProtoMask, OutProtoMask};
let packet: [u8; 28] = CfgPrtUartBuilder {
portid: UartPortId::Uart1,
reserved0: 0,
tx_ready: 0,
mode: 0x8d0,
mode: UartMode::new(DataBits::Eight, Parity::None, StopBits::One),
baud_rate: 9600,
in_proto_mask: 0x07,
out_proto_mask: 0x01,
in_proto_mask: InProtoMask::all(),
out_proto_mask: OutProtoMask::UBLOX,
flags: 0,
reserved5: 0,
}.into_packet_bytes();
Expand Down
8 changes: 4 additions & 4 deletions ublox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
//!
//! Constructing packets happens using the `Builder` variant of the packet, for example:
//! ```
//! use ublox::{CfgPrtUartBuilder, UartPortId};
//! use ublox::{CfgPrtUartBuilder, UartPortId, UartMode, DataBits, Parity, StopBits, InProtoMask, OutProtoMask};
//!
//! let packet: [u8; 28] = CfgPrtUartBuilder {
//! portid: UartPortId::Uart1,
//! reserved0: 0,
//! tx_ready: 0,
//! mode: 0x8d0,
//! mode: UartMode::new(DataBits::Eight, Parity::None, StopBits::One),
//! baud_rate: 9600,
//! in_proto_mask: 0x07,
//! out_proto_mask: 0x01,
//! in_proto_mask: InProtoMask::all(),
//! out_proto_mask: OutProtoMask::UBLOX,
//! flags: 0,
//! reserved5: 0,
//! }.into_packet_bytes();
Expand Down
3 changes: 2 additions & 1 deletion ublox_derive/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ pub fn generate_recv_code_for_packet(pack_descr: &PackDesc) -> TokenStream {
#[doc = "Contains a reference to an underlying buffer, contains accessor methods to retrieve data."]
pub struct #ref_name<'a>(&'a [u8]);
impl<'a> #ref_name<'a> {
#[inline]
pub fn as_bytes(&self) -> &[u8] {
self.0
}
Expand Down Expand Up @@ -361,7 +362,7 @@ pub fn generate_send_code_for_packet(pack_descr: &PackDesc) -> TokenStream {
} else {
ret.extend(quote! {
impl #payload_struct_lifetime #payload_struct #payload_struct_lifetime {
#[inline]
#[inline]
pub fn extend_to<T>(self, out: &mut T)
where
T: core::iter::Extend<u8> +
Expand Down
16 changes: 13 additions & 3 deletions ublox_derive/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ fn test_ubx_packet_recv_simple() {
#[doc = "Contains a reference to an underlying buffer, contains accessor methods to retrieve data."]
pub struct TestRef<'a>(&'a [u8]);
impl<'a> TestRef<'a> {
#[inline]
pub fn as_bytes(&self) -> &[u8] {
self.0
}

#[doc = ""]
#[inline]
pub fn itow(&self) -> u32 {
Expand Down Expand Up @@ -192,6 +197,11 @@ fn test_ubx_packet_recv_dyn_len() {
#[doc = "Contains a reference to an underlying buffer, contains accessor methods to retrieve data."]
pub struct TestRef<'a>(&'a [u8]);
impl<'a> TestRef<'a> {
#[inline]
pub fn as_bytes(&self) -> &[u8] {
self.0
}

#[doc = ""]
#[inline]
pub fn f1_raw(&self) -> &[u8] {
Expand Down Expand Up @@ -308,9 +318,9 @@ fn test_ubx_packet_send() {
ret[13usize] = bytes[3usize];
let bytes = self.a.to_le_bytes();
ret[14usize] = bytes[0usize];
let (ck_a, ck_b) = ubx_checksum(&ret[2..17usize - 2]);
ret[17usize - 2] = ck_a;
ret[17usize - 1] = ck_b;
let (ck_a, ck_b) = ubx_checksum(&ret[2..(Self::PACKET_LEN - 2)]);
ret[Self::PACKET_LEN - 2] = ck_a;
ret[Self::PACKET_LEN - 1] = ck_b;
ret
}
}
Expand Down

0 comments on commit 9eb1a41

Please sign in to comment.