#[macro_export]
macro_rules! supported_message_as {
($v: expr, $i: ident) => {
if let SupportedMessage::$i(value) = $v {
*value
} else {
panic!("Cannot convert to {:?}", stringify!($i));
}
};
}
lazy_static! {
pub static ref RUNTIME: crate::core::runtime::Runtime =
crate::core::runtime::Runtime::default();
}
#[macro_export]
macro_rules! runtime_components {
() => {{
use $crate::core::RUNTIME;
RUNTIME.components()
}};
}
#[macro_export]
macro_rules! register_runtime_component {
( $component_name:expr ) => {
RUNTIME.register_component($component_name);
};
}
#[macro_export]
macro_rules! deregister_runtime_component {
( $component_name:expr ) => {
RUNTIME.deregister_component($component_name);
};
}
pub mod debug {
pub fn log_buffer(message: &str, buf: &[u8]) {
if !log_enabled!(target: "hex", log::Level::Trace) {
return;
}
let line_len = 32;
let len = buf.len();
let last_line_padding = ((len / line_len) + 1) * line_len - len;
trace!(target: "hex", "{}", message);
let mut char_line = String::new();
let mut hex_line = format!("{:08x}: ", 0);
for (i, b) in buf.iter().enumerate() {
let value = *b as u8;
if i > 0 && i % line_len == 0 {
trace!(target: "hex", "{} {}", hex_line, char_line);
hex_line = format!("{:08}: ", i);
char_line.clear();
}
hex_line = format!("{} {:02x}", hex_line, value);
char_line.push(if value >= 32 && value <= 126 {
value as char
} else {
'.'
});
}
if last_line_padding > 0 {
for _ in 0..last_line_padding {
hex_line.push_str(" ");
}
trace!(target: "hex", "{} {}", hex_line, char_line);
}
}
}
#[cfg(test)]
pub mod tests;
pub mod constants {
pub const DEFAULT_OPC_UA_SERVER_PORT: u16 = 4840;
}
pub mod comms;
pub mod config;
pub mod handle;
pub mod runtime;
#[rustfmt::skip]
pub mod supported_message;
pub mod prelude {
pub use super::{comms::prelude::*, config::Config, supported_message::*};
pub use crate::types::{status_code::StatusCode, *};
}