OK, revisiting the idea of detecting the presence of a tuner and getting its id from with in the kernel, I have got this far in trying to work out how to code it. Can someone who knows a bit more than I about talking to ttys from within the kernel check what I have so far is right and tell me how I read characters from the tty...?
My guess is that I would call this from within hijack_init() to set a static tuner_id variable and then do interesting stuff with it based on some new flags in config.ini... Would this be too early to call some of these methods on IRQ_ports[15] ...? and should I be writing the init_data byte by byte instead of all at once with driver.write...? (maybe some other function?)
Cheers
Kim
#include <linux/tty.h>
static int // detect the presence of a tuner module and return its id
tuner_detect ()
{
int ret;
char buf[5];
char init_data[3] = { 0x01, 0x00, 0x01 };
struct async_struct *info = IRQ_ports[15]; // tuner on ttyS0
struct tty_struct *tty = info->tty;
tty->termios->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP |INLCR|IGNCR|ICRNL|IXON);
tty->termios->c_oflag &= ~OPOST;
tty->termios->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
tty->termios->c_cflag &= ~(CSIZE|PARENB);
tty->termios->c_cflag |= CS8;
tty->termios->c_iflag |= B19200;
tty->termios->c_oflag |= B19200;
if ( tty->driver.write(tty, 0, init_data, 3) < 3 ) {
// failed to send data to the tuner
return -1;
}
// here's where I want to read 3 bytes from the tty...
// with a timeout in case the tuner doesn't exist and therefore doesn't reply
return ret;
}