home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 May / Disc 2 / PCU0503CD2.iso / BitFax_BitWare / BitWarePro / Simply / fclass2.scp < prev    next >
Encoding:
Text File  |  2001-09-05  |  24.9 KB  |  978 lines

  1. //---------------------------------------------------------
  2. // ext vars
  3. // @szATCmd  - str (LPSTR)
  4. // @szCID    - str
  5. // @szDCS    - str
  6. // @szDIS    - str
  7. // @szDCC    - str
  8. // @szHNG    - str
  9. // @szNSF    - str
  10. // @lpszRespBuff - str
  11. // @lPageCnt    - long
  12. // @lPageTotal  - long
  13. // @lSizeForNSF - long
  14. // @ComIO     
  15. // @GlStr1
  16. // @GlStr2
  17. // @RespBuffer
  18. //---------------------------------------------------------
  19.  
  20.  
  21. //---------------------------------------------------------
  22. // ext functions
  23. //fSetBaudRate(DWORD lpParam, DWORD Baud, DWORD dwN1, DWORD dwN2);
  24. //fWaitResponse(DWORD lpParam, DWORD lpBuf, DWORD lTimeOut, DWORD dwN1);
  25. //fSendATCmd(DWORD lpParam, DWORD lpBuf, DWORD dwN1, DWORD dwN2);
  26. //fSendDLE_ETX(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  27. //fSleep(DWORD lTime, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  28. //fFlushRxQueue(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  29. //fFlushTxQueue(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  30. //fSendOneChar(DWORD lpParam, DWORD dwCh, DWORD dwN1, DWORD dwN2);
  31. //fWaitOneChar(DWORD lpParam, DWORD lpResultChar, DWORD lTimeOut, DWORD dwN1);
  32. //fSetDTR(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  33. //fResetDTR(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  34. //fSetRTS(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  35. //fResetRTS(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  36. //fSetMisc(DWORD lpParam, DWORD nParity, DWORD nDataBits, DWORD nStopBits);
  37. //fSetMiscMore(DWORD lpParam, DWORD bDTRDSR, DWORD bRTSCTS, DWORD bXONXOFF);
  38. //fHardFlowControl(DWORD lpParam, DWORD Type, DWORD dwN1, DWORD dwN2);
  39. //fSoftFlowControl(DWORD lpParam, DWORD Type, DWORD dwN1, DWORD dwN2);
  40. //fSkipSpaceStrStr(DWORD s1, DWORD s2, DWORD dwN1, DWORD dwN2);
  41. //fTxFirstResponseError(DWORD s1, DWORD s2, DWORD dwN1, DWORD dwN2);
  42. //
  43. //   For fHardFlowControl:
  44. //     param1 - 0000X0YY   X  - Cts flow control
  45. //                         YY : 00 - RTS DISABLE
  46. //                         YY : 01 - RTS ENABLE
  47. //                         YY : 10 - RTS HANDSHAKE
  48. //                         YY : 11 - RTS TOGGLE
  49. //---------------------------------------------------------
  50.  
  51. //
  52. // This is the script file for Class2.
  53. //
  54. // trace
  55. declare STRING %szStr1, %szStr2;
  56. declare STRING %szStr3, %szStr4;
  57. declare STRING %szPass1, %szPass2;
  58. declare STRING %szPass3, %szPass4;
  59. declare STRING %szMsg1;
  60. declare long   %lRes;
  61. declare long   %lRes1;
  62. declare long   %lTemp;
  63. declare long   %lGRes;
  64. declare long   %lMsg1;
  65. declare char   %XON;
  66. declare STRING %szNULL;
  67.  
  68. //----------------------------------------------------------------------
  69. // SubSendCmdWaitResp
  70. //----------------------------------------------------------------------
  71. sub  SubSendCmdWaitResp(STRING #szCmd, STRING #szResp, long #lWaitTime)
  72. declare long %lRes;
  73. declare STRING %szCheckAT;
  74. declare long %lLimit;
  75.  
  76.         %lLimit = 0
  77.         %szCheckAT = "AT"
  78.         %lRes = fSkipSpaceStrStr(%szCheckAT, #szCmd)
  79.         if (%lRes = 0)
  80.            {
  81.            %lRes = 0
  82.            goto SendCmd1
  83.            }
  84.  
  85.         %lRes = fSendATCmd(@ComIO, #szCmd)
  86.         if (%lRes!=0)
  87.            {
  88.            %lRes = 101
  89.            goto SendCmd1
  90.            }
  91.  
  92. :SendCmd0
  93.         %lRes = fWaitResponse(@ComIO, #lWaitTime)
  94.         if (%lRes != 0)
  95.            {
  96.            %lRes = 101
  97.            goto SendCmd1
  98.            }
  99.  
  100.         %lRes = fSkipSpaceStrStr(#szResp, @RespBuffer)
  101.         if (%lRes != 0)
  102.            {
  103.            %lRes = 0
  104.            goto SendCmd1
  105.            }
  106.  
  107.         // some response but doesnt match, retry agian if necessary
  108.         %lLimit = %lLimit+1
  109.         if (%lLimit < 3)
  110.            goto SendCmd0
  111.  
  112.         // Not match...
  113.         %lRes = 101
  114.  
  115. :SendCmd1
  116.         %lGRes = %lRes
  117. endsub
  118.  
  119. //----------------------------------------------------------------------
  120. // For Dialing number
  121. //----------------------------------------------------------------------
  122. :TX_DIAL
  123.     fFlushRxQueue(@ComIO)
  124.     fSendATCmd(@ComIO, @szATCmd)
  125.     fFlushRxQueue(@ComIO)
  126.     exit(0)
  127.  
  128.  
  129.  
  130. //----------------------------------------------------------------------
  131. // For TX initialization part 1
  132. //
  133. //   and for fHardFlowControl(@ComIO, 9) - CTS on / RTS on
  134. //----------------------------------------------------------------------
  135. :TX_INIT1
  136.     fHardFlowControl(@ComIO, 9)
  137.     fSetBaudRate(@ComIO, 19200)
  138.     fFlushRxQueue(@ComIO)
  139.     fFlushTxQueue(@ComIO)
  140.     @szATCmd = "ATS0=0M0E0"
  141.     fSendATCmd(@ComIO, @szATCmd)
  142.     fSleep(500)
  143.     fFlushRxQueue(@ComIO)
  144.     @szATCmd = "ATS0=0M0E0"
  145.     fSendATCmd(@ComIO, @szATCmd)
  146.     fSleep(500)
  147.     fFlushRxQueue(@ComIO)
  148.  
  149.     call SubSendCmdWaitResp("ATS0=0", "OK", 3000)
  150.     fSleep(150)
  151.  
  152.     call SubSendCmdWaitResp("ATE0V1&C1", "OK", 3000)
  153.     fSleep(150)
  154.  
  155. //  call SubSendCmdWaitResp(@szATCmd, "OK", 3000)
  156.  
  157.     %lRes1 = %lGRes
  158.     call SubSendCmdWaitResp("AT&K3", "OK", 3000)
  159. //  call SubSendCmdWaitResp("AT&K4", "OK", 3000)
  160.     %lGRes = %lRes1
  161.     fSleep(150)
  162.  
  163.     exit (%lGRes)
  164.  
  165. :TX_INIT2
  166.     call SubSendCmdWaitResp("AT+FCLASS=2", "OK", 3000)
  167.     fSleep(150)
  168.  
  169.     if (%lGRes = 0)
  170.         fSetBaudRate(@ComIO, 19200)
  171.     exit (%lGRes)
  172.  
  173. :TX_INIT3
  174.     %szStr1 = "AT+FLID="
  175.     %szStr2 = %szStr1 + @szCID
  176.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  177.     fSleep(150)
  178.     if (%lGRes!=0)
  179.         exit (%lGRes)
  180.  
  181.     %szStr1 = "AT+FDIS="
  182.     %szStr2 = %szStr1 + @szDCC
  183.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  184.     fSleep(150)
  185.     if (%lGRes!=0)
  186.         exit (%lGRes)
  187.  
  188.     %szStr2 = "AT+FAA=0"
  189.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  190.     fSleep(150)
  191.     if (%lGRes!=0)
  192.         exit (%lGRes)
  193.  
  194.     fFlushRxQueue(@ComIO)
  195.     %szStr2 = "AT+FBOR=0"
  196.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  197.     fSleep(150)
  198.     if (%lGRes!=0)
  199.         exit (%lGRes)
  200.  
  201.  
  202. //
  203. // You can do all kind of thing here...
  204. :TX_INIT4
  205.     exit (0)
  206.  
  207.  
  208. //----------------------------------------------------------------------
  209. // Now we go to Tx phase B - Wait for OK and send AT+FDR
  210. //
  211. // ??? I dont know whether we need to wait for FCON or not...
  212. //----------------------------------------------------------------------
  213. :TXPH_B_START
  214.     %szStr3 = "This is in TXPH_B_START"
  215.     %lRes = fPrintMsg(%szStr3)
  216.  
  217. :TXPH_B_START1
  218.     %lRes = fWaitResponse(@ComIO, 5000) 
  219.     if (%lRes != 0)
  220.         exit (4)
  221.  
  222.     // Check to see if any error happens. eg: No dial tone, busy...
  223.     %lRes = fTxFirstResponseError(@RespBuffer)
  224.     if (%lRes != 0)
  225.        {
  226.        exit (%lRes)
  227.        }
  228.  
  229.     // Yes, sth is the buffer, we need to compare it
  230.     %szStr3 = "OK"
  231.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  232.     if (%lRes != 0)
  233.         {
  234.         %szStr3 = "AT+FDT"
  235.         fSendATCmd(@ComIO, %szStr3)
  236.         exit (0)            // OK
  237.         }
  238.  
  239.     %szStr3 = "+FNSF"
  240.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  241.     if (%lRes != 0)
  242.         {
  243.         @szNSF = @RespBuffer
  244.         goto TXPH_B_START1
  245.         }
  246.  
  247.     %szStr3 = "+FCSI"
  248.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  249.     if (%lRes != 0)
  250.         {
  251.         @szCID = @RespBuffer
  252.         goto TXPH_B_START1
  253.         }
  254.  
  255.     %szStr3 = "+FDIS"
  256.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  257.     if (%lRes != 0)
  258.         {
  259.         @szDIS = @RespBuffer
  260.         goto TXPH_B_START1
  261.         }
  262.  
  263.     // The rest of them go back to start...
  264.     goto TXPH_B_START1
  265.  
  266. //----------------------------------------------------------------------
  267. // Tx Wait for training - Wait for CONNECT and XON
  268. //----------------------------------------------------------------------
  269. :TXTRAIN_START
  270.     %szStr3 = "This is in TXTRAIN_START"
  271.     %lRes = fPrintMsg(%szStr3)
  272.  
  273. :TXTRAIN_START1
  274.     %lRes = fWaitResponse(@ComIO, 20000) 
  275.     if (%lRes != 0)
  276.         exit (1)
  277.  
  278.     // Check for FDCS
  279.     %szStr3 = "FDCS"
  280.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  281.     if (%lRes != 0)
  282.        {
  283.        @szDCS = @RespBuffer
  284.        }
  285.  
  286.     if (%lRes != 0)
  287.         goto TXTRAIN_START1
  288.  
  289.     // Yes, sth is the buffer, we need to compare it
  290.     %szStr3 = "CONNECT"
  291.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  292.     if (%lRes != 0)
  293.         exit (0)
  294.     else
  295.         goto TXTRAIN_START1
  296.  
  297.  
  298. //----------------------------------------------------------------------
  299. //----------------------------------------------------------------------
  300. :TXPH_C_START    
  301.     fSoftFlowControl(@ComIO, 1)
  302.     exit (0)
  303.  
  304.  
  305. //----------------------------------------------------------------------
  306. // TX Phase D
  307. // 1) Wait for OK 
  308. // 2) Send AT+FET=0/2 
  309. // 3) Wait for +FPTS/+FHNG
  310. // 4) Wait for OK 
  311. // 5) Send AT+FDT if necessary
  312. // 6) Wait for CONNECT and XON if necessary
  313. //----------------------------------------------------------------------
  314. :TXPH_D_START
  315.     %szStr3 = "This is in TXPH_D_START"
  316.     %lRes = fPrintMsg(%szStr3)
  317.      fFlushRxQueue(@ComIO)
  318.      fSendDLE_ETX(@ComIO)
  319.  
  320. :TXPH_D0
  321.      %lRes = fWaitResponse(@ComIO, 25000)
  322.  
  323.      // NO response error (3)
  324.      if (%lRes != 0)
  325.         exit (3)
  326.  
  327.  
  328.     // Some dumb modem, even in no-echo mode, will still echo AT+FDT
  329.     %szStr3 = "AT+FDT"
  330.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  331.     if (%lRes != 0)
  332.        goto TXPH_D0
  333.  
  334.  
  335.      %szStr3 = "OK"
  336.      %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  337.      if (%lRes = 0)
  338.         goto TXPH_D0
  339.  
  340.     %lRes = @lPageCnt + 1
  341.     @lPageCnt = %lRes
  342.  
  343.     if (@lPageCnt >= @lPageTotal)
  344.         {
  345.         %lTemp = 0
  346.         @szATCmd = "AT+FET=2"
  347.         fSendATCmd(@ComIO, @szATCmd)
  348.         }
  349.     else
  350.         {
  351.         %lTemp = 1
  352.         @szATCmd = "AT+FET=0"
  353.         fSendATCmd(@ComIO, @szATCmd)
  354.         }
  355.  
  356. :TXPH_D1
  357.     %lRes = fWaitResponse(@ComIO, 20000) 
  358.     if (%lRes != 0)
  359.         exit (3)
  360.  
  361.     // Check to see if get the +FHNG signal...
  362.     %szStr3 = "FHNG"
  363.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  364.     if (%lRes != 0)
  365.         {
  366.         @szHNG = @RespBuffer
  367.         exit (0)
  368.         }
  369.  
  370.     //----------------------------------------------------------
  371.     // Check for bad page response...  NOTE A.  (Only FPTS:1 is good)
  372.     //----------------------------------------------------------
  373.             %szStr3 = "FPTS:0"
  374.             %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  375.             if (%lRes != 0)
  376.                 exit (3)
  377.  
  378.             %szStr3 = "FPTS:2"
  379.             %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  380.             if (%lRes != 0)
  381.                 exit (3)
  382.  
  383.             %szStr3 = "FPTS:3"
  384.             %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  385.             if (%lRes != 0)
  386.                 exit (3)
  387.  
  388.             %szStr3 = "FPTS:4"
  389.             %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  390.             if (%lRes != 0)
  391.                 exit (3)
  392.  
  393.             %szStr3 = "FPTS:5"
  394.             %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  395.             if (%lRes != 0)
  396.                 exit (3)
  397.  
  398.             %szStr3 = "FPTS:6"
  399.             %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  400.             if (%lRes != 0)
  401.                 exit (3)
  402.  
  403.             %szStr3 = "FPTS:7"
  404.             %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  405.             if (%lRes != 0)
  406.                 exit (3)
  407.  
  408.     //----------------------------------------------------------
  409.     // End of check bad page.  See NOTE A above
  410.     //----------------------------------------------------------
  411.  
  412.     %szStr3 = "OK"
  413.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  414.     if (%lRes != 0)
  415.         goto TXPH_D2
  416.     goto TXPH_D1
  417.  
  418. //
  419. // Send AT+FDT and wait for connect
  420. //
  421. :TXPH_D2
  422.         %szStr3 = "AT+FDT"
  423.         fSendATCmd(@ComIO, %szStr3)
  424.  
  425. :TXPH_D3
  426.         %lRes = fWaitResponse(@ComIO, 20000) 
  427.         if (%lRes != 0)
  428.            exit (3)
  429.  
  430.         // Yes, sth is the buffer, we need to compare it
  431.         %szStr3 = "CONNECT"
  432.         %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  433.         if (%lRes != 0)
  434.            exit (1)
  435.         else
  436.            goto TXPH_D3
  437.  
  438. //----------------------------------------------------------------------
  439. // TX Disconnecting the line
  440. //----------------------------------------------------------------------
  441. :ABORT1
  442. :TX_DISC1
  443.     %szStr3 = "This is in TX_DISC1"
  444.     %lRes = fPrintMsg(%szStr3)
  445.  
  446.         fFlushRxQueue(@ComIO)
  447.         fSendDLE_ETX(@ComIO)
  448.         %szStr3 = "AT"
  449.         fSendATCmd(@ComIO, %szStr3)
  450.         fSleep(1000)
  451.         %szStr3 = "AT"
  452.         fSendATCmd(@ComIO, %szStr3)
  453.         fSleep(1000)
  454.         fFlushRxQueue(@ComIO)
  455.         fFlushTxQueue(@ComIO)
  456.         %szStr3 = "AT+FCLASS=0"
  457.         fSendATCmd(@ComIO, %szStr3)
  458.         fSleep(1000)
  459.         fSetBaudRate(@ComIO, 2400)
  460.         fSleep(200)
  461.         %szStr3 = "ATH0"
  462.         fSendATCmd(@ComIO, %szStr3)
  463.         fSleep(200)
  464.         fFlushRxQueue(@ComIO)
  465.         fSendATCmd(@ComIO, @szATCmd)  // comes from szTxQuitString
  466.         fSleep(500)
  467.         fResetDTR(@ComIO)
  468.         fSleep(1000)
  469.         fSetDTR(@ComIO)
  470.         fFlushRxQueue(@ComIO)
  471.         fFlushTxQueue(@ComIO)
  472.         exit (0)
  473.  
  474. :ABORT2
  475. :TX_DISC2
  476.         fFlushRxQueue(@ComIO)
  477.         fFlushTxQueue(@ComIO)
  478.         fSendATCmd(@ComIO, @szATCmd)
  479.         fSleep(1000)
  480.         fFlushRxQueue(@ComIO)
  481.         fFlushTxQueue(@ComIO)
  482.         exit (0)
  483.  
  484. :TX_DISC3
  485.         exit (0)
  486.  
  487. :TX_DISC4
  488.         exit (0)
  489.  
  490. //----------------------------------------------------------------------
  491. // The following are for RX fax
  492. //----------------------------------------------------------------------
  493. //----------------------------------------------------------------------
  494. //  For HardFlowControl - use 11 means CTS on/RTS toggle.
  495. //----------------------------------------------------------------------
  496. :RX_INIT1
  497.     fHardFlowControl(@ComIO, 9)
  498.     fSoftFlowControl(@ComIO, 0)
  499.     fSetBaudRate(@ComIO, 19200)
  500.     fFlushRxQueue(@ComIO)
  501.     fFlushTxQueue(@ComIO)
  502.     @szATCmd = "ATS0=0M0E0"
  503.     fSendATCmd(@ComIO, @szATCmd)
  504.     fSleep(500)
  505.     fFlushRxQueue(@ComIO)
  506.     @szATCmd = "ATS0=0M0E0"
  507.     fSendATCmd(@ComIO, @szATCmd)
  508.     fSleep(500)
  509.     fFlushRxQueue(@ComIO)
  510.     call SubSendCmdWaitResp("ATS0=0", "OK", 3000)
  511.     fSleep(150)
  512.     call SubSendCmdWaitResp("AT&FE0V1&C1&D2", "OK", 3000)
  513.     fSleep(150)
  514.     exit (%lGRes)
  515.  
  516. :RX_INIT2
  517.     call SubSendCmdWaitResp("AT+FCLASS=2", "OK", 3000)
  518.     fSleep(150)
  519.     if (%lGRes = 0)
  520.         fSetBaudRate(@ComIO, 19200)
  521.     exit (%lGRes)
  522.  
  523. :RX_INIT3
  524.     %szStr1 = "AT+FLID="
  525.     %szStr2 = %szStr1 + @szCID
  526.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  527.     fSleep(150)
  528.     if (%lGRes!=0)
  529.         exit (%lGRes)
  530.  
  531.     %szStr1 = "AT+FDIS="
  532.     %szStr2 = %szStr1 + @szDCC
  533.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  534.     fSleep(150)
  535.     if (%lGRes!=0)
  536.         exit (%lGRes)
  537.  
  538.     %szStr2 = "AT+FAA=0"
  539.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  540.     fSleep(150)
  541.     if (%lGRes!=0)
  542.         exit (%lGRes)
  543.  
  544.     %szStr2 = "AT+FBOR=1"
  545.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  546.     fSleep(150)
  547.     if (%lGRes!=0)
  548.         exit (%lGRes)
  549.  
  550.  
  551.     %szStr2 = "AT+FCR=1"
  552.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  553.     fSleep(150)
  554.     if (%lGRes!=0)
  555.         exit (%lGRes)
  556.  
  557. :RX_INIT4
  558.     exit (0)
  559.  
  560.  
  561. //----------------------------------------------------------------------
  562. // RX_WAITCALL
  563. //
  564. // Wait for 3 seconds for RING signal
  565. //----------------------------------------------------------------------
  566. :RX_WAITCALL
  567.     %szStr3 = "This is in RX_WAITCALL (C2)"
  568.     %lRes = fPrintMsg(%szStr3)
  569.  
  570.         fFlushRxQueue(@ComIO)
  571.         fFlushTxQueue(@ComIO)
  572.         %lRes = fWaitResponse(@ComIO, 3000) 
  573.         if (%lRes != 0)
  574.             exit (%lRes)
  575.  
  576.         // Something is in the buffer, check if this is RING signal
  577.         %szStr3 = "RING"
  578.         %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  579.         if (%lRes != 0)
  580.            exit (0)
  581.         else
  582.            exit (1)
  583.  
  584.  
  585. //----------------------------------------------------------------------
  586. // RX_ANSWERCALL
  587. //----------------------------------------------------------------------
  588. :RX_ANSWERCALL
  589.     %szStr3 = "This is in RX_ANSWERCALL"
  590.     %lRes = fPrintMsg(%szStr3)
  591.  
  592.     fFlushRxQueue(@ComIO)
  593.     fFlushTxQueue(@ComIO)
  594.  
  595.     @lPageTotal = 0
  596.     @lPageCnt = 0
  597.  
  598.     call SubSendCmdWaitResp("AT+FCLASS=2", "OK", 3000)
  599.     fSleep(150)
  600.     if (%lGRes = 0)
  601.        fSetBaudRate(@ComIO, 19200)
  602.  
  603.  
  604.     fFlushRxQueue(@ComIO)
  605.     @szATCmd = "ATA"
  606.     fSendATCmd(@ComIO, @szATCmd)
  607.     exit (0)
  608.  
  609. //----------------------------------------------------------------------
  610. // RX_PH_B_START
  611. //----------------------------------------------------------------------
  612. :RXPH_B_START
  613.     %szStr3 = "This is in RXPH_B_START"
  614.     %lRes = fPrintMsg(%szStr3)
  615.  
  616.     %lRes = fWaitResponse(@ComIO, 30000) 
  617.     if (%lRes != 0)
  618.         exit (1)
  619.  
  620.     // Check to see if any error happens. eg: No dial tone, busy...
  621.     %lRes = fPrintMsg(@RespBuffer)
  622.  
  623.  
  624.     %lRes = fTxFirstResponseError(@RespBuffer)
  625.     if (%lRes != 0)
  626.        {
  627.        exit (%lRes)
  628.        }
  629.  
  630.     // Yes, sth is the buffer, we need to compare it
  631.     %szStr3 = "OK"
  632.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  633.     if (%lRes != 0)
  634.         {
  635.         %szStr3 = "AT+FDR"
  636.         fSendATCmd(@ComIO, %szStr3)
  637.         exit (0)            // OK
  638.         }
  639.  
  640.     %szStr3 = "+FNSS"
  641.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  642.     if (%lRes != 0)
  643.         {
  644.         @szNSF = @RespBuffer
  645.         goto RXPH_B_START
  646.         }
  647.  
  648.     %szStr3 = "+FTSI"
  649.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  650.     if (%lRes != 0)
  651.         {
  652.         @szCID = @RespBuffer
  653.         goto RXPH_B_START
  654.         }
  655.  
  656.     %szStr3 = "+FDCS"
  657.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  658.     if (%lRes != 0)
  659.         {
  660.         @szDCS = @RespBuffer
  661.         goto RXPH_B_START
  662.         }
  663.  
  664.     // The rest of them go back to start...
  665.     goto RXPH_B_START
  666.  
  667.  
  668.  
  669. //----------------------------------------------------------------------
  670. // Rx Wait for training - Wait for CONNECT and XON
  671. //----------------------------------------------------------------------
  672. :RXTRAIN_START
  673.     %szStr3 = "This is in RXTRAIN_START"
  674.     %lRes = fPrintMsg(%szStr3)
  675.  
  676.  
  677.     %lRes = fWaitResponse(@ComIO, 20000) 
  678.     if (%lRes != 0)
  679.         exit (1)
  680.  
  681.     // Check for FDCS
  682.     %szStr3 = "FDCS"
  683.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  684.     if (%lRes != 0)
  685.        {
  686.        @szDCS = @RespBuffer
  687.        }
  688.  
  689.     if (%lRes != 0)
  690.         goto RXTRAIN_START
  691.  
  692.     // Yes, sth is the buffer, we need to compare it
  693.     %szStr3 = "CONNECT"
  694.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  695.     if (%lRes != 0)
  696.         exit (0)
  697.     else
  698.         goto RXTRAIN_START
  699.  
  700.  
  701.  
  702. //----------------------------------------------------------------------
  703. // RX Phase D
  704. //
  705. // exit (3) - error
  706. //      (0) - No more page to receive
  707. //      (1) - more page to receive - go to phase C
  708. //      (2) - more page to receive - BUT go to phase B
  709. //----------------------------------------------------------------------
  710. :RXPH_D_START
  711.     %szStr3 = "This is in RXPH_D_START"
  712.     %lRes = fPrintMsg(%szStr3)
  713.  
  714.  
  715.      %lTemp = 0
  716.      %lRes = @lPageTotal + 1
  717.      @lPageTotal = %lRes
  718.  
  719.      %lRes = @lPageCnt + 1
  720.      @lPageCnt = %lRes
  721.  
  722.  
  723. :RXPH_D0
  724.      %lRes = fWaitResponse(@ComIO, 25000)
  725.  
  726.      // NO response error (3)
  727.      if (%lRes != 0)
  728.         exit (3)
  729.  
  730.      %szStr3 = "FET:0"
  731.      %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  732.      if (%lRes != 0)
  733.     %lTemp = 1
  734.  
  735.      if (%lRes != 0)
  736.         goto RXPH_D1
  737.  
  738.  
  739.      %szStr3 = "FET:2"
  740.      %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  741.      if (%lRes != 0)
  742.         goto RXPH_D1
  743.  
  744.      %szStr3 = "ERROR"
  745.      %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  746.      if (%lRes != 0)
  747.         exit (3)
  748.  
  749.      %szStr3 = "FHNG"
  750.      %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  751.      if (%lRes != 0)
  752.         {
  753.             @szHNG = @RespBuffer
  754.         exit (3)
  755.         }
  756.  
  757.      goto RXPH_D0
  758.  
  759. :RXPH_D1
  760.     %szStr3 = "This is in RXPH_D1_111"
  761.     %lRes = fPrintMsg(%szStr3)
  762.  
  763.     %lRes = fWaitResponse(@ComIO, 20000) 
  764.     if (%lRes != 0)
  765.         exit (3)
  766.  
  767.     // Check to see if get the +FHNG signal...
  768.     %szStr3 = "FHNG"
  769.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  770.     if (%lRes != 0)
  771.         {
  772.         @szHNG = @RespBuffer
  773.         exit (0)
  774.         }
  775.  
  776.     %szStr3 = "OK"
  777.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  778.     if (%lRes != 0)
  779.         goto RXPH_D2
  780.     goto RXPH_D1
  781.  
  782. //
  783. // Send AT+FDT and wait for connect
  784. //
  785. :RXPH_D2
  786.     %szStr3 = "This is in RXPH_D2_111"
  787.     %lRes = fPrintMsg(%szStr3)
  788.  
  789.     %szStr3 = "AT+FDR"
  790.     fSendATCmd(@ComIO, %szStr3)
  791.  
  792. :RXPH_D3
  793.     %lRes = fWaitResponse(@ComIO, 20000) 
  794.     if (%lRes != 0)
  795.        exit (3)
  796.  
  797.     // Some dumb modem, even in no-echo mode, will still echo AT+FDR
  798.     %szStr3 = "AT+FDR"
  799.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  800.     if (%lRes != 0)
  801.        goto RXPH_D3
  802.  
  803.  
  804.  
  805.     // Yes, sth is the buffer, we need to compare it.
  806.     %szStr3 = "CONNECT"
  807.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  808.     if (%lRes != 0)
  809.        exit (1)            // more page to receive - go to phase C
  810.  
  811.     %szStr3 = "FHNG"
  812.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  813.     if (%lRes != 0)
  814.            {
  815.            @szHNG = @RespBuffer
  816.            exit (0)
  817.            }
  818.  
  819.     %szStr3 = "OK"
  820.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  821.     if (%lRes != 0)
  822.        exit (0)
  823.  
  824.     %szStr3 = "ERROR"
  825.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  826.     if (%lRes != 0)
  827.        exit (3)
  828.  
  829.  
  830. //----------------------------------------------------------------------
  831. //
  832. //----------------------------------------------------------------------
  833. :RX_DISC1
  834.     %szStr3 = "This is in RX_DISC1"
  835.     %lRes = fPrintMsg(%szStr3)
  836.  
  837.         fFlushRxQueue(@ComIO)
  838.         fSendDLE_ETX(@ComIO)
  839.         %szStr3 = "AT"
  840.         fSendATCmd(@ComIO, %szStr3)
  841.         fSleep(1000)
  842.         %szStr3 = "AT"
  843.         fSendATCmd(@ComIO, %szStr3)
  844.         fSleep(1000)
  845.         fFlushRxQueue(@ComIO)
  846.         fFlushTxQueue(@ComIO)
  847.         %szStr3 = "AT+FCLASS=0"
  848.         fSendATCmd(@ComIO, %szStr3)
  849.         fSleep(1000)
  850.         fSetBaudRate(@ComIO, 2400)
  851.         fSleep(200)
  852.         %szStr3 = "ATH0"
  853.         fSendATCmd(@ComIO, %szStr3)
  854.         fSleep(200)
  855.         fFlushRxQueue(@ComIO)
  856.         fSendATCmd(@ComIO, @szATCmd)  // comes from szTxQuitString
  857.         fSleep(500)
  858.         fResetDTR(@ComIO)
  859.         fSleep(1000)
  860.         fSetDTR(@ComIO)
  861.         fFlushRxQueue(@ComIO)
  862.         fFlushTxQueue(@ComIO)
  863.         exit (0)
  864.  
  865. :RX_DISC2
  866.         fFlushRxQueue(@ComIO)
  867.         fFlushTxQueue(@ComIO)
  868.         fSendATCmd(@ComIO, @szATCmd)
  869.         fSleep(1000)
  870.         fFlushRxQueue(@ComIO)
  871.         fFlushTxQueue(@ComIO)
  872.     exit (0)
  873.  
  874. :RX_DISC3
  875.     exit (0)
  876.  
  877. :RX_DISC4
  878.     exit (0)
  879.  
  880.  
  881. //----------------------------------------------------------------------
  882. //----------------------------------------------------------------------
  883. :TAPIRX_INIT1
  884.     %szStr3 = "This is in TAPIRX_INIT"
  885.     %lRes = fPrintMsg(%szStr3)
  886.  
  887.     fSendOneChar(@ComIO, 16)
  888.     fSendOneChar(@ComIO, 3)
  889.     fSendOneChar(@ComIO, 16)
  890.     fSendOneChar(@ComIO, 3)
  891.  
  892.     fSendOneChar(@ComIO, 16)
  893.     fSendOneChar(@ComIO, 24)
  894.     call SubSendCmdWaitResp("AT", "OK", 1000)
  895.     fSleep(150)
  896.     call SubSendCmdWaitResp("ATE0V1", "OK", 1000)
  897.     fSleep(150)
  898.     fHardFlowControl(@ComIO, 9)
  899.     fSoftFlowControl(@ComIO, 0)
  900.     fSetBaudRate(@ComIO, 19200)
  901.     fFlushRxQueue(@ComIO)
  902.     fFlushTxQueue(@ComIO)
  903.  
  904.  
  905.     call SubSendCmdWaitResp("AT#CLS=0", "OK", 1000)
  906.     fSleep(500)
  907.     call SubSendCmdWaitResp("AT#BDR=0", "OK", 1000)
  908.     fSleep(150)
  909.     call SubSendCmdWaitResp("ATE0V1&C1&D2", "OK", 1000)
  910.     fSleep(150)
  911.     call SubSendCmdWaitResp("AT+FCLASS=2", "OK", 1000)
  912.     fSleep(150)
  913.     fSetBaudRate(@ComIO, 19200)
  914.     call SubSendCmdWaitResp("AT+FAA=0", "OK", 1000)
  915.     fSleep(150)
  916.     call SubSendCmdWaitResp("AT+FBOR=1", "OK", 1000)
  917.     fSleep(150)
  918.     call SubSendCmdWaitResp("AT+FCR=1", "OK", 1000)
  919.     fSleep(150)
  920.  
  921.     %szStr1 = "AT+FLID="
  922.     %szStr2 = %szStr1 + @szCID
  923.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  924.     fSleep(150)
  925.     if (%lGRes!=0)
  926.         exit (%lGRes)
  927.  
  928.     %szStr1 = "AT+FDIS="
  929.     %szStr2 = %szStr1 + @szDCC
  930.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  931.     fSleep(150)
  932.     if (%lGRes!=0)
  933.         exit (%lGRes)
  934.  
  935.     fFlushRxQueue(@ComIO)
  936.     fFlushTxQueue(@ComIO)
  937.     @szATCmd = "ATA"
  938.     fSendATCmd(@ComIO, @szATCmd)
  939.     exit (0)
  940.  
  941. :TAPIRX_INIT2
  942.     exit (0)
  943.  
  944. :TAPIRX_INIT3
  945.     exit (0)
  946.  
  947.  
  948. //----------------------------------------------------------------------
  949. //----------------------------------------------------------------------
  950. :TAPITX_INIT1
  951.     fHardFlowControl(@ComIO, 9)
  952.     fFlushRxQueue(@ComIO)
  953. //    call SubSendCmdWaitResp("ATE0V1&C1", "OK", 3000)
  954.     call SubSendCmdWaitResp("AT+FCLASS=2", "OK", 3000)
  955.     fSleep(150)
  956.     fSetBaudRate(@ComIO, 19200)
  957.  
  958. //    %szStr1 = "AT+FLID="
  959. //    %szStr2 = %szStr1 + @szCID
  960. //    call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  961.  
  962. //    %szStr1 = "AT+FDIS="
  963. //    %szStr2 = %szStr1 + @szDCC
  964. //    call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  965.  
  966.     @szATCmd = "ATD"
  967.     fSendATCmd(@ComIO, @szATCmd)
  968.     exit (0)
  969.  
  970. :TAPITX_INIT2
  971.     exit (0)
  972.  
  973. :TAPITX_INIT3
  974.     exit (0)
  975.  
  976.  
  977.  
  978.