home *** CD-ROM | disk | FTP | other *** search
Text File | 2001-09-05 | 32.1 KB | 1,300 lines |
- //-----------------------------------------------------------------------
- // ext vars
- // @szATCmd - str (LPSTR) @c1TxB_FRH = 3000 @c1RxB_FTH = 3000
- // @szCID - str @c1TxB_FRHFTH = 0 @c1RxB_FTHFRH = 0
- // @szDCS - str @c1TxB_FTH = 3000 @c1RxB_FRH = 3000
- // @szDIS - str @c1TxB_FTHFTM = 0 @c1RxB_FRHFRM = 0
- // @szDCC - str @c1TxB_FTM = 3000 @c1RxB_FRM = 3000
- // @szHNG - str @c1TxB_FTMFRH = 0 @c1RxB_FRMFTH = 0
- // @szNSF - str @c1TxB_FRH2 =3000 @c1RxB_FTH2 =3000
- // @lpszRespBuff - str @c1TxB_FRHFTM = 0 @c1RxB_FTHFRM = 0
- // @lPageCnt - long @c1TxC_FTM = 3000 @c1RxC_FRM = 3000
- // @lPageTotal - long @c1TxD_DataFTH =0 @c1RxD_DataFRH =0
- // @lSizeForNSF - long @c1TxD_FTH = 3000 @c1RxD_FRH = 3000
- // @ComIO @c1TxD_FTHFRH = 0 @c1RxD_FRHFTH = 0
- // @GlStr1 @c1TxD_FRH = 3000 @c1RxD_FTH = 3000
- // @GlStr2 @c1TxE_FRHFTH = 0 @c1RxE_FTHFRH = 0
- // @RespBuffer @c1TxE_FTH = 3000 @c1RxE_FRH = 3000
- //---------------------------------------------------------------------
- //---------------------------------------------------------------------
- // ext functions
- //fSetBaudRate(DWORD lpParam, DWORD Baud, DWORD dwN1, DWORD dwN2);
- //fWaitResponse(DWORD lpParam, DWORD lpBuf, DWORD lTimeOut, DWORD dwN1);
- //fSendATCmd(DWORD lpParam, DWORD lpBuf, DWORD dwN1, DWORD dwN2);
- //fSendDLE_ETX(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
- //fSleep(DWORD lTime, DWORD dwN1, DWORD dwN2, DWORD dwN3);
- //fFlushRxQueue(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
- //fFlushTxQueue(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
- //fSendOneChar(DWORD lpParam, DWORD dwCh, DWORD dwN1, DWORD dwN2);
- //fWaitOneChar(DWORD lpParam, DWORD lpResultChar, DWORD lTimeOut, DWORD dwN1);
- //fSetDTR(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
- //fResetDTR(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
- //fSetRTS(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
- //fResetRTS(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
- //fSetMisc(DWORD lpParam, DWORD nParity, DWORD nDataBits, DWORD nStopBits);
- //fSetMiscMore(DWORD lpParam, DWORD bDTRDSR, DWORD bRTSCTS, DWORD bXONXOFF);
- //fHardFlowControl(DWORD lpParam, DWORD Type, DWORD dwN1, DWORD dwN2);
- //fSoftFlowControl(DWORD lpParam, DWORD Type, DWORD dwN1, DWORD dwN2);
- //fSkipSpaceStrStr(DWORD s1, DWORD s2, DWORD dwN1, DWORD dwN2);
- //fTxFirstResponseError(DWORD s1, DWORD s2, DWORD dwN1, DWORD dwN2);
- //
- // For fHardFlowControl:
- // param1 - 0000X0YY X - Cts flow control
- // YY : 00 - RTS DISABLE
- // YY : 01 - RTS ENABLE
- // YY : 10 - RTS HANDSHAKE
- // YY : 11 - RTS TOGGLE
- // For fSoftFlowControl:
- // param1 - 00000XXX 000(0) - No flowcontrol
- // 001(1) - Send flowcontrol
- // 002(2) - Recv flowcontrol
- // 004(4) - Both send and recv flowcontrol
- //
- //-------------------------------------------------------------------------
- //
- //
- // This is the script file for Class1.
- //
- //trace
- popup
- declare STRING %szStr1, %szStr2;
- declare STRING %szStr3, %szStr4;
- declare STRING %szPass1, %szPass2;
- declare STRING %szPass3, %szPass4;
- declare STRING %szMsg1;
- declare long %lRes0;
- declare long %lRes1;
- declare long %lRes2;
- declare long %lTemp0;
- declare long %lTemp1;
- declare long %lGRes0;
- declare long %lGRes1;
- declare long %lMsg1;
- declare long %bSendFRH;
- declare long %lAccTrain;
- declare long %AlreadySendFrame;
- declare long %nRetryCount;
- declare long %bBadRxTrain;
- declare char %XON;
- declare STRING %szNULL;
- declare STRING %szFrameContent;
-
- //----------------------------------------------------------------------
- // SubSendCmdWaitResp
- //----------------------------------------------------------------------
- sub SubSendCmdWaitResp(STRING #szCmd, STRING #szResp, long #lWaitTime)
- declare long %lRes;
- declare STRING %szCheckAT;
- declare long %lLimit;
-
- %lLimit = 0
- %szCheckAT = "AT"
- %lRes = fSkipSpaceStrStr(%szCheckAT, #szCmd)
- if (%lRes = 0)
- {
- %lRes = 0
- goto SendCmd1
- }
-
- %lRes = fSendATCmd(@ComIO, #szCmd)
- if (%lRes!=0)
- {
- %lRes = 101
- goto SendCmd1
- }
-
- :SendCmd0
- %lRes = fWaitResponse(@ComIO, #lWaitTime)
- if (%lRes != 0)
- {
- %lRes = 101
- goto SendCmd1
- }
-
- %lRes = fSkipSpaceStrStr(#szResp, @RespBuffer)
- if (%lRes != 0)
- {
- %lRes = 0
- goto SendCmd1
- }
-
- // some response but doesnt match, retry agian if necessary
- %lLimit = %lLimit+1
- if (%lLimit < 3)
- goto SendCmd0
-
- // Not match...
- %lRes = 101
-
- :SendCmd1
- %lGRes0 = %lRes
- endsub
-
- //----------------------------------------------------------------------
- //----------------------------------------------------------------------
- sub SubWaitOK(long #lWaitTime)
- declare long %lRes;
- declare STRING %szStrOK;
- declare long %lLimit;
-
- %lLimit = 0
-
-
- :SubWOK0
- %lRes = fWaitResponse(@ComIO, #lWaitTime)
- if (%lRes != 0)
- {
- %lRes = 101
- goto SubWOK1
- }
-
- %szStrOK = "OK"
- %lRes = fSkipSpaceStrStr(%szStrOK, @RespBuffer)
- if (%lRes != 0)
- {
- %lRes = 0
- goto SubWOK1
- }
-
- //
- // %lRes = 0 means respbuffer and str doesnt match, try again if necessary
- //
- %lLimit = %lLimit+1
- if (%lLimit < 3)
- goto SubWOK0
-
- // error return 101 here
- %lRes = 101
-
- :SubWOK1
- %lGRes0 = %lRes
- endsub
-
- //----------------------------------------------------------------------
- //----------------------------------------------------------------------
- sub SubSendLastFrame(long #lWaitTime)
- declare long %lRes;
- declare STRING %szFTH;
-
- fFlushRxQueue(@ComIO)
- %szFTH = "AT+FTH=3"
- %lRes = fSendATCmd(@ComIO, %szFTH)
- if (%lRes!=0)
- {
- %lRes = 101
- goto SubSLF0
- }
-
- %lRes = fWaitResponse(@ComIO, #lWaitTime)
- if (%lRes != 0)
- {
- %lRes = 101
- goto SubSLF0
- }
-
- %szFTH = "CONNECT"
- %lRes = fSkipSpaceStrStr(%szFTH, @RespBuffer)
- if (%lRes = 0) // the response is not CONNECT
- {
- %lRes = 101
- goto SubSLF0
- }
-
- fC1SendLastFrame(@FClass1)
- %lRes = 0
-
- :SubSLF0
- %lGRes0 = %lRes
- endsub
-
-
- //----------------------------------------------------------------------
- // SubSendFrame(STRING #FrameContent,
- // long #lWaitTime,
- // long #lMode [for lMode = 1 : wait for connect,
- // 2 : no wait for connect]
- // )
- //----------------------------------------------------------------------
- sub SubSendFrame(STRING #FrameContent, long #lWaitTime, long #lMode)
- declare long %lRes;
- declare STRING %szFTH;
- %AlreadySendFrame = 1
-
- if (#lMode = 1) // wait for connect
- goto SubSF0
-
- if (#lMode = 2) // dont even wait for connect
- goto SubSF1
-
- fFlushRxQueue(@ComIO)
- %szFTH = "AT+FTH=3"
- %lRes = fSendATCmd(@ComIO, %szFTH)
- if (%lRes!=0)
- {
- %lRes = 101
- goto SubSF2
- }
-
- :SubSF0
- %lRes = fWaitResponse(@ComIO, #lWaitTime)
- if (%lRes != 0)
- {
- %lRes = 101
- goto SubSF2
- }
-
- %szFTH = "CONNECT"
- %lRes = fSkipSpaceStrStr(%szFTH, @RespBuffer)
- if (%lRes = 0) // the response is not CONNECT
- %lRes = 101
-
- :SubSF1
- fC1SendFrame(@FClass1, #FrameContent)
- %lRes = 0
-
- :SubSF2
- %lGRes0 = %lRes
- endsub
-
- //----------------------------------------------------------------------
- // Use lGRes0 as return
- // Send FRH if necessary
- // if bSendFRH = 0 -> send AT+FRH and wait for connect
- // 1 -> just wait data
- //
- // return 0 : OK
- // 1 : Error
- // 2 : Retry Overlimited
- //----------------------------------------------------------------------
- sub SubWaitFrame(long #bSendFRH, long #lWaitTime)
- declare long %lRes;
- declare STRING %szStrs;
- if (#bSendFRH = 1) goto SubWFrame8
-
- fSleep(30)
- %szStrs = "AT+FRH=3"
- %lRes = fSendATCmd(@ComIO, %szStrs)
- if (%lRes = 0)
- goto SubWFrame3
-
- %lRes = 1
- goto SubWFrame9
-
- // if (%lRes!=0)
- // {
- // %lRes = 1
- // goto SubWFrame9
- // }
- //
-
- :SubWFrame3
- %lRes = fWaitResponse(@ComIO, #lWaitTime)
- if (%lRes = 0)
- goto SubWFrame4
-
- %lRes = 1
- goto SubWFrame9
-
- // if (%lRes != 0)
- // {
- // %lRes = 1
- // goto SubWFrame9
- // }
- //
-
- :SubWFrame4
- %szStrs = "CONNECT"
- %lRes = fSkipSpaceStrStr(%szStrs, @RespBuffer)
- if (%lRes != 0)
- goto SubWFrame8
-
- %lRes = 1
- goto SubWFrame9
-
- //
- // if (%lRes = 0)
- // goto SubWFrame9
- //
- :SubWFrame8
- %lRes = fC1RecvFrame(@FClass1, #lWaitTime)
-
- :SubWFrame9
- %lGRes0 = %lRes
- endsub
-
-
-
-
-
-
- //----------------------------------------------------------------------
- //----------------------------------------------------------------------
- sub SubSendFrameDCS(STRING #FrameContent, long #lWaitTime, long #lMode)
- declare long %lRes;
- declare STRING %szFTH;
-
- if (#lMode = 1) // wait for connect
- goto SubSFDCS0
-
- if (#lMode = 2) // dont even wait for connect
- goto SubSFDCS1
-
- fFlushRxQueue(@ComIO)
-
- %szFTH = "AT+FTH=3"
- %lRes = fSendATCmd(@ComIO, %szFTH)
- if (%lRes!=0)
- {
- %lRes = 101
- goto SubSFDCS2
- }
-
- :SubSFDCS0
- %lRes = fWaitResponse(@ComIO, #lWaitTime)
- if (%lRes != 0)
- {
- %lRes = 101
- goto SubSFDCS2
- }
-
- %szFTH = "CONNECT"
- %lRes = fSkipSpaceStrStr(%szFTH, @RespBuffer)
- if (%lRes = 0) // the response is not CONNECT
- %lRes = 101
-
- :SubSFDCS1
- fC1SendFrame(@FClass1, @c1CommonDCS)
- %lRes = 0
-
- :SubSFDCS2
- %lGRes0 = %lRes
- endsub
-
-
-
- //----------------------------------------------------------------------
- //----------------------------------------------------------------------
- sub SubSendFrameDIS(STRING #FrameContent, long #lWaitTime, long #lMode)
- declare long %lRes;
- declare STRING %szFTH;
-
- if (#lMode = 1) // wait for connect
- goto SubSFDIS0
-
- if (#lMode = 2) // dont even wait for connect
- goto SubSFDIS1
-
- fFlushRxQueue(@ComIO)
-
- %szFTH = "AT+FTH=3"
- %lRes = fSendATCmd(@ComIO, %szFTH)
- if (%lRes!=0)
- {
- %lRes = 101
- goto SubSFDIS2
- }
-
- :SubSFDIS0
- %lRes = fWaitResponse(@ComIO, #lWaitTime)
- if (%lRes != 0)
- {
- %lRes = 101
- goto SubSFDIS2
- }
-
- %szFTH = "CONNECT"
- %lRes = fSkipSpaceStrStr(%szFTH, @RespBuffer)
- if (%lRes = 0) // the response is not CONNECT
- %lRes = 101
-
- :SubSFDIS1
- fC1SendFrame(@FClass1, @c1LocalDIS)
- %lRes = 0
-
- :SubSFDIS2
- %lGRes0 = %lRes
- endsub
-
-
- //----------------------------------------------------------------------
- // class1 timing
- //----------------------------------------------------------------------
- sub SubC1TimingPara
- @c1TxB_FRH = 3000 // For rx frame time limit
- @c1TxB_FRHFTH = 0 // After rx frame and before tx frame interval
- @c1TxB_FTH = 3000 // For tx frame interval
- @c1TxB_FTHFTM = 0 // After tx frame and tx training interval
- @c1TxB_FTM = 3000 // AT+FTM training time limit
- @c1TxB_FTMFRH = 0 // After tx training and rx frame interval
- @c1TxB_FRH2 =3000 // For rx frame time limit (frame CFR, FTT)
- @c1TxB_FRHFTM = 0 // After rx frame and tx data interval
- @c1TxC_FTM = 3000 // AT+FTM time limit
- @c1TxD_DataFTH =300 // PhaseC and PhaseD AT+FTH interval
- @c1TxD_FTH = 3000 // Tx frame time limit
- @c1TxD_FTHFRH = 0 // After tx frame and before rx frame interval
- @c1TxD_FRH = 3000 // Rx frame time limit
- @c1TxE_FRHFTH = 0 // After rx frame and before tx frame interval
- @c1TxE_FTH = 3000 // Tx frame time limit
-
- @c1RxB_FTH = 3000 // For tx frame time limit
- @c1RxB_FTHFRH = 0 // After tx frame and before rx frame interval
- @c1RxB_FRH = 3000 // For rx frame interval
- @c1RxB_FRHFRM = 0 // After rx frame and rx training interval
- @c1RxB_FRM = 3000 // AT+FRM training time limit
- @c1RxB_FRMFTH = 0 // After rx training and tx frame interval
- @c1RxB_FTH2 =3000 // For tx frame time limit (frame CFR, FTT)
- @c1RxB_FTHFRM = 0 // After tx frame and rx data interval
- @c1RxC_FRM = 3000 // AT+FRM time limit
- @c1RxD_DataFRH =0 // PhaseC and PhaseD AT+FRH interval
- @c1RxD_FRH = 3000 // Rx frame time limit
- @c1RxD_FRHFTH = 500 // After rx frame and before tx frame interval
- @c1RxD_FTH = 3000 // Tx frame time limit
- @c1RxE_FTHFRH = 0 // After tx frame and before rx frame interval
- @c1RxE_FRH = 3000 // Rx frame time limit
- endsub
-
- //----------------------------------------------------------------------
- // For Dialing number
- //----------------------------------------------------------------------
- :TX_DIAL
- call SubC1TimingPara
- fFlushRxQueue(@ComIO)
- fSleep(1500)
-
- fSendATCmd(@ComIO, @szATCmd)
- fSleep(1000)
- // fFlushRxQueue(@ComIO)
- %bSendFRH = 1
- %AlreadySendFrame = 0
- %nRetryCount = 0
- exit(0)
-
-
- //----------------------------------------------------------------------
- // For TX initialization part 1
- //
- // and for fHardFlowControl(@ComIO, 9) - CTS on / RTS on
- //----------------------------------------------------------------------
- :TX_INIT1
- call SubC1TimingPara
- %AlreadySendFrame = 0
- %nRetryCount = 0
-
- fHardFlowControl(@ComIO, 9)
- // fSoftFlowControl(@ComIO, 0)
-
- fSetBaudRate(@ComIO, 19200)
- fFlushRxQueue(@ComIO)
- fFlushTxQueue(@ComIO)
- @szATCmd = "ATZ"
- fSendATCmd(@ComIO, @szATCmd)
- fSleep(5000)
- fFlushRxQueue(@ComIO)
- @szATCmd = "ATS0=0M0E0"
- fSendATCmd(@ComIO, @szATCmd)
- fSleep(1000)
- fFlushRxQueue(@ComIO)
-
- call SubSendCmdWaitResp("ATE0", "OK", 3000)
- fSleep(150)
-
- call SubSendCmdWaitResp("ATS0=0", "OK", 3000)
- fSleep(150)
-
- call SubSendCmdWaitResp("ATE0V1&C1&D2", "OK", 3000)
- fSleep(150)
-
- %lGRes1 = %lGRes0
- call SubSendCmdWaitResp("AT&K3", "OK", 3000)
- // call SubSendCmdWaitResp("AT&K4", "OK", 3000)
- %lGRes0 = %lGRes1
- fSleep(150)
-
- %bSendFRH = 0
- exit (%lGRes0)
-
- :TX_INIT2
- fSetBaudRate(@ComIO, 19200)
- call SubSendCmdWaitResp("AT+FCLASS=1", "OK", 3000)
- if (%lGRes0 = 0)
- exit (0)
-
- exit (%lGRes0)
-
- :TX_INIT3
- exit (0)
-
- //
- // You can do all kind of thing here...
- :TX_INIT4
- exit (0)
-
-
- //----------------------------------------------------------------------
- // Now we go to Tx phase B - Wait for OK and send AT+FDR
- //
- // ??? I dont know whether we need to wait for FCON or not...
- //----------------------------------------------------------------------
- :TXPH_B_START
- // fSoftFlowControl(@ComIO, 0);
- %szStr3 = "This is in TXPH_B_START"
- %lRes0 = fPrintMsg(%szStr3)
-
- :TXPH_B_START1
- %lRes0 = fWaitResponse(@ComIO, 5000)
- if (%lRes0 != 0)
- exit (4)
-
- // Check to see if any error happens. eg: No dial tone, busy...
- %lRes0 = fTxFirstResponseError(@RespBuffer)
- if (%lRes0 != 0)
- {
- exit (%lRes0)
- }
-
- // Yes, sth is the buffer, we need to compare it. It must be
- // CONNECT.
- %szStr3 = "CONNECT"
- %lRes0 = fSkipSpaceStrStr(%szStr3, @RespBuffer)
- if (%lRes0 = 0)
- exit (1)
- exit (0)
-
-
- //----------------------------------------------------------------
- //----------------------------------------------------------------
- :TXPH_C_START
- fSoftFlowControl(@ComIO, 1)
- exit (0)
-
-
- //----------------------------------------------------------------
- //----------------------------------------------------------------
- :FAXMAIN
- :FAXMAIN_WAITFRAME
- // 0:good, 1:retry, 2:quit resulted in lGRes0
- // fSoftFlowControl(@ComIO, 0)
- call SubWaitFrame(%bSendFRH, 4500)
- %bSendFRH = 0
-
- if (%lGRes0 = 7) // to speed thing up
- {
- %nRetryCount = 0
- goto SIG_DCS
- }
-
- if (%lGRes0 = 0)
- {
- %nRetryCount = 0
- goto FAXMAIN_NEXTFRAME
- }
-
- // dont get good frame
- %lRes0 = %nRetryCount + 1
- %nRetryCount = %lRes0
- if (%nRetryCount > 6)
- exit (2)
-
- fSleep(1000)
- if (%AlreadySendFrame = 0)
- {
- call SubSendCmdWaitResp("AT", "OK", 2000)
- }
- else
- {
- call SubSendCmdWaitResp("AT", "OK", 2000)
- call SubSendLastFrame(3000)
- call SubWaitOK(3000)
- }
- goto FAXMAIN
-
- //---------------------------------------------------------
- // At this point, we receive a frame or some frames.
- //---------------------------------------------------------
- :FAXMAIN_NEXTFRAME
- %lRes2 = fC1NextFrame(@FClass1, %szFrameContent)
- :FAXMAIN_NXTFME
- if (%lRes2 = 7) goto SIG_DCS // to speed thing up
- if (%lRes2 = 1) goto SIG_DIS
- if (%lRes2 = 2) goto SIG_CSI
- if (%lRes2 = 3) goto SIG_NSF
- if (%lRes2 = 4) goto SIG_DTC
- if (%lRes2 = 5) goto SIG_CIG
- if (%lRes2 = 6) goto SIG_NSC
- if (%lRes2 = 7) goto SIG_DCS
- if (%lRes2 = 8) goto SIG_TSI
- if (%lRes2 = 9) goto SIG_NSS
- if (%lRes2 = 10) goto SIG_CFR
- if (%lRes2 = 11) goto SIG_FTT
- if (%lRes2 = 12) goto SIG_EOM
- if (%lRes2 = 13) goto SIG_MPS
- if (%lRes2 = 14) goto SIG_EOP
- if (%lRes2 = 15) goto SIG_PRIEOM
- if (%lRes2 = 16) goto SIG_PRIMPS
- if (%lRes2 = 17) goto SIG_PRIEOP
- if (%lRes2 = 18) goto SIG_MCF
- if (%lRes2 = 19) goto SIG_RTP
- if (%lRes2 = 20) goto SIG_PIP
- if (%lRes2 = 21) goto SIG_RTN
- if (%lRes2 = 22) goto SIG_PIN
- if (%lRes2 = 23) goto SIG_DCN
- if (%lRes2 = 24) goto SIG_CRP
- if (%lRes2 = 25) goto SIG_FCD
- if (%lRes2 = 26) goto SIG_RCP
- if (%lRes2 = 27) goto SIG_PPS
- if (%lRes2 = 28) goto SIG_PPR
- if (%lRes2 = 29) goto SIG_CTC
- if (%lRes2 = 30) goto SIG_CTR
- if (%lRes2 = 31) goto SIG_EOR
- if (%lRes2 = 32) goto SIG_ERR
- if (%lRes2 = 33) goto SIG_RR
- if (%lRes2 = 34) goto SIG_RNR
- if (%lRes2 = 35) goto SIG_FDM
- if (%lRes2 = 36) goto SIG_NUL
-
-
- //-------------------- for DIS
- :SIG_NSF
- goto FAXMAIN_NEXTFRAME
-
- :SIG_CSI
- fC1StoreRemoteID(@FClass1, %szFrameContent)
- goto FAXMAIN_NEXTFRAME
-
- :SIG_DIS
- fC1CopyFrame(@FClass1, @c1RemoteDIS, %szFrameContent)
- fC1MakeUpDCS(@FClass1)
-
- :SND_DCS
- call SubSendFrame(@c1TSI, 3000, 0)
- call SubSendFrameDCS(@c1CommonDCS, 3000, 1)
- call SubWaitOK(3000)
- fC1GetSpeedString(@FClass1, %szStr2, 1)
- %szStr3 = "AT+FTM="
- %szStr4 = %szStr3 + %szStr2
- call SubSendCmdWaitResp(%szStr4, "CONNECT", 3000)
-
- // fSoftFlowControl(@ComIO, 1)
- fC1TxTrain(@FClass1)
- // fSoftFlowControl(@ComIO, 0)
-
- call SubWaitOK(3000)
- goto FAXMAIN_WAITFRAME
-
-
- //-------------------- for DTC
- :SIG_NSC
- goto FAXMAIN_NEXTFRAME
- :SIG_CIG
- fC1StoreRemoteID(@FClass1, %szFrameContent)
- goto FAXMAIN_NEXTFRAME
- :SIG_DTC
- call SubSendFrame(@c1CSI, 3000, 0)
- call SubSendFrame(@c1LocalDIS, 3000, 1)
- call SubWaitOK(3000)
- goto FAXMAIN_WAITFRAME
-
- //-------------------- for DCS
- :SIG_NSS
- goto FAXMAIN_NEXTFRAME
- :SIG_TSI
- fC1StoreRemoteID(@FClass1, %szFrameContent)
- goto FAXMAIN_NEXTFRAME
- :SIG_DCS
- // call SubSendCmdWaitResp("AT+FRM=96", "CONNECT", 5500)
- //*
- //* fC1CopyFrame(@FClass1, @c1CommonDCS, %szFrameContent)
- //* fC1GetSpeedString(@FClass1, %szStr2, 1)
- //---Testing...
- // if (%bBadRxTrain = 1)
- // exit (1)
- // else
- // exit (0)
-
-
-
- :RXTRAIN_START
- %lAccTrain = 0
- // %szStr3 = "This is in RX_TRAINING..."
- // %lRes0 = fPrintMsg(%szStr3)
-
- :RXTRAIN_START_1
- %szStr3 = "AT+FRM="
- %szStr2 = @c1TrainSpeedStr
- %szStr4 = %szStr3 + %szStr2
- // fFlushRxQueue(@ComIO)
- call SubSendCmdWaitResp(%szStr4, "CONNECT", 5500)
- if (%lGRes0 = 0)
- {
- %szStr3 = "Get the Connect message now..."
- %lRes0 = fPrintMsg(%szStr3)
- %lGRes1 = fC1RxTrain(@FClass1, 3000)
- goto RXTRAIN_RESULT
- }
-
- %lAccTrain = %lAccTrain + 1
- %szStr3 = "Didnt Get the Connect message YET..."
- %lRes0 = fPrintMsg(%szStr3)
- call SubSendCmdWaitResp("AT", "OK", 1000)
- if (%lAccTrain > 6)
- %lGRes1 = 1
- else
- goto RXTRAIN_START_1
-
- %szStr3 = "go to RXTRAINRESULT..."
- %lRes0 = fPrintMsg(%szStr3)
- goto RXTRAIN_RESULT
- // Get rid of OK or CONNECT message
- //--------------------------------------------------------
- :RXTRAIN_1
- %lRes2 = fWaitResponse(@ComIO, 300)
- if (%lRes2 != 0)
- {
- // Sth wrong with the training.
- %lGRes1 = 1
- goto RXTRAIN_RESULT
- }
-
- %szStr4 = "OK"
- %lRes2 = fSkipSpaceStrStr(%szStr4, @RespBuffer)
- if (%lRes2 != 0)
- goto RXTRAIN_RESULT
-
- %szStr4 = "NO CARRIER"
- %lRes2 = fSkipSpaceStrStr(%szStr4, @RespBuffer)
- if (%lRes2 != 0)
- goto RXTRAIN_RESULT
- goto RXTRAIN_1
-
- //--------------------------------------------------------
- // Above is for Get rid of OK or CONNECT message
-
- :RXTRAIN_RESULT
- %szStr3 = "This is in RX_TRAINING RESULT"
- %lRes0 = fPrintMsg(%szStr3)
- fFlushRxQueue(@ComIO)
- if (%lGRes1 = 0)
- {
- %bBadRxTrain = 0
- call SubSendFrame(@c1CFR, 3000, 0)
- call SubWaitOK(3000)
-
- // Send AT+FRM=XX to receive data...
- %szStr3 = "AT+FRM="
- %szStr2 = @c1DataSpeedStr
- %szStr4 = %szStr3 + %szStr2
- fFlushRxQueue(@ComIO)
- call SubSendCmdWaitResp(%szStr4, "CONNECT", 3000)
- exit (0)
- }
- else
- {
- %bBadRxTrain = 1
- call SubSendFrame(@c1FTT, 3000, 0)
- call SubWaitOK(3000)
- goto FAXMAIN_WAITFRAME
- }
-
-
- //-------------------- for training
- :SIG_FTT
- %lRes0 = fC1StepDown(@FClass1)
- if (%lRes0 != 0)
- exit (%lRes0)
- goto SND_DCS
-
-
- // For class1 - We got SIG_CFR already. Send AT+FTM now
- :TXTRAIN_START
- fC1GetSpeedString(@FClass1, %szStr2, 0)
- %szStr3 = "AT+FTM="
- %szStr4 = %szStr3 + %szStr2
- call SubSendCmdWaitResp(%szStr4, "CONNECT", 3000)
- exit (0)
-
- :TXTRAIN_START_PHD
- fC1GetSpeedString(@FClass1, %szStr2, 1)
- %szStr3 = "AT+FTM="
- %szStr4 = %szStr3 + %szStr2
- call SubSendCmdWaitResp(%szStr4, "CONNECT", 3000)
- exit (1)
-
- :SIG_CFR
- // fSoftFlowControl(@ComIO, 1)
- exit (0)
-
-
- // for phase D
- :SIG_MPS
- %szStr3 = "GetMPS"
- %lRes0 = fPrintMsg(%szStr3)
- call SubSendFrame(@c1MCF, 3000, 0)
- call SubWaitOK(3000)
-
- %szStr3 = "AT+FRM="
- %szStr4 = %szStr3 + %szStr2
- fFlushRxQueue(@ComIO)
- call SubSendCmdWaitResp(%szStr4, "CONNECT", 3000)
- exit (1)
-
- :SIG_EOM
- call SubSendFrame(@c1MCF, 3000, 0)
- call SubWaitOK(3000)
- goto FAXMAIN_WAITFRAME
-
- :SIG_EOP
- %szStr3 = "GetEOP"
- %lRes0 = fPrintMsg(%szStr3)
- call SubSendFrame(@c1MCF, 3000, 0)
- call SubWaitOK(3000)
- goto FAXMAIN_WAITFRAME
-
-
- //-------------------- for phase D with interrupt (which we dont support)
- :SIG_PRIEOM
- :SIG_PRIEOP
- :SIG_PRIMPS
- goto FAXMAIN_WAITFRAME
-
- //-------------------- for phase D
- :SIG_MCF
- if (@lPageCnt >= @lPageTotal)
- goto SND_DCN
- else
- goto TXTRAIN_START_PHD
-
- :SIG_RTN
- :SIG_RTP
- %lRes0 = fC1StepDown(@FClass1)
- if (%lRes0 != 0)
- exit (%lRes0)
- goto SND_DCS
-
-
- //-------------------- disconnect
- :SIG_DCN
- goto FAXMAIN_DISCONNECT
-
- :SND_DCN
- call SubSendFrame(@c1DCN, 3000, 0)
- call SubWaitOK(3000)
- goto FAXMAIN_DISCONNECT
-
-
- //-------------------- repeat last signal
- :SIG_CRP
- call SubSendCmdWaitResp("AT", "OK", 500)
- call SubSendLastFrame(3000)
- call SubWaitOK(3000)
- goto FAXMAIN_DISCONNECT
-
-
- //-------------------- To Send DIS after ATA
- //Remember use 2 as the input parameter to SubSendFrame
- //
- :SND_DIS
- call SubSendFrame(@c1CSI, 3000, 2)
- call SubSendFrameDIS(@c1LocalDIS, 3000, 1)
- call SubWaitOK(3000)
- goto FAXMAIN_WAITFRAME
-
-
- :SND_MPS
- call SubSendFrame(@c1MPS, 3000, 0)
- call SubWaitOK(3000)
- goto FAXMAIN_WAITFRAME
-
- :SND_EOP
- call SubSendFrame(@c1EOP, 3000, 0)
- call SubWaitOK(3000)
- goto FAXMAIN_WAITFRAME
-
- :SND_EOM
- call SubSendFrame(@c1EOM, 3000, 0)
- call SubWaitOK(3000)
- goto FAXMAIN_WAITFRAME
-
-
-
- //
- // The below signals are for ECM
- //
- :SIG_CTC
- exit (0)
- :SIG_CTR
- exit (0)
- :SIG_EOR
- exit (0)
- :SIG_ERR
- exit (0)
- :SIG_FCD
- exit (0)
- :SIG_PIN
- exit (0)
- :SIG_PIP
- exit (0)
- :SIG_PIS
- exit (0)
- :SIG_PPS
- exit (0)
- :SIG_PPR
- exit (0)
- :SIG_RCP
- exit (0)
- :SIG_RNR
- exit (0)
- :SIG_RR
- exit (0)
- :SIG_NUL
- exit (0)
-
- :TXPH_D_START
- // %szStr3 = "This is in TXPH_D_START"
- // %lRes0 = fPrintMsg(%szStr3)
-
- fSendOneChar(@ComIO, 0)
- fSendOneChar(@ComIO, 0)
- fSendOneChar(@ComIO, 8)
- fSendOneChar(@ComIO, 128)
-
- fSendOneChar(@ComIO, 0)
- fSendOneChar(@ComIO, 8)
- fSendOneChar(@ComIO, 128)
-
- fSendOneChar(@ComIO, 0)
- fSendOneChar(@ComIO, 8)
- fSendOneChar(@ComIO, 128)
- fSendDLE_ETX(@ComIO)
-
-
- :TXPH_D0
- %lRes0 = fWaitResponse(@ComIO, 30000)
- // NO response error (3)
- if (%lRes0 != 0)
- exit (3)
-
- %szStr3 = "OK"
- %lRes0 = fSkipSpaceStrStr(%szStr3, @RespBuffer)
- if (%lRes0 = 0)
- goto TXPH_D0
-
- %lRes0 = @lPageCnt + 1
- @lPageCnt = %lRes0
- exit (0)
-
-
-
- //----------------------------------------------------------------------
- // Disconnecting the line
- //----------------------------------------------------------------------
- :FAXMAIN_DISCONNECT
- :ABORT1
- :TX_DISC1
- :RX_DISC1
- %AlreadySendFrame = 0
- %nRetryCount = 0
- %bBadRxTrain = 0
-
- %szStr3 = "This is in DISC1"
- %lRes0 = fPrintMsg(%szStr3)
-
- %bSendFRH = 0
- fFlushRxQueue(@ComIO)
- // fSendDLE_ETX(@ComIO)
- %szStr3 = "AT"
- fSendATCmd(@ComIO, %szStr3)
- fSleep(1000)
- %szStr3 = "AT"
- fSendATCmd(@ComIO, %szStr3)
- fSleep(1000)
-
- fFlushRxQueue(@ComIO)
- fFlushTxQueue(@ComIO)
- %szStr3 = "ATH0"
- call SubSendCmdWaitResp(%szStr3, "OK", 2000)
-
-
- fFlushRxQueue(@ComIO)
- fFlushTxQueue(@ComIO)
- %szStr3 = "AT+FCLASS=0"
- call SubSendCmdWaitResp(%szStr3, "OK", 2000)
- fSetBaudRate(@ComIO, 2400)
- fSleep(500)
-
- // %szStr3 = "ATZ"
- %szStr3 = "AT"
- call SubSendCmdWaitResp(%szStr3, "OK", 3000)
- fFlushRxQueue(@ComIO)
-
-
- // fSendATCmd(@ComIO, @szATCmd) // comes from szTxQuitString
- fSleep(500)
- fResetDTR(@ComIO)
- fSleep(1000)
- fSetDTR(@ComIO)
- fFlushRxQueue(@ComIO)
- fFlushTxQueue(@ComIO)
- exit (0)
-
- :ABORT2
- :TX_DISC2
- :RX_DISC2
- fFlushRxQueue(@ComIO)
- fFlushTxQueue(@ComIO)
- // fSendATCmd(@ComIO, @szATCmd)
- fSleep(1000)
- fFlushRxQueue(@ComIO)
- fFlushTxQueue(@ComIO)
- exit (0)
-
- :TX_DISC3
- :RX_DISC3
- exit (0)
-
- :TX_DISC4
- :RX_DISC4
- exit (0)
-
- //----------------------------------------------------------------------
- // The following are for RX fax
- //----------------------------------------------------------------------
- //----------------------------------------------------------------------
- // For HardFlowControl - use 11 means CTS on/RTS toggle.
- //----------------------------------------------------------------------
- :RX_INIT1
- call SubC1TimingPara
- %AlreadySendFrame = 0
- %nRetryCount = 0
- %bBadRxTrain = 0
-
- fHardFlowControl(@ComIO, 9)
- fSoftFlowControl(@ComIO, 0)
- fSetBaudRate(@ComIO, 19200)
- fFlushRxQueue(@ComIO)
- fFlushTxQueue(@ComIO)
- @szATCmd = "ATS0=0M0E0"
- fSendATCmd(@ComIO, @szATCmd)
- fSleep(1000) // 100
- fFlushRxQueue(@ComIO)
- @szATCmd = "ATS0=0M0E0"
- fSendATCmd(@ComIO, @szATCmd)
- fSleep(1000) // 100
- fFlushRxQueue(@ComIO)
- call SubSendCmdWaitResp("AT&FE0", "OK", 3000)
- fSleep(1000)
-
- call SubSendCmdWaitResp("ATS0=0", "OK", 3000)
- fSleep(150)
-
- call SubSendCmdWaitResp("ATE0V1&C1&D2X4", "OK", 3000)
- fSleep(150)
-
- %lGRes1 = %lGRes0
- call SubSendCmdWaitResp("AT&K3", "OK", 3000)
- // call SubSendCmdWaitResp("AT&K4", "OK", 3000)
- %lGRes0 = %lGRes1
- fSleep(150)
-
- %bSendFRH = 0
- exit (%lGRes0)
-
- :RX_INIT2
- // call SubSendCmdWaitResp("AT+FCLASS=1", "OK", 3000)
- // if (%lGRes0 = 0)
- // fSetBaudRate(@ComIO, 19200)
- call SubSendCmdWaitResp("AT+FCLASS=1", "OK", 3000)
- fSleep(500)
- fSetBaudRate(@ComIO, 19200)
- exit (%lGRes0)
-
- :RX_INIT3
- exit (0)
-
- :RX_INIT4
- exit (0)
-
-
- //----------------------------------------------------------------------
- // RX_WAITCALL
- //
- // Wait for 3 seconds for RING signal
- //----------------------------------------------------------------------
- :RX_WAITCALL
- %szStr3 = "This is in RX_WAITCALL (C2)"
- %lRes0 = fPrintMsg(%szStr3)
-
- fFlushRxQueue(@ComIO)
- fFlushTxQueue(@ComIO)
- %lRes0 = fWaitResponse(@ComIO, 3000)
- if (%lRes0 != 0)
- exit (%lRes0)
-
- // Something is in the buffer, check if this is RING signal
- %szStr3 = "RING"
- %lRes0 = fSkipSpaceStrStr(%szStr3, @RespBuffer)
- if (%lRes0 != 0)
- exit (0)
- else
- exit (1)
-
-
- //----------------------------------------------------------------------
- // RX_ANSWERCALL
- //----------------------------------------------------------------------
- :RX_ANSWERCALL
- call SubC1TimingPara
-
- %szStr3 = "This is in RX_ANSWERCALL"
- %lRes0 = fPrintMsg(%szStr3)
-
- %AlreadySendFrame = 0
- %nRetryCount = 0
- %bBadRxTrain = 0
-
- @lPageTotal = 0
- @lPageCnt = 0
-
- fFlushRxQueue(@ComIO)
- fFlushTxQueue(@ComIO)
-
- call SubSendCmdWaitResp("AT+FCLASS=1", "OK", 3000)
- if (%lGRes0 = 0)
- fSetBaudRate(@ComIO, 19200)
- fSleep(250)
-
- fFlushRxQueue(@ComIO)
- @szATCmd = "ATA"
- fSendATCmd(@ComIO, @szATCmd)
- exit (0)
-
- //----------------------------------------------------------------------
- // RX_PH_B_START
- //----------------------------------------------------------------------
- :RXPH_B_START
- %szStr3 = "This is in RXPH_B_START"
- %lRes0 = fPrintMsg(%szStr3)
-
- %lRes0 = fWaitResponse(@ComIO, 30000)
- if (%lRes0 != 0)
- exit (1)
-
- // Check to see if any error happens. eg: No dial tone, busy...
- %lRes0 = fTxFirstResponseError(@RespBuffer)
- if (%lRes0 != 0)
- {
- exit (%lRes0)
- }
-
- // Yes, sth is the buffer, we need to compare it
- %szStr3 = "CONNECT"
- %lRes0 = fSkipSpaceStrStr(%szStr3, @RespBuffer)
- if (%lRes0 != 0)
- exit (0)
- else
- exit (1)
-
-
- :RXPH_D_START
- %lRes0 = @lPageTotal + 1
- @lPageTotal = %lRes0
-
- %lRes0 = @lPageCnt + 1
- @lPageCnt = %lRes0
-
- exit (0)
-
-
- //----------------------------------------------------------------------
- //----------------------------------------------------------------------
- :TAPIRX_INIT1
- call SubC1TimingPara
- %szStr3 = "This is in TAPIRX_INIT"
- %lRes0 = fPrintMsg(%szStr3)
-
- %AlreadySendFrame = 0
- %nRetryCount = 0
- %bBadRxTrain = 0
-
- @lPageTotal = 0
- @lPageCnt = 0
-
- fSendOneChar(@ComIO, 16)
- fSendOneChar(@ComIO, 3)
- fSendOneChar(@ComIO, 16)
- fSendOneChar(@ComIO, 3)
-
- fSendOneChar(@ComIO, 16)
- fSendOneChar(@ComIO, 24)
- call SubSendCmdWaitResp("AT", "OK", 1000)
- fSleep(150)
-
- call SubSendCmdWaitResp("ATE0V1&D2", "OK", 1000)
- fSleep(150)
-
- fHardFlowControl(@ComIO, 9)
- fSoftFlowControl(@ComIO, 0)
- fSetBaudRate(@ComIO, 19200)
- fFlushRxQueue(@ComIO)
- fFlushTxQueue(@ComIO)
-
- call SubSendCmdWaitResp("AT+FCLASS=0", "OK", 1000)
- fSleep(1000)
- // call SubSendCmdWaitResp("AT#BDR=0", "OK", 1000)
- // fSleep(150)
- // call SubSendCmdWaitResp("AT&FE0", "OK", 1000)
- // fSleep(1000)
-
- call SubSendCmdWaitResp("ATE0V1&C1&D2X4", "OK", 1000)
- fSleep(300)
- call SubSendCmdWaitResp("AT+FCLASS=1", "OK", 1000)
- fSetBaudRate(@ComIO, 19200)
- fSleep(500)
- fFlushRxQueue(@ComIO)
- fFlushTxQueue(@ComIO)
-
-
- @szATCmd = "ATA"
- fSendATCmd(@ComIO, @szATCmd)
- exit (0)
-
- :TAPIRX_INIT2
- exit (0)
-
- :TAPIRX_INIT3
- exit (0)
-
- :TAPIRX_INIT4
- exit (0)
-
-
- //----------------------------------------------------------------------
- //----------------------------------------------------------------------
- :TAPITX_INIT1
- call SubC1TimingPara
- %AlreadySendFrame = 0
- %nRetryCount = 0
-
- fHardFlowControl(@ComIO, 9)
- fFlushRxQueue(@ComIO)
- call SubSendCmdWaitResp("ATE0V1&C1&D2", "OK", 3000)
- fSleep(150)
-
- call SubSendCmdWaitResp("AT+FCLASS=1", "OK", 3000)
- fSleep(150)
-
-
- fSetBaudRate(@ComIO, 19200)
- @szATCmd = "ATD"
- fSendATCmd(@ComIO, @szATCmd)
- exit (0)
-
- :TAPITX_INIT2
- exit (0)
-
- :TAPITX_INIT3
- exit (0)
-
- :TAPITX_INIT4
- exit (0)
-
-