17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 19:09:25 +02:00
Files
maszyna/input/zmq_input.cppm
maj00r 2896c2dd60 add the C library headers MSVC needs
Unqualified uint8_t/size_t and friends were reaching 24 units through
some other header on libstdc++; MSVC's STL does not do that, which broke
gl/ubo.cppm (and made its UBS_PAD macro look like garbage). Also
silences C5244, MSVC's counterpart to the clang warning about glm being
included in the module purview, which is deliberate here.
2026-09-10 00:10:52 +02:00

92 lines
2.1 KiB
C++

module;
#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