#include "pds700.h"

int main(int argc, char *argv[])
{
	WORD rs;
	char in_str[BUFSIZ], out_str[BUFSIZ], *p;
	pds_mod_t mod;
	int i;
	char server_ip[24];
	char ID[10] = {0}, DLC[5] = {0}, DATA[20] = {0};

	if (argc!= 2)
	{
		fprintf(stderr,"Usage:%s [PDS ip]\a\n",argv[0]);
		exit(1);
	}
	memset(&mod, 0, sizeof(pds_mod_t));
	strcpy(server_ip, argv[1]);
	rs = Open_CAN(&mod, server_ip);

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

	printf("\"Ctrl + c\" to exit.\n");
	while(1)
	{
		rs = Read_CAN_Msg(&mod, in_str);

		if(rs)
        	       	printf("Error Code %d : Read String Error\n", rs);

		printf("Read string from PDS : %s\n", in_str);
		p = in_str;
		sscanf(++p,"%3s%1s%s",ID,DLC,DATA);

		printf("ID   DLC  DATA\n");
		printf("%s  %s    %s\n\n",ID,DLC,DATA);
	}

	Close_CAN(&mod);
	Close_Module(&mod);
}
