diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 66a8c02..68df0b5 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -26,7 +26,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: doc - args: --verbose --no-deps --features "log" + args: --verbose --no-deps --features "log,lara-r6" # - name: Finalize documentation # run: | diff --git a/.github/workflows/grcov.yml b/.github/workflows/grcov.yml index 57afbeb..840904a 100644 --- a/.github/workflows/grcov.yml +++ b/.github/workflows/grcov.yml @@ -36,7 +36,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: test - args: --lib --no-fail-fast --features "log" + args: --lib --no-fail-fast --features "log,lara-r6" env: CARGO_INCREMENTAL: "0" RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=unwind -Zpanic_abort_tests" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 338dbda..4f385f6 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -11,7 +11,8 @@ defaults: shell: bash env: - CLIPPY_PARAMS: -W clippy::all -W clippy::pedantic -W clippy::nursery -W clippy::cargo + # CLIPPY_PARAMS: -W clippy::all -W clippy::pedantic -W clippy::nursery -W clippy::cargo + CLIPPY_PARAMS: jobs: rustfmt: @@ -81,4 +82,4 @@ jobs: uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} - args: -- ${{ env.CLIPPY_PARAMS }} + args: --features "lara-r6" -- ${{ env.CLIPPY_PARAMS }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 95e5182..85aa2dd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,10 +26,10 @@ jobs: uses: actions-rs/cargo@v1 with: command: build - args: --all --features "defmt-impl" --target thumbv7m-none-eabi + args: --all --features "defmt-impl,lara-r6" --target thumbv7m-none-eabi - name: Test uses: actions-rs/cargo@v1 with: command: test - args: --lib --features "log" + args: --lib --features "log,lara-r6" diff --git a/README.md b/README.md index 0a2c5bb..e8a1990 100644 --- a/README.md +++ b/README.md @@ -42,18 +42,19 @@ The samples can be built using `cargo build -p linux_example --target x86_64-unk ## Features - device selection (must select one, and only one!): - - `topy_l4` - - `mpci_l2` - - `lisa_u2` - - `sara_r5` - - `sara_g3` - - `sara_g4` - - `sara_u2` - - `sara_u1` - - `toby_l2` - - `toby_r2` - - `lara_r2` - - `leon_g1` + - `toby-l4` + - `mpci-l2` + - `lisa-u2` + - `sara-r5` + - `sara-g3` + - `sara-g4` + - `sara-u2` + - `sara-u1` + - `toby-l2` + - `toby-r2` + - `lara-r2` + - `lara-r6` + - `leon-g1` - `socket-tcp`: Enabled by default. Adds TCP socket capabilities, and implements [`TcpStack`] trait. - `socket-udp`: Enabled by default. Adds UDP socket capabilities, and implements [`UdpStack`] trait. - `defmt-impl `: Use `defmt` based logging. Typically used in no_std platforms. diff --git a/ublox-cellular/Cargo.toml b/ublox-cellular/Cargo.toml index 58dc88d..7e83d61 100644 --- a/ublox-cellular/Cargo.toml +++ b/ublox-cellular/Cargo.toml @@ -33,7 +33,7 @@ log = { version = "^0.4", default-features = false, optional = true } defmt = { version = "^0.3", optional = true } [features] -default = ["toby-r2", "socket-udp", "socket-tcp"] +default = ["socket-udp", "socket-tcp"] # Use `defmt-impl to enable defmt based logging defmt-impl = ["defmt", "ublox-sockets/defmt", "fugit/defmt", "atat/defmt", "heapless/defmt-impl"] @@ -41,6 +41,7 @@ defmt-impl = ["defmt", "ublox-sockets/defmt", "fugit/defmt", "atat/defmt", "heap log-impl = ["log", "ublox-sockets/log", "atat/log"] lara-r2 = [] +lara-r6 = [] leon-g1 = [] lisa-u2 = [] mpci-l2 = [] @@ -51,7 +52,7 @@ sara-u1 = [] sara-u2 = ["upsd-context-activation"] toby-l2 = [] toby-r2 = [] -topy-l4 = [] +toby-l4 = [] upsd-context-activation = [] diff --git a/ublox-cellular/src/client.rs b/ublox-cellular/src/client.rs index 00c2bdd..10bc046 100644 --- a/ublox-cellular/src/client.rs +++ b/ublox-cellular/src/client.rs @@ -6,12 +6,25 @@ use ublox_sockets::SocketSet; use crate::{ command::device_lock::{responses::PinStatus, types::PinStatusCode, GetPinStatus}, command::{ - control::{types::*, *}, - mobile_control::{types::*, *}, - system_features::{types::*, *}, - *, + control::{ + types::{Circuit108Behaviour, Circuit109Behaviour, FlowControl}, + SetCircuit108Behaviour, SetCircuit109Behaviour, SetFlowControl, + }, + ip_transport_layer, + mobile_control::{ + types::{AutomaticTimezone, Functionality, ResetMode, TerminationErrorMode}, + SetAutomaticTimezoneUpdate, SetModuleFunctionality, SetReportMobileTerminationError, + }, + network_service, psn, + system_features::{types::PowerSavingMode, SetPowerSavingControl}, + Urc, }, command::{ + general::{GetCCID, GetFirmwareVersion, GetModelId}, + gpio::{ + types::{GpioMode, GpioOutValue}, + SetGpioConfiguration, + }, network_service::{ responses::OperatorSelection, types::OperatorSelectionMode, GetOperatorSelection, SetOperatorSelection, @@ -31,7 +44,6 @@ use psn::{ types::{EPSNetworkRegistrationUrcConfig, GPRSNetworkRegistrationUrcConfig}, SetEPSNetworkRegistrationStatus, SetGPRSNetworkRegistrationStatus, }; -use sms::{types::MessageWaitingMode, SetMessageWaitingIndication}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -143,7 +155,7 @@ where /// ); /// ``` pub fn new(client: C, timer: CLK, config: Config) -> Self { - let mut device = Device { + let mut device = Self { config, state: State::Off, power_state: PowerState::Off, @@ -244,12 +256,12 @@ where // self.is_alive()?; } else { // Make sure AT commands parser is in clean state. - self.network.at_tx.reset()?; + // self.network.at_tx.reset()?; self.power_on()?; } // At this point, if is_alive fails, the configured Baud rate is probably wrong - self.is_alive(20).map_err(|_| Error::BaudDetection)?; + self.is_alive(10).map_err(|_| Error::BaudDetection)?; // Extended errors on self.network.send_internal( @@ -259,6 +271,30 @@ where false, )?; + // Select SIM + self.network.send_internal( + &SetGpioConfiguration { + gpio_id: 25, + gpio_mode: GpioMode::Output(GpioOutValue::High), + }, + false, + )?; + + self.network.send_internal(&GetModelId, false)?; + + // self.network.send_internal( + // &IdentificationInformation { + // n: 9 + // }, + // false, + // )?; + + self.network.send_internal(&GetFirmwareVersion, false)?; + + self.select_sim_card()?; + + self.network.send_internal(&GetCCID, false)?; + // DCD circuit (109) changes in accordance with the carrier self.network.send_internal( &SetCircuit109Behaviour { @@ -422,15 +458,11 @@ where return Ok(()); } - // At this point, if is_alive fails, the configured Baud rate is probably wrong - self.is_alive(20).map_err(|_| Error::BaudDetection)?; - self.setup_at_commands()?; self.select_sim_card()?; // Disable Message Waiting URCs (UMWI) - // SARA-R5 does not support it - #[cfg(not(feature = "sara-r5"))] + #[cfg(any(feature = "toby-r2"))] self.network.send_internal( &SetMessageWaitingIndication { mode: MessageWaitingMode::Disabled, @@ -448,18 +480,11 @@ where self.network.send_internal( &SetModuleFunctionality { fun: Functionality::Full, - rst: Some(ResetMode::DontReset), + rst: None, }, true, )?; - // self.network.send_internal( - // &SetRadioAccessTechnology { - // selected_act: RadioAccessTechnologySelected::GsmUmtsLte(RatPreferred::Lte, RatPreferred::Utran), - // }, - // false, - // )?; - self.network.status.reset(); self.network .status diff --git a/ublox-cellular/src/command/control/mod.rs b/ublox-cellular/src/command/control/mod.rs index 25875a2..6d75312 100644 --- a/ublox-cellular/src/command/control/mod.rs +++ b/ublox-cellular/src/command/control/mod.rs @@ -6,7 +6,7 @@ pub mod types; use atat::atat_derive::AtatCmd; -use types::*; +use types::{BaudRate, Circuit108Behaviour, Circuit109Behaviour, FlowControl, SoftwareFlowControl}; use super::NoResponse; diff --git a/ublox-cellular/src/command/device_data_security/mod.rs b/ublox-cellular/src/command/device_data_security/mod.rs index d9c750d..a1e7dec 100644 --- a/ublox-cellular/src/command/device_data_security/mod.rs +++ b/ublox-cellular/src/command/device_data_security/mod.rs @@ -17,7 +17,7 @@ //! protocol with these AT commands: //! - `AT+USECMNG`: import, removal, list and information retrieval of //! certificates or private keys; -//! - `AT+USECPRF`: configuration of USECMNG (u-blox SECurity MaNaGement) +//! - `AT+USECPRF`: configuration of USECMNG (u-blox `SECurity` `MaNaGement`) //! profiles used for an SSL/TLS connection. //! //! The USECMNG provides a default SSL/TLS profile which cannot be modified. The @@ -44,8 +44,8 @@ pub mod types; use atat::atat_derive::AtatCmd; use heapless::Vec; -use responses::*; -use types::*; +use responses::{SecurityData, SecurityDataImport}; +use types::{SecurityDataType, SecurityProfileOperation}; use super::NoResponse; use crate::services::data::ssl::SecurityProfileId; @@ -165,7 +165,7 @@ pub struct RetrieveSecurityMd5<'a> { /// needs to be issued (e.g. certificate validation level, minimum /// SSL/TLS version, ...). /// - To reset (set to factory-programmed value) all the parameters of a -/// specific security profile, issue the AT+USECPRF= command +/// specific security profile, issue the `AT+USECPRF= command /// (operation: None). #[derive(Clone, AtatCmd)] #[at_cmd("+USECPRF", NoResponse)] diff --git a/ublox-cellular/src/command/device_data_security/responses.rs b/ublox-cellular/src/command/device_data_security/responses.rs index 34adc37..fb33bfe 100644 --- a/ublox-cellular/src/command/device_data_security/responses.rs +++ b/ublox-cellular/src/command/device_data_security/responses.rs @@ -1,5 +1,5 @@ //! Responses for Device and data security Commands -use super::types::*; +use super::types::{SecurityDataType, SecurityOperation}; use atat::atat_derive::AtatResp; use heapless::String; diff --git a/ublox-cellular/src/command/device_lock/impl_.rs b/ublox-cellular/src/command/device_lock/impl_.rs index f65d8b6..538cbd2 100644 --- a/ublox-cellular/src/command/device_lock/impl_.rs +++ b/ublox-cellular/src/command/device_lock/impl_.rs @@ -1,4 +1,4 @@ -use super::types::*; +use super::types::PinStatusCode; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; impl Serialize for PinStatusCode { @@ -7,16 +7,16 @@ impl Serialize for PinStatusCode { S: Serializer, { match *self { - PinStatusCode::Ready => Serializer::serialize_bytes(serializer, b"READY"), - PinStatusCode::SimPin => Serializer::serialize_bytes(serializer, b"SIM PIN"), - PinStatusCode::SimPuk => Serializer::serialize_bytes(serializer, b"SIM PUK"), - PinStatusCode::SimPin2 => Serializer::serialize_bytes(serializer, b"SIM PIN2"), - PinStatusCode::SimPuk2 => Serializer::serialize_bytes(serializer, b"SIM PUK2"), - PinStatusCode::PhNetPin => Serializer::serialize_bytes(serializer, b"PH-NET PIN"), - PinStatusCode::PhNetSubPin => Serializer::serialize_bytes(serializer, b"PH-NETSUB PIN"), - PinStatusCode::PhSpPin => Serializer::serialize_bytes(serializer, b"PH-SP PIN"), - PinStatusCode::PhCorpPin => Serializer::serialize_bytes(serializer, b"PH-CORP PIN"), - PinStatusCode::PhSimPin => Serializer::serialize_bytes(serializer, b"PH-SIM PIN"), + Self::Ready => Serializer::serialize_bytes(serializer, b"READY"), + Self::SimPin => Serializer::serialize_bytes(serializer, b"SIM PIN"), + Self::SimPuk => Serializer::serialize_bytes(serializer, b"SIM PUK"), + Self::SimPin2 => Serializer::serialize_bytes(serializer, b"SIM PIN2"), + Self::SimPuk2 => Serializer::serialize_bytes(serializer, b"SIM PUK2"), + Self::PhNetPin => Serializer::serialize_bytes(serializer, b"PH-NET PIN"), + Self::PhNetSubPin => Serializer::serialize_bytes(serializer, b"PH-NETSUB PIN"), + Self::PhSpPin => Serializer::serialize_bytes(serializer, b"PH-SP PIN"), + Self::PhCorpPin => Serializer::serialize_bytes(serializer, b"PH-CORP PIN"), + Self::PhSimPin => Serializer::serialize_bytes(serializer, b"PH-SIM PIN"), } } } @@ -125,7 +125,7 @@ impl<'de> Deserialize<'de> for PinStatusCode { "PinStatusCode", VARIANTS, Visitor { - marker: core::marker::PhantomData::, + marker: core::marker::PhantomData::, lifetime: core::marker::PhantomData, }, ) diff --git a/ublox-cellular/src/command/device_lock/mod.rs b/ublox-cellular/src/command/device_lock/mod.rs index 8039a29..ab25abb 100644 --- a/ublox-cellular/src/command/device_lock/mod.rs +++ b/ublox-cellular/src/command/device_lock/mod.rs @@ -5,7 +5,7 @@ pub mod responses; pub mod types; use atat::atat_derive::AtatCmd; -use responses::*; +use responses::PinStatus; use super::NoResponse; diff --git a/ublox-cellular/src/command/device_lock/responses.rs b/ublox-cellular/src/command/device_lock/responses.rs index e9649f9..d41b5cf 100644 --- a/ublox-cellular/src/command/device_lock/responses.rs +++ b/ublox-cellular/src/command/device_lock/responses.rs @@ -1,9 +1,10 @@ //! Responses for Device lock Commands -use super::types::*; +use super::types::PinStatusCode; use atat::atat_derive::AtatResp; /// 9.1 Enter PIN +CPIN #[derive(Clone, Debug, PartialEq, Eq, AtatResp)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct PinStatus { #[at_arg(position = 0)] pub code: PinStatusCode, diff --git a/ublox-cellular/src/command/device_lock/types.rs b/ublox-cellular/src/command/device_lock/types.rs index 3df5c89..e230511 100644 --- a/ublox-cellular/src/command/device_lock/types.rs +++ b/ublox-cellular/src/command/device_lock/types.rs @@ -1,6 +1,7 @@ //! Argument and parameter types used by Device lock Commands and Responses #[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum PinStatusCode { /// • READY: MT is not pending for any password Ready, diff --git a/ublox-cellular/src/command/dns/mod.rs b/ublox-cellular/src/command/dns/mod.rs index eea0fa4..599129f 100644 --- a/ublox-cellular/src/command/dns/mod.rs +++ b/ublox-cellular/src/command/dns/mod.rs @@ -17,8 +17,8 @@ pub mod responses; pub mod types; use atat::atat_derive::AtatCmd; -use responses::*; -use types::*; +use responses::ResolveNameIpResponse; +use types::ResolutionType; /// 24.1 Resolve name / IP number through DNS +UDNSRN /// diff --git a/ublox-cellular/src/command/file_system/mod.rs b/ublox-cellular/src/command/file_system/mod.rs index 7abd26a..64b6eaf 100644 --- a/ublox-cellular/src/command/file_system/mod.rs +++ b/ublox-cellular/src/command/file_system/mod.rs @@ -7,7 +7,7 @@ pub mod responses; use atat::atat_derive::AtatCmd; use heapless::{String, Vec}; -use responses::*; +use responses::{ReadBlockResponse, ReadFileResponse}; use super::NoResponse; @@ -45,7 +45,7 @@ use super::NoResponse; /// connection, the DTE will send the binary data over the TCP connection to /// the DCE. The DTE monitors the TCP data port for the binary data transfer /// (for more details on the TCP/IP port configuration, see the -/// parameter of the +UIFCONF AT command). After the +/// <`tcp_data_port`> parameter of the +UIFCONF AT command). After the /// establishment of the TCP connection from the DTE to the specific port, the /// DTE will start the file transfer. The '>' prompt is not provided to the /// user on the AT interface over an IP connection. The DCE will close the @@ -79,7 +79,7 @@ pub struct DownloadFile<'a> { /// 22.3 List files information +ULSTFILE /// /// Retrieves some information about the FS. Depending on the specified -/// , it can print: +/// <`op_code`>, it can print: /// - List of files stored into the FS /// - Remaining free FS space expressed in bytes /// - Size of the specified file expressed in bytes @@ -101,7 +101,7 @@ pub struct ListFiles; /// on the AT interface over an IP connection, the DCE will send the binary /// data over the TCP connection to the DTE. The DTE monitors the TCP data /// port for the binary data transfer (for more details on the TCP/IP port -/// configuration, see the parameter of the +UIFCONF AT +/// configuration, see the <`tcp_data_port`> parameter of the +UIFCONF AT /// command). After the establishment of the TCP connection from the DTE to /// the specific port, the DCE starts the file transfer. The '>' prompt is not /// provided to the user on the AT interface over an IP connection. The DCE diff --git a/ublox-cellular/src/command/general/mod.rs b/ublox-cellular/src/command/general/mod.rs index fb1cf40..7dff0ef 100644 --- a/ublox-cellular/src/command/general/mod.rs +++ b/ublox-cellular/src/command/general/mod.rs @@ -3,8 +3,10 @@ pub mod responses; pub mod types; use atat::atat_derive::AtatCmd; -use responses::*; -use types::*; +use responses::{ + FirmwareVersion, IdentificationInformationResponse, ManufacturerId, ModelId, CCID, CIMI, IMEI, +}; +use types::Snt; /// 4.1 Manufacturer identification +CGMI /// diff --git a/ublox-cellular/src/command/gpio/mod.rs b/ublox-cellular/src/command/gpio/mod.rs index f8f2ea7..28e9d89 100644 --- a/ublox-cellular/src/command/gpio/mod.rs +++ b/ublox-cellular/src/command/gpio/mod.rs @@ -11,8 +11,8 @@ pub mod responses; pub mod types; use atat::atat_derive::AtatCmd; -use responses::*; -use types::*; +use responses::GpioConfiguration; +use types::GpioMode; use super::NoResponse; diff --git a/ublox-cellular/src/command/gpio/responses.rs b/ublox-cellular/src/command/gpio/responses.rs index e4d07e5..56dff21 100644 --- a/ublox-cellular/src/command/gpio/responses.rs +++ b/ublox-cellular/src/command/gpio/responses.rs @@ -1,5 +1,5 @@ //! Responses for GPIO Commands -use super::types::*; +use super::types::GpioMode; use atat::atat_derive::AtatResp; /// 20.2 GPIO select configuration command +UGPIOC diff --git a/ublox-cellular/src/command/gpio/types.rs b/ublox-cellular/src/command/gpio/types.rs index 6883b88..fa6c049 100644 --- a/ublox-cellular/src/command/gpio/types.rs +++ b/ublox-cellular/src/command/gpio/types.rs @@ -2,14 +2,14 @@ use atat::atat_derive::AtatEnum; -/// GPIO output value (for output function =0 only): +/// GPIO output value (for output function <`gpio_mode>=0` only): #[derive(Clone, PartialEq, Eq, AtatEnum)] pub enum GpioOutValue { Low = 0, High = 1, } -/// GPIO input value (for input function =1 only): +/// GPIO input value (for input function <`gpio_mode>=1` only): #[derive(Clone, PartialEq, Eq, AtatEnum)] pub enum GpioInPull { /// (default value): no resistor activated diff --git a/ublox-cellular/src/command/http/mod.rs b/ublox-cellular/src/command/http/mod.rs index 9c36d9e..695fe45 100644 --- a/ublox-cellular/src/command/http/mod.rs +++ b/ublox-cellular/src/command/http/mod.rs @@ -16,7 +16,7 @@ //! //! - **LISA-U200-00S / LISA-U200-01S / LISA-U200-02S / LISA-U200-52S / //! LISA-U200-62S / LISA-U230 / LISA-U260 / LISA-U270 / LISA-U1 / LEON-G1* - -//! If using CellLocate® and HTTP commands HTTP profiles in the range 1-3 must +//! If using `CellLocate`® and HTTP commands HTTP profiles in the range 1-3 must //! be used. pub mod urc; diff --git a/ublox-cellular/src/command/ip_transport_layer/mod.rs b/ublox-cellular/src/command/ip_transport_layer/mod.rs index 3552364..0424448 100644 --- a/ublox-cellular/src/command/ip_transport_layer/mod.rs +++ b/ublox-cellular/src/command/ip_transport_layer/mod.rs @@ -7,8 +7,11 @@ pub mod urc; use atat::atat_derive::AtatCmd; use embedded_nal::IpAddr; -use responses::*; -use types::*; +use responses::{ + CreateSocketResponse, SocketControlResponse, SocketData, SocketErrorResponse, + UDPSendToDataResponse, UDPSocketData, WriteSocketDataResponse, +}; +use types::{HexMode, SocketControlParam, SocketProtocol, SslTlsStatus}; use super::NoResponse; use ublox_sockets::SocketHandle; @@ -36,7 +39,7 @@ pub struct CreateSocket { /// /// Enables or disables the use of SSL/TLS connection on a TCP socket. The /// configuration of the SSL/TLS properties is provided with an SSL/TLS profile -/// managed by USECMNG. The parameter is listed in the +/// managed by USECMNG. The <`usecmng_profile_id`> parameter is listed in the /// information text response to the read command only if the SSL/TLS is enabled /// on the interested socket. /// @@ -61,7 +64,7 @@ pub struct SetSocketSslState { /// Closes the specified socket, like the BSD close routine. In case of remote /// socket closure the user is notified via the URC. \ /// By default the command blocks the AT command interface until the the -/// completion of the socket close operation. By enabling the +/// completion of the socket close operation. By enabling the <`async_close`> /// flag, the final result code is sent immediately. The following +UUSOCL URC /// will indicate the closure of the specified socket. #[derive(Clone, AtatCmd)] @@ -172,7 +175,7 @@ pub struct WriteSocketDataBinary<'a> { pub data: &'a atat::serde_bytes::Bytes, } -///25.11 SendTo command (UDP only) +USOST +///25.11 `SendTo` command (UDP only) +USOST /// /// Writes the specified amount of data to the remote address, /// like the BSD sendto routine, and returns the number of bytes diff --git a/ublox-cellular/src/command/ip_transport_layer/responses.rs b/ublox-cellular/src/command/ip_transport_layer/responses.rs index d81d2fd..1e5c9d6 100644 --- a/ublox-cellular/src/command/ip_transport_layer/responses.rs +++ b/ublox-cellular/src/command/ip_transport_layer/responses.rs @@ -1,5 +1,5 @@ //! Responses for Internet protocol transport layer Commands -use super::types::*; +use super::types::SocketControlParam; use crate::services::data::INGRESS_CHUNK_SIZE; use atat::atat_derive::AtatResp; use embedded_nal::IpAddr; diff --git a/ublox-cellular/src/command/mobile_control/mod.rs b/ublox-cellular/src/command/mobile_control/mod.rs index ea0bd93..832193a 100644 --- a/ublox-cellular/src/command/mobile_control/mod.rs +++ b/ublox-cellular/src/command/mobile_control/mod.rs @@ -4,8 +4,11 @@ pub mod responses; pub mod types; use atat::atat_derive::AtatCmd; -use responses::*; -use types::*; +use responses::{ + DateTime, ExtendedErrorReport, IndicatorControl, ModuleFunctionality, + ReportMobileTerminationError, +}; +use types::{AutomaticTimezone, Functionality, ResetMode, TerminationErrorMode}; use super::NoResponse; diff --git a/ublox-cellular/src/command/mobile_control/responses.rs b/ublox-cellular/src/command/mobile_control/responses.rs index 6ec8691..3f1c253 100644 --- a/ublox-cellular/src/command/mobile_control/responses.rs +++ b/ublox-cellular/src/command/mobile_control/responses.rs @@ -1,5 +1,5 @@ //! Responses for Mobile equipment control and status Commands -use super::types::*; +use super::types::{PowerMode, ReportMobileTerminationErrorStatus, STKMode}; use atat::atat_derive::AtatResp; /// 5.3 Set module functionality +CFUN @@ -9,7 +9,7 @@ pub struct ModuleFunctionality { #[at_arg(position = 0)] pub power_mode: PowerMode, #[at_arg(position = 1)] - pub stk_mode: STKMode, + pub stk_mode: Option, } /// 5.4 Indicator control +CIND diff --git a/ublox-cellular/src/command/mobile_control/types.rs b/ublox-cellular/src/command/mobile_control/types.rs index 52679e7..04f8349 100644 --- a/ublox-cellular/src/command/mobile_control/types.rs +++ b/ublox-cellular/src/command/mobile_control/types.rs @@ -13,6 +13,7 @@ pub enum Functionality { feature = "sara-u2", feature = "toby-r2", feature = "lara-r2", + feature = "lara-r6", feature = "toby-l4", feature = "leon-g1", feature = "sara-g3", @@ -30,6 +31,7 @@ pub enum Functionality { feature = "sara-u2", feature = "toby-r2", feature = "lara-r2", + feature = "lara-r6", feature = "toby-l4", feature = "leon-g1", feature = "sara-g3", @@ -48,6 +50,7 @@ pub enum Functionality { feature = "sara-u2", feature = "toby-r2", feature = "lara-r2", + feature = "lara-r6", feature = "toby-l4" ))] AirplaneMode = 4, @@ -62,6 +65,7 @@ pub enum Functionality { feature = "sara-u2", feature = "toby-r2", feature = "lara-r2", + feature = "lara-r6", feature = "toby-l4", feature = "leon-g1", feature = "sara-g3", @@ -117,6 +121,7 @@ pub enum Functionality { feature = "sara-u2", feature = "toby-r2", feature = "lara-r2", + feature = "lara-r6", feature = "toby-l4", feature = "leon-g1", feature = "sara-g3", @@ -132,6 +137,7 @@ pub enum Functionality { feature = "sara-u2", feature = "toby-r2", feature = "lara-r2", + feature = "lara-r6", feature = "toby-l4", feature = "leon-g1", feature = "sara-g3", @@ -151,7 +157,7 @@ pub enum Functionality { Halt = 127, } -/// Reset mode. This parameter can be used only when (ModuleFunctionality) is 1, 4 or 19 +/// Reset mode. This parameter can be used only when (`ModuleFunctionality`) is 1, 4 or 19 #[derive(Clone, PartialEq, Eq, AtatEnum)] pub enum ResetMode { /// Do not reset the MT before setting it to the selected @@ -194,6 +200,8 @@ pub enum PowerMode { On = 1, ///MT is in "airplane mode" AirplaneMode = 4, + ///MT is in "test mode" + TestMode = 5, ///MT is in minimum functionality with SIM deactivated MinimumWithoutSim = 19, } diff --git a/ublox-cellular/src/command/network_service/impl_.rs b/ublox-cellular/src/command/network_service/impl_.rs index 36d37e4..9c7ba46 100644 --- a/ublox-cellular/src/command/network_service/impl_.rs +++ b/ublox-cellular/src/command/network_service/impl_.rs @@ -1,17 +1,15 @@ -use super::types::*; +use super::types::NetworkRegistrationStat; use crate::network::Error; impl NetworkRegistrationStat { + #[must_use] pub fn is_access_alive(&self) -> bool { - matches!( - self, - NetworkRegistrationStat::Registered | NetworkRegistrationStat::RegisteredRoaming - ) + matches!(self, Self::Registered | Self::RegisteredRoaming) } pub fn registration_ok(self) -> Result { match self { - NetworkRegistrationStat::RegistrationDenied => Err(Error::RegistrationDenied), + Self::RegistrationDenied => Err(Error::RegistrationDenied), _ => Ok(self), } } diff --git a/ublox-cellular/src/command/network_service/mod.rs b/ublox-cellular/src/command/network_service/mod.rs index 70fb257..46ce48b 100644 --- a/ublox-cellular/src/command/network_service/mod.rs +++ b/ublox-cellular/src/command/network_service/mod.rs @@ -7,11 +7,31 @@ pub mod urc; use super::NoResponse; use atat::atat_derive::AtatCmd; -use responses::*; -use types::*; +use responses::{ + NetworkRegistrationStatus, OperatorSelection, RadioAccessTechnology, SignalQuality, +}; +use types::{ + FirstRadioAccessTechnology, NetworkRegistrationStat, NetworkRegistrationUrcConfig, + OperatorSelectionMode, SecondRadioAccessTechnology, ThirdRadioAccessTechnology, +}; /// 7.4 Extended signal quality +CESQ /// +/// Returns the radio signal strength <`signal_power`> and from the MT. +/// +/// **NOTES:** +/// - **TOBY-L4 / LARA-R2 / TOBY-R2** - The +CSQ utilization is deprecated. It +/// is warmly recommended to use the command +CESQ to obtain the same +/// information more accurately. +/// - **TOBY-L4 / TOBY-L2 / MPCI-L2 / LARA-R2 / TOBY-R2 / SARA-U2 / LISA-U2 / +/// LISA-U1 / SARA-G4 / SARA-G3 / LEON-G1** - The radio signal strength +/// <`signal_power`> will be also used to build and display the indicator +/// "signal" i.e. signal quality in the information text response of +CIND and +/// in the +CIEV URC (see the +CMER command description). +/// +/// In dedicated mode, during the radio channel reconfiguration (e.g. handover), +/// invalid measurements may be returned for a short transitory because the MT +/// must compute them on the newly assigned channel. /// Returns the received signal quality and level: /// - If the current serving cell is not a GERAN cell, the and parameters are set to value 99 /// - If the current serving cell is not a UTRA FDD cell, the and the parameters are set to 255 @@ -80,11 +100,22 @@ pub struct GetOperatorSelection; /// means of updating RAT related SIM files, can force RAT usage (see Notes). #[derive(Clone, AtatCmd)] #[at_cmd("+URAT", NoResponse)] +#[cfg(not(feature = "lara-r6"))] pub struct SetRadioAccessTechnology { #[at_arg(position = 0)] pub selected_act: RadioAccessTechnologySelected, } +#[derive(Clone, AtatCmd)] +#[at_cmd("+URAT", NoResponse)] +#[cfg(feature = "lara-r6")] +pub struct SetRadioAccessTechnology { + #[at_arg(position = 0)] + pub first_act: FirstRadioAccessTechnology, + pub second_act: Option, + pub third_act: Option, +} + #[derive(Clone, AtatCmd)] #[at_cmd("+URAT?", RadioAccessTechnology)] pub struct GetRadioAccessTechnology; diff --git a/ublox-cellular/src/command/network_service/responses.rs b/ublox-cellular/src/command/network_service/responses.rs index e977e82..cfc85c5 100644 --- a/ublox-cellular/src/command/network_service/responses.rs +++ b/ublox-cellular/src/command/network_service/responses.rs @@ -1,5 +1,8 @@ //! Responses for Network service Commands -use super::types::*; +use super::types::{ + NetworkRegistrationStat, NetworkRegistrationUrcConfig, OperatorNameFormat, + OperatorSelectionMode, RadioAccessTechnologySelected, RatAct, +}; use atat::atat_derive::AtatResp; use heapless::String; diff --git a/ublox-cellular/src/command/network_service/types.rs b/ublox-cellular/src/command/network_service/types.rs index 0cd6c50..7f9512d 100644 --- a/ublox-cellular/src/command/network_service/types.rs +++ b/ublox-cellular/src/command/network_service/types.rs @@ -136,6 +136,42 @@ pub enum RadioAccessTechnologySelected { UmtsLte(RatPreferred), } +/// Indicates the radio access technology +#[derive(Debug, Clone, PartialEq, Eq, AtatEnum)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[cfg(feature = "lara-r6")] +pub enum FirstRadioAccessTechnology { + /// • 0: GSM / GPRS / eGPRS (single mode) + #[at_arg(value = 0)] + GsmGprsEGprs, + /// • 2: UMTS (single mode) + #[at_arg(value = 2)] + Umts, + /// • 3: LTE (single mode) + #[at_arg(value = 3)] + Lte, +} + +/// Indicates the radio access technology +#[derive(Debug, Clone, PartialEq, Eq, AtatEnum)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[cfg(feature = "lara-r6")] +pub enum SecondRadioAccessTechnology { + /// • 2: UMTS (single mode) + #[at_arg(value = 2)] + Umts, +} + +/// Indicates the radio access technology +#[derive(Debug, Clone, PartialEq, Eq, AtatEnum)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[cfg(feature = "lara-r6")] +pub enum ThirdRadioAccessTechnology { + /// • 0: GSM / GPRS / eGPRS (single mode) + #[at_arg(value = 0)] + GsmGprsEGprs, +} + #[derive(Debug, Clone, PartialEq, Eq, AtatEnum)] pub enum OperatorNameFormat { #[at_arg(value = 0)] diff --git a/ublox-cellular/src/command/psn/mod.rs b/ublox-cellular/src/command/psn/mod.rs index 79f4929..9644485 100644 --- a/ublox-cellular/src/command/psn/mod.rs +++ b/ublox-cellular/src/command/psn/mod.rs @@ -10,23 +10,32 @@ //! context activated e.g. via dial-up). The Traffic Flow Filters for such //! secondary contexts shall be specified according to 3GPP TS 23.060 //! -//! The typical usage of the secondary PDP contexts is in VoIP calls, where RTP +//! The typical usage of the secondary PDP contexts is in `VoIP` calls, where RTP //! (speech) packets are conveyed on one PDP context (e.g. the primary one) with -//! a given QoS (e.g. low reliability) whereas SIP signalling is routed on a +//! a given `QoS` (e.g. low reliability) whereas SIP signalling is routed on a //! different PDP context (e.g. the secondary one, with the same IP address but -//! different port numbers) with a more reliable QoS. +//! different port numbers) with a more reliable `QoS`. //! //! A Traffic Flow Template (i.e. a filter based on port number, specifying //! relative flow precedence) shall be configured for the secondary context to -//! instruct the GGSN to route down-link packets onto different QoS flows +//! instruct the GGSN to route down-link packets onto different `QoS` flows //! towards the TE. pub mod responses; pub mod types; pub mod urc; use atat::atat_derive::AtatCmd; -use responses::*; -use types::*; +use responses::{ + EPSNetworkRegistrationStatus, ExtendedPSNetworkRegistrationStatus, GPRSAttached, + GPRSNetworkRegistrationStatus, PDPContextState, PacketSwitchedConfig, + PacketSwitchedNetworkData, +}; +use types::{ + AuthenticationType, EPSNetworkRegistrationUrcConfig, ExtendedPSNetworkRegistrationUrcConfig, + GPRSAttachedState, GPRSNetworkRegistrationUrcConfig, PDPContextStatus, PSEventReportingMode, + PacketSwitchedAction, PacketSwitchedNetworkDataParam, PacketSwitchedParam, + PacketSwitchedParamReq, +}; use super::NoResponse; use crate::network::{ContextId, ProfileId}; @@ -53,9 +62,9 @@ use crate::network::{ContextId, ProfileId}; /// /// The information text response to the read command provides the configuration /// of all the PDP context / EPS bearers that have already been defined. The -/// test command returns a different row for each value supported by +/// test command returns a different row for each <`PDP_type`> value supported by /// the module. -///"IPtial default bearer. Since dial-up supports only IPv4 +///"`IPtial` default bearer. Since dial-up supports only IPv4 /// connectivity, the defined IPv6 EPS bearers / PDP contexts will not be /// used. /// - **TOBY-L4 / TOBY-L2 / MPCI-L2 / LARA-R2 / TOBY-R2** - After the PDP @@ -350,26 +359,26 @@ pub struct GetExtendedPSNetworkRegistrationStatus; /// - +CEREG: [,[],[],[][,,]] when /// =3 and the value of changes /// - +CEREG: -/// [,[],[],[][,,[,[,[]]]]] +/// [,[],[],[][,,[,[<`Assigned_Active_Time`>,[<`Assigned_Periodic_TAU`>]]]]] /// when =4 if there is a change of the network cell in E-UTRAN /// - +CEREG: -/// [,[],[],[][,[],[][,[, -/// []]]]] when =5 and the value of changes +/// [,[],[],[][,[<`cause_type`>],[<`reject_cause`>][,[<`Assigned_Active_Time`>, +/// [<`Assigned_Periodic_TAU`>]]]]] when =5 and the value of changes /// -/// The parameters , , , , , -/// , and are +/// The parameters , , <`rac_or_mme`>, , <`cause_type`>, +/// <`reject_cause`>, <`Assigned_Active_Time`> and <`Assigned_Periodic_TAU`> are /// provided only if available. /// /// The read command returns always at least the mode configuration (), the /// EPS registration status (). The location parameters , -/// , and , if available, are returned only when =2, +/// <`rac_or_mme`>, and , if available, are returned only when =2, /// =3, =4 or =5 and the MT is registered with the network. The -/// parameters , , if available, are returned when -/// =3 or =5. The PSM related parameter is +/// parameters <`cause_type`>, , if available, are returned when +/// =3 or =5. The PSM related parameter <`Assigned_Active`_ Time> is /// returned only when =4 or =5, the MT is registered with the network and -/// PSM is granted by the network. The parameter is +/// PSM is granted by the network. The <`Assigned_Periodic_TAU`> parameter is /// returned only if when =4 or =5, the MT is registered with the network, -/// PSM is granted by the network and an extended periodic TAU value (T3412_ext) +/// PSM is granted by the network and an extended periodic TAU value (`T3412_ext`) /// is assigned. /// /// **NOTES:** @@ -395,7 +404,7 @@ pub struct GetEPSNetworkRegistrationStatus; /// as a protocol configuration options (PCO) information element. /// /// **NOTES:** -/// - **LARA-R2 / TOBY-R2 / SARA-U2 / LISA-U2 / SARA-G3** - When =3 +/// - **LARA-R2 / TOBY-R2 / SARA-U2 / LISA-U2 / SARA-G3** - When <`auth_type>=3` /// is set, AT+CGACT=1, may trigger at most 3 PDP context activation /// requests for to the protocol stack. The first request for is /// done with no authentication. If the PDP context activation fails, a second diff --git a/ublox-cellular/src/command/psn/responses.rs b/ublox-cellular/src/command/psn/responses.rs index bfca2c2..414041a 100644 --- a/ublox-cellular/src/command/psn/responses.rs +++ b/ublox-cellular/src/command/psn/responses.rs @@ -1,5 +1,10 @@ //! Responses for Packet Switched Data Services Commands -use super::types::*; +use super::types::{ + EPSNetworkRegistrationStat, EPSNetworkRegistrationUrcConfig, + ExtendedPSNetworkRegistrationState, ExtendedPSNetworkRegistrationUrcConfig, GPRSAttachedState, + GPRSNetworkRegistrationStat, GPRSNetworkRegistrationUrcConfig, PDPContextStatus, + PacketSwitchedNetworkDataParam, PacketSwitchedParam, +}; use crate::{command::network_service::types::RatAct, network::ProfileId, ContextId}; use atat::atat_derive::AtatResp; use heapless::String; @@ -41,6 +46,7 @@ pub struct PacketSwitchedNetworkData { /// during the command execution. Any active PDP context will be automatically /// deactivated when the GPRS registration state changes to detached. #[derive(AtatResp)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct GPRSAttached { #[at_arg(position = 0)] pub state: GPRSAttachedState, @@ -48,6 +54,7 @@ pub struct GPRSAttached { /// 18.16 PDP context activate or deactivate +CGACT #[derive(Clone, AtatResp)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct PDPContextState { #[at_arg(position = 0)] pub cid: ContextId, diff --git a/ublox-cellular/src/command/psn/types.rs b/ublox-cellular/src/command/psn/types.rs index 31c206b..dcb51b6 100644 --- a/ublox-cellular/src/command/psn/types.rs +++ b/ublox-cellular/src/command/psn/types.rs @@ -5,6 +5,7 @@ use heapless::String; /// Indicates the state of PDP context activation #[derive(Clone, PartialEq, Eq, AtatEnum)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum PDPContextStatus { /// 0: deactivated Deactivated = 0, diff --git a/ublox-cellular/src/command/psn/urc.rs b/ublox-cellular/src/command/psn/urc.rs index bb328c5..c69198c 100644 --- a/ublox-cellular/src/command/psn/urc.rs +++ b/ublox-cellular/src/command/psn/urc.rs @@ -1,5 +1,7 @@ //! Unsolicited responses for Packet Switched Data Services Commands -use super::types::*; +use super::types::{ + EPSNetworkRegistrationStat, ExtendedPSNetworkRegistrationState, GPRSNetworkRegistrationStat, +}; use crate::{command::network_service::types::RatAct, network::ProfileId}; use atat::atat_derive::AtatResp; use embedded_nal::IpAddr; diff --git a/ublox-cellular/src/command/sms/mod.rs b/ublox-cellular/src/command/sms/mod.rs index e5e6851..bdf077d 100644 --- a/ublox-cellular/src/command/sms/mod.rs +++ b/ublox-cellular/src/command/sms/mod.rs @@ -6,7 +6,7 @@ pub mod urc; use super::NoResponse; use atat::atat_derive::AtatCmd; -use types::*; +use types::MessageWaitingMode; /// 11.29 Message waiting indication +UMWI /// diff --git a/ublox-cellular/src/command/system_features/mod.rs b/ublox-cellular/src/command/system_features/mod.rs index fed2c6f..b336945 100644 --- a/ublox-cellular/src/command/system_features/mod.rs +++ b/ublox-cellular/src/command/system_features/mod.rs @@ -7,8 +7,8 @@ pub mod responses; pub mod types; use atat::atat_derive::AtatCmd; -use responses::*; -use types::*; +use responses::{FactoryConfiguration, PowerSavingControl}; +use types::{FSFactoryRestoreType, NVMFactoryRestoreType, PowerSavingMode, Seconds}; use super::NoResponse; diff --git a/ublox-cellular/src/command/system_features/responses.rs b/ublox-cellular/src/command/system_features/responses.rs index 6e7a95d..314d209 100644 --- a/ublox-cellular/src/command/system_features/responses.rs +++ b/ublox-cellular/src/command/system_features/responses.rs @@ -1,5 +1,5 @@ //! Responses for System features Commands -use super::types::*; +use super::types::{FSFactoryRestoreType, NVMFactoryRestoreType, PowerSavingMode, Seconds}; use atat::atat_derive::AtatResp; /// 19.8 Power saving control (Power Saving) +UPSV diff --git a/ublox-cellular/src/config.rs b/ublox-cellular/src/config.rs index 4284b03..7fb984e 100644 --- a/ublox-cellular/src/config.rs +++ b/ublox-cellular/src/config.rs @@ -41,7 +41,7 @@ pub struct Config { impl Default for Config { fn default() -> Self { - Config { + Self { rst_pin: None, dtr_pin: None, pwr_pin: None, @@ -61,8 +61,9 @@ where DTR: OutputPin, VINT: InputPin, { + #[must_use] pub fn new(pin: &str) -> Self { - Config { + Self { rst_pin: None, dtr_pin: None, pwr_pin: None, @@ -75,28 +76,28 @@ where } pub fn with_rst(self, rst_pin: RST) -> Self { - Config { + Self { rst_pin: Some(rst_pin), ..self } } pub fn with_pwr(self, pwr_pin: PWR) -> Self { - Config { + Self { pwr_pin: Some(pwr_pin), ..self } } pub fn with_dtr(self, dtr_pin: DTR) -> Self { - Config { + Self { dtr_pin: Some(dtr_pin), ..self } } pub fn with_vint(self, vint_pin: VINT) -> Self { - Config { + Self { vint_pin: Some(vint_pin), ..self } @@ -105,14 +106,14 @@ where pub fn baud_rate>(self, baud_rate: B) -> Self { // FIXME: Validate baudrates - Config { + Self { baud_rate: baud_rate.into(), ..self } } pub fn with_flow_control(self) -> Self { - Config { + Self { flow_control: true, ..self } diff --git a/ublox-cellular/src/error.rs b/ublox-cellular/src/error.rs index cd71c98..c4cb3ec 100644 --- a/ublox-cellular/src/error.rs +++ b/ublox-cellular/src/error.rs @@ -34,9 +34,9 @@ impl From for Error { fn from(e: DataServiceError) -> Self { // Unwrap generic and network errors match e { - DataServiceError::Generic(g) => Error::Generic(g), - DataServiceError::Network(g) => Error::Network(g), - _ => Error::DataService(e), + DataServiceError::Generic(g) => Self::Generic(g), + DataServiceError::Network(g) => Self::Network(g), + _ => Self::DataService(e), } } } @@ -45,8 +45,8 @@ impl From for Error { fn from(e: NetworkError) -> Self { // Unwrap generic errors match e { - NetworkError::Generic(g) => Error::Generic(g), - _ => Error::Network(e), + NetworkError::Generic(g) => Self::Generic(g), + _ => Self::Network(e), } } } diff --git a/ublox-cellular/src/lib.rs b/ublox-cellular/src/lib.rs index 6237133..751e74a 100644 --- a/ublox-cellular/src/lib.rs +++ b/ublox-cellular/src/lib.rs @@ -82,6 +82,7 @@ mod client; pub mod command; mod config; pub mod error; +mod module_timing; mod network; mod power; mod registration; diff --git a/ublox-cellular/src/module_timing.rs b/ublox-cellular/src/module_timing.rs new file mode 100644 index 0000000..0a9dac9 --- /dev/null +++ b/ublox-cellular/src/module_timing.rs @@ -0,0 +1,40 @@ +#![allow(clippy::if_same_then_else)] + +use fugit::ExtU32; +use fugit::TimerDurationU32; + +/// Low time of `PWR_ON` pin to trigger module switch on from power off mode +pub fn pwr_on_time() -> TimerDurationU32 { + if cfg!(feature = "lara-r6") { + 150.millis() + } else { + 50.micros() + } +} + +/// Low time of `PWR_ON` pin to trigger module graceful switch off +pub fn pwr_off_time() -> TimerDurationU32 { + if cfg!(feature = "lara-r6") { + 1500.millis() + } else { + 1.secs() + } +} + +/// Low time of `RESET_N` pin to trigger module reset (reboot) +pub fn reset_time() -> TimerDurationU32 { + if cfg!(feature = "lara-r6") { + 10.millis() + } else { + 50.millis() + } +} + +/// Low time of `RESET_N` pin to trigger module abrupt emergency switch off +pub fn kill_time() -> TimerDurationU32 { + if cfg!(feature = "lara-r6") { + 10.secs() + } else { + 10.secs() + } +} diff --git a/ublox-cellular/src/network.rs b/ublox-cellular/src/network.rs index 3637101..5d034e2 100644 --- a/ublox-cellular/src/network.rs +++ b/ublox-cellular/src/network.rs @@ -175,7 +175,7 @@ where CLK: Clock, { pub(crate) fn new(at_tx: AtTx, timer: CLK) -> Self { - Network { + Self { status: RegistrationState::new(timer), context_state: ContextState::Setup, at_tx, @@ -204,7 +204,7 @@ where self.handle_urc().ok(); // Ignore errors self.check_registration_state(); self.intervene_registration()?; - self.check_running_imsi(); + self.check_running_imsi().ok(); // Ignore errors let now = self.status.timer.now(); let should_check = self @@ -222,7 +222,7 @@ where self.status.reg_check_time.replace(now); - self.update_registration()?; + // self.update_registration()?; let now = self.status.timer.now(); let is_timeout = self diff --git a/ublox-cellular/src/power.rs b/ublox-cellular/src/power.rs index ec05571..5d8b6e5 100644 --- a/ublox-cellular/src/power.rs +++ b/ublox-cellular/src/power.rs @@ -16,6 +16,7 @@ use crate::{ AT, }, error::{from_clock, Error, GenericError}, + module_timing::{pwr_off_time, pwr_on_time, reset_time}, }; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -103,32 +104,28 @@ where Ok(()) } - /// Reset the module by driving it's RESET_N pin low for 50 ms + /// Reset the module by driving it's `RESET_N` pin low for 50 ms /// /// **NOTE** This function will reset NVM settings! pub fn hard_reset(&mut self) -> Result<(), Error> { trace!("Attempting to hard reset of the modem."); - match self.config.rst_pin { - Some(ref mut rst) => { - // Apply Low pulse on RESET_N for 50 milliseconds to reset - rst.set_low().ok(); - - self.network - .status - .timer - .start(50.millis()) - .map_err(from_clock)?; - nb::block!(self.network.status.timer.wait()).map_err(from_clock)?; - - rst.set_high().ok(); - self.network - .status - .timer - .start(5.secs()) - .map_err(from_clock)?; - nb::block!(self.network.status.timer.wait()).map_err(from_clock)?; - } - None => {} + if let Some(ref mut rst) = self.config.rst_pin { + rst.set_low().ok(); + + self.network + .status + .timer + .start(reset_time::()) + .map_err(from_clock)?; + nb::block!(self.network.status.timer.wait()).map_err(from_clock)?; + + rst.set_high().ok(); + self.network + .status + .timer + .start(5.secs()) + .map_err(from_clock)?; + nb::block!(self.network.status.timer.wait()).map_err(from_clock)?; } self.power_state = PowerState::Off; @@ -154,7 +151,7 @@ where self.network .status .timer - .start(50.micros()) + .start(pwr_on_time::()) .map_err(from_clock)?; nb::block!(self.network.status.timer.wait()).map_err(from_clock)?; @@ -166,7 +163,7 @@ where .map_err(from_clock)?; nb::block!(self.network.status.timer.wait()).map_err(from_clock)?; - if let Err(e) = self.wait_power_state(PowerState::On, 25.secs()) { + if let Err(e) = self.wait_power_state(PowerState::On, 10.secs()) { error!("Failed to power on modem"); return Err(e); } else { @@ -215,20 +212,13 @@ where self.network .status .timer - .start(1.secs()) + .start(pwr_off_time::()) .map_err(from_clock)?; nb::block!(self.network.status.timer.wait()).map_err(from_clock)?; pwr.set_high().ok(); self.power_state = PowerState::Off; trace!("Modem powered off"); - - self.network - .status - .timer - .start(10.secs()) - .map_err(from_clock)?; - nb::block!(self.network.status.timer.wait()).map_err(from_clock)?; } _ => { return Err(Error::Generic(GenericError::Unsupported)); @@ -274,8 +264,7 @@ where .timer .now() .checked_duration_since(start) - .map(|dur| dur < timeout) - .unwrap_or(false) + .map_or(false, |dur| dur < timeout) { if self.power_state()? == expected { res = true; diff --git a/ublox-cellular/src/registration.rs b/ublox-cellular/src/registration.rs index 5c1e4b0..7c5c4d4 100644 --- a/ublox-cellular/src/registration.rs +++ b/ublox-cellular/src/registration.rs @@ -154,10 +154,10 @@ impl Default for RegType { impl From for RegType { fn from(ran: RadioAccessNetwork) -> Self { match ran { - RadioAccessNetwork::UnknownUnused => RegType::Unknown, - RadioAccessNetwork::Geran => RegType::Creg, - RadioAccessNetwork::Utran => RegType::Cgreg, - RadioAccessNetwork::Eutran => RegType::Cereg, + RadioAccessNetwork::UnknownUnused => Self::Unknown, + RadioAccessNetwork::Geran => Self::Creg, + RadioAccessNetwork::Utran => Self::Cgreg, + RadioAccessNetwork::Eutran => Self::Cereg, } } } @@ -165,10 +165,10 @@ impl From for RegType { impl From for RadioAccessNetwork { fn from(regtype: RegType) -> Self { match regtype { - RegType::Unknown => RadioAccessNetwork::UnknownUnused, - RegType::Creg => RadioAccessNetwork::Geran, - RegType::Cgreg => RadioAccessNetwork::Utran, - RegType::Cereg => RadioAccessNetwork::Eutran, + RegType::Unknown => Self::UnknownUnused, + RegType::Creg => Self::Geran, + RegType::Cgreg => Self::Utran, + RegType::Cereg => Self::Eutran, } } } diff --git a/ublox-cellular/src/services/data/apn.rs b/ublox-cellular/src/services/data/apn.rs index c83f1f9..03478ff 100644 --- a/ublox-cellular/src/services/data/apn.rs +++ b/ublox-cellular/src/services/data/apn.rs @@ -8,7 +8,7 @@ pub enum Apn { impl Default for Apn { fn default() -> Self { - Apn::Automatic + Self::Automatic } } @@ -20,8 +20,9 @@ pub struct APNInfo { } impl APNInfo { + #[must_use] pub fn new(apn: &str) -> Self { - APNInfo { + Self { apn: Apn::Given(String::from(apn)), user_name: None, password: None, diff --git a/ublox-cellular/src/services/data/dns.rs b/ublox-cellular/src/services/data/dns.rs index c8afc0f..a87753b 100644 --- a/ublox-cellular/src/services/data/dns.rs +++ b/ublox-cellular/src/services/data/dns.rs @@ -18,7 +18,7 @@ where fn get_host_by_address(&mut self, ip_addr: IpAddr) -> nb::Result, Self::Error> { let mut ip_str = String::<256>::new(); - write!(&mut ip_str, "{}", ip_addr).map_err(|_| Error::BadLength)?; + write!(&mut ip_str, "{ip_addr}").map_err(|_| Error::BadLength)?; match self.network.send_internal( &dns::ResolveNameIp { diff --git a/ublox-cellular/src/services/data/error.rs b/ublox-cellular/src/services/data/error.rs index 0e4b2f2..4a6c557 100644 --- a/ublox-cellular/src/services/data/error.rs +++ b/ublox-cellular/src/services/data/error.rs @@ -24,14 +24,14 @@ pub enum Error { impl From for Error { fn from(e: NetworkError) -> Self { match e { - NetworkError::Generic(g) => Error::Generic(g), - _ => Error::Network(e), + NetworkError::Generic(g) => Self::Generic(g), + _ => Self::Network(e), } } } impl From for Error { fn from(e: SocketError) -> Self { - Error::Socket(e) + Self::Socket(e) } } diff --git a/ublox-cellular/src/services/data/mod.rs b/ublox-cellular/src/services/data/mod.rs index 0ecf759..3a951cb 100644 --- a/ublox-cellular/src/services/data/mod.rs +++ b/ublox-cellular/src/services/data/mod.rs @@ -16,23 +16,16 @@ use crate::{ command::mobile_control::types::{Functionality, ResetMode}, command::mobile_control::SetModuleFunctionality, command::psn::types::PDPContextStatus, - command::psn::types::PacketSwitchedParam, command::psn::SetPDPContextDefinition, command::psn::SetPDPContextState, - command::psn::SetPacketSwitchedConfig, + command::Urc, command::{ ip_transport_layer::{ responses::{SocketData, UDPSocketData}, ReadSocketData, ReadUDPSocketData, }, - psn::{ - self, - responses::{GPRSAttached, PacketSwitchedConfig, PacketSwitchedNetworkData}, - types::PacketSwitchedParamReq, - GetPDPContextState, GetPacketSwitchedConfig, GetPacketSwitchedNetworkData, - }, + psn::{self, responses::GPRSAttached, GetPDPContextState}, }, - command::{psn::SetPacketSwitchedAction, Urc}, error::Error as DeviceError, error::GenericError, network::{ContextId, Network}, @@ -44,12 +37,7 @@ use embedded_hal::digital::{InputPin, OutputPin}; use fugit::ExtU32; pub use error::Error; -use psn::{ - types::{ - AuthenticationType, GPRSAttachedState, PacketSwitchedAction, PacketSwitchedNetworkDataParam, - }, - GetGPRSAttached, SetAuthParameters, -}; +use psn::{types::GPRSAttachedState, GetGPRSAttached}; use ublox_sockets::{Error as SocketError, SocketSet, SocketType}; #[cfg(feature = "upsd-context-activation")] @@ -105,15 +93,15 @@ where )?; } - self.network.send_internal( - &SetAuthParameters { - cid, - auth_type: AuthenticationType::Auto, - username: &apn_info.clone().user_name.unwrap_or_default(), - password: &apn_info.clone().password.unwrap_or_default(), - }, - true, - )?; + // self.network.send_internal( + // &SetAuthParameters { + // cid, + // auth_type: AuthenticationType::Auto, + // username: &apn_info.clone().user_name.unwrap_or_default(), + // password: &apn_info.clone().password.unwrap_or_default(), + // }, + // true, + // )?; self.network.send_internal( &SetModuleFunctionality { @@ -418,7 +406,11 @@ where /// Activate context using 3GPP commands /// Required for SARA-R4 and TOBY modules. #[cfg(not(feature = "upsd-context-activation"))] - fn activate_context(&mut self, cid: ContextId, profile_id: ProfileId) -> nb::Result<(), Error> { + fn activate_context( + &mut self, + cid: ContextId, + _profile_id: ProfileId, + ) -> nb::Result<(), Error> { if self.network.context_state == ContextState::Active { return Ok(()); } @@ -440,41 +432,64 @@ where .unwrap_or(false); if activated { - // Note: SARA-R4 only supports a single context at any - // one time and so doesn't require/support AT+UPSD. - #[cfg(feature = "sara-r4")] - return Ok(()); - - if let PacketSwitchedConfig { - param: PacketSwitchedParam::MapProfile(context), - .. - } = self - .network - .send_internal( - &GetPacketSwitchedConfig { - profile_id, - param: PacketSwitchedParamReq::MapProfile, - }, - true, - ) - .map_err(Error::from)? + // Note: SARA-R4 only supports a single context at any one time and + // so doesn't require/support AT+UPSD. + #[cfg(not(any(feature = "sara-r4", feature = "lara-r6")))] { - if context != cid { - self.network - .send_internal( - &SetPacketSwitchedConfig { - profile_id, - param: PacketSwitchedParam::MapProfile(cid), - }, - true, - ) - .map_err(Error::from)?; + if let PacketSwitchedConfig { + param: PacketSwitchedParam::MapProfile(context), + .. + } = self + .network + .send_internal( + &GetPacketSwitchedConfig { + profile_id, + param: PacketSwitchedParamReq::MapProfile, + }, + true, + ) + .map_err(Error::from)? + { + if context != cid { + self.network + .send_internal( + &SetPacketSwitchedConfig { + profile_id, + param: PacketSwitchedParam::MapProfile(cid), + }, + true, + ) + .map_err(Error::from)?; + + self.network + .send_internal( + &GetPacketSwitchedNetworkData { + profile_id, + param: PacketSwitchedNetworkDataParam::PsdProfileStatus, + }, + true, + ) + .map_err(Error::from)?; + } + } + + let PacketSwitchedNetworkData { param_tag, .. } = self + .network + .send_internal( + &GetPacketSwitchedNetworkData { + profile_id, + param: PacketSwitchedNetworkDataParam::PsdProfileStatus, + }, + true, + ) + .map_err(Error::from)?; + if param_tag == 0 { self.network .send_internal( - &GetPacketSwitchedNetworkData { + &SetPacketSwitchedAction { profile_id, - param: PacketSwitchedNetworkDataParam::PsdProfileStatus, + action: PacketSwitchedAction::Activate, }, true, ) @@ -482,29 +497,6 @@ where } } - let PacketSwitchedNetworkData { param_tag, .. } = self - .network - .send_internal( - &GetPacketSwitchedNetworkData { - profile_id, - param: PacketSwitchedNetworkDataParam::PsdProfileStatus, - }, - true, - ) - .map_err(Error::from)?; - - if param_tag == 0 { - self.network - .send_internal( - &SetPacketSwitchedAction { - profile_id, - action: PacketSwitchedAction::Activate, - }, - true, - ) - .map_err(Error::from)?; - } - self.network.context_state = ContextState::Active; Ok(()) } else { diff --git a/ublox-cellular/src/services/data/ssl.rs b/ublox-cellular/src/services/data/ssl.rs index fccf29f..338ab43 100644 --- a/ublox-cellular/src/services/data/ssl.rs +++ b/ublox-cellular/src/services/data/ssl.rs @@ -1,5 +1,8 @@ use super::{DataService, Error}; -use crate::command::device_data_security::{types::*, *}; +use crate::command::device_data_security::{ + types::{CertificateValidationLevel, SecurityDataType, SecurityProfileOperation}, + PrepareSecurityDataImport, SecurityProfileManager, SendSecurityDataImport, +}; use atat::{atat_derive::AtatLen, clock::Clock}; use heapless::String; use serde::{Deserialize, Serialize}; diff --git a/ublox-cellular/src/test_helpers.rs b/ublox-cellular/src/test_helpers.rs index c2e1e20..b51fbfc 100644 --- a/ublox-cellular/src/test_helpers.rs +++ b/ublox-cellular/src/test_helpers.rs @@ -89,8 +89,7 @@ impl Clock for MockTimer { fn wait(&mut self) -> nb::Result<(), Self::Error> { if let Some(start) = self.start { - if std::time::Instant::now() - start - > std::time::Duration::from_millis(self.duration.ticks() as u64) + if start.elapsed() > std::time::Duration::from_millis(u64::from(self.duration.ticks())) { Ok(()) } else {