You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.4 KiB

#pragma once
#include <stdint.h>
#define ZPACKET_STRUCT(ordername, type, ...) \
typedef struct { \
__VA_ARGS__ \
} ordername##_##type##_t
#define ZPACKET_CMD_ACK(ordername, cmdpara, ackpara) \
typedef struct { \
cmdpara \
} ordername##_##cmd##_t; \
typedef struct { \
ackpara \
} ordername##_##ack##_t
#define ZPACKET_CMD_ACK_AND_REPORT(ordername, cmdpara, ackpara, reportpara) \
typedef struct { \
cmdpara \
} ordername##_##cmd##_t; \
typedef struct { \
ackpara \
} ordername##_##ack##_t; \
typedef struct { \
reportpara \
} ordername##_##report##_t
#define PROCESS_PACKET(ordername, varid) \
if (rxcmd->iscmd(ordername)) { \
auto* cmd = rxcmd->get_data_as<ordername##_##cmd##_t>(); \
auto* ack = (ordername##_##ack##_t*)m_txbuf; \
auto cmdheader = rxcmd->get_cmdheader(); \
uint32_t errorcode = 0; \
if (cmd->id == varid) { \
ack->id = cmd->id;
#define END_PROCESS_PACKET() \
if (errorcode == 0) { \
m_cancmder->sendAck(rxcmd->get_cmdheader(), m_txbuf, sizeof(*ack)); \
} else { \
m_cancmder->sendErrorAck(rxcmd->get_cmdheader(), errorcode); \
} \
} \
return; \
}
#define CMD(x) x
#define ACK(x) x
#define REPORT(x) x
namespace iflytop {
namespace zcr {
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
typedef float f32;
typedef double f64;
#pragma pack(push, 1)
typedef struct {
uint16_t packetindex;
uint16_t cmdid;
uint8_t subcmdid;
uint8_t packetType;
uint8_t data[];
} Cmdheader_t;
#pragma pack(pop)
typedef enum {
kpt_cmd = 0,
kpt_ack = 1,
kpt_error_ack = 2,
kpt_cmd_exec_status_report = 3,
} PacketType_t;
typedef enum {
kset_cmd_type_read = 0,
kset_cmd_type_set = 1,
} SetCmdOperationType_t;
typedef enum {
kMotorStopType_stop = 0,
kMotorStopType_break = 1,
} MotorStopType_t;
#define CMDID(cmdid, subcmdid) ((cmdid << 8) + subcmdid)
typedef enum {
kmodule_statu_idle,
kmodule_statu_work,
kmodule_statu_exception,
} module_statu_type_t;
} // namespace zcr
} // namespace iflytop