first connection success
Some checks failed
Rust/sat-rs/pipeline/head There was a failure building this commit
Some checks failed
Rust/sat-rs/pipeline/head There was a failure building this commit
This commit is contained in:
@ -61,18 +61,14 @@ pub struct SpiSimInterface {
|
||||
impl SpiInterface for SpiSimInterface {
|
||||
type Error = ();
|
||||
|
||||
fn transfer(&mut self, tx: &[u8], rx: &mut [u8]) -> Result<(), Self::Error> {
|
||||
// Right now, we only support requesting sensor data and not configuration of the sensor.
|
||||
fn transfer(&mut self, _tx: &[u8], _rx: &mut [u8]) -> Result<(), Self::Error> {
|
||||
let mgm_sensor_request = MgmRequestLis3Mdl::RequestSensorData;
|
||||
self.sim_request_tx
|
||||
.send(SimRequest::new_with_epoch_time(mgm_sensor_request))
|
||||
.expect("failed to send request");
|
||||
self.sim_reply_rx.recv().expect("reply timeout");
|
||||
/*
|
||||
let mgm_req_json = serde_json::to_string(&mgm_sensor_request)?;
|
||||
self.udp_socket
|
||||
.send_to(mgm_req_json.as_bytes(), self.sim_addr)
|
||||
.unwrap();
|
||||
*/
|
||||
// TODO: Write the sensor data to the raw buffer.
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,10 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use satrs_minisim::{udp::SIM_CTRL_PORT, SimComponent, SimMessageProvider, SimReply, SimRequest};
|
||||
use satrs_minisim::{
|
||||
udp::SIM_CTRL_PORT, SerializableSimMsgPayload, SimComponent, SimMessageProvider, SimReply,
|
||||
SimRequest,
|
||||
};
|
||||
use satrs_minisim::{SimCtrlReply, SimCtrlRequest};
|
||||
|
||||
struct SimReplyMap(pub HashMap<SimComponent, mpsc::Sender<SimReply>>);
|
||||
@ -19,20 +22,9 @@ pub fn create_sim_client(sim_request_rx: mpsc::Receiver<SimRequest>) -> Option<S
|
||||
log::info!("simulator client connection success");
|
||||
return Some(sim_client);
|
||||
}
|
||||
Err(e) => match e {
|
||||
SimClientCreationResult::Io(e) => {
|
||||
log::warn!("creating SIM client failed with io error {}", e);
|
||||
}
|
||||
SimClientCreationResult::Timeout => {
|
||||
log::warn!("timeout when attempting connection to SIM client");
|
||||
}
|
||||
SimClientCreationResult::InvalidPingReply(reply) => {
|
||||
log::warn!(
|
||||
"invalid ping reply when attempting connection to SIM client: {}",
|
||||
reply
|
||||
);
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
log::warn!("sim client creation error: {}", e);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
@ -44,7 +36,9 @@ pub enum SimClientCreationResult {
|
||||
#[error("timeout when trying to connect to sim UDP server")]
|
||||
Timeout,
|
||||
#[error("invalid ping reply when trying connection to UDP sim server")]
|
||||
InvalidPingReply(#[from] serde_json::Error),
|
||||
InvalidReplyJsonError(#[from] serde_json::Error),
|
||||
#[error("invalid sim reply, not pong reply as expected: {0:?}")]
|
||||
ReplyIsNotPong(SimReply),
|
||||
}
|
||||
|
||||
pub struct SimClientUdp {
|
||||
@ -68,9 +62,14 @@ impl SimClientUdp {
|
||||
udp_client.send_to(sim_req_json.as_bytes(), simulator_addr)?;
|
||||
match udp_client.recv(&mut reply_buf) {
|
||||
Ok(reply_len) => {
|
||||
let sim_reply: SimCtrlReply = serde_json::from_slice(&reply_buf[0..reply_len])?;
|
||||
let sim_reply: SimReply = serde_json::from_slice(&reply_buf[0..reply_len])?;
|
||||
if sim_reply.component() != SimComponent::SimCtrl {
|
||||
return Err(SimClientCreationResult::ReplyIsNotPong(sim_reply));
|
||||
}
|
||||
udp_client.set_read_timeout(None)?;
|
||||
match sim_reply {
|
||||
let sim_ctrl_reply =
|
||||
SimCtrlReply::from_sim_message(&sim_reply).expect("invalid SIM reply");
|
||||
match sim_ctrl_reply {
|
||||
SimCtrlReply::Pong => Ok(Self {
|
||||
udp_client,
|
||||
simulator_addr,
|
||||
|
Reference in New Issue
Block a user