mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 08:39:19 +02:00
A template defined in a module interface is instantiated in the importing unit, where its body's types must be complete. A declaration reaching the importer only through the interface's global module fragment is not enough for MSVC: cParser::operator>> uses std::stringstream, and every unit that parsed a float got an incomplete type. 526 headers across 161 units, derived from what each interface's template bodies actually name.
93 lines
2.1 KiB
C++
93 lines
2.1 KiB
C++
module;
|
|
#include <deque>
|
|
#include <cstdint>
|
|
#include <zmq_addon.hpp>
|
|
#include <chrono>
|
|
#include <map>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <tuple>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
export module eu07.input.zmq_input;
|
|
import eu07.input.command;
|
|
|
|
export {
|
|
|
|
|
|
class zmq_input
|
|
{
|
|
enum class output_fields {
|
|
shp,
|
|
alerter,
|
|
radio_stop,
|
|
motor_resistors,
|
|
line_breaker,
|
|
motor_overload,
|
|
motor_connectors,
|
|
wheelslip,
|
|
converter_overload,
|
|
converter_off,
|
|
compressor_overload,
|
|
ventilator_overload,
|
|
motor_overload_threshold,
|
|
train_heating,
|
|
cab,
|
|
recorder_braking,
|
|
recorder_power,
|
|
alerter_sound,
|
|
coupled_hv_voltage_relays,
|
|
velocity,
|
|
reservoir_pressure,
|
|
pipe_pressure,
|
|
brake_pressure,
|
|
hv_voltage,
|
|
hv_current_1,
|
|
hv_current_2,
|
|
hv_current_3,
|
|
lv_voltage,
|
|
distance,
|
|
radio_channel,
|
|
springbrake_active,
|
|
time_month_of_era,
|
|
time_minute_of_month,
|
|
time_millisecond_of_day
|
|
};
|
|
|
|
zmq::context_t ctx;
|
|
std::optional<zmq::socket_t> sock;
|
|
|
|
enum class input_type
|
|
{
|
|
none,
|
|
toggle, // two commands, each mapped to one state; press event on state change
|
|
impulse, // one command; press event when set, release when cleared
|
|
value // one command; press event, value of specified byte passed as param1
|
|
};
|
|
|
|
struct peer_state {
|
|
float update_interval;
|
|
std::vector<output_fields> sopi_list;
|
|
std::vector<std::tuple<input_type, user_command, user_command, bool>> sipo_list;;
|
|
std::chrono::time_point<std::chrono::high_resolution_clock> last_update;
|
|
};
|
|
|
|
std::map<uint32_t, peer_state> peers;
|
|
|
|
float unpack_float(const zmq::message_t &);
|
|
zmq::message_t pack_float(float f);
|
|
zmq::message_t pack_field(output_fields f);
|
|
|
|
std::unordered_map<std::string, user_command> nametocommandmap;
|
|
|
|
static std::unordered_map<std::string, output_fields> output_fields_map;
|
|
command_relay relay;
|
|
|
|
public:
|
|
zmq_input();
|
|
void poll();
|
|
};
|
|
|
|
} // export
|