#include "pds700.h"

int main(int argc, char *argv[])
{
	WORD rs;
        pds_mod_t mod;
        int i = 0, com = 1;
        int baud[8] = {115200, 38400, 9600, 115200, 38400, 9600, 115200, 38400};
        char minios_ver[128], vxcomm_ver[128], mod_name[16];
	
	int x = 0, ch;

	if (argc!= 2)
	{
		fprintf(stderr,"Usage:%s [PDS ip]\a\n",argv[0]);
		exit(1);
	}

	memset(&mod, 0, sizeof(pds_mod_t));
	rs = Open_Com(&mod, argv[1], 10000, com, baud[com-1], 8, 0, 1);
	if(rs)
        {
               	printf("Error Code %d : Open PDS-700 COM%d Error\n", rs, atoi(argv[2]));
		exit(1);
        }
	com++;

	rs = Get_PDS_Module_Name(&mod, mod_name);

	if(rs)
		return rs;
	printf("Module name %s\n",mod_name);

	while(1)	//get channel number
	{
		if(mod_name[i] == '7')
		{
			ch = mod_name[++i] - '0';
			break;
		}
		i++;
	}

	for(i = 1; i < ch; i++)
	{
		rs = Open_Com(&mod, argv[1], 10000, com, baud[com-1], 8, 0, 1);
		if(rs)
		{
			printf("Error Code %d : Open PDS-700 COM%d Error\n", rs, atoi(argv[2]));
			exit(1);
		}
		com++;
	}

	rs = Get_PDS_MiniOS_Version(&mod, minios_ver);
	
	if(rs)
		return rs;

	rs = Get_PDS_Vxcomm_Version(&mod, vxcomm_ver);

	if(rs)
                return rs;

	rs = Get_PDS_Network_Info(&mod);

	if(rs)
                return rs;

	com = 1;
	printf("MiniOS7 Version    : %s\n", minios_ver);
	printf("Vxcomm.exe Version : %s\n", vxcomm_ver);
	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", mod.server_submask);

	for(i = 0; i < ch; i++)
	{
		printf("PDS Server COM%d : %d,%d,%d,%d\n", com, mod.com_list[i].baud, mod.com_list[i].data, mod.com_list[i].parity, mod.com_list[i].stop);
		com++;
	}

	Close_Module(&mod);
}
