Compare commits
No commits in common. "dev" and "master" have entirely different histories.
@ -1,7 +1,7 @@
|
||||
SRC = irmc.c cwprotocol.c beep.c util.c
|
||||
OBJ = ${SRC:.c=.o}
|
||||
LDFLAGS = -lportaudio -lpthread -lm
|
||||
CFLAGS = -Wall -Wno-format-zero-length -Wno-parentheses
|
||||
CFLAGS = -Wall -Wno-format-zero-length
|
||||
INSTALLDIR = ${HOME}/bin
|
||||
|
||||
all: options irmc
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "cwprotocol.h"
|
||||
|
||||
@ -14,8 +13,6 @@ struct data_packet_format tx_data_packet;
|
||||
int tx_sequence = 0, rx_sequence;
|
||||
int fd_socket;
|
||||
|
||||
struct morse_timig_format morse_timing;
|
||||
|
||||
int prepare_id (struct data_packet_format *id_packet, char *id)
|
||||
{
|
||||
id_packet->command = DAT;
|
||||
@ -68,7 +65,7 @@ int send_latch (void)
|
||||
tx_data_packet.code[0] = -1;
|
||||
tx_data_packet.code[1] = 1;
|
||||
tx_data_packet.n = 2;
|
||||
for(i = 0; i < TX_RETRIES; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
|
||||
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
|
||||
tx_data_packet.n = 0;
|
||||
return 0;
|
||||
}
|
||||
@ -81,78 +78,8 @@ int send_unlatch (void)
|
||||
tx_data_packet.code[0] = -1;
|
||||
tx_data_packet.code[1] = 2;
|
||||
tx_data_packet.n = 2;
|
||||
for(i = 0; i < TX_RETRIES; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
|
||||
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
|
||||
tx_data_packet.n = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int prepare_text2morse (int wpm)
|
||||
{
|
||||
morse_timing.wpm = wpm;
|
||||
morse_timing.dot_len = (int) (1200/wpm); // in ms - PARIS standard
|
||||
morse_timing.dash_len = 3*morse_timing.dot_len;
|
||||
morse_timing.charspace_len = 3*morse_timing.dot_len;
|
||||
morse_timing.wordspace_len = 7*morse_timing.dot_len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int clean_tx (void)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<SIZE_CODE; i++)
|
||||
tx_data_packet.code[i] = 0;
|
||||
for (i=0; i<SIZE_STATUS; i++)
|
||||
tx_data_packet.status[i] = ' ';
|
||||
tx_data_packet.n = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// FIXME: This function is really nasty, even for this code :)
|
||||
int char2morse(int ff)
|
||||
{
|
||||
clean_tx();
|
||||
|
||||
int c, d, e;
|
||||
int a=0, b=0;
|
||||
int i=0;
|
||||
int k=0;
|
||||
c=ff;
|
||||
tx_sequence++;
|
||||
tx_data_packet.sequence = tx_sequence;
|
||||
|
||||
// why? because!!!
|
||||
// http://stackoverflow.com/questions/1352587/convert-a-string-into-morse-code/1355594^
|
||||
for(;c= c?c:(c=a=toupper(getchar())-32)?c<0?1:"\x95#\x8CKa`^ZRBCEIQiw#S#nx(37+$6-2&@/4)'18=,*%.:0;?5" [c-12]-34:-3;c/=2) {
|
||||
e=d;
|
||||
if (a!=b) {
|
||||
tx_data_packet.status[k] = a+32; //putchar (a+32);
|
||||
k++;
|
||||
}
|
||||
b=a;
|
||||
d=(c/2?46-c%2:32);
|
||||
//putchar (d);
|
||||
if (d == ' ' && e == ' ') break;
|
||||
tx_data_packet.code[i] = -1*morse_timing.dot_len;
|
||||
i++;
|
||||
int j;
|
||||
if (d == '.')
|
||||
j=1;
|
||||
if (d == '-')
|
||||
j=3;
|
||||
if (d == ' ')
|
||||
j=-3;
|
||||
tx_data_packet.code[i] = j*morse_timing.dot_len;
|
||||
i++;
|
||||
//printf ("(%d %d) ",tx_data_packet.code[i-2],tx_data_packet.code[i-1] );
|
||||
}
|
||||
tx_data_packet.code[i] = -1*morse_timing.dot_len;
|
||||
i++;
|
||||
tx_data_packet.n = i;
|
||||
|
||||
for(i = 0; i < TX_RETRIES; i++)
|
||||
send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
|
||||
tx_data_packet.n = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -10,9 +10,6 @@
|
||||
#define SIZE_DATA_PACKET 496
|
||||
#define SIZE_DATA_PACKET_PAYLOAD 492 // = SIZE_DATA_PACKET - SIZE_COMMAND_PACKET
|
||||
|
||||
#define TX_RETRIES 5 // how often will the udp packet be sent?
|
||||
#define KEEPALIVE_CYCLE 1000 // how often will the keepalive signals be sent?
|
||||
|
||||
#define SIZE_ID 128
|
||||
#define SIZE_STATUS 128
|
||||
#define SIZE_CODE 51
|
||||
@ -40,14 +37,12 @@ struct data_packet_format{
|
||||
|
||||
};
|
||||
|
||||
|
||||
// Define the packets used
|
||||
#define DEFAULT_CHANNEL 103
|
||||
|
||||
/* Define functions provided by cwprotocol */
|
||||
int prepare_id (struct data_packet_format *id_packet, char *id);
|
||||
int prepare_tx (struct data_packet_format *tx_packet, char *id);
|
||||
int clean_tx (void);
|
||||
void identifyclient (void);
|
||||
int send_latch (void);
|
||||
int send_unlatch (void);
|
||||
@ -63,14 +58,5 @@ extern int tx_sequence, rx_sequence;
|
||||
|
||||
extern int fd_socket;
|
||||
|
||||
// Morse Code Sender - Timings
|
||||
#define WPM_DEFAULT 40
|
||||
struct morse_timig_format {
|
||||
int wpm;
|
||||
int dot_len, dash_len;
|
||||
int wordspace_len, charspace_len;
|
||||
};
|
||||
|
||||
int prepare_text2morse (int wpm);
|
||||
int char2morse(int ff);
|
||||
|
||||
|
22
src/irmc.c
22
src/irmc.c
@ -35,12 +35,12 @@ double tx_timeout = 0;
|
||||
long tx_timer = 0;
|
||||
#define TX_WAIT 5000
|
||||
#define TX_TIMEOUT 240.0
|
||||
#define BEEP_FREQUENCY 1000.
|
||||
#define KEEPALIVE_CYCLE 100
|
||||
|
||||
/* TX Methods */
|
||||
#define TX_NONE 0
|
||||
//#define TX_SERIAL 1
|
||||
#define TX_KEYBOARD 2 // not implemented yet
|
||||
//#define TX_KEYBOARD 2 // not implemented yet
|
||||
#define TX_RASPI 3
|
||||
|
||||
long key_press_t1;
|
||||
@ -261,10 +261,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
pinMode(TX_RASPI_PIN, INPUT);
|
||||
#endif
|
||||
|
||||
#ifdef TX_KEYBOARD
|
||||
prepare_text2morse (WPM_DEFAULT);
|
||||
#endif
|
||||
|
||||
freeaddrinfo(servinfo); /* all done with this structure */
|
||||
|
||||
@ -320,7 +316,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
beep(BEEP_FREQUENCY, length/1000.);
|
||||
beep(1000.0, length/1000.);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -334,8 +330,7 @@ int main(int argc, char *argv[])
|
||||
if(tx_data_packet.n > 1 ){
|
||||
tx_sequence++;
|
||||
tx_data_packet.sequence = tx_sequence;
|
||||
for(i = 0; i < TX_RETRIES; i++)
|
||||
send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
|
||||
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
|
||||
#if DEBUG
|
||||
printf("irmc: sent data packet.\n");
|
||||
#endif
|
||||
@ -351,7 +346,7 @@ int main(int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
#ifdef RASPI
|
||||
if(digitalRead(TX_RASPI_PIN)==1){
|
||||
if(digitalRead(5)==1){
|
||||
txloop();
|
||||
tx_timer = TX_WAIT;
|
||||
message(1);
|
||||
@ -368,12 +363,11 @@ int main(int argc, char *argv[])
|
||||
if(tx_timer == 0) {
|
||||
keepalive_t--;
|
||||
usleep(50);
|
||||
}
|
||||
#ifdef TX_KEYBOARD
|
||||
}
|
||||
|
||||
if(kbhit() && tx_timer == 0){
|
||||
char2morse(0);
|
||||
getchar(); /* flush the buffer */
|
||||
}
|
||||
#endif
|
||||
} /* End of mainloop */
|
||||
|
||||
send(fd_socket, &disconnect_packet, SIZE_COMMAND_PACKET, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user