1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::{
    application_protocol::{
        primitives::data_value::{Date, Time},
        unconfirmed::UnconfirmedServiceChoice,
    },
    common::{
        io::Writer,
        tag::{ApplicationTagNumber, Tag, TagNumber},
    },
};

#[derive(Debug, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct TimeSynchronization {
    pub date: Date,
    pub time: Time,
}

impl TimeSynchronization {
    pub fn encode(&self, writer: &mut Writer) {
        writer.push(UnconfirmedServiceChoice::TimeSynchronization as u8);

        // date
        let tag = Tag::new(TagNumber::Application(ApplicationTagNumber::Date), 4);
        tag.encode(writer);
        self.date.encode(writer);

        // time
        let tag = Tag::new(TagNumber::Application(ApplicationTagNumber::Time), 4);
        tag.encode(writer);
        self.time.encode(writer);
    }
}