Noncanonical

A very simple CW keyboard program is presented. No thread programming, using only noncanonical input mode to catch your key strokes one by one. You enter your message from a keyboard, and as soon as you hit a space or a period or an enter key, a word is sent to IC-7410. Having six bytes of overhead for each word does not sound very efficient, but since IC-7410 can only accept up to 30 characters at a time, this is a good compromise.

[1] http://www.gnu.org/software/libc/manual/html_node/Noncanon-Example.html

[2] http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html

/* file name = ic-7410_cw_keyboard.c */
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>
#include <sys/wait.h>
#define BUFSIZE 4096
#define BAUDRATE B19200
#define MODEMDEVICE "/dev/ttyUSB0"

struct termios saved_attributes;
static int fd = -1;

void serial_init(int fd) {
struct termios tio;
memset(&tio, 0, sizeof(tio));
tio.c_cflag = CS8 | CLOCAL | CREAD;
tio.c_cc[VTIME] = 0;
tio.c_cc[VEOL] = 0xfd; /* IC-7410 postamble */
tio.c_lflag = ICANON;
tio.c_iflag = IGNPAR | ICRNL;
cfsetispeed(&tio, BAUDRATE);
cfsetospeed(&tio, BAUDRATE);
tcsetattr(fd, TCSANOW, &tio);
}

void reset_input_mode (void) {
tcsetattr (STDIN_FILENO, TCSANOW, &saved_attributes);
}

void set_input_mode (void) {
struct termios tattr;
char *name;

/* Save the terminal attributes so we can restore them later. */
tcgetattr (STDIN_FILENO, &saved_attributes);
atexit (reset_input_mode);

/* Set the funny terminal modes. */
tcgetattr (STDIN_FILENO, &tattr);
tattr.c_lflag &= ~ICANON; /* Clear ICANON. */
tattr.c_lflag |= ECHO; /* Use ECHO. */
tattr.c_cc[VMIN ] = 1;
tattr.c_cc[VTIME] = 0;
tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr);
}

int main (void) {
char c;
int i, nread, count=0, outputcount;
char message[BUFSIZE];
char output [BUFSIZE];
struct termios oldtio, newtio;

if (isatty (STDIN_FILENO)) {
fprintf (stderr, "Enter your message.. n");
}
set_input_mode ();

fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY);
if (fd < 0) {
fprintf(stderr,"Error: can not open %s n", MODEMDEVICE);
return (-1);
}

tcgetattr(fd, &oldtio);
memset(&newtio, 0, sizeof(newtio));
serial_init(fd);

while (1)
{
nread = read (STDIN_FILENO, &c, 1);
message[count++]=c;
if (c == '\004') /* C-d */
break;
else
if(c == ' ' || c == '.' || c == '\012') {
output[0] = 0xfe; /* IC-7410 preamble */
output[1] = 0xfe; /* IC-7410 preamble */
output[2] = 0x80; /* IC-7410 CI-V address */
output[3] = 0x00; /* my PC address (any) */
output[4] = 0x17; /* IC-7410 command for CW message */
for(i=0;i < count;i++) {
output[5+i] = message[i];
}
output[5+count] = 0xfd; /* IC-7410 postamble */
outputcount = count+6; /* total length = CW message + (5+1) */
write(fd, &output, outputcount);
count=0;
}
}
return EXIT_SUCCESS;
}

USB Sound

The USB I/F of IC-7410 can also be used for audio recording and playback.

usbSound
usbSound2

A GUI program Audacity is used here, but if your prefer to use CLIs, do as in the following way.

% arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: CODEC [USB Audio CODEC], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

% aplay -l
**** List of PLAYBACK Hardware Devices ****
card 1: CODEC [USB Audio CODEC], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

% arecord -d 5 -r 48000 -f S16_LE -D hw:1,0 &gt; test.wav
Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono

% aplay -D hw:1,0 test.wav
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono

You can check the maximum sampling frequency by giving some higher values.

% arecord -d 5 -r 96000 -f S16_LE -D hw:1,0 &gt; test.wav
Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 96000 Hz, Mono
Warning: rate is not accurate (requested = 96000Hz, got = 48000Hz)
         please, try the plug plugin