⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fax.cpp

📁 在嵌入时系统uc-osii中实现的串口程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:

{

return(Send_Our_ID(FAX_FCF_TSI));           // send TSI frame

}



/* ******************************************************************** *
 *
 *  Send_DIS -- Send the digital ID signal to caller
 *
 *  returns: -2 = User pressed ESC
 *           -1 - Timeout
 *            0 = successful
 *            1 = unsuccesful
 *
 * ******************************************************************** */

int Fax::Send_DIS(void)

{
int     i;                                  // work variable

for (i = 3; i--; hmsg.data[i] = dis_msg[i]);// copy the DIS to hmsg.data

return(Send_Hmsg(FINAL, FAX_FCF_DIS, 3));   // send the DIS

}



/* ******************************************************************** *
 *
 *  Send_DCS -- Send the digital control signal to called station
 *
 *  returns: -2 = User pressed ESC
 *           -1 - Timeout
 *            0 = successful
 *            1 = unsuccesful
 *
 * ******************************************************************** */

int Fax::Send_DCS(void)

{
int     i;                                  // work variable

for (i = 3; i--; hmsg.data[i] = dcs_msg[i]);// copy the DCS to hmsg.data

return(Send_Hmsg(FINAL, FAX_FCF_DCS, 3));   // send the DCS

}



/* ******************************************************************** *
 *
 *  HDLC_Mode -- Enter HDLC mode (transmit or receive)
 *
 *  returns: -2 = User pressed ESC
 *           -1 - Timeout
 *            0 = successful; CONNECT response from modem
 *            1 = ERROR response from modem
 *
 * ******************************************************************** */

int Fax::HDLC_Mode(int dir)                 // setup for HDLC tx or rx
                                            // 0 = transmit, 1 = receive
{
int rc;                                     // return code

if ((dir == TRANSMIT) && NOT connected)     // q. we transmitting?
    {                                       // a. yes ..
    cp->Write(FAX_SILENT);                  // .. request 80ms silence

    rc = wait_for(FAX_OK,                   // wait for response
                  FAX_ERR, 5) - 1;

    if (rc)                                 // q. any problems?
        return(rc);                         // a. yes .. return the error
    }

else if (connected)                         // q. connected already?
    {                                       // a. yes ..
    connected = FALSE;                      // .. reset connect status
    return(0);                              // .. and return ok
    }


cp->Write(dir ? FAX_RX_HDLC : FAX_TX_HDLC); // start requested HDLC mode

rc = wait_for(FAX_CONN, FAX_NO_CARR, 60)-1; // see if we connect

return(rc);                                 // return to caller

}



/* ******************************************************************** *
 *
 *  Data_Mode() -- Enter Fax Data mode (transmit or receive)
 *
 *  returns: -2 = User pressed ESC
 *           -1 - Timeout
 *            0 = successful; CONNECT response from modem
 *            1 = NO CARRIER response from modem
 *
 * ******************************************************************** */

int Fax::Data_Mode(int dir,                 // 0 = transmit, 1 = receive
                   int speed)               // speed for transfer

{
int rc;                                     // return code
char    msg[20];                            // work area for message

if ((dir == TRANSMIT) && NOT connected)     // q. we transmitting?
    {                                       // a. yes ..
    cp->Write(FAX_SILENT);                  // .. request 80ms silence

    rc = wait_for(FAX_OK,                   // wait for response
                  FAX_ERR, 5) - 1;

    if (rc)                                 // q. any problems?
        return(rc);                         // a. yes .. return the error
    }

sprintf(msg,                                // in message area ..
        dir ? FAX_RX_DATA : FAX_TX_DATA,    // .. select direction of xfer
        speed);                             // .. and build message


cp->Write(msg);                             // write to modem

rc = wait_for(FAX_CONN, FAX_NO_CARR, 60)-1; // see if we connect

return(rc);                                 // return to caller

}



/* ******************************************************************** *
 *
 *  Get_Line -- retrieve a CR-terminated line of information
 *
 *  returns: -2 = User pressed ESC
 *           -1 - Timeout
 *            0 = successful
 *            1 = data overrun
 *
 * ******************************************************************** */

int Fax::Get_Line(char *buf,                // buffer to contain info
                  int  secs)                // length of timeout

{
int     loop = TRUE;                        // loop condition
char    wc;                                 // work for msr, lsr
long    timer;                              // timer value

timer = SECS(secs);                         // initialize timer

while(loop)                                 // for as long as necessary ..
    {
    switch(cp->Read(buf, &wc, &wc))         // attempting to read a byte
        {
        case -1:                            // no character available
            if (TimeOut(&timer))            // q. timeout?
                return(-1);                 // a. yes.. tell the caller

            if ((stat)(0, &fs))             // q. user press escape?
                return(-2);                 // a. yes.. tell the caller

            continue;                       // else .. continue loop

        case 0:                             // character received
            if (*buf == '\r')               // q. character a CR?
               {                            // a. yes ..
               *buf = 0;                    // .. null it out
               loop = FALSE;                // .. and end the loop
               }

            else                            // else ..
               buf++;                       // .. point to next char position

            break;                          // end this case

        default:                            // lost characters
            return(1);                      // .. show receive unsuccessful
        }
    }

return(0);                                  // show we finished ok
}



/* ******************************************************************** *
 *
 *  Get_Char -- retrieve a single character
 *
 *  returns: -2 = User pressed ESC
 *           -1 - Timeout
 *            0 = successful
 *            1 = data overrun
 *
 * ******************************************************************** */

int Fax::Get_Char(char *c,                  // character to retrieve
                  int  secs)                // length of timeout

{
int     loop = TRUE;                        // loop condition
char    wc;                                 // work for msr, lsr
long    timer;                              // timer value

timer = SECS(secs);                         // initialize timer

while(loop)                                 // for as long as necessary ..
    {
    switch(cp->Read(c, &wc, &wc))           // attempting to read a byte
        {
        case -1:                            // no character available
            if (TimeOut(&timer))            // q. timeout?
                return(-1);                 // a. yes.. tell the caller

            if ((stat)(0, &fs))             // q. user press escape?
                return(-2);                 // a. yes.. tell the caller

            continue;                       // else .. continue loop

        case 0:                             // character received
            loop = FALSE;                   // .. end the loop
            break;

        default:                            // lost characters
            return(1);                      // .. show receive unsuccessful
        }
    }

return(0);                                  // show we finished ok
}



/* ******************************************************************** *
 *
 *  Display_Msg -- display a message without parameters
 *
 * ******************************************************************** */

void Fax::Display_Msg(int msgno)

{

fs.f_ptr = fax_msgs[msgno];                 // set the address
(stat)(2, &fs);                             // display the message

}



/* ******************************************************************** *
 *
 *  Reverse_Byte() -- Reverse the bits in a byte
 *
 * ******************************************************************** */

UCHAR Fax::Reverse_Byte(UCHAR value)        // byte to reverse

{

__asm  mov cx, 8                            // cx = bits to shift
__asm  mov al, value                        // al = starting value

top_loop:                                   // top of reverse loop
__asm  shl  ah, 1                           // shift ah up by one

__asm  shr  al, 1                           // shift out a bit
__asm  adc  ah, 0                           // .. add carry into ah

__asm  loop top_loop                        // .. until all bits moved

__asm  mov  value, ah                       // save reversed value

return(value);                              // .. and return it

}


/* ******************************************************************** *
 *
 *  Reverse_Bytes -- reverse the bits in the bytes of a string
 *
 * ******************************************************************** */

void Fax::Reverse_Bytes(UCHAR *str,         // string to reverse
                        int    len)         // length of string

{

while(len--)                                // while there are bytes..
     {
     *str = Reverse_Byte(*str);             // .. reverse the bits
     str++;                                 // .. next byte
     }

}



/* ********************************************************************
 *
 *  Receive -- Receive a Facsimile transmission
 *
 * ******************************************************************** */

void Fax::Receive(char *faxname)

{
int     rc = 0,                             // return code

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -