www.pudn.com > linuxcchuankou.rar > comm.h


#ifndef _COMM_H__
#define _COMM_H__

#ifdef FN_SWITCHAUDIO

#include "fn_protocol.h"

typedef struct 
{
	BYTE	Header;
	WORD	Version;
	WORD	Addr;
	WORD	CID1;
	WORD	CID2;
	WORD	Length1;
	WORD	Length2;
}STRUCTPACKED SWITCHPACKINFO;		//交换数据信息包

typedef struct 
{
	BYTE	Header;
	WORD	Version;
	WORD	Addr;
	WORD	CID1;
	WORD	CID2;
	WORD	Return;
	WORD	Length1;
	WORD	Length2;
}STRUCTPACKED SWITCHRETURNPACKINFO;		//交换返回信息包

typedef struct 
{
	WORD	Length:12;
	WORD	ChkSum:4;	
}STRUCTPACKED LENGTHANDCHKINFO;				//包长与校验和

typedef struct 
{
	WORD	Length1:4;
	WORD	Length2:4;
	WORD	Length3:4;
	WORD	ChkSum:4;	
}STRUCTPACKED OTHERLENGTHANDCHKINFO;		//其他长度与校验和

typedef union
{
	WORD					wLengthAndChk;
	LENGTHANDCHKINFO		LengthChkInfo;
	OTHERLENGTHANDCHKINFO	OthLengthChkInfo;
}STRUCTPACKED ULENGTHCHKINFO;						

typedef union
{
	float	fVal;
	DWORD	dwVal;
}STRUCTPACKED UFLOATVALINFO;

typedef struct 
{
	WORD	wVal1;
	WORD	wVal2;
	WORD	wVal3;
	WORD	wVal4;
}STRUCTPACKED FOURVALINFO;

typedef struct 
{
    WORD    SingleFlag;
    WORD    AudioInfo;
}STRUCTPACKED SWITCHAUDIOINFO;

#endif

class comm
{
private:
#ifdef FN_SWITCHAUDIO
    class PROTOCOL *m_pProtocol;
#endif
	char	*m_pSendBuff;									//发送缓冲区
protected:
	bool	bOpenDevFlag;									//串口打开标志
	int   set_speed(int speed);				//设置速率
	int		set_parity(int databits,int stopbits,char parity);			//设置校验

public:
#ifdef FN_SWITCHAUDIO
  BYTE	*m_pReadBuf;			//接受缓冲区
	DWORD	m_dwBufSize;				//缓冲大小
	DWORD	m_dwFrameLen;				//帧长度

  int		SetQueueSize(DWORD	dwSize);			//设置栈大小
	int		OnReadData(const BYTE *pReadBuf,int iLen);			//度数据函数
	int		HexStrtoAsc(char * Hexstr,BYTE *bRtByte);				//16进制转ASC
	int		OnValidateGetCmds(SWITCHRETURNPACKINFO *pFrameHead,WORD wFrameLen);			//
	int		CheckFrame(BYTE *pFrame);			//校验帧
	void	PrintMemBufInfo(BYTE *pBuf,int iLen);		//打印内存缓冲信息
	WORD	HexToAsc(BYTE bAsc);		
	int		FillChkFrame(BYTE *pFrame,int FrameLen);			//
	void	SetProtocolThread(class PROTOCOL *pProtocol);		//设置协议线程
  int     SendAudioBroadcast();		//发送音频广播
  int     SendSwitchAudio(bool SingleSwitch,unsigned char AudioPort);			//发送开关广播
#endif
public:
  int		m_fd;

	comm(int port,char *conf,int databits=8,int stopbits=1,char parity='N');
	~comm();

	bool Open();
	void Close();
	int		Read(char *buf,int len);			//接收函数
	int		Send(char *buf,int len);			//发送函数
	int     Getfd();		//获取设备
};
#endif

/////////////////////////////////////////////////////////////////////////////