merged linux build

This commit is contained in:
Gerolf Ziegenhain 2015-01-03 23:11:45 +01:00
parent 30b977c432
commit 0b242efc1a
2 changed files with 56 additions and 15 deletions

View File

@ -1,7 +1,7 @@
SRC = irmc.c sound.c SRC = irmc.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

63
irmc.c
View File

@ -11,10 +11,26 @@
#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>
#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#endif
#define MAXDATASIZE 1024 // max number of bytes we can get at once #define MAXDATASIZE 1024 // max number of bytes we can get at once
@ -73,7 +89,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 +98,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 +121,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;
@ -221,12 +252,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");
@ -278,7 +307,6 @@ int main(int argc, char *argv[])
char id[128]; char id[128];
char serialport[64]; char serialport[64];
if (argc < 4) { if (argc < 4) {
fprintf(stderr," %i usage: irmc [hostname] [port] [channel] [id] [serialport]\n", argc); fprintf(stderr," %i usage: irmc [hostname] [port] [channel] [id] [serialport]\n", argc);
exit(1); exit(1);
@ -354,7 +382,7 @@ 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);
printf("irmc: connected to %s\n", s); printf("irmc: 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"); printf("irmc: unable to open serial port.\n");
@ -362,7 +390,6 @@ int main(int argc, char *argv[])
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 */
@ -398,7 +425,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;
} }
} }
@ -442,7 +484,6 @@ int main(int argc, char *argv[])
send(fd_socket, &disconnect_packet, sizeof(disconnect_packet), 0); send(fd_socket, &disconnect_packet, sizeof(disconnect_packet), 0);
close(fd_socket); close(fd_socket);
close(fd_speaker);
close(fd_serial); close(fd_serial);
exit(0); exit(0);