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.
80 lines
3.2 KiB
80 lines
3.2 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(); \
|
|
uint16_t errorcode = 0; \
|
|
if (cmd->id == varid) { \
|
|
|
|
#define PROCESS_REPORT(type) \
|
|
osDelay(5); \
|
|
type##_report_t report = {0}; \
|
|
ZLOGI(TAG, #type " exec_status:%d", status); \
|
|
report.exec_status = status; \
|
|
m_cancmder->sendExecStatusReport(cmdheader, (uint8_t*)&report, sizeof(report));
|
|
|
|
#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 END_PP END_PROCESS_PACKET
|
|
#define CMD(x) x
|
|
#define ACK(x) x
|
|
#define REPORT(x) x
|
|
namespace iflytop {
|
|
namespace zcr {
|
|
|
|
#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;
|
|
|
|
#define CMDID(cmdid, subcmdid) ((cmdid << 8) + subcmdid)
|
|
|
|
} // namespace zcr
|
|
} // namespace iflytop
|