~ubuntu-branches/ubuntu/lucid/cwdaemon/lucid

« back to all changes in this revision

Viewing changes to ttys.c

  • Committer: Bazaar Package Importer
  • Author(s): Joop Stakenborg
  • Date: 2004-04-26 21:27:29 UTC
  • Revision ID: james.westby@ubuntu.com-20040426212729-3wwptnx2a1l9kein
Tags: 0.8
* Cwdaemon is now integrated with unixcw, see cwlib.c and cwlib.h.
  Weighting has been added to unixcw and some special characters needed
  by cwdaemon. The choppiness reported in previous versions of cwdaemon is
  fixed. And we have soundcard support!
* Better handling of aborting messages.
* Weighting now uses a value of -50 to 50.
* 2 extra command line options: -v for volume and -x for sound device.
* 2 extra escape sequences for controlling cwdaemon: ESCfx for switching the
  sound output on the fly and ESCgx for setting the soundcard volume.
* Tune (ESCc) now uses seconds as an argument, e.g. ESCc1 tunes 1 second,
  ESCc10 tunes 10 seconds. Maximum tune value is 10 seconds.
* A fix by Lada, OK1ZIA for big endian systems.
* Footswitch support by Wolf, DL2WRJ (pin 15 of the parallel port).
* New morse character '@' has been added.
* Process priority of cwdaemon can be set with the -P flag. You can try this
  if you experience timing problems.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * cwdaemon - morse sounding daemon for the parallel or serial port
 
3
 * Copyright (C) 2002 -2003 Joop Stakenborg <pg4i@amsat.org>
 
4
 *                       and many authors, see the AUTHORS file.
 
5
 *
 
6
 * This program is free oftware; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
14
 * GNU Library General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 */
 
20
 
 
21
# if HAVE_STDIO_H
 
22
# include <stdio.h>
 
23
#endif
 
24
#if STDC_HEADERS
 
25
# include <stdlib.h>
 
26
# include <stddef.h>
 
27
#else
 
28
# if HAVE_STDLIB_H
 
29
#  include <stdlib.h>
 
30
# endif
 
31
#endif
 
32
#if HAVE_UNISTD_H
 
33
# include <unistd.h>
 
34
#endif
 
35
#if HAVE_SYS_IOCTL_H
 
36
# include <sys/ioctl.h>
 
37
#endif
 
38
#if HAVE_FCNTL_H
 
39
# include <fcntl.h>
 
40
#endif
 
41
#if HAVE_TERMIOS_H
 
42
# include <termios.h>
 
43
#endif
 
44
 
 
45
#include "cwdaemon.h"
 
46
 
 
47
/* serial port functions*/
 
48
 
 
49
int
 
50
ttys_init (cwdevice * dev)
 
51
{
 
52
        int fd;
 
53
        char device[20];
 
54
 
 
55
        sprintf (device, "%s%s", "/dev/", dev->desc);
 
56
        fd = open (device, O_RDWR | O_NOCTTY | O_NDELAY);
 
57
        if (fd < 0)
 
58
        {
 
59
                errmsg ("Open serial port %s", dev->desc);
 
60
                exit (1);
 
61
        }
 
62
        debug ("Serial port opened");
 
63
        dev->fd = fd;
 
64
        dev->reset (dev);
 
65
        return 0;
 
66
}
 
67
 
 
68
int
 
69
ttys_free (cwdevice * dev)
 
70
{
 
71
        dev->reset (dev);
 
72
        close (dev->fd);
 
73
        return 0;
 
74
}
 
75
 
 
76
int
 
77
ttys_reset (cwdevice * dev)
 
78
{
 
79
        ttys_cw (dev, OFF);
 
80
        ttys_ptt (dev, OFF);
 
81
        return 0;
 
82
}
 
83
 
 
84
 
 
85
/* CW keying - bit1 (pin 4 for DB-9) */
 
86
int
 
87
ttys_cw (cwdevice * dev, int onoff)
 
88
{
 
89
        int result, y = TIOCM_DTR;
 
90
 
 
91
        result = ioctl (dev->fd, onoff ? TIOCMBIS : TIOCMBIC, &y);
 
92
        if (result < 0)
 
93
        {
 
94
                errmsg ("Ioctl serial port %s", dev->desc);
 
95
                exit (1);
 
96
        }
 
97
        return 0;
 
98
}
 
99
 
 
100
/* SSB PTT keying - 0 bit (pin 7 for DB-9) */
 
101
int
 
102
ttys_ptt (cwdevice * dev, int onoff)
 
103
{
 
104
        int result, y = TIOCM_RTS;
 
105
 
 
106
        result = ioctl (dev->fd, onoff ? TIOCMBIS : TIOCMBIC, &y);
 
107
        if (result < 0)
 
108
        {
 
109
                errmsg ("Ioctl serial port %s", dev->desc);
 
110
                exit (1);
 
111
        }
 
112
        return 0;
 
113
}