コード例 #1
0
ファイル: recv.c プロジェクト: eswartz/emul
/*
	Get a string.  Return 0 if okay.
*/
int	gs(char *s)
{
	int	ch;
	int	p;
	unsigned len;



//	len=bioscom(_COM_RECEIVE,0,port);
	len=com_read();
	if (len>=256)
		return 1;

	p=0;
	while (len)
	{
		if (kbhit())
		{
			printf("\nUser break\n");
			return 1;
		}
//		ch=bioscom(_COM_RECEIVE,0,port);
		ch=com_read();
		if (len>=256)
			return 1;
		s[p]=ch;
		p++;
		len--;
	}
	s[p]=0;

	return	0;
}
コード例 #2
0
ファイル: comapi.c プロジェクト: zhangbo7364/terminal
int recive(void*com, unsigned char*recbuf) {
	int reclen = 0;
	int i = 0;
	while (reclen < standlen) {
		currentlen = com_read(com, currentrec, 1024);
		if (currentlen == 0) {
			Sleep(20);
			i++;
			if (i == 10) {
				return 0;
			}
		}

		if (currentlen > 0) {
			memcpy(recbuf + reclen, currentrec, currentlen);
			reclen += currentlen;
			memset(currentrec, 0x00, 1024);
			currentlen = 0;
		}

	}

//	printf("rec=%s,len=%d", recbuf, reclen);
	return reclen;
}
コード例 #3
0
ファイル: R3.C プロジェクト: sam91wvu/undergradWVU
void ProcessIORequest(int device){
	if(device == 1){
		if(TerminalQueue->head->requestType == READ){
			trm_read(TerminalQueue->head->buffer, TerminalQueue->head->count);
		}else if(TerminalQueue->head->requestType == WRITE){
			trm_write(TerminalQueue->head->buffer, TerminalQueue->head->count);
		}else if(TerminalQueue->head->requestType == CLEAR){
			trm_clear();
		}else if(TerminalQueue->head->requestType == GOTOXY){
			trm_gotoxy(0,0);
		}
	}else if(device == 2){
		if(Com_PortQueue->head->requestType == READ){
			com_read(Com_PortQueue->head->buffer, Com_PortQueue->head->count);
		}else if(Com_PortQueue->head->requestType == WRITE){
			com_write(Com_PortQueue->head->buffer, Com_PortQueue->head->count);
		}
	}
}
コード例 #4
0
ファイル: serial.c プロジェクト: Ringdingcoder/d1x
int com_readline(int timeout_value, char *input_buffer,int len)
{
 char c;
 int j;
 int i=0;
 struct timeval timeout;
 fd_set set;

 if (timeout_value>0) {
 /* Initialise the file descriptor set */
 FD_ZERO(&set);
//edited 03/05/99 Matt Mueller - allow reading from different device
 FD_SET (rfd, &set);
//end edit -MM

 /* Initialise the timeout timer value */
 timeout.tv_sec=timeout_value / 1000;
//edited 02/06/99 Matt Mueller - microseconds, not milliseconds
 timeout.tv_usec=(timeout_value % 1000) * 1000;
//end edit -MM
	 
 j=select(FD_SETSIZE, &set, NULL, NULL, &timeout);
 if (j==0) return 0;
 }
 
 do {
//  j=com_read(&c,1,0);
  j=com_read(&c,1,timeout_value);
  if (isprint(c) && (j>0)) {
   input_buffer[i++]=c;
   if (i>=len) return i;
  }
 } while (c!='\n');
 input_buffer[i]=0;
 return i;
}
コード例 #5
0
ファイル: Packet.c プロジェクト: jinfeng-geeya/3202C
/****************************************************************************
 *
 *  Name:		packet_receive
 *	Function:	receive a packet
 *	variable:	pPacket 	-- packet information point
 *				nTimeOut	-- time out   
 *  
 ****************************************************************************/
UINT32 packet_receive(PPACKET pPacket, UINT32 nTimeOut)
{
	//receive and compare packet head flag
	unsigned char c = 0;
	BOOL bPacketHead = FALSE;
	BOOL bComtest = FALSE;
	UINT32 i = 0;
	int n = 0;
	UINT32 nLength = 0;
	MEMSET(pPacket, 0, sizeof(PACKET));
	for(i = 0; i < nTimeOut;)
	{
		if( c == 'H')
		{
			// judge if packet head
			for(n = 0; n < 3; n++)
			{
				if(SUCCESS != com_read_tm(&c, 1, 1))
				{
					c = 0;
					break;
				}
				if(c != l_packet_head_flag[n + 1])
					break;
			}

			if(n == 3)
			{
				bPacketHead = TRUE;
				break;
			}
		}
		else if(c == 'c')
		{
			pPacket->data_buffer[0] = 'c';
			LIB_ASH_OC(c);
			//judge if comtest
			for(n = 0; n < 6; n++)
			{
		//		c = LIB_ASH_IC();
				if(SUCCESS != com_read_tm(&c, 1, 100))
				{
					c = 0;
					SH_PRINTF("comtest not all : %d\n", n);
					break;
				}
				if(c != l_packet_comtest[n + 1])
					break;
				LIB_ASH_OC(c);
				
			}

			if(n == 6)
			{
				SH_PRINTF("RECEIVE comtest\n");
				bComtest = TRUE;
				break;
			}

		}
		else if(SUCCESS != com_read(&c, 1))
		{
			Sleep(1);
			i++;
		}	
		
	}

	
	if(bPacketHead)
	{
		//receive packet head
		unsigned char packet_head[PACKET_HEAD_LEN];
		if(SUCCESS != com_read_tm(packet_head + PACKET_TYPE_OFFSET, PACKET_HEAD_LEN - 4, 1000))
		{
			SH_PRINTF("ERROR:receive head error");
			return ERROR_PACKET_RECEIVEHEAD;
		}
		
		//compare CRC about packet head
		UINT32 nCRC = MG_Table_Driven_CRC(0xFFFFFFFF, packet_head + PACKET_TYPE_OFFSET, PACKET_HEAD_LEN - 8);
		if(nCRC != fetch_long(packet_head + PACKET_HEAD_CRC_OFFSET))
			return ERROR_PACKET_HEADCRC;
		
		MakePacketHead(packet_head, pPacket);

		//Receive data and CRC
		nLength = pPacket->packet_length;
	
		// if blank packet receive 4B packet number only
		if(0 != pPacket->blank_flag && PACKET_DATA == pPacket->packet_type)
			nLength = 4;
		
		if(SUCCESS != com_read_tm(pPacket->data_buffer, nLength + 4, 1000))
			return ERROR_PACKET_RECEIVEDATA;

		nCRC = MG_Table_Driven_CRC(0xFFFFFFFF, pPacket->data_buffer, nLength);
		if(nCRC != fetch_long(pPacket->data_buffer + nLength))
			return ERROR_PACKET_DATACRC;
		if(PACKET_DATA == pPacket->packet_type)
		{
			if(1 == pPacket->blank_flag)
				memset(pPacket->data_buffer + 4, 0xFF, pPacket->packet_length - 4);
			else if(2 == pPacket->blank_flag)
				memset(pPacket->data_buffer + 4, 0x00, pPacket->packet_length - 4);
		}
	}
	else if(bComtest)
	{
		pPacket->packet_type = PACKET_COMMAND;
		MEMCPY(pPacket->data_buffer, l_packet_comtest, 7);
		i = 7;
		while(i < 128)
		{
			pPacket->data_buffer[i] = LIB_ASH_IC();
			c = pPacket->data_buffer[i];
			LIB_ASH_OC(c);
			if (c == 0x0D || c == 0x0A)
		            break;			
			i++;
		}

		pPacket->packet_length = STRLEN(pPacket->data_buffer);
//		for(i = 0; i < pPacket->packet_length; i++)
//			LIB_ASH_OC(pPacket->data_buffer[i]);
	
       	SH_PRINTF(pPacket->data_buffer);
		
		g_packet_index = 0;
		g_packet_repeat = 0;
		
	}	
	else
		return ERROR_NOPACKETRECEIVE;
	
	return SUCCESS;
}
コード例 #6
0
ファイル: testcomr.c プロジェクト: fatMusketeer2/mpx1
void main()
{
	int e_flag;	/* event flag */
	int rc;		/* function return code */
	char buffer[BUFLEN+2];	/* general buffer */
	char prompt[BUFLEN+2];	/* prompt buffer */
	int prlen;
	int length;
	long tstart;

	/* open com port */
	rc = com_open( (int*) &e_flag, 1200);
	if ( rc != 0) {
		printf("\nOPEN failed!\n");
 		printf("error code = %d\n",rc);
		abort_test();
	}


	/* setup prompt string */
	strcpy(prompt, "\r\nEnter string: ");
	prlen = strlen(prompt);

	/* prompt and read until "quit" is typed */
	buffer[0] = NULCH;
	while (strcmp(buffer,"quit\r\n") != 0) {

		/* display the prompt */
		e_flag = 0;
		rc = com_write((char*) prompt, (int*) &prlen);
		if (rc != 0) {
			printf("\nerror displaying prompt!\n");
			printf("error code = %d\n",rc);
			abort_test();
		}

		/* loop until output is done */
		tstart = time(NULL);
		while (e_flag == 0) {
			if ((time(NULL) - tstart) > WR_TIME_LIMIT) {
				printf("\ntimeout on prompt\n");
				printf("event flag not set\n");
				exit();
			}
		}

		/* read a string */
		length = BUFLEN-1;
		e_flag = 0;
		rc = com_read((char*) buffer, (int*) &length);
		if (rc != 0) {
			printf("\nerror reading string!\n");
			printf("error code = %d\n",rc);
			abort_test();
		}

		/* loop until input is done */
		tstart = time(NULL);
		while (e_flag == 0) {
			if ((time(NULL) - tstart) > RD_TIME_LIMIT) {
				printf("\ntimeout on input\n");
				printf("event flag not set\n");
				abort_test();
			}
		}


		/* display the input string */
		e_flag = 0;
                if (buffer[length-1] == '\n') {
                   buffer[length-1] = NULCH;
                   length--;
                }
                strcat(buffer,"\r\n");
                length = length + 2;

		printf("%s",buffer);

		rc = com_write((char*) buffer, (int*) &length);
		if (rc != 0) {
			printf("\nerror displaying string!\n");
			printf("error code = %d\n",rc);
			abort_test();
		}

		/* loop until output is done */
 		tstart = time(NULL);
		while (e_flag == 0) {
			if ((time(NULL) - tstart) > WR_TIME_LIMIT) {
				printf("\ntimeout on output\n");
				printf("event flag not set\n");
				abort_test();
			}
		}

	} /* end of while loop */

	/* print final message */
	e_flag = 0;
	length = 29;
	printf("\nEnd of Com Driver IO Test\n");
	rc = com_write((char*) "\r\nEnd of Com Driver IO Test\r\n",
				(int*) &length);
	if (rc != 0) {
		printf("\nWRITE error on final message!\n");
		printf("error code = %d\n",rc);
		abort_test();
	}

	/* loop until output is done */
 	tstart = time(NULL);
	while (e_flag == 0) {
		if ((time(NULL) - tstart) > WR_TIME_LIMIT) {
			printf("\ntimeout on final message\n");
			printf("event flag not set\n");
			abort_test();
		}
	}

	/* close the com port */
	rc = com_close();
	if ( rc != 0) {
		printf("\nCLOSE failed!\n");
 		printf("error code = %d\n",rc);
		exit();
	}

	printf("Test completed successfully!\n");

}