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.
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
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.
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.
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
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.
Build the project using the provided Makefile:
$ make
This compiles all source files in src/ and places the final executable in bin/main.
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.
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.
In another terminal, start the transmitter:
$ make run_tx
This sends assets/penguin.gif through /dev/ttyS10.
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
Remove compiled files and received test data:
$ make clean
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.
- Afonso Neves ([email protected])
- Joรฃo Miranda ([email protected])
This project is licensed under the terms of the MIT License.