optical/NxFuncs/comm/ocom.h
2025-09-04 09:45:08 +08:00

124 lines
2.5 KiB
C

#ifndef __OCOM_H__
#define __OCOM_H__
#include "config.h"
//------------------------------------------------------------------------
// 通讯数据包定义
//------------------------------------
/*
一、数据包格式
1. 固定长度数据包格式
|-------------------------------------------------------------------|-----------|
| 数据识别序列 | 命令 | 数据内容 | 校验字 |
|-------------------------------------------------------------------|-----------|
| B0 B1 B2 | B3 | B4 B5 B6 B7 B8 B9 B10 B11 B12 B13 | B14 B15 |
|-------------------------------------------------------------------|-----------|
| 固定序列如下 | | 参数,不同命令定义不同 | B4--B13的 |
| | ID | 具体定义参考命令详细说明 |16位和校验 |
| 0xEB,0x90,0xD7| | | |
|-------------------------------------------------------------------|-----------|
*/
//------------------------------------
#define DC_SYNC_LEN 3 // 数据识别序列长度
#define DC_CMD_LEN 1 // 命令长度
#define DC_CONT_LEN 10 // 数据内容长度
#define DC_CHK_LEN 2 // 校验字长度
#define DC_CHECK_LEN (DC_CMD_LEN+DC_CONT_LEN)
#define LEN_OCOM_PKT (DC_SYNC_LEN+DC_CMD_LEN+DC_CONT_LEN+DC_CHK_LEN)
//------------------------------------
#ifdef _IN_OCOM_C
const u8 OCOM_SYNC[DC_SYNC_LEN] =
{
0xEB,
0x90,
0xD7,
};
#else
extern const u8 OCOM_SYNC[DC_SYNC_LEN];
#endif
//------------------------------------
typedef union
{
struct
{
u8 normal[LEN_OCOM_PKT];
} __attribute__ ((packed)) buff; // buff方式
struct
{
u8 sync[DC_SYNC_LEN];
u8 cmd;
u8 content[DC_CONT_LEN];
u16 check;
} __attribute__ ((packed)) normal; // 通用方式
struct
{
u8 sync[DC_SYNC_LEN];
u8 cmd;
u8 toggle;
u8 attr;
s32 ax;
s32 ay;
u16 check;
} __attribute__ ((packed)) offcmd; // 线迹偏移命令
struct
{
u8 sync[DC_SYNC_LEN];
u8 cmd;
u8 toggle;
u16 exlen;
u8 data1[7];
u16 check;
} __attribute__ ((packed)) d21cmd; // D21命令
}OComPacket;
typedef struct
{
int (*SendOComData)(u8 *, int);
int (*GetOComData)(u8 *, int);
int (*GetRsvLen)(void);
int (*GetTrsFreeLen)(void);
void (*Delay)(u32);
}OComExFuns;
//------------------------------------
// 读空缓冲区
void ReadOComBuffEmpty(OComExFuns * funs);
int GetAOComPacket(OComExFuns * funs, OComPacket * pPacket);
int GetOComExData(OComExFuns * funs, u8 * pBuff, int exlen);
int SendAOComPacket(OComExFuns * funs, OComPacket * pPacket);
int SendOComExData(OComExFuns * funs, u8 * pBuff, int exlen);
int PacketAOCom(OComPacket * pPacket);
#define GetAOComNormalPacket GetAOComPacket
#endif