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

传真(Fax)编程

开发平台:

C/C++

  1. /************************************************
  2. Description: 
  3.       process Dte Command
  4. Input:
  5.       none
  6. Output:
  7.       none
  8. Update:
  9.       2007.03.20 Bryan      add some function
  10.       2007.1.25  Bryan      function header     create
  11. ************************************************/
  12. #include "includeH.h"
  13. void DteGetModemBus(void)
  14. {
  15.     MODEM_BUS_CON_PORT |= MODEM_BUS_2_MCU;
  16.     MODEM_BUS_CON_PORT &= ~MODEM_BUS_2_PC; 
  17.     gucViewStaticStatus &= ~bitViewReceiving;
  18.     gucViewStaticStatus |= bitViewSending;
  19.     ViewCommunicationTX(0x01);
  20.     
  21. }
  22. //*************************************************************************
  23. void DteReturnModemBus(void)
  24. {
  25.      unsigned int  wGeneralCount = 0;
  26.      unsigned int  wOKcount=0;
  27.      unsigned int  wNotOKcount=0; 
  28.      unsigned char  ucRxIndex1=0;
  29.      unsigned char  ucRxIndex0=0;
  30.                     
  31.     MODEM_BUS_CON_PORT |= MODEM_BUS_2_PC;
  32.     MODEM_BUS_CON_PORT &= ~MODEM_BUS_2_MCU;
  33.     while (1)
  34.      {
  35.       ATcmdDelay();
  36.       SendATcmd();          
  37.       ATcmdDelay();
  38.       ATcmdDelay();
  39.     
  40.       while (wGeneralCount++<0xffff)
  41.       {
  42.        ucRxIndex1=gucUartRxCnt-3;
  43.        ucRxIndex0=gucUartRxCnt-2;
  44.        if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
  45.         {wOKcount++;break;}
  46.        if (wGeneralCount==0xffff)
  47.        {    
  48.         //wGeneralCount=0;
  49.         wNotOKcount++;
  50.         SendATcmdModemSoftReset();
  51.         ATcmdDelay();
  52.         ATcmdDelay();
  53.        }//if
  54.       }//while
  55.       ucRxIndex1=gucUartRxCnt-3;
  56.       ucRxIndex0=gucUartRxCnt-2;
  57.       if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
  58.         {wOKcount++;break;}
  59.      }//while
  60.      _NOP();
  61.      gucViewStaticStatus |= bitViewReceiving;
  62.      gucViewStaticStatus &= ~bitViewSending;
  63.      ViewCommunicationTX(0x01);
  64. }
  65. //*************************************************************************
  66. void DteGetFaxList(void)
  67. {
  68. unsigned int wPageAddress=0, wBlockAddress=0,
  69.              wColumnAddress=0,wNextPageAddress=0,
  70.              wRearPntCnt=0;
  71. unsigned char ucRxIndex=0,
  72.               ucGeneralCnt=0,ucFaxPropertyLenCnt,
  73.               ucRxIndex3=0,ucRxIndex2=0,
  74.               ucRxIndex0=0,ucRxIndex1=0;
  75.        SOFTUART_PORT_DIRECTION |= bitSOFTUARTTX;//set SOFTUARTTX open SoftUart TX
  76.   for (wBlockAddress=cstFaxPropertyTableStartBlockNum;
  77.      wBlockAddress<=cstFaxPropertyTableOverBlockNum;wBlockAddress++)
  78. {
  79. //1 block==64pages
  80. for (wPageAddress=(wBlockAddress<<6);wPageAddress<((wBlockAddress<<6)+64);wPageAddress++)
  81. {
  82.       do{
  83.     wNextPageAddress=wPageAddress+64;
  84.     wPageAddress=CalNextPageAddress(wPageAddress);
  85.       }while(wNextPageAddress==wPageAddress);
  86.       
  87.       wColumnAddress=0;
  88.       ROW_ADDRESS_LOW=wPageAddress & 0XFF;
  89.       ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF;
  90.       
  91.       //if a block no erase, one page can write 8 tiems(00 512 1024 1536 2048 2064 2080 2096)
  92.       //So 8 times shall be readed within one page.
  93.       for (ucGeneralCnt=0;ucGeneralCnt<8;ucGeneralCnt++)
  94.       {
  95. //COMMAND
  96.   COMMAND_VAL=0x00; //#0X00 //00H READ1 0-2111BYTE
  97.   COMMAND_LATCH_INTO();
  98. //ADDRESS
  99.   ADDRESS_VALUE=wColumnAddress & 0xff;//COLUMN_ADDRESS_LOW;
  100.   ADDRESS_LATCH_INTO();
  101.   ADDRESS_VALUE=(wColumnAddress>>8) & 0XFF;//COLUMN_ADDRESS_HIGH;
  102.   ADDRESS_LATCH_INTO();
  103.   ADDRESS_VALUE=ROW_ADDRESS_LOW;
  104.   ADDRESS_LATCH_INTO();
  105.   ADDRESS_VALUE=ROW_ADDRESS_HIGH;
  106.   ADDRESS_LATCH_INTO();
  107.   FLASH_CON_PORT_OUT &=~ ALE;
  108.   COMMAND_VAL=0X30;
  109.   COMMAND_LATCH_INTO();
  110.   //ATcmdDelay();
  111.   while((FLASH_CON_PORT_IN & RB)==0);
  112.   DATA_PORT_IN_INITIAL;
  113.   for (ucFaxPropertyLenCnt=0;ucFaxPropertyLenCnt<16;ucFaxPropertyLenCnt++)
  114.   {
  115.     FLASH_CON_PORT_OUT &=~ RE; //RE IS LOW,ENABLE READ DATA
  116.     SoftUartTxOneFrame(DATA_PORT_IN);//add at Jan. 25, 2007
  117.     aucUartRxBuf[ucRxIndex++]=DATA_PORT_IN;
  118.     FLASH_CON_PORT_OUT |= RE;
  119.   }
  120.   wRearPntCnt++;
  121.   ucRxIndex3=ucRxIndex-4;
  122.       ucRxIndex2=ucRxIndex-3;
  123.       ucRxIndex1=ucRxIndex-2;
  124.       ucRxIndex0=ucRxIndex-1;
  125.     if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
  126.        0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
  127.      {
  128.      break;  //next rear   
  129.      }//if
  130.   if (ucGeneralCnt<4)
  131.  wColumnAddress+=512;
  132.           else
  133.  wColumnAddress+=16;
  134.   }//for read next property pointer
  135.   
  136.   //ucRxIndex3=gucUartRxCnt-4;
  137.     //ucRxIndex2=gucUartRxCnt-3;
  138.     //ucRxIndex1=gucUartRxCnt-2;
  139.     //ucRxIndex0=gucUartRxCnt-1;
  140.   if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
  141.      0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
  142.     {break;}
  143.   }//for next page
  144. /*   
  145.   //send the 16 FaxProperty to PC (16*16=256bytes)
  146.   ucRxIndex=0;
  147.   for (wGeneralCnt=0;wGeneralCnt<256;wGeneralCnt++)//
  148.   {
  149.       SoftUartTxOneFrame(aucUartRxBuf[ucRxIndex++]);
  150.       ucRxIndex3=ucRxIndex+3;
  151.         ucRxIndex2=ucRxIndex+2;
  152.         ucRxIndex1=ucRxIndex+1;
  153.         ucRxIndex0=ucRxIndex+0;
  154.         if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
  155.          0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
  156.        break;
  157.   }
  158. */
  159.   //ucRxIndex3=gucUartRxCnt-4;
  160.     //ucRxIndex2=gucUartRxCnt-3;
  161.     //ucRxIndex1=gucUartRxCnt-2;
  162.     //ucRxIndex0=gucUartRxCnt-1;
  163.   if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
  164.      0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
  165.     {break;}
  166. }//for next block
  167. gwGeneralPageAddress=wPageAddress; //for write Fax property record
  168.   gwColumnAddress=wColumnAddress;    //for write Fax property record
  169.         SOFTUART_PORT_DIRECTION &= ~bitSOFTUARTTX;//off the SoftUart
  170. }
  171. //*************************************************************************
  172. void DteGetOneFax(unsigned int wEveryFaxHead, unsigned int wEveryFaxRear)
  173. {
  174.       unsigned char ucFlashColumnAddCnt=0;
  175.       
  176.       //unsigned char  ucRxIndex=0;
  177.       //unsigned char  ucBlockCnt=0;
  178.       unsigned int 
  179.                    wNextPageAddress=0,wPageAddress=0,
  180.                    wGeneralCnt=0;
  181.     //MODEM_BUS_CON_PORT |= SOFT_UART_2_PC;
  182.     //SOFTUART_PORT_DIRECTION |= SOFT_UART_2_PC;
  183.     SOFTUART_PORT_DIRECTION |= bitSOFTUARTTX;
  184.     if (wEveryFaxHead<wEveryFaxRear)//(wEveryFaxHead!=wEveryFaxRear)//
  185.       {
  186.          
  187.       for (wPageAddress=wEveryFaxHead;wPageAddress<=wEveryFaxRear;)//
  188.       {
  189.         
  190.         ROW_ADDRESS_LOW = wPageAddress & 0xff;
  191.         ROW_ADDRESS_HIGH = (wPageAddress>>8) & 0xff;
  192.         for (ucFlashColumnAddCnt = 0;ucFlashColumnAddCnt < 8;ucFlashColumnAddCnt++)//8*256=2048
  193.         {
  194.     //8 * 256 == 2048 Bytes 2^4*2^8 12bit column address HighColumnAddr:0~8
  195.             //total 8*256B+64B=2K+64B
  196.     COLUMN_ADDRESS_HIGH=ucFlashColumnAddCnt;
  197.     READ_256_BYTE();//read 256 Byte to aucUartRxBuf[256]
  198.     for (wGeneralCnt=0;wGeneralCnt<256;wGeneralCnt++)//
  199.     {
  200. SoftUartTxOneFrame(aucUartRxBuf[wGeneralCnt]);
  201. if (aucUartRxBuf[wGeneralCnt-1] == 0xfb && aucUartRxBuf[wGeneralCnt-2] == 0x13 && aucUartRxBuf[wGeneralCnt-3] == 0xff)
  202.   {_NOP();break;}             
  203.     }//third for
  204.     if (aucUartRxBuf[wGeneralCnt-1] == 0xfb && aucUartRxBuf[wGeneralCnt-2] == 0x13 && aucUartRxBuf[wGeneralCnt-3] == 0xff)
  205.   break;        
  206.         }//second for
  207.         
  208.        if (aucUartRxBuf[wGeneralCnt-1] == 0xfb && aucUartRxBuf[wGeneralCnt-2] == 0x13 && aucUartRxBuf[wGeneralCnt-3] == 0xff)//pageimage over
  209.           {                                                 
  210.             /*//Record the front pointer for Check new in DCE
  211.             ATcmdDelay();// a bug of Dec.23,2006 FF 10 00 0E // receive data delay(if not, can't receive 0x10 0x03)
  212.             if ((gwGeneralPageAddress>>6) > cstFaxFrontPointerTableOverBlockNum)
  213.            {
  214.             for (ucBlockCnt=0;ucBlockCnt<4;ucBlockCnt++)
  215.             {
  216.                  wPageAddress=(cstFaxFrontPointerTableStartBlockNum+ucBlockCnt)<<6;
  217.           ROW_ADDRESS_LOW=wPageAddress & 0XFF;
  218.           ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF; 
  219.           ERASE_ONE_BLOCK();
  220.             }
  221.             gwGeneralPageAddress = cstFaxFrontPointerTableStartPage;
  222.             gwColumnAddress=0;
  223.            }
  224.            
  225.             //Record the front pointer for Check new in DCE
  226.             
  227.             ReadLastFaxFrontPointer();    
  228.             ucRxIndex=0; //write Fax Front Pointer
  229.             aucUartRxBuf[ucRxIndex++]=wPageAddress & 0xff;
  230.             aucUartRxBuf[ucRxIndex++]=(wPageAddress>>8) & 0xff;
  231.             for (ucBlockCnt=0; ucBlockCnt<12; ucBlockCnt++)
  232.             {
  233.              aucUartRxBuf[ucRxIndex++]=0x55;
  234.             }
  235.             //WriteFaxFrontPointerTable();
  236.             Write16Bytes2FlashMemoryArea();
  237.             */
  238.             wPageAddress++;
  239.             if(wPageAddress==0)
  240.                wPageAddress += cstFaxContentStartPage;//2560;//Mar. 1, 20007
  241.             do{
  242.       wNextPageAddress=wPageAddress+64;
  243.       wPageAddress=CalNextPageAddress(wPageAddress);
  244.       }while(wNextPageAddress==wPageAddress);
  245.              //ReadLastFaxFrontPointer();//read next write fax front pointer addr    //delete at Jan. 19, 2007
  246.             continue;//break; a bug of Dec. 12,2006
  247.           }
  248.           wPageAddress++;
  249.           if(wPageAddress==0)
  250.                wPageAddress += cstFaxContentStartPage;//2560;//Mar. 1, 20007
  251.             do{
  252.       wNextPageAddress=wPageAddress+64;//wNextPageAddress=gwPageAddress+64;
  253.       wPageAddress=CalNextPageAddress(wPageAddress);
  254.       }while(wNextPageAddress==wPageAddress);             
  255.        }//third for ----> next page
  256.        
  257.        }//if wNewFaxHead<wNewFaxRear
  258.        //MODEM_BUS_CON_PORT &= ~SOFT_UART_2_PC;
  259.        //SOFTUART_PORT_DIRECTION &= ~SOFT_UART_2_PC;
  260.        SOFTUART_PORT_DIRECTION &= ~bitSOFTUARTTX;
  261. }//DteGetOneFax function over 
  262. /*
  263. void SetSystemTime(unsigned char ucYear, unsigned char ucMonth, unsigned char ucDate, 
  264.                    unsigned char ucHour, unsigned char ucMinute, unsigned char ucSecond)
  265. {
  266. ;
  267. */ 
  268. void DceResponsePc(void)
  269. {
  270.        unsigned char ucRxIndex=0;
  271.        for (ucRxIndex=0; ucRxIndex<8; ucRxIndex++)
  272.        SoftUartTxOneFrame(aucUartRxBuf[ucRxIndex]);