#include "pds700.h"

int main(int argc, char *argv[])
{
	WORD rs;
	pds_mod_t mod;
	int i, com = 1;
	int run = 2;
	char server_ip[60], server_mask[60], server_gw[60];
	
	if (argc!= 2)
	{
		fprintf(stderr,"Usage:%s [PDS ip]\a\n",argv[0]);
		exit(1);
	}

	strcpy(server_ip, argv[1]);

	memset(&mod, 0, sizeof(mod));
	rs = Open_Com(&mod, server_ip, 10000, com, 115200, 8, 0, 1);

	if(rs)
	{
		printf("Error Code %d : Open PDS-700 COM%d Error\n", rs, atoi(argv[2]));
		exit(1);
	}
		
	usleep(5000);

	rs = Get_PDS_Network_Info(&mod);
	if(rs)
               	return rs;

	printf("PDS Server IP      : %s\n", mod.server_ip);
	printf("PDS Server MAC     : %s\n", mod.server_mac);
	printf("PDS Server Gateway : %s\n", mod.server_gateway);
	printf("PDS Server Submask : %s\n\n", mod.server_submask);

	strcpy(server_ip, "10.1.0.40");
	strcpy(server_mask, "255.255.0.0");
	strcpy(server_gw, "10.1.0.254");

	rs = Set_PDS_Server_SubMask(&mod, server_mask);
	if(rs)
               	return rs;
	sleep(3);

	rs = Set_PDS_Server_Gateway(&mod, server_gw);
        if(rs)
               	return rs;
	sleep(3);

	rs = Set_PDS_Server_IP(&mod, server_ip);
	if(rs)
                return rs;

	Close_Module(&mod);

	memset(&mod, 0, sizeof(mod));

	rs = Open_Com(&mod, server_ip, 10000, com, 115200, 8, 0, 1);

	if(rs)
        {
        	printf("Error Code %d : Open PDS-700 COM%d Error\n", rs, atoi(argv[2]));
		exit(1);
	}

	rs = Get_PDS_Network_Info(&mod);
        if(rs)
		return rs;

	printf("PDS Server IP      : %s\n", mod.server_ip);
	printf("PDS Server MAC     : %s\n", mod.server_mac);
        printf("PDS Server Gateway : %s\n", mod.server_gateway);
        printf("PDS Server Submask : %s\n\n", mod.server_submask);

	Close_Module(&mod);
}
