2 changed files with 137 additions and 0 deletions
-
72src/iflytop/components/iflytop_cancmd_server/iflytop_cancmd_server.cpp
-
65src/iflytop/components/iflytop_cancmd_server/iflytop_cancmd_server.hpp
@ -0,0 +1,72 @@ |
|||||
|
#include "iflytop_cancmd_server.hpp"
|
||||
|
using namespace std; |
||||
|
using namespace iflytop; |
||||
|
using namespace icps; |
||||
|
|
||||
|
void IflytopCanCmdServer::initialize(string can_if_name, int baudrate, bool enablLoopback) { |
||||
|
// m_iflytopCanProtocolStack.reset(new IflytopCanProtocolStack());
|
||||
|
|
||||
|
m_can_if_name = can_if_name; |
||||
|
m_baudrate = baudrate; |
||||
|
m_enablLoopback = enablLoopback; |
||||
|
resetSocketCan(); |
||||
|
} |
||||
|
void IflytopCanCmdServer::startListen() {} |
||||
|
|
||||
|
void IflytopCanCmdServer::processRx(shared_ptr<SocketCanFrame> frame) { |
||||
|
if (!frame) { |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
if (frame->getCanIdentifier() == socketcan::kextFrame && //
|
||||
|
frame->getFanFrameType() == socketcan::kdataframe) { |
||||
|
processIflytopRxPacket(frame); |
||||
|
} else { |
||||
|
logger->warn("Rx unknown can frame"); |
||||
|
} |
||||
|
} |
||||
|
void IflytopCanCmdServer::processHamiltonCanRxPacket(shared_ptr<SocketCanFrame> frame) { //
|
||||
|
logger->info("Rx Hamilton packet : {}", frame->toString()); |
||||
|
} |
||||
|
void IflytopCanCmdServer::processIflytopRxPacket(shared_ptr<SocketCanFrame> frame) { |
||||
|
// shared_ptr<icps::Packet> icps_packet = m_iflytopCanProtocolStack->parseSocketCanFrame(frame);
|
||||
|
// if (!icps_packet) {
|
||||
|
// logger->error("parseSocketCanFrame fail,{}", frame->toString());
|
||||
|
// return;
|
||||
|
// }
|
||||
|
// onIflytopCanSubDevicePacket(icps_packet);
|
||||
|
} |
||||
|
|
||||
|
void IflytopCanCmdServer::resetSocketCan() { |
||||
|
auto socketCanConfig = make_shared<SocketCanConfig>(); |
||||
|
socketCanConfig->enablLoopback = m_enablLoopback; // 根据 SocketCan::dumpCanDriverInfo() 的输出,确定该标志位是false还是true
|
||||
|
socketCanConfig->m_canName = m_can_if_name; |
||||
|
socketCanConfig->m_canBaudrate = m_baudrate; |
||||
|
socketCanConfig->m_canfilters = {}; |
||||
|
|
||||
|
logger->info("IflytopCanCmdServer::initialize() m_canName:{} {}", socketCanConfig->m_canName, socketCanConfig->m_canBaudrate); |
||||
|
|
||||
|
m_socketCan.reset(new SocketCan()); |
||||
|
m_socketCan->initialize(socketCanConfig); |
||||
|
m_socketCan->startListen(); |
||||
|
m_socketCan->onSocketCanFrame.connect([this](shared_ptr<SocketCanFrame> canframe) { //
|
||||
|
processRx(canframe); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
// SocketCan::SocketCanError_t IflytopCanCmdServer::sendPacketToIflytopCanSubDevice(shared_ptr<icps::Packet> icps_packet, int overtime_ms) {
|
||||
|
// if (m_socketCan->isError()) {
|
||||
|
// logger->error("m_socketCan->isError() exit process");
|
||||
|
// exit(-1);
|
||||
|
// resetSocketCan();
|
||||
|
// }
|
||||
|
|
||||
|
// auto frame = m_iflytopCanProtocolStack->createSocketCanFrame(icps_packet);
|
||||
|
// if (!frame) {
|
||||
|
// logger->error("createSocketCanFrame fail,{}", icps_packet->toString());
|
||||
|
// return SocketCan::kErrorFrameFormat;
|
||||
|
// }
|
||||
|
// logger->debug("tx:{}", frame->toString());
|
||||
|
|
||||
|
// return m_socketCan->sendFrame(frame, overtime_ms);
|
||||
|
// }
|
@ -0,0 +1,65 @@ |
|||||
|
//
|
||||
|
// Created by iflytop
|
||||
|
//
|
||||
|
|
||||
|
#pragma once
|
||||
|
#include <fstream>
|
||||
|
#include <iostream>
|
||||
|
#include <list>
|
||||
|
#include <map>
|
||||
|
#include <memory>
|
||||
|
#include <set>
|
||||
|
#include <sstream>
|
||||
|
#include <string>
|
||||
|
#include <vector>
|
||||
|
|
||||
|
#include "iflytop/core/basic/nlohmann/json.hpp"
|
||||
|
#include "iflytop/core/driver/socketcan/socket_can.hpp"
|
||||
|
#include "iflytop/core/spdlogfactory/logger.hpp"
|
||||
|
#include "zservice_container/zservice_container.hpp"
|
||||
|
|
||||
|
/**
|
||||
|
* @brief |
||||
|
* |
||||
|
* service: IflytopCanCmdServer |
||||
|
* |
||||
|
* 1. 负责监听,分流IflytopSubDevice的CAN消息和哈美顿的CAN消息 |
||||
|
* 2. 负责将CanFrame转换成IflytopCanPacket |
||||
|
*/ |
||||
|
|
||||
|
namespace iflytop { |
||||
|
namespace icps { |
||||
|
using namespace std; |
||||
|
using namespace iflytop; |
||||
|
using namespace core; |
||||
|
using namespace nlohmann; |
||||
|
class IflytopCanCmdServer : public enable_shared_from_this<IflytopCanCmdServer> { |
||||
|
ENABLE_LOGGER(IflytopCanCmdServer); |
||||
|
|
||||
|
shared_ptr<SocketCan> m_socketCan; |
||||
|
|
||||
|
string m_can_if_name; |
||||
|
int m_baudrate; |
||||
|
bool m_enablLoopback; |
||||
|
|
||||
|
public: |
||||
|
// nod::signal<void(shared_ptr<icps::Packet> packet)> onIflytopCanSubDevicePacket;
|
||||
|
|
||||
|
void initialize(string can_if_name, int baudrate, bool enablLoopback); |
||||
|
void startListen(); |
||||
|
|
||||
|
// SocketCan::SocketCanError_t sendPacketToIflytopCanSubDevice(shared_ptr<icps::Packet> icps_packet, int overtime_ms);
|
||||
|
|
||||
|
private: |
||||
|
void processRx(shared_ptr<SocketCanFrame> frame); |
||||
|
// 处理iflytop子设备的CAN消息
|
||||
|
void processIflytopRxPacket(shared_ptr<SocketCanFrame> frame); |
||||
|
// 处理哈美顿的CAN消息
|
||||
|
void processHamiltonCanRxPacket(shared_ptr<SocketCanFrame> frame); |
||||
|
void resetSocketCan(); |
||||
|
|
||||
|
private: |
||||
|
}; |
||||
|
} // namespace icps
|
||||
|
|
||||
|
} // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue