matc/clusters/codec/
ota_provider.rs

1//! Generated Matter TLV encoders and decoders for OTA Software Update Provider Cluster
2//! Cluster ID: 0x0029
3//! 
4//! This file is automatically generated from OTAProvider.xml
5
6use crate::tlv;
7use anyhow;
8
9
10// Command encoders
11
12/// Encode QueryImage command (0x00)
13pub fn encode_query_image(vendor_id: u16, product_id: u16, software_version: u32, protocols_supported: Vec<u8>, hardware_version: u16, location: String, requestor_can_consent: bool, metadata_for_provider: Vec<u8>) -> anyhow::Result<Vec<u8>> {
14    let tlv = tlv::TlvItemEnc {
15        tag: 0,
16        value: tlv::TlvItemValueEnc::StructInvisible(vec![
17        (0, tlv::TlvItemValueEnc::UInt16(vendor_id)).into(),
18        (1, tlv::TlvItemValueEnc::UInt16(product_id)).into(),
19        (2, tlv::TlvItemValueEnc::UInt32(software_version)).into(),
20        (3, tlv::TlvItemValueEnc::StructAnon(protocols_supported.into_iter().map(|v| (0, tlv::TlvItemValueEnc::UInt8(v)).into()).collect())).into(),
21        (4, tlv::TlvItemValueEnc::UInt16(hardware_version)).into(),
22        (5, tlv::TlvItemValueEnc::String(location)).into(),
23        (6, tlv::TlvItemValueEnc::Bool(requestor_can_consent)).into(),
24        (7, tlv::TlvItemValueEnc::OctetString(metadata_for_provider)).into(),
25        ]),
26    };
27    Ok(tlv.encode()?)
28}
29
30/// Encode ApplyUpdateRequest command (0x02)
31pub fn encode_apply_update_request(update_token: Vec<u8>, new_version: u32) -> anyhow::Result<Vec<u8>> {
32    let tlv = tlv::TlvItemEnc {
33        tag: 0,
34        value: tlv::TlvItemValueEnc::StructInvisible(vec![
35        (0, tlv::TlvItemValueEnc::OctetString(update_token)).into(),
36        (1, tlv::TlvItemValueEnc::UInt32(new_version)).into(),
37        ]),
38    };
39    Ok(tlv.encode()?)
40}
41
42/// Encode NotifyUpdateApplied command (0x04)
43pub fn encode_notify_update_applied(update_token: Vec<u8>, software_version: u32) -> anyhow::Result<Vec<u8>> {
44    let tlv = tlv::TlvItemEnc {
45        tag: 0,
46        value: tlv::TlvItemValueEnc::StructInvisible(vec![
47        (0, tlv::TlvItemValueEnc::OctetString(update_token)).into(),
48        (1, tlv::TlvItemValueEnc::UInt32(software_version)).into(),
49        ]),
50    };
51    Ok(tlv.encode()?)
52}
53