morse encoder

This commit is contained in:
Gerolf Ziegenhain 2016-10-05 18:36:36 +02:00
parent 2c2ff2d2ed
commit 95365cf6c1
4 changed files with 38 additions and 2 deletions

View File

@ -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

View File

@ -1,5 +1,6 @@
#include <stdio.h>
#include <sys/socket.h>
#include <ctype.h>
#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;
}

View File

@ -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);

View File

@ -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 */