Guo Wenxue
2019-06-27 b64d6ff04401ed85fce543b8e20c8c360fb284f5
1
2
3
4
5
6
7
8
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*********************************************************************************
 *      Copyright:  (C) 2018 LingYun IoT System Studio
 *                  All rights reserved.
 *
 *       Filename:  tlv.c
 *    Description:  This file is TLV(Tag Length Value) protocal head file
 *                 
 *        Version:  1.0.0(2018/10/14)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "2018/10/14 12:13:26"
 *                 
 ********************************************************************************/
 
#include <stdio.h>
#include "tlv.h"
 
void tlv_dump_buf(const char *prompt, char *buf, int size)
    int           i; 
    
    if(!buf) 
               return ;
 
    if(prompt) 
               printf("%s", prompt); 
 
    for(i=0; i<size; i++ )
           {
               printf("0x%02x ", buf[i]);
           } 
    
    printf("\n");
}
 
int tlv_pack_ack(char *buf, int size)
{
    if( !buf )
        return 0;
 
    if(size < 2)
        return 0;
 
    buf[0]=TAG_ACK;  /* tag */
    buf[1]=0;        /*length*/
 
    /*No data here*/
 
    return 2;
}
 
int tlv_pack_nak(char *buf, int size)
{
    if( !buf )
        return 0;
 
    if(size < 2)
        return 0;
 
    buf[0]=TAG_NAK; /* tag */
    buf[1]=0;       /* length*/
 
    /*No data here*/
 
    return 2;
}