1
1
pub mod control;
2
2
pub mod runner;
3
- #[ cfg( feature = "ublox-sockets " ) ]
3
+ #[ cfg( feature = "internal-network-stack " ) ]
4
4
pub mod ublox_stack;
5
5
6
6
pub mod state;
@@ -9,9 +9,11 @@ use core::mem::MaybeUninit;
9
9
10
10
use crate :: {
11
11
command:: {
12
+ control:: { types:: FlowControl , SetFlowControl } ,
13
+ ipc:: SetMultiplexing ,
12
14
mobile_control:: {
13
- types:: { Functionality , ResetMode } ,
14
- SetModuleFunctionality ,
15
+ types:: { Functionality , ResetMode , TerminationErrorMode } ,
16
+ SetModuleFunctionality , SetReportMobileTerminationError ,
15
17
} ,
16
18
psn:: { DeactivatePDPContext , EnterPPP , SetPDPContextDefinition } ,
17
19
Urc ,
@@ -24,7 +26,8 @@ use atat::{
24
26
} ;
25
27
use embassy_sync:: { blocking_mutex:: raw:: NoopRawMutex , mutex:: Mutex } ;
26
28
use embassy_time:: { Duration , Instant , Timer } ;
27
- use embedded_io_async:: { BufRead , Write } ;
29
+ use embedded_io:: Error ;
30
+ use embedded_io_async:: { BufRead , Read , Write } ;
28
31
use runner:: Runner ;
29
32
30
33
use self :: control:: Control ;
@@ -42,17 +45,17 @@ pub type Resources<
42
45
const CMD_BUF_SIZE : usize ,
43
46
const INGRESS_BUF_SIZE : usize ,
44
47
const URC_CAPACITY : usize ,
45
- > = Resources <
48
+ > = UbxResources <
46
49
embassy_at_cmux:: ChannelTx < ' static , 256 > ,
47
50
CMD_BUF_SIZE ,
48
51
INGRESS_BUF_SIZE ,
49
52
URC_CAPACITY ,
50
53
> ;
51
54
52
- // #[cfg(not( feature = "ppp") )]
53
- // pub use self::Resources;
55
+ #[ cfg( feature = "internal-network-stack" ) ]
56
+ pub use self :: UbxResources as Resources ;
54
57
55
- pub struct Resources <
58
+ pub struct UbxResources <
56
59
W : Write ,
57
60
const CMD_BUF_SIZE : usize ,
58
61
const INGRESS_BUF_SIZE : usize ,
79
82
const CMD_BUF_SIZE : usize ,
80
83
const INGRESS_BUF_SIZE : usize ,
81
84
const URC_CAPACITY : usize ,
82
- > Resources < W , CMD_BUF_SIZE , INGRESS_BUF_SIZE , URC_CAPACITY >
85
+ > UbxResources < W , CMD_BUF_SIZE , INGRESS_BUF_SIZE , URC_CAPACITY >
83
86
{
84
87
pub fn new ( ) -> Self {
85
88
Self {
@@ -101,7 +104,8 @@ impl<
101
104
}
102
105
}
103
106
104
- pub fn new <
107
+ #[ cfg( feature = "internal-network-stack" ) ]
108
+ pub fn new_internal <
105
109
' a ,
106
110
R : embedded_io_async:: Read ,
107
111
W : embedded_io_async:: Write ,
@@ -117,7 +121,7 @@ pub fn new<
117
121
) -> (
118
122
state:: Device < ' a , Client < ' a , W , INGRESS_BUF_SIZE > , URC_CAPACITY > ,
119
123
Control < ' a , Client < ' a , W , INGRESS_BUF_SIZE > > ,
120
- UbloxRunner < ' a , R , W , C , INGRESS_BUF_SIZE , URC_CAPACITY > ,
124
+ InternalRunner < ' a , R , W , C , INGRESS_BUF_SIZE , URC_CAPACITY > ,
121
125
) {
122
126
// safety: this is a self-referential struct, however:
123
127
// - it can't move while the `'a` borrow is active.
@@ -158,7 +162,7 @@ pub fn new<
158
162
& resources. urc_channel ,
159
163
) ;
160
164
161
- let runner = UbloxRunner {
165
+ let runner = InternalRunner {
162
166
cellular_runner : runner,
163
167
ingress,
164
168
reader,
@@ -167,7 +171,8 @@ pub fn new<
167
171
( net_device, control, runner)
168
172
}
169
173
170
- pub struct UbloxRunner <
174
+ #[ cfg( feature = "internal-network-stack" ) ]
175
+ pub struct InternalRunner <
171
176
' a ,
172
177
R : embedded_io_async:: Read ,
173
178
W : embedded_io_async:: Write ,
@@ -180,14 +185,15 @@ pub struct UbloxRunner<
180
185
pub reader : R ,
181
186
}
182
187
188
+ #[ cfg( feature = "internal-network-stack" ) ]
183
189
impl <
184
190
' a ,
185
191
R : embedded_io_async:: Read ,
186
192
W : embedded_io_async:: Write ,
187
193
C : CellularConfig < ' a > ,
188
194
const INGRESS_BUF_SIZE : usize ,
189
195
const URC_CAPACITY : usize ,
190
- > UbloxRunner < ' a , R , W , C , INGRESS_BUF_SIZE , URC_CAPACITY >
196
+ > InternalRunner < ' a , R , W , C , INGRESS_BUF_SIZE , URC_CAPACITY >
191
197
{
192
198
pub async fn run ( & mut self ) -> ! {
193
199
embassy_futures:: join:: join (
@@ -273,6 +279,28 @@ pub fn new_ppp<
273
279
( net_device, control, runner)
274
280
}
275
281
282
+ pub struct ReadWriteAdapter < R , W > ( pub R , pub W ) ;
283
+
284
+ impl < R , W > embedded_io_async:: ErrorType for ReadWriteAdapter < R , W > {
285
+ type Error = embedded_io:: ErrorKind ;
286
+ }
287
+
288
+ impl < R : Read , W > Read for ReadWriteAdapter < R , W > {
289
+ async fn read ( & mut self , buf : & mut [ u8 ] ) -> Result < usize , Self :: Error > {
290
+ self . 0 . read ( buf) . await . map_err ( |e| e. kind ( ) )
291
+ }
292
+ }
293
+
294
+ impl < R , W : Write > Write for ReadWriteAdapter < R , W > {
295
+ async fn write ( & mut self , buf : & [ u8 ] ) -> Result < usize , Self :: Error > {
296
+ self . 1 . write ( buf) . await . map_err ( |e| e. kind ( ) )
297
+ }
298
+
299
+ async fn flush ( & mut self ) -> Result < ( ) , Self :: Error > {
300
+ self . 1 . flush ( ) . await . map_err ( |e| e. kind ( ) )
301
+ }
302
+ }
303
+
276
304
#[ cfg( feature = "ppp" ) ]
277
305
pub struct PPPRunner <
278
306
' a ,
@@ -327,16 +355,66 @@ impl<'a, C: CellularConfig<'a>, const INGRESS_BUF_SIZE: usize, const URC_CAPACIT
327
355
Ok ( ( ) )
328
356
}
329
357
330
- pub async fn run < R : BufRead , W : Write > (
358
+ async fn init < R : Read , W : Write > ( rx : & mut R , tx : & mut W ) -> Result < ( ) , atat:: Error > {
359
+ let mut buf = [ 0u8 ; 64 ] ;
360
+ let mut at_client = SimpleClient :: new (
361
+ ReadWriteAdapter ( rx, tx) ,
362
+ atat:: AtDigester :: < Urc > :: new ( ) ,
363
+ & mut buf,
364
+ atat:: Config :: default ( ) ,
365
+ ) ;
366
+
367
+ at_client
368
+ . send ( & SetReportMobileTerminationError {
369
+ n : TerminationErrorMode :: Enabled ,
370
+ } )
371
+ . await ?;
372
+
373
+ at_client
374
+ . send ( & SetFlowControl {
375
+ value : FlowControl :: RtsCts ,
376
+ } )
377
+ . await ?;
378
+
379
+ at_client
380
+ . send ( & SetMultiplexing {
381
+ mode : 0 ,
382
+ subset : None ,
383
+ port_speed : None ,
384
+ n1 : None ,
385
+ t1 : None ,
386
+ n2 : None ,
387
+ t2 : None ,
388
+ t3 : None ,
389
+ k : None ,
390
+ } )
391
+ . await ?;
392
+
393
+ Ok ( ( ) )
394
+ }
395
+
396
+ pub async fn run < R : BufRead + Read , W : Write > (
331
397
& mut self ,
332
398
mut rx : R ,
333
399
mut tx : W ,
334
400
stack : & embassy_net:: Stack < embassy_net_ppp:: Device < ' a > > ,
335
401
) -> ! {
336
402
loop {
337
403
// Reset modem
404
+ // if self.cellular_runner.init().await.is_err() {
405
+ // Timer::after(Duration::from_secs(5)).await;
406
+ // continue;
407
+ // }
408
+
409
+ // Timer::after(Duration::from_secs(5)).await;
338
410
339
411
// Do AT init and enter CMUX mode using interface
412
+ if Self :: init ( & mut rx, & mut tx) . await . is_err ( ) {
413
+ Timer :: after ( Duration :: from_secs ( 5 ) ) . await ;
414
+ continue ;
415
+ } ;
416
+
417
+ Timer :: after ( Duration :: from_secs ( 1 ) ) . await ;
340
418
341
419
let ppp_fut = async {
342
420
let mut fails = 0 ;
0 commit comments