54 Commits

Author SHA1 Message Date
Gerolf Ziegenhain
0252a2803b wip 2016-09-24 16:34:20 +02:00
Gerolf Ziegenhain
2445a111f3 sort headers 2016-09-24 16:28:30 +02:00
Gerolf Ziegenhain
d91a7b2a29 wip 2016-09-24 16:21:29 +02:00
Gerolf Ziegenhain
910b60eb37 rm commandmode 2016-09-24 15:59:41 +02:00
Gerolf Ziegenhain
8f7648f7f6 redo commandmode 2016-09-24 15:58:47 +02:00
Gerolf Ziegenhain
7b8e7a5e18 add morse lib 2016-09-23 22:33:19 +02:00
Gerolf Ziegenhain
405634e645 rm osx dir 2016-09-23 22:32:24 +02:00
Gerolf Ziegenhain
ba4e67f0a4 add paex_sine.c 2015-07-08 23:24:41 +02:00
Gerolf Ziegenhain
36fa067cc5 cleanup 2015-07-08 22:38:29 +02:00
Gerolf Ziegenhain
c464cc7dcb moip hp 2015-07-08 21:42:28 +02:00
Gerolf Ziegenhain
5295c33b74 add reference to moip website 2015-07-08 21:41:53 +02:00
Gerolf Ziegenhain
b3bed56197 rm old screenshot 2015-07-08 21:40:30 +02:00
Gerolf Ziegenhain
a4eed20392 pins 2015-07-08 21:38:58 +02:00
Gerolf Ziegenhain
51528cd34b table 2015-07-08 21:37:48 +02:00
Gerolf Ziegenhain
c37c2b4a0d table 2015-07-08 21:37:29 +02:00
Gerolf Ziegenhain
594bb6006f table 2015-07-08 21:35:25 +02:00
Gerolf Ziegenhain
2d99d0deba table 2015-07-08 21:34:26 +02:00
Gerolf Ziegenhain
49a033f9a3 version description 2015-07-08 21:33:02 +02:00
Gerolf Ziegenhain
79b9ab5dc1 commandline options 2015-07-08 21:06:39 +02:00
Gerolf Ziegenhain
a8b5ad29b7 Merge branch 'master' into dev 2015-07-07 22:45:46 +02:00
Gerolf Ziegenhain
a8468dbe42 exclude obj 2015-07-07 22:45:38 +02:00
Gerolf Ziegenhain
d2254a907b merged code cleanup 2015-07-07 22:44:21 +02:00
Gerolf Ziegenhain
cc3bf0ae5a typo 2015-07-07 19:54:19 +02:00
Gerolf Ziegenhain
7305e8a723 add osx screenshot 2015-04-29 21:36:28 +02:00
Gerolf Ziegenhain
aa596c0c66 add screenshot on osx 2015-04-29 21:35:08 +02:00
Gerolf Ziegenhain
2d8ca13a22 rm old posting 2015-03-04 20:10:57 +01:00
Gerolf Ziegenhain
f05f4ae2f7 add pins 2015-02-16 21:32:13 +01:00
Gerolf Ziegenhain
2f88687332 added test cases 2015-02-16 21:00:42 +01:00
Gerolf Ziegenhain
fbd96d2495 doc 2015-02-16 18:39:55 +01:00
Gerolf Ziegenhain
67acd163b6 wip 2015-02-15 13:11:40 +01:00
Gerolf Ziegenhain
2c71fe456d add doc by Les Kerr 2015-02-15 11:45:47 +01:00
Gerolf Ziegenhain
e4a61ba4a9 code quality warning 2015-02-15 09:27:13 +01:00
Gerolf Ziegenhain
251fa57b32 add java morsekob for testing 2015-02-07 21:23:58 +01:00
Gerolf Ziegenhain
b075427a3c more information on ext. hw 2015-02-07 21:21:33 +01:00
Gerolf Ziegenhain
77dc0cf117 formatting 2015-02-07 20:54:54 +01:00
Gerolf Ziegenhain
9319409282 wip 2015-02-03 23:29:32 +01:00
Gerolf Ziegenhain
572c6d93ac added jar for testing 2015-02-03 23:20:40 +01:00
Gerolf Ziegenhain
dd0881a5d4 added wikipedia section 2015-02-03 22:47:12 +01:00
Gerolf Ziegenhain
d73eb66b99 network trace for debug 2015-01-06 00:18:10 +01:00
Gerolf Ziegenhain
ae779dc2f5 magic numbers 2015-01-04 15:32:43 +01:00
Gerolf Ziegenhain
f028280963 cleanup 2015-01-04 15:29:26 +01:00
Gerolf Ziegenhain
765cb854ed initialization of packets 2015-01-04 15:26:52 +01:00
Gerolf Ziegenhain
12f2d905ce started separating protocol. 2015-01-04 15:02:18 +01:00
Gerolf Ziegenhain
1140c99193 started separating protocol. 2015-01-04 15:02:03 +01:00
Gerolf Ziegenhain
272d03cbc8 merged from master 2015-01-04 14:44:17 +01:00
Gerolf Ziegenhain
d2f8a0b65f merged from master 2015-01-04 14:43:50 +01:00
Gerolf Ziegenhain
87dbb05d3e merged from master 2015-01-04 14:43:28 +01:00
Gerolf Ziegenhain
9599bae5a8 merged from master 2015-01-04 14:43:06 +01:00
Gerolf Ziegenhain
adeba195f6 merged makefiles 2015-01-03 23:00:47 +01:00
Gerolf Ziegenhain
0424b7e2d3 removed obsolete files 2015-01-03 22:59:08 +01:00
Gerolf Ziegenhain
87f8437b87 modified for wheezy - without sound.c 2015-01-03 22:58:48 +01:00
Gerolf Ziegenhain
ecce799bb7 add osx build 2015-01-03 22:45:02 +01:00
Gerolf Ziegenhain
a4bbec6497 osx port 2015-01-03 22:38:23 +01:00
Gerolf Ziegenhain
325d794b7c compile instructions debian 2015-01-03 22:36:21 +01:00
10 changed files with 416 additions and 213 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
.DS_Store
irmc
*.o

View File

@@ -1,13 +1,6 @@
irmc - Internet Relay Morse Code
================================
IRMC stands for Internet Relay Morse Code and is an implementation of [MOIP](https://github.com/8cH9azbsFifZ/moip).
It implements the [CWCom protocol](http://kob.sdf.org/morsekob/docs/cwcom.pdf)
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.
![Screenshot on OSX](/doc/screenshot.png?raw=true "Screenshot")
IRMC stands for Internet Relay Morse Code and is an implementation of [MOIP](http://8ch9azbsfifz.github.io/moip/).
# How to build?
## Install dependency: morse keyer library
@@ -39,50 +32,29 @@ Compilation with make :)
For the USB serial devices you need a PL2303 driver
(i.e. [PL2303_Serial-USB_on_OSX_Lion.pkg](http://changux.co/osx-installer-to-pl2303-serial-usb-on-osx-lio/)).
## Testing
./irmc morsecode.dyndns.org 7890 2348 test
Or you may want to use tcpdump, i.e.:
```
sudo tcpdump -i all -vvvv "host faeroes.sdf.org"
```
# How to use:
The usage is: `irmc [hostname] [port] [channel] [id] [serialport`
For example:
`./irmc mtc-kob.dyndns.org 7890 103 MyID /dev/tty.usbserial´
## Hardware interface options
# 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
| 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.3 [zip](https://github.com/8cH9azbsFifZ/irmc/archive/v0.3.zip) - commandline option cleanup
* 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.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

BIN
lib/morse-0.1.tar.gz Normal file

Binary file not shown.

View File

@@ -1,6 +1,6 @@
SRC = irmc.c
SRC = irmc.c cwprotocol.c
OBJ = ${SRC:.c=.o}
LDFLAGS = -L/usr/local/lib -L/opt/local/lib -lm -lmorse
LDFLAGS = -L/usr/local/lib -L/opt/local/lib -lportaudio -lpthread -lm -lmorse
CFLAGS = -I/usr/local/include -I/opt/local/include -Wall
INSTALLDIR = ${HOME}/bin
@@ -21,9 +21,8 @@ irmc: ${OBJ}
@echo CC -o $@
@${CC} -o $@ ${OBJ} ${LDFLAGS}
hex: ${OBJ}
@echo avr-gcc -o $@
avr-gcc -o $@ ${OBJ} ${LDFLAGS}
java:
java -jar test/MorseKOB.jar
clean:
@echo cleaning

178
src/beep.h Normal file
View File

@@ -0,0 +1,178 @@
/** @file paex_sine.c
@ingroup examples_src
@brief Play a sine wave for several seconds.
@author Ross Bencina <rossb@audiomulch.com>
@author Phil Burk <philburk@softsynth.com>
*/
/*
* $Id$
*
* This program uses the PortAudio Portable Audio Library.
* For more information see: http://www.portaudio.com/
* Copyright (c) 1999-2000 Ross Bencina and Phil Burk
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* The text above constitutes the entire PortAudio license; however,
* the PortAudio community also makes the following non-binding requests:
*
* Any person wishing to distribute modifications to the Software is
* requested to send the modifications to the original developer so that
* they can be incorporated into the canonical version. It is also
* requested that these non-binding requests be included along with the
* license above.
*/
#include <stdio.h>
#include <math.h>
#include "portaudio.h"
#define NUM_SECONDS (5)
#define SAMPLE_RATE (44100)
#define FRAMES_PER_BUFFER (64)
#ifndef M_PI
#define M_PI (3.14159265)
#endif
#define TABLE_SIZE (200)
typedef struct
{
float sine[TABLE_SIZE];
int left_phase;
int right_phase;
char message[20];
}
paTestData;
/* This routine will be called by the PortAudio engine when audio is needed.
** It may called at interrupt level on some machines so don't do anything
** that could mess up the system like calling malloc() or free().
*/
static int patestCallback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData )
{
paTestData *data = (paTestData*)userData;
float *out = (float*)outputBuffer;
unsigned long i;
(void) timeInfo; /* Prevent unused variable warnings. */
(void) statusFlags;
(void) inputBuffer;
for( i=0; i<framesPerBuffer; i++ )
{
*out++ = data->sine[data->left_phase]; /* left */
*out++ = data->sine[data->right_phase]; /* right */
data->left_phase += 1;
if( data->left_phase >= TABLE_SIZE ) data->left_phase -= TABLE_SIZE;
data->right_phase += 3; /* higher pitch so we can distinguish left and right. */
if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE;
}
return paContinue;
}
/*
* This routine is called by portaudio when playback is done.
*/
static void StreamFinished( void* userData )
{
paTestData *data = (paTestData *) userData;
printf( "Stream Completed: %s\n", data->message );
}
/*******************************************************************/
void beep_init(void);
int beep(double freq_hz, double duration_sec)
{
PaStreamParameters outputParameters;
PaStream *stream;
PaError err;
paTestData data;
int i;
printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER);
/* initialise sinusoidal wavetable */
for( i=0; i<TABLE_SIZE; i++ )
{
data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. );
}
data.left_phase = data.right_phase = 0;
err = Pa_Initialize();
if( err != paNoError ) goto error;
outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
if (outputParameters.device == paNoDevice) {
fprintf(stderr,"Error: No default output device.\n");
goto error;
}
outputParameters.channelCount = 2; /* stereo output */
outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;
err = Pa_OpenStream(
&stream,
NULL, /* no input */
&outputParameters,
SAMPLE_RATE,
FRAMES_PER_BUFFER,
paClipOff, /* we won't output out of range samples so don't bother clipping them */
patestCallback,
&data );
if( err != paNoError ) goto error;
sprintf( data.message, "No Message" );
err = Pa_SetStreamFinishedCallback( stream, &StreamFinished );
if( err != paNoError ) goto error;
err = Pa_StartStream( stream );
if( err != paNoError ) goto error;
printf("Play for %d seconds.\n", NUM_SECONDS );
Pa_Sleep( duration_sec * 1000 );
err = Pa_StopStream( stream );
if( err != paNoError ) goto error;
err = Pa_CloseStream( stream );
if( err != paNoError ) goto error;
Pa_Terminate();
printf("Test finished.\n");
return err;
error:
Pa_Terminate();
fprintf( stderr, "An error occured while using the portaudio stream\n" );
fprintf( stderr, "Error number: %d\n", err );
fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
return err;
}

36
src/cwprotocol.c Normal file
View 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
View 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);

View File

@@ -9,68 +9,45 @@
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <math.h>
#include <fcntl.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 <pthread.h>
#include <signal.h>
#include <arpa/inet.h>
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#define BEEP_MORSE
#ifdef BEEP_MORSE
#include <morse/beep.h>
#else
#include "portaudio.h"
#endif
#define DEBUG 0
#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#else
#include <linux/ioctl.h>
#include <asm-generic/ioctl.h>
#include <asm-generic/termios.h>
#endif
//#define DEBUG 1
#define MAXDATASIZE 1024 // max number of bytes we can get at once
// Structures for the packets: unsigned short command
#define DIS 0x0002 // disconnect
#define DAT 0x0003
#define CON 0x0004 // connect
#define ACK 0x0005
#include "cwprotocol.h"
// 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
};
#define SIZE_COMMAND_PACKET 4
// This structure will be used for id, rx and tx packets
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];
};
#define SIZE_DATA_PACKET 496
struct command_packet_format connect_packet;
struct command_packet_format connect_packet = {CON, DEFAULT_CHANNEL};
struct command_packet_format disconnect_packet = {DIS, 0};
struct data_packet_format id_packet;
struct data_packet_format rx_data_packet;
struct data_packet_format tx_data_packet;
int serial_status = 0, fd_serial, fd_socket, numbytes;
int tx_sequence = 0, rx_sequence;
@@ -80,13 +57,18 @@ long tx_timer = 0;
#define TX_TIMEOUT 240.0
#define KEEPALIVE_CYCLE 100
/* TX Methods */
#define TX_NONE 0
#define TX_SERIAL 1
#define TX_KEYBOARD 2
long key_press_t1;
long key_release_t1;
int last_message = 0;
char last_sender[16];
/* settings */
int translate = 0;
int translate = 1;
int audio_status = 1;
/* portable time, as listed in https://gist.github.com/jbenet/1087739 */
@@ -106,8 +88,7 @@ void current_utc_time(struct timespec *ts) {
}
/* a better clock() in milliseconds */
long
fastclock(void)
long fastclock(void)
{
struct timespec t;
long r;
@@ -131,7 +112,6 @@ int kbhit (void)
select (STDIN_FILENO+1, &rdfs, NULL, NULL, &tv);
return FD_ISSET(STDIN_FILENO, &rdfs);
}
@@ -146,8 +126,7 @@ void *get_in_addr(struct sockaddr *sa)
}
// connect to server and send my id.
void
identifyclient(void)
void identifyclient(void)
{
tx_sequence++;
id_packet.sequence = tx_sequence;
@@ -156,8 +135,7 @@ identifyclient(void)
}
// disconnect from the server
void
inthandler(int sig)
void inthandler(int sig)
{
signal(sig, SIG_IGN);
send(fd_socket, &disconnect_packet, SIZE_COMMAND_PACKET, 0);
@@ -166,8 +144,7 @@ inthandler(int sig)
exit(1);
}
void
txloop (void)
void txloop (void)
{
key_press_t1 = fastclock();
tx_timeout = 0;
@@ -192,27 +169,16 @@ txloop (void)
if(tx_timeout > TX_TIMEOUT) return;
}
key_press_t1 = fastclock();
if(tx_data_packet.n == 50) {
if(tx_data_packet.n == SIZE_CODE) {
printf("irmc: warning packet is full.\n");
return;
}
}
}
int
commandmode(void)
int send_latch (void)
{
char cmd[32];
int i;
last_message = 0; /* reset status message */
printf(".");
fgets(cmd, 32, stdin);
if(strncmp(cmd, ".", 1) == 0){
printf("\n");
return 1;
}
if((strncmp(cmd, "latch", 3)) == 0){
tx_sequence++;
tx_data_packet.sequence = tx_sequence;
tx_data_packet.code[0] = -1;
@@ -221,9 +187,11 @@ commandmode(void)
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
tx_data_packet.n = 0;
return 0;
}
}
if((strncmp(cmd, "unlatch", 3)) == 0){
int send_unlatch (void)
{
int i;
tx_sequence++;
tx_data_packet.sequence = tx_sequence;
tx_data_packet.code[0] = -1;
@@ -232,31 +200,9 @@ commandmode(void)
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
tx_data_packet.n = 0;
return 0;
}
if((strncmp(cmd, "ton", 3)) == 0){
translate = 1;
return 0;
}
if((strncmp(cmd, "toff", 3)) == 0){
translate = 0;
return 0;
}
if((strncmp(cmd, "aon", 3)) == 0){
audio_status = 1;
return 0;
}
if((strncmp(cmd, "aoff", 3)) == 0){
audio_status = 0;
return 0;
}
printf("?\n");
return 0;
}
void
message(int msg)
void message(int msg)
{
switch(msg){
case 1:
@@ -286,6 +232,8 @@ message(int msg)
fflush(0);
}
/* Main Loop */
int main(int argc, char *argv[])
{
char buf[MAXDATASIZE];
@@ -296,46 +244,62 @@ int main(int argc, char *argv[])
char hostname[64];
char port[16];
int channel;
char id[128];
char id[SIZE_ID];
char serialport[64];
int tx_method = TX_NONE;
if (argc < 4) {
fprintf(stderr," %i usage: irmc [hostname] [port] [channel] [id] [serialport]\n", argc);
exit(1);
// 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, "");
// Read commandline
opterr = 0;
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. Example: /dev/tty.usbserial Default: \"%s\"\n", serialport);
return 1;
default:
abort ();
}
}
snprintf(hostname, 64, argv[1], "%s");
snprintf(port, 16, argv[2], "%s");
channel = atoi(argv[3]);
if(argc > 4) snprintf(id, 128, argv[4], "%s");
else snprintf(id, 128, "irmc");
if(argc > 5) snprintf(serialport, 64, argv[5], "%s");
// Preparing connection
fprintf(stderr, "irmc - Internet Relay Morse Code\n\n");
fprintf(stderr, "Connecting to %s:%s on channel %d with ID %s.\n", hostname, port, channel, id);
id_packet.command = DAT;
id_packet.length = 492;
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;
prepare_id (&id_packet, id);
prepare_tx (&tx_data_packet, id);
connect_packet.channel = channel;
signal(SIGINT, inthandler);
memset(&hints, 0, sizeof hints);
@@ -364,20 +328,24 @@ int main(int argc, char *argv[])
break;
}
fcntl(fd_socket, F_SETFL, O_NONBLOCK);
if (p == NULL) {
fprintf(stderr, "irmc: failed to connect\n");
fprintf(stderr, "Failed to connect.\n");
return 2;
}
inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
s, sizeof s);
printf("irmc: connected to %s\n", 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) {
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 */
@@ -391,6 +359,7 @@ int main(int argc, char *argv[])
usleep(250);
if(numbytes == SIZE_DATA_PACKET && tx_timer == 0){
memcpy(&rx_data_packet, buf, SIZE_DATA_PACKET);
#if DEBUG
printf("length: %i\n", rx_data_packet.length);
printf("id: %s\n", rx_data_packet.id);
@@ -398,8 +367,9 @@ int main(int argc, char *argv[])
printf("version: %s\n", rx_data_packet.status);
printf("n: %i\n", rx_data_packet.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
if(rx_data_packet.n > 0 && rx_sequence != rx_data_packet.sequence){
message(2);
if(translate == 1){
@@ -419,19 +389,19 @@ int main(int argc, char *argv[])
if(audio_status == 1)
{
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.);
}
}
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;
}
@@ -449,12 +419,14 @@ beep(1000.0, length/1000.);
#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);
}
}
if(keepalive_t < 0 && tx_timer == 0){
#if DEBUG
@@ -470,7 +442,6 @@ beep(1000.0, length/1000.);
if(kbhit() && tx_timer == 0){
getchar(); /* flush the buffer */
if(commandmode()== 1)break;
}
} /* End of mainloop */

BIN
src/test/MorseKOB.jar Executable file

Binary file not shown.