AP25 Installation and Operating Guide
Version 1.00
Appendix H. Serial Command AP!
H-12
Document #: 9301H79500 Ver. 1.00
/* ======================================================================== **
* Prototypes
* ======================================================================== */
int AP20Command( char *strAp20_IpAddress, char *StrCmd, char *StrPassword );
int Send( int fd , char *StrCmd );
int ReadResponse( int fd , char *StrCmd );
/* ======================================================================== **
* Functions
* ======================================================================== */
/* ------------------------------------------------------------------------ **
* Function: main
*
* Picks up the Command from the command line arguments.
* In this example the AP20 IP address and AP20 Setup password is hardcoded.
* ------------------------------------------------------------------------ */
int main (int argc, char **argv)
{
char StrCmd[256];
int cnt;
if ( argc < 2)
{
printf ("Usage: Ap20NetCmd arg1 ... arg\n");
exit(1);
}
// collect args
int firstarg=1;
snprintf( StrCmd, sizeof(StrCmd), "%s", argv[f+] );
for ( cnt = firstarg; cnt < argc; cnt++ )
{
strcat ( StrCmd , " ");
strcat ( StrCmd , argv[cnt]);
}
AP20Command( StrAp20Ip, StrCmd, StrAp20Password );
}
/* ------------------------------------------------------------------------ **
* Function: AP20Command
*
* - A socket connection to the AP20 is established to the AP20 IP
* address using port 14500.
* - Send the AUTH command if the AP20 has a password defined.
* ------------------------------------------------------------------------ */
int AP20Command( char *strAp20_IpAddress, char *StrCmd, char *StrPassword )
{
int fd;
struct sockaddr_in MySocket;
// sender main socket
memset(&MySocket, 0, sizeof(MySocket));
MySocket.sin_addr.s_addr = inet_addr( "127.0.0.1" );
MySocket.sin_addr.s_addr = inet_addr( strAp20_IpAddress ); // Set the AP20 IP address here
MySocket.sin_family = AF_INET;
MySocket.sin_port = htons( AP20_PORT_NUM ); // Set the AP20 Port address
// Get a file descriptor for the socket
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
printf("socket() failed\n");
return -1;
}
// Connect to the AP20
if( ::connect( fd, (struct sockaddr *)&MySocket, sizeof( MySocket ) ) != 0 )