/*********************************************************************************
|
* 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;
|
}
|