Skip to content

Commit

Permalink
Added debugging statements and changed order of coms bootup
Browse files Browse the repository at this point in the history
  • Loading branch information
rrasmuss4200 committed Sep 13, 2024
1 parent 25dc2a1 commit bba6b66
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
3 changes: 2 additions & 1 deletion ex3_obc_fsw/cmd_dispatcher/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
40 changes: 20 additions & 20 deletions ex3_obc_fsw/handlers/coms_handler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions ex3_shared_libs/interfaces/ipc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fn create_socket() -> Result<OwnedFd, IoError> {
}

/// 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,
Expand Down

0 comments on commit bba6b66

Please sign in to comment.