⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcsyn_protocol.h

📁 是一个手机功能的模拟程序
💻 H
字号:
#ifndef _PCSYN_PROTOCOL_
#define _PCSYN_PROTOCOL_

#define BYTE unsigned char

#define STX 0x02
#define ETX 0x02
#define DLE 0x10
#define HEADER_DL 0x80 //target ->pc
#define HEADER_UL 0x12 //pc->target

//定义帧号的起始和末尾
#define PC_FRAME_MIN 0x11
#define PC_FRAME_MAX 0xe0



//一个包最小size,不包括stx,header,etx
#define PACKET_MINSIZE 3
//一个包最大size,不包括stx,header,etx
#define PACKET_MAXSIZE 50

//定义各个字段的位置
typedef enum
{
	iDL_HEADER 		=	-1,
	iDL_FRAMETYPE 	 ,
	iDL_FRAMEID,
	iDL_STATUS	,		
	iDL_FRAMEIDUL,  		
	iDL_DATASIZE  ,      
	iDL_DATA
};

//定义各个字段的位置
typedef enum
{
	iUL_HEADER 		=	-1,
	iUL_FRAMETYPE ,
	iUL_FRAMEID,
	iUL_DATASIZE,
	iUL_DATA
};

 
typedef enum
{
	PC_FT_Monitor = 0x00,/*0000 0000*/
	PC_FT_Control = 0x40,/*0100 0000*/
	PC_FT_Info     = 0x80 /*1000 0000*/
}PC_FrameType;

/*control frame type*/ 
typedef enum
{
	PC_CF_Connect = 0x00,
	PC_CF_DisConnect,
	PC_CF_Cmd  = 0x11, 
	PC_CF_DataEnd
}PC_CFType;

/*info frame type*/
typedef enum
{
	PC_IF_Data,
	PC_IF_DataAck
}PC_IFType;


/*define status machine of a connect*/
typedef enum
{
	PC_NOCONNECT,//没有连接
	PC_CONNECTED,//连接
	PC_CMDRECV,//收到命令包后等数据包或传送数据包
	PC_DATAUL,//数据包传送
	PC_DATADL,
	PC_DATAULEND,//数据包传送结束
	PC_DATADLEND,//数据包接受结束
	PC_WAITDISCONNECT//wsit disconect
}PC_CNNT_STATUS;

typedef enum
{
	PC_Error_NoError = 0x00,
	PC_Error_CheckSum, //checksumerror
	PC_Error_InvalidPktSize = 0x03,//invalid packed size
	PC_Error_InvalidDataSize ,
	PC_Error_NoConnect,//NO connect
	PC_Error_ConnectExisted,// a connect existed
	PC_Error_InvalidFrameType,
	PC_Error_InvalidFrameid,
	PC_Error_FrameIsReRX = 0x20, //frame 是被重发的
	PC_Error_WaitData,//    用于异步的操作,data不能立即得到
	PC_Error_SerialNoResponse = 0x81,//说明target响应timeout,for example:serial is invalid
	App_Error_ReadError	 = 0x83,//说明读取失败
	App_Error_WriteError ,//说明写失败
	App_Error_DeleteError ,//说明删除失败
	App_Error_CopyError ,//说明复制失败
	App_Error_InfoError ,//说明获取信息失败
	PC_Error_MMINotAllow =  0x90,//手机不允许pc同步, 要先进入菜单工具箱->pc同步
	PC_Error_MMINeedPause,//有电话进来,需要暂停
	
}PC_Error;
	
typedef struct
{
	BYTE stx;
	BYTE etx;
	BYTE dle;
	BYTE header_ul;//pc ->target
	BYTE header_dl;//target->pc
	BYTE frameid;
	BYTE frametype;
	unsigned int status	;//the status machine of connect
							
}PC_Protocol;

//packet of  pc-->target
typedef struct 
{
	BYTE frametype;
	BYTE frameid;
	BYTE datasize;
	BYTE data[128];
}PC_Packet_UL;

//packet of target-->pc
typedef struct 
{
	BYTE frametype;
	BYTE frameid;
	BYTE status;
	BYTE frametype_ul;
	BYTE datasize;
	BYTE data[128];
}PC_Packet_DL;





int  pc_resend();
int  buffer_in_copy(BYTE *buffer,unsigned short size);
int handle_inbuffer();
int pc_writebystatus(int status);

//int pc_interface(PC_Interface_Info * info);
int serial2protocol(BYTE *buffer,int size);
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -