Friday Ppt New

48
Prepared by R.NARENDRANATH REDDY 08H61D5515

Transcript of Friday Ppt New

Page 1: Friday Ppt New

Prepared by R.NARENDRANATH REDDY 08H61D5515

Page 2: Friday Ppt New

IEEE Paper complaintNow a days all home appliances are becoming multi-

functional and the system that control these functions is also becoming larger .

Time synchronization for these multi functional A/V devices is becoming a key requirement especially in the cases of event management.

To realize a desired stable time base system various methods can be adopted like

1.RTC incorporated in a Micro Processor unit . 2. Radio controlled Clock 3. Global Positioning System(GPS) 4. A method of obtaining time data from an upper

level SNTP server.

Page 3: Friday Ppt New

Structure of sntp for home use

Page 4: Friday Ppt New

For the radio wave clock, the number of transmitting stations and the regions that can receive the service from certain stations are limited, and further, radio waves can be received only at or near a window.

For GPS(global positioning system), the system will work only in places at which three or more GPS satellites are visible in the open sky, and thus it does not suit general domestic applications.

So above two methods cannot be used, a communication tool to connect to the Internet is supplied in order to obtain the time data from an upper level SNTP server.

Page 5: Friday Ppt New

Structure of SNTP for this project

Sntp client

Sntp server

Event manager

internet

Target Board

Event

Audio video system

Remote NTP

server

LAN

Page 6: Friday Ppt New

SNTP Simple network time protocol is used to

synchronize computer clock with standard time(UTC(universal co-ordinated time) via internet

SNTP is application layer protocol and it is dedicated for time synchronization .

Page 7: Friday Ppt New

Application layer

(SNTP)Transport layer

(UDP)Network layer

(IP)

Data Link layer

Physical layer

TCP/IP model

(my

project)

these layers implementedin Linux -2.6 kernel

Page 8: Friday Ppt New

PROJECT MODULES1.Event Management Program .2.SNTP client .3.SNTP server .3.Porting movie media player to target board.

Page 9: Friday Ppt New

DEVELOPMENT ENVIRONMENT

1.Programming Language : C.2.Operating System: LINUX.3. LINUX Kernel Version: 2.6.4.Compiler : ARM-LINUX-GCC for target board.5.Debugging Tools :arm-linux-gdb (Gnu Debugger).6.Target Board : Mini S3c 2440A(friendly arm board) .

.

Page 10: Friday Ppt New

SNTP TIME STAMP FORMAT

Sntp uses two fixed point time stamp formats 1.long format(64 bit) with integer(decimal)between bits

31 or 32 2.short format(32 bit) with with decimalbetween bits

15 and 16.

Page 11: Friday Ppt New

For that 64 bit we use following structuretypedef struct { union {

unsigned long int Xl_ui; long int Xl_i;

} Ul_i; union {

unsigned long int Xl_uf; long int Xl_f;

} Ul_f; }l_fp;For 32 bit format we just select unsigned long int root delay. unsigned long int root_dispersion.

Page 12: Friday Ppt New

SNTP MESSAGE FORMAT

Page 13: Friday Ppt New

SNTP message format is in big-endian mode that is network byte order for this we have htonl(),htons(),ntohl(),ntohs() funtions which converts host byte order(little Endian) to network byte order(big Endian mode) and vice versa.

Big Endian mode Little Endian

A B

C DA B

C D

B A

D C

B A

D C

Page 14: Friday Ppt New

Description of LI fieldLI Value Meaning

-------------------------------------------------------

00 0 no warning

01 1 last minute has 61 seconds

10 2 last minute has 59 seconds

11 3 alarm condition Leap Indicator (LI): This is a two-bit code warning of an

impending leap second to be inserted/deleted in the last minute of the current day, with bit 0 and bit 1, respectively, coded as above

Page 15: Friday Ppt New

Mode FieldMode: This is a three-bit integer indicating the mode, with

values defined as follows:

Mode Meaning

--------------------------------------------------

0 reserved

1 symmetric active

2 symmetric passive

3 client

4 server

5 broadcast

6 reserved for NTP control message

7 reserved for private use

Page 16: Friday Ppt New

Stratum FieldStratum: This is a eight-bit unsigned integer indicating the

stratum level of the local clock, with values defined as follows:

Stratum Meaning

----------------------------------------------

0 ------------> unspecified or unavailable

1 -----------> primary reference (e.g., radio clock)

2-15 ------------> secondary reference (via NTP or SNTP)

16-255 -----------> reserved

Page 17: Friday Ppt New

NTP Secondary server 1

SNTP server

stratum1

Stratum 2 to 15

Hierarchical layered system

NTP Secondary server 2

National standard time(Radio clock)

SNTP client

Page 18: Friday Ppt New

Reference Identifier: This is a 32-bit bitstring identifying the particular reference source

Root Dispersion: This is a 32-bit unsigned fixed-point number indicating the nominal error relative to the primary reference source, in seconds with fraction point between bits 15 and 16.

Root Delay: This is a 32-bit signed fixed-point number indicating the total roundtrip delay to the primary reference source, in seconds with fraction point between bits 15 and 16.

Precision: This is an eight-bit signed integer indicating the precision of the local clock, in seconds to the nearest power of two. The values that normally appear in this field range from -6 for mains-frequency clocks to -20 for microsecond clocks found in some workstations.

Poll Interval: This is an eight-bit signed integer indicating the maximum interval between successive messages, in seconds to the nearest power of two. The values that can appear in this field presently range from 4 (16 s) to 14 (16284 s); however, most applications use only the sub-range 6 (64 s) to 10 (1024 s).

Page 19: Friday Ppt New

Reference Timestamp: This is the time at which the local clock was last set or corrected, in 64-bit timestamp

format.Originate Timestamp: This is the time at which the request

departed the client for the server, in 64-bit timestamp format.Receive Timestamp: This is the time at which the request

arrived at the server, in 64-bit timestamp format.Transmit Timestamp: This is the time at which the reply

departed the server for the client, in 64-bit timestamp format.Authenticator (optional): When the NTP authentication scheme

is implemented, the Key Identifier and Message Digest fields contain the message authentication code (MAC)

Page 20: Friday Ppt New

Flow chart for SNTP client

start

enter input

options

Extract user entered

input

Is it valid

Poll the sntp

server

Send request

to server

Is p==

0

Get the offset and

delay

Set the RTC

EMP

Page 21: Friday Ppt New

user input from command line is in the form sntpdate [-dvqgh] [-p poll-time] [-t timeout] server [...]

-d Enable the debugging mode. Information useful for general debugging will be printed.

-v Be verbose print current version of SNTP.

-p samples: Specify the number of poll-times to be acquired from each server as the integer samples. The default is 5.

-q Query only - don't set the clock. -g Normally, the client ignore a server if the offset exceeds a 1000 s

sanity limit. This option overrides this limit and allows the offset to be any value without restriction, by it this mode is on.

-t timeoutSpecify the maximum time waiting for a server response as the value timeout, in seconds. The default is 1 second, a value suitable for polling across a LAN.

-h Print usage and this is for help to user how to enter inputs.

Page 22: Friday Ppt New

A number of poll-times are obtained from server is specified. An average of the offsets is obtain and local date and time are set using settimeofday() according to this average .

Input options are parsed and extracted by getopt() function which returns character after ’ –’ operator and optarg gives that character and optind gives string after this character.

Host ( SNTP server)is found by getaddrinfo() funtion.Keep Polling the server with sending request to server until

poll times reaches zero. So accuracy and reliability depends on poll times.

Page 23: Friday Ppt New

Initially send request with all zeros except li ,mode,Vn and transmit time stamp.

Initially li field is 0x3 and version no is 4 and mode is 3 for SNTP client and transmit time stamp contains time when request is sent.

SNTP Server copies this transmit time field to originate time stamp field, and sends transmit time stamp field with time when it sent and also sends receive time stamp field with time when it is received.

As soon as SNTP client receives reply from SNTPserver it will generate destination time stamp with time when it is received reply from SNTP server.

with this we can calculate offset and round trip delay.

Page 24: Friday Ppt New

SNTP CLIENT AND SERVER OPERATIONS

Page 25: Friday Ppt New

ROUNDTRIP DELAY AND LOCAL CLOCK OFFSET CALCULATIONS in clientTimestamp Name ID When

Generated------------------------------------------------------------Originate Timestamp T1 time request sent

by clientReceive Timestamp T2 time request

received by server

Transmit Timestamp T3 time reply sent by server

Destination Timestamp T4 time reply received by

clientThe roundtrip delay (d) and local clock offset (t

)are defined as d = (T4 - T1) - (T2 - T3) t = ((T2 - T1) +

(T3 - T4)) / 2.

Page 26: Friday Ppt New

For example send request at 8.00 received request at 9.00 (T1=28800 seconds) (T2=32400 seconds) reply received at reply send at (T4=28840 seconds) (T3=32420 seconds) d=(28840 – 28800)-(32400 -32420)=60 seconds t=((32400-28800)+(32420-28840))/2=3590. so client will add (3590 +60) seconds to client side

current RTC so client RTC is same as server RTC.

SNTP client SNTP server

Page 27: Friday Ppt New

So we calculate average offset and delay for poll-times and these are added to current client side RTC ,current RTC is given by gettimeofday() funtion.

With New corrected time we can set the RTC by using settimeofday() funtion. if we are a super user . Super user mode is found by getuid() funtion.

Page 28: Friday Ppt New

Event management program(EMP)Time base event management program deals with the

playing the events based on the user requirements. In this project we have 3 events like 1 audiofile,1 video

files, buzzer. So, time base event management program will take care about these events based on the user requirement time.

Event management program uses “time.h” functions, these are time() asctime(), ctime(), gmtime(),localtime(),mktime() ,difftime() ,these are predefined functions in TIME.H header file.

Page 29: Friday Ppt New

Flow chart for EMP

start

User input

Extract the input and validate

Is it valid

Convert user entered time into seconds

Diff between

user entered

start time and

systime ==0

Keep playing event

Diff between

stoptime and

systime

==0

Stop playin

g event

Page 30: Friday Ppt New

User input is type of event(audio,buzzer,video) and start time and time of that event ,if it is audio or video ,then user have to enter file name to be played.

User entered time is validated by strptime() funtion.user entered time is converted to seconds by using mktime()funtion.

mktime() converts broken down time to calendar time in seconds.

time_t the_time; Struct tm tm_ptr; Time(&the_time); tm_ptr=localtime(&the_time); the_time=mktime(&tm_ptr);

Page 31: Friday Ppt New

struct tm { int tm_sec; /* The number of seconds after the minute, normally in the

range 0 to 59, but can be up to 60 to allow for leap seconds.*/

int tm_min; /* The number of minutes after the hour, in the range 0 to 59. */

int tm_hour;/* number of hours past midnight, in the range 0 to 23. */ int tm_mday; /* The day of the month, in the range 1 to 31.*/ int tm_mon; /* The number of months since January, in the range 0 to 11.

*/ int tm_year; /* number of years since 1900.*/ int tm_wday; /* The number of days since Sunday, in the range 0 to 6.*/ int tm_yday; /* The number of days since January 1, in the range 0 to

365.*/ int tm_isdst; /* A flag that indicates whether daylight saving time is in

effect at the time described */ };

Page 32: Friday Ppt New

We can get system time by using time() in seconds and difftime() difference between two times.

When ever diff between user start time and system time equal to zero then start playing event, if not it keeps waiting until their difference equal to zero.

When ever diff between user stop time and system time equal to zero stop playing the user selected event.

Page 33: Friday Ppt New

Flow chart for SNTP Server

start

enter input

options

Extract user entered

input

Is it valid

Poll the NTP

server

Send request to NTP server

Is p==

0

calculate the offset and delay

Set the RTC with offset and delay

Is itL==0

Wait for client request in infinite loop

Send reply to SNTP

client

Page 34: Friday Ppt New

user input from command line is in the form sntpdate [-dvqghl] [-p poll-time] [-t timeout] server [...]

-d Enable the debugging mode. Information useful for general debugging will be printed.

-v Be verbose, it will print current version of SNTP.

-p samples: Specify the number of poll-times to be acquired from each server as the integer samples. The default is 5.

-q Query only - don't set the clock. -l if user wants local clock of SNTP server , type ‘l’ in command prompt. -g Normally, the client ignore a server if the offset exceeds a 1000 s

sanity limit. This option overrides this limit and allows the offset to be any value without restriction, by it this mode is on.

-t timeout: Specify the maximum time waiting for a server response as the value timeout, in seconds. The default is 1 second, a value suitable for polling across a LAN.

-h Print usage and this is for help to user how to enter inputs.

Page 35: Friday Ppt New

A number of poll-times are obtained from server is specified. An average of the offsets is obtain and local date and time are set using settimeofday() according to this average .

Input options are parsed and extracted by getopt() function which returns character after ’ –’ operator and optarg gives that character and optind gives string after this character.

Check whether user entered local clock mode, if local clock mode is on then following steps are skipped untill SNTP

Host ( NTP server)is found by getaddrinfo() funtion.Keep Polling the server with sending request to server until

poll times reaches zero. So accuracy and reliability depends on poll times.

Page 36: Friday Ppt New

Initially send request with all zeros except li ,mode,Vn and transmit time stamp.

Initially li field is 0x3 and version no is 4 and mode is 3 for SNTP client and transmit time stamp contains time when request is sent.

NTP Server copies this transmit time field to originate time stamp field, and sends transmit time stamp field with time when it sent and also sends receive time stamp field with time when it is received.

As soon as SNTP client receives reply from NTPserver it will generate destination time stamp with time when it is received reply from NTP server.

with this we can calculate offset and round trip delay.

Page 37: Friday Ppt New

After setting RTC with settimeofday() funtion SNTP sever is waiting for SNTP client request in infinite loop.

If sntp client sends request to sntp server , it replies to same client by using getnameinfo() funtion and comes back to infinite loop.

SNTP server sends information to sntp client using socket(logical start and end point) which is created by socket() funtion.

Page 38: Friday Ppt New

Application layer

(Sntp client)Transport layer

(UDP)Network layer

(IP)Data Link layer

Physical layer

Applictaion layer

(Sntp server)Transport layer(UDP port 123)

Network layer (IP)

Data Link layer

Physical layer

Data transfer between client and server

socket

Page 39: Friday Ppt New

Movie media player (Mplayer) The Mplayer one of the popular media player commonly

used in Linux environments ,it needs two dependencies 1.lame encoder 2.Xvid video codec.

1.Lame is an open source MP3 encoder. MPlayer uses lame for compressing audio into MP3 audio.

2. XviD is an ISO MPEG-4 compliant video codec. MPlayer can encode movie files formats into the XviD format.

Page 40: Friday Ppt New

Porting Mplayer to target board

Mplayer needs two dependencies those are xvid video codec and lame audio encoder.

export PATH=/home/guest/friendlyarm/usr/local/arm/4.3.2/bin:$PATH

./configure --enable-cross-compile --cc=arm-linux-gcc --target=arm-linux --disable-gui --enable-largefiles --enable-menu --prefix=/usr -- disable-live --confdir=/etc/mplayer.

make for compilinfg mplayer source code.Now mplayer ELF file ported to target board

Page 41: Friday Ppt New

Demonstrating The Results

Sntp client

Sntp server

Event manager

Connected to

LAN/WAN

Target Board

Event

Audio video system

Remote NTP

server

LAN

Page 42: Friday Ppt New

TARGET BOARD DETAILSFriendly arm board which consists of samsung S3c2440A

cmos 32 bit microcontroller , it uses ARM920 core processor.

CPU operating frequency: 400 MHz to 533 MHz

System clock : 12 MHz.

System bus : 32 bit.

RAM : 64 MB Flash : 64 MB Nand Flash

2MB Nor Flash.

Serial Ports : 1x DB9 connector (RS232),

Audio Output Port

Ethernet : 10/100Mbps Fast ethernet(DM9000)

Beeper : PWM buzzer.

Page 43: Friday Ppt New

LCD :

NL2432hc22-22b is a Thin film transistor (TFT) active matrix color liquid crystal display(LCD) which is developed by NEC corporation.

It contains 8.9 cm (3.5 inches) diagonal diplay area and pixel size is 240(H)×320(V) pixels.

It can display 262,144 colors simulataneously.

Page 44: Friday Ppt New

LCD interface with s3c2440A target board

The target board has got a 41 pin display connector.

The jumper J2 is used for the LCD driver board power supply select signal, either 5v or 3.3v supply.

Page 45: Friday Ppt New
Page 46: Friday Ppt New

LCD interface pins with S3C2440A

Page 47: Friday Ppt New

PWM Buzzer interface with s3c2440A target boardThe Buzzer is connected to GPB0.

Page 48: Friday Ppt New

conclusion So SNTP server and client system is

dedicated for home appliances in audio , video applications.

Sntp is developed for embedded system applications.