This commit is contained in:
Gerolf Ziegenhain 2015-07-08 22:38:29 +02:00
parent c464cc7dcb
commit 36fa067cc5

View File

@ -9,16 +9,15 @@
#include <sys/types.h> #include <sys/types.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/ioctl.h>
#include <math.h> #include <math.h>
#include <fcntl.h> #include <fcntl.h>
#include <morse/beep.h> #include <morse/beep.h>
#ifdef __MACH__ #ifdef __MACH__
#define LIBOSS_INTERNAL
#include <liboss/soundcard.h> //will not be used for audio any more
#else #else
#include <linux/ioctl.h> #include <linux/ioctl.h>
#include <asm-generic/ioctl.h> #include <asm-generic/ioctl.h>
#include <asm-generic/termios.h> #include <asm-generic/termios.h>
#endif #endif
#include <signal.h> #include <signal.h>
#include <arpa/inet.h> #include <arpa/inet.h>
@ -27,8 +26,8 @@
#include <stdio.h> #include <stdio.h>
#ifdef __MACH__ #ifdef __MACH__
#include <mach/clock.h> #include <mach/clock.h>
#include <mach/mach.h> #include <mach/mach.h>
#endif #endif
#define DEBUG 0 #define DEBUG 0
@ -77,8 +76,7 @@ void current_utc_time(struct timespec *ts) {
} }
/* a better clock() in milliseconds */ /* a better clock() in milliseconds */
long long fastclock(void)
fastclock(void)
{ {
struct timespec t; struct timespec t;
long r; long r;
@ -117,8 +115,7 @@ void *get_in_addr(struct sockaddr *sa)
} }
// connect to server and send my id. // 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;
@ -127,8 +124,7 @@ identifyclient(void)
} }
// disconnect from the server // 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, SIZE_COMMAND_PACKET, 0); send(fd_socket, &disconnect_packet, SIZE_COMMAND_PACKET, 0);
@ -137,8 +133,7 @@ inthandler(int sig)
exit(1); exit(1);
} }
void void txloop (void)
txloop (void)
{ {
key_press_t1 = fastclock(); key_press_t1 = fastclock();
tx_timeout = 0; tx_timeout = 0;
@ -170,8 +165,7 @@ txloop (void)
} }
} }
int int commandmode(void)
commandmode(void)
{ {
char cmd[32]; char cmd[32];
int i; int i;
@ -226,8 +220,7 @@ commandmode(void)
} }
void void message(int msg)
message(int msg)
{ {
switch(msg){ switch(msg){
case 1: case 1:
@ -256,7 +249,9 @@ message(int msg)
} }
fflush(0); fflush(0);
} }
/* Main Loop */
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char buf[MAXDATASIZE]; char buf[MAXDATASIZE];
@ -351,7 +346,7 @@ 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, "Failed to connect.\n"); fprintf(stderr, "Failed to connect.\n");
return 2; return 2;
@ -411,10 +406,13 @@ int main(int argc, char *argv[])
else else
{ {
if(length < 0) { if(length < 0) {
printf("beep no");
beep(0.0, abs(length)/1000.); beep(0.0, abs(length)/1000.);
} }
else else
{ {
printf("beep yes");
beep(1000.0, length/1000.); beep(1000.0, length/1000.);
} }
} }