Struct echonet_lite::ElPacket

source ·
pub struct ElPacket {
    pub seoj: EchonetObject,
    pub deoj: EchonetObject,
    pub esv: ServiceCode,
    pub props: Properties,
    /* private fields */
}
Expand description

An ECHONET Lite packet representation.

ECHONET Lite SPEC shows an ECHONET Lite packet contains

  • EHD1: ECHONET Lite message header1 (1-byte)
  • EHD2: ECHONET Lite message header2 (1-byte)
  • SEOJ: Source ECHONET Lite object specification (3-byte)
  • DEOJ: Destination ECHONET Lite object specification (3-byte)
  • ESV: ECHONET Lite service
  • OPC: Number of processing properties
  • (EPC, PDC, EDT) * OPC

Fields§

§seoj: EchonetObject§deoj: EchonetObject§esv: ServiceCode§props: Properties

Implementations§

source§

impl ElPacket

source

pub fn serialize(&self) -> Result<Vec<u8>, Error>

Serializes an ECHONET Lite packet into byte array.

Examples found in repository?
examples/find.rs (line 22)
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
34
35
36
37
38
39
40
41
fn main() -> io::Result<()> {
    let socket = UdpSocket::bind("0.0.0.0:3610")?;
    socket.set_read_timeout(Some(Duration::from_secs(2)))?;
    socket.set_multicast_loop_v4(true)?;
    socket.join_multicast_v4(&EL_MULTICAST_ADDR, &[0, 0, 0, 0].into())?;

    let packet = el::ElPacketBuilder::new()
        .transaction_id(1)
        .seoj([0x05u8, 0xFFu8, 0x01u8])
        .deoj([0x0Eu8, 0xF0u8, 0x01u8])
        .esv(el::ServiceCode::Get)
        .props(el::props!([0x80, []]))
        .build();
    let bytes = packet.serialize().expect("fail to serialize");

    socket.send_to(&bytes, (EL_MULTICAST_ADDR, 3610))?;
    loop {
        let mut buffer = [0u8; 1024];
        match socket.recv_from(&mut buffer) {
            Err(_) => break,
            Ok((_, src_addr)) => {
                if let Ok((_, response)) = el::ElPacket::from_bytes(&buffer) {
                    if response.is_response_for(&packet) {
                        println!("got response from {src_addr}");
                        println!("{response}");
                    }
                }
            }
        }
    }

    Ok(())
}
source

pub fn from_bytes(bytes: &[u8]) -> Result<(usize, ElPacket), Error>

Deserializes an ECHONET Lite packet from byte array.

Examples found in repository?
examples/find.rs (line 30)
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
34
35
36
37
38
39
40
41
fn main() -> io::Result<()> {
    let socket = UdpSocket::bind("0.0.0.0:3610")?;
    socket.set_read_timeout(Some(Duration::from_secs(2)))?;
    socket.set_multicast_loop_v4(true)?;
    socket.join_multicast_v4(&EL_MULTICAST_ADDR, &[0, 0, 0, 0].into())?;

    let packet = el::ElPacketBuilder::new()
        .transaction_id(1)
        .seoj([0x05u8, 0xFFu8, 0x01u8])
        .deoj([0x0Eu8, 0xF0u8, 0x01u8])
        .esv(el::ServiceCode::Get)
        .props(el::props!([0x80, []]))
        .build();
    let bytes = packet.serialize().expect("fail to serialize");

    socket.send_to(&bytes, (EL_MULTICAST_ADDR, 3610))?;
    loop {
        let mut buffer = [0u8; 1024];
        match socket.recv_from(&mut buffer) {
            Err(_) => break,
            Ok((_, src_addr)) => {
                if let Ok((_, response)) = el::ElPacket::from_bytes(&buffer) {
                    if response.is_response_for(&packet) {
                        println!("got response from {src_addr}");
                        println!("{response}");
                    }
                }
            }
        }
    }

    Ok(())
}
source

pub fn is_response_for(&self, req: &ElPacket) -> bool

Returns whether self is a response for the req.

Examples found in repository?
examples/find.rs (line 31)
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
34
35
36
37
38
39
40
41
fn main() -> io::Result<()> {
    let socket = UdpSocket::bind("0.0.0.0:3610")?;
    socket.set_read_timeout(Some(Duration::from_secs(2)))?;
    socket.set_multicast_loop_v4(true)?;
    socket.join_multicast_v4(&EL_MULTICAST_ADDR, &[0, 0, 0, 0].into())?;

    let packet = el::ElPacketBuilder::new()
        .transaction_id(1)
        .seoj([0x05u8, 0xFFu8, 0x01u8])
        .deoj([0x0Eu8, 0xF0u8, 0x01u8])
        .esv(el::ServiceCode::Get)
        .props(el::props!([0x80, []]))
        .build();
    let bytes = packet.serialize().expect("fail to serialize");

    socket.send_to(&bytes, (EL_MULTICAST_ADDR, 3610))?;
    loop {
        let mut buffer = [0u8; 1024];
        match socket.recv_from(&mut buffer) {
            Err(_) => break,
            Ok((_, src_addr)) => {
                if let Ok((_, response)) = el::ElPacket::from_bytes(&buffer) {
                    if response.is_response_for(&packet) {
                        println!("got response from {src_addr}");
                        println!("{response}");
                    }
                }
            }
        }
    }

    Ok(())
}
source

pub fn create_response(&self, esv: ServiceCode, props: Properties) -> ElPacket

Creates a new response for itself.

esv must be one of response service code. props contains all response properties.

The created response packet has the same transaction ID as original packet. The source and the destination are reversed.

Trait Implementations§

source§

impl Clone for ElPacket

source§

fn clone(&self) -> ElPacket

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ElPacket

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for ElPacket

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for ElPacket

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<ElPacket> for AirConditionerPacket

source§

fn from(value: ElPacket) -> Self

Converts to this type from the input type.
source§

impl From<ElPacket> for ClassPacket

source§

fn from(value: ElPacket) -> Self

Converts to this type from the input type.
source§

impl From<ElPacket> for ControllerPacket

source§

fn from(value: ElPacket) -> Self

Converts to this type from the input type.
source§

impl From<ElPacket> for EvpsPacket

source§

fn from(value: ElPacket) -> Self

Converts to this type from the input type.
source§

impl From<ElPacket> for FuelCellPacket

source§

fn from(value: ElPacket) -> Self

Converts to this type from the input type.
source§

impl From<ElPacket> for GeneralLightingPacket

source§

fn from(value: ElPacket) -> Self

Converts to this type from the input type.
source§

impl From<ElPacket> for HpPacket

source§

fn from(value: ElPacket) -> Self

Converts to this type from the input type.
source§

impl From<ElPacket> for InstantaneousWaterHeaterPacket

source§

fn from(value: ElPacket) -> Self

Converts to this type from the input type.
source§

impl From<ElPacket> for LightingSystemPacket

source§

fn from(value: ElPacket) -> Self

Converts to this type from the input type.
source§

impl From<ElPacket> for MeteringPacket

source§

fn from(value: ElPacket) -> Self

Converts to this type from the input type.
source§

impl From<ElPacket> for MonoFunctionLightingPacket

source§

fn from(value: ElPacket) -> Self

Converts to this type from the input type.
source§

impl From<ElPacket> for ProfilePacket

source§

fn from(value: ElPacket) -> Self

Converts to this type from the input type.
source§

impl From<ElPacket> for SmartMeterPacket

source§

fn from(value: ElPacket) -> Self

Converts to this type from the input type.
source§

impl From<ElPacket> for SolarPowerPacket

source§

fn from(value: ElPacket) -> Self

Converts to this type from the input type.
source§

impl From<ElPacket> for StorageBatteryPacket

source§

fn from(value: ElPacket) -> Self

Converts to this type from the input type.
source§

impl From<ElPacket> for UnimplementedPacket

source§

fn from(value: ElPacket) -> Self

Converts to this type from the input type.
source§

impl PartialEq for ElPacket

source§

fn eq(&self, other: &ElPacket) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for ElPacket

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StructuralPartialEq for ElPacket

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,