Skip to main content

rsiot/components_config/i2c_master/
fieldbus_request.rs

1use std::time::Instant;
2
3use crate::components_config::master_device::RequestResponseBound;
4
5use super::Operation;
6
7// ANCHOR: FieldbusRequest
8/// Структура отдельного запроса на коммуникацию по шине I2C
9#[derive(Clone, Debug)]
10pub struct FieldbusRequest {
11    /// Время создания запроса.
12    ///
13    /// Можно контролировать время выполнения запросов
14    pub request_creation_time: Instant,
15
16    /// Адрес устройства
17    pub address: u8,
18
19    /// Вид запроса.
20    ///
21    /// Необходим для правильной расшифровки ответа
22    pub request_kind: u8,
23
24    /// Массив операций
25    pub operations: Vec<Operation>,
26}
27// ANCHOR: FieldbusRequest
28
29impl FieldbusRequest {
30    /// Создание запроса. Адрес задается позже
31    pub fn new(address: u8, request_kind: impl Into<u8>, operations: Vec<Operation>) -> Self {
32        Self {
33            request_creation_time: Instant::now(),
34            address,
35            request_kind: request_kind.into(),
36            operations,
37        }
38    }
39}
40
41impl RequestResponseBound for FieldbusRequest {}