|
@@ -2,6 +2,7 @@ mod modulecommrust;
|
|
|
|
|
|
mod proto;
|
|
|
use proto::mapdata::Tracemap;
|
|
|
+use proto::gpsimu::Gpsimu;
|
|
|
use protobuf::Message;
|
|
|
extern crate protobuf;
|
|
|
|
|
@@ -9,16 +10,31 @@ use std::os::raw::{c_char, c_uint};
|
|
|
use std::thread;
|
|
|
use std::time::Duration;
|
|
|
|
|
|
+use std::sync::Mutex;
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
|
|
|
|
-struct adcdes{
|
|
|
- xtr:Tracemap
|
|
|
+struct Adcdes{
|
|
|
+ xtr:Tracemap,
|
|
|
+ bxtrupdate : bool,
|
|
|
+ xgpsimu: Gpsimu,
|
|
|
+ bgpsimuupdate: bool
|
|
|
+}
|
|
|
+
|
|
|
+impl Adcdes{
|
|
|
+ fn GetDecision(&mut self) -> f32{
|
|
|
+ println!("in decision xtr Size: {} update {}", self.xtr.point.len(),self.bxtrupdate);
|
|
|
+ self.bgpsimuupdate = false;
|
|
|
+
|
|
|
+
|
|
|
+ 1.0
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
lazy_static! {
|
|
|
|
|
|
- static ref DES:adcdes = adcdes{xtr:Tracemap::new()};
|
|
|
+ static ref DES:Mutex<Adcdes> = Mutex::new(Adcdes {xtr:Tracemap::new(),bxtrupdate : false,
|
|
|
+ xgpsimu:Gpsimu::new(),bgpsimuupdate:false});
|
|
|
|
|
|
}
|
|
|
|
|
@@ -47,13 +63,17 @@ extern "C" fn tracemap_callback(strdata: *const c_char, nsize: c_uint, index: c_
|
|
|
println!("Callback received: (size: {}, index: {})", nsize, index);
|
|
|
let n_size: usize = nsize as usize;
|
|
|
let bytes = c_str_to_bytes(strdata, n_size);
|
|
|
- // let xtracemap = proto::mapdata::Tracemap::parse_from_bytes(&bytes).unwrap();
|
|
|
match proto::mapdata::Tracemap::parse_from_bytes(&bytes) {
|
|
|
|
|
|
Ok(xtracemap) => {
|
|
|
- let xdes = adcdes{xtr:xtracemap};
|
|
|
- println!("receive new map Size: {}", xdes.xtr.point.len());
|
|
|
-
|
|
|
+ let mut a = DES.lock().unwrap();
|
|
|
+ println!("before xtr Size: {} update {}", a.xtr.point.len(),a.bxtrupdate);
|
|
|
+ println!("receive new map Size: {}", xtracemap.point.len());
|
|
|
+
|
|
|
+ a.xtr = xtracemap;
|
|
|
+ a.bxtrupdate = true;
|
|
|
+ println!("after xtr Size: {}", a.xtr.point.len());
|
|
|
+
|
|
|
|
|
|
},
|
|
|
|
|
@@ -64,14 +84,26 @@ extern "C" fn tracemap_callback(strdata: *const c_char, nsize: c_uint, index: c_
|
|
|
},
|
|
|
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+extern "C" fn gpsimu_callback(strdata: *const c_char, nsize: c_uint, index: c_uint) {
|
|
|
+ let n_size: usize = nsize as usize;
|
|
|
+ let bytes = c_str_to_bytes(strdata, n_size);
|
|
|
+ match proto::gpsimu::Gpsimu::parse_from_bytes(&bytes) {
|
|
|
+
|
|
|
+ Ok(xgpsimu) => {
|
|
|
+ let mut a = DES.lock().unwrap();
|
|
|
+ a.xgpsimu = xgpsimu;
|
|
|
+ a.bgpsimuupdate = true;
|
|
|
+ },
|
|
|
+ Err(e) => {
|
|
|
+ eprintln!("Error parsing gpsimu protobuf: {:?}", e);
|
|
|
+ },
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
fn main() {
|
|
|
println!("Hello, world!");
|
|
|
|
|
@@ -84,13 +116,18 @@ fn main() {
|
|
|
let _pa = unsafe { modulecommrust::RegisterSendRUST(c_commname.as_ptr(), nsize, npaccount) };
|
|
|
|
|
|
let strmapmsgname = "newtracemap";
|
|
|
- let c_strmapmsgname = std::ffi::CString::new(strmapmsgname).unwrap();
|
|
|
-
|
|
|
+ let c_strmapmsgname = std::ffi::CString::new(strmapmsgname).unwrap();
|
|
|
let _pamap = unsafe { modulecommrust::RegisterRecvRUST(c_strmapmsgname.as_ptr(), tracemap_callback) };
|
|
|
|
|
|
+ let strgpsmsgname: &str = "hcp2_gpsimu";
|
|
|
+ let c_strgpsmsgname = std::ffi::CString::new(strgpsmsgname).unwrap();
|
|
|
+ let _pagps = unsafe { modulecommrust::RegisterRecvRUST(c_strgpsmsgname.as_ptr(), gpsimu_callback) };
|
|
|
+
|
|
|
loop {
|
|
|
|
|
|
- thread::sleep(Duration::from_millis(10));
|
|
|
+ thread::sleep(Duration::from_millis(1000));
|
|
|
+ let mut a = DES.lock().unwrap();
|
|
|
+ a.GetDecision();
|
|
|
}
|
|
|
|
|
|
// unsafe { modulecommrust::UnregisterRUST(_pa) };
|