Dust Networks Inc. M1030 사용자 설명서

다운로드
페이지 28
Interfaces
22
D
UST
 N
ETWORKS
M1030-2 M
OTE
 D
ATASHEET
C
ONFIDENTIAL
7.4.5
HDLC Packet Processing Examples
Example 1: Constructing an HDLC packet to send to the mote
This example demonstrates how to construct an HDLC packet to set the network ID value to 00 7D. (All values are in 
hexadecimal.)
Step 1
Define HDLC packet payload:
Command type 
=> 87
Parameter => 
01
Network ID
=> 00 7D
Note that the additional control bytes do not count against the 80-byte payload limit.
Step 2
Calculate FCS:
Calculate the FCS using FCS-16 algorithm (RFC 1662) on the hexadecimal sequence '87 01 00 7D'.
 
The FCS (including 1's complement) is 74 2F.
Append FCS to payload, FCS is sent least significant byte first (RFC 1662):
Step 3
Perform byte stuffing.
To perform byte stuffing, check the HDLC Packet Payload and FCS for instances of “7D” or “7E” and replace as 
follows:
7D => 7D 5D
7E => 7D 5E
Note that the additional control bytes do not count against the 80-byte payload limit.
Step 4
Add start and stop delimiters.
Enclose the above in start/stop flags (RFC 1662).
Or simply, the hexadecimal sequence:
7E 87 01 00 7D 5D 2F 74 7E
Example 2: Decoding an HDLC packet received from the mote
To understand how to decode an HDLC packet sent from the mote, let’s assume that the mote received a Get 
command with a parameter of mote information (see section 7.4.4.7), and replied with the following HDLC Packet. 
(All values are in hexadecimal.)
Step 1
(HDLC layer) strip off delimiters.
HDLC Packet Payload
Command Type
Message Content
87
01 00 7D
HDLC Packet Payload
FCS
87 01 00 7D
2F 74
HDLC Packet Payload (stuffed)
FCS (stuffed)
87 01 00 7D 5D
2F 74
Start Delimiter
HDLC Packet Payload (stuffed)
FCS (stuffed)
Stop Delimiter
7E
87 01 00 7D 5D
2F 74
7E
Start Byte
HDLC Packet Payload (stuffed)
FCS (stuffed)
Stop Byte
7E
8A 07 00 20 00 00 5B 00 01 01 06 00 3C 00 00 00 00 00 00 
7D 5E C3 01 00 08 30 30 30 5F 45 56 30 31 00 13 00 00
40 E8
7E
HDLC Packet Payload (stuffed)
FCS (stuffed)
8A 07 00 20 00 00 5B 00 01 01 06 00 3C 00 00 00 00 00 00 
7D 5E C3 01 00 08 30 30 30 5F 45 56 30 31 00 13 00 00
40 E8