📄 dataflash.c
字号:
#ifdef _DEBUG
DebugString("the Card SerialNo no found\r\n");
#endif
return FAILURE; //返回未找到
}
unsigned char FoundCardStatusTable(unsigned long lCardSerialNo)
{
unsigned char rst=FAILURE; //函数返回值
#ifdef _DEBUG
DebugString("stOtherTableInfo Data:\r\n");
DebugData(sizeof(sttOtherTableInfo),sizeof(sttOtherTableInfo),(unsigned char *)&stOtherTableInfo);
#endif
//查找挂失临时表
#ifdef _DEBUG
DebugString("查找挂失临时表\r\n");
#endif
rst = IsInCardStatusList(lCardSerialNo,BLACKLIST_TEMP);
if(rst == SUCCESS) return rst; //若在挂失临时表里找到,直接返回
if(rst != FAILURE) return rst; //返回函数操作出错
//查找挂失主表
#ifdef _DEBUG
DebugString("查找挂失主表\r\n");
#endif
rst = IsInCardStatusList(lCardSerialNo,BLACKLIST_MAIN);
if(rst == SUCCESS)
{ //查找解挂临时表
#ifdef _DEBUG
DebugString("查找解挂临时表\r\n");
#endif
rst = IsInCardStatusList(lCardSerialNo,RESUME_LIST);
if(rst == SUCCESS)
return FAILURE; //若在解挂临时表里找到,直接返回
else if(rst == FAILURE) return SUCCESS;
}
return rst; //返回没找到(FAILURE)或函数操作出错
}
//=========================自动充值:充值表部分函数==============================
//读取充值限制信息
//pstFillLimitInfo:返回充值限制信息数据结构指针
//返回:见存贮器返回定义
unsigned char ReadFillLimitInfo(sttFillLimitInfo *pstFillLimitInfo)
{
unsigned int iPage,iAddr;
iPage = FILL_LIMIT_INFO_PAGEADDR;
iAddr = 0;
return Memory_ArrayRead(pstFillLimitInfo,sizeof(sttFillLimitInfo),iPage,iAddr);
}
//写充值限制信息
//pstFillLimitInfo:要写入的充值限制信息数据结构指针
//返回:见存贮器返回定义
unsigned char WriteFillLimitInfo(sttFillLimitInfo *pstFillLimitInfo)
{
unsigned int iPage,iAddr;
unsigned char rst;
#ifdef _DEBUG
for(iPage=0;iPage<30;iPage++)
for(iAddr=0;iAddr<60000;iAddr++);
DebugString("sttFillLimitInfo Data:\r\n");
DebugData(12,12,(unsigned char *)pstFillLimitInfo);
#endif
iPage = FILL_LIMIT_INFO_PAGEADDR;
iAddr = 0;
rst = Write_To_Buffer(pstFillLimitInfo,
sizeof(sttFillLimitInfo),
THE_BUFFER_ONE,iAddr);
if(rst != SUCCESS) return rst;
//把Flash的缓冲区数据存到Flash的存贮区上
return Buffer_To_Mem(THE_BUFFER_ONE,iPage);
}
//读充值信息表信息
//iPageIndex: 包系列号0..20030
//cRecordCount: 记录数
//stFillPara[16/17]:充值信息表数据,偶数页为16条,奇数页为17条
//返回:见存贮器返回定义
unsigned char ReadFillPara(unsigned int iPageIndex,
unsigned char cRecordCount,
sttFillPara stFillPara[])
{
unsigned int iPage,iAddr;
if(iPageIndex % 2)
{
if(cRecordCount > 17) return FORMAT_ERR; //参数错误
iAddr = 128;
}else{
if(cRecordCount > 16) return FORMAT_ERR; //参数错误
iAddr = 0;
}
iPage = iPageIndex + FILL_INFO_START_PAGEADDR;
if(iPage > FILL_INFO_END_PAGEADDR) return FORMAT_ERR; //参数错误
return Memory_ArrayRead(stFillPara,sizeof(sttFillPara) * cRecordCount,iPage,iAddr);
}
//写充值信息表信息
//iPageIndex: 包系列号0..20030
//cRecordCount: 记录数
//stFillPara[16/17]:充值信息表数据,偶数页为16条,奇数页为17条
//返回:见存贮器返回定义
unsigned char WriteFillPara(unsigned int iPageIndex,
unsigned char cRecordCount,
sttFillPara stFillPara[])
{
unsigned int iPage,iAddr;
unsigned char rst;
#ifdef _DEBUG
if(TempCount > 5)
{
for(iPage=0;iPage<30;iPage++)
for(iAddr=0;iAddr<60000;iAddr++);
DebugString("iPageIndex=");DebugData(2,2,(unsigned char*)&iPageIndex);
DebugString("cRecordCount=");DebugData(1,1,&cRecordCount);
DebugString("stFillPara Data:\r\n");
//DebugData(16,8,(unsigned char *)stFillPara);
DebugData(cRecordCount*sizeof(sttFillPara),sizeof(sttFillPara),(unsigned char *)stFillPara);
}
TempCount++;
#endif
iPage = iPageIndex / 2 + FILL_INFO_START_PAGEADDR;
if(iPage > FILL_INFO_END_PAGEADDR) return FORMAT_ERR; //参数错误
if(iPageIndex % 2)
{
if(cRecordCount > 17) return FORMAT_ERR; //参数错误
iAddr = 128;
}else{
if(cRecordCount > 16) return FORMAT_ERR; //参数错误
iAddr = 0;
}
if(iAddr > 0)
{
rst = Mem_To_Buffer(THE_BUFFER_ONE,iPage);
if(rst != SUCCESS) return rst;
}
#ifdef _DEBUG
// DebugString("iPage=");DebugData(2,2,(unsigned char *)&iPage);
// DebugString("iAddr=");DebugData(2,2,(unsigned char *)&iAddr);
#endif
rst = Write_To_Buffer(stFillPara,
sizeof(sttFillPara) * cRecordCount,
THE_BUFFER_ONE,iAddr);
if(rst != SUCCESS) return rst;
//把Flash的缓冲区数据存到Flash的存贮区上
rst = Buffer_To_Mem(THE_BUFFER_ONE,iPage);
stOtherTableInfo.iFillParaTableRecordCount = (iPageIndex / 2) * 33;
if(iPageIndex % 2) stOtherTableInfo.iFillParaTableRecordCount += 16;
if(rst == SUCCESS)
stOtherTableInfo.iFillParaTableRecordCount += cRecordCount;
return rst;
}
//查找指定卡流水号的充值信息数据
//pstFillPara:传入的卡流水号和返回的具体充值信息数据
//piOffSet: 返回当前卡流水号的充值信息数据所处的位置
//返回:见存贮器返回定义
unsigned char FoundFillPara(sttFillPara *pstFillPara,unsigned int *piOffSet)
{
unsigned int iPage; //页地址
unsigned int iAddr; //页内地址
short iMin,iMax; //此处必须用符号数
unsigned int iMid;
char rst;
sttFillPara xdata stFillParaTemp;
/* for(iPage = FILL_INFO_START_PAGEADDR;iPage < FILL_INFO_START_PAGEADDR + 4; iPage ++)
{
iAddr = 0;iMid=128;
DebugString("iPage=");DebugData(2,2,(unsigned char*)&iPage);
DebugString("iAddr=");DebugData(2,2,(unsigned char*)&iAddr);
rst=Memory_ArrayRead(UART_SendBuffer,iMid,iPage,iAddr);
if(rst == SUCCESS)
DebugData(iMid,8,UART_SendBuffer);
else
DebugString("Read Memory Error\r\n");
iAddr = 128;iMid=136;
DebugString("iPage=");DebugData(2,2,(unsigned char*)&iPage);
DebugString("iAddr=");DebugData(2,2,(unsigned char*)&iAddr);
rst=Memory_ArrayRead(UART_SendBuffer,iMid,iPage,iAddr);
if(rst == SUCCESS)
DebugData(iMid,8,UART_SendBuffer);
else
DebugString("Read Memory Error\r\n");
}
*/
#ifdef _DEBUG
DebugString("sttFillPara Data:");
DebugData(8,8,(unsigned char*)pstFillPara);
DebugString("充值信息表记录数:");
DebugData(2,2,(unsigned char *)&stOtherTableInfo.iFillParaTableRecordCount);
#endif
iMax = stOtherTableInfo.iFillParaTableRecordCount;
iMin = 0;
while(iMin < iMax) //判断终止条件
{
iMid = ((unsigned int)iMin + (unsigned int)iMax) / 2; //中折
iPage = FILL_INFO_START_PAGEADDR
+ iMid / FILL_INFO_PAGE_MAX_RECORD_COUNT;
iAddr = iMid % FILL_INFO_PAGE_MAX_RECORD_COUNT
* sizeof(sttFillPara);
#ifdef _DEBUG
DebugString("iMax=");DebugData(2,2,(unsigned char *)&iMax);
DebugString("iMin=");DebugData(2,2,(unsigned char *)&iMin);
DebugString("iMid=");DebugData(2,2,(unsigned char *)&iMid);
DebugString("iPage=");DebugData(2,2,(unsigned char *)&iPage);
DebugString("iAddr=");DebugData(2,2,(unsigned char *)&iAddr);
#endif
rst = Memory_ArrayRead(&stFillParaTemp,sizeof(sttFillPara),iPage,iAddr);
if(rst != SUCCESS)
{
#ifdef _DEBUG
DebugString("Read Order Dinner Parameter From DataFlash Error.\r\n");
#endif
return rst; //出错返回
}
#ifdef _DEBUG
DebugString("Current Record Data:");
DebugData(8,8,(unsigned char*)&stFillParaTemp);
#endif
rst = memcmp(pstFillPara->CardIndex, stFillParaTemp.CardIndex, 3);
if(rst == 0)
{
memcpy(pstFillPara,&stFillParaTemp,sizeof(sttFillPara));
*piOffSet = iMid;
return SUCCESS;
}
else if(rst > 0) iMin = iMid + 1; else iMax = iMid;
}
return UNALLOWED_CARDCLASS;
}
//更新充值表信息状态字为已充值状态
//iOffSet:要修改的记录偏移量,即当前记录位置
unsigned char UpdateFillParaStatus(unsigned int iOffSet)
{
unsigned int idata iPage,iAddr;
unsigned char rst,i;
iPage = FILL_INFO_START_PAGEADDR
+ iOffSet / FILL_INFO_PAGE_MAX_RECORD_COUNT;
iAddr = iOffSet % FILL_INFO_PAGE_MAX_RECORD_COUNT
* sizeof(sttFillPara) + sizeof(sttFillPara) - 1;
for(i=0;i<3;i++)
{
rst = Mem_To_Buffer(THE_BUFFER_ONE,iPage);
if(rst != SUCCESS) continue;
rst = 0;
rst = Write_To_Buffer(&rst,1,THE_BUFFER_ONE,iAddr);
if(rst != SUCCESS) continue;
//把Flash的缓冲区数据存到Flash的存贮区上
rst = Buffer_To_Mem(THE_BUFFER_ONE,iPage);
if(rst != SUCCESS) continue;
}
return rst;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -