main.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. raw_ptr->CopyFrom(*pchassis);
  24. std::shared_ptr<iv::chassis> chassis_ptr(raw_ptr);
  25. chassis_writer_->Write(chassis_ptr);
  26. }
  27. int main(int argc, char *argv[])
  28. {
  29. // QCoreApplication a(argc, argv);
  30. apollo::cyber::Init("apollochassis");
  31. std::unique_ptr<apollo::cyber::Node> pilot_node = apollo::cyber::CreateNode("apollochassis");
  32. gchassisfun = std::bind(&ChassisCallBack,std::placeholders::_1);
  33. chassis_writer_ = pilot_node->CreateWriter<iv::chassis>("/adc/chassis");
  34. can0recv_reader_ = pilot_node->CreateReader<iv::can::canmsg>(
  35. "/adc/canrecv0",
  36. [](const std::shared_ptr<iv::can::canmsg> &xmsg) {
  37. RecvCANMsg(xmsg);
  38. });
  39. std::string strvehtype = std::string("SHENLAN_CANFD");
  40. gpChassis = new Adchassis(&gchassisfun,strvehtype);
  41. apollo::cyber::WaitForShutdown();
  42. delete gpChassis;
  43. return 0;
  44. }