AP25 Installation and Operating Guide
Version 1.00
Appendix H. Serial Command AP!
H-13
Document #: 9301H79500 Ver. 1.00
{
printf("connect() fail\n");
close( fd );
fd = -1;
return -1;
}
printf( "Connection to %s:%d OK\n", strAp20_IpAddress, AP20_PORT_NUM );
// Send passord only if AP20 has Setup Password defined
char StrAuth[100];
sprintf( StrAuth, "AUTH %s", StrPassword );
if( strlen( StrPassword ) )
{
Send( fd, StrAuth );
ReadResponse( fd, StrAuth );
if( !strcmp( rxBuf, "SETUP" ) )
{
printf( "Wrong Password\n" );
return( -1 );
}
else
printf( "Password OK\n" );
}
Send( fd, StrCmd );
ReadResponse( fd, StrCmd );
close( fd ); // Close connection
fd = -1;
return( 0 );
}
/* ------------------------------------------------------------------------ **
* Function: Send
*
* Sends a command string the AP20.
* ------------------------------------------------------------------------ */
int Send( int fd , char *StrCmd )
{
char strAP20Cmd[1024];
// Command starts with '@' and ends with CR
strcpy( strAP20Cmd, "@" );
strcat( strAP20Cmd, StrCmd );
strcat( strAP20Cmd, "\r" );
printf( "Sending NetCmd to AP20: %s\n", strAP20Cmd );
int ret = write(fd,&strAP20Cmd,strlen(strAP20Cmd) );
if ( ret < 0 )
{
fprintf(stderr,"write fail\n");
close(fd);
fd = -1;
}
return 0;
}
/* ------------------------------------------------------------------------ **
* Function: ReadResponse
*
* Reads data received from the AP20 until CR is received.
* ------------------------------------------------------------------------ */
int ReadResponse( int fd , char *StrCmd )
{
char c;