Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
0252a2803b | ||
|
2445a111f3 | ||
|
d91a7b2a29 | ||
|
910b60eb37 | ||
|
8f7648f7f6 | ||
|
7b8e7a5e18 | ||
|
405634e645 | ||
|
ba4e67f0a4 | ||
|
36fa067cc5 | ||
|
c464cc7dcb | ||
|
5295c33b74 | ||
|
b3bed56197 |
@@ -1,8 +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).
|
||||
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
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 33 KiB |
BIN
lib/morse-0.1.tar.gz
Normal file
BIN
lib/morse-0.1.tar.gz
Normal file
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
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
|
||||
|
||||
|
178
src/beep.h
Normal file
178
src/beep.h
Normal 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;
|
||||
}
|
@@ -40,6 +40,6 @@ struct data_packet_format{
|
||||
// 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);
|
||||
|
||||
|
165
src/irmc.c
165
src/irmc.c
@@ -9,33 +9,39 @@
|
||||
#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
|
||||
|
||||
#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 0
|
||||
//#define DEBUG 1
|
||||
|
||||
#define MAXDATASIZE 1024 // max number of bytes we can get at once
|
||||
|
||||
#include "cwprotocol.h"
|
||||
|
||||
struct command_packet_format connect_packet = {CON, DEFAULT_CHANNEL};
|
||||
struct command_packet_format disconnect_packet = {DIS, 0};
|
||||
struct data_packet_format id_packet;
|
||||
@@ -51,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 */
|
||||
@@ -77,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;
|
||||
@@ -102,7 +112,6 @@ int kbhit (void)
|
||||
|
||||
select (STDIN_FILENO+1, &rdfs, NULL, NULL, &tv);
|
||||
return FD_ISSET(STDIN_FILENO, &rdfs);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -117,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;
|
||||
@@ -127,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);
|
||||
@@ -137,8 +144,7 @@ inthandler(int sig)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
txloop (void)
|
||||
void txloop (void)
|
||||
{
|
||||
key_press_t1 = fastclock();
|
||||
tx_timeout = 0;
|
||||
@@ -170,64 +176,33 @@ txloop (void)
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
tx_data_packet.n = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if((strncmp(cmd, "unlatch", 3)) == 0){
|
||||
tx_sequence++;
|
||||
tx_data_packet.sequence = tx_sequence;
|
||||
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);
|
||||
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");
|
||||
tx_sequence++;
|
||||
tx_data_packet.sequence = tx_sequence;
|
||||
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);
|
||||
tx_data_packet.n = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int send_unlatch (void)
|
||||
{
|
||||
int i;
|
||||
tx_sequence++;
|
||||
tx_data_packet.sequence = tx_sequence;
|
||||
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);
|
||||
tx_data_packet.n = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
message(int msg)
|
||||
void message(int msg)
|
||||
{
|
||||
switch(msg){
|
||||
case 1:
|
||||
@@ -256,7 +231,9 @@ message(int msg)
|
||||
}
|
||||
fflush(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Main Loop */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char buf[MAXDATASIZE];
|
||||
@@ -269,13 +246,14 @@ 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");
|
||||
snprintf(port, 16, "7890");
|
||||
channel = 103;
|
||||
snprintf(id, SIZE_ID, "irmc-default");
|
||||
snprintf(serialport, 64, "/dev/tty.usbserial");
|
||||
snprintf(serialport, 64, "");
|
||||
|
||||
// Read commandline
|
||||
opterr = 0;
|
||||
@@ -307,7 +285,7 @@ int main(int argc, char *argv[])
|
||||
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);
|
||||
fprintf(stderr, " -s [serialport] Serial port device name. Example: /dev/tty.usbserial Default: \"%s\"\n", serialport);
|
||||
return 1;
|
||||
default:
|
||||
abort ();
|
||||
@@ -350,7 +328,6 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
fcntl(fd_socket, F_SETFL, O_NONBLOCK);
|
||||
if (p == NULL) {
|
||||
fprintf(stderr, "Failed to connect.\n");
|
||||
@@ -361,10 +338,15 @@ int main(int argc, char *argv[])
|
||||
s, sizeof s);
|
||||
fprintf(stderr, "Connected to %s.\n", s);
|
||||
beep_init();
|
||||
fd_serial = open(serialport, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
if(fd_serial == -1) {
|
||||
fprintf(stderr,"Unable to open serial port %s.\n", serialport);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
freeaddrinfo(servinfo); /* all done with this structure */
|
||||
|
||||
key_release_t1 = fastclock();
|
||||
@@ -377,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);
|
||||
@@ -386,6 +369,7 @@ int main(int argc, char *argv[])
|
||||
printf("code:\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){
|
||||
@@ -435,11 +419,13 @@ int main(int argc, char *argv[])
|
||||
#endif
|
||||
tx_data_packet.n = 0;
|
||||
}
|
||||
ioctl(fd_serial,TIOCMGET, &serial_status);
|
||||
if(serial_status & TIOCM_DSR){
|
||||
txloop();
|
||||
tx_timer = TX_WAIT;
|
||||
message(1);
|
||||
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){
|
||||
@@ -456,7 +442,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
if(kbhit() && tx_timer == 0){
|
||||
getchar(); /* flush the buffer */
|
||||
if(commandmode()== 1)break;
|
||||
}
|
||||
} /* End of mainloop */
|
||||
|
||||
|
Reference in New Issue
Block a user