Closes #24
This commit is contained in:
1 parent
fc97682b37
commit
e555ebb571
16 files changed
+337
-52
No files matched your search
@@ -2,6 +2,7 @@
|
||||
// Copyright (c) 2026 Dim Himro
|
||||
|
||||
#include "decode_database.h"
|
||||
#include "j1939.h"
|
||||
#include "signal_layout.h"
|
||||
#include <bitset>
|
||||
#include <cmath>
|
||||
@@ -55,6 +56,9 @@ namespace {
|
||||
if (frame.canId > maximumId)
|
||||
throw std::invalid_argument("Invalid normalized CAN ID: " + std::to_string(frame.canId));
|
||||
|
||||
if (frame.hasPgn && (!frame.isExtended || frame.pgn != ExtractJ1939Pgn(frame.canId)))
|
||||
throw std::invalid_argument("Invalid J1939 PGN metadata: " + frame.name);
|
||||
|
||||
std::unordered_set<std::string> names;
|
||||
const DecodeSignal *selector = nullptr;
|
||||
for (const DecodeSignal &signal: frame.signals) {
|
||||
@@ -99,6 +103,8 @@ DecodeDatabase::Storage::Storage(const std::vector<DecodeFrame> &definitions)
|
||||
frameIndexByKey.reserve(frames.size());
|
||||
for (std::size_t index = 0U; index < frames.size(); ++index) {
|
||||
frameIndexByKey.emplace(frames[index].GetKey(), index);
|
||||
if (frames[index].hasPgn)
|
||||
frameIndicesByPgn[frames[index].pgn].push_back(index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,6 +127,22 @@ std::shared_ptr<const DecodeFrame> DecodeDatabase::FindFrame(const FrameKey &key
|
||||
return std::shared_ptr<const DecodeFrame>(storage, &storage->frames[it->second]);
|
||||
}
|
||||
|
||||
PgnLookupResult DecodeDatabase::FindFrameByPgn(std::uint32_t pgn) const {
|
||||
PgnLookupResult result;
|
||||
if (!storage)
|
||||
return result;
|
||||
const std::unordered_map<std::uint32_t, std::vector<std::size_t>>::const_iterator it =
|
||||
storage->frameIndicesByPgn.find(pgn);
|
||||
if (it == storage->frameIndicesByPgn.end())
|
||||
return result;
|
||||
if (it->second.size() != 1U) {
|
||||
result.ambiguous = true;
|
||||
return result;
|
||||
}
|
||||
result.definition = std::shared_ptr<const DecodeFrame>(storage, &storage->frames[it->second[0]]);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::shared_ptr<const DecodeSignal> DecodeDatabase::FindSignal(const SignalKey &key) const {
|
||||
const std::shared_ptr<const DecodeFrame> frame = FindFrame(key.frame);
|
||||
if (!frame)
|
||||
|
||||
Reference in new issue
Block a user