Compare commits
128 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2c2ff2d2ed | ||
|
4c7442e3ea | ||
|
2c7de4792d | ||
|
496aa90bfe | ||
|
827798b86b | ||
|
5f9609ce0c | ||
|
75c77b0cac | ||
|
7bf9183401 | ||
|
746b1dcfe5 | ||
|
63300fa955 | ||
|
a43019e565 | ||
|
370858ce8e | ||
|
a62c28dcdf | ||
|
d8815db878 | ||
|
d6d0679fb5 | ||
|
9d28c29a51 | ||
|
5d1ea8138b | ||
|
af81f9a084 | ||
|
1145e2769e | ||
|
516c1b4a57 | ||
|
1db2782667 | ||
|
ba6ece9ddd | ||
|
4f9169d026 | ||
|
e36b01ce41 | ||
|
efeee5b0ee | ||
|
e01c86a248 | ||
|
6163a138ce | ||
|
5dad7c3f64 | ||
|
8622552f86 | ||
|
1d3b674ecc | ||
|
81316638fc | ||
|
83d152c2bc | ||
|
fddeaab8ed | ||
|
197ac3224e | ||
|
7ead5be229 | ||
|
46842ab42b | ||
|
86e7cc039b | ||
|
5e586d03d9 | ||
|
bf0ebc9f6e | ||
|
8da5cc22d6 | ||
|
ff773f1f4e | ||
|
05ad58cb09 | ||
|
08423de98c | ||
|
a9371e16d4 | ||
|
57f6c84f88 | ||
|
15ab7fbbcc | ||
|
c60842a89f | ||
|
a5b7aed310 | ||
|
49d87c5cc8 | ||
|
1c1ef6ca4d | ||
|
bd54a9cec4 | ||
|
5b51a3459a | ||
|
ab06957571 | ||
|
108d04efd2 | ||
|
aaf24cf35d | ||
|
d77de7e47c | ||
|
b2418e4aa6 | ||
|
d4531a3f73 | ||
|
13a1af9ed4 | ||
|
43ac116425 | ||
|
08f5c20420 | ||
|
e78a722025 | ||
|
2e975376dc | ||
|
b227bd5d90 | ||
|
5ac4d0f63f | ||
|
9be4962d53 | ||
|
9fdfc71ab3 | ||
|
3c469edf69 | ||
|
4a2e3ca88f | ||
|
4f08a0c6c7 | ||
|
eee931feb1 | ||
|
96264ece63 | ||
|
6e24a9e0ba | ||
|
1262a6abfd | ||
|
9dd1055495 | ||
|
96c1a5c030 | ||
|
ae5dffa383 | ||
|
0d9924f9e6 | ||
|
b398e6df30 | ||
|
a56a475361 | ||
|
b3938f5a5e | ||
|
28767e86a6 | ||
|
82611ac618 | ||
|
2c236c0b25 | ||
|
55f4a137b2 | ||
|
609a9e2b3c | ||
|
bc66ce5855 | ||
|
592de3d5a9 | ||
|
5995b5e619 | ||
|
d62992fdf1 | ||
|
0417c67854 | ||
|
6142bab18b | ||
|
8142e10343 | ||
|
fc605357df | ||
|
a61c528315 | ||
|
b24c2d5bb3 | ||
|
2a72f535a7 | ||
|
f3b0df241d | ||
|
06a2dec810 | ||
|
4c62e4f573 | ||
|
e340b9f9be | ||
|
72ab6292fd | ||
|
8da3e55d8b | ||
|
0dbe192f7a | ||
|
b3e2c0fa72 | ||
|
98ec981c98 | ||
|
934b28aa1f | ||
|
5d045fa8b4 | ||
|
e8b8e526f6 | ||
|
a056678346 | ||
|
40853a0d4c | ||
|
2cfb08aa18 | ||
|
ab83ca4738 | ||
|
436d30d5e1 | ||
|
c7e095b145 | ||
|
c4a2a45805 | ||
|
a76682e1ab | ||
|
ef4c54eeb9 | ||
|
84691e75bf | ||
|
f77a4c5821 | ||
|
6d5f7173a3 | ||
|
736ce016ad | ||
|
19842349d9 | ||
|
a447eed37c | ||
|
183e60aa16 | ||
|
fde22697d8 | ||
|
5286a77c70 | ||
|
b29dc7281a |
40
README.md
40
README.md
|
@ -2,35 +2,19 @@ irmc - Internet Relay Morse Code
|
||||||
================================
|
================================
|
||||||
IRMC stands for Internet Relay Morse Code and is an implementation of [MOIP](http://8ch9azbsfifz.github.io/moip/).
|
IRMC stands for Internet Relay Morse Code and is an implementation of [MOIP](http://8ch9azbsfifz.github.io/moip/).
|
||||||
|
|
||||||
# How to build?
|
# Building
|
||||||
## Install dependency: morse keyer library
|
## On Linux
|
||||||
```
|
sudo apt-get install -y alsa-oss oss-compat build-essential autoconf libao-dev libtool libportaudio-dev portaudio19-dev
|
||||||
wget https://github.com/8cH9azbsFifZ/morse/archive/v0.1.tar.gz
|
make
|
||||||
tar xzf v0.1.tar.gz
|
|
||||||
cd morse-0.1
|
### On Raspi (GPIO Interface)
|
||||||
libtoolize
|
Follow: http://wiringpi.com/download-and-install/
|
||||||
./autogen.sh
|
make raspi
|
||||||
./configure --with-portaudio
|
|
||||||
|
|
||||||
|
## On OSX
|
||||||
|
brew install portaudio
|
||||||
make
|
make
|
||||||
sudo make install
|
|
||||||
```
|
|
||||||
|
|
||||||
## 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
|
|
||||||
```
|
|
||||||
|
|
||||||
## OSX (Yosemite)
|
|
||||||
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/)).
|
|
||||||
|
|
||||||
# Hardware interface options
|
# Hardware interface options
|
||||||
A good description on how to build different interfaces (telegraph key, sounder or both)
|
A good description on how to build different interfaces (telegraph key, sounder or both)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
SRC = irmc.c cwprotocol.c beep.c
|
SRC = irmc.c cwprotocol.c beep.c util.c
|
||||||
OBJ = ${SRC:.c=.o}
|
OBJ = ${SRC:.c=.o}
|
||||||
LDFLAGS = -lportaudio -lpthread -lm
|
LDFLAGS = -lportaudio -lpthread -lm
|
||||||
CFLAGS = -Wall
|
CFLAGS = -Wall -Wno-format-zero-length
|
||||||
INSTALLDIR = ${HOME}/bin
|
INSTALLDIR = ${HOME}/bin
|
||||||
|
|
||||||
all: options irmc
|
all: options irmc
|
||||||
|
@ -21,6 +21,10 @@ irmc: ${OBJ}
|
||||||
@echo CC -o $@
|
@echo CC -o $@
|
||||||
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||||
|
|
||||||
|
raspi:
|
||||||
|
@${CC} -c -DRASPI ${CFLAGS} ${SRC}
|
||||||
|
@${CC} -o irmc ${OBJ} ${LDFLAGS} -lwiringPi
|
||||||
|
|
||||||
java:
|
java:
|
||||||
java -jar test/MorseKOB.jar
|
java -jar test/MorseKOB.jar
|
||||||
|
|
||||||
|
|
26
src/beep.c
26
src/beep.c
|
@ -3,8 +3,14 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <unistd.h> // for usleep()
|
#include <unistd.h> // for usleep()
|
||||||
#include <portaudio.h>
|
#include <portaudio.h>
|
||||||
|
|
||||||
#include "beep.h"
|
#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
|
// http://stackoverflow.com/questions/7678470/generating-sound-of-a-particular-frequency-using-gcc-in-ubuntu
|
||||||
|
|
||||||
|
@ -88,7 +94,7 @@ int buzzer_start(void)
|
||||||
outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
|
outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
|
||||||
outputParameters.channelCount = 1; /* stereo output */
|
outputParameters.channelCount = 1; /* stereo output */
|
||||||
outputParameters.sampleFormat = paUInt8; /* 32 bit floating point output */
|
outputParameters.sampleFormat = paUInt8; /* 32 bit floating point output */
|
||||||
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
|
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency * RASPI_AUDIO_LATENCY_FIX;
|
||||||
outputParameters.hostApiSpecificStreamInfo = NULL;
|
outputParameters.hostApiSpecificStreamInfo = NULL;
|
||||||
|
|
||||||
err = Pa_OpenStream(
|
err = Pa_OpenStream(
|
||||||
|
@ -155,28 +161,10 @@ int beep_init()
|
||||||
|
|
||||||
int beep_test(void)
|
int beep_test(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
// notes frequency chart: http://www.phy.mtu.edu/~suits/notefreqs.html
|
|
||||||
|
|
||||||
buzzer_start();
|
buzzer_start();
|
||||||
buzzer_set_freq(261);
|
buzzer_set_freq(261);
|
||||||
msleep(250);
|
msleep(250);
|
||||||
buzzer_set_freq(0);
|
buzzer_set_freq(0);
|
||||||
msleep(250);
|
|
||||||
buzzer_set_freq(329);
|
|
||||||
msleep(250);
|
|
||||||
buzzer_set_freq(349);
|
|
||||||
msleep(250);
|
|
||||||
buzzer_set_freq(392);
|
|
||||||
msleep(250);
|
|
||||||
buzzer_set_freq(440);
|
|
||||||
msleep(250);
|
|
||||||
buzzer_set_freq(494);
|
|
||||||
msleep(250);
|
|
||||||
buzzer_beep(523, 200);
|
|
||||||
msleep(250);
|
|
||||||
|
|
||||||
buzzer_stop();
|
buzzer_stop();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,6 @@ typedef struct
|
||||||
uint32_t freq;
|
uint32_t freq;
|
||||||
} paTestData;
|
} paTestData;
|
||||||
|
|
||||||
static int patestCallback( const void *inputBuffer, void *outputBuffer,
|
|
||||||
unsigned long framesPerBuffer,
|
|
||||||
const PaStreamCallbackTimeInfo* timeInfo,
|
|
||||||
PaStreamCallbackFlags statusFlags,
|
|
||||||
void *userData );
|
|
||||||
void buzzer_set_freq(int frequency);
|
void buzzer_set_freq(int frequency);
|
||||||
void buzzer_beep(int frequency, int msecs);
|
void buzzer_beep(int frequency, int msecs);
|
||||||
int buzzer_start(void);
|
int buzzer_start(void);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
#include "cwprotocol.h"
|
#include "cwprotocol.h"
|
||||||
|
|
||||||
/* Global variables */
|
/* Global variables */
|
||||||
|
@ -41,7 +42,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->a21 = 0; /* These magic numbers was provided by Les Kerr */
|
||||||
tx_packet->a22 = 755;
|
tx_packet->a22 = 755;
|
||||||
tx_packet->a23 = 16777215;
|
tx_packet->a23 = 16777215;
|
||||||
snprintf(tx_packet->status, SIZE_STATUS, "?");
|
snprintf(tx_packet->status, SIZE_STATUS, "?"); // this shall include the sent character
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#define INTERFACE_VERSION "irmc v0.02"
|
#define INTERFACE_VERSION "irmc v0.3.3"
|
||||||
|
|
||||||
// Structures for the packets: unsigned short command
|
// Structures for the packets: unsigned short command
|
||||||
#define DIS 0x0002 // disconnect
|
#define DIS 0x0002 // disconnect
|
||||||
|
|
164
src/irmc.c
164
src/irmc.c
|
@ -15,31 +15,19 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <time.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <stdio.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 1
|
|
||||||
|
|
||||||
#define MAXDATASIZE 1024 // max number of bytes we can get at once
|
#define MAXDATASIZE 1024 // max number of bytes we can get at once
|
||||||
|
|
||||||
#include "cwprotocol.h"
|
#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;
|
int serial_status = 0, fd_serial, numbytes;
|
||||||
|
|
||||||
|
@ -51,8 +39,9 @@ long tx_timer = 0;
|
||||||
|
|
||||||
/* TX Methods */
|
/* TX Methods */
|
||||||
#define TX_NONE 0
|
#define TX_NONE 0
|
||||||
#define TX_SERIAL 1
|
//#define TX_SERIAL 1
|
||||||
#define TX_KEYBOARD 2
|
//#define TX_KEYBOARD 2 // not implemented yet
|
||||||
|
#define TX_RASPI 3
|
||||||
|
|
||||||
long key_press_t1;
|
long key_press_t1;
|
||||||
long key_release_t1;
|
long key_release_t1;
|
||||||
|
@ -63,67 +52,15 @@ char last_sender[16];
|
||||||
int translate = 1;
|
int translate = 1;
|
||||||
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 */
|
|
||||||
long fastclock(void)
|
|
||||||
{
|
|
||||||
struct timespec t;
|
|
||||||
long r;
|
|
||||||
|
|
||||||
current_utc_time (&t);
|
|
||||||
r = t.tv_sec * 1000;
|
|
||||||
r = r + t.tv_nsec / 1000000;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
int kbhit (void)
|
|
||||||
{
|
|
||||||
struct timeval tv;
|
|
||||||
fd_set rdfs;
|
|
||||||
|
|
||||||
tv.tv_sec = 0;
|
|
||||||
tv.tv_usec = 0;
|
|
||||||
|
|
||||||
FD_ZERO(&rdfs);
|
|
||||||
FD_SET (STDIN_FILENO, &rdfs);
|
|
||||||
|
|
||||||
select (STDIN_FILENO+1, &rdfs, NULL, NULL, &tv);
|
|
||||||
return FD_ISSET(STDIN_FILENO, &rdfs);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* get sockaddr, IPv4 or IPv6: */
|
|
||||||
void *get_in_addr(struct sockaddr *sa)
|
|
||||||
{
|
|
||||||
if (sa->sa_family == AF_INET) {
|
|
||||||
return &(((struct sockaddr_in*)sa)->sin_addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return &(((struct sockaddr_in6*)sa)->sin6_addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// disconnect from the server
|
// disconnect from the server
|
||||||
void inthandler(int sig)
|
void inthandler(int sig)
|
||||||
{
|
{
|
||||||
signal(sig, SIG_IGN);
|
signal(sig, SIG_IGN);
|
||||||
send(fd_socket, &disconnect_packet, SIZE_COMMAND_PACKET, 0);
|
send(fd_socket, &disconnect_packet, SIZE_COMMAND_PACKET, 0);
|
||||||
close(fd_socket);
|
close(fd_socket);
|
||||||
|
#ifdef TX_SERIAL
|
||||||
close(fd_serial);
|
close(fd_serial);
|
||||||
|
#endif
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,18 +73,32 @@ void txloop (void)
|
||||||
tx_data_packet.code[tx_data_packet.n - 1] =
|
tx_data_packet.code[tx_data_packet.n - 1] =
|
||||||
(int) ((key_press_t1 - key_release_t1) * -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);
|
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();
|
key_release_t1 = fastclock();
|
||||||
|
|
||||||
tx_data_packet.n++;
|
tx_data_packet.n++;
|
||||||
tx_data_packet.code[tx_data_packet.n - 1] =
|
tx_data_packet.code[tx_data_packet.n - 1] =
|
||||||
(int) ((key_release_t1 - key_press_t1) * 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){
|
while(1){
|
||||||
|
#ifdef TX_SERIAL
|
||||||
ioctl(fd_serial, TIOCMGET, &serial_status);
|
ioctl(fd_serial, TIOCMGET, &serial_status);
|
||||||
if(serial_status & TIOCM_DSR) break;
|
if(serial_status & TIOCM_DSR) break;
|
||||||
|
#endif
|
||||||
|
#ifdef RASPI
|
||||||
|
if(digitalRead(TX_RASPI_PIN)==1) break;
|
||||||
|
#endif
|
||||||
tx_timeout = fastclock() - key_release_t1;
|
tx_timeout = fastclock() - key_release_t1;
|
||||||
if(tx_timeout > TX_TIMEOUT) return;
|
if(tx_timeout > TX_TIMEOUT) return;
|
||||||
}
|
}
|
||||||
|
@ -204,7 +155,6 @@ int main(int argc, char *argv[])
|
||||||
int channel;
|
int channel;
|
||||||
char id[SIZE_ID];
|
char id[SIZE_ID];
|
||||||
char serialport[64];
|
char serialport[64];
|
||||||
int tx_method = TX_NONE;
|
|
||||||
|
|
||||||
// Set default values
|
// Set default values
|
||||||
snprintf(hostname, 64, "mtc-kob.dyndns.org");
|
snprintf(hostname, 64, "mtc-kob.dyndns.org");
|
||||||
|
@ -295,21 +245,30 @@ int main(int argc, char *argv[])
|
||||||
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);
|
||||||
fprintf(stderr, "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) {
|
#ifdef TX_SERIAL
|
||||||
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) {
|
||||||
fprintf(stderr,"Unable to open serial port %s.\n", serialport);
|
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
|
||||||
|
|
||||||
freeaddrinfo(servinfo); /* all done with this structure */
|
freeaddrinfo(servinfo); /* all done with this structure */
|
||||||
|
|
||||||
key_release_t1 = fastclock();
|
key_release_t1 = fastclock();
|
||||||
identifyclient();
|
identifyclient();
|
||||||
|
|
||||||
|
beep_init();
|
||||||
|
|
||||||
/* Main Loop */
|
/* Main Loop */
|
||||||
for(;;) {
|
for(;;) {
|
||||||
if(tx_timer == 0)
|
if(tx_timer == 0)
|
||||||
|
@ -377,14 +336,22 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
tx_data_packet.n = 0;
|
tx_data_packet.n = 0;
|
||||||
}
|
}
|
||||||
if (tx_method == TX_SERIAL) {
|
#ifdef TX_SERIAL
|
||||||
ioctl(fd_serial,TIOCMGET, &serial_status);
|
ioctl(fd_serial,TIOCMGET, &serial_status);
|
||||||
if(serial_status & TIOCM_DSR){
|
if(serial_status & TIOCM_DSR){
|
||||||
txloop();
|
txloop();
|
||||||
tx_timer = TX_WAIT;
|
tx_timer = TX_WAIT;
|
||||||
message(1);
|
message(1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef RASPI
|
||||||
|
if(digitalRead(5)==1){
|
||||||
|
txloop();
|
||||||
|
tx_timer = TX_WAIT;
|
||||||
|
message(1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if(keepalive_t < 0 && tx_timer == 0){
|
if(keepalive_t < 0 && tx_timer == 0){
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
@ -405,7 +372,10 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
send(fd_socket, &disconnect_packet, SIZE_COMMAND_PACKET, 0);
|
send(fd_socket, &disconnect_packet, SIZE_COMMAND_PACKET, 0);
|
||||||
close(fd_socket);
|
close(fd_socket);
|
||||||
|
#ifdef TX_SERIAL
|
||||||
close(fd_serial);
|
close(fd_serial);
|
||||||
|
#endif
|
||||||
|
buzzer_stop();
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
57
src/util.c
Normal file
57
src/util.c
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
|
long fastclock(void)
|
||||||
|
{
|
||||||
|
struct timespec t;
|
||||||
|
long r;
|
||||||
|
|
||||||
|
current_utc_time (&t);
|
||||||
|
r = t.tv_sec * 1000;
|
||||||
|
r = r + t.tv_nsec / 1000000;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
int kbhit (void)
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
fd_set rdfs;
|
||||||
|
|
||||||
|
tv.tv_sec = 0;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
|
FD_ZERO(&rdfs);
|
||||||
|
FD_SET (STDIN_FILENO, &rdfs);
|
||||||
|
|
||||||
|
select (STDIN_FILENO+1, &rdfs, NULL, NULL, &tv);
|
||||||
|
return FD_ISSET(STDIN_FILENO, &rdfs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get sockaddr, IPv4 or IPv6: */
|
||||||
|
void *get_in_addr(struct sockaddr *sa)
|
||||||
|
{
|
||||||
|
if (sa->sa_family == AF_INET) {
|
||||||
|
return &(((struct sockaddr_in*)sa)->sin_addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return &(((struct sockaddr_in6*)sa)->sin6_addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
30
src/util.h
Normal file
30
src/util.h
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __MACH__
|
||||||
|
#include <mach/clock.h>
|
||||||
|
#include <mach/mach.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void current_utc_time(struct timespec *ts);
|
||||||
|
long fastclock(void);
|
||||||
|
int kbhit (void);
|
||||||
|
void *get_in_addr(struct sockaddr *sa);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user