SENA HD1100 User Manual
Page 36
Starter Kit and User Manual for the HelloDevice 1100
33
(struct sockaddr*)&clientAddr,
sizeof(clientAddr)
) ;
if (err == -1)
{
perror("\nsend error\n");
exit (1);
}
// Allocate buffer for incoming packet = 16 bytes
ResponseBuf = calloc(0x10, sizeof(char)) ;
// Receive incomming packet....
lenReceived = recvfrom
(
sock,
ResponseBuf,
0x10,
0,
(struct sockaddr*)&clientAddr,
&clientLen
);
if (lenReceived < 0)
{
perror("\nError receiving???\n") ;
exit(0) ;
}
// Display incoming packet size
printf("\n%d bytes received...\n", lenReceived) ;
// Store I/O status for future use
for (i=0; i<4; i++)
IOStatus[i] = ResponseBuf[i] ;
// Display I/O status
printf("\n\n*********************************\n") ;
printf("Input : %x:%x\t\tOutput : %x:%x", IOStatus[0], IOStatus[1], IOStatus[2],
IOStatus[3]) ;
printf("*********************************\n") ;
// Free
free(ResponseBuf) ;
// Close TCP socket
TCPSocketClose() ;
}
//---------------------
// Process Output set
//---------------------
void OutputSet()
{
char
commandBuf[3] ;
int
commandLen ;
int
outbit=0, outdata=0x0001 ;
// Read output set value
printf("Select the output point to be set (0-15) :") ;
scanf("%d", &outbit) ;
outdata <<= outbit ;
// Read current output status
IOMonitor() ;
// Re-Initialize TCP socket
TCPSocketInit() ;
// Determine the output value considering current output status
outdata |= ((IOStatus[2]<<8) | IOStatus[3]) ;
// Make TCP command