File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,10 @@ fn main() -> ! {
115
115
. send_and_wait_reply ( & at_command:: power_saving_mode:: GetPowerSavingMode { } )
116
116
. unwrap ( ) ;
117
117
info ! ( "power_saving_mode: {}" , power_saving_mode) ;
118
+ let battery_charge = modem
119
+ . send_and_wait_reply ( & at_command:: battery:: BatteryCharge { } )
120
+ . unwrap ( ) ;
121
+ info ! ( "battery_charge: {}" , battery_charge) ;
118
122
let gprs_status = modem
119
123
. send_and_wait_reply ( & at_command:: at_cgatt:: GPRSServiceStatus { } )
120
124
. unwrap ( ) ;
Original file line number Diff line number Diff line change
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 struct BatteryChargeStatus {
7
+ capacity_percent : i32 ,
8
+ voltage_millivolt : i32 ,
9
+ }
10
+
11
+
12
+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
13
+ pub struct BatteryCharge ;
14
+
15
+ impl AtRequest for BatteryCharge {
16
+ type Response = Result < ( ) , AtError > ;
17
+
18
+ fn get_command < ' a > ( & ' a self , buffer : & ' a mut BufferType ) -> Result < & ' a [ u8 ] , usize > {
19
+ at_commands:: builder:: CommandBuilder :: create_execute ( buffer, true )
20
+ . named ( "+CBC" )
21
+ . finish ( )
22
+ }
23
+
24
+ fn parse_response ( & self , data : & [ u8 ] ) -> Result < AtResponse , AtError > {
25
+ let ( capacity_percent, voltage_millivolt) = CommandParser :: parse ( data)
26
+ . expect_identifier ( b"\r \n +CBC: " )
27
+ . expect_int_parameter ( )
28
+ . expect_int_parameter ( )
29
+ . expect_identifier ( b"\r \n \r \n OK" )
30
+ . finish ( ) ?;
31
+ let status = BatteryChargeStatus { capacity_percent, voltage_millivolt} ;
32
+ Ok ( AtResponse :: BatteryCharge ( status) )
33
+ }
34
+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ use crate::at_command::sleep_indication::SleepIndication;
10
10
use crate :: { AtError , BUFFER_SIZE } ;
11
11
#[ cfg( feature = "defmt" ) ]
12
12
use defmt:: debug;
13
+ use crate :: at_command:: battery:: BatteryChargeStatus ;
13
14
14
15
pub mod at;
15
16
pub mod at_cgatt;
@@ -33,6 +34,7 @@ pub mod ntp;
33
34
pub mod pdp_context;
34
35
pub mod power_saving_mode;
35
36
pub mod sleep_indication;
37
+ pub mod battery;
36
38
37
39
type BufferType = [ u8 ; BUFFER_SIZE ] ;
38
40
@@ -55,6 +57,7 @@ pub enum AtResponse {
55
57
PDPContext ( Option < ( PDPState , i32 ) > ) ,
56
58
SleepIndication ( SleepIndication ) ,
57
59
PowerSavingMode ( PowerSavingModeState ) ,
60
+ BatteryCharge ( BatteryChargeStatus ) ,
58
61
}
59
62
60
63
pub trait AtRequest {
You can’t perform that action at this time.
0 commit comments