Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add emulated serial port #16

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Add emulated serial port #16

wants to merge 8 commits into from

Conversation

giomba
Copy link
Collaborator

@giomba giomba commented Jan 9, 2025

Desciption

This pull request implements an emulated serial port which you can use to communicate with the emulated software. Serial port is emulated as a TCP socket.

Review by commit is possible, but full-review is okay too.

Usage

  1. type serial open in the emulator's command line (with an optional port number): the emulator will start listening for an incoming connection at the specified port (or 52955 (0xCEDB) in case no port is given)
  2. you can use socat to emulate a serial port which can be used by serial port libraries, and connect it to the TCP socket, for example: socat -v -d -d pty TCP4:127.0.0.1:52955 (the -d -d option is used to show which virtual /dev/pts is created)
  3. connect to the given /dev/pts/x using your favorite application/serial terminal emulator/kermit client/whatever

@giomba giomba self-assigned this Jan 9, 2025
@giomba giomba requested a review from giuliof January 9, 2025 22:20
@giuliof
Copy link
Contributor

giuliof commented Jan 10, 2025

Comment "en passant": may be a good idea to use, if I recall their names, a "named pipe" instead of TCP socket. In this way the serial port is actually mapped to a file and can be accessed like a real serial port, avoiding socat.
Named pipes and TCP sockets are interchangeable and the usage of the former or the latter can be switched through config file, CLI, or - better- program option.

if (ret == 0) // timeout
return;

connfd = accept(sockfd, NULL, NULL);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC you never check for return value

Copy link
Collaborator Author

@giomba giomba Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module implements the CEDAModule interface (see src/module.h), which means that this function is polled in the main loop, so the check is performed during next loop iteration, and (if I did not get something wrong) nothing will break.
Anyhow, I'm always printing the "accept client" message, which may actually be wrong. Fixed.

@@ -293,14 +293,12 @@ uint8_t sio2_in(ceda_ioaddr_t address) {
#endif

if (address == SIO2_CHA_DATA_REG) {
// TODO(giomba): read external RS232

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why not squashing this commit in the previous one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept two different commits because the first one (Implement TX-ready channel flag in SIO/2) actually implements a new feature, which can be kept in its independent commit, while this one (Remove TODO comments for virtual serial port emulation) is more like a "chore" commit where I just remove some outdated comments (some of which are related to the implementation in the previous commit, but others aren't, like the ones referring to the keyboard).

@giomba
Copy link
Collaborator Author

giomba commented Jan 22, 2025

@giuliof

may be a good idea to use, if I recall their names, a "named pipe" instead of TCP socket

I tought about using a pipe, but decided to go with the TCP solution, because I've already seen and used it on other emulators (eg. Vice for the Commodore machines).

Named pipes and TCP sockets are interchangeable and the usage of the former or the latter can be switched through config file, CLI, or - better- program option.

You can open a follow-up issue.

@giomba giomba force-pushed the giomba/serial-port branch from 0906053 to e7426aa Compare January 22, 2025 10:55
@giomba giomba force-pushed the giomba/serial-port branch from e7426aa to c8b1f44 Compare January 22, 2025 10:58
@giomba giomba requested a review from luigix25 January 23, 2025 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants