Exemplo n.º 1
0
/**
 * wait for synchronization of syncCardNum
 * Inputs: NONE
 * Return: 0 if success
 */
int getCardNum(){
	int cn[3];
	recvchar(cn);
	usleep(80);
	recvchar(cn+1);
	usleep(80);
	recvchar(cn+2);
	usleep(80);
	sramwrite(CHNP, cn[0]);
	sramwrite(CHNP+1, cn[1]);
	sramwrite(CHNP+2, cn[2]);
	return 0;
}
Exemplo n.º 2
0
/**
 * wait for synchronization of deleteSRAM
 * Inputs: NONE
 * Return: 0 if success
 */
int deleteRecv(){
	int addr;
	recvchar(&addr);
	usleep(50);
	deleteSRAM(addr);
	return 0;
}
Exemplo n.º 3
0
/*
 * 02Feb2005, Maiko, Make this one function for all modem types,
 * no need to have a dxp_out, or ptc_out, etc - this will be easier
 * to maintain and we have a standard way of doing it then.
 */
static void keyboard_to_hfdd (int dev, void *n1, void *n2)
{
	struct session *sp = (struct session*)n1;

	HFDD_PARAMS *hfdd_params = (HFDD_PARAMS*)n2;

	int soc, save_errno, c, maxlen, len;

	char outdata[300], *ptr = outdata;

	/* initialize the changeover control variable */
	int changeover = hfdd_params->pactor;

	int changeoverdone = 0;	/* 25May2005 */

	if (hfdd_debug)
		log (-1, "entry into keyboard_to_hfdd");

	while (1)
	{
		if (hfdd_debug)
			log (-1, "waiting for forwarding socket to be assigned");

		while (hfdd_fwdsock == -1)
		{
			/*
			 * We might be told to die nicely through an ALERT, note
			 * that pause returns a zero after normal wait is over, but
			 * will return a -1 for other exceptions (like ALERTS).
			 */
			if (j2pause (1000) == -1)
			{
				log (-1, "keyboard handler alerted - die nicely");
				sp->proc1 = NULLPROC;
				return;
			}
		}

		soc = hfdd_fwdsock;

	if (hfdd_debug)
		log (-1, "entering the read-from-keyboard loop");

	/* 03Jun07, Maiko, Oops, these need to be reset with Xtra while loop */
	changeoverdone = 0;
	ptr = outdata;


	/* 21Sep08, Maiko, Don't think we need this minimum anymore */
#ifdef	DONT_COMPILE
	/*
	 * 24Jul08, Maiko, The 'maxlen' was initially put in to help me debug
	 * a problem with the new PK232 driver code. However, I should probably
	 * be setting the limit based on the type of hardware, instead of using
	 * a generic value like 64 - which was the maximum regardless of modem.
	 */
    if (hfdd_is_pk232 (hfdd_params->iface))
        maxlen = 16;
    else
#endif
        maxlen = 250;	/* let's try 128 instead */

	while (1)
	{
		/*
		 * The whole idea here is that if we don't get anything from
		 * the keyboard or our forwarding mailbox after 2 seconds, I
		 * think it's safe to assume there is nothing more to send to
		 * the remote side. In the case of Pactor, we use this to make
		 * the changeover so that the remote end can then send to us.
		 */

		j2alarm (2000);
    	c = recvchar (soc);
		j2alarm (0);

		/*
		 * An EOF tells us that we did not receive anything from
		 * the keyboard or the forwarding mailbox for 2 seconds,
		 * or it tells us that we need to terminate this proc !
		 */
		if (c == EOF)
		{
			save_errno = errno;

			/* 10Feb2007, Maiko, Actually if the following happens,
			 * then very likely a mailbox or session died, in which
			 * case (now that we want this to not die), we need to
			 * do cleanup - .....
			 */
			if (save_errno != EALARM)
			{
				if (hfdd_debug)
				{
					log (-1, "errno %d reading from mailbox or keyboard",
						save_errno);

					log (-1, "mailbox probably shutdown !!!");
				}

				/* 10Feb2007, Maiko, Force disconnect just to be safe */

#ifdef WINMOR
			/* 12Apr2010, maiko */
				if (hfdd_is_winmor (hfdd_params->iface))
					set_winmor_disc_flag ();
				else
#endif
				if (hfdd_is_ptc (hfdd_params->iface))
					set_ptc_disc_flag ();
				else if (hfdd_is_dxp (hfdd_params->iface))
					dxp_disconnect (dev);
				else if (hfdd_is_kam (hfdd_params->iface))
					set_kam_disc_flag ();
				/* 23Apr08, Maiko (VE4KLM), Added support for pk232 */
				else if (hfdd_is_pk232 (hfdd_params->iface))
					pk232_disconnect (dev);	/* 09Sep08, Maiko, New way */

				hfdd_fwdsock = -1;	/* socket no longer valid */

				hfdd_conn_flag = 0;		/* Set as disconnected !!! */

				break;	/* break out 10Feb2007 to wait for new socket */
			}
		}

		/*
		 * 03Jun07, Maiko, If not connected, then we should not
		 * even be in this while loop anymore. Leave and wait for
		 * a new mailbox to be created.
	 	 */

		if (!hfdd_conn_flag)
		{
			if (hfdd_debug)
				log (-1, "no longer connected, no point reading mailbox");

			hfdd_fwdsock = -1;	/* socket no longer valid */

			hfdd_conn_flag = 0;		/* Set as disconnected !!! */

			break;
		}

		/* Do not put the EOF into the outgoing buffer */
		if (c != EOF)
		{
			/* log (-1, "(%c)", (char)c); 13Apr2010, Maiko, Debugging */

			/* 05Oct06, Maiko, Forgot about escape chars - DXP only */
			if (hfdd_is_dxp (hfdd_params->iface))
			{
				/*
				 * DXP sees 0x80 and 0x81 as special characters, so we
				 * must first send $81 as an escape, then $80 or $81.
				 */
				if (c == 0x80 || c == 0x81)
				{
					if (hfdd_debug)
						log (-1, "escape character");

					*ptr++ = 0x81;
				}

				*ptr++ = c & 0xff;
			}

			/* 10Feb07, Maiko, Escape characters for Kantronics */
			else if (hfdd_is_kam (hfdd_params->iface))
			{
				/*
				 * KAM sees FEND or FESC as special characters, so
				 * we actually replace them with sequences instead.
				 */
				if (c == 0xc0)
				{
					if (hfdd_debug)
						log (-1, "escape (fend) character");

					*ptr++ = 0xdb;
					*ptr++ = 0xdc;
				}
				else if (c == 0xdb)
				{
					if (hfdd_debug)
						log (-1, "escape (esc) character");

					*ptr++ = 0xdb;
					*ptr++ = 0xdd;
				}
				else *ptr++ = c & 0xff;
			}
			/* 30May08, Maiko, Escape character for AEA */
			else if (hfdd_is_pk232 (hfdd_params->iface))
			{
				/* 17Jun08, Maiko, Corrected - 3 characters require escape */
				if (c == 0x01 || c == 0x10 || c == 0x17)
				{
					if (hfdd_debug)
						log (-1, "escape (dle) character");

					*ptr++ = 0x10;
				}

				*ptr++ = c & 0xff;
			}

			/* 10Feb07, Maiko, I don't believe SCS has escape chars */
			else *ptr++ = c & 0xff;
		}

		/* Calculate the length of data in the outgoing buffer */
		len = (int)(ptr - outdata);

		/*
		 * 24Jul08, Do not send any more than 'maxlen' bytes at a time
		 * to the tnc. Before this, the maximum length was hardcoded to
		 * a value of 64 bytes (regardless of the type of modem).
		 */
        if (len > maxlen)
		{
			if (!changeoverdone)
			{
				hfdd_changeover (dev, hfdd_params->iface, 1);
				changeoverdone = 1;
			}

			if (hfdd_debug)
				log (-1, "waiting for us to be ISS ...");
           /*
            * 20Sep2006, Maiko, Don't send out any data until the
            * modem tells us that we are indeed the ISS (sender). I
			* found out that failure to wait results in lost data.
            */

            while (!hfdd_iss ())
			{
				j2pause (100);	/* putting this in will free up jnos */
              	pwait (NULL);
			}

			if (hfdd_debug)
				log (-1, "we are now ISS - sending %d bytes", len);

#ifdef WINMOR
		/* 09Apr2010, Maiko, Finally got back to backs hooked up, play time */
			if (hfdd_is_winmor (hfdd_params->iface))
				winmor_send_data (outdata, len);

			else
#endif
			if (hfdd_is_ptc (hfdd_params->iface))
				ptc_send_data (dev, outdata, len);

			else if (hfdd_is_dxp (hfdd_params->iface))
				hfdd_send (dev, outdata, len);

			else if (hfdd_is_kam (hfdd_params->iface))
				kam_send_data (dev, outdata, len);

			/* 29Apr2008, Maiko, Finally doing the pk232 modem */
			else if (hfdd_is_pk232 (hfdd_params->iface))
				pk232_send_data (dev, outdata, len);

			ptr = outdata;	/* make sure we start from beginning again */

			continue;
		}

		/*
		 * If forwarding, send the data if we get an EOF indicating that
		 * we have not received any data within 2 seconds, OR if there is
		 * a real user at the keyboard, send if a Carriage Return has been
		 * hit by the user, OR if we get an EOF indicating this process
		 * is about to be terminated (in which case we have flush any
		 * remaining data in the output buffer.
		 */
		if (c == EOF)
		{
			if (len)
			{
				if (!changeoverdone)
				{
					hfdd_changeover (dev, hfdd_params->iface, 1);
					changeoverdone = 1;
				}

				if (hfdd_debug)
					log (-1, "waiting for us to be ISS ...");
				/*
				 * 20Sep2006, Maiko, Don't send out any data until the
				 * modem tells us that we are indeed the ISS (sender). I
				 * found out that failure to wait results in lost data.
				 */

            	while (!hfdd_iss ())
				{
					j2pause (100);	/* putting this in will free up jnos */
              		pwait (NULL);
				}

				if (hfdd_debug)
					log (-1, "we are now ISS - sending %d bytes", len);

#ifdef WINMOR
			/* 09Apr2010, Maiko, got back to backs hooked up, play time */
				if (hfdd_is_winmor (hfdd_params->iface))
					winmor_send_data (outdata, len);

				else
#endif
				if (hfdd_is_ptc (hfdd_params->iface))
					ptc_send_data (dev, outdata, len);

				else if (hfdd_is_dxp (hfdd_params->iface))
					hfdd_send (dev, outdata, len);

				else if (hfdd_is_kam (hfdd_params->iface))
					kam_send_data (dev, outdata, len);

				/* 29Apr2008, Maiko, Finally doing the pk232 modem */
				else if (hfdd_is_pk232 (hfdd_params->iface))
					pk232_send_data (dev, outdata, len);

				ptr = outdata;	/* reset output buffer pointer !!! */
			}

			/* 30May2008, Maiko, We need to do this whether len is 0 or not,
			 * ran into a case where len = 0, so previously we would never let
			 * the final changeover to the remote occur, and the remote would
			 * just sit there waiting and waiting. Discovered this by accident
			 * while testing my pk232 hfdd code -> chance happening len = 0.
			 * NOTE : only do this once on the first len = 0, use the change
			 * overdone flag to make sure we did the forced one first !
			 */
			if (changeoverdone)
			{	
				if (changeover)
					hfdd_changeover (dev, hfdd_params->iface, 0);
			}

			changeoverdone = 0;	/* 25May2005 */
		}
	}

	}	/* NEW WHILE(1) LOOP - 10Feb2007, Maiko */

	/* 10Feb2007, Maiko, Let's try staying inside keyboard loop now */

	log (-1, "left the read-from-keyboard loop, errno %d, save_errno %d",
		errno, save_errno);
}
Exemplo n.º 4
0
Arquivo: play.c Projeto: suix2/InUW
int play(){
	int pass=0;
	Boolean firstRound=FALSE;
	// true if first round
	if(ll==myNum)
		firstRound=TRUE;
	// use for "for loop"
	int i;
	// number of cards played
	int number = 0;
	// pattern code
	int pattern=0; //sync
	int temp; //for sync
	// current card played, no need to init
	char ccp[20];
	// key value of card played
	int key=CUTOFF; //sync
	char card[3];
	Boolean check;
	//checkPattern
	printf("Current Player: %d\n", PCS);
	while(!haveWinner()){
		if(isCurrentPlayer()){
			check=TRUE;
			do{
				if(!check)
					printf("Your Inputs Are Illegal, Please Input Again\n");
				check=FALSE;
				//input to ccp, check num here
				display();
				printf("hey player, tell me the number of cards you want to play this round."
						"You can input 0 if you want to give up\n");
				scanf(" %d", &number);
				for(i=0;i<number;i++) {
					if(!i)
						printf("please tell me the card you want to play this round. One by One please. \n");
					else
						printf("please tell me the next card you want to play. \n");
					scanf("%s", card);
					switch(card[0]){
						case 'a':
						case 'A':
							ccp[i]=11;
							break;
						case '2':
							ccp[i]=12;
							break;
						case '3':
							ccp[i]=0;
							break;
						case '4':
							ccp[i]=1;
							break;
						case '5':
							ccp[i]=2;
							break;
						case '6':
							ccp[i]=3;
							break;
						case '7':
							ccp[i]=4;
							break;
						case '8':
							ccp[i]=5;
							break;
						case '9':
							ccp[i]=6;
							break;
						case '1':
							ccp[i]=7;
							break;
						case 'j':
						case 'J':
							ccp[i]=8;
							break;
						case 'q':
						case 'Q':
							ccp[i]=9;
							break;
						case 'k':
						case 'K':
							ccp[i]=10;
							break;
						case 'b':
						case 'B':
							ccp[i]=13;
							break;
						case 'r':
						case 'R':
							ccp[i]=14;
							break;
					}
				}
				if(number && checkCards(number, ccp))
					check=checkPatternAndValue(&pattern, ccp, number, &key);
				printf("check: %d\nkey: %d\n", pattern, key);
			}while((number && !check) || (!number && firstRound));
			if(!number){
				sendchar(CUTOFF | 0x40);
				usleep(10000);
			}
			else{
				if(firstRound)
					firstRound=!firstRound;
				sendchar(key | 0x40);
				usleep(1000);
				sendchar((pattern & 0x3f) | 0x40);
				usleep(1000);
				sendchar((pattern >> 6) | 0x40);
				usleep(1000);
				deleteCards(number, ccp);
				temp=sramread(CHNP+myNum-1);
				sramwrite(CHNP+myNum-1, temp-pattern/10);
				usleep(1000);
				sendchar(sramread(CHNP) | 0x40);
				usleep(1000);
				sendchar(sramread(CHNP+1) | 0x40);
				usleep(1000);
				sendchar(sramread(CHNP+2) | 0x40);
				usleep(1000);
			}
		}
		else{
			recvchar(&temp);
			usleep(80);
			if(temp!=CUTOFF){
				key=temp;
				recvchar(&pattern); //last 6 bits
				usleep(80);
				recvchar(&temp); //11-6 bits of pattern
				usleep(80);
				pattern+=temp*64;
				recvchar(&temp);
				usleep(80);
				sramwrite(CHNP, temp);
				recvchar(&temp);
				usleep(80);
				sramwrite(CHNP+1, temp);
				recvchar(&temp);
				usleep(80);
				sramwrite(CHNP+2, temp);
			}
			else{
				pass++;
				if(pass==2){
					pass=0;
					pattern=0;
					key=0;
				}
			}
		}
		if(pattern==42)
			multiplier*=2;
		temp=sramread(CHNP);
		printf("Pattern Is: %d\nKey Is: %d\nPlayer1 Num Remainds: %d\n", pattern, (key+3)%14+(key==11)+(key==12)+12*(key==13)+12*(key==14), temp);
		temp=sramread(CHNP+1);
		printf("Player2 Num Remainds: %d\n", temp);
		temp=sramread(CHNP+2);
		printf("Player3 Num Remainds: %d\n", temp);
		nextPlayer();
	}
Exemplo n.º 5
0
/**
 * pick the landlord
 * Inputs: NONE
 * Return: int
 */
int landlord(){
	int i;
	int choice;
	int opcode;
	while(!isCurrentPlayer()){
		recvchar(&opcode);
		usleep(50);
		switch(opcode){
		case 1:
				nextPlayer();
				break;
		case 5:
				if(PCS==1){
					firstchoice=1;
				} else if(PCS==2){
					secondchoice=1;
				} else {
					thirdchoice=1;
				}
				break;
		case 6:
				if(PCS==1){
					firstchoice=2;
				} else if(PCS==2){
					secondchoice=2;
				} else {
					thirdchoice=2;
				}
				break;
		case 7:
				if(PCS==1){
					firstchoice=3;
				} else if(PCS==2){
					secondchoice=3;
				} else {
					thirdchoice=3;
				}
				break;
		}
	}
	alt_printf("Pick a score from 1, 2 or 3. The score you choose will determine who will be landlord and multiplier\n");
	alt_printf("Make your choice #%d player!",PCS);
	scanf (" %d",&choice);
	printf("your choice is %d\n",choice);
	if(choice==1) {
		sendchar(5|0x40);
		usleep(250);
		if(PCS==1){
			firstchoice=1;
		} else if(PCS==2){
			secondchoice=1;
		} else {
			thirdchoice=1;
		}
	} else if (choice ==2) {
		sendchar(6|0x40);
		usleep(250);
		if(PCS==1){
			firstchoice=2;
		} else if(PCS==2){
			secondchoice=2;
		} else {
			thirdchoice=2;
		}
	} else if(choice == 3) {
		sendchar(7|0x40);
		usleep(250);
		if(PCS==1){
			firstchoice=3;
		} else if(PCS==2){
			secondchoice=3;
		} else {
			thirdchoice=3;
		}
	}
	usleep(250);
	nextPlayer();
	usleep(250);
	incPCS();
	while(PCS!=1){
		recvchar(&opcode);
		usleep(50);
		switch(opcode){
		case 1:
				nextPlayer();
				break;
		case 5:
				if(PCS==1){
					firstchoice=1;
				} else if(PCS==2){
					secondchoice=1;
				} else {
					thirdchoice=1;
				}
				break;
		case 6:
				if(PCS==1){
					firstchoice=2;
				} else if(PCS==2){
					secondchoice=2;
				} else {
					thirdchoice=2;
				}
				break;
		case 7:
				if(PCS==1){
					firstchoice=3;
				} else if(PCS==2){
					secondchoice=3;
				} else {
					thirdchoice=3;
				}
				break;
		}
	}
	alt_printf("current player: %x\n", PCS);
	alt_printf("first player chooses %d\n",firstchoice);
	alt_printf("second player chooses %d\n",secondchoice);
	alt_printf("third player chooses %d\n",thirdchoice);
	return 0;
}