tramex_tools/interface/
types.rs

1//! This module contains the types used in the websocket module.
2
3use std::str::FromStr;
4
5use crate::interface::onelog::OneLog;
6
7// deserialize the message
8#[derive(serde::Deserialize, Debug)]
9/// LogGet struct
10pub struct WebSocketLog {
11    /// Same as request
12    pub message: String,
13
14    ///Any type, force as string // Same as in request.
15    pub message_id: Option<u64>,
16
17    /// Number representing time in seconds since start of the process. // Useful to send command with absolute time.
18    pub time: f64,
19
20    ///Number representing UTC seconds.
21    pub utc: f64,
22
23    /// Logs vectors
24    pub logs: Vec<OneLog>,
25}
26
27/// LogGet struct
28#[derive(serde::Deserialize, Debug)]
29pub struct BaseMessage {
30    /// Message
31    pub message: String,
32
33    /// Message ID
34    pub name: String,
35
36    /// Time
37    pub time: f64,
38
39    /// UTC
40    pub utc: f64,
41
42    /// Version
43    pub version: String,
44}
45
46#[derive(Debug, PartialEq)]
47/// LogLevel struct
48pub enum LogLevel {
49    /// Error log level
50    ERROR = 1,
51
52    /// Warning log level
53    WARN = 2,
54
55    /// Info log level
56    INFO = 3,
57
58    /// Debug log level
59    DEBUG = 4,
60}
61
62#[derive(serde::Deserialize, Debug, PartialEq)]
63/// SourceLog enum
64pub enum SourceLog {
65    /// ENB source
66    ENB,
67
68    /// MME source
69    MME,
70}
71
72#[derive(serde::Deserialize, Debug, PartialEq, Default, Clone)]
73/// Direction enum
74pub enum Direction {
75    #[default]
76    /// Uplink direction
77    UL,
78
79    /// Downlink direction
80    DL,
81
82    /// From direction
83    FROM,
84
85    /// To direction
86    TO,
87}
88
89impl FromStr for Direction {
90    type Err = ();
91
92    fn from_str(input_string: &str) -> Result<Self, Self::Err> {
93        match input_string {
94            "UL" => Ok(Direction::UL),
95            "DL" => Ok(Direction::DL),
96            "FROM" => Ok(Direction::FROM),
97            "TO" => Ok(Direction::TO),
98            _ => Err(()),
99        }
100    }
101}
102
103impl<'de> serde::Deserialize<'de> for LogLevel {
104    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
105    where
106        D: serde::Deserializer<'de>,
107    {
108        let deserialized_int = u8::deserialize(deserializer)?;
109        match deserialized_int {
110            1 => Ok(LogLevel::ERROR),
111            2 => Ok(LogLevel::WARN),
112            3 => Ok(LogLevel::INFO),
113            4 => Ok(LogLevel::DEBUG),
114            _ => Ok(LogLevel::INFO), // default
115        }
116    }
117}