first connection success
Some checks failed
Rust/sat-rs/pipeline/head There was a failure building this commit

This commit is contained in:
Robin Müller 2024-05-08 20:55:56 +02:00
parent c20163b10a
commit fe4126f7e2
Signed by: muellerr
GPG Key ID: A649FB78196E3849
4 changed files with 38 additions and 26 deletions

View File

@ -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(())
}
}

View File

@ -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,

View File

@ -16,6 +16,11 @@ use crate::{
eps::PcduModel,
};
const SIM_CTRL_REQ_WIRETAPPING: bool = true;
const MGM_REQ_WIRETAPPING: bool = true;
const PCDU_REQ_WIRETAPPING: bool = true;
const MGT_REQ_WIRETAPPING: bool = true;
// The simulation controller processes requests and drives the simulation.
pub struct SimController {
pub sys_clock: SystemClock,
@ -91,6 +96,9 @@ impl SimController {
fn handle_ctrl_request(&mut self, request: &SimRequest) -> Result<(), SimRequestError> {
let sim_ctrl_request = SimCtrlRequest::from_sim_message(request)?;
if SIM_CTRL_REQ_WIRETAPPING {
log::info!("received sim ctrl request: {:?}", sim_ctrl_request);
}
match sim_ctrl_request {
SimCtrlRequest::Ping => {
self.reply_sender
@ -103,6 +111,9 @@ impl SimController {
fn handle_mgm_request(&mut self, request: &SimRequest) -> Result<(), SimRequestError> {
let mgm_request = MgmRequestLis3Mdl::from_sim_message(request)?;
if MGM_REQ_WIRETAPPING {
log::info!("received MGM request: {:?}", mgm_request);
}
match mgm_request {
MgmRequestLis3Mdl::RequestSensorData => {
self.simulation.send_event(
@ -117,6 +128,9 @@ impl SimController {
fn handle_pcdu_request(&mut self, request: &SimRequest) -> Result<(), SimRequestError> {
let pcdu_request = PcduRequest::from_sim_message(request)?;
if PCDU_REQ_WIRETAPPING {
log::info!("received PCDU request: {:?}", pcdu_request);
}
match pcdu_request {
PcduRequest::RequestSwitchInfo => {
self.simulation
@ -135,6 +149,9 @@ impl SimController {
fn handle_mgt_request(&mut self, request: &SimRequest) -> Result<(), SimRequestError> {
let mgt_request = MgtRequest::from_sim_message(request)?;
if MGT_REQ_WIRETAPPING {
log::info!("received MGT request: {:?}", mgt_request);
}
match mgt_request {
MgtRequest::ApplyTorque { duration, dipole } => self.simulation.send_event(
MagnetorquerModel::apply_torque,

View File

@ -89,7 +89,7 @@ impl SimMessageProvider for SimRequest {
}
/// A generic simulation reply type. Right now, the payload data is expected to be
/// JSON, which might be changed inthe future.
/// JSON, which might be changed in the future.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SimReply {
inner: SimMessage,