home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 2
/
goldfish_vol2_cd1.bin
/
files
/
comm
/
misc
/
elcheapofax
/
faxcmd
/
libfax
/
rcs
/
gen.c,v
< prev
next >
Wrap
Text File
|
1993-12-21
|
8KB
|
362 lines
head 1.5;
access;
symbols
OCT93:1.5;
locks;
comment @ * @;
1.5
date 93.10.25.02.20.15; author Rhialto; state Exp;
branches;
next 1.4;
1.4
date 93.09.18.20.16.23; author Rhialto; state Exp;
branches;
next 1.3;
1.3
date 93.07.13.05.45.30; author Rhialto; state Exp;
branches;
next 1.2;
1.2
date 93.06.11.16.15.25; author Rhialto; state Exp;
branches;
next 1.1;
1.1
date 93.06.11.15.19.27; author Rhialto; state Exp;
branches;
next ;
desc
@Things needed for both sending and receiving
@
1.5
log
@Make +FBOR flexible.
@
text
@/* $Id: gen.c,v 1.4 1993/09/18 20:16:23 Rhialto Exp $
* $Log: gen.c,v $
* Revision 1.4 1993/09/18 20:16:23 Rhialto
* Add +FSPL command.
*
* Revision 1.3 1993/07/13 05:45:30 Rhialto
* Now uses verbal response codes instead of non-standard numeric ones.
*
* Revision 1.2 1993/06/11 16:15:25 Rhialto
* First real RCS checkin
*
*/
/*
* This file is part of El Cheapo Fax. All modifications relative to the
* base source are (C) Copyright 1993 by Olaf 'Rhialto' Seibert.
* All rights reserved. The GNU General Public License applies.
*/
/*
This file is part of the NetFax system.
(c) Copyright 1989 by David M. Siegel and Sundar Narasimhan.
All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <string.h>
void sleep(int);
#include "log.h"
#include "c2proto.h"
#include "response.h"
#include "read.h"
#include "write.h"
#include "gen.h"
#include "tty.h"
#include "swap.h"
int faxmodem_open(f, filename)
FaxModem *f;
char *filename;
{
return (f->fd = tty_open(filename));
}
int faxmodem_close(f)
FaxModem *f;
{
return (tty_close(f->fd));
}
int faxmodem_sync(f, total_tries)
FaxModem *f;
int total_tries;
{
int tries;
log(L_INFO, "syncing with %d tries", total_tries);
for (tries = 0; tries < total_tries; tries++) {
int count;
/* Send XON just in case data stream was left off from last page */
tcflow(f->fd, TCOON);
tcflow(f->fd, TCION);
/*
* Clean out the fd.
*/
tcflush(f->fd, TCIOFLUSH);
/*
* Command +FCLASS=2 puts us in class 2 faxmodem mode
* and supposedly resets other parameters
*
* V0 - result codes are digits
* V1 - result codes are words
* Q0 - result codes are sent
* E0 - do not echo
* M0 - speaker off
* S0=0 - dont automatically answer phone
* S2=255 - disable escape character
* S12=255 - longest possible escape guard time
* +FCLASS=2 - enable faxmodem commands
* S7=120 - wait 120 seconds for carrier event
* &K3 - use RTS/CTS instead of XONXOFF
* &D2 - hang up phone when DTR drops
* +FCR=1 - enable fax reception
*/
fdprintf(f->fd, "ATZ\r");
tcdrain(f->fd); sleep(1);
/* fdprintf(f->fd, "ATV0Q0E0M0S0=0S2=255S12=255 +FCLASS=2\r");*/
fdprintf(f->fd, "ATV1Q0E0 S0=0S2=255S12=255 +FCLASS=2\r");
tcdrain(f->fd); sleep(1);
#ifdef AMIGA /* Rhialto */
fdprintf(f->fd, "AT&K3&D2\r");
tcdrain(f->fd); sleep(1);
#endif
fdprintf(f->fd, "ATS7=120 +FCR=1\r");
tcdrain(f->fd); sleep(1);
/* flush any echoes or return codes */
tcflush(f->fd, TCIFLUSH);
/* now see if the modem is talking to us properly */
fdprintf(f->fd, "AT\r");
count = get_modem_response(f, 1);
if (count < 0) {
if (f->status == MODEM_STATUS_FAILED) {
log(L_ERR, "read failed: %m");
return (-1);
} else if (f->status == MODEM_STATUS_TIMEOUT) {
log(L_NOTICE, "read timeout, tries=%d", tries);
} else {
log(L_ERR, "read failed, unknown reason %d", f->status);
}
continue;
} else {
if (f->result != 0) {
log(L_NOTICE, "bad modem response: %d, tries=%d",
f->result, tries);
} else {
log(L_INFO, "modem is now in sync");
/*
* Set DCE capabilities. Just use defaults for now.
*/
return faxmodem_set_capabilities(f, VR_FINE, BR_14400, WD_1728,
LN_UNLIMITED, DF_1DHUFFMAN, EC_DA_ECM, BF_DISABLED, ST_0);
return (0);
}
}
/* wait a little while between tries */
sleep(5);
}
log(L_NOTICE, "cannot sync with fax modem");
return (-1);
}
/*
* Force the modem to hangup: ATH
*
* Usually, this would be called at the very end of a session,
* to insure that the modem goes back on hook.
*
* Return codes:
* 0 ok, hangup has been issued.
* -1 hangup failed.
*/
int faxmodem_hangup(f)
FaxModem *f;
{
log(L_NOTICE, "hanging up the modem");
if (fdprintf(f->fd, "ATH\r") < 0)
return (-1);
return (get_modem_response(f, TIMEOUT_HANGUP));
}
/*
* Bit reversal options: +FBOR
*/
int faxmodem_bit_reverse(f, code)
FaxModem *f;
int code;
{
log(L_NOTICE, "bit reversal mode %d", code);
if (fdprintf(f->fd, "AT+FBOR=%d\r", code) < 0)
return (-1);
set_swapmode(code);
return (get_modem_response(f, TIMEOUT_BIT_REVERSE));
}
/*
* Bit reversal options: +FREL
* 0 = data is bit aligned as received
* 1 = dat is byte aligned at EOLS
*/
int faxmodem_byte_align(f, code)
FaxModem *f;
int code;
{
log(L_NOTICE, "setting byte alignment to mode %d", code);
if (fdprintf(f->fd, "AT+FREL=%d\r", code) < 0)
return (-1);
return (get_modem_response(f, TIMEOUT_BYTE_ALIGN));
}
/*
* 8.5.1.1 DCE capabilities parameters, +FDCC
* Write Syntax: +FDCC=VR,BR,WD,LN,DF,EC,BF,ST
* Default Values: 1,3,2,2,0,0,0,0 (wish that were so)
*/
int faxmodem_set_capabilities(f, vr, br, wd, ln, df, ec, bf, st)
FaxModem *f;
int vr, br, wd, ln, df, ec, bf, st;
{
log(L_NOTICE, "setting DCE capabilities: vr %d br %d wd %d ln %d df %d ec %d bf %d st %d",
vr, br, wd, ln, df, ec, bf, st);
if (fdprintf(f->fd, "AT+FDCC=%d,%d,%d,%d,%d,%d,%d,%d\r",
vr, br, wd, ln, df, ec, bf, st) < 0)
return (-1);
return (get_modem_response(f, TIMEOUT_SET_CAPABILITIES));
}
/*
* Indicating we want to poll a document
*/
int faxmodem_want_poll(f)
FaxModem *f;
{
log(L_NOTICE, "indicating desire to poll");
if (fdprintf(f->fd, "AT+FSPL=1\r") < 0)
return (-1);
return (get_modem_response(f, TIMEOUT_WANT_POLL));
}
@
1.4
log
@Add +FSPL command.
@
text
@d1 1
a1 1
/* $Id: gen.c,v 1.3 1993/07/13 05:45:30 Rhialto Exp $
d3 3
d50 1
d188 2
@
1.3
log
@Now uses verbal response codes instead of non-standard numeric ones.
@
text
@d1 1
a1 1
/* $Id: gen.c,v 1.2 1993/06/11 16:15:25 Rhialto Exp $
d3 3
d180 1
a180 1
log(L_NOTICE, "enabling bit reversal");
d222 14
@
1.2
log
@First real RCS checkin
@
text
@d1 5
a5 2
/* $Id$
* $Log$
a66 1
char buf[128];
d83 1
d99 1
a99 1
fdprintf(f->fd, "ATV0Q0E0 S0=0S2=255S12=255 +FCLASS=2\r");
d101 1
a101 1
#ifdef AMIGA /* OIS */
d113 1
a113 1
count = tfdgets(f->fd, buf, sizeof(buf), 2);
d115 8
a122 4
log(L_ERR, "read failed: %m");
return (-1);
} else if (count == 0) {
log(L_NOTICE, "read timeout, tries=%d", tries);
d125 3
a127 3
if (strncmp(buf, "0\r", 2) != 0) {
log(L_NOTICE, "bad modem response: \"%.*s\", tries=%d",
count, buf, tries);
@
1.1
log
@Initial revision
@
text
@d1 3
@