Compare commits
67 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
79b9ab5dc1 | ||
|
a8b5ad29b7 | ||
|
a8468dbe42 | ||
|
d2254a907b | ||
|
cc3bf0ae5a | ||
|
bc62081ced | ||
|
24a5afa697 | ||
|
7305e8a723 | ||
|
aa596c0c66 | ||
|
2d8ca13a22 | ||
|
f05f4ae2f7 | ||
|
2f88687332 | ||
|
98d3b54d82 | ||
|
fbd96d2495 | ||
|
0ccfe55978 | ||
|
eb1c87cb37 | ||
|
67acd163b6 | ||
|
2c71fe456d | ||
|
0519826df2 | ||
|
e4a61ba4a9 | ||
|
251fa57b32 | ||
|
b075427a3c | ||
|
77dc0cf117 | ||
|
9319409282 | ||
|
572c6d93ac | ||
|
dd0881a5d4 | ||
|
d73eb66b99 | ||
|
ae779dc2f5 | ||
|
f028280963 | ||
|
765cb854ed | ||
|
12f2d905ce | ||
|
1140c99193 | ||
|
272d03cbc8 | ||
|
d2f8a0b65f | ||
|
87dbb05d3e | ||
|
9599bae5a8 | ||
|
dccf7e6cfc | ||
|
b20d4efe9e | ||
|
e0471a4c62 | ||
|
24a74dbd55 | ||
|
cb783b97e1 | ||
|
45716af4f9 | ||
|
9d540cf369 | ||
|
a2200a4aa6 | ||
|
182be32401 | ||
|
f222d65bd8 | ||
|
840bbd0c04 | ||
|
50dfd48602 | ||
|
5ffefff868 | ||
|
dd72972a96 | ||
|
572345d34b | ||
|
04572c6c16 | ||
|
f7b1bf6e1e | ||
|
4c02a54109 | ||
|
7e8c1803af | ||
|
247deb12dc | ||
|
6e141246f6 | ||
|
8f77f51fcf | ||
|
c8105acca0 | ||
|
b2f24af29e | ||
|
0b242efc1a | ||
|
adeba195f6 | ||
|
0424b7e2d3 | ||
|
87f8437b87 | ||
|
ecce799bb7 | ||
|
a4bbec6497 | ||
|
325d794b7c |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1,3 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
irmc
|
||||||
|
*.o
|
||||||
|
8
AUTHORS
Normal file
8
AUTHORS
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
Fernan Bolando (VE4FEB)
|
||||||
|
Gerolf Ziegenhain (DG6FL)
|
||||||
|
|
||||||
|
MorseKOB:
|
||||||
|
Lex Kerr
|
||||||
|
|
||||||
|
CWCom Protocol:
|
||||||
|
John Samien (VK1EME)
|
99
README.md
99
README.md
@@ -1,41 +1,82 @@
|
|||||||
=== WIP - Snipplets ===
|
irmc - Internet Relay Morse Code
|
||||||
How to use:
|
================================
|
||||||
|
|
||||||
1 usage: irmc [hostname] [port] [channel] [id] [serialport]
|
IRMC stands for Internet Relay Morse Code and is an implementation of [MOIP](https://github.com/8cH9azbsFifZ/moip).
|
||||||
./irmc mtc-kob.dyndns.org 7890 103 123 /dev/tty.usbserial
|
It implements the [CWCom protocol](http://kob.sdf.org/morsekob/docs/cwcom.pdf)
|
||||||
faeroes.sdf.org.7890
|
as adopted by [MorseKOB](http://kob.sdf.org/morsekob/docs/history.pdf).
|
||||||
|
You can try out the software in a [browser](http://kob.sdf.org/morsekob/morsekob30/index.htm) using Java.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
TBD: Driver:
|
# How to build?
|
||||||
serial - 2usb!
|
## Install dependency: morse keyer library
|
||||||
|
```
|
||||||
|
wget https://github.com/8cH9azbsFifZ/morse/archive/v0.1.tar.gz
|
||||||
|
tar xzf v0.1.tar.gz
|
||||||
|
cd morse-0.1
|
||||||
|
libtoolize
|
||||||
|
./autogen.sh
|
||||||
|
./configure --with-portaudio
|
||||||
|
make
|
||||||
|
sudo make install
|
||||||
|
```
|
||||||
|
|
||||||
TBD: OSX - howto install dependencies
|
## Debian (Wheezy)
|
||||||
|
Some dependencies have to be installed:
|
||||||
|
```
|
||||||
|
apt-get install -y alsa-oss oss-compat build-essential autoconf libao-dev libtool
|
||||||
|
```
|
||||||
|
Afterwards compilation with `make` should work. If something went wrong, you may have
|
||||||
|
to adjust your `LD_LIBRARY_PATH`. Alternatively try:
|
||||||
|
```
|
||||||
|
LD_LIBRARY_PATH=/usr/local/lib ./irmc mtc-kob.dyndns.org 7890 33 123
|
||||||
|
```
|
||||||
|
|
||||||
=== Original post ===
|
## OSX (Yosemite)
|
||||||
I have been using cwcom to practice sending morsecode, unfortunately my main computer at home is running openbsd and it has gotten harder to gain access to a reliable MS Windows machine. So I wrote my own client that works on openbsd.
|
Compilation with make :)
|
||||||
This is written in C and although not tested it should compile under other OS. If any one wants to try it and send me feedback. you can download version 0.01 here http://fernan.bitbucket.org/irmc.tgz
|
|
||||||
Les Kerr of https://home.comcast.net/~morsekob/ has been very patient in answering my questions regarding the cwcom protocol and setting up a test server during debugging.
|
|
||||||
|
|
||||||
There are few difference between this and the official cwcom client
|
For the USB serial devices you need a PL2303 driver
|
||||||
1. It is a command line tool
|
(i.e. [PL2303_Serial-USB_on_OSX_Lion.pkg](http://changux.co/osx-installer-to-pl2303-serial-usb-on-osx-lio/)).
|
||||||
2. It does not send the characters of the message to the receivers screen.
|
|
||||||
3. It does not translate CW for you. You can try fldigi if you just want see the transmission.
|
|
||||||
4. Tone pitch is currently hard coded to 650Hz
|
|
||||||
5. It does not have a way to show you who is listening.
|
|
||||||
|
|
||||||
Bugs
|
## Testing
|
||||||
There are a few that I am working on right now, but feel free to send me feedback if you get a chance to try it out.
|
./irmc morsecode.dyndns.org 7890 2348 test
|
||||||
|
|
||||||
File(s)
|
Or you may want to use tcpdump, i.e.:
|
||||||
http://fernan.bitbucket.org/irmc.tgz
|
```
|
||||||
|
sudo tcpdump -i all -vvvv "host faeroes.sdf.org"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
Resources
|
# How to use:
|
||||||
The following people have helped me a lot to learn the protocols and setting up test servers.
|
`./irmc -h`
|
||||||
Les Kerr - https://home.comcast.net/~morsekob/
|
|
||||||
Bob Denny - http://morse-rss-news.sourceforge.net/
|
|
||||||
John Samin - http://www.mrx.com.au/
|
|
||||||
|
|
||||||
=== Source: http://fernski.blogspot.de/2013/03/internet-relay-morsecode.html ===
|
|
||||||
=== End Original Post ===
|
|
||||||
|
|
||||||
|
## Hardware interface options
|
||||||
|
A good description on how to build different interfaces (telegraph key, sounder or both)
|
||||||
|
is given on the [MorseKOB Website](http://kob.sdf.org/morsekob/interface.htm).
|
||||||
|
Landline telegraphs use "closed circuits" for communications; if you have built one at home,
|
||||||
|
you may also use the [loop interface](http://kob.sdf.org/morsekob/docs/loopinterface.pdf).
|
||||||
|
|
||||||
|
Connection of a morse key:
|
||||||
|
Serial PIN: 4 & 6
|
||||||
|
[layout of pins](http://techpubs.sgi.com/library/dynaweb_docs/0650/SGI_Admin/books/MUX_IG/sgi_html/figures/4-2.serial.port.con.gif)
|
||||||
|
Connecting the palm radio: keep an eye on the grounding :)
|
||||||
|
|
||||||
|
|
||||||
|
http://kob.sdf.org/morsekob/interface.htm#portpins
|
||||||
|
RS232 DB9 Function
|
||||||
|
DTR 4 Manual Key / paddle common
|
||||||
|
DSR 6 Manual key / dot paddle
|
||||||
|
CTS 8 Dash paddle
|
||||||
|
RTS 7 Sounder output
|
||||||
|
SG 5 Sounder ground
|
||||||
|
|
||||||
|
|
||||||
|
# Changelog
|
||||||
|
* v0.2 [zip](https://github.com/8cH9azbsFifZ/irmc/archive/v0.2.zip) - ported to debian wheezy and osx yosemite, DG6FL
|
||||||
|
* v0.1 [zip](https://github.com/8cH9azbsFifZ/irmc/archive/v0.1.zip) - original version, VE7FEB
|
||||||
|
|
||||||
|
Code Quality
|
||||||
|
============
|
||||||
|
This is experimental code.
|
||||||
|
BIN
doc/cwcom.pdf
Normal file
BIN
doc/cwcom.pdf
Normal file
Binary file not shown.
BIN
doc/loopinterface.pdf
Normal file
BIN
doc/loopinterface.pdf
Normal file
Binary file not shown.
BIN
doc/screenshot.png
Normal file
BIN
doc/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
94
sound.c
94
sound.c
@@ -1,94 +0,0 @@
|
|||||||
/* irmc - internet relay morsecode client */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <soundcard.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#define SAMPLE_RATE 48000
|
|
||||||
|
|
||||||
int sample_rate = SAMPLE_RATE;
|
|
||||||
int fd_speaker;
|
|
||||||
int zinebuf[SAMPLE_RATE * 2];
|
|
||||||
int pitch = 650;
|
|
||||||
|
|
||||||
void
|
|
||||||
init_sound()
|
|
||||||
{
|
|
||||||
int i, pr;
|
|
||||||
|
|
||||||
pr = sample_rate / pitch;
|
|
||||||
|
|
||||||
for(i = 0; i < SAMPLE_RATE * 2; i++)
|
|
||||||
zinebuf[i] = 32767 * sin(2 * 3.1415 / pr * (double)i );
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
play_code_element (int length)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
short buf[SAMPLE_RATE * 4];
|
|
||||||
|
|
||||||
int outsz;
|
|
||||||
|
|
||||||
outsz = abs(length) * SAMPLE_RATE / 1000;
|
|
||||||
|
|
||||||
if(length == 0 || abs(length) > 2000) return;
|
|
||||||
if(length < 0) { /* Space */
|
|
||||||
for (i = 0; i < outsz; i++) buf[i] = 0;
|
|
||||||
} else { /* Mark */
|
|
||||||
for (i = 0; i < outsz; i++) buf[i] = zinebuf[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (write (fd_speaker, buf, outsz * 2) != (outsz * 2)){
|
|
||||||
perror ("Audio write");
|
|
||||||
exit (-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
open_audio_device (char *name, int mode)
|
|
||||||
{
|
|
||||||
int tmp, fd;
|
|
||||||
|
|
||||||
if ((fd = open (name, mode, 0)) == -1){
|
|
||||||
perror (name);
|
|
||||||
//exit (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = AFMT_S16_NE; /* Native 16 bits */
|
|
||||||
if (ioctl (fd, SNDCTL_DSP_SETFMT, &tmp) == -1){
|
|
||||||
perror ("SNDCTL_DSP_SETFMT");
|
|
||||||
exit (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tmp != AFMT_S16_NE){
|
|
||||||
fprintf (stderr,
|
|
||||||
"The device doesn't support the 16 bit sample format.\n");
|
|
||||||
exit (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = 1;
|
|
||||||
if (ioctl (fd, SNDCTL_DSP_CHANNELS, &tmp) == -1){
|
|
||||||
perror ("SNDCTL_DSP_CHANNELS");
|
|
||||||
exit (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tmp != 1){
|
|
||||||
fprintf (stderr, "The device doesn't support mono mode.\n");
|
|
||||||
exit (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
//sample_rate = 48000;
|
|
||||||
if (ioctl (fd, SNDCTL_DSP_SPEED, &sample_rate) == -1){
|
|
||||||
perror ("SNDCTL_DSP_SPEED");
|
|
||||||
exit (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
3
sound.h
3
sound.h
@@ -1,3 +0,0 @@
|
|||||||
void init_sound (void);
|
|
||||||
void play_code_element (int);
|
|
||||||
int open_audio_device (char *, int);
|
|
@@ -1,7 +1,7 @@
|
|||||||
SRC = irmc.c sound.c
|
SRC = irmc.c cwprotocol.c
|
||||||
OBJ = ${SRC:.c=.o}
|
OBJ = ${SRC:.c=.o}
|
||||||
LDFLAGS = -lm -lossaudio
|
LDFLAGS = -L/usr/local/lib -L/opt/local/lib -lm -lmorse
|
||||||
CFLAGS = -Wall
|
CFLAGS = -I/usr/local/include -I/opt/local/include -Wall
|
||||||
INSTALLDIR = ${HOME}/bin
|
INSTALLDIR = ${HOME}/bin
|
||||||
|
|
||||||
all: options irmc
|
all: options irmc
|
||||||
@@ -21,9 +21,8 @@ irmc: ${OBJ}
|
|||||||
@echo CC -o $@
|
@echo CC -o $@
|
||||||
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||||
|
|
||||||
hex: ${OBJ}
|
java:
|
||||||
@echo avr-gcc -o $@
|
java -jar test/MorseKOB.jar
|
||||||
avr-gcc -o $@ ${OBJ} ${LDFLAGS}
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo cleaning
|
@echo cleaning
|
36
src/cwprotocol.c
Normal file
36
src/cwprotocol.c
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "cwprotocol.h"
|
||||||
|
|
||||||
|
int prepare_id (struct data_packet_format *id_packet, char *id)
|
||||||
|
{
|
||||||
|
id_packet->command = DAT;
|
||||||
|
id_packet->length = SIZE_DATA_PACKET_PAYLOAD;
|
||||||
|
snprintf(id_packet->id, SIZE_ID, id, "%s");
|
||||||
|
id_packet->sequence = 0;
|
||||||
|
id_packet->n = 0;
|
||||||
|
snprintf(id_packet->status, SIZE_ID, INTERFACE_VERSION);
|
||||||
|
id_packet->a21 = 1; /* These magic numbers was provided by Les Kerr */
|
||||||
|
id_packet->a22 = 755;
|
||||||
|
id_packet->a23 = 65535;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int prepare_tx (struct data_packet_format *tx_packet, char *id)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
tx_packet->command = DAT;
|
||||||
|
tx_packet->length = SIZE_DATA_PACKET_PAYLOAD;
|
||||||
|
snprintf(tx_packet->id, SIZE_ID, id, "%s");
|
||||||
|
tx_packet->sequence = 0;
|
||||||
|
tx_packet->n = 0;
|
||||||
|
for(i = 1; i < 51; i++)tx_packet->code[i] = 0;
|
||||||
|
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, "?");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
45
src/cwprotocol.h
Normal file
45
src/cwprotocol.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#define INTERFACE_VERSION "irmc v0.02"
|
||||||
|
|
||||||
|
// Structures for the packets: unsigned short command
|
||||||
|
#define DIS 0x0002 // disconnect
|
||||||
|
#define DAT 0x0003
|
||||||
|
#define CON 0x0004 // connect
|
||||||
|
#define ACK 0x0005
|
||||||
|
|
||||||
|
#define SIZE_COMMAND_PACKET 4
|
||||||
|
#define SIZE_DATA_PACKET 496
|
||||||
|
#define SIZE_DATA_PACKET_PAYLOAD 492 // = SIZE_DATA_PACKET - SIZE_COMMAND_PACKET
|
||||||
|
|
||||||
|
#define SIZE_ID 128
|
||||||
|
#define SIZE_STATUS 128
|
||||||
|
#define SIZE_CODE 51
|
||||||
|
|
||||||
|
// This structure will be used to (dis-)connect to KOB servers
|
||||||
|
struct command_packet_format{
|
||||||
|
unsigned short command; // CON / DIS
|
||||||
|
unsigned short channel; // Channel number
|
||||||
|
};
|
||||||
|
|
||||||
|
// This structure will be used for id, rx and tx packets
|
||||||
|
struct data_packet_format{
|
||||||
|
unsigned short command;
|
||||||
|
unsigned short length;
|
||||||
|
char id[SIZE_ID];
|
||||||
|
char a1[4];
|
||||||
|
unsigned int sequence;
|
||||||
|
unsigned int a21;
|
||||||
|
unsigned int a22;
|
||||||
|
unsigned int a23;
|
||||||
|
signed int code[SIZE_CODE];
|
||||||
|
unsigned int n;
|
||||||
|
char status[SIZE_STATUS]; /* This is called version in MorseKob */
|
||||||
|
char a4[8];
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// Define the packets used
|
||||||
|
#define DEFAULT_CHANNEL 103
|
||||||
|
|
||||||
|
|
||||||
|
int prepare_id (struct data_packet_format *id_packet, char *id);
|
||||||
|
int prepare_tx (struct data_packet_format *tx_packet, char *id);
|
@@ -11,60 +11,38 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <soundcard.h>
|
#include <morse/beep.h>
|
||||||
|
#ifdef __MACH__
|
||||||
|
#define LIBOSS_INTERNAL
|
||||||
|
#include <liboss/soundcard.h> //will not be used for audio any more
|
||||||
|
#else
|
||||||
|
#include <linux/ioctl.h>
|
||||||
|
#include <asm-generic/ioctl.h>
|
||||||
|
#include <asm-generic/termios.h>
|
||||||
|
#endif
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include "sound.h"
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#define MAXDATASIZE 1024 // max number of bytes we can get at once
|
#ifdef __MACH__
|
||||||
|
#include <mach/clock.h>
|
||||||
#define DIS 0x0002
|
#include <mach/mach.h>
|
||||||
#define DAT 0x0003
|
#endif
|
||||||
#define CON 0x0004
|
|
||||||
#define ACK 0x0005
|
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
|
||||||
struct command_packet_format{
|
#define MAXDATASIZE 1024 // max number of bytes we can get at once
|
||||||
unsigned short command;
|
|
||||||
unsigned short channel;
|
|
||||||
};
|
|
||||||
struct data_packet_format{
|
|
||||||
unsigned short command;
|
|
||||||
unsigned short length;
|
|
||||||
char id[128];
|
|
||||||
char a1[4];
|
|
||||||
unsigned int sequence;
|
|
||||||
unsigned int a21;
|
|
||||||
unsigned int a22;
|
|
||||||
unsigned int a23;
|
|
||||||
signed int code[51];
|
|
||||||
unsigned int n;
|
|
||||||
char status[128]; /* This is called version in MorseKob */
|
|
||||||
char a4[8];
|
|
||||||
|
|
||||||
};
|
#include "cwprotocol.h"
|
||||||
struct code_packet_format{
|
struct command_packet_format connect_packet = {CON, DEFAULT_CHANNEL};
|
||||||
unsigned short command;
|
|
||||||
unsigned short length;
|
|
||||||
char id[128];
|
|
||||||
char a1[4];
|
|
||||||
unsigned int sequence;
|
|
||||||
unsigned int a21;
|
|
||||||
unsigned int a22;
|
|
||||||
unsigned int a23;
|
|
||||||
signed int code[51];
|
|
||||||
unsigned int n;
|
|
||||||
char a3[128];
|
|
||||||
char a4[8];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct command_packet_format connect_packet;
|
|
||||||
struct command_packet_format disconnect_packet = {DIS, 0};
|
struct command_packet_format disconnect_packet = {DIS, 0};
|
||||||
struct data_packet_format id_packet;
|
struct data_packet_format id_packet;
|
||||||
struct data_packet_format rx_data_packet;
|
struct data_packet_format rx_data_packet;
|
||||||
struct data_packet_format tx_data_packet;
|
struct data_packet_format tx_data_packet;
|
||||||
int serial_status = 0, fd_speaker, fd_serial, fd_socket, numbytes;
|
|
||||||
|
int serial_status = 0, fd_serial, fd_socket, numbytes;
|
||||||
int tx_sequence = 0, rx_sequence;
|
int tx_sequence = 0, rx_sequence;
|
||||||
|
|
||||||
double tx_timeout = 0;
|
double tx_timeout = 0;
|
||||||
@@ -73,7 +51,6 @@ long tx_timer = 0;
|
|||||||
#define TX_TIMEOUT 240.0
|
#define TX_TIMEOUT 240.0
|
||||||
#define KEEPALIVE_CYCLE 100
|
#define KEEPALIVE_CYCLE 100
|
||||||
|
|
||||||
char soundcard[] = "/dev/audio";
|
|
||||||
long key_press_t1;
|
long key_press_t1;
|
||||||
long key_release_t1;
|
long key_release_t1;
|
||||||
int last_message = 0;
|
int last_message = 0;
|
||||||
@@ -83,6 +60,22 @@ char last_sender[16];
|
|||||||
int translate = 0;
|
int translate = 0;
|
||||||
int audio_status = 1;
|
int audio_status = 1;
|
||||||
|
|
||||||
|
/* portable time, as listed in https://gist.github.com/jbenet/1087739 */
|
||||||
|
void current_utc_time(struct timespec *ts) {
|
||||||
|
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
|
||||||
|
clock_serv_t cclock;
|
||||||
|
mach_timespec_t mts;
|
||||||
|
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
|
||||||
|
clock_get_time(cclock, &mts);
|
||||||
|
mach_port_deallocate(mach_task_self(), cclock);
|
||||||
|
ts->tv_sec = mts.tv_sec;
|
||||||
|
ts->tv_nsec = mts.tv_nsec;
|
||||||
|
#else
|
||||||
|
clock_gettime(CLOCK_REALTIME, ts);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* a better clock() in milliseconds */
|
/* a better clock() in milliseconds */
|
||||||
long
|
long
|
||||||
fastclock(void)
|
fastclock(void)
|
||||||
@@ -90,7 +83,7 @@ fastclock(void)
|
|||||||
struct timespec t;
|
struct timespec t;
|
||||||
long r;
|
long r;
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &t);
|
current_utc_time (&t);
|
||||||
r = t.tv_sec * 1000;
|
r = t.tv_sec * 1000;
|
||||||
r = r + t.tv_nsec / 1000000;
|
r = r + t.tv_nsec / 1000000;
|
||||||
return r;
|
return r;
|
||||||
@@ -123,22 +116,23 @@ void *get_in_addr(struct sockaddr *sa)
|
|||||||
return &(((struct sockaddr_in6*)sa)->sin6_addr);
|
return &(((struct sockaddr_in6*)sa)->sin6_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// connect to server and send my id.
|
||||||
void
|
void
|
||||||
identifyclient(void)
|
identifyclient(void)
|
||||||
{
|
{
|
||||||
tx_sequence++;
|
tx_sequence++;
|
||||||
id_packet.sequence = tx_sequence;
|
id_packet.sequence = tx_sequence;
|
||||||
send(fd_socket, &connect_packet, sizeof(connect_packet), 0);
|
send(fd_socket, &connect_packet, SIZE_COMMAND_PACKET, 0);
|
||||||
send(fd_socket, &id_packet, 496, 0);
|
send(fd_socket, &id_packet, SIZE_DATA_PACKET, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// disconnect from the server
|
||||||
void
|
void
|
||||||
inthandler(int sig)
|
inthandler(int sig)
|
||||||
{
|
{
|
||||||
signal(sig, SIG_IGN);
|
signal(sig, SIG_IGN);
|
||||||
send(fd_socket, &disconnect_packet, sizeof(disconnect_packet), 0);
|
send(fd_socket, &disconnect_packet, SIZE_COMMAND_PACKET, 0);
|
||||||
close(fd_socket);
|
close(fd_socket);
|
||||||
close(fd_speaker);
|
|
||||||
close(fd_serial);
|
close(fd_serial);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -169,7 +163,7 @@ txloop (void)
|
|||||||
if(tx_timeout > TX_TIMEOUT) return;
|
if(tx_timeout > TX_TIMEOUT) return;
|
||||||
}
|
}
|
||||||
key_press_t1 = fastclock();
|
key_press_t1 = fastclock();
|
||||||
if(tx_data_packet.n == 50) {
|
if(tx_data_packet.n == SIZE_CODE) {
|
||||||
printf("irmc: warning packet is full.\n");
|
printf("irmc: warning packet is full.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -195,7 +189,7 @@ commandmode(void)
|
|||||||
tx_data_packet.code[0] = -1;
|
tx_data_packet.code[0] = -1;
|
||||||
tx_data_packet.code[1] = 1;
|
tx_data_packet.code[1] = 1;
|
||||||
tx_data_packet.n = 2;
|
tx_data_packet.n = 2;
|
||||||
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, 496, 0);
|
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
|
||||||
tx_data_packet.n = 0;
|
tx_data_packet.n = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -206,7 +200,7 @@ commandmode(void)
|
|||||||
tx_data_packet.code[0] = -1;
|
tx_data_packet.code[0] = -1;
|
||||||
tx_data_packet.code[1] = 2;
|
tx_data_packet.code[1] = 2;
|
||||||
tx_data_packet.n = 2;
|
tx_data_packet.n = 2;
|
||||||
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, 496, 0);
|
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
|
||||||
tx_data_packet.n = 0;
|
tx_data_packet.n = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -221,12 +215,10 @@ commandmode(void)
|
|||||||
|
|
||||||
if((strncmp(cmd, "aon", 3)) == 0){
|
if((strncmp(cmd, "aon", 3)) == 0){
|
||||||
audio_status = 1;
|
audio_status = 1;
|
||||||
fd_speaker = open_audio_device(soundcard, O_WRONLY);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if((strncmp(cmd, "aoff", 3)) == 0){
|
if((strncmp(cmd, "aoff", 3)) == 0){
|
||||||
audio_status = 0;
|
audio_status = 0;
|
||||||
close(fd_speaker);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
printf("?\n");
|
printf("?\n");
|
||||||
@@ -275,47 +267,61 @@ int main(int argc, char *argv[])
|
|||||||
char hostname[64];
|
char hostname[64];
|
||||||
char port[16];
|
char port[16];
|
||||||
int channel;
|
int channel;
|
||||||
char id[128];
|
char id[SIZE_ID];
|
||||||
char serialport[64];
|
char serialport[64];
|
||||||
|
|
||||||
|
// Set default values
|
||||||
|
snprintf(hostname, 64, "mtc-kob.dyndns.org");
|
||||||
|
snprintf(port, 16, "7890");
|
||||||
|
channel = 103;
|
||||||
|
snprintf(id, SIZE_ID, "irmc-default");
|
||||||
|
snprintf(serialport, 64, "/dev/tty.usbserial");
|
||||||
|
|
||||||
if (argc < 4) {
|
// Read commandline
|
||||||
fprintf(stderr," %i usage: irmc [hostname] [port] [channel] [id] [serialport]\n", argc);
|
opterr = 0;
|
||||||
exit(1);
|
int c;
|
||||||
|
while ((c = getopt (argc, argv, "h:p:c:i:s:")) != -1)
|
||||||
|
{
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case 'h':
|
||||||
|
snprintf(hostname, 64, "%s", optarg);
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
snprintf(port, 16, "%s", optarg);
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
channel = atoi (optarg);
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
snprintf(id, SIZE_ID, "%s", optarg);
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
snprintf(serialport, 64, "%s", optarg);
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
fprintf(stderr, "irmc - Internet Relay Morse Code\n\n");
|
||||||
|
fprintf(stderr, "usage: irmc [arguments]\n\n");
|
||||||
|
fprintf(stderr, "Arguments:\n\n");
|
||||||
|
fprintf(stderr, " -h [hostname] Hostname of morsekob server. Default: %s\n", hostname);
|
||||||
|
fprintf(stderr, " -p [port] Port of morsekob server. Default: %s\n", port);
|
||||||
|
fprintf(stderr, " -c [channel] Channel. Default: %d\n", channel);
|
||||||
|
fprintf(stderr, " -i [id] My ID. Default: %s\n", id);
|
||||||
|
fprintf(stderr, " -s [serialport] Serial port device name. Default: %s\n", serialport);
|
||||||
|
return 1;
|
||||||
|
default:
|
||||||
|
abort ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(hostname, 64, argv[1], "%s");
|
// Preparing connection
|
||||||
snprintf(port, 16, argv[2], "%s");
|
fprintf(stderr, "irmc - Internet Relay Morse Code\n\n");
|
||||||
channel = atoi(argv[3]);
|
fprintf(stderr, "Connecting to %s:%s on channel %d with ID %s.\n", hostname, port, channel, id);
|
||||||
if(argc > 4) snprintf(id, 128, argv[4], "%s");
|
|
||||||
else snprintf(id, 128, "irmc");
|
|
||||||
if(argc > 5) snprintf(serialport, 64, argv[5], "%s");
|
|
||||||
|
|
||||||
id_packet.command = DAT;
|
prepare_id (&id_packet, id);
|
||||||
id_packet.length = 492;
|
prepare_tx (&tx_data_packet, id);
|
||||||
snprintf(id_packet.id, 128, id, "%s");
|
|
||||||
id_packet.sequence = 0;
|
|
||||||
id_packet.n = 0;
|
|
||||||
snprintf(id_packet.status, 128, "irmc v0.02");
|
|
||||||
id_packet.a21 = 1; /* These magic numbers was provided by Les Kerr */
|
|
||||||
id_packet.a22 = 755;
|
|
||||||
id_packet.a23 = 65535;
|
|
||||||
|
|
||||||
tx_data_packet.command = DAT;
|
|
||||||
tx_data_packet.length = 492;
|
|
||||||
snprintf(tx_data_packet.id, 128, id, "%s");
|
|
||||||
tx_data_packet.sequence = 0;
|
|
||||||
tx_data_packet.n = 0;
|
|
||||||
for(i = 1; i < 51; i++)tx_data_packet.code[i] = 0;
|
|
||||||
tx_data_packet.a21 = 0; /* These magic numbers was provided by Les Kerr */
|
|
||||||
tx_data_packet.a22 = 755;
|
|
||||||
tx_data_packet.a23 = 16777215;
|
|
||||||
snprintf(tx_data_packet.status, 128, "?");
|
|
||||||
|
|
||||||
connect_packet.command = CON;
|
|
||||||
connect_packet.channel = channel;
|
connect_packet.channel = channel;
|
||||||
|
|
||||||
|
|
||||||
signal(SIGINT, inthandler);
|
signal(SIGINT, inthandler);
|
||||||
|
|
||||||
memset(&hints, 0, sizeof hints);
|
memset(&hints, 0, sizeof hints);
|
||||||
@@ -347,22 +353,21 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
fcntl(fd_socket, F_SETFL, O_NONBLOCK);
|
fcntl(fd_socket, F_SETFL, O_NONBLOCK);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
fprintf(stderr, "irmc: failed to connect\n");
|
fprintf(stderr, "Failed to connect.\n");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
|
inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
|
||||||
s, sizeof s);
|
s, sizeof s);
|
||||||
printf("irmc: connected to %s\n", s);
|
fprintf(stderr, "Connected to %s.\n", s);
|
||||||
fd_speaker = open_audio_device(soundcard, O_WRONLY);
|
beep_init();
|
||||||
fd_serial = open(serialport, O_RDWR | O_NOCTTY | O_NDELAY);
|
fd_serial = open(serialport, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||||
if(fd_serial == -1) {
|
if(fd_serial == -1) {
|
||||||
printf("irmc: unable to open serial port.\n");
|
fprintf(stderr,"Unable to open serial port %s.\n", serialport);
|
||||||
}
|
}
|
||||||
freeaddrinfo(servinfo); /* all done with this structure */
|
freeaddrinfo(servinfo); /* all done with this structure */
|
||||||
|
|
||||||
key_release_t1 = fastclock();
|
key_release_t1 = fastclock();
|
||||||
init_sound();
|
|
||||||
identifyclient();
|
identifyclient();
|
||||||
|
|
||||||
/* Main Loop */
|
/* Main Loop */
|
||||||
@@ -370,8 +375,8 @@ int main(int argc, char *argv[])
|
|||||||
if(tx_timer == 0)
|
if(tx_timer == 0)
|
||||||
if((numbytes = recv(fd_socket, buf, MAXDATASIZE-1, 0)) == -1)
|
if((numbytes = recv(fd_socket, buf, MAXDATASIZE-1, 0)) == -1)
|
||||||
usleep(250);
|
usleep(250);
|
||||||
if(numbytes == 496 && tx_timer == 0){
|
if(numbytes == SIZE_DATA_PACKET && tx_timer == 0){
|
||||||
memcpy(&rx_data_packet, buf, 496);
|
memcpy(&rx_data_packet, buf, SIZE_DATA_PACKET);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
printf("length: %i\n", rx_data_packet.length);
|
printf("length: %i\n", rx_data_packet.length);
|
||||||
printf("id: %s\n", rx_data_packet.id);
|
printf("id: %s\n", rx_data_packet.id);
|
||||||
@@ -379,7 +384,7 @@ int main(int argc, char *argv[])
|
|||||||
printf("version: %s\n", rx_data_packet.status);
|
printf("version: %s\n", rx_data_packet.status);
|
||||||
printf("n: %i\n", rx_data_packet.n);
|
printf("n: %i\n", rx_data_packet.n);
|
||||||
printf("code:\n");
|
printf("code:\n");
|
||||||
for(i = 0; i < 51; i++)printf("%i ", rx_data_packet.code[i]); printf("\n");
|
for(i = 0; i < SIZE_CODE; i++)printf("%i ", rx_data_packet.code[i]); printf("\n");
|
||||||
#endif
|
#endif
|
||||||
if(rx_data_packet.n > 0 && rx_sequence != rx_data_packet.sequence){
|
if(rx_data_packet.n > 0 && rx_sequence != rx_data_packet.sequence){
|
||||||
message(2);
|
message(2);
|
||||||
@@ -398,7 +403,22 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if(audio_status == 1)
|
if(audio_status == 1)
|
||||||
play_code_element (rx_data_packet.code[i]);
|
{
|
||||||
|
|
||||||
|
int length = rx_data_packet.code[i];
|
||||||
|
if(length == 0 || abs(length) > 2000) {
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(length < 0) {
|
||||||
|
beep(0.0, abs(length)/1000.);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
beep(1000.0, length/1000.);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -409,7 +429,7 @@ int main(int argc, char *argv[])
|
|||||||
if(tx_data_packet.n > 1 ){
|
if(tx_data_packet.n > 1 ){
|
||||||
tx_sequence++;
|
tx_sequence++;
|
||||||
tx_data_packet.sequence = tx_sequence;
|
tx_data_packet.sequence = tx_sequence;
|
||||||
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, 496, 0);
|
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
printf("irmc: sent data packet.\n");
|
printf("irmc: sent data packet.\n");
|
||||||
#endif
|
#endif
|
||||||
@@ -440,9 +460,8 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
} /* End of mainloop */
|
} /* End of mainloop */
|
||||||
|
|
||||||
send(fd_socket, &disconnect_packet, sizeof(disconnect_packet), 0);
|
send(fd_socket, &disconnect_packet, SIZE_COMMAND_PACKET, 0);
|
||||||
close(fd_socket);
|
close(fd_socket);
|
||||||
close(fd_speaker);
|
|
||||||
close(fd_serial);
|
close(fd_serial);
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
BIN
src/test/MorseKOB.jar
Executable file
BIN
src/test/MorseKOB.jar
Executable file
Binary file not shown.
Reference in New Issue
Block a user