?? jbdcomm.c
字號:
}
// End function: DlpConnectModem()
/***********************************************************
*
* 函數名: DynamicPassword()
* 功 能: 接收動態密碼.
*
**********************************************************/
bool DlpDynamicPassword(void)
{
bPaBuf=0x00;
bNeBuf=0x10;
iPaNeNum=0;
if(!DlpRxData(0x2000))
return FALSE;
DlpTxCmd(OK);
return TRUE;
}
// End function: DlpDynamicPassQWord()
/******************************************************
*
* 函數名:DlpQueryVersion()
* 功 能:發送應用程序版本號.
*
******************************************************/
bool DlpQueryVersion(void)
{
DlpTxCmd(QUERY_VERSION);
if(!DlpRxCmd())
return FALSE;
if(bRecSBUF!=OK){
bErrorCode=0x05;
return FALSE;
}
bPaBuf=VERSION_PA; // 0x00
bNeBuf=VERSION_NE; // 0x0a
if(!DlpTxPaNe())
return FALSE;
DlpReadData(1,PARA_50,10); // 數據在aDataBuf[]中.
if(!DlpTxData())
return FALSE;
DlpTxCmd(EQ); // 尋問管理機下一命令
if(!DlpRxCmd())
return FALSE;
if(bRecSBUF==END){
bErrorCode=ERR_34;
return FALSE;
}
if(bRecSBUF!=DOWNLOAD_PROGRAM){
bErrorCode=ERR_05;
return FALSE;
}
return TRUE;
}
// End function: DlpQueryVersion()
/******************************************************
*
* 函數名:DlpSendTelNum()
* 功 能:發送計費器本機電話號碼.
*
******************************************************/
bool DlpSendTelNum(bool fSelect)
{
byte i,bCheckSum;
if(!fWorkMode){
DlpReadData(1,PARA_210,4);
for(i=0;i<4;i++)
aParaBuf[i]=aDataBuf[i];
for(i=0;i<4;i++){
aDataBuf[2*i]=aParaBuf[i]>>4;
aDataBuf[2*i+1]=aParaBuf[i]&0x0f;
}
}
else
DlpReadData(1,PARA_02,8);
for(i=0,bCheckSum=0;i<8;i++){
if(!DlpTxByte(aDataBuf[i]))
return FALSE;
bCheckSum+=aDataBuf[i];
}
if(fSelect){
DlpTxByte(~bCheckSum);
return TRUE;
}
else{
DlpTxByte(bCheckSum);
if(!DlpRxCmd())
return FALSE;
if(bRecSBUF!=OK){
bErrorCode=ERR_05;
return FALSE;
}
return TRUE;
}
}
// End function: DlpSendTelNum()
/***********************************************************
*
*
* 函數名:DlpResetModem()
* 功 能:初始化CML644A芯片
*
*
***********************************************************/
void DlpResetModem(void)
{
DlpPage(7);
XBYTE[0x8001]=0x04;
DlpPage(5);
MD_CLK=1;
}
/*************************************************************
*
* 函數名:DlpModemRead()
* 功 能:從CML644A中由bAddr指定的寄存器中讀出字節返回
*
*************************************************************/
byte DlpModemRead(byte bAddr)
{
byte i;
DlpPage(7);
i=XBYTE[0x8000+bAddr];
DlpPage(5);
return i;
}
// End function: DlpModemRead()
/***********************************************************
*
* 函數名:DlpWriteModem()
* 功 能:將ToWrite寫入CML644A芯片TargetAddr寄存器
*
***********************************************************/
void DlpWriteModem(byte tAddr,byte ToWrite)
{
DlpPage(7);
XBYTE[0x8000+tAddr]=ToWrite;
DlpPage(5);
}
// End function: DlpWriteModem()
//
// 下為MODEM或UART的接收與發送函數:
//
/******************************************************************
*
* 函數名:DlpTxByte()
* 功 能:往UART或MODEM發送一個字節
*
******************************************************************/
bool DlpTxByte(byte bByte)
{
SBUF=bByte;
while(!fTxDataReady){;}
bLastCmd=0xff;
fTxDataReady=0;
return TRUE;
}
// End function: DlpTxByte()
/******************************************************************
*
* 函數名:DlpTxCmd()
* 功 能:發送一條命令
*
******************************************************************/
void DlpTxCmd(byte bCmd)
{
DlpFlashComm();
DlpTxByte(bCmd);
DlpTxByte(~bCmd);
bLastCmd=bCmd;
}
// End function: DlpTxCmd()
/******************************************************************
*
* 函數名:DlpRxByte()
* 功 能:接收一個字節
*
******************************************************************/
bool DlpRxByte(void)
{
cbDelaySecond=SLAVE_TIME_OUT;
fDelaySecond=FALSE;
while(TRUE){
if(fRxDataReady){
fRxDataReady=FALSE;
return TRUE;
}
if(fDelaySecond){
bErrorCode=ERR_02;
return FALSE;
}
}
}
// End function: DlpRxByte()
/***********************************************************
*
* 函數名:DlpRxCmd()
* 功 能:接收一條命令
*
**********************************************************/
bool DlpRxCmd(void)
{
bool fErrOneTime=FALSE;
byte i,aTemp[2];
byte bSendTimes;
for(bSendTimes=0;bSendTimes<3;bSendTimes++){
for(i=0;i<2;i++){
if(!DlpRxByte()){
if(fErrOneTime)
return FALSE;
fErrOneTime=TRUE;
i=0xff;
continue;
}
if(fFirstCmd&&(i==0)&&(bRecSBUF<0x80)){
i=0xff;
continue;
}
aTemp[i]=bRecSBUF;
}
if(aTemp[0]==~aTemp[1]){
bRecSBUF=aTemp[0];
if((bRecSBUF==ERR_CS)&&(bLastCmd<0x99)){
DlpTxByte(bLastCmd);
DlpTxByte(~bLastCmd);
continue;
}
bLastCmd=0xff;
return TRUE;
}
DlpTxCmd(ERR_CS);
}
bErrorCode=ERR_08;
return FALSE;
}
// End function: DlpRxCmd()
/******************************************************************
*
* 函數名:DlpTxPaNe()
* 功 能:發送包數量Pa和剩余字節Ne
*
******************************************************************/
bool DlpTxPaNe(void)
{
byte i;
for(i=0;i<3;i++){
DlpTxByte(bPaBuf);
DlpTxByte(bNeBuf);
DlpTxByte((byte)(bPaBuf+bNeBuf));
if(!DlpRxCmd())
continue;
if(bRecSBUF==OK)
return TRUE;
else if(bRecSBUF!=ERR_CS)
break;
}
return FALSE;
}
// End function: DlpTxPaNe()
/***********************************************************
*
* 函數名:DlpRxData()
* 功 能:程序下載時,Pa個數據包和Ne個剩余字節接收過程,
* 接收到的數據存入頁面4的0x2000開始處.
*
**********************************************************/
bool DlpRxData(uint iNextAddr)
{
bool fOneTimes;
byte i,j,bCheckSum;
uint iAddr=iNextAddr;
if(iPaNeNum!=0)
DlpTxCmd(OK);
while(bPaBuf!=0){
for(i=0,fOneTimes=FALSE;i<3;i++){
for(j=0,bCheckSum=0;j<129;j++){
if(!DlpRxByte()){
if((j>=1)&&
(aDataBuf[iAddr]==ERR_CS)&&(aDataBuf[iAddr+1]==~ERR_CS)){
aDataBuf[iAddr]=0;
aDataBuf[iAddr+1]=0;
DlpTxCmd(bLastCmd);
j=0xff;
continue;
}
if(fOneTimes)
return FALSE;
else{
fOneTimes=TRUE;
j=0xff;
continue;
}
}
if(j<128){
bCheckSum+=bRecSBUF;
DlpPage(4);
XBYTE[iAddr+j]=bRecSBUF;
DlpPage(5);
}
} // End for(j...)
if(bCheckSum!=bRecSBUF){ //若校驗和不正確,重新發送數據
DlpTxCmd(ERR_CS);
continue;
}
iAddr+=128;
iAddress++;
j=(byte)(iAddress);
if((j&0x0f)==0x0a)
iAddress+=6;
j=(byte)(iAddress);
if(j==0xa0)
iAddress+=0x60;
DlpDispLP();
if((--bPaBuf!=0)||(bNeBuf!=0))
DlpTxCmd(OK);
break;
} // End for(i...)
if(i==3){
bErrorCode=ERR_04;
return FALSE;
}
}// End while(bPaBuf!=0)
while(bNeBuf!=0){
for(i=0,fOneTimes=FALSE;i<3;i++){
for(j=0,bCheckSum=0;j<bNeBuf+1;j++){
if(!DlpRxByte()){
if((j>=1)&&
(aDataBuf[iAddr]==ERR_CS)&&(aDataBuf[iAddr+1]==~ERR_CS)){
aDataBuf[iAddr]=0;
aDataBuf[iAddr+1]=0;
DlpTxCmd(bLastCmd);
j=0xff;
continue;
}
if(fOneTimes)
return FALSE;
else{
fOneTimes=TRUE;
j=0xff;
continue;
}
}
if(j<bNeBuf){
aDataBuf[iAddr+j]=bRecSBUF;
bCheckSum+=bRecSBUF;
}
} // End for(j...)
if(bCheckSum!=bRecSBUF){ //若校驗和不正確,重新發送數據
DlpTxCmd(ERR_CS);
continue;
}
return TRUE;
} // End for(i...)
bErrorCode=ERR_04;
return FALSE;
} // End while(bNeBuf!=0)
return TRUE;
}
// End function: DlpRxData()
bool DlpRxPaNe(void)
{
byte i,aTemp[3];
bool fFalse=FALSE;
byte bSendTimes=3;
for(bSendTimes=0;bSendTimes<3;bSendTimes++){
for(i=0;i<3;i++){
if(!DlpRxByte()){
if(fFalse)
return FALSE;
fFalse=TRUE;
i=0xff;
continue;
}
aTemp[i]=bRecSBUF;
if((i==1)&&(aTemp[0]==ERR_CS)&&(aTemp[1]==~ERR_CS)){
DlpTxCmd(bLastCmd);
i=0xff;
continue;
}
}
if(aTemp[2]==(byte)(aTemp[0]+aTemp[1])){
bPaBuf=aTemp[0];
bNeBuf=aTemp[1];
iPaNeNum=bPaBuf*128+bNeBuf;
return TRUE;
}
DlpTxCmd(ERR_CS);
}
bErrorCode=ERR_04;
return FALSE;
}
// End function: DlpRxPaNe()
/******************************************************************
*
* 函數名:DlpTxData()
* 功 能:發送Pa個數據包和Ne個剩余字節。
*
******************************************************************/
bool DlpTxData(void)
{
byte i,j,bCheckSum;
uint iAddr=0;
while(bNeBuf!=0){
for(i=0;i<3;i++){
for(j=0,bCheckSum=0;j<bNeBuf;j++){
if(!DlpTxByte(aDataBuf[iAddr+j]))
return FALSE;
bCheckSum+=aDataBuf[iAddr+j];
}
DlpTxByte(bCheckSum);
if(!DlpRxCmd())
continue;
if(bRecSBUF==OK)
break;
else if(bRecSBUF!=ERR_CS)
break;
}
if((i==3)||(bRecSBUF!=OK)){
bErrorCode=ERR_05;
return FALSE;
}
bNeBuf=0;
}
return TRUE;
}
// End function: DlpTxData()
void DlpWriteOut(uint iAddr,byte bData)
{
DlpPage(6);
XBYTE[iAddr]=bData;
DlpPage(5);
}
// End function: DlpWriteOut()
void DlpOpen(byte bWhich)
{
OutBuf|=bWhich;
DlpWriteOut(OUT_CE,OutBuf);
}
// End function: DlpOpen()
void DlpClose(byte bWhich)
{
OutBuf&=~bWhich;
DlpWriteOut(OUT_CE,OutBuf);
}
// End function: DlpClose()
void DlpFlashComm(void)
{
fFlash=~fFlash;
if(fFlash)
DlpDispSymbol(LARGE_FLASH);
else
DlpDispSymbol(LARGE_UNFLASH);
}
// End function: DlpFlash()
//
// End file: jbDlpComm.c
//
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -