You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.cpp 1.6 kB

2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <iostream> /**< std::cout std::cerr std::endl */
  2. #include <string> /**< std::string */
  3. #include <memory> /**< std::shared_ptr */
  4. #include "dbcc/signal_delegate.h"
  5. #include "dbcc/dbc_iterator.h"
  6. #include "dbcc/signal_processor.h"
  7. const std::string usage = "This parser is meant to be used via CLi at the moment\n"
  8. "\t./parser <FILE>\n";
  9. class MyDelegate : public ad::dbcc::SignalDecodeDelegate
  10. {
  11. virtual void OnDecoded(uint32_t msg_id, const std::string &signal_name, const ad::dbcc::ParsedValue &pv)
  12. {
  13. std::cout << "msg: #0x" << std::hex << msg_id << std::dec << ", " << signal_name << " -> pv: " << pv << std::endl;
  14. }
  15. };
  16. int main(int argc, char *argv[])
  17. {
  18. if (argc < 2)
  19. {
  20. std::cout << usage << std::endl;
  21. return 0;
  22. }
  23. ad::dbcc::DbcIterator iter(argv[1]);
  24. for (auto msg : iter)
  25. {
  26. std::cout << "msg: " << msg.Name() << std::endl;
  27. }
  28. std::shared_ptr<ad::dbcc::SignalDecodeDelegate> delegate = std::make_shared<MyDelegate>();
  29. uint8_t data[8] = { 0 };
  30. data[0] = 0x01;
  31. data[1] = 0xA8;
  32. uint8_t data1[2] = { 0x40, 0x0 };
  33. ad::dbcc::SignalProcessor sp(iter);
  34. sp.RegisterDelegate(578, "ACCAccReqValHSC2", delegate);
  35. sp.RegisterDelegate(498, "SysBPMHSC2", delegate);
  36. sp.RegisterDelegate(498, "SysBPMEnbdHSC2", delegate);
  37. sp.DecodeMessage(578, data, 8);
  38. sp.DecodeMessage(498, data1, 2);
  39. std::cout << "Keep the order stable" << std::endl;
  40. for (auto msg : iter)
  41. {
  42. std::cout << "msg: " << msg.Name() << std::endl;
  43. }
  44. // Unpacked value: -5.1
  45. return 0;
  46. }