semtech_udp/packet/
pull_data.rs

1/*
2### 5.2. PULL_DATA packet ###
3
4That packet type is used by the gateway to poll data from the server.
5
6This data exchange is initialized by the gateway because it might be
7impossible for the server to send packets to the gateway if the gateway is
8behind a NAT.
9
10When the gateway initialize the exchange, the network route towards the
11server will open and will allow for packets to flow both directions.
12The gateway must periodically send PULL_DATA packets to be sure the network
13route stays open for the server to be used at any time.
14
15 Bytes  | Function
16:------:|---------------------------------------------------------------------
17 0      | protocol version = 2
18 1-2    | random token
19 3      | PULL_DATA identifier 0x02
20 4-11   | Gateway unique identifier (MAC address)
21 */
22
23use super::super::simple_up_packet;
24use super::{pull_ack, write_preamble, Identifier, MacAddress, Result, SerializablePacket};
25use std::io::{Cursor, Write};
26
27#[derive(Debug, Clone)]
28pub struct Packet {
29    pub random_token: u16,
30    pub gateway_mac: MacAddress,
31}
32
33impl Default for Packet {
34    fn default() -> Packet {
35        Packet {
36            random_token: 0,
37            gateway_mac: MacAddress::from([0; 8]),
38        }
39    }
40}
41
42simple_up_packet!(Packet, Identifier::PullData);
43
44impl From<Packet> for super::Packet {
45    fn from(packet: Packet) -> super::Packet {
46        super::Packet::Up(super::Up::PullData(packet))
47    }
48}
49
50impl Packet {
51    pub fn new(random_token: u16) -> Packet {
52        Packet {
53            random_token,
54            gateway_mac: MacAddress::from([0; 8]),
55        }
56    }
57
58    pub fn into_ack(self) -> pull_ack::Packet {
59        pull_ack::Packet {
60            random_token: self.random_token,
61        }
62    }
63}