File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 1
1
use simplelog:: * ;
2
+ use std:: path:: PathBuf ;
2
3
use std:: sync:: Arc ;
4
+ use tokio:: fs;
3
5
use tokio:: sync:: mpsc:: Sender ;
4
6
use tokio:: sync:: Mutex ;
5
7
@@ -101,8 +103,18 @@ pub async fn send_ev_data(
101
103
ev_battery_capacity : u64 ,
102
104
ev_factor : f32 ,
103
105
) -> Result < ( ) > {
104
- // parse initial sample Ford data
105
- let mut msg = SensorBatch :: parse_from_bytes ( FORD_EV_MODEL ) ?;
106
+ // obtain binary model data
107
+ let model_path: PathBuf = PathBuf :: from ( EV_MODEL_FILE ) ;
108
+ let data = if fs:: try_exists ( & model_path) . await ? {
109
+ // reading model from file
110
+ fs:: read ( & model_path) . await ?
111
+ } else {
112
+ // default initial sample Ford data
113
+ FORD_EV_MODEL . to_vec ( )
114
+ } ;
115
+
116
+ // parse
117
+ let mut msg = SensorBatch :: parse_from_bytes ( & data) ?;
106
118
107
119
// apply our changes
108
120
msg. energy_model_control [ 0 ] . u1 . as_mut ( ) . unwrap ( ) . u6 = 1.0 ;
You can’t perform that action at this time.
0 commit comments