17 : eventDistributor(eventDistributor_), scheduler(scheduler_)
18 , rs232InputFilenameSetting(
19 commandController,
"rs232-inputfilename",
20 "filename of the file where the RS232 input is read from",
22 , rs232OutputFilenameSetting(
23 commandController,
"rs232-outputfilename",
24 "filename of the file where the RS232 output is written to",
39 auto outName = rs232OutputFilenameSetting.
getString();
47 auto inName = rs232InputFilenameSetting.
getString();
54 auto& rs232Connector = checked_cast<RS232Connector&>(connector_);
62 thread = std::thread([
this]() { run(); });
78 return "rs232-tester";
83 return "RS232 tester pluggable. Reads all data from file specified "
84 "with the 'rs-232-inputfilename' setting. Writes all data "
85 "to the file specified with the 'rs232-outputfilename' "
89void RS232Tester::run()
92 while (!feof(inFile.get())) {
94 if (poller.
poll(fileno(inFile.get()))) {
98 std::array<uint8_t, 1> buf;
99 size_t num = fread(buf.data(),
sizeof(uint8_t), buf.size(), inFile.get());
107 std::scoped_lock lock(mutex);
129 auto* conn = checked_cast<RS232Connector*>(
getConnector());
130 if (!conn->acceptsData()) {
131 std::scoped_lock lock(mutex);
135 if (!conn->ready())
return;
137 std::scoped_lock lock(mutex);
138 if (queue.
empty())
return;
143bool RS232Tester::signalEvent(
const Event& )
148 std::scoped_lock lock(mutex);
158 if (outFile.is_open()) {
159 outFile.put(narrow_cast<char>(value));
165template<
typename Archive>
Represents something you can plug devices into.
void unregisterEventListener(EventType type, EventListener &listener)
Unregisters a previously registered event listener.
void distributeEvent(Event &&event)
Schedule the given event for delivery.
void registerEventListener(EventType type, EventListener &listener, Priority priority=Priority::OTHER)
Registers a given object to receive certain events.
zstring_view getString() const noexcept
Thrown when a plug action fails.
bool isPluggedIn() const
Returns true if this pluggable is currently plugged into a connector.
void setConnector(Connector *conn)
Connector * getConnector() const
Get the connector this Pluggable is plugged into.
bool poll(int fd)
Waits for an event to occur on the given file descriptor.
void reset()
Reset aborted() to false.
bool aborted() const
Returns true iff abort() was called.
void abort()
Aborts a poll in progress and any future poll attempts.
RS232Tester(EventDistributor &eventDistributor, Scheduler &scheduler, CommandController &commandController)
void plugHelper(Connector &connector, EmuTime::param time) override
std::string_view getName() const override
Name used to identify this pluggable.
std::optional< bool > getCTS(EmuTime::param time) const override
void signal(EmuTime::param time) override
void serialize(Archive &ar, unsigned version)
void unplugHelper(EmuTime::param time) override
std::optional< bool > getDSR(EmuTime::param time) const override
void recvByte(uint8_t value, EmuTime::param time) override
std::string_view getDescription() const override
Description for this pluggable.
EmuTime::param getCurrentTime() const
Get the current scheduler time.
void openOfStream(std::ofstream &stream, zstring_view filename)
Open an ofstream in a platform-independent manner.
FILE_t openFile(zstring_view filename, zstring_view mode)
Call fopen() in a platform-independent manner.
This file implemented 3 utility functions:
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, WindowEvent, TextEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent, Rs232NetEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)