File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ use crate::{
13
13
14
14
pub mod orbic;
15
15
pub mod tmobile;
16
+ pub mod tplink;
16
17
pub mod wingtech;
17
18
18
19
const LOW_BATTERY_LEVEL : u8 = 10 ;
@@ -50,6 +51,7 @@ pub async fn get_battery_status(device: &Device) -> Result<BatteryState, Rayhunt
50
51
Device :: Orbic => orbic:: get_battery_state ( ) . await ?,
51
52
Device :: Wingtech => wingtech:: get_battery_state ( ) . await ?,
52
53
Device :: Tmobile => tmobile:: get_battery_state ( ) . await ?,
54
+ Device :: Tplink => tplink:: get_battery_state ( ) . await ?,
53
55
_ => return Err ( RayhunterError :: FunctionNotSupportedForDeviceError ) ,
54
56
} )
55
57
}
Original file line number Diff line number Diff line change
1
+ use crate :: { battery:: BatteryState , error:: RayhunterError } ;
2
+
3
+ pub async fn get_battery_state ( ) -> Result < BatteryState , RayhunterError > {
4
+ let uci_battery = tokio:: process:: Command :: new ( "uci" )
5
+ . arg ( "get" )
6
+ . arg ( "battery.battery_mgr.power_level" )
7
+ . output ( )
8
+ . await ?;
9
+
10
+ let uci_plugged_in = tokio:: process:: Command :: new ( "uci" )
11
+ . arg ( "get" )
12
+ . arg ( "battery.battery_mgr.is_charging" )
13
+ . output ( )
14
+ . await ?;
15
+
16
+ if !uci_battery. status . success ( ) {
17
+ return Err ( RayhunterError :: BatteryLevelParseError ) ;
18
+ }
19
+
20
+ if !uci_plugged_in. status . success ( ) {
21
+ return Err ( RayhunterError :: BatteryPluggedInStatusParseError ) ;
22
+ }
23
+
24
+ let uci_battery = String :: from_utf8_lossy ( & uci_battery. stdout )
25
+ . to_string ( )
26
+ . trim_end ( )
27
+ . parse ( )
28
+ . or ( Err ( RayhunterError :: BatteryLevelParseError ) ) ;
29
+
30
+ let uci_plugged_in = match String :: from_utf8_lossy ( & uci_plugged_in. stdout )
31
+ . to_string ( )
32
+ . chars ( )
33
+ . next ( )
34
+ {
35
+ Some ( '0' ) => Ok ( false ) ,
36
+ Some ( '1' ) => Ok ( true ) ,
37
+ _ => Err ( RayhunterError :: BatteryPluggedInStatusParseError ) ,
38
+ } ;
39
+
40
+ Ok ( BatteryState {
41
+ level : uci_battery?,
42
+ is_plugged_in : uci_plugged_in?,
43
+ } )
44
+ }
You can’t perform that action at this time.
0 commit comments