main.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //#include <QCoreApplication>
  2. #include <thread>
  3. #include <mutex>
  4. #include <iostream>
  5. #include "cyber/cyber.h"
  6. #include "cyber/time/rate.h"
  7. #include "cyber/time/time.h"
  8. #include "adchassis.h"
  9. #include <canmsg.pb.h>
  10. static Adchassis * gpChassis;
  11. static chassisfun gchassisfun;
  12. static std::shared_ptr<apollo::cyber::Writer<iv::chassis>>
  13. chassis_writer_;
  14. static std::shared_ptr<apollo::cyber::Reader<iv::can::canmsg>>
  15. can0recv_reader_;
  16. void RecvCANMsg(const std::shared_ptr<iv::can::canmsg> &xmsg)
  17. {
  18. gpChassis->ProcCANMsg(*xmsg);
  19. }
  20. void ChassisCallBack(iv::chassis * pchassis)
  21. {
  22. iv::chassis* raw_ptr = new iv::chassis();
  23. std::shared_ptr<iv::chassis> chassis_ptr(raw_ptr);
  24. chassis_writer_->Write(chassis_ptr);
  25. }
  26. int main(int argc, char *argv[])
  27. {
  28. // QCoreApplication a(argc, argv);
  29. apollo::cyber::Init("apollochassis");
  30. std::unique_ptr<apollo::cyber::Node> pilot_node = apollo::cyber::CreateNode("apollochassis");
  31. gchassisfun = std::bind(&ChassisCallBack,std::placeholders::_1);
  32. chassis_writer_ = pilot_node->CreateWriter<iv::chassis>("/adc/chassis");
  33. can0recv_reader_ = pilot_node->CreateReader<iv::can::canmsg>(
  34. "/adc/canrecv0",
  35. [](const std::shared_ptr<iv::can::canmsg> &xmsg) {
  36. RecvCANMsg(xmsg);
  37. });
  38. std::string strvehtype = std::string("shenlanfd");
  39. gpChassis = new Adchassis(&gchassisfun,strvehtype);
  40. apollo::cyber::WaitForShutdown();
  41. delete gpChassis;
  42. return 0;
  43. }