tlf-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tlf-devel] PTT in cwdaemon?


From: Joop Stakenborg
Subject: Re: [Tlf-devel] PTT in cwdaemon?
Date: Mon, 05 May 2003 21:31:56 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030430 Debian/1.3-5

Wolf-Ruediger Juergens wrote:
Hello OM's,
Before I try to implement the PTT in cwdaemon, can you explain how the PTT should work exactly? As far as I know PTT should become activ a few milliseconds before the first char is send and must stay a while longer activ after the last char. The pin must be pin 7, RTS. Thats what I read from other keying and/or digital programs. What is the main reason for this PTT feature? Delayed switching of a PA? Or using as PTT key for SSB? And what times for delay is handy?
Sorry for so many questions only to switch one pin , hi. :-)

73 de Wolf, DL2WRJ

Hello Wolf,

As far as I know, some rig's need a different line to turn transmit on/off, because the 'VOX' won't work in CW mode.

I have received a patch from Lada, OK1ZIA which contains basic PTT support (but without a delay). Lada has also used vsnprintf in the code, which prevents buffer overflows in cwdaemon. There is also support for changing the keyer port on the fly from tlf (could come in handy if you have different transmitters :-)).

His code takes some time to understand, but generally it is very well written. I have attached his patch.

There is some support for what lada calls 'SSB source switching', a pin on the printer port is designated to switching the MIC input either to the microphone or the soundcard (see the README after applying the patch). He uses this in a VHF contest program.

Let me know what you think of the code. I currently don't have the time to review it thoroughly, but there may be some interest stuff in there.

Joop PA4TU
diff -ruN cwdaemon-0.4/Makefile.am cwdaemon-0.4-zia/Makefile.am
--- cwdaemon-0.4/Makefile.am    Wed Mar 12 21:39:20 2003
+++ cwdaemon-0.4-zia/Makefile.am        Wed Apr 23 20:55:34 2003
@@ -2,11 +2,11 @@
 
 CLEANFILES =  *~
 
-EXTRA_DIST = cwdaemon.spec.in cwdaemon.spec TODO
+EXTRA_DIST = cwdaemon.spec.in cwdaemon.spec cwtest.sh TODO
 
 man_MANS = cwdaemon.8
 
-cwdaemon_SOURCES = cwdaemon.c
+cwdaemon_SOURCES = cwdaemon.c cwdaemon.h lp.c ttys.c
 
 install-data-local:
        @$(NORMAL_INSTALL)
diff -ruN cwdaemon-0.4/README cwdaemon-0.4-zia/README
--- cwdaemon-0.4/README Thu Apr 10 19:40:40 2003
+++ cwdaemon-0.4-zia/README     Wed Apr 23 22:10:54 2003
@@ -29,6 +29,10 @@
 <ESC>"5"                 Stop (Exit) the daemon
 <ESC>"6"                 Set uninterruptable (word- ) mode for simulator
 <ESC>"7"<"weight value"> Set weighting (-5 ... 5)
+<ESC>"8"<"device type">  Set device type (same as -d)
+<ESC>"9"<"port number">  Set lp or ttyS port number (dec or 0xhex) 
+<ESC>"a"<"0|1">          PTT keying off or on
+<ESC>"b"<"0|1">          SSB signal from microphone or soundcard
 Any message                             Send morse code message  (max 1 
packet!)
 qrz de pa0rct ++test--   In- and decrease speed on the fly in 2 wpm steps
 de d~l~2~w~r~j pse k     Add half-space delay after each character
@@ -69,21 +73,45 @@
 
 Cwdaemon parallel port circuitry:
 ---------------------------------
-                                        ----o  CW out to TRX
-                                       |
-                                       |
-                                       | C
-                         1k       B | /
-   SELECT IN      o----/\/\/\-------|/      BC547, 2N2222, etc.
-   (pin 17)                         |\
-                                    | \| E
-                                       |
-   STROBE         o--------------------
-   (pin 1)
-
-
-   GROUND         o-------------------------o  GROUND
-   (pin 18)
+                                   ----o  CW out to TRX
+                                  |
+                                  |
+                                  | C
+                    1k       B | /
+  SELECT IN  o----/\/\/\-------|/      BC547, 2N2222, etc.
+  (pin 17)                     |\
+                               | \| E
+                                  |
+  STROBE     o--------------------*
+  (pin 1)                         |
+                               | /| E
+                               |/   
+  INIT       o----/\/\/\-------|\                                MIROPHONE
+  (pin 16)                     | \  C                        --------o 
+                                  |                         |
+                                   ----o  PTT out to TRX    |    ----o 
+                                                            |   | SOUNDCARD
+                                           _                o  /o
+                               relay coil | |................ / 
+                                   ----*--| |--               o
+                                  | C  |  |_|  |              |
+                               | /     |       |               ------o 
+  AUTOLF     o----/\/\/\-------|/       --|>|--*---o  to +Ucc    MIC input
+  (pin 14)                     |\        diode                   to radio
+                               | \| E    (1N4148 etc)
+                                  | 
+  GROUND     o--------------------*----------------o  GROUND
+  (pin 18)
+
+    
+Notes: -Pin 1 (STROBE) disable CW and PTT between reboot of computer 
+        and cwdaemon initialization. This prevent TRX to transmit
+        before cwdaemon initiate port properly.
+    
+       -Relay -inactive - SSB source from soundcard
+              -active   - SSB source from microphone
+                                         
+       -Pin 14 is reserve                                   
 
 Cwdaemon serial port circuitry (DB9 connector):
 -----------------------------------------------
diff -ruN cwdaemon-0.4/cwdaemon.8.in cwdaemon-0.4-zia/cwdaemon.8.in
--- cwdaemon-0.4/cwdaemon.8.in  Wed Apr  9 19:59:51 2003
+++ cwdaemon-0.4-zia/cwdaemon.8.in      Wed Apr 23 20:55:34 2003
@@ -19,7 +19,10 @@
 .TP
 \fB\-n\fR Do not fork and print debug information to stdout.
 .TP
-\fB\-p <port>\fR Use a different port number (default = 6789)
+\fB\-p <port>\fR Use a different UDP port number (default = 6789)
+.TP
+\fB\-l <port>\fR Use a different ttyS or lp base port number.
+Defaults are 0x378, 0x3f8, 0x2f8.
 .TP
 \fB\-v\fR Output version information and exit.
 .TP
diff -ruN cwdaemon-0.4/cwdaemon.c cwdaemon-0.4-zia/cwdaemon.c
--- cwdaemon-0.4/cwdaemon.c     Wed Apr  9 20:42:43 2003
+++ cwdaemon-0.4-zia/cwdaemon.c Wed Apr 23 22:23:49 2003
@@ -31,104 +31,7 @@
  *
  */
 
-#include <stdio.h>
-#if HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-#if STDC_HEADERS
-# include <stdlib.h>
-# include <stddef.h>
-#else
-# if HAVE_STDLIB_H
-#  include <stdlib.h>
-# endif
-#endif
-#if HAVE_STRING_H
-# if !STDC_HEADERS && HAVE_MEMORY_H
-#  include <memory.h>
-# endif
-# include <string.h>
-#endif
-#if HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-#if DHAVE_ARPA_INET
-# include <arpa/inet.h>
-#endif
-#if HAVE_FCNTL_H
-# include <fcntl.h>
-#endif
-#if HAVE_LIMITS_H
-# include <limits.h>
-#endif
-#if HAVE_NETDB
-# include <netdb.h>
-#endif
-#if HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-#if HAVE_SYS_IOCTL_H
-# include <sys/ioctl.h>
-#endif
-#if HAVE_SYS_SOCKET_H
-# include <sys/socket.h>
-#endif
-#if HAVE_SYSLOG_H
-# include <syslog.h>
-#endif
-#if HAVE_ERRNO_H
-# include <errno.h>
-#endif
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-
-#include <sys/io.h>
-#include <sys/kd.h>
-#include <signal.h>
-#include <ctype.h>
-
-/* device to use */
-enum
-{
-  LP0,
-  LP1,
-  TTYS0,
-  TTYS1
-};
-
-/* default device: default printer port */
-int device = LP0;
-int iobase = 0x378;
-
-/* for printer port */
-#define DATA iobase
-#define STATUS DATA + 1
-#define CONTROL DATA + 2
-
-/* for serial port */
-#define RBR(iobase) (iobase+0)
-#define THR(iobase) (iobase+0)
-#define IER(iobase) (iobase+1)
-#define IIR(iobase) (iobase+2)
-#define FCR(iobase) (iobase+2)
-#define LCR(iobase) (iobase+3)
-#define MCR(iobase) (iobase+4)
-#define LSR(iobase) (iobase+5)
-#define MSR(iobase) (iobase+6)
-#define SCR(iobase) (iobase+7)
-#define DLL(iobase) (iobase+0)
-#define DLM(iobase) (iobase+1)
+#include <cwdaemon.h>
 
 /* we fork by default */
 int forking = 1;
@@ -152,19 +55,6 @@
 #define MAXMORSE 4000
 char morsetext[MAXMORSE];
 
-typedef struct
-{
-  char code;
-  enum
-  {
-    NIL,
-    DIH,
-    DAH,
-  }
-  data[8];
-}
-morse;
-
 morse morsetable[] = {
   {' ', {NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL}},
   {'A', {DIH, DAH, NIL, NIL, NIL, NIL, NIL, NIL}},
@@ -227,6 +117,34 @@
   {0, {NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL}}        /* END MARKER */
 };
 
+cwdevice cwdevice_ttys = {
+  init : ttys_init,
+  free : ttys_free,
+  reset : ttys_reset,
+  cw_on   : ttys_cw_on,
+  cw_off  : ttys_cw_off,
+  ptt_on  : ttys_ptt_on,
+  ptt_off : ttys_ptt_off,
+  ssbway_soundcard : NULL,
+  ssbway_mic : NULL,
+  base : 0x3f8            
+};
+
+cwdevice cwdevice_lp = {
+  init : lp_init,
+  free : lp_free,
+  reset : lp_reset,
+  cw_on   : lp_cw_on,
+  cw_off  : lp_cw_off,
+  ptt_on  : lp_ptt_on,
+  ptt_off : lp_ptt_off,
+  ssbway_soundcard : lp_ssbway_soundcard,
+  ssbway_mic : lp_ssbway_mic,
+  base : 0x378               
+};
+
+cwdevice *cwdev = &cwdevice_lp;
+
 /*
   int weight [-5...0...+5]
   0 = dot/space ratio 1:3, element space = dot time
@@ -252,18 +170,41 @@
 RETSIGTYPE
 catchint (int signal)
 {
+  cwdev->free(cwdev);
   printf ("%s: Exiting\n", PACKAGE);
   exit (0);
 }
 
 /* print error message to the console or syslog if we are forked */
 void
-errmsg (char *info)
+errmsg (char *info, ...)
 {
+  va_list ap;
+  char s[1025];
+
+  va_start(ap, info);
+  vsnprintf(s, 1024, info, ap);
+  va_end(ap);
+    
   if (forking)
-    syslog (LOG_ERR, "%s\n", info);
+    syslog (LOG_ERR, "%s\n", s);
   else
-    printf ("%s: %s failed: %s\n", PACKAGE, info, strerror (errno));
+    printf ("%s: %s failed: %s\n", PACKAGE, s, strerror (errno));
+}
+
+/* print only debug message to the console */
+void
+debug (char *info, ...)
+{
+  va_list ap;
+  char s[1025];
+
+  va_start(ap, info);
+  vsnprintf(s, 1024, info, ap);
+  va_end(ap);
+    
+  if (!forking)
+    printf ("%s: %s \n", PACKAGE, s);
 }
 
 /* use nanosleep instead of usleep */
@@ -301,26 +242,6 @@
 {
   int fd;
 
-  /* open 8 bits of parallel port control register */
-  if (device == LP0 || device == LP1)
-    {
-      if (ioperm (CONTROL, 1, 1) == -1)
-        {
-          errmsg ("Open printer port");
-          exit (1);
-        }
-    }
-
-   /* open 8 bytes of serial port */
-  else if (device == TTYS0 || device == TTYS1)
-    {
-        if (ioperm (iobase, 8, 1) == -1)
-          {
-            errmsg ("Open serial port");
-            exit (1);
-          }
-    }
-
   if (morse_sound)
     {
       signal (SIGINT, SIG_IGN);
@@ -342,11 +263,7 @@
         }
     }
 
-  if (device == LP0 || device == LP1)
-    outb (1, CONTROL); /* SELECT IN bit (pin 17) ON */
-  else if (device == TTYS0 || device == TTYS1)
-    outb (0x03, MCR(iobase));
-
+  cwdev->cw_on(cwdev);
   udelay (duration / morse_speed);
 
   if (morse_sound)
@@ -372,11 +289,7 @@
         signal (SIGINT, catchint);
       signal (SIGQUIT, SIG_DFL);
     }
-
-  if (device == LP0 || device == LP1)
-    outb (0, CONTROL); /* SELECT IN bit (pin 17) OFF */
-  else if (device == TTYS0 || device == TTYS1)
-    outb (0x02, MCR(iobase));
+    cwdev->cw_off(cwdev);
 }
 
 /* play dot, dash and use a delay */
@@ -405,12 +318,12 @@
 int
 recv_code (void)
 {
-  char message[256];
+  char message[257];
   ssize_t recv_rc;
   int speed = 0;
   int weight = 0;
 
-  recv_rc = recvfrom (socket_descriptor, message, sizeof (message), 0,
+  recv_rc = recvfrom (socket_descriptor, message, sizeof (message) - 1, 0,
     (struct sockaddr *) &k_sin, &sin_len);
 
   if (recv_rc == -1 && errno != EAGAIN)
@@ -424,8 +337,7 @@
       if (message[0] != 27)
         { /* no ESCAPE */
           message[recv_rc] = '\0';
-          if (!forking)
-            printf ("%s: Message: %s, length: %d\n", PACKAGE, message, 
recv_rc);
+          debug ("Message: %s, length: %d", message, recv_rc);
           if ((strlen (message) + strlen (morsetext)) <= MAXMORSE - 1)
             strcat (morsetext, message);
           return 1;
@@ -441,15 +353,14 @@
                 morse_tone = 1500;
                 morse_sound = 1;
                 wordmode = 0;
-                if (!forking)
-                  printf ("%s: Reset all values\n", PACKAGE);
+                cwdev->reset(cwdev);
+                debug ("Reset all values");
               break;
               case '2': /*speed */
                 speed = atoi (message + 2);
                 if (speed > 4) /* prevent divide by zero */
                   morse_speed = speed;
-                if (!forking)
-                  printf ("%s: Speed: %d wpm\n", PACKAGE, morse_speed);
+                debug ("Speed: %d wpm", morse_speed);
               break;
               case '3': /* tone */
                 if (atoi (message + 2) != 0)
@@ -459,21 +370,19 @@
                   }
                 else /* sidetone off */
                   morse_sound = 0;
-                if (!forking)
-                  {
-                    if (morse_sound == 1)
-                      printf ("%s: Tone: %s Hz\n", PACKAGE, message + 2);
-                    else
-                      printf ("%s: Tone off\n", PACKAGE);
-                  }
+                
+                if (morse_sound == 1)
+                  errmsg ("Tone: %s Hz", message + 2);
+                else
+                  errmsg ("Tone off");
               break;
               case '4':  /* message abort */
                 message[0] = '\0';
                 morsetext[0] = '\0';
-                if (!forking)
-                  printf ("%s: Message abort\n", PACKAGE);
+                debug ("Message abort");
               break;
               case '5':
+                cwdev->free(cwdev);
                 errno = 0;
                 errmsg ("Sender has told me to end the connection");
                 exit (0);
@@ -482,15 +391,89 @@
                 message[0] = '\0';
                 morsetext[0] = '\0';
                 wordmode = 1;
-                if (!forking)
-                  printf ("%s: Wordmode set\n", PACKAGE);
+                debug ("Wordmode set");
               break;
               case '7': /* set weighting */
                 weight = atoi (message + 2);
                 if ((weight > -6) && (weight < 6)) /* only allowed range */
                   set_weighting (weight);
-                if (!forking)
-                  printf ("%s: Weight: %d\n", PACKAGE, weight);
+                debug("Weight: %d", weight);
+                break;
+             case '8': /* device type */
+                if (!strcmp (message + 2, "ttyS0"))
+                    {
+                        cwdev = &cwdevice_ttys;
+                        cwdev->base = 0x3f8;
+                        cwdev->desc = "ttyS0";
+                      }
+                else if (!strcmp (message + 2, "ttyS1"))
+                    {
+                        cwdev = &cwdevice_ttys;
+                        cwdev->base = 0x2f8;
+                        cwdev->desc = "ttyS1";
+                    }
+                else if (!strcmp (message + 2, "lp0"))
+                    {
+                        cwdev = &cwdevice_lp;
+                        cwdev->base = 0x378;
+                        cwdev->desc = "lp0";
+                    }
+                else if (!strcmp (message + 2, "lp1"))
+                    {
+                        cwdev = &cwdevice_lp;
+                        cwdev->base = 0x278;
+                        cwdev->desc = "lp1";
+                    }
+                else if (!strcmp (message + 2, "lp2"))
+                    {
+                        cwdev = &cwdevice_lp;
+                        cwdev->base = 0x3bc;
+                        cwdev->desc = "lp2";
+                    }
+                break;
+              case '9': /* base port number (decimal or 0xhexadecimal) */
+                errmsg("Closed port 0x%x, %d dec", cwdev->base, cwdev->base);
+                cwdev->free(cwdev);
+                cwdev->base = strtol(message + 2, NULL, 0);
+                cwdev->init(cwdev);
+                errmsg("Setting base port number to 0x%x, %d", cwdev->base, 
cwdev->base);
+              break;
+              case 'a': /* PTT keying on or off */
+                if (atoi (message + 2))
+                {
+                  if (cwdev->ptt_on){
+                    cwdev->ptt_on(cwdev); 
+                    debug("PTT on");
+                  }
+                  else debug("PTT on unimplemented");
+                }
+                else
+                {
+                  if (cwdev->ptt_off){
+                    cwdev->ptt_off(cwdev); 
+                    debug("PTT off");
+                  }
+                  else debug("PTT off unimplemented");
+                }
+              break;
+              case 'b': /* SSB way */
+                if (atoi (message + 2))
+                {
+                  if (cwdev->ssbway_soundcard){
+                    cwdev->ssbway_soundcard(cwdev); 
+                    debug("SSB way set to SOUNDCARD", PACKAGE);
+                  }
+                  else debug("SOUNDCARD unimplemented");
+                }
+                else
+                {
+                  if (cwdev->ssbway_mic){
+                    cwdev->ssbway_mic(cwdev); 
+                    debug("SSB way set to MIC");
+                  }
+                  else debug("MICROPHONE unimplemented");
+                }
+              break;
             }
           return 0;
         }
@@ -543,8 +526,13 @@
 {
   int p;
   int w = 0;
+  int base = -1;
+  
+  cwdev = &cwdevice_lp;
+  cwdev->base = 0x378;
+  cwdev->desc = "lp0";
 
-  while ((p = getopt (argc, argv, "d:hnp:vw:")) != -1)
+  while ((p = getopt (argc, argv, "d:hnp:l:vw:")) != -1)
     {
       switch (p)
         {
@@ -563,7 +551,9 @@
             printf ("       -n           ");
             printf ("Do not fork and print debug information to stdout\n");
             printf ("       -p <port>    ");
-            printf ("Use a different port number (default = 6789)\n");
+            printf ("Use a different UDP port number (default = 6789)\n");
+            printf ("       -l <port>    ");
+            printf ("Use a different ttyS or lp base port number (defaults are 
0x378, 0x3f8, 0x2f8)\n");
             printf ("       -v           ");
             printf ("Output version information and exit\n");
             printf ("       -w <weight>  ");
@@ -585,26 +575,40 @@
                 exit (1);
               }
           break;
+          case 'l':
+            base = strtol(optarg, NULL, 0);
+            debug("Setting base port number to 0x%x, %d dec\n", base, base);
+          break;
           case 'd':
             if (!strcmp (optarg, "ttyS0"))
-                   {
-                iobase = 0x3f8;
-                device = TTYS0;
-                         }
+                 {
+                   cwdev = &cwdevice_ttys;
+                cwdev->base = 0x3f8;
+                cwdev->desc = "ttyS0";
+                     }
             else if (!strcmp (optarg, "ttyS1"))
-                   {
-                iobase = 0x2f8;
-                device = TTYS1;
-                       }
+                 {
+                   cwdev = &cwdevice_ttys;
+                cwdev->base = 0x2f8;
+                cwdev->desc = "ttyS1";
+                 }
             else if (!strcmp (optarg, "lp0"))
               {
-                iobase = 0x378;
-                device = LP0;
+                   cwdev = &cwdevice_lp;
+                cwdev->base = 0x378;
+                cwdev->desc = "lp0";
               }
             else if (!strcmp (optarg, "lp1"))
               {
-                iobase = 0x278;
-                device = LP1;
+                   cwdev = &cwdevice_lp;
+                cwdev->base = 0x378;
+                cwdev->desc = "lp1";
+              }
+            else if (!strcmp (optarg, "lp2"))
+              {
+                   cwdev = &cwdevice_lp;
+                cwdev->base = 0x3bc;
+                cwdev->desc = "lp2";
               }
             else
               {
@@ -624,6 +628,8 @@
           break;
         }
     }
+    if (base!=-1)
+        cwdev->base = base;
 }
 
 /* main program: fork, open network connection and go into an endless loop 
@@ -636,8 +642,8 @@
   long save_file_flags;
 
   parsecommandline (argc, argv);
-  if (!forking)
-    printf ("%s: Device used: %d\n", PACKAGE, device);
+  
+  debug ("Device used: %s at 0x%x, %d", cwdev->desc, cwdev->base, cwdev->base);
  
   if (forking)
     {
@@ -669,10 +675,12 @@
     }
   else
     {
-      printf ("%s: Press ^C to quit\n", PACKAGE);
+      debug ("Press ^C to quit");
       signal (SIGINT, catchint);
     }
 
+  cwdev->init(cwdev);
+
   bzero (&k_sin, sizeof (k_sin));
   k_sin.sin_family = AF_INET;
   k_sin.sin_addr.s_addr = htonl (INADDR_ANY);
@@ -711,6 +719,7 @@
         playmorsestring (morsetext);
     }
 
+  cwdev->free(cwdev);
   close_rc = close (socket_descriptor);
   if (close_rc == -1)
     {
diff -ruN cwdaemon-0.4/cwdaemon.h cwdaemon-0.4-zia/cwdaemon.h
--- cwdaemon-0.4/cwdaemon.h     Thu Jan  1 01:00:00 1970
+++ cwdaemon-0.4-zia/cwdaemon.h Wed Apr 23 20:55:34 2003
@@ -0,0 +1,128 @@
+#ifndef _CWDAEMON_H
+#define _CWDAEMON_H
+
+#include <stdio.h>
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#if HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#if STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# if HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif
+#if HAVE_STRING_H
+# if !STDC_HEADERS && HAVE_MEMORY_H
+#  include <memory.h>
+# endif
+# include <string.h>
+#endif
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#if DHAVE_ARPA_INET
+# include <arpa/inet.h>
+#endif
+#if HAVE_FCNTL_H
+# include <fcntl.h>
+#endif
+#if HAVE_LIMITS_H
+# include <limits.h>
+#endif
+#if HAVE_NETDB
+# include <netdb.h>
+#endif
+#if HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+#if HAVE_SYS_IOCTL_H
+# include <sys/ioctl.h>
+#endif
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+#if HAVE_SYSLOG_H
+# include <syslog.h>
+#endif
+#if HAVE_ERRNO_H
+# include <errno.h>
+#endif
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+#include <sys/io.h>
+#include <sys/kd.h>
+#include <signal.h>
+#include <ctype.h>
+#include <stdarg.h>
+
+#define MAXMORSE 4000
+
+typedef struct
+{
+  char code;
+  enum
+  {
+    NIL,
+    DIH,
+    DAH,
+  }
+  data[8];
+}
+morse;
+
+
+typedef struct cwdev_s
+{
+    int (*init)(struct cwdev_s *);
+    int (*free)(struct cwdev_s *);
+    int (*reset)(struct cwdev_s *);
+    int (*cw_on)(struct cwdev_s *);
+    int (*cw_off)(struct cwdev_s *);
+    int (*ptt_on)(struct cwdev_s *);
+    int (*ptt_off)(struct cwdev_s *);
+    int (*ssbway_soundcard)(struct cwdev_s *);
+    int (*ssbway_mic)(struct cwdev_s *);
+
+    int base;
+    char *desc;
+}
+cwdevice;
+
+void errmsg (char *info, ...);
+void debug (char *info, ...);
+
+int lp_init(cwdevice *dev);
+int lp_free(cwdevice *dev);
+int lp_reset(cwdevice *dev);
+int lp_cw_on(cwdevice *dev);
+int lp_cw_off(cwdevice *dev);
+int lp_ptt_on(cwdevice *dev);
+int lp_ptt_off(cwdevice *dev);
+int lp_ssbway_soundcard(cwdevice *dev);
+int lp_ssbway_mic(cwdevice *dev);
+
+
+
+int ttys_init(cwdevice *dev);
+int ttys_free(cwdevice *dev);
+int ttys_reset(cwdevice *dev);
+int ttys_cw_on(cwdevice *dev);
+int ttys_cw_off(cwdevice *dev);
+int ttys_ptt_on(cwdevice *dev);
+int ttys_ptt_off(cwdevice *dev);
+
+#endif /* _CWDAEMON_H */
diff -ruN cwdaemon-0.4/cwdaemon.spec cwdaemon-0.4-zia/cwdaemon.spec
--- cwdaemon-0.4/cwdaemon.spec  Thu Apr 10 19:48:32 2003
+++ cwdaemon-0.4-zia/cwdaemon.spec      Thu Jan  1 01:00:00 1970
@@ -1,54 +0,0 @@
-# cwdaemon.spec
-#
-# Copyright (c) 2003 Joop Stakenborg address@hidden
-#
-%define name cwdaemon
-%define version 0.4
-%define release 1
-
-# required items
-Name: %{name}
-Version: %{version}
-Release: %{release}
-Copyright: GPL
-Group: Daemons
-Prefix: /usr
-BuildRoot: /var/tmp/%{name}-%{version}
-Summary:  Morse daemon for the parallel or serial port
-Vendor: Joop Stakenborg <address@hidden>
-URL: http://people.debian.org/~pa3aba/cwdaemon.html
-Packager: Joop Stakenborg <address@hidden>
-Source: %{name}-%{version}.tar.gz
-
-%description
-Cwdaemon is a small daemon which uses the pc parallel or serial port 
-and a simple transistor switch to output morse code to a transmitter
-from a text message sent to it via the udp internet protocol.
-
-%prep
-%setup -q
-
-%build
-export RPM_OPT_FLAGS="-O2 -march=i386"
-export CFLAGS="-O2"
-%configure
-make
-
-%install
-rm -rf $RPM_BUILD_ROOT
-mkdir -p $RPM_BUILD_ROOT
-make DESTDIR=$RPM_BUILD_ROOT install
-
-%clean
-rm -rf $RPM_BUILD_ROOT
-
-%files
-%defattr(-,root,root)
-%doc ChangeLog
-/usr/sbin/cwdaemon
-/usr/share/man/man8/cwdaemon.8.gz
-/usr/share/cwdaemon/README
-
-%changelog
-* Sat Jan 18 2003 Joop Stakenborg
-- Initial spec file
diff -ruN cwdaemon-0.4/cwtest.sh cwdaemon-0.4-zia/cwtest.sh
--- cwdaemon-0.4/cwtest.sh      Thu Jan  1 01:00:00 1970
+++ cwdaemon-0.4-zia/cwtest.sh  Wed Apr 23 20:55:34 2003
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+old_tty_settings=$(stty -g)
+stty -icanon
+trap 'stty "$old_tty_settings"; exit 0' INT
+
+echo "Press (CTRL-C) to interrupt..."
+
+while true; do
+  nc -u localhost 6789
+done
+
diff -ruN cwdaemon-0.4/lp.c cwdaemon-0.4-zia/lp.c
--- cwdaemon-0.4/lp.c   Thu Jan  1 01:00:00 1970
+++ cwdaemon-0.4-zia/lp.c       Wed Apr 23 22:09:50 2003
@@ -0,0 +1,79 @@
+
+#include "cwdaemon.h"
+
+/* LP functions */
+
+int lp_init(cwdevice *dev)
+{
+  if (ioperm (dev->base+2, 1, 1) == -1)
+    {
+      errmsg ("Open lp port 0x%x, %d", dev->base, dev->base);
+      exit (1);
+    }
+  
+  dev->reset(dev);  
+
+  /* Enable CW & PTT - /STROBE bit (pin 1) */
+  outb( inb(dev->base+2) |  0x01, dev->base+2);    
+  
+  return 0;
+}
+
+int lp_free(cwdevice *dev)
+{
+  dev->reset(dev);  
+  /* Disable CW & PTT - /STROBE bit (pin 1) */
+  outb( inb(dev->base+2) & ~0x01, dev->base+2);    
+
+  if (ioperm (dev->base+2, 1, 0) == -1)
+    errmsg ("Close lp port 0x%x, %d", dev->base, dev->base);
+  
+  return 0;
+}
+
+int lp_reset(cwdevice *dev)
+{
+  lp_cw_off(dev);
+  lp_ptt_off(dev);
+  lp_ssbway_mic(dev);
+}
+    
+/* CW keying - SELECT IN bit (pin 17) */
+int lp_cw_on(cwdevice *dev)
+{
+  outb( inb(dev->base+2) & ~0x08, dev->base+2);    
+  return 0;
+}
+
+int lp_cw_off(cwdevice *dev)
+{
+  outb( inb(dev->base+2) |  0x08, dev->base+2);  
+  return 0;
+}
+
+/* SSB PTT keying - /INIT bit (pin 16) (inverted) */
+int lp_ptt_on(cwdevice *dev)
+{
+  outb( inb(dev->base+2) |  0x04, dev->base+2);  
+  return 0;
+}
+
+int lp_ptt_off(cwdevice *dev)
+{
+  outb( inb(dev->base+2) & ~0x04, dev->base+2);    
+  return 0;
+}
+
+/* SSB way from mic/soundcard - AUTOLF bit (pin 14) */
+int lp_ssbway_soundcard(cwdevice *dev)
+{
+  outb( inb(dev->base+2) |  0x02, dev->base+2);  
+  return 0;
+}
+
+int lp_ssbway_mic(cwdevice *dev)
+{
+  outb( inb(dev->base+2) & ~0x02, dev->base+2);    
+  return 0;
+}
+
diff -ruN cwdaemon-0.4/ttys.c cwdaemon-0.4-zia/ttys.c
--- cwdaemon-0.4/ttys.c Thu Jan  1 01:00:00 1970
+++ cwdaemon-0.4-zia/ttys.c     Wed Apr 23 20:55:34 2003
@@ -0,0 +1,75 @@
+
+#include "cwdaemon.h"
+
+/* for serial port */
+#define RBR(iobase) (iobase+0)
+#define THR(iobase) (iobase+0)
+#define IER(iobase) (iobase+1)
+#define IIR(iobase) (iobase+2)
+#define FCR(iobase) (iobase+2)
+#define LCR(iobase) (iobase+3)
+#define MCR(iobase) (iobase+4)
+#define LSR(iobase) (iobase+5)
+#define MSR(iobase) (iobase+6)
+#define SCR(iobase) (iobase+7)
+#define DLL(iobase) (iobase+0)
+#define DLM(iobase) (iobase+1)
+
+
+
+/* ttyS functions */
+
+int ttys_init(cwdevice *dev)
+{
+  if (ioperm (dev->base, 8, 1) == -1)
+    {
+      errmsg ("Open ttys port 0x%x, %d", dev->base, dev->base);
+      exit (1);
+    }
+  
+  dev->reset(dev);  
+  return 0;
+}
+
+int ttys_free(cwdevice *dev)
+{
+  dev->reset(dev);  
+
+  if (ioperm (dev->base+2, 8, 0) == -1)
+    errmsg ("Close ttys port 0x%x, %d", dev->base, dev->base);
+  
+  return 0;
+}
+
+int ttys_reset(cwdevice *dev)
+{
+  ttys_cw_off(dev);
+  ttys_ptt_off(dev);
+}
+
+/* CW keying - ? bit (pin ?) */
+int ttys_cw_on(cwdevice *dev)
+{
+  outb (0x03, MCR(dev->base));
+  return 0;
+}
+
+int ttys_cw_off(cwdevice *dev)
+{
+  outb (0x02, MCR(dev->base));
+  return 0;
+}
+
+/* SSB PTT keying - ? bit (pin ?) */
+int ttys_ptt_on(cwdevice *dev)
+{
+  return 0;
+}
+
+int ttys_ptt_off(cwdevice *dev)
+{
+  return 0;
+}
+
+
+

reply via email to

[Prev in Thread] Current Thread [Next in Thread]