⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rxtext.c

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 C
📖 第 1 页 / 共 2 页
字号:
				sXferResult.pBufAddr = psRxInfo->pReqAddr;
				psRxInfo->state = TRAN_STATE_READY;		// Waiting for the transmission ready
				psRxInfo->pfnCallback( UART_FUNCM_RCV_TEXT_CMP, wStatus, &sXferResult );
			}
		}else{
			// TRAN_STATE_EXEC_SYNC
			psRxInfo->state = TRAN_STATE_CMP;	// The state is changed without callback at synchronization.
		}

		// Update the receive data
		return STATUS_SUCCESS;
	}

	// Read FIFO data
	//----------------------------
	wRxStatus = UART_IFReadData( ch, (unsigned short)(psRxInfo->wReqSize-psRxInfo->wActSize), psRxInfo->pPutAddr, &wReadSize );
	if( wRxStatus != STATUS_SUCCESS ){
		return STATUS_UNSUCCESSFUL;
	}

	for( i = 0; i < wReadSize; i++ ){

		if( IntRcvCtrlCh > 0 ){
			IntRcvCtrlCh--;
			continue;
		}

		// It judges if there is Backspace
		if( *psRxInfo->pPutAddr  == '\b' ){
			if( psRxInfo->pReqAddr < psRxInfo->pPutAddr ){
				psRxInfo->pPutAddr--;
				psRxInfo->wActSize--;
				*psRxInfo->pPutAddr = '\0';		// Make sure that it is set to NULL.
			}
			continue;
		}

		// It is judged whether there is trailing character.
		if( *psRxInfo->pPutAddr == '\r' || *psRxInfo->pPutAddr == '\n' ){
			// find the ending charactor
			*psRxInfo->pPutAddr = '\0'; // Change to NULL

			// It processes according to the confirmation of the asynchronous or synchronous.
			if( psRxInfo->state == TRAN_STATE_EXEC_TXTASYNC ){
				// ---Asynchronous---
				if( psRxInfo->pfnCallback != NULL ){		// The callback is not notified if pCallbackProc is NULL.
					UART_FUNC_XFER_RESULT sXferResult;
					sXferResult.bChannel = ch;
					sXferResult.wReqSize = psRxInfo->wReqSize;
					sXferResult.wActSize = psRxInfo->wActSize;
					sXferResult.pBufAddr = psRxInfo->pReqAddr;		// Address specified by API call
					psRxInfo->state = TRAN_STATE_READY;		// Waiting for the transmission ready
					psRxInfo->pfnCallback( UART_FUNCM_RCV_TEXT_CMP, STATUS_SUCCESS, &sXferResult );
				}
			}else{
				// --- synchronous ---
				psRxInfo->state = TRAN_STATE_CMP;	// The state is changed without callback at synchronization.
			}

			// When data is received after NULL, saves it in the temp buffer.
			if( (i+1) < wReadSize ){
				// Update data
				psRxInfo->pPutAddr++;
				psRxInfo->wRcvdSize = wReadSize - (i+1);		// i begins from 0,so increases by 1
				memcpy( psRxInfo->pTempBuf, psRxInfo->pPutAddr, psRxInfo->wRcvdSize );
			}
			return STATUS_SUCCESS;
		}
		if( TRUE == IsAsciiCode( *psRxInfo->pPutAddr ) ){
			// Update data
			psRxInfo->wActSize++;
			psRxInfo->pPutAddr++;
		} else {
			// Ignore the control caharactor.
			if( ch != '\t' ){
				// Disregards because it is a control character.
				if( ch == 0x1b ){
					IntRcvCtrlCh = 2;		// 0x1b is three bytecodes. (arrow etc.)
				}else{
					IntRcvCtrlCh = 1;		// Except for the above,They are two bytecodes
				}
			}
		}

	}

	if( psRxInfo->wActSize >= psRxInfo->wReqSize ){
		// --- All the data had been received.---

		// It processes according to the confirmation of the asynchronous or synchronous.
		if( psRxInfo->state == TRAN_STATE_EXEC_TXTASYNC ){
			// ---Asynchronous---
			if( psRxInfo->pfnCallback != NULL ){		// The callback is not notified if pCallbackProc is NULL.
				UART_FUNC_XFER_RESULT sXferResult;
				sXferResult.bChannel = ch;
				sXferResult.wReqSize = psRxInfo->wReqSize;
				sXferResult.wActSize = psRxInfo->wActSize;
				sXferResult.pBufAddr = psRxInfo->pReqAddr;		// Address specified by API call
				psRxInfo->state = TRAN_STATE_READY;		// Waiting for the transmission ready
				psRxInfo->pfnCallback( UART_FUNCM_RCV_TEXT_CMP, STATUS_SUCCESS, &sXferResult );
			}
		}else{
			// --- synchronous ---
			psRxInfo->state = TRAN_STATE_CMP;	// The state is changed without callback at synchronization.
		}
		return STATUS_SUCCESS;;
	}

	return STATUS_SUCCESS;
}


/*
--------------------------------------------------------------------------------
*					  GetRcvBufData
* @brief   Copy the data collected in the internal reception buffer to the specified address.
* @param   unsigned short reqSize 		Number of data to copy
*		   unsigned char* pReqAdd 		The address to cop
* @retval  unsigned short
*		   Number of data actually set to buffer
--------------------------------------------------------------------------------
*/
static unsigned char GetRcvBufData( unsigned short reqSize, unsigned char *pReqAdd, unsigned short* pwActSize, PRX_INFO psRxInfo )
{
	int i,j;
	unsigned char ctrlCh = 0;
	unsigned char ch;
	unsigned char status = STS_SUCCESS;

	UART_DISABLE_INT();				// Disable the interrupt
	if( psRxInfo->wRcvdSize != 0 ){
		// There are receiving data

		if( reqSize <= psRxInfo->wRcvdSize ){
			// --- When all the request data had received. ---
			for( i = 0, j = 0 ; i < reqSize; i++ ){
				ch = *(psRxInfo->pTempBuf + j);

				// Confirm the recept data
				//-----------------------------------

				// Is the control code received?
				if( IntRcvCtrlCh > 0 ){
					// The control code was received in the callback.
					IntRcvCtrlCh--;
					continue;
				}else if( ctrlCh > 0 ){
					// The control code was received in the loop
					ctrlCh--;
					continue;
				}

				if( ch == '\b' ){
					// If it is backspace, return one character.
					psRxInfo->wRcvdSize--;
				} else if( ch == '\r' || ch == '\n' ){
					// If it is changing line or carriage return, converts it into NULL and ends.
					*(pReqAdd + j) = '\0';
					psRxInfo->wRcvdSize--;
					if( psRxInfo->wRcvdSize != 0 ){
						memcpy( psRxInfo->pTempBuf, psRxInfo->pTempBuf + (j+1), psRxInfo->wRcvdSize );
					}
					status = STS_NULL_FOUND;
					break;
				}else if( TRUE == IsAsciiCode( ch ) ){ // --- Judge if it is an ASCII character ---
					// ASCII character
					*(pReqAdd + j) = ch;
					psRxInfo->wRcvdSize--;
					j++;
					psRxInfo->wActSize++;
				}
				else{
					// Control charactor
					if( ch != '\t' ){		// Is it charactor except for tab?
						// Disregards because it is a control character.
						if( ch == 0x1b ){
							ctrlCh = 2;		// 0x1b is three bytecodes. (arrow etc.)
						}else{
							ctrlCh = 1;		// Except for the above,They are two bytecodes
						}
					}
				}
			}

		}else{
			// There are data and not meet the number of required number of data.
			for( i = 0, j = 0; i < reqSize; i++, j++ ){
				ch = *(psRxInfo->pTempBuf + j);
				if( IntRcvCtrlCh > 0 ){
					IntRcvCtrlCh--;
					continue;
				} else if( ctrlCh > 0 ){
					ctrlCh--;
					continue;
				}
				if( ch == '\b' ){
					// If it is backspace, return one character.
					psRxInfo->wRcvdSize--;
				}else if( ch == '\r' || ch == '\n' ){
					// Because the terminal code was discovered before the requered number, API is ended.

					*(pReqAdd + j) = '\0';
					// --- Update the number of data ---
					psRxInfo->wRcvdSize--;
					if( psRxInfo->wRcvdSize != 0 ){
						memcpy( psRxInfo->pTempBuf, psRxInfo->pTempBuf + (j+1), psRxInfo->wRcvdSize );
					}
					status = STS_NULL_FOUND;
					break;
				}else if( TRUE == IsAsciiCode( ch ) ){
					*(pReqAdd + j) = *(psRxInfo->pTempBuf + j);
					psRxInfo->wRcvdSize--;
					psRxInfo->wActSize++;
				} else {
					if( ch != '\t' ){
						// Disregards because it is a control character.
						if( ch == 0x1b ){
							ctrlCh = 2;		// 0x1b is three bytecodes. (arrow etc.)
						}else{
							ctrlCh = 1;		// Except for the above,They are two bytecodes
						}
					}
				}

				if( psRxInfo->wRcvdSize == 0 ){
					// All the interanl buffer had been copied.
					break;
				}
			}
			// --- Update data ----
			psRxInfo->wRcvdSize = 0;
		}
	}
	UART_ENABLE_INT();
	*pwActSize = psRxInfo->wActSize;
	return status;
}

/*
--------------------------------------------------------------------------------
*					  IsAsciiCode
* @brief   Confirm the ASCII code
* @param   unsigned char ch 	: Outside the ASCII string
* @retval  BOOL
*			TRUE : ASCII code
*			FALSE: Not ASCII code
--------------------------------------------------------------------------------
*/
static BOOL IsAsciiCode( unsigned char ch )
{
	if( iscntrl( (int)ch ) != 0 ){
		return FALSE;
	}

	return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -