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