server port is configurable now
This commit is contained in:
parent
d7acd93ee9
commit
948c42c7c2
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@
|
|||||||
|
|
||||||
# Ignore logs folder generared by application.
|
# Ignore logs folder generared by application.
|
||||||
/logs
|
/logs
|
||||||
|
/exp278.toml
|
||||||
|
55
Cargo.lock
generated
55
Cargo.lock
generated
@ -491,6 +491,7 @@ dependencies = [
|
|||||||
"satrs-mib",
|
"satrs-mib",
|
||||||
"strum",
|
"strum",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
"toml",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -518,7 +519,7 @@ version = "3.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284"
|
checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"toml_edit",
|
"toml_edit 0.21.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -591,9 +592,9 @@ checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "satrs"
|
name = "satrs"
|
||||||
version = "0.2.0-rc.1"
|
version = "0.2.0-rc.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8d6f3286d35464fdc75dc846b663aaad4a81437a50e623053b1b4d481d782cd0"
|
checksum = "6aa9241e4d6cb0cc395927cfe653d8bc4a9cb6b2c27f28fec713d5e6ceb0ba23"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bus",
|
"bus",
|
||||||
"cobs",
|
"cobs",
|
||||||
@ -680,6 +681,15 @@ dependencies = [
|
|||||||
"syn 2.0.59",
|
"syn 2.0.59",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_spanned"
|
||||||
|
version = "0.6.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smallvec"
|
name = "smallvec"
|
||||||
version = "0.6.14"
|
version = "0.6.14"
|
||||||
@ -785,11 +795,26 @@ dependencies = [
|
|||||||
"syn 2.0.59",
|
"syn 2.0.59",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml"
|
||||||
|
version = "0.8.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_spanned",
|
||||||
|
"toml_datetime",
|
||||||
|
"toml_edit 0.22.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_datetime"
|
name = "toml_datetime"
|
||||||
version = "0.6.5"
|
version = "0.6.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
|
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_edit"
|
name = "toml_edit"
|
||||||
@ -799,7 +824,20 @@ checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"toml_datetime",
|
"toml_datetime",
|
||||||
"winnow",
|
"winnow 0.5.40",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml_edit"
|
||||||
|
version = "0.22.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
"serde",
|
||||||
|
"serde_spanned",
|
||||||
|
"toml_datetime",
|
||||||
|
"winnow 0.6.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1037,6 +1075,15 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winnow"
|
||||||
|
version = "0.6.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f0c976aaaa0e1f90dbb21e9587cdaf1d9679a1cde8875c0d6bd83ab96a208352"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zerocopy"
|
name = "zerocopy"
|
||||||
version = "0.7.32"
|
version = "0.7.32"
|
||||||
|
@ -7,6 +7,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fern = "0.6"
|
fern = "0.6"
|
||||||
|
toml = "0.8"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
|
@ -8,6 +8,7 @@ use std::net::Ipv4Addr;
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
pub const STOP_FILE_NAME: &str = "stop-experiment";
|
pub const STOP_FILE_NAME: &str = "stop-experiment";
|
||||||
|
pub const CONFIG_FILE_NAME: &str = "exp278.toml";
|
||||||
pub const HOME_FOLER_EXPERIMENT: &str = "/home/exp278";
|
pub const HOME_FOLER_EXPERIMENT: &str = "/home/exp278";
|
||||||
pub const LOG_FOLDER: &str = "logs";
|
pub const LOG_FOLDER: &str = "logs";
|
||||||
|
|
||||||
@ -51,6 +52,80 @@ lazy_static! {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod cfg_file {
|
||||||
|
use std::{
|
||||||
|
fs::File,
|
||||||
|
io::Read,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::{CONFIG_FILE_NAME, HOME_PATH, TCP_SPP_SERVER_PORT};
|
||||||
|
|
||||||
|
pub const SPP_CLIENT_PORT_CFG_KEY: &str = "tcp_spp_server_port";
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct AppCfg {
|
||||||
|
pub tcp_spp_server_port: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for AppCfg {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
tcp_spp_server_port: TCP_SPP_SERVER_PORT,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_app_config() -> AppCfg {
|
||||||
|
let mut cfg_path = HOME_PATH.clone();
|
||||||
|
cfg_path.push(CONFIG_FILE_NAME);
|
||||||
|
let cfg_path_home = cfg_path.as_path();
|
||||||
|
let relevant_path = if Path::new(CONFIG_FILE_NAME).exists() {
|
||||||
|
Some(PathBuf::from(Path::new(CONFIG_FILE_NAME)))
|
||||||
|
} else if cfg_path_home.exists() {
|
||||||
|
Some(PathBuf::from(cfg_path_home))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut app_cfg = AppCfg::default();
|
||||||
|
if relevant_path.is_none() {
|
||||||
|
log::warn!("No config file found, using default values");
|
||||||
|
return app_cfg;
|
||||||
|
}
|
||||||
|
let relevant_path = relevant_path.unwrap();
|
||||||
|
match File::open(relevant_path.as_path()) {
|
||||||
|
Ok(mut file) => {
|
||||||
|
let mut toml_str = String::new();
|
||||||
|
match file.read_to_string(&mut toml_str) {
|
||||||
|
Ok(_size) => match toml_str.parse::<toml::Table>() {
|
||||||
|
Ok(table) => {
|
||||||
|
handle_config_file_table(table, &mut app_cfg);
|
||||||
|
}
|
||||||
|
Err(e) => log::error!("error parsing TOML config file: {e}"),
|
||||||
|
},
|
||||||
|
Err(e) => log::error!("error reading TOML config file: {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => log::error!("error opening TOML config file: {e}"),
|
||||||
|
}
|
||||||
|
app_cfg
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::collapsible_match)]
|
||||||
|
pub fn handle_config_file_table(table: toml::Table, app_cfg: &mut AppCfg) {
|
||||||
|
if let Some(value) = table.get(SPP_CLIENT_PORT_CFG_KEY) {
|
||||||
|
if let toml::Value::Integer(port) = value {
|
||||||
|
if *port < 0 {
|
||||||
|
log::warn!("invalid port value, is negative");
|
||||||
|
} else {
|
||||||
|
app_cfg.tcp_spp_server_port = *port as u16
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub mod tmtc_err {
|
pub mod tmtc_err {
|
||||||
use super::*;
|
use super::*;
|
||||||
use satrs::res_code::ResultU16;
|
use satrs::res_code::ResultU16;
|
||||||
|
@ -6,7 +6,7 @@ use std::time::Duration;
|
|||||||
use mio::net::TcpStream;
|
use mio::net::TcpStream;
|
||||||
use mio::{Events, Interest, Poll, Token};
|
use mio::{Events, Interest, Poll, Token};
|
||||||
use ops_sat_rs::config::tasks::STOP_CHECK_FREQUENCY;
|
use ops_sat_rs::config::tasks::STOP_CHECK_FREQUENCY;
|
||||||
use ops_sat_rs::config::{SPP_CLIENT_WIRETAPPING_RX, TCP_SPP_SERVER_PORT};
|
use ops_sat_rs::config::SPP_CLIENT_WIRETAPPING_RX;
|
||||||
use satrs::encoding::ccsds::parse_buffer_for_ccsds_space_packets;
|
use satrs::encoding::ccsds::parse_buffer_for_ccsds_space_packets;
|
||||||
use satrs::queue::GenericSendError;
|
use satrs::queue::GenericSendError;
|
||||||
use satrs::spacepackets::PacketId;
|
use satrs::spacepackets::PacketId;
|
||||||
@ -43,11 +43,11 @@ impl TcpSppClient {
|
|||||||
tc_source_tx: mpsc::Sender<PacketAsVec>,
|
tc_source_tx: mpsc::Sender<PacketAsVec>,
|
||||||
tm_tcp_client_rx: mpsc::Receiver<PacketAsVec>,
|
tm_tcp_client_rx: mpsc::Receiver<PacketAsVec>,
|
||||||
valid_ids: &'static [PacketId],
|
valid_ids: &'static [PacketId],
|
||||||
|
port: u16,
|
||||||
) -> io::Result<Self> {
|
) -> io::Result<Self> {
|
||||||
let mut poll = Poll::new()?;
|
let mut poll = Poll::new()?;
|
||||||
let events = Events::with_capacity(128);
|
let events = Events::with_capacity(128);
|
||||||
let server_addr =
|
let server_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), port);
|
||||||
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 1, 1)), TCP_SPP_SERVER_PORT);
|
|
||||||
let client = Self::attempt_connection(&mut poll, &server_addr);
|
let client = Self::attempt_connection(&mut poll, &server_addr);
|
||||||
if client.is_err() {
|
if client.is_err() {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
|
@ -7,6 +7,7 @@ use std::{
|
|||||||
|
|
||||||
use log::info;
|
use log::info;
|
||||||
use ops_sat_rs::config::{
|
use ops_sat_rs::config::{
|
||||||
|
cfg_file::create_app_config,
|
||||||
components::{CONTROLLER_ID, TCP_SERVER, TCP_SPP_CLIENT, UDP_SERVER},
|
components::{CONTROLLER_ID, TCP_SERVER, TCP_SPP_CLIENT, UDP_SERVER},
|
||||||
tasks::{FREQ_MS_CTRL, FREQ_MS_PUS_STACK},
|
tasks::{FREQ_MS_CTRL, FREQ_MS_PUS_STACK},
|
||||||
VALID_PACKET_ID_LIST,
|
VALID_PACKET_ID_LIST,
|
||||||
@ -42,6 +43,9 @@ fn main() {
|
|||||||
setup_logger().expect("setting up logging with fern failed");
|
setup_logger().expect("setting up logging with fern failed");
|
||||||
println!("OPS-SAT Rust Experiment OBSW");
|
println!("OPS-SAT Rust Experiment OBSW");
|
||||||
|
|
||||||
|
let app_cfg = create_app_config();
|
||||||
|
println!("App Configuration: {:?}", app_cfg);
|
||||||
|
|
||||||
let stop_signal = Arc::new(AtomicBool::new(false));
|
let stop_signal = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
let (tc_source_tx, tc_source_rx) = mpsc::channel();
|
let (tc_source_tx, tc_source_rx) = mpsc::channel();
|
||||||
@ -169,6 +173,7 @@ fn main() {
|
|||||||
tc_source_tx,
|
tc_source_tx,
|
||||||
tm_tcp_client_rx,
|
tm_tcp_client_rx,
|
||||||
VALID_PACKET_ID_LIST,
|
VALID_PACKET_ID_LIST,
|
||||||
|
app_cfg.tcp_spp_server_port,
|
||||||
)
|
)
|
||||||
.expect("creating TCP SPP client failed");
|
.expect("creating TCP SPP client failed");
|
||||||
|
|
||||||
|
2
templates/exp278.toml
Normal file
2
templates/exp278.toml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# On the small flatsat, change this to 9999.
|
||||||
|
tcp_spp_client_port = 4096
|
Loading…
x
Reference in New Issue
Block a user