/*******************************************************************
   echochar.c
   Z-Word Inc 2003

	This sample program is for any RabbitNet board.

	Description
	===========
	This program demonstrates a simple character echo to any
	RabbitNet board.  A character is sent to the RabbitNet board
   found by using the rn_find() to search for a board that matches
   criteria. If is found, the character will be returned back plus
   the status of the board.  Otherwise, the status byte will
   indicate a no connection.

	Connections
	===========
   Connect RabbitNet and power supply cables to the controller
   and RN boards as described in the RabbitNet Manual.

	Instructions
	============
	1. Compile and run this program.

*******************************************************************/
#class auto

#define MATCHFLAG  RN_MATCH_PORT|RN_MATCH_PRDID
#define MATCHPORT 0           //port 0 or port 1 on the controller
#define MATCHPID RN1100			//RN1100 DI/0 board; RN1200 for AD board

nodebug
void msDelay(unsigned int delay)
{
	auto unsigned long done_time;

	done_time = MS_TIMER + delay;
   while( (long) (MS_TIMER - done_time) < 0 );
}


main()
{
	auto int device0;
	auto char statusbyte, sendbyte, recbyte;
	auto rn_search newdev;

	brdInit();                 //initialize controller
   rn_init(RN_PORTS, 1);      //initialize controller RN ports

   //search for device match
	newdev.flags = MATCHFLAG;
	newdev.ports = MATCHPORT;
	newdev.productid = MATCHPID;
   if ((device0 = rn_find(&newdev)) == -1)
   {
   	printf("\n no device found\n");
      exit(0);
   }


	while (1)
	{
		for (sendbyte='A'; sendbyte<='Z'; sendbyte++)
		{
			statusbyte = rn_echo(device0, sendbyte, &recbyte);
			printf("send %c, status %x rec %c\n", sendbyte, statusbyte, recbyte);
         msDelay(500);
		}
	}
}

