FaxProcess1.c
上传用户:xhjmsc
上传日期:2019-09-13
资源大小:389k
文件大小:24k
源码类别:

传真(Fax)编程

开发平台:

C/C++

  1. #include "includeH.h"
  2. //**************************************************************************
  3. void  FaxRXProcess(void)
  4. {     
  5.       unsigned char ucFlashSttsOverflowCnt=0,
  6.                     ucGeneralCount=0,ucGeneralCnt=0,
  7.                     ucRxIndex3=0,ucRxIndex2=0,
  8.                     ucRxIndex1=0,ucRxIndex0=0;
  9.       unsigned int wNextPageAddress=0,wPageAddress,
  10.                    wGeneralCount=0,wDataRearCount=0;
  11.       FaxRxInit();
  12. /***************************************************************************/      
  13. //detect ringing two times
  14. //ATA     
  15.       
  16.       SendATcmdATA();                 //Connect
  17.       while (1)  //CONNECT(54) 0D 0A
  18.       {
  19.        ucRxIndex1=gucUartRxCnt-3;
  20.         ucRxIndex0=gucUartRxCnt-2;
  21.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x54==aucUartRxBuf[ucRxIndex1]))
  22.           break;
  23.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  24.         RxFaxTimeOverflowErrorQuit();
  25.       }
  26.       
  27.       Delay1500ms();  // delay 1.5S minimun 1 second
  28.       
  29.       SendATdataFTHCSI();    //The final bit is 0. The modem will generates CONNECT message.
  30.       while (1)  //CONNECT(54) 0D 0A
  31.       {
  32.         ucRxIndex1=gucUartRxCnt-3;
  33.         ucRxIndex0=gucUartRxCnt-2;
  34.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x54==aucUartRxBuf[ucRxIndex1]))
  35.           break;
  36.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  37.         RxFaxTimeOverflowErrorQuit();
  38.       }
  39.       
  40.       for (ucGeneralCount=0; ucGeneralCount<50; ucGeneralCount++)// delay 1.5S minimun 1 second
  41.       {
  42.          ATcmdDelay();  //50ms
  43.       }
  44.       SendATdataFTHDIS();//SendATdataFTHTSI(sizeof (FTHDIS)); a bug of Sep.18
  45.       
  46.       while (1)    //O K 0D 0A
  47.       {
  48.         ucRxIndex1=gucUartRxCnt-3;
  49.         ucRxIndex0=gucUartRxCnt-2;
  50.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1])) //K ==0x4b
  51.           break;
  52.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  53.         RxFaxTimeOverflowErrorQuit();
  54.       }
  55.           
  56. //*
  57. //FRH  TSI (transmitting subscriber identification)        
  58.       SendATcmdFRH();  
  59.       while (1)    //Connect data.....OK 0D 0A
  60.       {
  61.         ucRxIndex1=gucUartRxCnt-3;
  62.         ucRxIndex0=gucUartRxCnt-2;
  63.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x54==aucUartRxBuf[ucRxIndex1]))
  64.           break;
  65.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x52==aucUartRxBuf[ucRxIndex1]))
  66.           break;
  67.         //if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4b==aucUartRxBuf[ucRxIndex1]))
  68.           //{gucFrhErrorStatus=0x03;break;}
  69.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  70.         RxFaxTimeOverflowErrorQuit();
  71.       }//while
  72.       
  73.       for (ucGeneralCnt=0;ucGeneralCnt<5;ucGeneralCnt++)
  74.       {
  75.       
  76.       
  77.       if (gucFrhErrorStatus==0x03 || (0x0d==aucUartRxBuf[ucRxIndex0])&&(0x52==aucUartRxBuf[ucRxIndex1]))
  78.       {
  79.        SendATcmdSuffix();
  80.        ATcmdDelay();
  81.        ATcmdDelay();
  82.        ATcmdDelay();
  83.        SendATcmdPrefix();
  84.        ATcmdDelay();
  85.        SendATcmdSuffix();
  86.        ATcmdDelay();
  87.        ATcmdDelay();
  88.        ATcmdDelay();
  89.        Delay2000ms();//add at Jan. 16, 2007
  90.        FthCsiDis();
  91.        SendATcmdFRH();  
  92.        while (1)    //Connect data.....OK 0D 0A
  93.        {
  94.         ucRxIndex1=gucUartRxCnt-3;
  95.         ucRxIndex0=gucUartRxCnt-2;
  96.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x54==aucUartRxBuf[ucRxIndex1]))
  97.           break;
  98.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x52==aucUartRxBuf[ucRxIndex1]))
  99.           break;
  100.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  101.         RxFaxTimeOverflowErrorQuit();
  102.        }//while
  103.       }//if
  104.       if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x54==aucUartRxBuf[ucRxIndex1]))
  105.       {
  106.         while (1)    
  107.         {
  108.          ucRxIndex1=gucUartRxCnt-3;
  109.           ucRxIndex0=gucUartRxCnt-2;
  110.           if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
  111.             break;
  112.           if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x52==aucUartRxBuf[ucRxIndex1]))
  113.             break;
  114.           if ((0x13==aucUartRxBuf[ucRxIndex0])&&(0xff==aucUartRxBuf[ucRxIndex1]))
  115.             {gucFrhErrorStatus=CNGFthOnlySendOneNSF;}
  116.           //if check time>min. 5S, Receive Fax error, progra should be quit  
  117.           RxFaxTimeOverflowErrorQuit();
  118.         }//while
  119.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x52==aucUartRxBuf[ucRxIndex1]))
  120.             continue;//Response is not OK, but NO Carrier. should Re FTH CSI and DIS
  121.         else
  122.             break;//break for cycle
  123.       }//if
  124.       }//for
  125.       
  126.       ucRxIndex0=gucUartRxCnt-25;
  127.       for (ucGeneralCnt=0;ucGeneralCnt<25;ucGeneralCnt++)
  128.       {FRHTSI[ucRxIndex1++]=aucUartRxBuf[ucRxIndex0++];}
  129.       
  130. //FRH DCS (digital command signal)
  131.       if (gucFrhErrorStatus!=CNGFthOnlySendOneNSF)
  132.       {          
  133.         SendATcmdFRH(); 
  134.         while (1)    
  135.         {
  136.          ucRxIndex1=gucUartRxCnt-3;
  137.           ucRxIndex0=gucUartRxCnt-2;
  138.           if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x54==aucUartRxBuf[ucRxIndex1]))
  139.             break;
  140.           //if check time>min. 5S, Receive Fax error, progra should be quit  
  141.           RxFaxTimeOverflowErrorQuit();
  142.         }//while
  143.       
  144.         while (1)    
  145.         {
  146.          ucRxIndex1=gucUartRxCnt-3;
  147.           ucRxIndex0=gucUartRxCnt-2;
  148.           if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
  149.             break;
  150.           //if check time>min. 5S, Receive Fax error, progra should be quit  
  151.           RxFaxTimeOverflowErrorQuit();
  152.         }//while      
  153.       }//if
  154. //*/
  155.       if (gucFrhErrorStatus==0x03) return;
  156. //FRM TCF (training check)
  157.       SendATcmdFRM();
  158.       while (1)    
  159.       {
  160.        ucRxIndex1=gucUartRxCnt-3;
  161.         ucRxIndex0=gucUartRxCnt-2;
  162.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x54==aucUartRxBuf[ucRxIndex1]))
  163.           break;
  164.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  165.         RxFaxTimeOverflowErrorQuit();
  166.       }
  167.       if (gucFrhErrorStatus==0x03) return;
  168.       //Carrier==Training check     
  169. ///* //add the No carrier check a bug of Dec.25,2006     
  170.       while (1)    
  171.       {
  172.         ucRxIndex1=gucUartRxCnt-3;
  173.         ucRxIndex0=gucUartRxCnt-2;
  174.         if ((aucUartRxBuf[ucRxIndex0]==0x0d)&&(aucUartRxBuf[ucRxIndex1]==0x52))//4B Result code is not OK, but No carrier
  175.           break;
  176.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  177.         RxFaxTimeOverflowErrorQuit();
  178.       }
  179.       if (gucFrhErrorStatus==0x03) return;      
  180. //*/   
  181. //Training check over   
  182. //FTHCFR  (confirmation to receive)
  183.       SendATcmdFTH();
  184.       while (1)    //Connect
  185.       {
  186.        ucRxIndex1=gucUartRxCnt-3;
  187.         ucRxIndex0=gucUartRxCnt-2;
  188.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x54==aucUartRxBuf[ucRxIndex1]))
  189.           break;
  190.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  191.         RxFaxTimeOverflowErrorQuit();
  192.       }
  193.       if (gucFrhErrorStatus==0x03) return;
  194.       
  195.       for (ucGeneralCount=0; ucGeneralCount<30; ucGeneralCount++)// delay 1.5S minimun 1 second
  196.       {
  197.          ATcmdDelay();  //50ms
  198.       }
  199.       
  200.       SendATdataFTHCFR();
  201.       while (1)    
  202.       {
  203.        ucRxIndex1=gucUartRxCnt-3;
  204.         ucRxIndex0=gucUartRxCnt-2;
  205.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
  206.           break;
  207.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  208.         RxFaxTimeOverflowErrorQuit();
  209.       }  
  210.       if (gucFrhErrorStatus==0x03) return;
  211. //FRM pageimage
  212.       //SendATcmdFRM146();
  213.       SendATcmdFRM();
  214.            
  215.       wGeneralCount=0;//63;
  216.       ucGeneralCnt=0;//28;
  217.       //wPageAddress=0;
  218.       gucFrhErrorStatus=0;
  219.       gucUartRxCnt=0;
  220.       gpucQueueRear=0;
  221.       gpucQueueFront=0;
  222.       gdwRxQueueRearCnt=0;
  223.       gdwRxQueueFrontCnt=0;
  224.       //ZERO_ADDRESS();
  225.       wPageAddress=cstFaxRxBufStartPage;//Block 19 Modify at Jan. 6, 2007
  226.       do{
  227.  wNextPageAddress=wPageAddress+64;
  228.  wPageAddress=CalNextPageAddress(wPageAddress);
  229. }while(wNextPageAddress==wPageAddress);
  230.            //erase next block
  231.       if (wPageAddress%64==0)
  232.       {
  233.          ROW_ADDRESS_LOW=wPageAddress & 0XFF;
  234.          ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF; 
  235.          ERASE_ONE_BLOCK();
  236.       }
  237. //COMMAND
  238.               //Flash_Reset();
  239.               COMMAND_VAL=0X80;
  240.           COMMAND_LATCH_INTO();
  241. //ADDRESS
  242.           ADDRESS_VALUE=0;//COLUMN_ADDRESS_HIGH; //#0X00
  243.           ADDRESS_LATCH_INTO();
  244.           ADDRESS_VALUE=0;//COLUMN_ADDRESS_HIGH; //#0X00
  245.           ADDRESS_LATCH_INTO();
  246.           ADDRESS_VALUE=wPageAddress & 0xff; //#0X00
  247.           ADDRESS_LATCH_INTO();
  248.           ADDRESS_VALUE=(wPageAddress>>8) & 0xff; //#0X00
  249.           ADDRESS_LATCH_INTO();
  250.           FLASH_CON_PORT_OUT &=~ ALE;
  251.           //CALL DELAY_100US
  252.           //for(i=0;i<0xff;i++);
  253.           DATA_PORT_OUT_INITIAL; //MCU OUTPUT,MCU WRITE A DATA TO FLASH
  254. //Pageimage     
  255.       while (1)    
  256.       {
  257.        //if ((0x10 == aucUartRxBuf[ucRxIndex1]) && (0x03 == aucUartRxBuf[ucRxIndex0]))//terminate stream 10 03
  258.        //if ((0x10 == aucUartRxBuf[gucUartRxCnt-1]) && (0x03 == aucUartRxBuf[gucUartRxCnt]))//terminate stream 10 03
  259.              //break;
  260.           //if check time>min. 5S, Receive Fax error, progra should be quit  
  261.           RxFaxTimeOverflowErrorQuit();
  262.           ucRxIndex1=gucUartRxCnt-3;
  263.           ucRxIndex0=gucUartRxCnt-2;
  264.           if ((aucUartRxBuf[ucRxIndex0]==0x0d)&&(aucUartRxBuf[ucRxIndex1]==0x52))//4B  Result code is not OK, but No carrier
  265.              {
  266.                   
  267.                  PageImageEndProcess();
  268.                  //More than two pages process //add at Dec.27,2006
  269.                  ucRxIndex3=gucUartRxCnt-38;
  270.                  ucRxIndex2=gucUartRxCnt-37;
  271.                  ucRxIndex1=gucUartRxCnt-36;
  272.                  ucRxIndex0=gucUartRxCnt-35;
  273.                  if ((aucUartRxBuf[ucRxIndex0]==0x05)&&(aucUartRxBuf[ucRxIndex1]==0x35)&&
  274.                      (aucUartRxBuf[ucRxIndex2]==0x4f)&&(aucUartRxBuf[ucRxIndex3]==0x13))
  275.                   {
  276.                     SendATcmdFRM();
  277.                   }
  278. // multi pages over flag                 
  279.                  if ((aucUartRxBuf[ucRxIndex0]==0x66)&&(aucUartRxBuf[ucRxIndex1]==0x33)&&
  280.                      (aucUartRxBuf[ucRxIndex2]==0x2f)&&(aucUartRxBuf[ucRxIndex3]==0x13))
  281.                   {  
  282.                     break;
  283.                   }
  284. // one page over flag                 
  285.                  if ((aucUartRxBuf[ucRxIndex0]==0x2f)&&(aucUartRxBuf[ucRxIndex1]==0x13))
  286.                     { 
  287.                       break;
  288.                     }
  289.              }
  290.           if (gdwRxQueueRearCnt-gdwRxQueueFrontCnt>32)
  291.           {
  292.               if (gdwRxQueueRearCnt-gdwRxQueueFrontCnt>254)   // if data num is more than the buffer space, error happan.
  293.                 {
  294.                   while (1);//gucGeneralStatus |= FAXRXERROR;
  295.                 }
  296.               if (wGeneralCount++<64) // 32*64=2048
  297.               {
  298.                 for (ucGeneralCnt=0;ucGeneralCnt<32;ucGeneralCnt++)
  299.                 {
  300.                  FLASH_CON_PORT_OUT&=~WE;
  301.                DATA_PORT_OUT=aucUartRxBuf[gpucQueueFront++];
  302.                gdwRxQueueFrontCnt++;               //The total num that is writed to flash
  303.                FLASH_CON_PORT_OUT |= WE;
  304.               }
  305.         //ucGeneralCnt=0;
  306.               }
  307.               else
  308.               { 
  309.                 wGeneralCount=0;
  310.                 
  311.                 COMMAND_VAL=0X10; //10H INITIATES PROGRAM
  312.             COMMAND_LATCH_INTO();
  313.             READ_STATUS();
  314.                 ucFlashSttsOverflowCnt=0;
  315.             while (FLASH_STATUS==1&&(ucFlashSttsOverflowCnt++)<2)
  316.           {
  317.            ;//ERASE_ONE_BLOCK();
  318.            //PROGRAM_ONE_PAGE();
  319.           }
  320.                 if (wPageAddress<2559) wPageAddress++; //add at Jan. 18, 2007
  321.              do{
  322.              wNextPageAddress=wPageAddress+64;
  323.              wPageAddress=CalNextPageAddress(wPageAddress);
  324.              }while(wNextPageAddress==wPageAddress);
  325.            if (wPageAddress%64==0)
  326.                {
  327.                   ROW_ADDRESS_LOW=wPageAddress & 0XFF;
  328.                   ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF; 
  329.                   ERASE_ONE_BLOCK();
  330.                }
  331.               //Flash_Reset();
  332.               COMMAND_VAL=0X80;
  333.           COMMAND_LATCH_INTO();
  334. //ADDRESS
  335.           ADDRESS_VALUE=0;//COLUMN_ADDRESS_HIGH; //#0X00
  336.           ADDRESS_LATCH_INTO();
  337.           ADDRESS_VALUE=0;//COLUMN_ADDRESS_HIGH; //#0X00
  338.           ADDRESS_LATCH_INTO();
  339.           ADDRESS_VALUE=wPageAddress & 0xff; //#0X00
  340.           ADDRESS_LATCH_INTO();
  341.           ADDRESS_VALUE=(wPageAddress>>8) & 0xff; //#0X00
  342.           ADDRESS_LATCH_INTO();
  343.           FLASH_CON_PORT_OUT &=~ ALE;
  344.           //CALL DELAY_100US
  345.           //for(i=0;i<0xff;i++);
  346.           DATA_PORT_OUT_INITIAL; //MCU OUTPUT,MCU WRITE A DATA TO FLASH
  347.             
  348.               }//else
  349.           }//if
  350.       }//while 
  351. //FRH DNC (disconnect)   //Modity at Dec. 28,2006. DNC is the over flag
  352.       SendATcmdFRH();           
  353.       
  354.       while (1)    
  355.       {
  356.        ucRxIndex1=gucUartRxCnt-3;
  357.         ucRxIndex0=gucUartRxCnt-2;
  358.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x54==aucUartRxBuf[ucRxIndex1]))
  359.           break;
  360.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  361.         RxFaxTimeOverflowErrorQuit();
  362.       }
  363.       
  364.       while (1)    
  365.       {
  366.        ucRxIndex1=gucUartRxCnt-3;
  367.         ucRxIndex0=gucUartRxCnt-2;
  368.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
  369.           break;
  370.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  371.         RxFaxTimeOverflowErrorQuit();
  372.       } 
  373.       
  374. //FaxRearDataProcess      
  375.         while (gdwRxQueueRearCnt-gdwRxQueueFrontCnt>=32)
  376.           {
  377.               if (gdwRxQueueRearCnt-gdwRxQueueFrontCnt>254)   // if data num is more than the buffer space, error happan.
  378.                 {
  379.                   gucGeneralStatus |= FAXRXERROR;
  380.                 }
  381.               if (wGeneralCount++<64) // 32*64=2048
  382.               {
  383.                 for (ucGeneralCnt=0;ucGeneralCnt<32;ucGeneralCnt++)
  384.                 {
  385.                  FLASH_CON_PORT_OUT&=~WE;
  386.                DATA_PORT_OUT=aucUartRxBuf[gpucQueueFront++];
  387.                gdwRxQueueFrontCnt++;               //The total num that is writed to flash
  388.                FLASH_CON_PORT_OUT |= WE;
  389.               }
  390.               }
  391.               else
  392.               { 
  393.                 wGeneralCount=0;
  394.                 
  395.                 COMMAND_VAL=0X10; //10H INITIATES PROGRAM
  396.             COMMAND_LATCH_INTO();
  397.             READ_STATUS();
  398.                 ucFlashSttsOverflowCnt=0;
  399.             while (FLASH_STATUS==1&&(ucFlashSttsOverflowCnt++)<2)
  400.           {
  401.            ;//ERASE_ONE_BLOCK();
  402.            //PROGRAM_ONE_PAGE();
  403.           }
  404.                 if (wPageAddress<2559) wPageAddress++;//add at Jan. 18, 2007
  405.              do{
  406.              wNextPageAddress=wPageAddress+64;
  407.              wPageAddress=CalNextPageAddress(wPageAddress);
  408.              }while(wNextPageAddress==wPageAddress);
  409.            if (wPageAddress%64==0)
  410.                {
  411.                   ROW_ADDRESS_LOW=wPageAddress & 0XFF;
  412.                   ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF; 
  413.                   ERASE_ONE_BLOCK();
  414.                }
  415.               COMMAND_VAL=0X80;
  416.           COMMAND_LATCH_INTO();
  417. //ADDRESS
  418.           ADDRESS_VALUE=0;//COLUMN_ADDRESS_LOW; //#0X00
  419.           ADDRESS_LATCH_INTO();
  420.           ADDRESS_VALUE=0;//COLUMN_ADDRESS_LOW; //#0X00
  421.           ADDRESS_LATCH_INTO();
  422.           ADDRESS_VALUE=wPageAddress & 0xff; //#0X00
  423.           ADDRESS_LATCH_INTO();
  424.           ADDRESS_VALUE=(wPageAddress>>8) & 0xff; //#0X00
  425.           ADDRESS_LATCH_INTO();
  426.           FLASH_CON_PORT_OUT &=~ ALE;
  427.           //CALL DELAY_100US
  428.           //for(i=0;i<0xff;i++);
  429.           DATA_PORT_OUT_INITIAL; //MCU OUTPUT,MCU WRITE A DATA TO FLASH
  430.             
  431.               }//else
  432.           }//while
  433.  //***************************************     
  434.       wDataRearCount=gdwRxQueueRearCnt-gdwRxQueueFrontCnt;      
  435.       if (wDataRearCount)//wDataRearCount<2048-wGeneralCount*ucGeneralCnt)
  436.       {
  437.          //for (ucGeneralCnt=0;ucGeneralCnt<wGeneralCount;ucGeneralCnt++)
  438.          for (ucGeneralCnt=0;ucGeneralCnt<wDataRearCount;ucGeneralCnt++)
  439.           {
  440.             FLASH_CON_PORT_OUT&=~WE;
  441.          DATA_PORT_OUT=aucUartRxBuf[gpucQueueFront++];
  442.          gdwRxQueueFrontCnt++;
  443.          FLASH_CON_PORT_OUT |= WE;
  444.         }
  445.         
  446.         wGeneralCount=0;
  447.         COMMAND_VAL=0X10; //10H INITIATES PROGRAM
  448.       COMMAND_LATCH_INTO();
  449.       READ_STATUS();
  450.         ucFlashSttsOverflowCnt=0;
  451.       if(FLASH_STATUS==1&&(ucFlashSttsOverflowCnt++)<2)
  452.     {
  453.      ;//ERASE_ONE_BLOCK();
  454.      //PROGRAM_ONE_PAGE();
  455.     }
  456.       }//if  
  457.       
  458.       
  459.       
  460.       
  461.       SendATcmdH0();
  462.      
  463.       while (1)    
  464.       {
  465.        ucRxIndex1=gucUartRxCnt-3;
  466.         ucRxIndex0=gucUartRxCnt-2;
  467.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
  468.           break;
  469.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  470.         RxFaxTimeOverflowErrorQuit();
  471.       }   
  472.       ATcmdDelay();
  473.       ATcmdDelay();
  474.       ATcmdDelay();
  475.       ATcmdDelay();
  476.       
  477.       SendATcmdH0();
  478.       
  479.       while (1)    
  480.       {
  481.        ucRxIndex1=gucUartRxCnt-3;
  482.         ucRxIndex0=gucUartRxCnt-2;
  483.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
  484.           break;
  485.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  486.         RxFaxTimeOverflowErrorQuit();
  487.       }   
  488.       ATcmdDelay();
  489.       ATcmdDelay();
  490.       ATcmdDelay();
  491.       ATcmdDelay();
  492.       ATcmdDelay();
  493.       ATcmdDelay();
  494.       ATcmdDelay();
  495.       ATcmdDelay();
  496. //AT Fclass0
  497.      
  498.       SendATcmdFCLASS0();
  499.       ATcmdDelay();
  500.       ATcmdDelay();
  501.       ATcmdDelay();
  502.       ATcmdDelay();
  503. //AT      
  504.       SendATcmdPrefix();
  505.       ATcmdDelay();
  506.       SendATcmdSuffix();
  507.       ATcmdDelay();
  508.       ATcmdDelay();
  509.       ATcmdDelay();
  510. //AT     
  511.       SendATcmdPrefix();
  512.       ATcmdDelay();
  513.       SendATcmdSuffix();
  514.       ATcmdDelay();
  515.       ATcmdDelay();
  516.       ATcmdDelay();
  517. //AT    
  518.       SendATcmdPrefix();
  519.       ATcmdDelay();
  520.       SendATcmdSuffix();
  521.       ATcmdDelay();
  522.       ATcmdDelay();
  523.       ATcmdDelay();
  524.       
  525.       SendATconfigFE0EndofRX();
  526.       ATcmdDelay();
  527.       ATcmdDelay();
  528.       ATcmdDelay();
  529.       ATcmdDelay();
  530.       
  531.       SendATconfigS7RX();
  532.       ATcmdDelay();
  533.       ATcmdDelay();
  534.       ATcmdDelay();
  535.       ATcmdDelay();
  536.       
  537.       SendATconfigS0RX();
  538.       ATcmdDelay();
  539.       ATcmdDelay();
  540.       ATcmdDelay();
  541.       ATcmdDelay();
  542.             
  543.       
  544.  
  545. //***************************************/     
  546.       //gucRxTxFlag = DTERX;// set Rx Tx flag
  547.       _NOP();
  548.       gwPageAddress = wPageAddress;
  549.       
  550.       while (1)
  551.      {
  552.         SendATcmdModemSoftReset();
  553.         ATcmdDelay();
  554.         ATcmdDelay();
  555.       
  556.       ucRxIndex1=gucUartRxCnt-3;
  557.       ucRxIndex0=gucUartRxCnt-2;
  558.       if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
  559.         {break;}
  560.      }//while
  561.           
  562. }//FaxRXProcess
  563. void FaxRxInit(void)
  564. {
  565.       SendATconfigFS0();
  566.       ATcmdDelay();
  567.       ATcmdDelay();
  568.       ATcmdDelay();
  569. //AT      
  570.       SendATcmdPrefix();
  571.       ATcmdDelay();
  572.       SendATcmdSuffix();
  573.       ATcmdDelay();
  574.       ATcmdDelay();
  575.       ATcmdDelay();
  576.       
  577.       SendATconfigS7();
  578.       ATcmdDelay();
  579.       ATcmdDelay();
  580.       ATcmdDelay();
  581.       
  582.       SendATconfigX4M1();
  583.       ATcmdDelay();
  584.       ATcmdDelay();
  585.       ATcmdDelay();
  586.       
  587.       SendATcmdFCLASS();
  588.       ATcmdDelay();
  589.       ATcmdDelay();
  590.       ATcmdDelay();
  591. //AT
  592.       SendATcmdPrefix();
  593.       ATcmdDelay();
  594.       SendATcmdSuffix();
  595.       ATcmdDelay();
  596.       ATcmdDelay();
  597.       ATcmdDelay();
  598.       
  599.       SendATcmdFCLASS();
  600.       ATcmdDelay();
  601.       ATcmdDelay();
  602.       ATcmdDelay();
  603. //AT
  604.       SendATcmdPrefix();
  605.       ATcmdDelay();
  606.       SendATcmdSuffix();
  607.       ATcmdDelay();
  608.       ATcmdDelay();
  609.       ATcmdDelay();
  610. void PageImageEndProcess(void)
  611. {   
  612.       unsigned char ucRxIndex1=0,ucRxIndex0=0;
  613. //FRHEOP (end of procedure)
  614.       SendATcmdFRH();
  615.       //ATcmdDelay();
  616.       
  617.       while (1)    
  618.       {
  619.        ucRxIndex1=gucUartRxCnt-3;
  620.         ucRxIndex0=gucUartRxCnt-2;
  621.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x54==aucUartRxBuf[ucRxIndex1]))
  622.           break;
  623.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  624.         RxFaxTimeOverflowErrorQuit();
  625.       }//while
  626.       
  627.       while (1)    
  628.       {
  629.        ucRxIndex1=gucUartRxCnt-3;
  630.         ucRxIndex0=gucUartRxCnt-2;
  631.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
  632.           break;
  633.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  634.         RxFaxTimeOverflowErrorQuit();
  635.       }
  636.                
  637. //FTHMCF  (message confirmation)
  638.       SendATcmdFTH();
  639.       while (1)    
  640.       {
  641.        ucRxIndex1=gucUartRxCnt-3;
  642.         ucRxIndex0=gucUartRxCnt-2;
  643.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x54==aucUartRxBuf[ucRxIndex1]))
  644.           break;
  645.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  646.         RxFaxTimeOverflowErrorQuit();
  647.       }
  648.       Delay1500ms();  // delay 1.5S minimun 1 second
  649.       SendATdataFTHMCF();
  650.       while (1)    
  651.       {
  652.        ucRxIndex1=gucUartRxCnt-3;
  653.         ucRxIndex0=gucUartRxCnt-2;
  654.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
  655.           break;
  656.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  657.         RxFaxTimeOverflowErrorQuit();
  658.       } 
  659. }
  660. void FRHDncProcess(void)
  661. {
  662.  ;
  663. }
  664. void FthCsiDis(void)
  665. {
  666.       unsigned char ucRxIndex1=0,ucRxIndex0=0,
  667.                     ucGeneralCount=0;
  668. //FTH
  669.       SendATcmdFTH();
  670.       while (1)  //CONNECT(54) 0D 0A
  671.       {
  672.        ucRxIndex1=gucUartRxCnt-3;
  673.         ucRxIndex0=gucUartRxCnt-2;
  674.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x54==aucUartRxBuf[ucRxIndex1]))
  675.           break;
  676.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  677.         RxFaxTimeOverflowErrorQuit();
  678.       }
  679.       
  680.       Delay1500ms();  // delay 1.5S minimun 1 second
  681.       
  682.       SendATdataFTHCSI();    //The final bit is 0. The modem will generates CONNECT message.
  683.       while (1)  //CONNECT(54) 0D 0A
  684.       {
  685.         ucRxIndex1=gucUartRxCnt-3;
  686.         ucRxIndex0=gucUartRxCnt-2;
  687.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x54==aucUartRxBuf[ucRxIndex1]))
  688.           break;
  689.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  690.         RxFaxTimeOverflowErrorQuit();
  691.       }
  692.       
  693.       for (ucGeneralCount=0; ucGeneralCount<50; ucGeneralCount++)// delay 1.5S minimun 1 second
  694.       {
  695.          ATcmdDelay();  //50ms
  696.       }
  697.       SendATdataFTHDIS();//SendATdataFTHTSI(sizeof (FTHDIS)); a bug of Sep.18
  698.       
  699.       while (1)    //O K 0D 0A
  700.       {
  701.         ucRxIndex1=gucUartRxCnt-3;
  702.         ucRxIndex0=gucUartRxCnt-2;
  703.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1])) //K ==0x4b
  704.           break;
  705.         //if check time>min. 5S, Receive Fax error, progra should be quit  
  706.         RxFaxTimeOverflowErrorQuit();
  707.       }