From d6cf0a8e8580978f8bd7dbb3965255b96851bb7f Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Wed, 26 Jun 2019 02:09:24 +0800
Subject: [PATCH] update mqttd makefile, remove lwiringPi
---
ch8_tlv/tlv_sample.c | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/ch8_tlv/tlv_sample.c b/ch8_tlv/tlv_sample.c
index 97bf93a..b86184f 100644
--- a/ch8_tlv/tlv_sample.c
+++ b/ch8_tlv/tlv_sample.c
@@ -29,6 +29,7 @@
#define PACK_HEADER 0xFD
+/* Tag definition */
enum
{
TAG_LOGON=1,
@@ -53,6 +54,8 @@
bytes = packtlv_led(buf, sizeof(buf), ON);
+ /* print every byte in the buffer as HEX and corresponding charactor,
+ which is not printable charactor will be instead as '?' */
dump_buf(buf, bytes);
bytes = packtlv_logon(buf, sizeof(buf), "iot@yun");
@@ -68,7 +71,7 @@
unsigned short crc16 = 0;
int pack_len = 0;
int data_len = 0;
- int ofset = 0;
+ int ofset = 0; /* index position for the buf */
if(!buf || !pwd || size<TLV_MIN_SIZE )
{
@@ -84,7 +87,8 @@
buf[ofset] = TAG_LOGON;
ofset += 1;
- /* $pwd too long maybe result buffer overflow, if it's too long then truncate it */
+ /* $pwd too long maybe result buffer overflow, so we need check the buffer
+ * is large enuf or not. If buf size is not enuf we will truncate $pwd string */
if( strlen(pwd) <= size-TLV_FIXED_SIZE )
data_len = strlen(pwd);
else
@@ -99,8 +103,10 @@
memcpy(&buf[ofset], pwd, data_len);
ofset += data_len;
- /* Calc CRC16 value from Packet Head(buf[0])~ Packet Value(buf[ofset]) */
- crc16 = crc_itu_t(IoT_MAGIC_CRC, buf, ofset);
+ /* Calc CRC16 checksum value from Packet Head(buf[0])~ Value(buf[ofset]) */
+ crc16 = crc_itu_t(MAGIC_CRC, buf, ofset);
+
+ /* Append the 2 Bytes CRC16 checksum value into the last two bytes in packet buffer */
ushort_to_bytes(&buf[ofset], crc16);
ofset += 2;
@@ -132,10 +138,10 @@
/* Value */
buf[3] = (OFF==cmd) ? 0x00 : 0x01;
- /* Calc CRC16 value from Packet Head(buf[0])~ Packet Value(buf[3]) */
- crc16 = crc_itu_t(IoT_MAGIC_CRC, buf, 4);
+ /* Calc CRC16 checksum value from Packet Head(buf[0])~ Packet Value(buf[3]) */
+ crc16 = crc_itu_t(MAGIC_CRC, buf, 4);
- /* Append the 2 Bytes CRC16 value into the packet buffer */
+ /* Append the 2 Bytes CRC16 checksum value into the last two bytes in packet buffer */
ushort_to_bytes(&buf[4], crc16);
return pack_len;
@@ -167,6 +173,7 @@
"????????????????"
"????????????????";
+/* print every byte in the buffer as HEX and corresponding charactor, which is not printable charactor will be instead as '?' */
void dump_buf(char *data, int len)
{
int rc;
--
Gitblit v1.9.1