STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
ScriptConfig.cpp
Go to the documentation of this file.
2
3#include <map>
4
6
7namespace fsw {
8namespace script {
9
10namespace {
11
12/** Insert canonical->slug into `table`, recording a bad slug or an in-namespace collision. */
13void addName(const std::string& canonical, const char* where,
14 std::map<std::string, std::string>& table, TableBuild& out) {
15 if (canonical.empty())
16 return;
17 const std::string slug = slugify(canonical);
18 if (!is_valid_slug(slug)) {
19 // Refused rather than mangled. Every name on all three shipped profiles slugs cleanly, so
20 // this only fires on something new — and inventing a punctuation mangling would be a rule
21 // the operator cannot see and the editor's autocomplete would have to guess at.
22 out.bad.push_back({canonical, slug, where});
23 return;
24 }
25 auto it = table.find(slug);
26 if (it != table.end()) {
27 if (it->second != canonical)
28 out.collisions.push_back({slug, it->second, canonical, where});
29 return;
30 }
31 table.emplace(slug, canonical);
32}
33
34} // namespace
35
37 TableBuild out;
38
39 for (const auto& [name, role] : cfg.actuator_roles)
40 addName(name, "actuator", out.tables.actuators, out);
41
42 // Sensors come through the shared resolver rather than by walking [sensor_roles_*] again, so
43 // the set a script may name is exactly the set the pressure subscriber can resolve to a table.
44 // Two walks would eventually disagree, and the disagreement would look like a sensor that
45 // validates fine and then reads nothing.
46 for (const auto& ref : fsw::config::pt_role_tables(cfg))
47 addName(ref.role, "sensor", out.tables.sensors, out);
48
49 for (const auto& s : cfg.states)
50 addName(s.name, "state", out.tables.states, out);
51
52 return out;
53}
54
55} // namespace script
56} // namespace fsw
TOML_PURE_GETTER TOML_EXPORTED_MEMBER_FUNCTION iterator find(std::string_view key) noexcept
TOML_PURE_INLINE_GETTER iterator end() noexcept
Definition toml.hpp:8004
std::vector< PtRoleRef > pt_role_tables(const Config &cfg)
Every PT sensor role declared by an enabled PT board, in board-declaration order, then every PT input...
void addName(const std::string &canonical, const char *where, std::map< std::string, std::string > &table, TableBuild &out)
Insert canonical->slug into table, recording a bad slug or an in-namespace collision.
std::string slugify(const std::string &name)
Canonical name -> slug: trim, uppercase, collapse internal whitespace runs to a single '_'.
Definition Slug.cpp:8
bool is_valid_slug(const std::string &slug)
True when a slug is usable as a bare identifier: ^[A-Z][A-Z0-9_]*$.
Definition Slug.cpp:29
TableBuild build_slug_tables(const fsw::config::Config &cfg)
Build the actuator / sensor / state slug tables from a loaded config.
Motorized ball valve position: raw ADC counts -> % open.
The whole parsed config.toml, restricted to what C++ consumes.
Definition Config.hpp:264