2
* cwtest.c - test program for cwdaemon
3
* Copyright (C) 2003, 2006 Joop Stakenborg <pg4i@amsat.org>
5
* Some of this code is taken from netkeyer.c, which is part of the tlf source,
6
* here is the copyright:
7
* Tlf - contest logging program for amateur radio operators
8
* Copyright (C) 2001-2002-2003 Rein Couperus <pa0rct@amsat.org>
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Library General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
* Compile this program with "gcc -o cwtest cwtest.c"
27
* Usage: cwtest or cwtest <portname>
34
#include <sys/socket.h>
35
#include <netinet/in.h>
36
#include <arpa/inet.h>
51
#define K_TOD 9 // set txdelay (turn on delay)
52
#define K_ADDRESS 10 // set port address of device (obsolete)
53
#define K_SET14 11 // set pin 14 on lpt
54
#define K_TUNE 12 // tune
55
#define K_PTT 13 // PTT on/off
56
#define K_SWITCH 14 // set band switch output pins 2,7,8,9 on lpt
57
#define K_SDEVICE 15 // set sound device
58
#define K_VOLUME 16 // volume for soundcard
60
int netkeyer_port = 6789;
61
char netkeyer_hostaddress[16] = "127.0.0.1";
62
int socket_descriptor;
65
struct sockaddr_in address;
66
struct hostent *hostbyname;
69
int netkeyer_init (void)
71
hostbyname = gethostbyname (netkeyer_hostaddress);
72
if (hostbyname == NULL)
74
perror ("gethostbyname failed");
77
bzero (&address, sizeof(address));
78
address.sin_family = AF_INET;
79
memcpy (&address.sin_addr.s_addr, hostbyname->h_addr,
80
sizeof (address.sin_addr.s_addr));
81
address.sin_port = htons (netkeyer_port);
82
socket_descriptor = socket (AF_INET, SOCK_DGRAM, 0);
83
if (socket_descriptor == -1)
85
perror ("socket call failed");
91
int netkeyer_close (void)
94
close_rc = close (socket_descriptor);
97
perror ("close call failed");
104
int netkeyer(int cw_op, char *cwmessage)
115
sprintf (buf, cwmessage);
120
sprintf (buf+2, cwmessage);
125
sprintf (buf+2, cwmessage);
142
sprintf (buf+2, cwmessage);
147
sprintf (buf+2, cwmessage);
152
sprintf (buf+2, cwmessage);
157
sprintf (buf+2, cwmessage);
162
sprintf (buf+2, cwmessage);
167
sprintf (buf+2, cwmessage);
172
sprintf (buf+2, cwmessage);
180
sendto_rc = sendto (socket_descriptor, buf, sizeof (buf),
181
0, (struct sockaddr *)&address, sizeof (address));
189
printf ("Keyer send failed...!\n");
196
catchint (int signal)
198
int result = netkeyer (K_ABORT, "");
202
int main (int argc, char **argv)
206
result = netkeyer_init ();
207
if (result == 1) exit (1);
209
/* tests start here, no error handling */
212
result = netkeyer (K_DEVICE, argv[1]);
213
printf("opening port %s\n", argv[1]);
216
printf("test message abort");
217
signal (SIGALRM, catchint);
218
result = netkeyer (K_MESSAGE, "paris paris");
225
result = netkeyer_close ();
226
if (result == 1) exit (1);