ECE 1322 : PROGRAMMING FOR ENGINEERS
C PROGRAMMING PROJECT :
SIMPLE TDMA PROJECT USING C
PROGRAM
MUHAMMAD AINUDDIN BIN ZAMERY
1019129
MUHAMMAD IRFAN BIN OSMAN
1019401
Introduction
Time division multiple access (TDMA) is a channel access method for shared
medium networks. It allows several users to share the same frequency channel by
dividing the signal into different time slots. The users transmit in rapid succession,
one after the other, each using his own time slot. This allows multiple stations to
share the same transmission medium (e.g. radio frequency channel) while using only
a part of its channel capacity. TDMA is used in the digital 2G cellular systems such
as Global System for Mobile Communications (GSM), IS-136, Personal Digital
Cellular (PDC) andiDEN, and in the Digital Enhanced Cordless
Telecommunications (DECT) standard for portable phones. It is also used
extensively in satellite systems, and combat-net radio systems.
TDMA is a type of Time-division multiplexing, with the special point that instead of
having one transmitter connected to one receiver, there are multiple transmitters. In
the case of the uplink from a mobile phone to a base station this becomes
particularly difficult because the mobile phone can move around and vary the timing
advance required to make its transmission match the gap in transmission from its
peers.
TDMA Illustration
Designing A Simple TDMA Project using C program
To design a simple TDMA using c program, first we need to analyze and list all the problems.
In this program, we will assume the nodes are files.
The problems that we encounter during designing the program are :
1. How to read the data line by line.
2. How to design the time slot and time period.
3. How to loop the process of sending and receiving data.
After we have solved all the problems, we start to draw the flow chart. By referring to the flow
chart, we design the problem codes.
The codes are checked for any flaws so that it will run smoothly. For the final touch, we
make the program looks nicer by putting the introduction and coloring to the command
windows.
The Nodes
node1_input
= Time
Division
Multiple
Access
node2_input = 01110001
01000010
01000100
11100100
The Flowchart
node3_input = 10001101
00100101
00001101
01100110
main.c
START
"Assalamualaikum. This program simulate the TDMA (Time Division Multiple
Access)
Node 1 :Time\nDivision\nMultiple\ntAccess
Node 2 :01110001\n01000010\n01000100\n11100100
Node 3 :10001101\n00100101\n00001101\n01100110
Create_function()
node1 =
fopen("node1_input.txt","r");
node2 =
fopen("node2_input.txt","r");
node3 =
fopen("node3_input.txt","r");
TDMA_function()
END
source.c
Create_function()
node1=fopen("node1_input.txt","w");
fprintf(node1,"%s","Time\nDivision\nMultiple\nAccess");
fclose(node1);
node2=fopen("node2_input.txt","w");
fprintf(node2,"%s","01110001\n01000010\n01000100\n11100100");
fclose(node2);
node3=fopen("node3_input.txt","w");
fprintf(node3,"%s","10001101\n00100101\n00001101\n01100110");
fclose(node3);
END
TDMA_function()
Sleep(1000);
t1 = time(NULL);
Sleep(1000);
Sleep(1000);
receive_node1
receive_node3
receive_node2
sending_node1()
sending_node2()
sending_node3()
t2
t3=
=time(NULL);
time(NULL);
while(getc(node3)!
TRUE
FALS
E END
sending_node
1()
t1>t0
t1<t2
t2<t3
TRU
E
sending_node
END
END
END
FALS
FALS
FALS
TRU
TRU
fscanf(node1,"%s",&receive_nod
receiving_node1()
receiving_node3()
fscanf(node1,"%s",&receive_nod
fscanf(node1,"%s",&receive_nod
receiving_node2()
sending_node2
()
receiving_node1()
fprintf(node4,"\n
END
%s",receive_node1)
receiving_node2()
fprintf(node4,"\n
%s",receive_node2)
END
receiving_node3()
fprintf(node4,"\n
%s",receive_node3)
The Program Codes
END
1) main.c :
#include<stdio.h>
#include<time.h>
#include <windows.h>
#include "header.h"
#include "source.c"
//To link with the header.h file.
//To link with the source.c file.
main()
{
printf("Assalamualaikum. This program simulate the TDMA (Time Division Multiple
Access)\n");
//Introduction and opening.
printf("\nNode 1 :Time\n\tDivision\n\tMultiple\n\tAccess");
printf("\n\nNode 2 :01110001\n\t01000010\n\t01000100\n\t11100100");
printf("\n\nNode 3 :10001101\n\t00100101\n\t00001101\n\t01100110");
create_function();
//Function call linked to create_fuction to create files.
node1 = fopen("node1_input.txt","r");
node2 = fopen("node2_input.txt","r");
node3 = fopen("node3_input.txt","r");
node4 = fopen("node4_output.txt","w");
TDMA_function();
//To open new files.
//To process the data files.
}
2) header.h
#ifndef HEADER_H_INCLUDE
#define HEADER_H_INCLUDE
FILE *node1;
FILE *node2;
FILE *node3;
FILE *node4;
//The syntax to define a header file.
//Data files declaration.
//Declaration for temporary storage.
char receive_node1[999],receive_node2[999],receive_node3[999];
time_t t0,t1,t2,t3;
create_function();
TDMA_function();
sending_node1();
sending_node2();
//Time function declaration t0:initial time,
t1:time slot for node1, t2:time slot for node2,
t3:time slot for node3.
//Function definitions.
sending_node3();
receiving_node1();
receiving_node2();
receiving_node3();
#endif
//The syntax to define a header file.
3) source.c
#include<stdio.h>
#include "header.h"
create_function()
{
//To link with the header.h file.
//To fill-up the opened files with data.
node1=fopen("node1_input.txt","w");
fprintf(node1,"%s","Time\nDivision\nMultiple\nAccess");
fclose(node1);
//Node 1
node2=fopen("node2_input.txt","w");
//Node 2
fprintf(node2,"%s","01110001\n01000010\n01000100\n11100100");
fclose(node2);
node3=fopen("node3_input.txt","w");
//Node 3
fprintf(node3,"%s","10001101\n00100101\n00001101\n01100110");
fclose(node3);
}
TDMA_function()
according to each files time slots.
{
//To process the data within the time period
t0 = time(NULL);
//Initial time.
do
{
//To loop process so that nothing will be left behind.
Sleep(1000);
//Time slot for node 1 is 1 second.
t1 = time(NULL);
//Time for node 1.
sending_node1();
//To send the data to node 4.
printf("\n%s",receive_node1);
Sleep(1000);
//To print the output on the command window.
//Time slot for node 2 is 1 second.
t2 = time(NULL);
//Time for node 2.
sending_node2();
//To send the data to node 4.
printf("\n%s",receive_node2);
//To print the output on the command window.
Sleep(1000);
//Time slot for node 3 is 1 second.
t3 = time(NULL);
//Time for node 3.
sending_node3();
//To send the data to node 4.
fprintf(node4,"\n");
//To give spacing inside node 4's file.
printf("\n%s",receive_node3);
//To print the output on the command window.
printf("\n\n");
}while(getc(node3)!=EOF); //The condition to loop until the end-of-file is reached.
}
sending_node1()
//Function to send data from node 1 to node 4 .
{
if(t1>t0)
{
fscanf(node1,"%s",&receive_node1);
receiving_node1(); //Funtion call for node 4 to receive data from node 1.
}
}
sending_node2()
{
//Function to send data from node 2 to node 4 .
if(t2>t1)
{
fscanf(node2,"%s",&receive_node2);
receiving_node2(); //Funtion call for node 4 to receive data from node 2.
}
}
sending_node3()
{
//Function to send data from node 3 to node 4 .
if(t3>t2)
{
fscanf(node3,"%s",&receive_node3);
receiving_node3(); //Funtion call for node 4 to receive data from node 3.
}
}
receiving_node1()
//Function for node 4 to receive data from node 1.
{
fprintf(node4,"\n%s",receive_node1);
}
receiving_node2()
//Function for node 4 to receive data from node 2.
{
fprintf(node4,"\n%s",receive_node2);
}
receiving_node3()
//Function for node 4 to receive data from node 3.
{
fprintf(node4,"\n%s",receive_node3);
}