📄 fax.cpp
字号:
case 72: // 7200 found
speeds |= FAX_T7200; // .. set set the speed flag
break;
case 96: // 9600 found
speeds |= FAX_T9600; // .. set set the speed flag
break;
}
}
cp->Write(FAX_RX_SPD); // retrieve receive speeds
rc = Get_Line(buf, 5); // kill the first CR
rc = Get_Line(buf, 5); // get the line from the modem
if (rc) // q. any error?
return(rc); // a. yes.. return w/error
Purge(cp, 1); // kill additional characters
c = (*buf == '\n') ? buf+1 : buf; // select start point
while ((t = strtok(c, ",")) != 0) // while there are tokens
{
c = NULL; // continue searching buf
i = atoi(t); // get the token's value
switch(i) // for various values..
{
case 24: // 2400 found
speeds |= FAX_R2400; // .. set set the speed flag
break;
case 48: // 4800 found
speeds |= FAX_R4800; // .. set set the speed flag
break;
case 72: // 7200 found
speeds |= FAX_R7200; // .. set set the speed flag
break;
case 96: // 9600 found
speeds |= FAX_R9600; // .. set set the speed flag
break;
}
}
return(0); // return ok
}
/* ******************************************************************** *
*
* Reset_Modem -- reset modem and communications parameters
*
* ******************************************************************** */
void Fax::Reset_Modem(void)
{
int rc; // return code
cp->Write("\r"); // send a <CR> to modem
cp->DTR(); // lower DTR
Purge(cp, 1); // .. kill any receive messages
cp->SetBPS(oldspeed); // reset the comm speed
cp->SetLine(oldparms); // .. and the comm parms
cp->Write(FAX_RSTMDM); // try to reset the modem
switch (rc = wait_for(FAX_OK, FAX_ERR, 2)) // based on response
{
case -1: // user pressed escape
return; // .. return without message
case 0: // time out
case 1: // received OK
case 2: // received ERROR
Display_Msg(37+rc); // display appropriate message
}
}
/* ******************************************************************** *
*
* Send_Our_ID -- send our ID to the other station
*
* returns: -2 = User pressed ESC
* -1 - Timeout
* 0 = successful; CONNECT response from modem
* 1 = NO CARRIER response from modem
*
* ******************************************************************** */
int Fax::Send_Our_ID(UCHAR ctl_byte) // FAX control field
{
int i, j; // work variables
UCHAR *ch; // work pointer
ch = hmsg.data; // get the data address
for (i = 0; i < 20; ch[i++] = 0x04); // set to 'reversed' blanks
if (station != NULL) // q. station ID set?
{ // a. yes ..
i = strlen(station); // get station ID length
i = i > 20 ? 20 : i; // max ID length = 20
for (j = 0; i--;) // for each char in station ID
{
if (strchr("0123456789+ ", // q. valid ID character?
station[i]) != 0)
ch[j++] = // a. yes.. reverse & copy it
Reverse_Byte(station[i]);
}
}
return(Send_Hmsg(NON_FINAL, ctl_byte, 20)); // send the HDLC message
}
/* ******************************************************************** *
*
* Display_ID -- display remote station ID
*
* ******************************************************************** */
void Fax::Display_ID(char *pf, // prefix
UCHAR *id) // id string
{
char cw[21]; // work area
int i, j; // work variables
for (i = 20; i--;) // backscan the ID
if (id[i] != ' ') // q. blank?
break; // a. no .. get out now
if (i++ == -1) // q. ID found?
return; // a. no .. leave now
for (j = 0; i--; cw[j++] = id[i]); // copy the ID in reverse
cw[j] = 0; // .. and end the string
sprintf(fs.f_msg, "%s %s\r\n", pf, cw); // put message in buffer
(stat)(1, &fs); // .. and display it
}
/* ******************************************************************** *
*
* Rcv_Hmsg -- receive an HDLC frame
*
* returns: -2 = User pressed ESC
* -1 - Timeout
* 0 = successfully received
* 1 = NO CARRIER or error
*
* ******************************************************************** */
int Fax::Rcv_Hmsg(void)
{
int rc, // return code
loop = 1, // loop until finished
dleflag = FALSE; // dle not seen yet
char *nxtchar, // next receive address
wc; // work for char reads
long timer; // workspace for timer
hmsg.len = 0; // initialize length
nxtchar = (char *) cmsg; // .. and next receive pointer
if ((rc = HDLC_Mode(RECEIVE)) != 0) // q. connect ok?
return(rc); // a. no .. leave w/error
timer = SECS(5); // start 5 second timer
while(loop) // enter a loop ..
switch(cp->Read(nxtchar, &wc, &wc)) // attempting to read bytes
{
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
hmsg.len++; // increment received count
if (dleflag) // q. previous char DLE?
{ // a. yes ..
dleflag = FALSE; // .. reset the flag
if (*nxtchar == ETX) // q. DLE ETX sequence?
loop = 0; // a. yes .. exit the loop
}
else if (*nxtchar == DLE) // q. char a DLE?
dleflag = TRUE; // a. yes .. show true
nxtchar++; // point at next character
break; // end this case
default: // lost characters
return(1); // .. show receive unsuccessful
}
rc = wait_for(FAX_OK, FAX_ERR, 5) - 1; // OK should follow message
Reverse_Bytes(cmsg, hmsg.len - 2); // reverse the bits
return(rc); // return to caller
}
/* ******************************************************************** *
*
* Send_Hmsg -- send an HDLC frame
*
* returns: -2 = User pressed ESC
* -1 - Timeout
* 0 = successful; CONNECT response from modem
* 1 = NO CARRIER response from modem
*
* ******************************************************************** */
int Fax::Send_Hmsg(UCHAR finalflg, // final flag
UCHAR ctl_byte, // fax control field
int len) // length of data bytes
{
int rc; // return code
hmsg.addr = FAX_ADDR; // set the address field
hmsg.ctl_fld = FAX_CTL | finalflg; // .. and the control field
hmsg.fax_ctl_fld = ctl_byte; // .. and fax control field
hmsg.data[len] = DLE; // .. add DLE
hmsg.data[len+1] = ETX; // .. and ETX
Reverse_Bytes(cmsg, len+3); // reverse the bits
if (NOT connected) // q. connected already?
{ // a. no .. connect now
rc = HDLC_Mode(TRANSMIT); // attempt the connection
if (rc) // q. connect ok?
return(rc); // a. no .. leave w/error
connected = TRUE; // else .. show connected.
}
cp->Write((char *) cmsg, len+5); // send to remote
if (finalflg) // q. final flag on?
{ // a. yes ..
rc = wait_for(FAX_OK, FAX_ERR, 5) - 1; // .. wait for OK
connected = FALSE; // .. and we're not connected
}
else
rc = wait_for(FAX_CONN, // else .. wait for CONNECT
FAX_NO_CARR, 60) - 1; // .. or NO CARRIER
return(rc); // return to caller
}
/* ******************************************************************** *
*
* Send_CSI -- Send the called subscriber ID signal to caller
*
* returns: -2 = User pressed ESC
* -1 - Timeout
* 0 = successful; CONNECT response from modem
* 1 = NO CARRIER response from modem
*
* ******************************************************************** */
int Fax::Send_CSI(void)
{
return(Send_Our_ID(FAX_FCF_CSI)); // send CSI frame to caller
}
/* ******************************************************************** *
*
* Send_TSI -- Send the transmitting subscriber ID signal
*
* returns: -2 = User pressed ESC
* -1 - Timeout
* 0 = successful
* 1 = unsuccessful
*
* ******************************************************************** */
int Fax::Send_TSI(void)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -