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 >
Text File  |  1993-12-21  |  8KB  |  362 lines

  1. head    1.5;
  2. access;
  3. symbols
  4.     OCT93:1.5;
  5. locks;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.5
  10. date    93.10.25.02.20.15;    author Rhialto;    state Exp;
  11. branches;
  12. next    1.4;
  13.  
  14. 1.4
  15. date    93.09.18.20.16.23;    author Rhialto;    state Exp;
  16. branches;
  17. next    1.3;
  18.  
  19. 1.3
  20. date    93.07.13.05.45.30;    author Rhialto;    state Exp;
  21. branches;
  22. next    1.2;
  23.  
  24. 1.2
  25. date    93.06.11.16.15.25;    author Rhialto;    state Exp;
  26. branches;
  27. next    1.1;
  28.  
  29. 1.1
  30. date    93.06.11.15.19.27;    author Rhialto;    state Exp;
  31. branches;
  32. next    ;
  33.  
  34.  
  35. desc
  36. @Things needed for both sending and receiving
  37. @
  38.  
  39.  
  40. 1.5
  41. log
  42. @Make +FBOR flexible.
  43. @
  44. text
  45. @/* $Id: gen.c,v 1.4 1993/09/18 20:16:23 Rhialto Exp $
  46.  * $Log: gen.c,v $
  47.  * Revision 1.4  1993/09/18  20:16:23  Rhialto
  48.  * Add +FSPL command.
  49.  *
  50.  * Revision 1.3  1993/07/13  05:45:30  Rhialto
  51.  * Now uses verbal response codes instead of non-standard numeric ones.
  52.  *
  53.  * Revision 1.2  1993/06/11  16:15:25  Rhialto
  54.  * First real RCS checkin
  55.  *
  56.  */
  57. /*
  58.  * This file is part of El Cheapo Fax. All modifications relative to the
  59.  * base source are (C) Copyright 1993 by Olaf 'Rhialto' Seibert.
  60.  * All rights reserved. The GNU General Public License applies.
  61.  */
  62. /*
  63.   This file is part of the NetFax system.
  64.  
  65.   (c) Copyright 1989 by David M. Siegel and Sundar Narasimhan.
  66.       All rights reserved.
  67.  
  68.     This program is free software; you can redistribute it and/or modify
  69.     it under the terms of the GNU General Public License as published by
  70.     the Free Software Foundation.
  71.  
  72.     This program is distributed in the hope that it will be useful,
  73.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  74.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  75.     GNU General Public License for more details.
  76.  
  77.     You should have received a copy of the GNU General Public License
  78.     along with this program; if not, write to the Free Software
  79.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  80. */
  81.  
  82. #include <stdio.h>
  83. #include <string.h>
  84.  
  85. void sleep(int);
  86.  
  87. #include "log.h"
  88. #include "c2proto.h"
  89. #include "response.h"
  90. #include "read.h"
  91. #include "write.h"
  92. #include "gen.h"
  93. #include "tty.h"
  94. #include "swap.h"
  95.  
  96. int faxmodem_open(f, filename)
  97.      FaxModem *f;
  98.      char *filename;
  99. {
  100.     return (f->fd = tty_open(filename));
  101. }
  102.  
  103. int faxmodem_close(f)
  104.      FaxModem *f;
  105. {
  106.     return (tty_close(f->fd));
  107. }
  108.  
  109. int faxmodem_sync(f, total_tries)
  110.      FaxModem *f;
  111.      int total_tries;
  112. {
  113.     int tries;
  114.  
  115.     log(L_INFO, "syncing with %d tries", total_tries);
  116.  
  117.     for (tries = 0; tries < total_tries; tries++) {
  118.     int count;
  119.  
  120.     /* Send XON just in case data stream was left off from last page */
  121.     tcflow(f->fd, TCOON);
  122.     tcflow(f->fd, TCION);
  123.  
  124.     /*
  125.      * Clean out the fd.
  126.      */
  127.     tcflush(f->fd, TCIOFLUSH);
  128.  
  129.     /*
  130.      * Command +FCLASS=2 puts us in class 2 faxmodem mode
  131.      * and supposedly resets other parameters
  132.      *
  133.      *    V0      - result codes are digits
  134.      *    V1      - result codes are words
  135.      *    Q0      - result codes are sent
  136.      *    E0      - do not echo
  137.      *    M0      - speaker off
  138.      *    S0=0      - dont automatically answer phone
  139.      *    S2=255      - disable escape character
  140.      *    S12=255   - longest possible escape guard time
  141.      *    +FCLASS=2 - enable faxmodem commands
  142.      *    S7=120      - wait 120 seconds for carrier event
  143.      *    &K3      - use RTS/CTS instead of XONXOFF
  144.      *    &D2      - hang up phone when DTR drops
  145.      *    +FCR=1      - enable fax reception
  146.      */
  147.     fdprintf(f->fd, "ATZ\r");
  148.     tcdrain(f->fd); sleep(1);
  149. /*      fdprintf(f->fd, "ATV0Q0E0M0S0=0S2=255S12=255 +FCLASS=2\r");*/
  150.     fdprintf(f->fd, "ATV1Q0E0  S0=0S2=255S12=255 +FCLASS=2\r");
  151.     tcdrain(f->fd); sleep(1);
  152. #ifdef AMIGA                    /* Rhialto */
  153.     fdprintf(f->fd, "AT&K3&D2\r");
  154.     tcdrain(f->fd); sleep(1);
  155. #endif
  156.     fdprintf(f->fd, "ATS7=120 +FCR=1\r");
  157.     tcdrain(f->fd); sleep(1);
  158.  
  159.     /* flush any echoes or return codes */
  160.     tcflush(f->fd, TCIFLUSH);
  161.  
  162.     /* now see if the modem is talking to us properly */
  163.     fdprintf(f->fd, "AT\r");
  164.     count = get_modem_response(f, 1);
  165.     if (count < 0) {
  166.         if (f->status == MODEM_STATUS_FAILED) {
  167.         log(L_ERR, "read failed: %m");
  168.         return (-1);
  169.         } else if (f->status == MODEM_STATUS_TIMEOUT) {
  170.         log(L_NOTICE, "read timeout, tries=%d", tries);
  171.         } else {
  172.         log(L_ERR, "read failed, unknown reason %d", f->status);
  173.         }
  174.         continue;
  175.     } else {
  176.         if (f->result != 0) {
  177.         log(L_NOTICE, "bad modem response: %d, tries=%d",
  178.             f->result, tries);
  179.         } else {
  180.         log(L_INFO, "modem is now in sync");
  181.         /*
  182.          * Set DCE capabilities. Just use defaults for now.
  183.          */
  184.         return faxmodem_set_capabilities(f, VR_FINE, BR_14400, WD_1728,
  185.                LN_UNLIMITED, DF_1DHUFFMAN, EC_DA_ECM, BF_DISABLED, ST_0);
  186.  
  187.         return (0);
  188.         }
  189.     }
  190.  
  191.     /* wait a little while between tries */
  192.     sleep(5);
  193.     }
  194.  
  195.     log(L_NOTICE, "cannot sync with fax modem");
  196.  
  197.     return (-1);
  198. }
  199.  
  200. /*
  201.  * Force the modem to hangup: ATH
  202.  *
  203.  * Usually, this would be called at the very end of a session,
  204.  * to insure that the modem goes back on hook.
  205.  *
  206.  * Return codes:
  207.  *     0    ok, hangup has been issued.
  208.  *    -1    hangup failed.
  209.  */
  210. int faxmodem_hangup(f)
  211.      FaxModem *f;
  212. {
  213.     log(L_NOTICE, "hanging up the modem");
  214.  
  215.     if (fdprintf(f->fd, "ATH\r") < 0)
  216.       return (-1);
  217.  
  218.     return (get_modem_response(f, TIMEOUT_HANGUP));
  219. }
  220.  
  221. /*
  222.  * Bit reversal options: +FBOR
  223.  */
  224. int faxmodem_bit_reverse(f, code)
  225.      FaxModem *f;
  226.      int code;
  227. {
  228.     log(L_NOTICE, "bit reversal mode %d", code);
  229.  
  230.     if (fdprintf(f->fd, "AT+FBOR=%d\r", code) < 0)
  231.       return (-1);
  232.  
  233.     set_swapmode(code);
  234.  
  235.     return (get_modem_response(f, TIMEOUT_BIT_REVERSE));
  236. }
  237.  
  238. /*
  239.  * Bit reversal options: +FREL
  240.  *   0 = data is bit aligned as received
  241.  *   1 = dat is byte aligned at EOLS
  242.  */
  243. int faxmodem_byte_align(f, code)
  244.      FaxModem *f;
  245.      int code;
  246. {
  247.     log(L_NOTICE, "setting byte alignment to mode %d", code);
  248.  
  249.     if (fdprintf(f->fd, "AT+FREL=%d\r", code) < 0)
  250.       return (-1);
  251.  
  252.     return (get_modem_response(f, TIMEOUT_BYTE_ALIGN));
  253. }
  254.  
  255. /*
  256.  * 8.5.1.1 DCE capabilities parameters, +FDCC
  257.  *   Write Syntax: +FDCC=VR,BR,WD,LN,DF,EC,BF,ST
  258.  *   Default Values: 1,3,2,2,0,0,0,0 (wish that were so)
  259.  */
  260. int faxmodem_set_capabilities(f, vr, br, wd, ln, df, ec, bf, st)
  261.      FaxModem *f;
  262.      int vr, br, wd, ln, df, ec, bf, st;
  263. {
  264.     log(L_NOTICE, "setting DCE capabilities: vr %d br %d wd %d ln %d df %d ec %d bf %d st %d",
  265.           vr, br, wd, ln, df, ec, bf, st);
  266.  
  267.     if (fdprintf(f->fd, "AT+FDCC=%d,%d,%d,%d,%d,%d,%d,%d\r",
  268.             vr, br, wd, ln, df, ec, bf, st) < 0)
  269.       return (-1);
  270.  
  271.     return (get_modem_response(f, TIMEOUT_SET_CAPABILITIES));
  272. }
  273.  
  274. /*
  275.  * Indicating we want to poll a document
  276.  */
  277. int faxmodem_want_poll(f)
  278.      FaxModem *f;
  279. {
  280.     log(L_NOTICE, "indicating desire to poll");
  281.  
  282.     if (fdprintf(f->fd, "AT+FSPL=1\r") < 0)
  283.       return (-1);
  284.  
  285.     return (get_modem_response(f, TIMEOUT_WANT_POLL));
  286. }
  287. @
  288.  
  289.  
  290. 1.4
  291. log
  292. @Add +FSPL command.
  293. @
  294. text
  295. @d1 1
  296. a1 1
  297. /* $Id: gen.c,v 1.3 1993/07/13 05:45:30 Rhialto Exp $
  298. d3 3
  299. d50 1
  300. d188 2
  301. @
  302.  
  303.  
  304. 1.3
  305. log
  306. @Now uses verbal response codes instead of non-standard numeric ones.
  307. @
  308. text
  309. @d1 1
  310. a1 1
  311. /* $Id: gen.c,v 1.2 1993/06/11 16:15:25 Rhialto Exp $
  312. d3 3
  313. d180 1
  314. a180 1
  315.     log(L_NOTICE, "enabling bit reversal");
  316. d222 14
  317. @
  318.  
  319.  
  320. 1.2
  321. log
  322. @First real RCS checkin
  323. @
  324. text
  325. @d1 5
  326. a5 2
  327. /* $Id$
  328.  * $Log$
  329. a66 1
  330.     char buf[128];
  331. d83 1
  332. d99 1
  333. a99 1
  334.     fdprintf(f->fd, "ATV0Q0E0  S0=0S2=255S12=255 +FCLASS=2\r");
  335. d101 1
  336. a101 1
  337. #ifdef AMIGA                    /* OIS */
  338. d113 1
  339. a113 1
  340.     count = tfdgets(f->fd, buf, sizeof(buf), 2);
  341. d115 8
  342. a122 4
  343.         log(L_ERR, "read failed: %m");
  344.         return (-1);
  345.     } else if (count == 0) {
  346.         log(L_NOTICE, "read timeout, tries=%d", tries);
  347. d125 3
  348. a127 3
  349.         if (strncmp(buf, "0\r", 2) != 0) {
  350.         log(L_NOTICE, "bad modem response: \"%.*s\", tries=%d",
  351.             count, buf, tries);
  352. @
  353.  
  354.  
  355. 1.1
  356. log
  357. @Initial revision
  358. @
  359. text
  360. @d1 3
  361. @
  362.