mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-30 22:30:28 +01:00
hardware protocol v2: frame layer and shared symbol registry
Adds the transport-independent core of the MaSzyna Hardware Protocol v2: COBS framing with a CRC32C protected 24 byte header, bounds checked payload readers and writers, and a resynchronising stream decoder. The shared TrainState registry describes simulator state in engineering units with per-value quality, the command registry generates the command namespace from Commands_descriptions, and the symbol registry merges both into the public, name-addressed hardware api.
This commit is contained in:
69
hardware/registry/hardware_symbol_registry.cpp
Normal file
69
hardware/registry/hardware_symbol_registry.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "hardware/registry/hardware_symbol_registry.h"
|
||||
|
||||
#include "hardware/registry/command_registry.h"
|
||||
#include "hardware/registry/state_registry.h"
|
||||
|
||||
namespace hardware
|
||||
{
|
||||
|
||||
symbol_registry const &symbol_registry::instance()
|
||||
{
|
||||
static symbol_registry const registry;
|
||||
return registry;
|
||||
}
|
||||
|
||||
std::size_t symbol_registry::find( std::string const &Name ) const
|
||||
{
|
||||
auto const lookup = m_index.find( Name );
|
||||
return ( lookup != m_index.end() ? lookup->second : npos );
|
||||
}
|
||||
|
||||
symbol_registry::symbol_registry()
|
||||
{
|
||||
auto const &states = state_registry::instance().entries();
|
||||
m_entries.reserve( states.size() + command_registry::instance().entries().size() );
|
||||
|
||||
for( std::size_t index = 0; index < states.size(); ++index )
|
||||
{
|
||||
auto const &state = states[ index ];
|
||||
symbol_descriptor descriptor;
|
||||
descriptor.name = "state." + state.name;
|
||||
descriptor.kind = symbol_kind::state;
|
||||
descriptor.type = state.type;
|
||||
descriptor.access = access_read;
|
||||
descriptor.unit = state.unit;
|
||||
descriptor.minimum = state.minimum;
|
||||
descriptor.maximum = state.maximum;
|
||||
descriptor.source_index = index;
|
||||
m_index.emplace( descriptor.name, m_entries.size() );
|
||||
m_entries.emplace_back( std::move( descriptor ) );
|
||||
}
|
||||
|
||||
auto const &commands = command_registry::instance().entries();
|
||||
for( std::size_t index = 0; index < commands.size(); ++index )
|
||||
{
|
||||
auto const &command = commands[ index ];
|
||||
symbol_descriptor descriptor;
|
||||
descriptor.name = "command." + command.name;
|
||||
descriptor.kind = symbol_kind::command;
|
||||
descriptor.type = command.parameter_type;
|
||||
descriptor.access = access_write;
|
||||
descriptor.minimum = command.minimum;
|
||||
descriptor.maximum = command.maximum;
|
||||
descriptor.source_index = index;
|
||||
m_index.emplace( descriptor.name, m_entries.size() );
|
||||
m_entries.emplace_back( std::move( descriptor ) );
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace hardware
|
||||
Reference in New Issue
Block a user