2023-02-01 14:52:54 -06:00
|
|
|
#include "communication_cmd_handle.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "hal_chipid.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "hal_dma.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "hal_trace.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "plat_types.h"
|
|
|
|
#include "stdbool.h"
|
|
|
|
#include "stdint.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "string.h"
|
|
|
|
|
|
|
|
static bool communication_cmd_inited = false;
|
|
|
|
static int (*send_reply_cb)(const unsigned char *, unsigned int);
|
|
|
|
|
|
|
|
extern "C" int extend_cmd_pmu_open(void);
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
int communication_cmd_init(int (*cb)(const unsigned char *, unsigned int)) {
|
|
|
|
if (!communication_cmd_inited) {
|
|
|
|
send_reply_cb = cb;
|
|
|
|
communication_cmd_inited = true;
|
|
|
|
}
|
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
int communication_cmd_send_reply(const unsigned char *payload,
|
|
|
|
unsigned int len) {
|
|
|
|
return send_reply_cb(payload, len);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
enum ERR_CODE communication_cmd_check_msg_hdr(struct message_t *msg) {
|
|
|
|
return ERR_NONE;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void FloatToByte(float floatNum, unsigned char *byteArry) {
|
|
|
|
char *pchar = (char *)&floatNum;
|
|
|
|
for (u32 i = 0; i < sizeof(float); i++) {
|
|
|
|
*byteArry = *pchar;
|
|
|
|
pchar++;
|
|
|
|
byteArry++;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
enum ERR_CODE communication_cmd_handle_cmd(enum COMMUNICATION_CMD_TYPE cmd,
|
|
|
|
unsigned char *param,
|
|
|
|
unsigned int len) {
|
|
|
|
enum ERR_CODE nRet = ERR_NONE;
|
|
|
|
// uint8_t cret[5]={0x01,0x02,0x03,0x04,0x05};
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
// cret[0] = ERR_NONE;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
TRACE(1, "###communication_cmd_handle_cmd,len=%d", len);
|
|
|
|
switch (cmd) {
|
|
|
|
case COMMUNICATION_CMD_EQ_OP: {
|
|
|
|
#ifdef __PC_CMD_UART__
|
|
|
|
// DUMP8("%02x ",param,len);
|
|
|
|
communication_cmd_send_reply(param, len);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
} break;
|
|
|
|
case COMMUNICATION_CMD_DRC_OP: {
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
} break;
|
|
|
|
case COMMUNICATION_CMD_HF_OP: {
|
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
TRACE(1, "Invalid command: 0x%x", cmd);
|
|
|
|
nRet = ERR_INTERNAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// communication_cmd_send_reply(cret,10);
|
|
|
|
return nRet;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|