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_);
61 thread = std::thread([
this]() { run(); });
77 return "rs232-tester";
82 return "RS232 tester pluggable. Reads all data from file specified "
83 "with the 'rs-232-inputfilename' setting. Writes all data "
84 "to the file specified with the 'rs232-outputfilename' "
88void RS232Tester::run()
91 while (!feof(inFile.get())) {
93 if (poller.
poll(fileno(inFile.get()))) {
97 std::array<uint8_t, 1> buf;
98 size_t num = fread(buf.data(),
sizeof(uint8_t), buf.size(), inFile.get());
106 std::lock_guard<std::mutex> lock(mutex);
109 Event::create<Rs232TesterEvent>());
116 auto* conn = checked_cast<RS232Connector*>(
getConnector());
117 if (!conn->acceptsData()) {
118 std::lock_guard<std::mutex> lock(mutex);
122 if (!conn->ready())
return;
124 std::lock_guard<std::mutex> lock(mutex);
125 if (queue.
empty())
return;
130int RS232Tester::signalEvent(
const Event& )
135 std::lock_guard<std::mutex> lock(mutex);
145 if (outFile.is_open()) {
146 outFile.put(narrow_cast<char>(value));
152template<
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=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.
bool aborted()
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.
void signal(EmuTime::param time) override
void serialize(Archive &ar, unsigned version)
void unplugHelper(EmuTime::param time) 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:
REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, CassettePlayer, "CassettePlayer")
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)