📄 pcsyn_protocol.h
字号:
/*
+-------------------------------------------------------------------+
| PROJECT: PC Synchronization
| $Workfile: pcsyn_protocol.h
| $Author: Talcon Hu
| CREATED: 18.05.2004
+-------------------------------------------------------------------+
*/
#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,L1 trace
//定义帧号的起始和末尾
#define PC_FRAME_MIN 0x11
#define PC_FRAME_MAX 0xe0
//defien falg for pc_interface
#define PC_IF_FLAGS_DATAUL 0x01
#define PC_IF_FLAGS_CMD 0x02
#define PC_IF_FLAGS_DATADL 0x10
//一个包最小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_WAITDISCONNECT//wsit disconect
}PC_CNNT_STATUS;
/***********************************
定义错误代码
<0x80: protocol error
>=0x80: application error
*************************/
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_DefaultError = 0x82,//默认失败
App_Error_ReadError = 0x83,//说明读取失败
App_Error_WriteError ,//说明写失败
App_Error_DeleteError ,//说明删除失败
App_Error_CopyError ,//说明复制失败
App_Error_InfoError ,//说明获取信息失败
App_Error_SendError, //发送短消息失败
App_Error_StoreError, //存储短消息失败
PC_Error_MMINotAllow = 0x90,//手机不允许pc同步, 要先进入菜单工具箱->pc同步
PC_Error_MMINeedPause,//有电话进来,需要暂停
PC_Error_MemoryAlloc,/*内存分配失败,不能操作*/
App_Error_ModifyError, //更改短消息失败
}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;
typedef struct
{
unsigned int flag;
BYTE *pdata_cmd;
unsigned int size_cmd;
BYTE *pdata_ulbuff;
unsigned int size_ulbuff;
BYTE *pdata_dlbuff;
unsigned int size_dlbuff;
unsigned int status;//返回值
}PC_Interface_Info;
/*
*flag:
0x01: write data to target
0x02: transfer cmd to target
*/
int handle_inbuffer(BYTE *buff_in,unsigned short size_buff_in);
int pc_writebystatus(int status);
//zkc add 07/22/04
int pc_writebyinfo(unsigned int status);
unsigned int pc_interface(PC_Interface_Info * info);
extern unsigned long SER_tr_WriteNBytes (int serial_data_flow,
BYTE *buffer,
unsigned long chars_to_write);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -