Exemple #1
0
/*
从可使用改成已使用,即0---->1
ucKeyFileID: 密钥所在的文件ID
uiRecID: 密钥所在的记录号

步骤:
1、通过记录号,读取该记录,得到原密钥状态位
2、若该密钥可使用,则修改其状态位,写FLASH
3、若该密钥已使用,则不做修改,返回失败
成功返回EM_SUCCESS, 失败返回EM_ERROR
*/
uchar ucChageState(uchar ucKeyFileID,uint uiRecID)
{
    //先读出,后改写
    uchar ucKeyInfo[50];
    uchar ucRet;
    uint uiRecCntW;
    ucRet = EA_ucPFReadRec(ucKeyFileID, uiRecID, 1, &uiRecCntW, ucKeyInfo);

    if(ucRet != EM_SUCCESS)
    {
        PubClearAll();
        PubDisplayInv(1, "错误");
        PubDisplayCen(2, "读取该记录失败");

        PubuiInkey(3);
        return EM_ERROR;
    }
    if(ucKeyInfo[48] == '0')  //原状态可使用
    {
        ucKeyInfo[48] = '1';
    }
    else
    {
        PubClearAll();
        PubDisplayInv(1, "错误");
        PubDisplayCen(2, "该记录不可使用");

        PubuiInkey(3);
        return EM_ERROR;
    }

    ucRet = EA_ucPFWriteRec( ucKeyFileID, uiRecID, ucKeyInfo);
    if(ucRet != EM_SUCCESS )
    {
        PubClearAll();
        PubDisplayInv(1, "错误");
        PubDisplayCen(2, "改写该记录失败");

        PubuiInkey(3);
        return EM_ERROR;
    }
    return EM_SUCCESS;
}
Exemple #2
0
// *****************************************************************
// 功能:		QUERY_NOTE_RECORD
// 说明:		查询日结小票
// 入口参数:	
// 出口参数:	Null
// 作者:
// 返回值:	-1 关机				
// *****************************************************************
int QUERY_NOTE_RECORD(void)
{
	int         count;
	INT32U      RecordCount = 0;
	uchar       uckey; 
	uint        uikey; 
	uchar 		ucOpenID=0;
	INT8U 		rec[60];

	memset(rec, 0, sizeof(rec));

	if ( EA_ucPFOpen( (uchar *)hisrecFileName, &ucOpenID) != EM_ffs_SUCCESS )
	{
		lcddisperr("打开日结文件失败");
		return 0;
	}
	// 获取有效信息条数
	(void)EA_ucPFInfo(ucOpenID, EM_ffs_VALIDREC, &RecordCount);
	if( RecordCount == 0)
	{
		lcddisperr("没有日结信息");
		(void)EA_ucPFClose(ucOpenID);
		return 0;//表示没有记录
	}
	count = RecordCount;//最后一条		

	if(EA_ucPFReadRec(ucOpenID, count, 1, &RecordCount, rec) != EM_SUCCESS)
	{
		(void)EA_ucPFClose(ucOpenID);
		lcddisperr((void *)"读取不符合");
		return 0;
	}

	AnalyAndDisplayNote(rec);

	while ( 1 )
	{
		uckey = EA_ucKBHit();
		if(uckey == EM_key_HIT)    //有按键
		{
			uikey = EA_uiInkey(0);    //读取按键键值
			if ( (uikey == EM_key_EXIT) || (uikey == EM_key_CANCEL) )			//退出
			{
				(void)EA_ucPFClose(ucOpenID);
				return 1;
			}
			switch ( uikey )
			{
				case EM_key_UP:	//	按[2]键或往上拨动拨轮则屏幕往上滚动一行
					count --;
					if ( count < 0 )//记录超限
					{
						lcddisperr("最后一条");
						count ++;
					}
					break;

				case EM_key_DOWN:	//	按[8]键或往下拨动拨轮则屏幕往下滚动一行
					count ++;
					if ( count >= RecordCount )
					{
						lcddisperr("最后一条");
						count --;
					}
					break;
				case EM_key_ENTER:
					break;
				default:
					break;
			}

			if ( (uikey==EM_key_UP) || (uikey==EM_key_DOWN)  )
			{
				if(EA_ucPFReadRec(ucOpenID, count, 1, &RecordCount, rec) != EM_SUCCESS)
				{
					(void)EA_ucPFClose(ucOpenID);
					lcddisperr((void *)"读取不符合");
					return 0;
				}
				AnalyAndDisplayNote(rec);
			}

			if(uikey == EM_key_ENTER)
			{
				print_work_note_his(rec);
				(void)EA_ucPFClose(ucOpenID);
				return 1;
			}			
		}
	}
}
Exemple #3
0
uchar EA_ucEfsRead(uint uiOpenID, uint uiRecBeginID, uint uiRecordNum,uchar *pvReadBuff, uint *puiReadNumber)
{
	return EA_ucPFReadRec(uiOpenID , uiRecBeginID , 1 , puiReadNumber , pvReadBuff);
}
Exemple #4
0
/*
ucKeyInfo[n] : 商户号+终端号+密钥密文+KEK索引
n = 48
ucKeyFileID:密钥文件ID
将ucKeyInfo[n]+(初始状态位)0 构造成一条密钥记录,写入文件

步骤:
1、利用 商户号+终端号 搜索密钥文件中是否存在本记录;
   构造密钥记录,初始化状态位。
2、若存在该记录,且其他信息一致,跳过,不写FLASH。
3、若不存在该记录,或记录不存在,覆盖或添加该记录。
4、成功返回 EM_SUCCESS, 错误返回 EM_ERROR.
*/
uchar ucFileOp(uchar ucKeyFileID,uchar ucKeyInfo[])
{

    uchar ucResult,ucRet;   //返回API函数的结果
    ushort usLen,usOffset;  //用于搜索
    uchar ucSearchArr[23];  //存放 商户号+终端号,用于搜索
    uchar ucBuff[30];       //搜索关键字格式

    uint iIndex;          //用于循环
    uint uiRecID;        //记录号
    uchar ucRecInfo[50]; //ucKeyInfo[]+1字节的状态字(初始为0x00)

    //用于读取文件参数
    uint uiRecCntW;
    uchar ucString[50];

    //搜索是否有同一 (商户号+终端号)
    for( iIndex = 0; iIndex < 23; iIndex++)
        ucSearchArr[iIndex] = ucKeyInfo[iIndex];


    //先构造搜索关键字
    usLen = 23; // 要查找数据的长度 An23: 商户号An15 + 终端号An8

    usOffset = 0; // 从版本号 N4 字符串后面开始,strlen("0001")

    memcpy(ucBuff, &usLen, sizeof(ushort)); // 拷贝要查找的关键字长度

    memcpy(&ucBuff[sizeof(ushort)], &usOffset, sizeof(ushort)); // 拷贝要查找数据在记录中的偏移

    memcpy(&ucBuff[2*sizeof(ushort)], ucSearchArr, usLen); // 拷贝要查找的关键字

    usOffset = 0;      // 结束查找数据
    memcpy(&ucBuff[2*sizeof(ushort)+usLen], &usOffset, sizeof(ushort));

    //构造一条记录内容
    for( iIndex = 0; iIndex < 50; iIndex++)
        ucRecInfo[iIndex] = ucKeyInfo[iIndex];
    ucRecInfo[48] = '0';

    uiRecID=0;
    //从文件头信息文件中 第一条记录 开始查找
    ucResult =EA_ucPFFindRec( ucKeyFileID, 1, ucBuff, &uiRecID);

    //存在该记录
    if((ucResult == EM_SUCCESS && uiRecID != 0))
    {

        //读取该记录
        ucRet = EA_ucPFReadRec(ucKeyFileID, uiRecID, 1, &uiRecCntW, ucString);

        if(ucRet == EM_SUCCESS)
        {
            iIndex = memcmp(ucString,ucRecInfo,50); //比较密钥文件中记录是否与欲存记录一致
            if(iIndex == 0)  //一致
            {
                return EM_SUCCESS;
            }
        }
    }
    //欲存密钥记录与原记录不一致,则覆盖
    if((ucResult == EM_SUCCESS && uiRecID != 0) || ucResult == EM_ffs_NOTFIND || ucResult == EM_ffs_INPUTERR )
    {
        /*if( ucResult == EM_ffs_NOTFIND && ucCheckPF(ucKeyFileID) != EM_SUCCESS)
        {
        	//关闭文件
        	ucResult = EA_ucPFClose( ucKeyFileID );
        	return EM_ERROR;
        }*/
        //修改原有记录 或 将该记录添加(uiRecID == 0)
        if(EA_ucPFWriteRec(ucKeyFileID, uiRecID, ucRecInfo) != EM_SUCCESS)
        {
            PubClearAll();
            PubDisplayInv(1, "错误");
            PubDisplayCen(2, "写FLASH失败");
            PubuiInkey(3);
            //关闭文件
            ucResult = EA_ucPFClose( ucKeyFileID );
            return EM_ERROR;
        }
    }
    else
    {
        PubClearAll();
        PubDisplayInv(1, "错误");
        //其他出错
        if(ucResult == EM_ffs_CHECKERR)
            PubDisplayCen(2,"文件系统内存变量校验出错");
        if(ucResult == EM_ffs_FLASHERR)
            PubDisplayCen(2,"flash坏");
        if(ucResult == EM_ffs_NOTFMT)
            PubDisplayCen(2,"未格式化");
        if(ucResult == EM_ffs_SYSCLP)
            PubDisplayCen(2,"文件系统崩溃");
        if(ucResult == EM_ffs_NOTOPEN)
            PubDisplayCen(2,"未打开文件");
        if(ucResult == EM_ffs_INPUTERR)
            PubDisplayCen(2,"输入错误");

        PubuiInkey(3);
        //关闭文件
        ucResult = EA_ucPFClose( ucKeyFileID );
        return EM_ERROR;
    }
    return EM_SUCCESS;
}
Exemple #5
0
/*
ucKeyFileID : 密钥文件ID
ucBossNo[] : 商户号,有效长度15
ucTermNo[] : 终端号,有效长度8

返回值
uiRecID : 记录号(第几组密钥)
uiState : 状态,0表示可用,1表示已用
uiKEKIndex :  KEK索引
ucKeyInfo[] : 密钥信息,有效长度24

步骤:
1、通过 商户号+终端号,搜索密钥文件是否存在该记录,返回记录号uiRecID
2、若存在该记录,读取该记录信息。返回 EM_SUCCESS
3、若不存在该记录,返回 EM_ERROR
*/
uchar ucKeyExtract(uchar ucKeyFileID,uchar ucBossNo[],uchar ucTermNo[],uint *uiRecID,uint *uiState,uint *uiKEKIndex, uchar ucKeyInfo[] ,uchar * ucTMKIndex)
{
    uchar ucResult;         //返回API函数的结果
    ushort usLen,usOffset;  //用于搜索
    uchar ucSearchArr[23];  //存放 商户号+终端号,用于搜索
    uchar ucBuff[30];       //搜索关键字格式

    uint iIndex;          //用于循环
    uchar ucRecInfo[100]; //ucKeyInfo[]+1字节的状态字(初始为0x00)
    uint uiRecCntW;
    uint uiTmkIndex;

    //搜索是否有同一 (商户号+终端号)
    for( iIndex = 0; iIndex < 15; iIndex++)
        ucSearchArr[iIndex] = ucBossNo[iIndex];
    for( iIndex = 0; iIndex < 8; iIndex++)
        ucSearchArr[15 + iIndex] = ucTermNo[iIndex];

    //先构造搜索关键字
    usLen = 23; // 要查找数据的长度 An23: 商户号An15 + 终端号An8

    usOffset = 0; // 从版本号 N4 字符串后面开始,strlen("0001")

    memcpy(ucBuff, &usLen, sizeof(ushort)); // 拷贝要查找的关键字长度

    memcpy(&ucBuff[sizeof(ushort)], &usOffset, sizeof(ushort)); // 拷贝要查找数据在记录中的偏移

    memcpy(&ucBuff[2*sizeof(ushort)], ucSearchArr, usLen); // 拷贝要查找的关键字

    usOffset = 0;      // 结束查找数据
    memcpy(&ucBuff[2*sizeof(ushort)+usLen], &usOffset, sizeof(ushort));

    *uiRecID=0;
    //从文件头信息文件中 第一条记录 开始查找
    ucResult =EA_ucPFFindRec( ucKeyFileID, 1, ucBuff, uiRecID);

    if( ucResult == EM_SUCCESS && uiRecID != 0 )
    {
        //读取记录信息
        if(EA_ucPFReadRec( ucKeyFileID, *uiRecID, 1, &uiRecCntW, ucRecInfo) ==EM_SUCCESS)
        {
            //提取记录信息供返回

            //状态
            *uiState = ucRecInfo[48] - '0';

            //KEY索引
            *uiKEKIndex = ucRecInfo[47]/16*10 + ucRecInfo[47] % 16;
            uiTmkIndex = ucRecInfo[49]/16*10 + ucRecInfo[49] % 16;
            sprintf(ucTMKIndex , "%02d" , uiTmkIndex);
#ifdef SET_DEBUG
            PubDisplay(1 , "[%ld]tmk[%ld]", *uiKEKIndex ,uiTmkIndex );
            PubDisplay(2 , "[%02x][%02x]" , ucRecInfo[47] , ucRecInfo[49]);
            PubuiInkey(0);
#endif

            //密钥密文
            for( iIndex = 0; iIndex < 24; iIndex++)
                ucKeyInfo [iIndex] = ucRecInfo [23 + iIndex];
        }

    }
    else if( ucResult == EM_ffs_NOTFIND || ucResult == EM_ffs_INPUTERR)
    {
        //记录未找到,或者输入参数错误
        PubClearAll();
        PubDisplayInv(1, "错误");
        PubDisplayCen(3,"没有找到匹配的密钥");

        PubuiInkey(3);
        return EM_ERROR;
    }
    else
    {
        //其他出错
        PubClearAll();

        if(ucResult == EM_ffs_CHECKERR)
            EA_vDisplay(4,"内存变量校验出错");
        if(ucResult == EM_ffs_FLASHERR)
            EA_vDisplay(4,"flash坏");
        if(ucResult == EM_ffs_NOTFMT)
            EA_vDisplay(4,"未格式化");
        if(ucResult == EM_ffs_SYSCLP)
            EA_vDisplay(4,"文件系统崩溃");
        if(ucResult == EM_ffs_NOTOPEN)
            EA_vDisplay(4,"未打开文件");

        PubuiInkey(3);
        //关闭文件
        ucResult = EA_ucPFClose( ucKeyFileID );
        return EM_ERROR;
    }
    return EM_SUCCESS;
}