From 95365cf6c1fe952a12cfd607830d8ea80a1b53fc Mon Sep 17 00:00:00 2001 From: Gerolf Ziegenhain Date: Wed, 5 Oct 2016 18:36:36 +0200 Subject: [PATCH] morse encoder --- src/Makefile | 2 +- src/cwprotocol.c | 21 +++++++++++++++++++++ src/cwprotocol.h | 10 ++++++++++ src/irmc.c | 7 ++++++- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Makefile b/src/Makefile index 5b9c193..b970cc9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,7 @@ SRC = irmc.c cwprotocol.c beep.c util.c OBJ = ${SRC:.c=.o} LDFLAGS = -lportaudio -lpthread -lm -CFLAGS = -Wall -Wno-format-zero-length +CFLAGS = -Wall -Wno-format-zero-length -Wno-parentheses INSTALLDIR = ${HOME}/bin all: options irmc diff --git a/src/cwprotocol.c b/src/cwprotocol.c index 64435b4..03836ec 100644 --- a/src/cwprotocol.c +++ b/src/cwprotocol.c @@ -1,5 +1,6 @@ #include #include +#include #include "cwprotocol.h" @@ -13,6 +14,8 @@ struct data_packet_format tx_data_packet; int tx_sequence = 0, rx_sequence; int fd_socket; +struct morse_timig_format morse_timing; + int prepare_id (struct data_packet_format *id_packet, char *id) { id_packet->command = DAT; @@ -83,3 +86,21 @@ int send_unlatch (void) return 0; } +int prepare_text2morse (int wpm) +{ + morse_timing.wpm = wpm; + morse_timing.dot_len = (int) (1200/wpm); // in ms - PARIS standard + morse_timing.dash_len = 3*morse_timing.dot_len; + morse_timing.charspace_len = 3*morse_timing.dot_len; + morse_timing.wordspace_len = 7*morse_timing.dot_len; + + return 0; +} + +int char2morse(char c) +{ + // why? because!!! + // http://stackoverflow.com/questions/1352587/convert-a-string-into-morse-code/1355594^ + for(;c= c?c:(c=toupper(getchar())-32)?c<0?1:"\x95#\x8CKa`^ZRBCEIQiw#S#nx(37+$6-2&@/4)'18=,*%.:0;?5" [c-12]-34:-3;c/=2)putchar(c/2?46-c%2:32); + return 0; +} diff --git a/src/cwprotocol.h b/src/cwprotocol.h index 28bab33..d996634 100644 --- a/src/cwprotocol.h +++ b/src/cwprotocol.h @@ -37,6 +37,7 @@ struct data_packet_format{ }; + // Define the packets used #define DEFAULT_CHANNEL 103 @@ -58,5 +59,14 @@ extern int tx_sequence, rx_sequence; extern int fd_socket; +// Morse Code Sender - Timings +#define WPM_DEFAULT 20 +struct morse_timig_format { + int wpm; + int dot_len, dash_len; + int wordspace_len, charspace_len; +}; + +int prepare_text2morse (int wpm); diff --git a/src/irmc.c b/src/irmc.c index 8c4ef03..e9c19c9 100644 --- a/src/irmc.c +++ b/src/irmc.c @@ -40,7 +40,7 @@ long tx_timer = 0; /* TX Methods */ #define TX_NONE 0 //#define TX_SERIAL 1 -//#define TX_KEYBOARD 2 // not implemented yet +#define TX_KEYBOARD 2 // not implemented yet #define TX_RASPI 3 long key_press_t1; @@ -261,6 +261,10 @@ int main(int argc, char *argv[]) } pinMode(TX_RASPI_PIN, INPUT); #endif + +#ifdef TX_KEYBOARD + prepare_text2morse (WPM_DEFAULT); +#endif freeaddrinfo(servinfo); /* all done with this structure */ @@ -366,6 +370,7 @@ int main(int argc, char *argv[]) } if(kbhit() && tx_timer == 0){ + char2morse("s"); getchar(); /* flush the buffer */ } } /* End of mainloop */