fc3422a4a9
Picks up the file renames that landed alongside the previous commit and fixes everything that pointed at the old root locations: - README.md doc-map updated: every entry now points at docs/X.md, with a new "docs/" lead entry pointing at the guided-tour index. - README inline cross-refs (ARCHITECTURE / INTEGRATION / SECURITY / BENCHMARKS / MES_INTEROP / PROOFS) repointed to docs/. - README "Interop" section rewritten — used to mention only secsgem-py; now covers all four external validators (secsgem-py 31 / secs4java8 55 / tshark 69 frames / libFuzzer 200 k+ runs) with a one-line summary each, plus pointers to interop/README.md and docs/VERIFICATION.md. - README "Deferred follow-ups" cleaned: dropped the explanatory "Listed here so reviewers don't go looking for them in COMPLIANCE.md and find an 'out of scope' entry that sounds defensive" sentence — the section header speaks for itself. - docs/00_index.md "Where the rest of the docs live" table: dropped every `../` prefix since the docs are now siblings. - docs/01_what_is_secs_gem.md PROOFS reference updated to sibling. - docs/02_the_cast.md INTEGRATION + MES_INTEROP refs updated to siblings; dropped the stale "at the repo root" wording. - interop/README.md: VERIFICATION + PROOFS refs updated to ../docs/X.md; stale "~24 + 4 checks" updated to 31 (matches PROOFS.md and README). - examples/pvd_tool/README.md: every doc cross-ref now points at ../../docs/X.md. - Source / data / CI comments mentioning doc names (e.g. "INTEGRATION.md §3", "COMPLIANCE.md gap") rewritten to "docs/INTEGRATION.md §3" etc. — affects 9 files across include/, apps/, tests/, data/, examples/, .gitea/workflows/. Verified: full build under docker passes, 445/445 test cases pass, 2 753/2 753 assertions pass. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
111 lines
3.8 KiB
C++
111 lines
3.8 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <map>
|
|
#include <optional>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <variant>
|
|
#include <vector>
|
|
|
|
#include "secsgem/secs2/item.hpp"
|
|
|
|
namespace secsgem::gem {
|
|
|
|
namespace s2 = secsgem::secs2;
|
|
|
|
struct EquipmentConstant {
|
|
uint32_t id;
|
|
std::string name;
|
|
std::string units;
|
|
s2::Item value;
|
|
s2::Item def_value;
|
|
std::string min_str; // bounds for S2F30 + EAC validation; "" disables check
|
|
std::string max_str;
|
|
};
|
|
|
|
// S2F16 EAC per SEMI E5: 0=OK, 1=one or more constants does not exist,
|
|
// 2=busy, 3=one or more values out of range. Values 4-127 are reserved.
|
|
enum class EquipmentAck : uint8_t {
|
|
Accept = 0,
|
|
Denied_UnknownEcid = 1,
|
|
Denied_Busy = 2,
|
|
Denied_OutOfRange = 3,
|
|
};
|
|
|
|
class EquipmentConstantStore {
|
|
public:
|
|
void add(EquipmentConstant ec) { by_id_.insert_or_assign(ec.id, std::move(ec)); }
|
|
std::optional<EquipmentConstant> get(uint32_t id) const {
|
|
auto it = by_id_.find(id);
|
|
if (it == by_id_.end()) return std::nullopt;
|
|
return it->second;
|
|
}
|
|
std::vector<EquipmentConstant> all() const {
|
|
std::vector<EquipmentConstant> out;
|
|
out.reserve(by_id_.size());
|
|
for (const auto& [_, ec] : by_id_) out.push_back(ec);
|
|
return out;
|
|
}
|
|
bool has(uint32_t id) const { return by_id_.count(id) > 0; }
|
|
|
|
// Validates against min/max for numeric formats (only when min_str and
|
|
// max_str parse cleanly). Returns Denied_UnknownEcid / Denied_OutOfRange
|
|
// per S2F16 EAC. This is the rule that closes the docs/COMPLIANCE.md gap
|
|
// about "EC range validation against min/max".
|
|
EquipmentAck set_value(uint32_t id, s2::Item value) {
|
|
auto it = by_id_.find(id);
|
|
if (it == by_id_.end()) return EquipmentAck::Denied_UnknownEcid;
|
|
if (!in_range(it->second, value)) return EquipmentAck::Denied_OutOfRange;
|
|
it->second.value = std::move(value);
|
|
return EquipmentAck::Accept;
|
|
}
|
|
|
|
private:
|
|
// For numeric formats, parse min_str / max_str as integers / doubles and
|
|
// compare against the first value of the array (we don't support setting
|
|
// multi-element ECs in this implementation).
|
|
static bool in_range(const EquipmentConstant& ec, const s2::Item& value) {
|
|
if (ec.min_str.empty() && ec.max_str.empty()) return true;
|
|
|
|
auto parse_d = [](const std::string& s, double& out) {
|
|
if (s.empty()) return false;
|
|
try { out = std::stod(s); return true; } catch (...) { return false; }
|
|
};
|
|
|
|
double v;
|
|
if (!extract_number(value, v)) return true; // unknown format: skip
|
|
|
|
double lo = -1e300, hi = 1e300;
|
|
parse_d(ec.min_str, lo);
|
|
parse_d(ec.max_str, hi);
|
|
return v >= lo && v <= hi;
|
|
}
|
|
|
|
static bool extract_number(const s2::Item& item, double& out) {
|
|
auto first = [&](const auto& v) -> bool {
|
|
if (v.empty()) return false;
|
|
out = static_cast<double>(v.front());
|
|
return true;
|
|
};
|
|
switch (item.format()) {
|
|
case s2::Format::U1: return first(std::get<std::vector<uint8_t>>(item.storage()));
|
|
case s2::Format::U2: return first(std::get<std::vector<uint16_t>>(item.storage()));
|
|
case s2::Format::U4: return first(std::get<std::vector<uint32_t>>(item.storage()));
|
|
case s2::Format::U8: return first(std::get<std::vector<uint64_t>>(item.storage()));
|
|
case s2::Format::I1: return first(std::get<std::vector<int8_t>>(item.storage()));
|
|
case s2::Format::I2: return first(std::get<std::vector<int16_t>>(item.storage()));
|
|
case s2::Format::I4: return first(std::get<std::vector<int32_t>>(item.storage()));
|
|
case s2::Format::I8: return first(std::get<std::vector<int64_t>>(item.storage()));
|
|
case s2::Format::F4: return first(std::get<std::vector<float>>(item.storage()));
|
|
case s2::Format::F8: return first(std::get<std::vector<double>>(item.storage()));
|
|
default: return false;
|
|
}
|
|
}
|
|
|
|
std::map<uint32_t, EquipmentConstant> by_id_;
|
|
};
|
|
|
|
} // namespace secsgem::gem
|