libits_client/monitor.rs
1// Software Name: its-client
2// SPDX-FileCopyrightText: Copyright (c) 2016-2022 Orange
3// SPDX-License-Identifier: MIT License
4//
5// This software is distributed under the MIT license, see LICENSE.txt file for more details.
6//
7// Author: Frédéric GARDES <frederic.gardes@orange.com> et al.
8// Software description: This Intelligent Transportation Systems (ITS) [MQTT](https://mqtt.org/) client based on the [JSon](https://www.json.org) [ETSI](https://www.etsi.org/committee/its) specification transcription provides a ready to connect project for the mobility (connected and autonomous vehicles, road side units, vulnerable road users,...).
9use crate::analyse::cause::Cause;
10use crate::reception::exchange::message::Message;
11use crate::reception::exchange::Exchange;
12use crate::reception::mortal::now;
13
14// TODO implement the Rust macro monitor!
15pub fn monitor(
16 exchange: &Exchange,
17 cause: Option<Cause>,
18 direction: &str,
19 component: String,
20 partner: String,
21) {
22 match &exchange.message {
23 // FIXME find how to call position() on any Message implementing Mobile
24 Message::CAM(message) => {
25 // log to monitoring platform
26 println!(
27 "{} {} {} {} {}/{} at {}",
28 component,
29 exchange.type_field,
30 direction,
31 partner,
32 message.station_id,
33 message.generation_delta_time,
34 now()
35 );
36 }
37 Message::DENM(message) => {
38 // log to monitoring platform
39 println!(
40 "{} {} {} {} {}/{}/{}/{}/{}{} at {}",
41 component,
42 exchange.type_field,
43 direction,
44 partner,
45 message.station_id,
46 message
47 .management_container
48 .action_id
49 .originating_station_id,
50 message.management_container.action_id.sequence_number,
51 message.management_container.reference_time,
52 message.management_container.detection_time,
53 get_cause_str(cause),
54 now()
55 );
56 }
57 Message::CPM(message) => {
58 // log to monitoring platform
59 println!(
60 "{} {} {} {} {}/{} at {}",
61 component,
62 exchange.type_field,
63 direction,
64 partner,
65 message.station_id,
66 message.generation_delta_time,
67 now()
68 );
69 }
70 };
71}
72
73fn get_cause_str(cause: Option<Cause>) -> String {
74 return match cause {
75 Some(cause) => format!("/cause_type:{}/cause_id:{}", cause.m_type, cause.id),
76 None => String::new(),
77 };
78}