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.

message.cpp 1.7 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
2 years ago
2 years ago
11 months ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
11 months ago
2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "dbcc/message.h"
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <limits>
  5. namespace ad {
  6. namespace dbcc {
  7. std::istream& operator>>(std::istream& in, Message& msg)
  8. {
  9. // Parse the message ID.
  10. in >> msg.id_;
  11. // Parse the name of the message
  12. std::string name;
  13. in >> name;
  14. msg.name_ = name.substr(0, name.length() - 1);
  15. // Parse the message length
  16. in >> msg.dlc_;
  17. // Parse the sender
  18. in >> msg.from_;
  19. in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  20. // As long as there is a signal, parse the signal
  21. while (true) {
  22. std::string preamble;
  23. auto pos = in.tellg();
  24. in >> preamble;
  25. // Check if we are actually reading a signal
  26. if (preamble != "SG_") {
  27. if (in.eof()) {
  28. return in;
  29. }
  30. // Revert the stream to the preamble position
  31. in.seekg(pos, std::ios_base::beg);
  32. break;
  33. }
  34. Signal sig;
  35. in >> sig;
  36. if (in) {
  37. msg.AppendSignal(sig);
  38. }
  39. }
  40. in.clear();
  41. return in;
  42. }
  43. std::set<std::string> Message::To() const
  44. {
  45. std::set<std::string> collection;
  46. for (auto sig : signals_) {
  47. auto to_list = sig.To();
  48. collection.insert(to_list.begin(), to_list.end());
  49. }
  50. return collection;
  51. }
  52. std::ostream& operator<<(std::ostream& out, const Message& msg)
  53. {
  54. out << "BU_ " << msg.Id() << " " << msg.Name()
  55. << ": " << msg.Dlc() << " ";
  56. if (!msg.From().empty()) {
  57. out << msg.From();
  58. }
  59. out << "\n";
  60. for (auto& sig : msg.signals_) {
  61. out << " " << sig.ToDbcString() << "\n";
  62. }
  63. return out;
  64. }
  65. } // namespace dbcc
  66. } // namespace ad