some more optimizations

This commit is contained in:
Robin Müller 2024-04-29 16:45:08 +02:00
parent e227fa1d01
commit a095132d57
Signed by: muellerr
GPG Key ID: A649FB78196E3849
3 changed files with 28 additions and 15 deletions

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python3
import socket
import json
import abc
import time
import select
@ -15,7 +16,7 @@ EXP_ID = 278
EXP_APID = 1024 + EXP_ID
EXP_PACKET_ID_TM = PacketId(PacketType.TM, True, EXP_APID)
EXP_PACKET_ID_TC = PacketId(PacketType.TC, True, EXP_APID)
OPSSAT_SERVER_PORT = 4096
OPSSAT_DEFAULT_SERVER_PORT = 4096
TMTC_SERVER_PORT = 4097
LOG_LEVEL = logging.INFO
@ -36,7 +37,17 @@ def main():
)
print("Starting OPS-SAT ground TMTC server")
KILL_SIGNAL.clear()
ops_sat_thread = OpsSatServer()
ops_sat_server_port = OPSSAT_DEFAULT_SERVER_PORT
with open("tmtc_conf.json") as cfg_file:
# Load JSON data
data = json.loads(cfg_file.read())
# Access the value of the tcpip_tcp_server_port key
maybe_ops_sat_server_port = data.get("tcpip_tcp_server_port")
if maybe_ops_sat_server_port is not None:
ops_sat_server_port = maybe_ops_sat_server_port
_LOGGER.info(f"creating OPS-SAT server on port {ops_sat_server_port}")
ops_sat_thread = OpsSatServer(ops_sat_server_port)
ops_sat_thread.start()
tmtc_thread = TmtcServer()
tmtc_thread.start()
@ -142,8 +153,9 @@ class BaseServer(Thread):
class OpsSatServer(BaseServer):
def __init__(self):
super().__init__("[OPS-SAT]", OPSSAT_SERVER_PORT)
def __init__(self, port: int):
self.port = port
super().__init__("[OPS-SAT]", port)
def handle_read_bytestream(self, analysis_deque: deque):
parsed_packets = parse_space_packets(analysis_deque, [EXP_PACKET_ID_TM])

View File

@ -145,6 +145,16 @@ impl TcpSppClientStd {
}
pub fn operation(&mut self) -> Result<ClientResult, ClientError> {
let result = self.operation_inner();
if let Ok(client_result) = &result {
if *client_result != ClientResult::Ok {
std::thread::sleep(self.read_and_idle_delay);
}
}
result
}
fn operation_inner(&mut self) -> Result<ClientResult, ClientError> {
if let Some(client) = &mut self.stream {
// Write TM first before blocking on the read call.
self.common.write_to_server(client)?;

View File

@ -24,10 +24,7 @@ use satrs::{
pus::event_man::EventRequestWithToken,
};
use crate::{
controller::ControllerPathCollection, interface::tcp_spp_client::ClientResult,
tmtc::tm_sink::TmFunnelDynamic,
};
use crate::{controller::ControllerPathCollection, tmtc::tm_sink::TmFunnelDynamic};
use crate::{controller::ExperimentController, pus::test::create_test_service};
use crate::{
events::EventHandler,
@ -284,13 +281,7 @@ fn main() {
info!("Running TCP SPP client");
loop {
match tcp_spp_client.operation() {
Ok(result) => {
// If the client connection was processed regularly, the read timeout takes
// care of the sleep time.
if result != ClientResult::Ok {
std::thread::sleep(STOP_CHECK_FREQUENCY);
}
}
Ok(_result) => (),
Err(e) => {
log::error!("TCP SPP client error: {}", e);
}