📄 b1240.cpp
字号:
#include "B1240.H"
int main(void)
{
int iPublic;
iPublic = OpenFile();
if( iPublic == -1 )
{
Message("File Con't Opened,Please Cheack And Try Again");
return ERR_NoFile;
}
iPublic = RunTruns();
if( iPublic == -1 )
{
Message("Con't Truns The Data To Bill File");
return ERR_TrunFail;
}
Message("I Have Truns The Data To Bill Successed");
return 0;
}
void Message(char *Message)
{
printf("\n*------------------------Out Message -------------------------------------*\n");
printf("OutMessage: %s",Message);
printf("\n*-------------------------------------------------------------------------*\n");
}
int RunTruns(void)
{
int iMaxFile;
int iRead,iCount,isError;
char cFileName[20],buf[5];
char fileBuf[128];
long lCount;
char DiskBuffer[LenBlock];
unsigned char *p;
PhoneStruct *pps;
getdate(&DateNow);
for( iMaxFile = 0; iMaxFile < 10; iMaxFile++)
{
sprintf(buf, "%d",iMaxFile);
printf(buf, "%d",iMaxFile);
strcpy(cFileName, DataPath);
strcat(cFileName, DataName);
strcat(cFileName, buf);
inFile = open(cFileName,O_RDONLY | O_BINARY);
if( inFile == -1 )
{
// sprintf(fileBuf,"In File Con't Opened-->%s",cFileName);
// Message(fileBuf);
continue;
}
else
{
do
{
printf(".");
// fprintf( OutFile,"-------------------\n");
fprintf(OutFile,"");
iRead = ReadData(inFile,DiskBuffer);
if( iRead <= 0 )
break;
else
{
if( DiskBuffer[0] != 0x02 )
break;
p = DiskBuffer + 4;
for (iCount=0; iCount< 68; iCount++)
{
if (*p==0xEE)
break;
isError = getPhoneStruct(p,pps);
if( isError != FALSE )
SavePhoneStruct(pps);
p += 30;
}
}
}while(1);
} //For (iMaxFile)
} //if --> else
//printf("File Close All");
fcloseall();
//printf("1240 End");
return 1;
}
int OpenFile(void)
{
char NameBuf[128];
strcpy(NameBuf, DataPath);
strcat(NameBuf, OutName);
OutFile = fopen(NameBuf,"a+");
if( OutFile == NULL )
{
Message("OutFile Not Opened");
return -1;
}
strcpy(NameBuf, DataPath);
strcat(NameBuf, ErrName);
ErrFile = fopen(NameBuf,"a+");
if( ErrFile == NULL )
{
Message("Error File Not Opened");
return -1;
}
return 0;
}
int ReadData(int finFile,unsigned char *p)
{
int iReadByte;
iReadByte = read(finFile,p,LenBlock);
if( iReadByte <= 0 )
return -1;
return iReadByte;
}
int getPhoneStruct(unsigned char *p,PhoneStruct *pps)
{
unsigned long Times,Minute;
char buf[40];
char ch;
int i,j,isError=FALSE;
if (*p == 0xEE) return isError;
if (*p == 0x00) return isError;
if (*p != 0x01) return isError;
memset(pps,0,sizeof(PhoneStruct));
memset(buf,0,sizeof(buf));
for (i=0,j=0; i<5; i++)
{
if ((buf[j++]=getHigh(*(p+i+1)))>'9') isError=FALSE;
if (j>=PhoneLength) break;
if ((buf[j++]=getLow(*(p+i+1)))>'9') isError=FALSE;
if (j>=PhoneLength) break;
}
buf[j]=0;
strcpy(pps->CallingNo,buf);
memset(buf,0,sizeof(buf));
for (i=0; i<8; i++)
{
ch=getHigh(*(p+7+i));
if (ch>'9') break;
buf[2*i]=ch;
ch=getLow(*(p+7+i));
if (ch>'9') break;
buf[2*i+1]=ch;
}
strcpy(pps->CalledNo,buf);
buf[0]=getHigh(*(p+15));
buf[1]=getLow(*(p+15));
buf[2]=getHigh(*(p+16));
buf[3]=getLow(*(p+16));
buf[4]=getHigh(*(p+17));
buf[5]=getLow(*(p+17));
buf[6]=0;
strcpy(pps->startTime,buf);
buf[0]=getHigh(*(p+18));
buf[1]=getLow(*(p+18));
buf[2]=getHigh(*(p+19));
buf[3]=getLow(*(p+19));
buf[4]=getHigh(*(p+20));
buf[5]=getLow(*(p+20));
buf[6]=0;
strcpy(pps->endTime,buf);
memset(buf,0,sizeof(buf));
ThisTime.tm_year = DateNow.da_year - 1900;
ThisTime.tm_mon = *( p + 22);
ThisTime.tm_mday = *( p + 23);
ThisTime.tm_hour = *( p + 16);
ThisTime.tm_min = *( p + 17);
ThisTime.tm_sec = *( p + 18);
ThisTime.tm_isdst = -1;
mktime(&ThisTime);
sprintf(buf,"%2d",ThisTime.tm_wday + 1);
strcpy(pps->dayInWork,buf);
Times = 0;
Minute = 0;
ch=getHigh(*(p+23))-'0';
Times+= 100000lu * (unsigned long)ch;
ch=getLow(*(p+23)) -'0';
Times+= 10000lu * (unsigned long)ch;
ch=getHigh(*(p+24))-'0';
Times+= 1000lu * (unsigned long)ch;
ch=getLow(*(p+24)) -'0';
Times+= 100lu * (unsigned long)ch;
ch=getHigh(*(p+25))-'0';
Times+= 10lu * (unsigned long)ch;
ch=getLow(*(p+25)) -'0';
Times+= 1lu * (unsigned long)ch;
memset(buf,0,sizeof(buf));
sprintf(buf,"%7d" , Times);
strcpy(pps->timeLen, buf);
memset(buf,0,sizeof(buf));
Minute = Times / 60lu;
if ( (Times % 60lu) !=0 )
Minute++;
sprintf(buf,"%6d",Minute);
strcpy(pps->MinCount,buf);
buf[0]=getHigh(*(p+29));
buf[1]=getLow(*(p+29));
buf[2]=getHigh(*(p+30));
buf[3]=getLow(*(p+30));
buf[4]=0;
strcpy(pps->outGoing,buf);
buf[0]=getHigh(*(p+21));
buf[1]=getLow (*(p+21));
buf[2]=getHigh(*(p+22));
buf[3]=getLow (*(p+22));
buf[4]=0;
strcpy(pps->startDate,buf);
strcpy(pps->endDate ,buf);
strcpy(pps->arcNo," ");
strcpy(pps->RATE," ");
strcpy(pps->FEE," ");
pps->FLAG = '1';
isError = TRUE;
return isError;
}
int SavePhoneStruct(PhoneStruct *pps)
{
fprintf( OutFile,"%7s",pps->CallingNo );
fprintf( OutFile,"%8s",pps->arcNo );
fprintf( OutFile,"%-16s",pps->CalledNo );
fprintf( OutFile,"%8s",pps->startTime );
fprintf( OutFile,"%8s",pps->endTime );
fprintf( OutFile,"%2s",pps->dayInWork );
fprintf( OutFile,"%7s",pps->timeLen);
fprintf( OutFile,"%6s",pps->MinCount );
fprintf( OutFile,"%5s",pps->outGoing );
fprintf( OutFile,"%5s",pps->startDate );
fprintf( OutFile,"%5s",pps->endDate );
fprintf( OutFile,"%6s",pps->RATE );
fprintf( OutFile,"%8s",pps->FEE );
fprintf( OutFile,"%c\n",pps->FLAG );
return 0;
}
int getHigh(int ch)
{
ch=(ch&0xF0)>>4;
ch+=(ch>9)?0x37:0x30;
return ch;
}
int getLow(int ch)
{
ch=ch&0x0F;
ch+=(ch>9)?0x37:0x30;
return ch;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -