fixed function duplicated def issue

This commit is contained in:
Ruixiang Du
2021-07-09 22:24:46 +08:00
parent 41f598c65c
commit 6a8073e90c
8 changed files with 43 additions and 17 deletions

View File

@@ -0,0 +1,26 @@
/*
* hunter_protocol_v1_parser.hpp
*
* Created on: Jul 09, 2021 22:20
* Description:
*
* Copyright (c) 2021 Ruixiang Du (rdu)
*/
#ifndef HUNTER_PROTOCOL_V1_PARSER_HPP
#define HUNTER_PROTOCOL_V1_PARSER_HPP
#include "ugv_sdk/details/interface/parser_interface.hpp"
namespace westonrobot {
class HunterProtocolV1Parser : public ParserInterface {
public:
bool DecodeMessage(const struct can_frame *rx_frame,
AgxMessage *msg) override;
void EncodeMessage(const AgxMessage *msg,
struct can_frame *tx_frame) override;
uint8_t CalculateChecksum(uint16_t id, uint8_t *data, uint8_t dlc) override;
};
} // namespace westonrobot
#endif /* HUNTER_PROTOCOL_V1_PARSER_HPP */

View File

@@ -53,7 +53,7 @@ RangerState RangerBase::GetRangerState() {
void RangerBase::ParseCANFrame(can_frame *rx_frame) {
AgxMessage status_msg;
DecodeCanFrame(rx_frame, &status_msg);
DecodeCanFrameV2(rx_frame, &status_msg);
std::lock_guard<std::mutex> guard(state_mutex_);
UpdateRangerState(status_msg, ranger_state_);
}

View File

@@ -42,7 +42,7 @@ TracerState TracerBaseV2::GetTracerState() {
void TracerBaseV2::ParseCANFrame(can_frame *rx_frame) {
AgxMessage status_msg;
DecodeCanFrame(rx_frame, &status_msg);
DecodeCanFrameV2(rx_frame, &status_msg);
std::lock_guard<std::mutex> guard(state_mutex_);
UpdateTracerState(status_msg, tracer_state_);
}

View File

@@ -13,6 +13,6 @@
#include "stdio.h"
#include "string.h"
bool DecodeCanFrame(const struct can_frame *rx_frame, AgxMessageV1 *msg) {}
void EncodeCanFrame(const AgxMessageV1 *msg, struct can_frame *tx_frame) {}
uint8_t CalcCanFrameChecksum(uint16_t id, uint8_t *data, uint8_t dlc) {}
bool DecodeCanFrameV1(const struct can_frame *rx_frame, AgxMessageV1 *msg) {}
void EncodeCanFrameV1(const AgxMessageV1 *msg, struct can_frame *tx_frame) {}
uint8_t CalcCanFrameChecksumV1(uint16_t id, uint8_t *data, uint8_t dlc) {}

View File

@@ -30,9 +30,9 @@ struct can_frame {
#include "protocol_v1/agilex_message_v1.h"
bool DecodeCanFrame(const struct can_frame *rx_frame, AgxMessageV1 *msg);
void EncodeCanFrame(const AgxMessageV1 *msg, struct can_frame *tx_frame);
uint8_t CalcCanFrameChecksum(uint16_t id, uint8_t *data, uint8_t dlc);
bool DecodeCanFrameV1(const struct can_frame *rx_frame, AgxMessageV1 *msg);
void EncodeCanFrameV1(const AgxMessageV1 *msg, struct can_frame *tx_frame);
uint8_t CalcCanFrameChecksumV1(uint16_t id, uint8_t *data, uint8_t dlc);
#ifdef __cplusplus
}

View File

@@ -13,7 +13,7 @@
#include "stdio.h"
#include "string.h"
bool DecodeCanFrame(const struct can_frame *rx_frame, AgxMessage *msg) {
bool DecodeCanFrameV2(const struct can_frame *rx_frame, AgxMessage *msg) {
msg->type = AgxMsgUnkonwn;
switch (rx_frame->can_id) {
@@ -309,7 +309,7 @@ bool DecodeCanFrame(const struct can_frame *rx_frame, AgxMessage *msg) {
return true;
}
void EncodeCanFrame(const AgxMessage *msg, struct can_frame *tx_frame) {
void EncodeCanFrameV2(const AgxMessage *msg, struct can_frame *tx_frame) {
switch (msg->type) {
/***************** command frame *****************/
case AgxMsgMotionCommand: {
@@ -595,7 +595,7 @@ void EncodeCanFrame(const AgxMessage *msg, struct can_frame *tx_frame) {
}
}
uint8_t CalcCanFrameChecksum(uint16_t id, uint8_t *data, uint8_t dlc) {
uint8_t CalcCanFrameChecksumV2(uint16_t id, uint8_t *data, uint8_t dlc) {
uint8_t checksum = 0x00;
checksum = (uint8_t)(id & 0x00ff) + (uint8_t)(id >> 8) + dlc;
for (int i = 0; i < (dlc - 1); ++i) checksum += data[i];

View File

@@ -30,9 +30,9 @@ struct can_frame {
#include "ugv_sdk/details/interface/agilex_message.h"
bool DecodeCanFrame(const struct can_frame *rx_frame, AgxMessage *msg);
void EncodeCanFrame(const AgxMessage *msg, struct can_frame *tx_frame);
uint8_t CalcCanFrameChecksum(uint16_t id, uint8_t *data, uint8_t dlc);
bool DecodeCanFrameV2(const struct can_frame *rx_frame, AgxMessage *msg);
void EncodeCanFrameV2(const AgxMessage *msg, struct can_frame *tx_frame);
uint8_t CalcCanFrameChecksumV2(uint16_t id, uint8_t *data, uint8_t dlc);
#ifdef __cplusplus
}

View File

@@ -13,16 +13,16 @@
namespace westonrobot {
bool ProtocolV2Parser::DecodeMessage(const struct can_frame *rx_frame,
AgxMessage *msg) {
return DecodeCanFrame(rx_frame, msg);
return DecodeCanFrameV2(rx_frame, msg);
}
void ProtocolV2Parser::EncodeMessage(const AgxMessage *msg,
struct can_frame *tx_frame) {
EncodeCanFrame(msg, tx_frame);
EncodeCanFrameV2(msg, tx_frame);
}
uint8_t ProtocolV2Parser::CalculateChecksum(uint16_t id, uint8_t *data,
uint8_t dlc) {
return CalcCanFrameChecksum(id, data, dlc);
return CalcCanFrameChecksumV2(id, data, dlc);
}
} // namespace westonrobot