This project was developed for the 'Real-Time Embedded Systems' course, part of the MEng in Electrical and Computer Engineering at the Aristotle University of Thessaloniki in 2019. Its purpose is to develop a simple message exchange system based on an integrated real-time system that manages the flow of messages. Messages are generated by devices corresponding to each student and are shared among all possible devices until they reach their destination.
The logic behind the implemented code is as follows: A thread is created and tasked with passively receiving messages from neighboring devices seeking communication. Concurrently, it attempts to connect to every possible available device sequentially to send stored messages. In addition to these, randomly generated messages are sent to devices at regular intervals. This process continues for the 2 hours designated as the experiment's duration.
Note on terminology: In this project, "AEM" refers to the unique student identification number used in Greece. This is practically the ID of each participating student.
uint32_t peerAEM[nAEMs]
: A static vector storing an array of AEMs of potential network devices (wherenAEMs
is the constant for the number of these AEMs).char** history
: A two-dimensional dynamic array storing incoming messages.char** aemIPs
: A 2D dynamic array storing the IP addresses of potential network devices.int history_idx
: A pointer to the current position inhistory
where a new entry is stored.int end_flag
: A flag indicating the end of the program after 2 hours.uint32_t info[6][nAEMs]
: A multipurpose 2D static array storing AEMs, message indices, and statistics for communication analysis.FILE* recFile, sendFile, randomMesFile, forMeFile, statsFile
: Files for storing received messages, sent messages, random messages, messages intended for the device itself, and statistical data, respectively.
int IptoAEM(char* ip)
: Converts an IP address to its corresponding AEM number by extracting and processing the address components.
void makeIPs()
: Converts stored AEMs to their corresponding IP addresses and stores them in aemIPs
.
void write_file(FILE* file, char* data)
: Writes data to a file if the file is open successfully.
int connect_server(char* ip, char* message)
: Creates a socket and connects to a device at the specified IP address to send a message.
void server(char* ip)
: Manages connections to an IP address and sends messages following a random delay.
void listener()
: Creates a socket to passively receive messages from any neighboring device and processes them.
void* thListener(void* ptr)
: Calls the listener
function; used to implement a listener thread.
int main(int argc, char const *argv[])
: Initializes files, arrays, and variables; creates a listener thread; and manages the sending and receiving of messages.