📄 rcvdrvctltask.c
字号:
/*
* description: RcvDrvCtlTask
* Maker : Kamada Satoru
* Copyright : (C)2004,SEIKO EPSON Corp. All Rights Reserved.
*/
#include <string.h>
#include "kernel.h"
#include "SPRSTS.h"
#include "DrvCtlTask.h"
#include "hw_serial.h"
typedef struct _RCV_DATA
{
UCHAR rcvData[COMBUFSZ]; // Message data part
} RCV_DATA;
DRVCTL_MSG* pMsg; // Message area
OS_ER ercd = 0; // Error code
UCHAR i , j , k , l; // Index
UCHAR c = 0; // Character to receive
UCHAR str = 0; // Character to save
stSio sios;
RCV_DATA rcvPastData[RCVDATAMAX]; // String which received past
/*
//=============================================================================
// Function_Name: RcvDrvCtlTask
// description : Receiving driver control task
// argument :
// return :
// flag :
// global :
//=============================================================================
*/
void RcvDrvCtlTask( INT ch )
{
/* Initialize string for receved past */
memset( rcvPastData , 0x00 , sizeof( rcvPastData ) );
/* initialize */
InitSio(ch, (CHAR *) "" );
CtlSio(ch, 0);
RefSio(ch, sios);
for (j = 0 , l = 0 ;;)
{
/* Get memory block */
OS_GetMpf( MPFID_RCV_MSG, (VP)&pMsg );/* Memory pool with fix length for transmitting message use */
/* Received one line */
for (i = 0;;)
{
ercd = GetSio(ch, &c, 100 );
str = c;
/* In case of time out, waiting for receiving */
if (ercd == E_TMOUT)
{
continue;
}
/* In case of buffer is full or return, send mail */
if ((i >= COMBUFSZ - 1) || ( str == '\r' ) || ( str == '\n' ) )
{
break;
}
if( str == 0x1E )
/* Output information inputed past ( Key of upward arrow is pushed ) */
{
/* Don't refer once saving */
if( j == RCVDATAMAX - 1 || j >= l )
{
continue;
}
// Clear output character
for( k = i ; k != 0 ; k--)
{
PutSio(ch, '\b' , 1);
PutSio(ch, ' ' , 1);
PutSio(ch, '\b' , 1);
}
/* Initialize number of charaterc to input */
i = 0;
/* Add pointer of information past */
j++;
/* String which is inputed last time saving & output */
for( k = 0 ; k < COMBUFSZ ; k++)
{
pMsg->pMsgData[ i ] = rcvPastData[ j ].rcvData[ k ];
if ( rcvPastData[ j ].rcvData[ k ] == '\0')
{
break;
}
/* ECHO back */
PutSio(ch, rcvPastData[j].rcvData[ k ] , 1 );
/* Count up number of characters inputed */
i++;
}
}
else if( str == 0x1F )
/* Output information inputed past ( Key of downward arrow is pushed ) */
{
/* No log in case of 0 */
if( l == 0 || j == 0 )
{
continue;
}
// Clear character to output
for( k = i ; k != 0 ; k--)
{
PutSio(ch, '\b' , 1 );
PutSio(ch, ' ' , 1 );
PutSio(ch, '\b' , 1 );
}
/* Initialize number of characters to input */
i = 0;
/* Subtract pointer of information past */
j--;
/* String which is inputed last time saving & output */
for( k = 0 ; k < COMBUFSZ ; k++)
{
pMsg->pMsgData[ i ] = rcvPastData[j].rcvData[ k ];
if ( rcvPastData[j].rcvData[ k ] == '\0')
{
break;
}
/* ECHO back */
PutSio(ch, rcvPastData[j].rcvData[ k ] , 1 );
/* Count up number of characters inputed */
i++;
}
}
/* It is acceptable until 'z' ( Cope with BackSpace and Delete in following process ) */
else if( ( str >= ' ' ) && ( str <= 'z' ) && ( str != '\b' ) )
{
pMsg->pMsgData[ i ] = str;
/* ECHO back */
PutSio(ch, str , 1 );
i++;
}
else if( str == '\b' && i > 0 )
{
/* Cope with Back_Space */
i -= 1;
pMsg->pMsgData[ i ] = '\0';
PutSio(ch, '\b' , 1 );
PutSio(ch, ' ' , 1 );
PutSio(ch, '\b' , 1 );
continue;
}
else
{
/* Do nothing except above */
continue;
}
}
/* Append NULL to the end */
pMsg->pMsgData[ i ] = '\0';
/* Don't save only in case of return */
if ( pMsg->pMsgData[ 0 ] != '\0' )
{
/* Save command */
for( i = RCVDATAMAX ; i >= 2 ; i-- )
{
// Save in string to receive
memset( rcvPastData[ i - 1 ].rcvData , 0x00 , sizeof( rcvPastData[ 0 ].rcvData ) );
memcpy( rcvPastData[ i - 1 ].rcvData , rcvPastData[ i - 2 ].rcvData , sizeof( rcvPastData[ 0 ].rcvData ) );
}
memset( rcvPastData[ 1 ].rcvData , 0x00 , sizeof( rcvPastData[ 1 ].rcvData ) );
memcpy( rcvPastData[ 1 ].rcvData , pMsg->pMsgData , sizeof( pMsg->pMsgData ) ); // Save in string to receive
/* Count up the number of saved characters */
if ( l < 11 )
{
l++;
}
}
/* Clear pointer of past information */
j = 0;
/* Head part */
pMsg->head.useMpfId = MPFID_RCV_MSG;
pMsg->head.msgSndTskId = TSKID_RCV;
pMsg->head.msgNo = 0;
pMsg->head.msgLength = i;
/* Send message */
OS_SndMbx( MBXID_DBG , (T_MSG *)pMsg ); /* Send message */
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -