beautypg.com

SENA HD1200 User Manual

Page 45

background image

Starter Kit and User Manual for the HelloDevice 1200

42

6.4 Sample Programs

6.4.1 Using the Socket Program for Communication

The following C program source code shows how to implement Internet socket interface program for the

HelloDevice communication. This sample code is implemented to read and to write Dual-Port RAM data, by

using Berkeley socket C API functions. This source is a part of the entire source code “the HelloDevice

installation folder\Src\C\dprdemo.c”. TestThroughput() function is for testing the maximal speed of the

communication in your network environment.

//---------------------
// Process Test Throughput
//---------------------
void TestThroughput()
{

unsigned char

commandBuf[5], *ResponseBuf ;

int

commandLen,

lenReceived

;

int

j,

total_length=0

;

int

offset, length, tmp ;

double

bps=0

;

int err, loop ;

int

clientLen

;


clock_t start, finish;

double

duration;


// Enter loop count for this test...

printf("\nEnter loop count of this demo....\n>>") ;


// Read loop count

scanf("%d", &loop) ;


// Fix the size as 1450, which is max. of Ethernet packet size

// This is max. size of the DPRAM data that can be transferred in the HelloDevice

offset = 0 ;

length = 1450 ;


// Initialize TCP socket

TCPSocketInit()

;


// Make TCP command : 6-byte coce


// 1) Command ID

commandBuf[0] = DPRGet ;

// 2) DPRAM address

tmp = offset >> 8 ;

commandBuf[1] = tmp ;


tmp = offset & 0x00FF ;

commandBuf[2] = tmp ;

// 3) DPRAM length

tmp = length >> 8 ;

commandBuf[3] = tmp ;


tmp = length & 0x00FF ;

commandBuf[4] = tmp ;


// 4) Interrupt flag

commandBuf[5] = 0 ; // 0: Do not generate Interrupt to device, AA: Generate interrupt


commandLen = 6 ;