www.pudn.com > sliplib.rar > slipLib.h


/**************************************************************************
Copyright 2002-2007 TGL Ltd. All rights reserved

slipLib.h -- the header file for slipLib

DESCRIPTION


modification history
--------------------
2006-12-29, majun, v1.0 initial version
--------------------

**************************************************************************/
#ifndef __SLIPLIB_H

#define __SLIPLIB_H

#define SLIP_END ( 0xC0 )
#define SLIP_ESC ( 0xDB )
#define SLIP_TRANS_END ( 0xDC )
#define SLIP_TRANS_ESC ( 0xDD )

#define SLIP_WHOLE_DECODE ( 0x00000001 )
#define SLIP_PARTIALLY_DECODE ( 0x00000000 )
#define SLIP_WHOLE_ENCODE ( 0x00000002 )
#define SLIP_PARTIALLY_ENCODE ( 0x00000000 )

enum SLIP_STATUS
{
SLIP_STATUS_NOSTART,
SLIP_STATUS_START,
SLIP_STATUS_TRANS
};

struct SLIP
{
enum SLIP_STATUS enumSlipDecodeStatus;

unsigned char * pucSlipDecodeBuff;
int iSlipDecodeBuffMaxLength;
int iSlipDecodeBuffLength;
unsigned int uiSlipDecodeErrorNo;

unsigned char * pucSlipEncodeBuff;
int iSlipEncodeBuffMaxLength;
int iSlipEncodeBuffLength;

unsigned int uiOption;
int ( * pfDecodeCallBack )( unsigned char * pucUnpackedBuff, int iUnpackedBuffLength );
int ( * pfEncodeCallBack )( unsigned char * pucPackedBuff, int iPackedBuffLength );
};

typedef struct SLIP * SLIP_ID;

SLIP_ID slipCreate( const int iMaxBytes, const unsigned int uiOption,
int ( * pfDecodeCallBack )( ), int ( * pfEncodeCallBack )( ) );
unsigned int slipDecodeErrorGet( SLIP_ID strSlipId );
unsigned int slipDecodeErrorSet( SLIP_ID strSlipId, unsigned int uiErrorNo );
int slipDelete( SLIP_ID strSlipId );
int slipDecode( SLIP_ID strSlipId, const unsigned char * pucPackedBuff, const int iPackedBuffLength );
int slipPacketEncode( SLIP_ID strSlipId, const unsigned char * pucUnpackedBuff, const int iUnpackedBuffLength );
int slipEncodeBegin( SLIP_ID strSlipId );
int slipEncode( SLIP_ID strSlipId, const unsigned char * pucUnpackedBuff, const int iUnpackedBuffLength );
int slipEncodeEnd( SLIP_ID strSlipId );

#endif