modem 的發送過程

來源:互聯網
上載者:User

該作者通過複原傳真整個過程,分析mgetty-1.1.36源碼得到的分析結果,具有參考意義。

http://hi.baidu.com/kkernel/blog/item/c331c0291b7bdef999250aa0.html

Auther:  Guo Wenxue     Data: 2008.11.20

 

 

參考3類傳真機收發傳真的過程:

http://hi.baidu.com/kkernel/blog/item/05ffd52e87e9b9574ec22663.html

參考mgetty-1.1.36的原始碼分析:

 

PHASE A

Modem發送命令:

Ate0;

At+fclass=1;

Atdt628;   //我們的傳真分機號碼

 

Modem返回:

======================Part1 : modem echo ========================

Rev 9: 0x61 0x74 0x64 0x74 0x36 0x32 0x38 0x0d 0x0a

a    t    d    t    6   2   8    /r   /n

 

======================Part2: Fax return “Connect” ====================        

Rev 11: 0x0d 0x0a 0x43 0x4f 0x4e 0x4e 0x45 0x43 0x54 0x0d 0x0a

       /r   /n    C   O   N   N   E   C    T    /r   /n

 

======================Part3: NSF Frame ===========================

Rev 24: 0xff 0x03 0x20 0x00 0x00 0x56 0x55 0x55 0x00 0x8c 0x90 0x80 0x34 0x0c 0x94 0x37

 

0x10 0x03 0x0d 0x0a 0x4f 0x4b 0x0d 0x0a

DLE ETX /r   /n   O   K   /r   /n

註:

在class1.c的int fax1_dial_and_phase_AB _P2( (dial_cmd,fd), char * dial_cmd, int fd )函數中:

0x03 à0x10這一部分為NSF Frame,他由0x20這個值標誌。

 

代碼:

 

if ( (len = fax1_receive_frame( fd, first? 0:3, 30, framebuf ) ) //讀Modem的返回到framebuf中

switch ( framebuf[1] )

{

           case T30_CSI: fax1_copy_id( framebuf ); break;

          case T30_NSF: fax1_incoming_nsf( framebuf+2, len-2 ); break; //如果是NSF

           case T30_DIS: fax1_parse_dis( framebuf ); break; //如果是DIS,下面介紹

           case T30_DCN: fax1_send_dcn( fd, 20 ); return ERROR;

           default:

               lprintf( L_WARN, "unexpected frame type 0x%02x", framebuf[1] );

}

 

fax1_incoming_nsf定義在faxlib.c中;

fax1_parse_dis定義在class1lib.c中;

 

 

======================Part4: Remote傳真的相關資訊========================

Rev 16: 0xff 0x03 0x40 0x32 0x30 0x37 0x30 0x33 0x37 0x39 0x35 0x37 0x32 0x30 0x20 0x20

ETX   @    2    0     7    0    3    7    9   5    7    2    0   SPACE SPACE //這是我們的傳真號碼

 

Rev 17: 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0xbd 0x64 0x10 0x03 0x0d 0x0a 0x4f 0x4b 0x0d 0x0a

SPACE ---------------------------------> SPACE             DLE ETX /r /n   O    K     /r /n

 

==================Part5: DIS Frame Remote傳真機的capability==================

 

Rev 19: 0xff 0x13 0x80 0x00 0xee 0xa8 0xc4 0x80 0x11 0xe7 0xb3 0x10 0x03 0x0d 0x0a 0x4f 0x4b 0x0d 0x0a

註:0x80標誌這是DIS frame,參考上面的代碼。

在class1lib.c的void fax1_parse_dis _P1((frame), uch * frame )函數中:

首先將frame知道0x00 (FIF), 這樣frame[1]=0xee frame[2]=0xa8,下面按原始碼的注釋對這兩個位元組進行分析:0xee= 1110 1110    0xa8=1010 1000

BIT9是從0x00(FIF)這個位置開始位移,即frame[1]的bit0,依次類推:

BIT    9:  0->fax_to_poll=FALSE

BIT   10:   1->Can receive   //receiving capabilities

BIT 11-14:   1110 1110(0xee)&0011 1100 (0x3c) = 0x2c

所以:case 0x2c: remote_cap.br = V17 | V29 | V27ter=ffe

BIT   15:    1->remote_cap.vr = 1;

BIT   16:    1->remote_cap.df = 1;

 

BIT 17-18:    remote_cap.wd = frame[2] & 0x03;

頁面寬度valid: 0/1/2 = 215/255/303 mm:   00->215mm

BIT 19-20: remote_cap.ln = ( frame[2] >> 2 ) & 0x03;

頁面長度valid: 0/1/2 = A4/B4/unlimited:   10->unlimited

 

BIT 21-23: remote_cap.st = fax1_st_table[ (frame[2] >> 4) & 0x07 ].st;

           (Frame[2]>>4)&0x07=0x0010=2

           查表得:fax1_st_table[2].st = { 3, 10, 10, " 10ms" } /* 2 = 010 */

           struct fax1_st_table { int st; int ms_n; int ms_f; char * txt; };

           所以remote_cap.st=3.

BIT 24: extend bit

             if ( frame[2] & 0x80 ) /* extend bit */ 最高位為1,故為真

             {

                   /* bit 27: ECM */

                if ( frame[3] & 0x04 )    // 0xc4 &0x80 = 0, 不帶ECM

remote_cap.ec = 1;

             }

 

PHASE B:

檔案Class1lib.c的int fax1_send_dcs _P2((fd, s_time), int fd, int s_time )函數是modem向Remote FAX 發送DCS Frame:

while( dcs_btp->speed > 2400 &&

          ( dcs_btp->speed > fax1_max || ( dcs_btp->flag & fax1_ftm & remote_cap.br ) == 0 ) )

       dcs_btp++;

其中:

fax1_max初始化為最大速率14400,即V17_14400;

fax1_ftm是由at+ftm=?命令擷取的modem支援的速率,我們的modem返回是:

3,24,48,72,73,74,96,97,98,121,122,145,146,

所以該modem支援class1lib.c中結構體struct fax1_btable fax1_btable[]定義的全部速率;

remote_cap.br為上PHASE A擷取的remote_cap.br = V17 | V29 | V27ter=ffe

這樣Local Modem與remote FAX協商的速率應該為V29_9600, 即dcs_btp= fax1_btable[3];

 

此時,發送的DCS Frame為:

framebuf[0] = 0x03 | T30_FINAL = 0x03 | 0x10 = 0x13;

framebuf[1] = fax1_dis | T30_DCS = 0x0 | 0x82 = 0x82; //fax1_dump_frame() will set last bit to 0

framebuf[2] = 0;

framebuf[3] = 0x02 | dcs_btp->dcs_bits | ((fax1_res&remote_cap.vr)<<6) | 0x00

= 0x02 | 0x04          | (     (1 &1)          <<6) | 00

= 0100 0010 = 0x46;

 

 

 

framebuf[4] = 0x00     // 00-> 215 mm width

| 0x04     // B4 length

| 0x00     // scan time: 00->?

| 0x00;    // No extend bit

         = 0x04;

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.