1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//! # config.rs – Centralized Parameter Store
//!
//! This module holds all static program parameters used throughout the system.
//! Keeping configuration in one place makes tuning, experimentation, and testing easier.
//!
//! ## ⚠️ Maintenance Note:
//! Some of these constants may no longer be used. Consider cleaning up unused values.
use Ipv4Addr;
use Mutex;
use Duration;
use Lazy;
//
// ──────────────────────────────────────────────────────────────
// 1. NETWORK SETTINGS
// ──────────────────────────────────────────────────────────────
//
/// Base network prefix for Sanntidshallen
pub static NETWORK_PREFIX: &str = "10.100.23";
/// Port used for inter-node TCP communication (not active in current design)
pub static PN_PORT: u16 = u16MAX;
/// Port for local TCP communication with backup client
pub static BCU_PORT: u16 = 50001;
/// Dummy port for UDP broadcast messages
pub static BROADCAST_PORT: u16 = 42069;
/// Port used for direct UDP communication of elevator containers
pub const UDP_CONTAINER_PORT: u16 = 50000;
/// UDP broadcast listen address (bind address)
pub static BC_LISTEN_ADDR: &str = "0.0.0.0";
/// Broadcast address used for system-wide discovery
pub static BC_ADDR: &str = "255.255.255.255";
/// Dummy offline IP for fallback logic (used when disconnected)
pub static OFFLINE_IP: Ipv4Addr = new;
/// Localhost address used for visualization tools
pub static LOCAL_ELEV_IP: &str = "localhost:15657";
/// Broadcast key used to filter out invalid worldview messages
pub const KEY_STR: &str = "Secret Key";
/// SSH password
pub const SSH_PASSWORD: &str = "Your_Password";
//
// ──────────────────────────────────────────────────────────────
// 2. SYSTEM & ELEVATOR PARAMETERS
// ──────────────────────────────────────────────────────────────
//
/// Default number of floors in Sanntidshallen setup
pub const DEFAULT_NUM_FLOORS: u8 = 4;
/// Duration between elevator hardware polls
pub const ELEV_POLL: Duration = from_millis;
/// Special error ID used to mark invalid elevators
pub const ERROR_ID: u8 = 255;
/// Position in serialized worldview used to extract the master ID
pub const MASTER_IDX: usize = 1;
//
// ──────────────────────────────────────────────────────────────
// 3. TIMING & TIMEOUTS & INTERVALS
// ──────────────────────────────────────────────────────────────
//
/// Timeout duration for TCP connections
pub const TCP_TIMEOUT: u64 = 5000;
/// Period used for TCP message transmission
pub const TCP_PER_U64: u64 = 10;
/// Time interval between UDP broadcast transmissions
pub const UDP_PERIOD: Duration = from_millis;
/// General polling frequency (10 ms)
pub const POLL_PERIOD: Duration = from_millis;
/// Size of UDP receive buffer in bytes
pub const UDP_BUFFER: usize = u16MAX as usize;
/// Timeout for individual elevator tasks before being marked failed
pub const TASK_TIMEOUT: u64 = 100;
/// Delay between slave retransmissions
pub const SLAVE_TIMEOUT: Duration = from_millis;
/// Time backup waits before taking over as master
pub const MASTER_TIMEOUT: Duration = from_millis;
/// Timeout for backup mode takeover (same as above)
pub const BACKUP_TIMEOUT: Duration = from_millis;
/// How often the backup client receives worldview updates
pub const BACKUP_SEND_INTERVAL: Duration = from_millis;
/// How often the backup refreshes worldview locally
pub const BACKUP_WORLDVIEW_REFRESH_INTERVAL: Duration = from_millis;
/// Time between retry attempts to reconnect to master
pub const BACKUP_RETRY_DELAY: Duration = from_millis;
/// Number of retries before promoting backup to master
pub const BACKUP_FAILOVER_THRESHOLD: u32 = 50;
//
// ──────────────────────────────────────────────────────────────
// 4. PID REDUNDANCY CONTROL
// ──────────────────────────────────────────────────────────────
//
/// Proportional gain for PID redundancy controller
pub const REDUNDANCY_PID_KP: f64 = 60.0;
/// Integral gain for PID redundancy controller
pub const REDUNDANCY_PID_KI: f64 = 14.05;
/// Derivative gain for PID redundancy controller
pub const REDUNDANCY_PID_KD: f64 = 1.01;
/// Minimum clamp value for integral term (anti-windup)
pub const PID_INTEGRAL_MIN: f64 = -20.0;
/// Maximum clamp value for integral term (anti-windup)
pub const PID_INTEGRAL_MAX: f64 = 20.0;
/// Minimum redundancy factor (always send at least 1 packet)
pub const REDUNDANCY_MIN: f64 = 1.0;
/// Maximum redundancy factor (prevent network overload)
pub const REDUNDANCY_MAX: f64 = 300.0;
//
// ──────────────────────────────────────────────────────────────
// 5. LOGGING CONFIGURATION
// ──────────────────────────────────────────────────────────────
//
/// Enable/disable printing of worldview updates
pub static PRINT_WV_ON: = new;
/// Enable/disable printing of errors
pub static PRINT_ERR_ON: = new;
/// Enable/disable printing of warnings
pub static PRINT_WARN_ON: = new;
/// Enable/disable printing of success messages
pub static PRINT_OK_ON: = new;
/// Enable/disable printing of general info
pub static PRINT_INFO_ON: = new;
/// Enable/disable miscellaneous debug prints
pub static PRINT_ELSE_ON: = new;