Skip to content

Commit

Permalink
feature(): Add support for LARA-R6 (#74)
Browse files Browse the repository at this point in the history
* Bump embedded-hal to alpha.8

* Update to embedded-hal-alpha.9

* Add support for LARA-R6 LTE module

* Remove merge marker

* Correct toby feature and readme section on device features

* Add module_timing.rs to abstract over different ublox module timing requirements on pwr & rst pins

* Add device feature in CI

* Run cargo clippy, and loosen the clippy CI requirements

* Formatting
  • Loading branch information
MathiasKoch committed Mar 24, 2023
1 parent 71efe2f commit b7f8fb5
Show file tree
Hide file tree
Showing 50 changed files with 424 additions and 265 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/grcov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions ublox-cellular/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ 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"]
# Use `log-impl` to enable log based logging
log-impl = ["log", "ublox-sockets/log", "atat/log"]

lara-r2 = []
lara-r6 = []
leon-g1 = []
lisa-u2 = []
mpci-l2 = []
Expand All @@ -51,7 +52,7 @@ sara-u1 = []
sara-u2 = ["upsd-context-activation"]
toby-l2 = []
toby-r2 = []
topy-l4 = []
toby-l4 = []

upsd-context-activation = []

Expand Down
67 changes: 46 additions & 21 deletions ublox-cellular/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))]
Expand Down Expand Up @@ -143,7 +155,7 @@ where
/// );
/// ```
pub fn new(client: C, timer: CLK, config: Config<RST, DTR, PWR, VINT>) -> Self {
let mut device = Device {
let mut device = Self {
config,
state: State::Off,
power_state: PowerState::Off,
Expand Down Expand Up @@ -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(
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ublox-cellular/src/command/control/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
pub mod types;

use atat::atat_derive::AtatCmd;
use types::*;
use types::{BaudRate, Circuit108Behaviour, Circuit109Behaviour, FlowControl, SoftwareFlowControl};

use super::NoResponse;

Expand Down
8 changes: 4 additions & 4 deletions ublox-cellular/src/command/device_data_security/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -165,7 +165,7 @@ pub struct RetrieveSecurityMd5<'a> {
/// <operation> 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=<profile_id> command
/// specific security profile, issue the `AT+USECPRF=<profile_id`> command
/// (operation: None).
#[derive(Clone, AtatCmd)]
#[at_cmd("+USECPRF", NoResponse)]
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
24 changes: 12 additions & 12 deletions ublox-cellular/src/command/device_lock/impl_.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::types::*;
use super::types::PinStatusCode;
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};

impl Serialize for PinStatusCode {
Expand All @@ -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"),
}
}
}
Expand Down Expand Up @@ -125,7 +125,7 @@ impl<'de> Deserialize<'de> for PinStatusCode {
"PinStatusCode",
VARIANTS,
Visitor {
marker: core::marker::PhantomData::<PinStatusCode>,
marker: core::marker::PhantomData::<Self>,
lifetime: core::marker::PhantomData,
},
)
Expand Down
2 changes: 1 addition & 1 deletion ublox-cellular/src/command/device_lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod responses;
pub mod types;

use atat::atat_derive::AtatCmd;
use responses::*;
use responses::PinStatus;

use super::NoResponse;

Expand Down
3 changes: 2 additions & 1 deletion ublox-cellular/src/command/device_lock/responses.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 1 addition & 0 deletions ublox-cellular/src/command/device_lock/types.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions ublox-cellular/src/command/dns/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down
8 changes: 4 additions & 4 deletions ublox-cellular/src/command/file_system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
/// <tcp_data_port> 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
Expand Down Expand Up @@ -79,7 +79,7 @@ pub struct DownloadFile<'a> {
/// 22.3 List files information +ULSTFILE
///
/// Retrieves some information about the FS. Depending on the specified
/// <op_code>, 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
Expand All @@ -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 <tcp_data_port> 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
Expand Down

0 comments on commit b7f8fb5

Please sign in to comment.