From ef3d95049758f866a7c2c05ca468fa3470ef5604 Mon Sep 17 00:00:00 2001 From: Igor Prilepov Date: Sun, 22 Nov 2026 17:45:40 -0800 Subject: [PATCH] Return all messages containing a signal name --- j1939_parser/j1939_parser.cpp | 1 - j1939_parser/j1939_parser.h | 3 ++- j1939_parser/j1939_parser_test.cpp | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/j1939_parser/j1939_parser.cpp b/j1939_parser/j1939_parser.cpp index 807cf3b..9abc5c5 100644 --- a/j1939_parser/j1939_parser.cpp +++ b/j1939_parser/j1939_parser.cpp @@ -243,7 +243,6 @@ std::set J1939Parser::pgnFor(const std::string & signal, const std::ma for (const auto & it: dbc) { if (it.second.signalByName(signal.c_str())) { result.emplace(it.first); - break; } } return result; diff --git a/j1939_parser/j1939_parser.h b/j1939_parser/j1939_parser.h index 7cc47bb..7c4716b 100644 --- a/j1939_parser/j1939_parser.h +++ b/j1939_parser/j1939_parser.h @@ -97,7 +97,8 @@ class J1939Parser { return setSignalValue(name.c_str(), enum_name); } - // Find all PGNs which may contain the given signal + // Return every database key whose message contains this signal name. + // Matches are by name; an unknown name returns an empty set. static std::set pgnFor(const std::string & signal, const std::map &dbc); }; diff --git a/j1939_parser/j1939_parser_test.cpp b/j1939_parser/j1939_parser_test.cpp index 6d1e2bc..d24e1ad 100644 --- a/j1939_parser/j1939_parser_test.cpp +++ b/j1939_parser/j1939_parser_test.cpp @@ -529,3 +529,11 @@ TEST_F(J1939ParserTest, SetValuesConfigBigEndianTest) { EXPECT_EQ(frame_.buffer_[1], 6); EXPECT_EQ(frame_.buffer_[2], 64); } + +TEST(J1939ParserLookupTest, FindsEveryMessageContainingTheName) { + const SPN shared{"Shared", 0, 8, false, true, 1, 0, 0, 255, {}}; + const std::map dbc{{100, {"First", 1, {shared}}}, + {101, {"Second", 1, {shared}}}, + {102, {"Empty", 1, {}}}}; + EXPECT_EQ(J1939Parser::pgnFor("Shared", dbc), (std::set{100, 101})); +}