diff --git a/ex3_obc_fsw/cmd_dispatcher/src/main.rs b/ex3_obc_fsw/cmd_dispatcher/src/main.rs index a75b6030..a1900ad6 100644 --- a/ex3_obc_fsw/cmd_dispatcher/src/main.rs +++ b/ex3_obc_fsw/cmd_dispatcher/src/main.rs @@ -19,7 +19,8 @@ fn main() { }, } }).collect(); - + + println!("GOT {:?}", component_streams.get(7)); // prints COMS connection for x in 0..ComponentIds::LAST as usize { let payload = match ComponentIds::try_from(x as u8) { Ok(p) => { diff --git a/ex3_obc_fsw/handlers/coms_handler/src/main.rs b/ex3_obc_fsw/handlers/coms_handler/src/main.rs index e631b664..553c3b4d 100644 --- a/ex3_obc_fsw/handlers/coms_handler/src/main.rs +++ b/ex3_obc_fsw/handlers/coms_handler/src/main.rs @@ -122,20 +122,6 @@ fn main() { init_logger(&log_path); trace!("Logger initialized"); trace!("Beginning Coms Handler..."); - - //Setup interface for comm with UHF transceiver [ground station] (TCP for now) - let mut tcp_interface = - TcpInterface::new_server("127.0.0.1".to_string(), ports::SIM_COMMS_PORT).unwrap(); - - //Setup interface for comm with OBC FSW components (IPC), for the purpose of passing messages to and from the GS - let ipc_gs_interfac_res = IpcClient::new("gs_bulk".to_string()); - let mut ipc_gs_interface = match ipc_gs_interfac_res { - Ok(i) => Some(i), - Err(e) => { - warn!("Cannot connect to bulk interface: {e}"); - None - } - }; //Setup interface for comm with OBC FSW components (IPC), for passing messages to and from the UHF specifically // TODO - name this to gs_handler once uhf handler and gs handler are broken up from this program. @@ -150,6 +136,20 @@ fn main() { } let mut ipc_coms_interface = ipc_coms_interface_res.unwrap(); + + //Setup interface for comm with UHF transceiver [ground station] (TCP for now) + let mut tcp_interface = + TcpInterface::new_server("127.0.0.1".to_string(), ports::SIM_COMMS_PORT).unwrap(); + + //Setup interface for comm with OBC FSW components (IPC), for the purpose of passing messages to and from the GS + let ipc_gs_interfac_res = IpcClient::new("gs_bulk".to_string()); + let mut ipc_gs_interface = match ipc_gs_interfac_res { + Ok(i) => Some(i), + Err(e) => { + warn!("Cannot connect to bulk interface: {e}"); + None + } + }; let mut uhf_buf = vec![0; UHF_MAX_MESSAGE_SIZE_BYTES as usize]; //Buffer to read incoming messages from UHF let mut uhf_num_bytes_read = 0; @@ -164,17 +164,17 @@ fn main() { let coms_bytes_read_res = poll_ipc_server_sockets(&mut servers); let ipc_bytes_read_res = poll_ipc_clients(&mut clients); - if let Some(ref mut ipc_gs_interfac) = ipc_gs_interface { - if ipc_gs_interfac.buffer != [0u8; IPC_BUFFER_SIZE] { + if let Some(ref mut init_ipc_gs_interface) = ipc_gs_interface { + if init_ipc_gs_interface.buffer != [0u8; IPC_BUFFER_SIZE] { trace!("Received IPC Msg bytes for GS"); - let deserialized_msg_result = deserialize_msg(&ipc_gs_interfac.buffer); + let deserialized_msg_result = deserialize_msg(&init_ipc_gs_interface.buffer); match deserialized_msg_result { Ok(deserialized_msg) => { // writes directly to GS, handling case if it's a bulk message if deserialized_msg.header.msg_type == MsgType::Bulk as u8 && !received_bulk_ack { // If we haven't received Bulk ACK, we need to send ack - if let Some(e) = send_bulk_ack(&ipc_gs_interfac.fd).err() { + if let Some(e) = send_bulk_ack(&init_ipc_gs_interface.fd).err() { println!("failed to send bulk ack: {e}"); } received_bulk_ack = true; @@ -194,7 +194,7 @@ fn main() { if bulk_msgs_read < expected_msgs { if let Ok((ipc_bytes_read, ipc_name)) = ipc_bytes_read_res { if ipc_name.contains("gs") { - let cur_buf = ipc_gs_interfac.buffer[..ipc_bytes_read].to_vec(); + let cur_buf = init_ipc_gs_interface.buffer[..ipc_bytes_read].to_vec(); println!("Bytes read: {}", cur_buf.len()); let cur_msg = deserialize_msg(&cur_buf).unwrap(); write_msg_to_uhf_for_downlink(&mut tcp_interface, cur_msg); @@ -214,7 +214,7 @@ fn main() { } }; trace!("Bulk msgs read: {}", bulk_msgs_read); - ipc_gs_interfac.clear_buffer(); + init_ipc_gs_interface.clear_buffer(); } } // If we are done reading bulk msgs, start protocol with GS diff --git a/ex3_shared_libs/interfaces/ipc/src/lib.rs b/ex3_shared_libs/interfaces/ipc/src/lib.rs index cbfd49db..67e43491 100644 --- a/ex3_shared_libs/interfaces/ipc/src/lib.rs +++ b/ex3_shared_libs/interfaces/ipc/src/lib.rs @@ -27,6 +27,7 @@ fn create_socket() -> Result { } /// Client struct using a unix domain socket of type SOCKSEQ packet, that connects to a server socket +#[derive(Debug)] pub struct IpcClient { pub socket_path: String, pub fd: OwnedFd,