30 Commits
v0.3.5 ... dev

Author SHA1 Message Date
Gerolf Ziegenhain
3b4a4607e0 wip 2016-10-05 21:27:37 +02:00
Gerolf Ziegenhain
df63fe0359 wip 2016-10-05 20:35:47 +02:00
Gerolf Ziegenhain
c33910cdbd wip 2016-10-05 20:29:08 +02:00
Gerolf Ziegenhain
8e7ce33e3b wip 2016-10-05 18:56:58 +02:00
Gerolf Ziegenhain
1a648e1cff wip 2016-10-05 18:50:41 +02:00
Gerolf Ziegenhain
95365cf6c1 morse encoder 2016-10-05 18:36:36 +02:00
Gerolf Ziegenhain
2c2ff2d2ed raspi 2016-10-04 21:29:16 +02:00
Gerolf Ziegenhain
4c7442e3ea wip 2016-10-04 21:23:07 +02:00
Gerolf Ziegenhain
2c7de4792d wip 2016-10-04 21:21:59 +02:00
Gerolf Ziegenhain
496aa90bfe wip 2016-10-04 21:19:18 +02:00
Gerolf Ziegenhain
827798b86b wip 2016-10-04 21:19:06 +02:00
Gerolf Ziegenhain
5f9609ce0c wip 2016-10-04 21:18:09 +02:00
Gerolf Ziegenhain
75c77b0cac wip 2016-10-04 21:13:07 +02:00
Gerolf Ziegenhain
7bf9183401 wip 2016-10-04 21:10:34 +02:00
Gerolf Ziegenhain
746b1dcfe5 wip 2016-10-04 21:10:13 +02:00
Gerolf Ziegenhain
63300fa955 wip 2016-10-04 21:07:05 +02:00
Gerolf Ziegenhain
a43019e565 wip 2016-10-04 21:05:21 +02:00
Gerolf Ziegenhain
370858ce8e wip 2016-10-04 21:02:06 +02:00
Gerolf Ziegenhain
a62c28dcdf rm tx_method 2016-10-04 20:59:40 +02:00
Gerolf Ziegenhain
d8815db878 serial_sep 2016-10-04 20:58:30 +02:00
Gerolf Ziegenhain
d6d0679fb5 wip 2016-10-04 20:54:13 +02:00
Gerolf Ziegenhain
9d28c29a51 wip 2016-10-04 20:48:42 +02:00
Gerolf Ziegenhain
5d1ea8138b wip 2016-10-04 20:48:17 +02:00
Gerolf Ziegenhain
af81f9a084 raspi 2016-10-04 20:45:48 +02:00
Gerolf Ziegenhain
1145e2769e wip 2016-10-04 19:07:03 +02:00
Gerolf Ziegenhain
516c1b4a57 wip 2016-10-04 19:06:37 +02:00
Gerolf Ziegenhain
1db2782667 wiring 2016-10-04 19:00:49 +02:00
Gerolf Ziegenhain
ba6ece9ddd wiring 2016-10-04 18:53:27 +02:00
Gerolf Ziegenhain
4f9169d026 wiring 2016-10-04 18:52:52 +02:00
Gerolf Ziegenhain
e36b01ce41 wiring 2016-10-04 18:48:43 +02:00
6 changed files with 184 additions and 35 deletions

View File

@@ -5,9 +5,16 @@ IRMC stands for Internet Relay Morse Code and is an implementation of [MOIP](htt
# Building
## On Linux
sudo apt-get install -y alsa-oss oss-compat build-essential autoconf libao-dev libtool libportaudio-dev portaudio19-dev
make
### On Raspi (GPIO Interface)
Follow: http://wiringpi.com/download-and-install/
make raspi
## On OSX
brew install portaudio
make
# Hardware interface options
A good description on how to build different interfaces (telegraph key, sounder or both)

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
@@ -21,6 +21,10 @@ irmc: ${OBJ}
@echo CC -o $@
@${CC} -o $@ ${OBJ} ${LDFLAGS}
raspi:
@${CC} -c -DRASPI ${CFLAGS} ${SRC}
@${CC} -o irmc ${OBJ} ${LDFLAGS} -lwiringPi
java:
java -jar test/MorseKOB.jar

View File

@@ -6,7 +6,11 @@
#include "beep.h"
#ifdef RASPI
#define RASPI_AUDIO_LATENCY_FIX (30./5.) // https://app.assembla.com/spaces/portaudio/tickets/246-paex_sine-choppy-on-raspberry-pi---defaultlowoutputlatency-too-low/details
#else
#define RASPI_AUDIO_LATENCY_FIX (1.)
#endif
// http://stackoverflow.com/questions/7678470/generating-sound-of-a-particular-frequency-using-gcc-in-ubuntu

View File

@@ -1,5 +1,7 @@
#include <stdio.h>
#include <sys/socket.h>
#include <ctype.h>
#include "cwprotocol.h"
/* Global variables */
@@ -12,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;
@@ -41,7 +45,7 @@ int prepare_tx (struct data_packet_format *tx_packet, char *id)
tx_packet->a21 = 0; /* These magic numbers was provided by Les Kerr */
tx_packet->a22 = 755;
tx_packet->a23 = 16777215;
snprintf(tx_packet->status, SIZE_STATUS, "?");
snprintf(tx_packet->status, SIZE_STATUS, "?"); // this shall include the sent character
return 0;
}
@@ -64,7 +68,7 @@ int send_latch (void)
tx_data_packet.code[0] = -1;
tx_data_packet.code[1] = 1;
tx_data_packet.n = 2;
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
for(i = 0; i < TX_RETRIES; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
tx_data_packet.n = 0;
return 0;
}
@@ -77,8 +81,78 @@ int send_unlatch (void)
tx_data_packet.code[0] = -1;
tx_data_packet.code[1] = 2;
tx_data_packet.n = 2;
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
for(i = 0; i < TX_RETRIES; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
tx_data_packet.n = 0;
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 clean_tx (void)
{
int i;
for (i=0; i<SIZE_CODE; i++)
tx_data_packet.code[i] = 0;
for (i=0; i<SIZE_STATUS; i++)
tx_data_packet.status[i] = ' ';
tx_data_packet.n = 0;
return 0;
}
// FIXME: This function is really nasty, even for this code :)
int char2morse(int ff)
{
clean_tx();
int c, d, e;
int a=0, b=0;
int i=0;
int k=0;
c=ff;
tx_sequence++;
tx_data_packet.sequence = tx_sequence;
// why? because!!!
// http://stackoverflow.com/questions/1352587/convert-a-string-into-morse-code/1355594^
for(;c= c?c:(c=a=toupper(getchar())-32)?c<0?1:"\x95#\x8CKa`^ZRBCEIQiw#S#nx(37+$6-2&@/4)'18=,*%.:0;?5" [c-12]-34:-3;c/=2) {
e=d;
if (a!=b) {
tx_data_packet.status[k] = a+32; //putchar (a+32);
k++;
}
b=a;
d=(c/2?46-c%2:32);
//putchar (d);
if (d == ' ' && e == ' ') break;
tx_data_packet.code[i] = -1*morse_timing.dot_len;
i++;
int j;
if (d == '.')
j=1;
if (d == '-')
j=3;
if (d == ' ')
j=-3;
tx_data_packet.code[i] = j*morse_timing.dot_len;
i++;
//printf ("(%d %d) ",tx_data_packet.code[i-2],tx_data_packet.code[i-1] );
}
tx_data_packet.code[i] = -1*morse_timing.dot_len;
i++;
tx_data_packet.n = i;
for(i = 0; i < TX_RETRIES; i++)
send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
tx_data_packet.n = 0;
return 0;
}

View File

@@ -10,6 +10,9 @@
#define SIZE_DATA_PACKET 496
#define SIZE_DATA_PACKET_PAYLOAD 492 // = SIZE_DATA_PACKET - SIZE_COMMAND_PACKET
#define TX_RETRIES 5 // how often will the udp packet be sent?
#define KEEPALIVE_CYCLE 1000 // how often will the keepalive signals be sent?
#define SIZE_ID 128
#define SIZE_STATUS 128
#define SIZE_CODE 51
@@ -37,12 +40,14 @@ struct data_packet_format{
};
// Define the packets used
#define DEFAULT_CHANNEL 103
/* Define functions provided by cwprotocol */
int prepare_id (struct data_packet_format *id_packet, char *id);
int prepare_tx (struct data_packet_format *tx_packet, char *id);
int clean_tx (void);
void identifyclient (void);
int send_latch (void);
int send_unlatch (void);
@@ -58,5 +63,14 @@ extern int tx_sequence, rx_sequence;
extern int fd_socket;
// Morse Code Sender - Timings
#define WPM_DEFAULT 40
struct morse_timig_format {
int wpm;
int dot_len, dash_len;
int wordspace_len, charspace_len;
};
int prepare_text2morse (int wpm);
int char2morse(int ff);

View File

@@ -16,26 +16,32 @@
#include <signal.h>
#include <arpa/inet.h>
//#define DEBUG 1
#define MAXDATASIZE 1024 // max number of bytes we can get at once
#include "cwprotocol.h"
#include "beep.h"
#include "util.h"
// http://raspberrypiguide.de/howtos/raspberry-pi-gpio-how-to/
#ifdef RASPI
#include <wiringPi.h>
#define TX_RASPI_PIN 5
#endif
int serial_status = 0, fd_serial, numbytes;
double tx_timeout = 0;
long tx_timer = 0;
#define TX_WAIT 5000
#define TX_TIMEOUT 240.0
#define KEEPALIVE_CYCLE 100
#define BEEP_FREQUENCY 1000.
/* TX Methods */
#define TX_NONE 0
#define TX_SERIAL 1
#define TX_KEYBOARD 2
//#define TX_SERIAL 1
#define TX_KEYBOARD 2 // not implemented yet
#define TX_RASPI 3
long key_press_t1;
long key_release_t1;
@@ -52,7 +58,9 @@ void inthandler(int sig)
signal(sig, SIG_IGN);
send(fd_socket, &disconnect_packet, SIZE_COMMAND_PACKET, 0);
close(fd_socket);
#ifdef TX_SERIAL
close(fd_serial);
#endif
exit(1);
}
@@ -65,18 +73,32 @@ void txloop (void)
tx_data_packet.code[tx_data_packet.n - 1] =
(int) ((key_press_t1 - key_release_t1) * -1);
//printf("space: %i\n", tx_data_packet.code[tx_data_packet.n -1]);
#ifdef DEBUG
printf("space: %i\n", tx_data_packet.code[tx_data_packet.n -1]);
#endif
#ifdef TX_SERIAL
while(serial_status & TIOCM_DSR) ioctl(fd_serial, TIOCMGET, &serial_status);
#endif
#ifdef RASPI
while(digitalRead(TX_RASPI_PIN)==1) { }
#endif
key_release_t1 = fastclock();
tx_data_packet.n++;
tx_data_packet.code[tx_data_packet.n - 1] =
(int) ((key_release_t1 - key_press_t1) * 1);
//printf("mark: %i\n", tx_data_packet.code[tx_data_packet.n -1]);
#ifdef DEBUG
printf("mark: %i\n", tx_data_packet.code[tx_data_packet.n -1]);
#endif
while(1){
#ifdef TX_SERIAL
ioctl(fd_serial, TIOCMGET, &serial_status);
if(serial_status & TIOCM_DSR) break;
#endif
#ifdef RASPI
if(digitalRead(TX_RASPI_PIN)==1) break;
#endif
tx_timeout = fastclock() - key_release_t1;
if(tx_timeout > TX_TIMEOUT) return;
}
@@ -133,7 +155,6 @@ int main(int argc, char *argv[])
int channel;
char id[SIZE_ID];
char serialport[64];
int tx_method = TX_NONE;
// Set default values
snprintf(hostname, 64, "mtc-kob.dyndns.org");
@@ -224,21 +245,34 @@ int main(int argc, char *argv[])
inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
s, sizeof s);
fprintf(stderr, "Connected to %s.\n", s);
beep_init();
if ((strcmp (serialport, "")) != 0)
tx_method = TX_SERIAL;
if (tx_method == TX_SERIAL) {
fd_serial = open(serialport, O_RDWR | O_NOCTTY | O_NDELAY);
if(fd_serial == -1) {
fprintf(stderr,"Unable to open serial port %s.\n", serialport);
}
#ifdef TX_SERIAL
fd_serial = open(serialport, O_RDWR | O_NOCTTY | O_NDELAY);
if(fd_serial == -1) {
fprintf(stderr,"Unable to open serial port %s.\n", serialport);
}
#endif
#ifdef RASPI
if (wiringPiSetup() == -1)
{
fprintf(stderr,"Unable to setup wiringPi for PIN %d\n", TX_RASPI_PIN);
exit (1);
}
pinMode(TX_RASPI_PIN, INPUT);
#endif
#ifdef TX_KEYBOARD
prepare_text2morse (WPM_DEFAULT);
#endif
freeaddrinfo(servinfo); /* all done with this structure */
key_release_t1 = fastclock();
identifyclient();
beep_init();
/* Main Loop */
for(;;) {
if(tx_timer == 0)
@@ -286,7 +320,7 @@ int main(int argc, char *argv[])
}
else
{
beep(1000.0, length/1000.);
beep(BEEP_FREQUENCY, length/1000.);
}
}
}
@@ -300,20 +334,29 @@ int main(int argc, char *argv[])
if(tx_data_packet.n > 1 ){
tx_sequence++;
tx_data_packet.sequence = tx_sequence;
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
for(i = 0; i < TX_RETRIES; i++)
send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
#if DEBUG
printf("irmc: sent data packet.\n");
#endif
tx_data_packet.n = 0;
}
if (tx_method == TX_SERIAL) {
ioctl(fd_serial,TIOCMGET, &serial_status);
if(serial_status & TIOCM_DSR){
txloop();
tx_timer = TX_WAIT;
message(1);
}
#ifdef TX_SERIAL
ioctl(fd_serial,TIOCMGET, &serial_status);
if(serial_status & TIOCM_DSR){
txloop();
tx_timer = TX_WAIT;
message(1);
}
#endif
#ifdef RASPI
if(digitalRead(TX_RASPI_PIN)==1){
txloop();
tx_timer = TX_WAIT;
message(1);
}
#endif
if(keepalive_t < 0 && tx_timer == 0){
#if DEBUG
@@ -325,16 +368,19 @@ int main(int argc, char *argv[])
if(tx_timer == 0) {
keepalive_t--;
usleep(50);
}
if(kbhit() && tx_timer == 0){
getchar(); /* flush the buffer */
}
#ifdef TX_KEYBOARD
if(kbhit() && tx_timer == 0){
char2morse(0);
}
#endif
} /* End of mainloop */
send(fd_socket, &disconnect_packet, SIZE_COMMAND_PACKET, 0);
close(fd_socket);
#ifdef TX_SERIAL
close(fd_serial);
#endif
buzzer_stop();
exit(0);