From 0fef3f69dd3a9c620c8231db23f164f586da7c31 Mon Sep 17 00:00:00 2001 From: Rowan Date: Thu, 12 Sep 2024 16:35:31 -0600 Subject: [PATCH] commit before rebase --- .../cli_ground_station/src/main.rs | 2 +- ex3_obc_fsw/handlers/coms_handler/src/main.rs | 15 ++++++------- ex3_shared_libs/interfaces/ipc/src/lib.rs | 22 +++++++++++-------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/ex3_ground_station/cli_ground_station/src/main.rs b/ex3_ground_station/cli_ground_station/src/main.rs index 1153f638..ef3328f7 100644 --- a/ex3_ground_station/cli_ground_station/src/main.rs +++ b/ex3_ground_station/cli_ground_station/src/main.rs @@ -202,7 +202,7 @@ async fn main() { eprintln!("Connecting to Coms handler via TCP at {ipaddr}..."); - let mut tcp_interface = match TcpInterface::new_client(ipaddr.to_string(), SIM_UHF_GS_PORT) { + let mut tcp_interface = match TcpInterface::new_client(ipaddr.to_string(), ports::SIM_COMMS_PORT) { Ok(ti) => ti, Err(e) => { eprintln!("Can't connect to satellite: {e}"); diff --git a/ex3_obc_fsw/handlers/coms_handler/src/main.rs b/ex3_obc_fsw/handlers/coms_handler/src/main.rs index 6ab45aa7..ed0bbb98 100644 --- a/ex3_obc_fsw/handlers/coms_handler/src/main.rs +++ b/ex3_obc_fsw/handlers/coms_handler/src/main.rs @@ -125,18 +125,17 @@ fn main() { //Setup interface for comm with UHF transceiver [ground station] (TCP for now) let mut tcp_interface = - TcpInterface::new_client("127.0.0.1".to_string(), ports::SIM_COMMS_PORT).unwrap(); + 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 mut ipc_gs_interface; let ipc_gs_interface_res = IpcClient::new("gs_bulk".to_string()); - if ipc_gs_interface_res.is_err() { - warn!( - "Error creating IPC interface: {:?}", - ipc_gs_interface_res.err() - ); - return; + if let Err(e) = ipc_gs_interface_res { + warn!("Error creating IPC interface: {e}"); + } else { + ipc_gs_interface = ipc_gs_interface_res.unwrap(); + } - let mut ipc_gs_interface = ipc_gs_interface_res.unwrap(); //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. diff --git a/ex3_shared_libs/interfaces/ipc/src/lib.rs b/ex3_shared_libs/interfaces/ipc/src/lib.rs index 2e79541d..a62aaadf 100644 --- a/ex3_shared_libs/interfaces/ipc/src/lib.rs +++ b/ex3_shared_libs/interfaces/ipc/src/lib.rs @@ -7,6 +7,7 @@ use nix::libc; use nix::sys::socket::{self, accept, bind, listen, socket, Backlog, AddressFamily, SockFlag, SockType, UnixAddr}; use nix::unistd::{read, write}; use std::ffi::CString; +use nix::errno::Errno; use std::io::Error as IoError; use std::os::fd::{AsFd, AsRawFd, FromRawFd, OwnedFd, RawFd}; use std::path::Path; @@ -46,7 +47,7 @@ impl IpcClient { Ok(client) } - fn connect_to_server(&mut self) -> Result<(), IoError> { + fn connect_to_server(&mut self) -> Result<(), Errno> { let socket_path_c_str = CString::new(self.socket_path.clone()).unwrap(); let addr = UnixAddr::new(socket_path_c_str.as_bytes()).unwrap_or_else(|err| { eprintln!("Failed to create UnixAddr: {}", err); @@ -57,14 +58,17 @@ impl IpcClient { self.socket_path ); let fd: RawFd = self.fd.as_raw_fd(); - socket::connect(fd, &addr).unwrap_or_else(|err| { - eprintln!("Failed to connect to server socket: {}", err); - process::exit(1) - }); - println!("Connected to server socket at: {}", self.socket_path); - self.connected = true; - - Ok(()) + match socket::connect(fd, &addr) { + Ok(()) => { + println!("Connected to server socket at: {}", self.socket_path); + self.connected = true; + Ok(()) + } + Err(e) => { + eprintln!("Failed to connect to server socket: {}", e); + Err(e) + } + } } /// Users of this lib can call this to clear the buffer - otherwise the preivous read data will remain