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

传真(Fax)编程

开发平台:

C/C++

  1. /************************************************
  2. Network 3G Fax
  3. Copyright 2006 by Vson. All rights reserved.
  4. Author:      Bryan Cai
  5. Date:        2006.09.04
  6. Description: Carry out a Network 3G Fax with Conexant CX06833.
  7. Note:
  8. Identifier abbreviation: 
  9.                          c-const
  10.                          a-array
  11.                          p-pointer
  12.                          g-global
  13.                          uc-unsigned char
  14.                          w-unsigned int
  15.                          cnt-count
  16.                          pnt-point
  17. Update:
  18.       2007.04.12  Bryan      Concise the FaxManager program
  19.       2007.03.20  Bryan      Complete all DTE command function
  20.       2007.03.16  Bryan      Fast exit RxProcess when error occur.
  21.       2007.01.03  Bryan      Add Modem RX parameter set
  22.       2006.12.27  Bryan      add RX multi imagepages
  23.       2006.12.22  Bryan      Flash I/O changed
  24.       2006.11.02  Bryan      program header
  25. ************************************************/
  26. #include "includeH.h"
  27. //interrupt [USART0TX_VECTOR] void intUartTx(void);
  28. //interrupt [USART0RX_VECTOR] void intUartRx(void);
  29. /* AT command Set
  30. unsigned char  ATcmdPrefix[]={0x41,0x54}, ATcmdSuffix[]={0x0D},
  31.                 //ATFS0[]={0x26,0x46,0x53,0x30,0x3d,0x30,0x45,0x31,0x56,0x31,0x51,0x30},
  32.                 //ATS7[]={0x53,0x37,0x3d,0x36,0x30,0x26,0x44,0x33,0x26,0x4b,0x34},
  33.                 //ATX4M1L0[]={0x58,0x34,0x4d,0x31,0x4c,0x30},
  34.                 //FCLASS[]={0x2b,0x46,0x43,0x4c,0x41,0x53,0x53,0x3d,0x31},
  35.                 //FCLASS0[]={0x2b,0x46,0x43,0x4c,0x41,0x53,0x53,0x3d,0x30},
  36.                 
  37.                 
  38.                 ATS0RX[]={0x53,0x30,0x3d,0x30},                
  39.                 DT[]={0x44,0x54,0x39,0x36,0x31,0x31,0x33,0x39,0x35,0x30,0x39},
  40.                 A[]={0x41},
  41.                 //DT[]={0x44,0x54,0x39,0x30,0x37,0x39,0x37,0x36,0x39,0x30,0x35,0x31,0x39,0x31},     
  42.                 FRH[]={0x2b,0x46,0x52,0x48,0x3d,0x33,0x0d},  
  43.                 FTH[]={0x2b,0x46,0x54,0x48,0x3d,0x33,0x0d},
  44.                 //FTHNSF[]={0xff,0x03,0x54,0x47,0x46,0x33,0x36,0x36,0x43,0x00,0x77,0x9C,0x10,0x03},
  45.         //for TX 
  46.                 FTHTSI[]={0xff,0x03,0x43,0x78,0x61,0x46,0x10,0x03},
  47.                 FTHDCS[]={0xff,0x13,0x83,0x00,0x46,0x78,0x10,0x03},//for TX
  48.         //for RX
  49.                 //FTHCSI[]={0xff,0x03,0x40,0x78,0x61,0x46,0x10,0x03},//@Fax
  50.                 FTHCSI[]={0xff,0x03,0x40,0x36,0x33,0x38,0x10,0x03},//@836
  51.                 FTHDIS[]={0xff,0x13,0x80,0x00,0xee,0x78,0x10,0x03},//for RX ee 78
  52.                 //FTHDIS[]={0xff,0x13,0x80,0x00,0x46,0x70,0x10,0x03},//for RX ee 78
  53.                 //FTHCSI[]={0xff,0x03,0x40,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x36,0x33,0x38,0x10,0x03},//@Fax
  54.                 //FTHDIS[]={0xff,0x13,0x80,0x00,0xee,0x78,0x10,0x03},//for RX ee 78
  55.                 FTHCFR[]={0xff,0x13,0x84,0x10,0x03},// Confirmation to receive  MSB 21H LSB 83H
  56.                 FTHMCF[]={0xff,0x13,0x8C,0x10,0x03},// Message Confirmation MSB 31H LSB 8CH
  57.                 FTHEOP[]={0xff,0x13,0x2f,0x10,0x03},
  58.                 FTHDNC[]={0xff,0x13,0xfb,0x10,0x03},
  59.                 FTHEOM[]={0xff,0x03,0x43,0x78,0x61,0x46,0x10,0x03},
  60.                 FTS[]={0x2b,0x46,0x54,0x53,0x3d,0x38},  
  61.                 FTM[]={0x2b,0x46,0x54,0x4d,0x3d,0x39,0x36},
  62.                 //FRM[]={0x2b,0x46,0x52,0x4d,0x3d,0x31,0x34,0x35},
  63.                 FRM[]={0x2b,0x46,0x52,0x4d,0x3d,0x39,0x36},  
  64.                 H0[]={0x48,0x00}, 
  65.                 TerminalFlag[]={0x10,0x03};
  66. */
  67. void main(void)
  68. {     
  69.         
  70.       unsigned int wGeneralCount = 0, 
  71.                    wOKcount=0, 
  72.                    wNotOKcount=0, 
  73.                    wOneFaxHead=0, 
  74.                    wOneFaxRear=0,
  75.                    wGeneralVar=0;
  76.       unsigned char
  77.                     ucRxIndex3=0,ucRxIndex2=0,
  78.                     ucRxIndex1=0,ucRxIndex0=0,
  79.                     ucSoftUartRxCnt=0;
  80.       //unsigned char ucGeneralCount=1;
  81.       unsigned char ucGeneralCnt=0;
  82.       unsigned char ucRingNum=0;
  83.       unsigned char ucRxIndex=0;
  84.       //unsigned char ucSoftUartRxData=0;
  85.       //unsigned char ucFlashWriteData;
  86.       //unsigned char ucFlashColumnAddCnt;
  87.       //unsigned int wGeneralCnt;
  88.       //unsigned int wBlockAddress=0,wPageAddress=0;
  89.       WDTCTL=WDTPW+WDTHOLD;              //close watch dog
  90.       
  91. /*
  92.       FLASH_CON_PORT_OUT |= CE; //COMMAND_LATCH_INTO_INITAIL all control disable
  93.        FLASH_CON_PORT_OUT &= ~CE;
  94.       FLASH_CON_PORT_OUT |= WE;
  95.        FLASH_CON_PORT_OUT &= ~WE;
  96.       FLASH_CON_PORT_OUT |= RE;
  97.        FLASH_CON_PORT_OUT &= ~RE;
  98.         FLASH_CON_PORT_OUT |= CLE;
  99.       FLASH_CON_PORT_OUT &= ~CLE;
  100.        FLASH_CON_PORT_OUT |= ALE;
  101.       FLASH_CON_PORT_OUT &= ~ALE;
  102. */
  103.       //while (1) _NOP(); 
  104.       IoInitial();
  105.       InitUART();
  106.       Flash_Reset();
  107.       FLASH_READ_ID();
  108.       //while (0) aucUartRxBuf[ucRxIndex++]=SoftUartRxOneFrame();
  109.       SOFTUART_PORT_DIRECTION |= bitSOFTUARTTX;
  110. /*
  111.       while (0)
  112.       {
  113.       SOFTUART_PORT_OUT |= bitSOFTUARTTX;
  114.       delay1us(20);
  115.       SOFTUART_PORT_OUT &= ~bitSOFTUARTTX;
  116.       delay1us(8);
  117.       SOFTUART_PORT_OUT |= bitSOFTUARTTX;
  118.       for (ucGeneralCnt=0;ucGeneralCnt<8;ucGeneralCnt++)
  119.      {
  120.         delay1us(2);//SoftUartDelayHalf();
  121.         ucSoftUartRxData=ucSoftUartRxData>>1;
  122.         //if ((SOFTUART_PORT_IN & bitSOFTUARTRX) == bitSOFTUARTRX)
  123.           //ucSoftUartRxData |= BIT7;//BIT7;//(1<<ucGeneralCount);//set   Rx bit
  124.         //else
  125.           //{ucSoftUartRxData &= ~BIT7;__no_operation();__no_operation();__no_operation();}//~BIT7;//~(1<<ucGeneralCount);//set   Rx bit
  126.         if ((SOFTUART_PORT_OUT & bitSOFTUARTTX) != bitSOFTUARTTX)
  127.           {SOFTUART_PORT_OUT |= bitSOFTUARTTX;} //set   Tx bit
  128.         else
  129.           {SOFTUART_PORT_OUT &= ~bitSOFTUARTTX;__no_operation();__no_operation();}
  130.         delay1us(2);//SoftUartDelayHalf();
  131.         __no_operation();
  132.         __no_operation();
  133.         __no_operation();
  134.         __no_operation();
  135.         __no_operation();
  136.           
  137.       }
  138.       
  139.       SOFTUART_PORT_OUT &= ~bitSOFTUARTTX;
  140.       delay1us(8);
  141.       SOFTUART_PORT_OUT |= bitSOFTUARTTX;
  142.      }
  143.      */
  144.       Delay2000ms();
  145.       
  146.       ReadLastViewData();
  147.       //ReadLast16BytesFromFlashMemoryArea(cstViewDataAreaStartBlockNum,cstViewDataAreaOverBlockNum);
  148.        
  149.       ucRxIndex=gucUartRxCnt;
  150.       if ((gucGeneralStatus & bitReadFlashMemoryOK) == bitReadFlashMemoryOK)
  151.       {
  152.        gucViewRingNum = aucUartRxBuf[ucRxIndex++];
  153.        gucViewStaticStatus = aucUartRxBuf[ucRxIndex++];
  154.        gucViewDynamicStatus = aucUartRxBuf[ucRxIndex++];
  155.        gucViewDceNewFaxNum = aucUartRxBuf[ucRxIndex++];
  156.       }
  157.       ViewCommunicationTX(0);
  158.       
  159.       //while (1) wGeneralCount = gwGeneralPageAddress>>6;
  160.       //while (1) _NOP();
  161. /*
  162.       while (1) 
  163.       {
  164.        ViewCommunicationTX(1); 
  165.        ViewCommunicationRX();
  166.       }
  167. */
  168.  
  169.    
  170.      
  171.      //while (1)
  172.      //{
  173.      //Initial Device  Reset Modem
  174.       ModemResetPortDir |= bitModemHardwareReset;
  175.       ModemResetCon &= ~bitModemHardwareReset;
  176.       ATcmdDelay();
  177.       ModemResetPortDir &= ~bitModemHardwareReset;
  178.       ModemResetCon |= bitModemHardwareReset;
  179.      while (1)
  180.      {
  181.            
  182.         ATcmdDelay();
  183.         SendATcmd();          
  184.         ATcmdDelay();
  185.         ATcmdDelay();
  186.         if ((0x0d!=aucUartRxBuf[ucRxIndex0])&&(0x4B!=aucUartRxBuf[ucRxIndex1]))
  187.         {
  188.         SendATcmdModemSoftReset();
  189.         ATcmdDelay();
  190.         ATcmdDelay();
  191.       
  192.         ucRxIndex1=gucUartRxCnt-3;
  193.         ucRxIndex0=gucUartRxCnt-2;
  194.         if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
  195.           {break;}
  196.         }
  197.      }//while
  198.      while (1)
  199.      {
  200.       ATcmdDelay();
  201.       SendATcmd();          //a bug of Sep.22 If this AT is not added, the ring can't receive sometimes.
  202.       ATcmdDelay();
  203.       ATcmdDelay();
  204.     
  205.       while (wGeneralCount++<0xffff)
  206.       {
  207.        ucRxIndex1=gucUartRxCnt-3;
  208.        ucRxIndex0=gucUartRxCnt-2;
  209.        if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
  210.         {wOKcount++;break;}
  211.        if (wGeneralCount==0xffff)
  212.        {    
  213.         //wGeneralCount=0;
  214.         wNotOKcount++;
  215.         SendATcmdModemSoftReset();
  216.         ATcmdDelay();
  217.         ATcmdDelay();
  218.        }//if
  219.       }//while
  220.       ucRxIndex1=gucUartRxCnt-3;
  221.       ucRxIndex0=gucUartRxCnt-2;
  222.       if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
  223.         {wOKcount++;break;}
  224.      }//while
  225.      _NOP();
  226.      gucGeneralStatus &= ~bitModemActive;
  227.      
  228.      //gucUartRxCnt++;
  229.      //}//while
  230.       
  231.      //Main Circle
  232.      while (1)
  233.      {     
  234.       //Key Scan and Set Parameters
  235.       
  236.       KeyScan();
  237.       //}// test keyscan
  238.       //while (1)//test keyscan
  239.       //{//test keyscan
  240.       
  241.       //if Modem active(bitModemActive=0X0002)
  242.          //detect modem
  243.       //else
  244.         //detect PC command through SoftUart
  245.       ucRingNum=0;
  246.       if ((gucGeneralStatus & bitModemActive) == bitModemActive)
  247.       {             
  248.             while (wGeneralCount++<0xffff)    
  249.             { 
  250.               ucRxIndex3=gucUartRxCnt-6;
  251.               ucRxIndex2=gucUartRxCnt-5;
  252.               ucRxIndex1=gucUartRxCnt-4;
  253.               ucRxIndex0=gucUartRxCnt-3;
  254.               if ((aucUartRxBuf[ucRxIndex0]==0x47)&&(aucUartRxBuf[ucRxIndex1]==0x4e)&&
  255.                   (aucUartRxBuf[ucRxIndex2]==0x49)&&(aucUartRxBuf[ucRxIndex3]==0x52))
  256.               {
  257.                 gucUartRxCnt+=1;
  258.                 ucRingNum++;
  259.                 //if AutoMode
  260.                 //{
  261.                 //if Ring Num < Ring Num Max
  262.                     //gucUartRxCnt++; RingNumCnt++;
  263.                 //else
  264.                     //break;
  265.                 //}
  266.                 //else (Manual Mode)
  267.                   //if Receive Start Key Switch On
  268.                   //   break;
  269.                 if ((gucViewStaticStatus & bitViewAutoMode) == bitViewAutoMode) //auto mode
  270.                  {
  271.                    while (1)
  272.                     {
  273.                    
  274.                       ucRxIndex3=gucUartRxCnt-6;
  275.                         ucRxIndex2=gucUartRxCnt-5;
  276.                         ucRxIndex1=gucUartRxCnt-4;
  277.                         ucRxIndex0=gucUartRxCnt-3;
  278.                         if ((aucUartRxBuf[ucRxIndex0]==0x47)&&(aucUartRxBuf[ucRxIndex1]==0x4e)&&
  279.                             (aucUartRxBuf[ucRxIndex2]==0x49)&&(aucUartRxBuf[ucRxIndex3]==0x52))
  280.                              {ucRingNum++;gucUartRxCnt++;}// pointer to next imcoming RING
  281.                         if (ucRingNum>=gucViewRingNum) 
  282.                          {gucGeneralStatus |= bitSendFaxSignalOK;break;}//OK
  283.                         //time overflow quit
  284.                         if (gwTimeOverflowCount++ == 0xffff)
  285.                              gucTimeOverflowCount++;
  286.                         if (gucTimeOverflowCount == 20)
  287.                         {gucGeneralStatus &= ~bitSendFaxSignalOK;gucTimeOverflowCount=0;gwTimeOverflowCount=0;break;}
  288.                     }
  289.                    
  290.                  }//if auto mode end
  291.                 else //manual mode
  292.                  {
  293.                    while (1)
  294.                    {
  295.                      gucUartRxCnt++;// pointer to next imcoming RING
  296.                      ucRxIndex3=gucUartRxCnt-6;
  297.                       ucRxIndex2=gucUartRxCnt-5;
  298.                       ucRxIndex1=gucUartRxCnt-4;
  299.                       ucRxIndex0=gucUartRxCnt-3;
  300.                       if ((aucUartRxBuf[ucRxIndex0]==0x47)&&(aucUartRxBuf[ucRxIndex1]==0x4e)&&
  301.                           (aucUartRxBuf[ucRxIndex2]==0x49)&&(aucUartRxBuf[ucRxIndex3]==0x52))
  302.                           ucRingNum++;
  303.                       if (ucRingNum>10)//if RING is over 10, error
  304.                       {gucGeneralStatus &= ~bitSendFaxSignalOK;break;}//Not OK
  305.                      if ((KEY_PORT_IN & bitKeySendFaxSignal) != bitKeySendFaxSignal)
  306.                       {gucGeneralStatus |= bitSendFaxSignalOK;break;}//OK      
  307.                    }
  308.                  }//else manual mode end
  309.                 break;
  310.               }//if 
  311.             }//while
  312.             
  313.               //receive fax
  314.               if ((gucGeneralStatus & bitSendFaxSignalOK) == bitSendFaxSignalOK)
  315.                 {
  316.                   gucGeneralStatus &= ~bitSendFaxSignalOK;
  317.                   //Driver Screen Flash Receiving
  318.                   
  319.                   gucViewDynamicStatus |= bitViewReceiving;
  320.    
  321.                   ViewCommunicationTX(0x01);
  322.                   //ViewCommunicationRX();
  323.                   
  324.                   gucUartRxCnt=0;//
  325.                   gucFrhErrorStatus=0x00;
  326.                   FaxRXProcess();
  327.                   
  328.                   //Off Screen Flash Receiving
  329.                   gucViewDynamicStatus &= ~bitViewReceiving;
  330.                   ViewCommunicationTX(0x01);
  331.                   //if receive is OK
  332.                       //write data to flash
  333.                   //FaxRawDataBuf2Flash();
  334.                   //gucRxTxFlag = DTERX;
  335.                   
  336.                   
  337.                   if (gucFrhErrorStatus!=3)
  338.                   {
  339.                     FaxRxBufRawdata2PCFromSoftUart();
  340.                     //FaxRxBufRawdata2PCFromUart();
  341.                     FaxRxBufRawdata2Flash();
  342.                     //FaxData2PCFromSoftUart();
  343.                     gucViewStaticStatus |= bitViewNewFax;
  344.                     gucViewDynamicStatus |= bitViewNewFax;
  345.                     gucViewDceNewFaxNum++;
  346.                     ViewCommunicationTX(0x01);
  347.                     ReadAndWriteViewDataMemory();
  348.                     
  349.                   }//if
  350.                   else
  351.                    { 
  352.                      ModemResetPortDir |= bitModemHardwareReset;
  353.                      ModemResetCon &= ~bitModemHardwareReset;
  354.                      ATcmdDelay();
  355.                      ModemResetPortDir &= ~bitModemHardwareReset;
  356.                      ModemResetCon |= bitModemHardwareReset;
  357.                      //InitUART();
  358.                      while (1) //add at Apr. 13, 2007 can't receive RS232 Data
  359.                      {
  360.                       SendATcmdModemSoftReset();
  361.                       ATcmdDelay();
  362.                       ATcmdDelay();
  363.       
  364.                       ucRxIndex1=gucUartRxCnt-3;
  365.                       ucRxIndex0=gucUartRxCnt-2;
  366.                       if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
  367.                          {break;}
  368.                      }
  369.                     }//else Rx error
  370.                   //break; //Cant's delete it should be over this while circle //break; //delete at Mar. 16, 2007
  371.                 }//if fax receive end
  372.         //Fax receive over, reset bitModemActive for PC detect the new fax
  373.         gucGeneralStatus &= ~bitModemActive;  //fax receiving over 
  374.       }//if modem active end
  375.       else
  376.       {
  377.         //receive data from SoftUart
  378.         ucSoftUartRxCnt=0;
  379.         gucSoftUartRxCnt=0;
  380.         //ucGeneralCnt=0;
  381.         while (1)
  382.         {
  383.            aucSoftUartRxBuf[ucSoftUartRxCnt++]=SoftUartRxOneFrame();//receive one Byte Data
  384.            if (ucSoftUartRxCnt>19)//17)//
  385.              ucSoftUartRxCnt=0;//gucSoftUartRxCnt=0; 2-2=0
  386.            if (aucSoftUartRxBuf[ucSoftUartRxCnt-1]==0x03 && aucSoftUartRxBuf[ucSoftUartRxCnt-2]==0x10)
  387.              {gucSoftUartRxCnt=ucSoftUartRxCnt;ucSoftUartRxCnt=0; break;}//{gucSoftUartRxCnt=0; break;} //bug of Apr. 03, 20007
  388.            if ((gucGeneralStatus & bitModemActive) == bitModemActive)//if modem active, over this while function
  389.              break;
  390.          if (((KEY_PORT_IN & bitKeyRingNumDec) != bitKeyRingNumDec) || 
  391.         ((KEY_PORT_IN & bitKeyRingNumAdd) != bitKeyRingNumAdd) ||
  392.         ((KEY_PORT_IN & bitKeyAutoMode) != bitKeyAutoMode) ||
  393.         ((KEY_PORT_IN & bitKeyManualMode) != bitKeyManualMode)) //||
  394.         //((KEY_PORT_IN & bitKeySendFaxSignal) != bitKeySendFaxSignal))
  395.         break;
  396.         }
  397.       
  398.       //Judge the received data
  399.       
  400.       //PC get Modem Bus command:ba 23 00 01 10 03
  401.         if ((aucSoftUartRxBuf[gucSoftUartRxCnt-1]==0x03) && (aucSoftUartRxBuf[gucSoftUartRxCnt-2]==0x10)&&
  402.             (aucSoftUartRxBuf[gucSoftUartRxCnt-3]==0x01) && (aucSoftUartRxBuf[gucSoftUartRxCnt-4]==0x00)&&
  403.             (aucSoftUartRxBuf[gucSoftUartRxCnt-5]==0x23) && (aucSoftUartRxBuf[gucSoftUartRxCnt-6]==0xba))
  404.         {
  405.            DteGetModemBus();
  406.            SoftUartTxOneFrame(0xff); 
  407.         }
  408.       
  409.       //PC return Modem Bus command:ba 23 00 02 10 03
  410.         if ((aucSoftUartRxBuf[gucSoftUartRxCnt-1]==0x03) && (aucSoftUartRxBuf[gucSoftUartRxCnt-2]==0x10)&&
  411.             (aucSoftUartRxBuf[gucSoftUartRxCnt-3]==0x02) && (aucSoftUartRxBuf[gucSoftUartRxCnt-4]==0x00)&&
  412.             (aucSoftUartRxBuf[gucSoftUartRxCnt-5]==0x23) && (aucSoftUartRxBuf[gucSoftUartRxCnt-6]==0xba))
  413.         {
  414.            DteReturnModemBus();
  415.            SoftUartTxOneFrame(0xff);
  416.         }
  417.       
  418.       //PC get Fax List command:ba 23 00 03 10 03
  419.         if ((aucSoftUartRxBuf[gucSoftUartRxCnt-1]==0x03)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-2]==0x10)&&
  420.             (aucSoftUartRxBuf[gucSoftUartRxCnt-3]==0x03)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-4]==0x00)&&
  421.             (aucSoftUartRxBuf[gucSoftUartRxCnt-5]==0x23)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-6]==0xba))
  422.         {
  423.            DteGetFaxList();
  424.         }
  425.       
  426.       //PC get One Fax command:ba 23 00 04 HeadLow HeadHigh RearLow RearHigh 10 03
  427.         if ((aucSoftUartRxBuf[gucSoftUartRxCnt-1]==0x03)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-2]==0x10)&&
  428.             (aucSoftUartRxBuf[gucSoftUartRxCnt-7]==0x04)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-8]==0x00)&&
  429.             (aucSoftUartRxBuf[gucSoftUartRxCnt-9]==0x23)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-10]==0xba))
  430.         {
  431.          
  432.            if (gucFrhErrorStatus==0)
  433.            {
  434.              ucRxIndex1=gucSoftUartRxCnt-6;//Low  Byte
  435.              ucRxIndex0=gucSoftUartRxCnt-5;//High Byte
  436.              wGeneralVar=aucSoftUartRxBuf[ucRxIndex0];
  437.              wOneFaxHead=(wGeneralVar<<8) | aucSoftUartRxBuf[ucRxIndex1];
  438.            
  439.              ucRxIndex1=gucSoftUartRxCnt-4;//Low  Byte
  440.              ucRxIndex0=gucSoftUartRxCnt-3;//High Byte
  441.              wGeneralVar=aucSoftUartRxBuf[ucRxIndex0];
  442.              wOneFaxRear=(wGeneralVar<<8) | aucSoftUartRxBuf[ucRxIndex1];
  443.            
  444.              DteGetOneFax(wOneFaxHead, wOneFaxRear);
  445.              if (gucViewDceNewFaxNum>0) 
  446.               {
  447.               gucViewDceNewFaxNum--;// for DCE check the new fax
  448.                 gucViewStaticStatus |= bitViewNewFax;
  449.                 gucViewDynamicStatus |= bitViewNewFax;
  450.               }
  451.              else
  452.               {gucViewStaticStatus &= ~bitViewNewFax;}
  453.              
  454.              ViewCommunicationTX(0x01);
  455.              ReadAndWriteViewDataMemory();
  456.            }
  457.         }
  458.         
  459.       //PC delete One Fax command:ba 23 00 05 HeadLow HeadHigh RearLow RearHigh 10 03
  460.         if ((aucSoftUartRxBuf[gucSoftUartRxCnt-1]==0x03)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-2]==0x10)&&
  461.             (aucSoftUartRxBuf[gucSoftUartRxCnt-7]==0x05)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-8]==0x00)&&
  462.             (aucSoftUartRxBuf[gucSoftUartRxCnt-9]==0x23)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-10]==0xba))
  463.         {
  464.          
  465.            if (gucFrhErrorStatus==0)
  466.            {
  467.              ucRxIndex1=gucSoftUartRxCnt-6;//Low  Byte
  468.              ucRxIndex0=gucSoftUartRxCnt-5;//High Byte
  469.              wGeneralVar=aucSoftUartRxBuf[ucRxIndex0];
  470.              wOneFaxHead=(wGeneralVar<<8) | aucSoftUartRxBuf[ucRxIndex1];
  471.            
  472.              ucRxIndex1=gucSoftUartRxCnt-4;//Low  Byte
  473.              ucRxIndex0=gucSoftUartRxCnt-3;//High Byte
  474.              wGeneralVar=aucSoftUartRxBuf[ucRxIndex0];
  475.              wOneFaxRear=(wGeneralVar<<8) | aucSoftUartRxBuf[ucRxIndex1];
  476.            
  477.              //DteDelOneFax(wOneFaxHead, wOneFaxRear);
  478.            }
  479.         }
  480.         
  481.       //PC delete all fax command:ba 23 00 05 10 03
  482.         if ((aucSoftUartRxBuf[gucSoftUartRxCnt-1]==0x03)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-2]==0x10)&&
  483.             (aucSoftUartRxBuf[gucSoftUartRxCnt-3]==0x06)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-4]==0x00)&&
  484.             (aucSoftUartRxBuf[gucSoftUartRxCnt-5]==0x23)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-6]==0xba))
  485.         {
  486.            ;//DteDelAllFax();
  487.         }
  488.       
  489.       //PC send the system time to Dce command:ba 23 00 0b YearLow YearHigh Month Day Hour Minute Second 10 03
  490.         if ((aucSoftUartRxBuf[gucSoftUartRxCnt-1]==0x03)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-2]==0x10)&&
  491.             (aucSoftUartRxBuf[gucSoftUartRxCnt-10]==0x0b)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-11]==0x00)&&
  492.             (aucSoftUartRxBuf[gucSoftUartRxCnt-12]==0x23)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-13]==0xba))
  493.         {
  494.          
  495.            if (gucFrhErrorStatus==0)
  496.            {
  497.              /*
  498.              SetSystemTime(aucSoftUartRxBuf[gucSoftUartRxCnt-9], aucSoftUartRxBuf[gucSoftUartRxCnt-8],
  499.                            aucSoftUartRxBuf[gucSoftUartRxCnt-7], aucSoftUartRxBuf[gucSoftUartRxCnt-6],
  500.                            aucSoftUartRxBuf[gucSoftUartRxCnt-5], aucSoftUartRxBuf[gucSoftUartRxCnt-4],
  501.                            aucSoftUartRxBuf[gucSoftUartRxCnt-3]);
  502.              */
  503.              ucRxIndex=gucSoftUartRxCnt-8;
  504.              for (ucGeneralCnt = 0; ucGeneralCnt < 6; ucGeneralCnt++)
  505.              {
  506.                  aucViewData[cstViewSecondIndex] = aucUartRxBuf[ucRxIndex++];//second
  507.                  aucViewData[cstViewMinuteIndex] = aucUartRxBuf[ucRxIndex++];//minute
  508.                  aucViewData[cstViewHourIndex] = aucUartRxBuf[ucRxIndex++];//hour
  509.                  aucViewData[cstViewDateIndex] = aucUartRxBuf[ucRxIndex++];//date
  510.                  aucViewData[cstViewMonthIndex] = aucUartRxBuf[ucRxIndex++];//month
  511.                  aucViewData[cstViewYearIndex] = aucUartRxBuf[ucRxIndex++];//Year
  512.              }
  513.              ViewCommunicationTX(0x00);
  514.            }
  515.         }
  516.           
  517.       //format flash
  518.         if ((aucSoftUartRxBuf[gucSoftUartRxCnt-1]==0x03)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-2]==0x10)&&
  519.             (aucSoftUartRxBuf[gucSoftUartRxCnt-3]==0x0c)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-4]==0x00)&&
  520.             (aucSoftUartRxBuf[gucSoftUartRxCnt-5]==0x23)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-6]==0xba))
  521.         {
  522.          FlashFormat();
  523.         }
  524.         
  525.       //Flash bad block process
  526.         if ((aucSoftUartRxBuf[gucSoftUartRxCnt-1]==0x03)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-2]==0x10)&&
  527.             (aucSoftUartRxBuf[gucSoftUartRxCnt-3]==0x0d)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-4]==0x00)&&
  528.             (aucSoftUartRxBuf[gucSoftUartRxCnt-5]==0x23)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-6]==0xba))
  529.         {
  530.          CheckInvalidBlock();
  531.          SoftUartTxOneFrame(0xff);
  532.         }
  533.         
  534.       //PC set CSI and DIS
  535.         if ((aucSoftUartRxBuf[gucSoftUartRxCnt-1]==0x03)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-2]==0x10)&&
  536.             (aucSoftUartRxBuf[gucSoftUartRxCnt-7]==0x0e)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-8]==0x00)&&
  537.             (aucSoftUartRxBuf[gucSoftUartRxCnt-9]==0x23)&&(aucSoftUartRxBuf[gucSoftUartRxCnt-10]==0xba))
  538.         {
  539.            SetCSIandDIS();
  540.            DceResponsePc();
  541.          
  542.         }
  543.       /* get new fax
  544.         if ((aucUartRxBuf[gucUartRxCnt-1]==0x03)&&(aucUartRxBuf[gucUartRxCnt-2]==0x10)&&
  545.             (aucUartRxBuf[gucUartRxCnt-3]==0x01)&&(aucUartRxBuf[gucUartRxCnt-4]==0x00)&&
  546.             (aucUartRxBuf[gucUartRxCnt-5]==0x23)&&(aucUartRxBuf[gucUartRxCnt-6]==0xba))
  547.             //;
  548.         //if (gucRxTxFlag == DTERX)
  549.         {
  550.           FaxData2PCFromSoftUart();//FaxRXProcess();//FaxData2PC();   //FaxTXProcess();
  551.           gucRxTxFlag = DTETX;
  552.         }
  553.       */
  554.        }//else over Modem active not active 
  555.     }//while end Main circle over
  556. }//main function over
  557.  
  558. /***************************************************************************
  559.      
  560. ***************************************************************************/
  561. /***************************************************************************/