rsiot/components_config/uart_general/fieldbus_request.rs
1use std::{fmt::Debug, time::Instant};
2
3use crate::components_config::master_device::RequestResponseBound;
4
5// ANCHOR: FieldbusRequest
6/// Структура отдельного запроса на коммуникацию по шине UART
7#[derive(Clone, Debug)]
8pub struct FieldbusRequest {
9 /// Время создания запроса.
10 ///
11 /// Можно контролировать время выполнения запросов
12 pub request_creation_time: Instant,
13
14 /// Вид запроса.
15 ///
16 /// Необходим для правильной расшифровки ответа
17 pub request_kind: u8,
18
19 /// Данные для передачи по uart
20 pub packet: Vec<u8>,
21}
22// ANCHOR: FieldbusRequest
23
24impl FieldbusRequest {
25 /// Создание запроса
26 pub fn new(request_kind: impl Into<u8>, packet: Vec<u8>) -> Self {
27 Self {
28 request_creation_time: Instant::now(),
29 request_kind: request_kind.into(),
30 packet,
31 }
32 }
33
34 // /// Восстановить запрос из буфера передачи по сети
35 // pub fn from_read_buffer(read_buf: &[u8]) -> Self {
36 // Self {
37 // request_creation_time: Instant::now(),
38 // packet: read_buf.to_vec(),
39 // }
40 // }
41
42 // /// Подготовить запрос для передачи по сети
43 // pub fn to_write_buffer(self) -> Vec<u8> {
44 // self.packet
45 // }
46}
47
48impl RequestResponseBound for FieldbusRequest {}