Skip to content

A C implementation of a data transmission protocol over an RS-232 serial connection using Stop-and-Wait flow control and error handling, developed for the Computer Networks course at FEUP.

License

Notifications You must be signed in to change notification settings

AFNeves/PenguinRS232

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PenguinRS232

A C implementation of a data transmission protocol over a serial connection, using a simplified link-layer and application-layer architecture. The project was developed for the Computer Networks course at FEUP.

📁 Project Structure

The project is structured as follows:

.
├── bin/                # Compiled binaries (created after building)
├── include/            # Header files for link and application layers
│   ├── application_layer.h
│   └── link_layer.h
├── src/                # Source code for protocol implementation
│   ├── application_layer.c
│   └── link_layer.c
├── assets/             # Test files used for transmission
│   └── penguin.gif     # Default file to send
├── docs/               # Project documentation
│   └── Report_3LEIC12_G1.pdf
├── main.c              # Entry point for the application
├── Makefile            # Build and run instructions
├── LICENSE             # MIT License
└── README.md           # Project overview and usage guide

🧪 Running the Project

This project is designed to operate on real Linux systems connected via an RS-232 serial cable. However, for ease of testing and demonstration, these instructions use socat to create virtual serial ports on a single machine. You can follow the steps below to set up and test the protocol using virtual ports. If you wish to use actual hardware, simply update the serial port paths in the configuration (e.g., /dev/ttyS0, /dev/ttyS1) to match your physical devices.

0. Optional Configuration

Before running the project, you may wish to customize certain settings to match your environment or testing needs. This includes changing serial port paths, selecting a different test file, or adjusting transmission parameters.

Edit Serial Port Paths and Test Files

Open the Makefile and update these variables as needed:

# Serial port device paths
TX_SERIAL_PORT = /dev/ttyS10   # Transmitter port
RX_SERIAL_PORT = /dev/ttyS11   # Receiver port

# Test file names
TX_FILE = penguin.gif          # File to send
RX_FILE = penguin-received.gif # File to receive

Adjust Transmission Parameters

To experiment with different protocol settings, edit the following constants in main.c:

#define BAUDRATE 9600  // Serial communication speed
#define N_TRIES 4      // Number of retransmission attempts
#define TIMEOUT 3      // Timeout (seconds) for retransmission

Make sure to rebuild the project after making changes to the Makefile or source files.

1. Compilation

Build the project using the provided Makefile:

$ make

This compiles all source files in src/ and places the final executable in bin/main.

2. Create Virtual Serial Ports

Run this command in a separate terminal window to create a pair of connected serial ports:

$ sudo socat -d -d PTY,link=/dev/ttyS10,mode=777 PTY,link=/dev/ttyS11,mode=777
  • /dev/ttyS10 → transmitter port
  • /dev/ttyS11 → receiver port

⚠️ Keep this terminal open while testing!

The virtual serial ports will remain active only as long as this terminal is running. Closing it will disconnect the ports and interrupt communication.

3. Start the Receiver

In a new terminal, start the receiver process:

$ make run_rx

This listens on /dev/ttyS11 and saves the received file as assets/penguin-received.gif.

4. Start the Transmitter

In another terminal, start the transmitter:

$ make run_tx

This sends assets/penguin.gif through /dev/ttyS10.

4. Verify File Integrity

After the transfer completes, compare the original and received files:

$ make check_files

If everything worked correctly, you should see:

Files assets/penguin.gif and assets/penguin-received.gif are identical

5. Clean Up

Remove compiled files and received test data:

$ make clean

📄 Documentation

The full project report detailing the protocol design and implementation can be found in docs/Report_3LEIC12_G1.pdf.

Note: The report is written in Portuguese.

👥 Authors

📎 License

This project is licensed under the terms of the MIT License.

About

A C implementation of a data transmission protocol over an RS-232 serial connection using Stop-and-Wait flow control and error handling, developed for the Computer Networks course at FEUP.

Topics

Resources

License

Stars

Watchers

Forks