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.
83 lines
2.4 KiB
83 lines
2.4 KiB
#include <stdio.h>
|
|
|
|
#include "zlinuxcomponents/zmainhelper.hpp"
|
|
//
|
|
#include "iflytopcpp/core/spdlogfactory/logger.hpp"
|
|
#include "iflytopcpp/core/thread/thread.hpp"
|
|
#include "spdlog/spdlog.h"
|
|
//
|
|
|
|
#include <linux/can.h>
|
|
#include <linux/can/raw.h>
|
|
#include <net/if.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/ioctl.h>
|
|
#include <sys/socket.h>
|
|
#include <unistd.h>
|
|
|
|
#include "iflytopcpp/core/driver/socketcan/socket_can.hpp"
|
|
|
|
using namespace iflytop;
|
|
using namespace core;
|
|
using namespace std;
|
|
using namespace clipp;
|
|
|
|
// using sockcanpp::CanDriver;
|
|
// using sockcanpp::CanId;
|
|
// using sockcanpp::CanMessage;
|
|
// using sockcanpp::exceptions::CanException;
|
|
// using sockcanpp::exceptions::CanInitException;
|
|
// using sockcanpp::exceptions::InvalidSocketException;
|
|
|
|
/***********************************************************************/
|
|
/***********************************************************************/
|
|
/***********************************************************************/
|
|
/***********************************************************************/
|
|
class Main {
|
|
ENABLE_LOGGER(Main);
|
|
unique_ptr<Thread> thread;
|
|
|
|
shared_ptr<SocketCan> socketCan;
|
|
|
|
public:
|
|
Main(/* args */) {}
|
|
~Main() {}
|
|
void run(int argc, char* argv[]) {
|
|
thread.reset(new Thread("main", [&]() { exit(main(argc, argv)); }));
|
|
while (true) sleep(1000);
|
|
}
|
|
void onSIGINT() { exit(0); }
|
|
int main(int argCount, char* argValues[]) {
|
|
socketCan.reset(new SocketCan());
|
|
shared_ptr<SocketCanConfig> socketCanConfig = make_shared<SocketCanConfig>();
|
|
socketCanConfig->m_canName = "can0";
|
|
socketCanConfig->m_canBaudrate = 500000;
|
|
socketCanConfig->enablLoopback = false;
|
|
|
|
socketCan->initialize(socketCanConfig);
|
|
socketCan->startListen();
|
|
|
|
socketCan->onSocketCanFrame.connect([this](shared_ptr<SocketCanFrame> frame) { logger->info("RX:{}", frame->toString()); });
|
|
|
|
ThisThread thisThread;
|
|
int i = 0;
|
|
while (!thisThread.getExitFlag()) {
|
|
uint8_t data[8] = {1, 2, 3, 4, 5, 6, 7, 8};
|
|
shared_ptr<SocketCanFrame> canframe = SocketCanFrame::createExtDataFrame(0x11223344, data, 8);
|
|
logger->info("TX Frame {}", i);
|
|
socketCan->sendFrame(canframe, 5);
|
|
i++;
|
|
}
|
|
while (true) {
|
|
sleep(1000);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
};
|
|
MAIN_ENTRY();
|
|
// ip link set can0 down
|
|
// ip link set can0 type can bitrate 500000
|
|
// ip link set can0 up
|