SENA HD1200 User Manual

Page 47

Advertising
background image

Starter Kit and User Manual for the HelloDevice 1200

44

}


//---------------------
// Process DPR Read
//---------------------
void DPR_Read()
{

unsigned char

commandBuf[5], *ResponseBuf ;

int

commandLen,

lenReceived

;

int

i,

count,

err

;

int

clientLen

;

int

offset, length, tmp ;


printf("\n\nEnter offset in hex (MAX. 0x7FF):") ;

scanf("%x",

&offset)

;


printf("\nEnter length in digit (MAX. 1450):") ;

scanf("%d",

&length)

;


// Initialize TCP socket

TCPSocketInit()

;


// Make TCP command


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



// Send command to the HelloDevice

err

=

sendto

(

sock,

&commandBuf,

commandLen,

0,

(struct

sockaddr*)&clientAddr,

sizeof(clientAddr)
)

;

if (err == -1)

{
perror("\nsend

error\n");

exit

(1);

}

// Allocate buffer for incoming packet

ResponseBuf = calloc(length+4, sizeof(char)) ;


// Receive incomming packet....

lenReceived

=

recvfrom

(

sock,
ResponseBuf,

Advertising