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.
85 lines
3.7 KiB
85 lines
3.7 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; \
|
|
static_assert(sizeof(*ack) < sizeof(m_txbuf), "ack size too large"); \
|
|
auto __attribute__((unused)) cmdheader = rxcmd->get_cmdheader(); \
|
|
uint32_t errorcode = 0; \
|
|
if (cmd->id == varid) { \
|
|
|
|
#define PROCESS_REPORT(type) \
|
|
zlock_guard l(m_lock); \
|
|
auto* report = (type##_report_t*)m_txbuf; \
|
|
static_assert(sizeof(*report) < sizeof(m_txbuf), "report size too large"); \
|
|
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(), m_id, 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,
|
|
kpt_report = 4,
|
|
} PacketType_t;
|
|
|
|
#define CMDID(cmdid, subcmdid) ((cmdid << 8) + subcmdid)
|
|
#define SUBCMDID(cmdid) (cmdid & 0xff)
|
|
#define MODULE_CMDID(cmdid) (cmdid >> 8)
|
|
|
|
} // namespace zcr
|
|
} // namespace iflytop
|