kb_dc_dataparse.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:8k
- //-----------------------------------------------------------------------------
- // Project include files:
- //-----------------------------------------------------------------------------
- #include "kb_dc_pub.h"
- DCDIR *gDCDir = NULL;
- DCFILE *gDCFile = NULL;
- unsigned long gDcTimeOut = 0;
- void ResetTimeOut(void)
- {
- gDcTimeOut=0;
- }
- //-----------------------------------------------------------------------------
- // FUNCTION: SetDCDIR
- //
- // DESCRIPTION: 设置当前DIR
- //
- // RETURN:
- //
- // NOTES: None
- //-----------------------------------------------------------------------------
- void SetDCDIR(DCDIR *dir)
- {
- gDCDir=dir;
- }
- //-----------------------------------------------------------------------------
- // FUNCTION: GetDCDIR
- //
- // DESCRIPTION: 获得当前DIR
- //
- // RETURN:
- //
- // NOTES: None
- //-----------------------------------------------------------------------------
- pDCDIR GetDCDIR()
- {
- return gDCDir;
- }
- //-----------------------------------------------------------------------------
- // FUNCTION: SetDCFILE
- //
- // DESCRIPTION: 设置当前文件指针
- //
- // RETURN:
- //
- // NOTES: None
- //-----------------------------------------------------------------------------
- void SetDCFILE(DCFILE *file)
- {
- gDCFile=file;
- }
- //-----------------------------------------------------------------------------
- // FUNCTION: GetDCFILE
- //
- // DESCRIPTION: 获得当前的文件指针
- //
- // RETURN:
- //
- // NOTES: None
- //-----------------------------------------------------------------------------
- pDCFILE GetDCFILE( )
- {
- return gDCFile;
- }
- //-----------------------------------------------------------------------------
- // FUNCTION: ParseDIISection
- //
- // DESCRIPTION: DII section pareser
- //
- // RETURN: None
- //
- // NOTES:
- //-----------------------------------------------------------------------------
- int ParseDIISection(const char* fileName,unsigned char *buf,unsigned long length)
- {
- DCFILE *file;
- DCDIR *dir;
-
- // 获得dir 结构
- dir = OpenDirectory(buf,(int)length);
- if(dir==NULL)
- {
- DCDebug1("n OpenDirectory error");
- return 0;
- }
-
- SetDCDIR(dir);
- dir = GetDCDIR();
-
- //根据filename解析生成file
- file=DcOpenFile(dir,fileName);
- if(file==NULL)
- {
- DCDebug1("n DcOpenFile error");
- return 0;
- }
- SetDCFILE(file);
-
- return 1;
- }
- //-----------------------------------------------------------------------------
- // FUNCTION: ParseModuleDDBSection
- //
- // DESCRIPTION: 解析一个module的所有DDB数据
- //
- // RETURN: None
- //
- // NOTES:
- //-
- int ParseModuleDDBSection(unsigned char *buf,unsigned int firstmodId)
- {
- DDBHead head;
- unsigned char *data,*pTemp;
- int length;
- DCFILE *file;
- unsigned int modId, index;
- file=GetDCFILE();
- if(file==NULL) return 0;
- // get ddb data
- GetDDBHead(buf,&head);
- modId = head.moduleID;
- data = GetDDBData(buf,&length);
- file->position+=length;
- if(head.blockNumber>255||head.blockNumber>=file->BufStatus.modStat[index].blockCount)
- {
- DCDebug1("n head.blockNumber[%d] out of range", head.blockNumber);
- return 0;
- }
- DCDebug2("nnthe blockNumber is %d,the length is %d of moduleid:%d n",head.blockNumber,length,modId);
- DCDebug4("nnow the file.position is %dn",file->position);
- //the data will be written into the file->section structure in cycle
- pTemp=(file->section) + (head.blockNumber)*(4066);
- KBDcMemcpy((void*)pTemp,(const void*)data,(size_t)length);
- //填充buffer 状态
- index = modId - firstmodId;
- if(file->BufStatus.modcount>0&&file->BufStatus.modStat!=NULL)
- {
- if(file->BufStatus.modStat[index].blockCount>0&&file->BufStatus.modStat[index].blockStat!=NULL)
- {
- file->BufStatus.modStat[index].blockStat[head.blockNumber] = FILLED;
- }
- }
- return 1;
- #if 0
- PrintfDDBData(data,length,head.blockNumber);
- printf("nn------------------n");
- PrintfDDBData(((file->section) + (head.blockNumber)*(4066)), length, head.blockNumber);
- #endif
-
- }
- //----------------------------------------------------------------------------
- // DESCRIPTION: 解析一个文件所包含的所有DDB数据,它调用ParseModuleDDBSection()
- //-
- int ParseALLDDBSection(unsigned char *buf,unsigned int firstModId)
- {
- unsigned int DDBOfmoduleId;
- DCFILE *file;
- DDBHead head;
- int filemodNum = 0;
- int index = 0;
- file = GetDCFILE();
- if(file==NULL)
- {
- DCDebug1("n file or is NULL!!!");
- return -4;
- }
- GetDDBHead(buf,&head);
- DDBOfmoduleId = head.moduleID;
- filemodNum = DCGetModNumByFile(file);
- if(filemodNum<0)
- {
- DCDebug1("n DCGetModNumByFile error!!!");
- return -3;
- }
- // 判断该DDB是否是在制定文件所包含的module范围内
- // 如果不是,则不作任何处理
- // 判断一个DDB是否已经接收,如果是,则不作任何处理。
- if(DDBOfmoduleId<firstModId
- ||DDBOfmoduleId>=firstModId+filemodNum)
- {
- DCDebug1("n block number[mod=%d] out of module range!!!", DDBOfmoduleId);
- DCDebug1("n firstModId=%d filemodNum=%d",firstModId, filemodNum);
- return -1;
- }
- index = DDBOfmoduleId-firstModId;
- if(index < 0) index = 0;
- if(head.blockNumber>255||head.blockNumber>=file->BufStatus.modStat[index].blockCount)
- {
- DCDebug1("n head.blockNumber[%d] out of range", head.blockNumber);
- return -5;
- }
-
- if(file->BufStatus.modcount>0&&file->BufStatus.modStat!=NULL)
- {
- if(file->BufStatus.modStat[index].blockCount>0&&file->BufStatus.modStat[index].blockStat!=NULL)
- {
- if(file->BufStatus.modStat[index].blockStat[head.blockNumber]==FILLED)
- {
- DCDebug3("n mod[%d]: %d already received!!!", index, head.blockNumber);
- // 记录重复收取section的次数,过多的重复收取被认为是
- // 可能存在错误,需要强制退出数据过滤以进行其它冗余处理
- gDcTimeOut++;
- if((gDcTimeOut/(file->BufStatus.modStat[index].blockCount))>=5)
- {
- gDcTimeOut=0;
- DCDebug2("n too many repeat, begin one-by-one filter mode!");
- return -2;
- }
- else
- return 0;
- }
- }
-
- }
-
- //解析一个DDB
- if(ParseModuleDDBSection(buf,firstModId)==0)
- {
- DCDebug1("n ParseModuleDDBSection return error!");
- return -6;
- }
- // 读取完一个file的所有module的所有DDB section
- if(file->position == file->fileLength)
- {
- DCDebug2("nn all modules been parsed[%d]vs[%d]n", file->position, file->fileLength);
- //PrintfDCFileData(GetDCFILE());
- return 1;
- }
- return 0;
- }
- //-----------------------------------------------------------------------------
- // FUNCTION: printfFileData
- //
- // DESCRIPTION: 打印文件数据
- //
- // RETURN: None
- //
- // NOTES:
- //-
- void PrintfDCFileData(DCFILE *file)
- {
- int i;
- unsigned int line = 0x00000000;
- DCDebug4("[%s]:[%ld]n", file->fileName, file->fileLength);
- for(i=0;i<file->fileLength;i++)
- {
- if(i==0)
- {
- DCDebug4("n");
- DCDebug4("%x: ",line);
- }
- DCDebug4("%4.2x",file->section[i]);
- if((i+1)%16==0)
- {
- line = line + 16;
- DCDebug4("n");
- DCDebug4("%x: ",line);
- }
- }
- DCDebug4("n print endn");
- return;
- }
- void PrintfDDBData(unsigned char *data, int size,int blockNo)
- {
- int i;
- unsigned int line = 0x00000000;
- DCDebug4("n--------------PrintfDDBData------------------");
- for(i=0;i<size;i++)
- {
- if(i==0)
- {
- DCDebug4("n");
- DCDebug4("%x: ",line);
- }
-
- DCDebug4("%4.2x",data[i]);
- if((i+1)%16==0)
- {
- line = line + 16;
- DCDebug4("n");
- DCDebug4("%x: ",line);
- }
- }
- DCDebug4("n print ddb %d end",blockNo);
- return;
- }