Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ ferroflow-vcan down vcan0

## Development

### Runtime Configuration

Ferroflow reads `config.yml` on startup. An example can be found at `config.example.yml`.

### Running CI Checks

The repository includes a CI script (`ci-rust.sh`) that runs all quality checks on the Rust implementation. This script is used both locally and in GitHub Actions
Expand Down
11 changes: 11 additions & 0 deletions config.example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
can_bus_interfaces:
- can0

heartbeat:
period: 1
backoff_multiplier: 2
max_period: 60
max_unanswered: 5

# Leave empty to disable database logging.
database_url: ""
29 changes: 28 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@ use anyhow::{Context, Result};
use config as config_builder;
use serde::{Deserialize, Serialize};

const DEFAULT_HEARTBEAT_BACKOFF_MULTIPLIER: u32 = 2;
const DEFAULT_HEARTBEAT_MAX_PERIOD: u32 = 60;
const DEFAULT_HEARTBEAT_MAX_UNANSWERED: u32 = 5;

#[derive(Deserialize, Serialize, Debug)]
pub struct HeartbeatConfig {
pub period: u32,
#[serde(default = "default_heartbeat_backoff_multiplier")]
pub backoff_multiplier: u32,
#[serde(default = "default_heartbeat_max_period")]
pub max_period: u32,
#[serde(default = "default_heartbeat_max_unanswered")]
pub max_unanswered: u32,
}

#[derive(Deserialize, Serialize, Debug)]
pub struct Config {
pub can_bus_interfaces: Vec<String>,
pub heartbeat_period: u64,
pub heartbeat: HeartbeatConfig,
pub database_url: String,
}

Expand All @@ -20,3 +35,15 @@ pub fn load_config(path: &str) -> Result<Config> {
.try_deserialize()
.with_context(|| format!("Failed to deserialize config from {}", path))
}

fn default_heartbeat_backoff_multiplier() -> u32 {
DEFAULT_HEARTBEAT_BACKOFF_MULTIPLIER
}

fn default_heartbeat_max_period() -> u32 {
DEFAULT_HEARTBEAT_MAX_PERIOD
}

fn default_heartbeat_max_unanswered() -> u32 {
DEFAULT_HEARTBEAT_MAX_UNANSWERED
}
7 changes: 1 addition & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ pub fn run_with_dependencies(
println!("Starting node registration");

nodes::spawn_can_msg_handler_thread(node_manager, event_dispatcher, scope);
nodes::spawn_heartbeat_thread(
node_manager,
std::time::Duration::from_secs(config.heartbeat_period),
event_dispatcher,
scope,
);
nodes::spawn_heartbeat_thread(node_manager, &config.heartbeat, event_dispatcher, scope);

node_manager.start_node_registration();

Expand Down
Loading
Loading