Skip to content

Commit fe1ebde

Browse files
add pdp context query
1 parent f6aaac1 commit fe1ebde

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

examples/pico/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn main() -> ! {
110110
modem.set_flow_control().unwrap();
111111
modem.enable_numeric_errors().unwrap();
112112
'outer: loop {
113-
info!("waiting for operator");
113+
info!("waiting for operator...........................................");
114114
let gprs_status = modem
115115
.send_and_wait_reply(&at_command::at_cgatt::GPRSServiceStatus {})
116116
.unwrap();
@@ -127,6 +127,10 @@ fn main() -> ! {
127127
.send_and_wait_reply(&at_command::network_registration_status::NetworkRegistration {})
128128
.unwrap();
129129
info!("network registration status: {:?}", registration);
130+
let pdp_context = modem
131+
.send_and_wait_reply(&at_command::pdp_context::PDPContext {})
132+
.unwrap();
133+
info!("pdp context: {:?}", pdp_context);
130134
let network_information = modem
131135
.send_and_wait_reply(&at_command::network_information::NetworkInformation {})
132136
.unwrap();

src/at_command/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::at_command::network_information::{NetworkFormat, NetworkMode, Network
33
use crate::at_command::network_registration_status::{
44
NetworkRegistrationStatus, UnsolicitedResultCodes,
55
};
6+
use crate::at_command::pdp_context::PDPState;
67
use crate::{AtError, BUFFER_SIZE};
78
#[cfg(feature = "defmt")]
89
use defmt::debug;
@@ -25,6 +26,7 @@ pub mod mqtt;
2526
pub mod network_information;
2627
pub mod network_registration_status;
2728
pub mod ntp;
29+
pub mod pdp_context;
2830

2931
type BufferType = [u8; BUFFER_SIZE];
3032

@@ -43,6 +45,7 @@ pub enum AtResponse {
4345
ReportMobileEquipmentErrorSetting(i32),
4446
NetworkRegistration(UnsolicitedResultCodes, NetworkRegistrationStatus),
4547
NetworkRegistrationStatus(UnsolicitedResultCodes, NetworkRegistrationStatus),
48+
PDPContext(PDPState, i32),
4649
}
4750

4851
pub trait AtRequest {

src/at_command/pdp_context.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use crate::at_command::{AtRequest, AtResponse, BufferType};
2+
use crate::AtError;
3+
use at_commands::parser::CommandParser;
4+
5+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6+
pub enum PDPState {
7+
Deactivated,
8+
Activated,
9+
}
10+
11+
impl From<i32> for PDPState {
12+
fn from(value: i32) -> Self {
13+
match value {
14+
0 => PDPState::Deactivated,
15+
1 => PDPState::Activated,
16+
_ => {
17+
unreachable!()
18+
}
19+
}
20+
}
21+
}
22+
23+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
24+
pub struct PDPContext;
25+
26+
impl AtRequest for PDPContext {
27+
type Response = Result<(), AtError>;
28+
29+
fn get_command<'a>(&'a self, buffer: &'a mut BufferType) -> Result<&'a [u8], usize> {
30+
at_commands::builder::CommandBuilder::create_query(buffer, true)
31+
.named("+CGACT")
32+
.finish()
33+
}
34+
35+
fn parse_response(&self, data: &[u8]) -> Result<AtResponse, AtError> {
36+
let (state, context) = CommandParser::parse(data)
37+
.expect_identifier(b"\r\n+CGACT: ")
38+
.expect_int_parameter()
39+
.expect_int_parameter()
40+
.expect_identifier(b"\r\n\r\nOK")
41+
.finish()?;
42+
let state = PDPState::from(state);
43+
Ok(AtResponse::PDPContext(state, context))
44+
}
45+
}

0 commit comments

Comments
 (0)