portfolio programming

15
ECE 1322 : PROGRAMMING FOR ENGINEERS C PROGRAMMING PROJECT : SIMPLE TDMA PROJECT USING C PROGRAM MUHAMMAD ‘AINUDDIN BIN ZAMERY 1019129

Upload: mohd-saatarie

Post on 11-Jul-2016

214 views

Category:

Documents


1 download

DESCRIPTION

needed in programming assignment

TRANSCRIPT

Page 1: Portfolio programming

ECE 1322 : PROGRAMMING FOR ENGINEERS

C PROGRAMMING PROJECT :

SIMPLE TDMA PROJECT USING C PROGRAM

MUHAMMAD ‘AINUDDIN BIN ZAMERY 1019129

MUHAMMAD IRFAN BIN OSMAN 1019401

Page 2: Portfolio programming

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

Page 3: Portfolio programming

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 node3_input = 10001101Division 00100101Multiple 00001101Access 01100110

node2_input = 01110001010000100100010011100100

Page 4: Portfolio programming

The Flowchartmain.c

START

Create_function()

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()

"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”

END

Page 5: Portfolio programming

source.c

Create_function()

END

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);

Page 6: Portfolio programming

TDMA_function()

Sleep(1000);

t1 = time(NULL);

receive_node1

Sleep(1000);

t2 = time(NULL);

receive_node2

Sleep(1000);

t3 = time(NULL);

sending_node1()

sending_node2()

sending_node3()

receive_node3

while(getc(node3)!=EOF)

END

FALSE

TRUE

Page 7: Portfolio programming

sending_node3()

sending_node2()

sending_node1()

receiving_node3()

receiving_node1()

t2<t3 fscanf(node1,"%s",&receive_node3);

END

TRUE

FALSE

FALSE

TRUE

END

receiving_node2()

fscanf(node1,"%s",&receive_node2);t1<t2

FALSE

t1>t0

END

fscanf(node1,"%s",&receive_node1);TRUE

Page 8: Portfolio programming

receiving_node2()

fprintf(node4,"\n%s",receive_node2)

END

receiving_node3()

fprintf(node4,"\n%s",receive_node3)

END

receiving_node1()

fprintf(node4,"\n%s",receive_node1)

END

Page 9: Portfolio programming

The Program Codes

1) main.c :

#include<stdio.h>#include<time.h>#include <windows.h>#include "header.h" //To link with the header.h file.#include "source.c" //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"); //To open new files.node2 = fopen("node2_input.txt","r");node3 = fopen("node3_input.txt","r");node4 = fopen("node4_output.txt","w");

TDMA_function(); //To process the data files.

}

2) header.h

#ifndef HEADER_H_INCLUDE //The syntax to define a header file.#define HEADER_H_INCLUDE

FILE *node1; //Data files declaration.FILE *node2;FILE *node3;FILE *node4;

//Declaration for temporary storage.char receive_node1[999],receive_node2[999],receive_node3[999];

time_t t0,t1,t2,t3; //Time function declaration t0:initial time, t1:time slot for node1, t2:time slot for node2, t3:time slot for node3.

Page 10: Portfolio programming

create_function(); //Function definitions.TDMA_function();sending_node1();sending_node2();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" //To link with the header.h file.

create_function() //To fill-up the opened files with data.{

node1=fopen("node1_input.txt","w"); //Node 1fprintf(node1,"%s","Time\nDivision\nMultiple\nAccess");fclose(node1);

node2=fopen("node2_input.txt","w"); //Node 2fprintf(node2,"%s","01110001\n01000010\n01000100\n11100100");fclose(node2);

node3=fopen("node3_input.txt","w"); //Node 3fprintf(node3,"%s","10001101\n00100101\n00001101\n01100110");fclose(node3);

}

TDMA_function() //To process the data within the time period according to each files time slots.{

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.

Page 11: Portfolio programming

printf("\n%s",receive_node1); //To print the output on the command window.

Sleep(1000); //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 .{

Page 12: Portfolio programming

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);}