LinuxPort Class Reference

#include <hdlinuxio.h>

Collaboration diagram for LinuxPort:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 LinuxPort ()
void setconfig (ConfigFile *)
void setverbose (bool)
bool testport (string)
bool findhdradio ()
void setportattr (int)
bool openport ()
void closeport ()
void setserialport (string)
string getserialport ()
void hdsendbyte (char)
void hdsendbytes (char *)
char * hdreadbytes (int)
char * hdreadbyte ()
int hdlastreadleangth ()
void addsearchdevice (string)
void addsearchtype (string)
void toggledtr (bool)
void printdtr ()
void printdtr (string)
bool getdtr ()
void hanguponexit (bool)

Protected Member Functions

void chout (unsigned char)

Private Attributes

bool isOpen
bool verbose
int portfd
int lastread
int cflag
float autodiscoverwait
float defautodiscwait
unsigned int testparm [11]
unsigned long naptime
long BAUD
long DATABITS
long STOPBITS
long PARITYON
long PARITY
string serialdevice
string testdata
vector< string > devlist
vector< string > devtype
struct termios options oldios
ConfigFilemainConfig


Constructor & Destructor Documentation

LinuxPort::LinuxPort (  ) 

Create the LinuxPort class. Set all initial variables.


Member Function Documentation

void LinuxPort::setconfig ( ConfigFile cf  ) 

Add the config object. Must be done!! Config is needed to supply some variables and to make sure the serial port device is saved for use next time.

Parameters:
cf config object found in halcyon.cpp

void LinuxPort::setverbose ( bool  verbosity  ) 

Set the verbosity. Provides output to the console for debugging.

Parameters:
verbosity true for console output

bool LinuxPort::testport ( string  serport  ) 

Test a port to see if a radio we can work with is connected. We open it with openport() and wait to see if that turned on a radio that sends us a power reply. Checking a port could disrupt communications with any other device on that port, so this is not recommended for use each time a program is run but only the first time, to find the radio.

Parameters:
serport the serial port to check

bool LinuxPort::findhdradio (  ) 

Find the HD Radio hooked up to this system. Also referred to as autodiscovery. This should not be done unless the radio is not found or can't be confirmed. This uses the testport() function which can disrupt communications with other devices on serial ports while we search for a compatible radio. For that reason, autodiscovery should only be used the first time a program is ever run to find the radio or when it has been moved to a different port. If the port is known, autodiscovery can be avoided just by specifying what port to use and setting the firstrun variable in the config file to false.

Returns:
true if a radio was found

void LinuxPort::setportattr ( int  portfd  ) 

Set the serial port attributes so we can communicate with the radio. This could effect the state of the DTR line in some cases.

Parameters:
portfd the file descriptor for the port we're setting

bool LinuxPort::openport (  ) 

We opne the serial port here. The port should already be specified with setserialport().

void LinuxPort::closeport (  ) 

Close the serial port for both input and output (the serial port is opened twice, once for input and once for output.

void LinuxPort::setserialport ( string  sport  ) 

Set the serial port to use for communication. When it's set here, it's also set in the config so it'll be written out to the config file as the last known port. During autodiscovery that won't help, but the config file isn't saved during autodiscovery. It is saved whenever settings on the radio change, so setting the serial port in the config class here will ensure the port is saved when the radio is tuned to any station.

On startup next time, the port saved will be used again unless overridden.

Parameters:
sport serial port

string LinuxPort::getserialport (  ) 

Get the currently used serial port file name.

Returns:
the path or name of the currently used serial device

void LinuxPort::hdsendbyte ( char  outbyte  ) 

Send a byte to the radio through the serial port. Actually just calls hdsendbytes() and says to send only 1 byte.

Parameters:
outbyte character or byte to send through the port

void LinuxPort::hdsendbytes ( char *  outbytes  ) 

Send a series of bytes or characters through the serial port to the device.

Parameters:
outbytes the characters/bytes to send

char * LinuxPort::hdreadbytes ( int  ilen  ) 

Read the specified number of bytes from the serial port. Our buffer is 1k, since we're never working with anywhere near that much data anyway.

Parameters:
ilen number of bytes to read in
Returns:
pointer to the buffer where returned data is stored.

char * LinuxPort::hdreadbyte (  ) 

Read a single byte into a buffer and return it.

Returns:
pointer to a 1 byte buffer with one byte read from the port

int LinuxPort::hdlastreadleangth (  ) 

Number of bytes read in on the last read.

Returns:
number of bytes read in

void LinuxPort::addsearchdevice ( string  devname  ) 

Add a device to check when searching for the radio in autodiscovery. All devices given will be searched in order if autodiscovery is used to find the radio.

Parameters:
devname file path for the device to add

void LinuxPort::addsearchtype ( string  devicetype  ) 

Add a "type" of device to search for the radio. This is mainly used to allow multiple ports with almost the same filenames to be searched. For example, specifying "/dev/ttyS" instead of "/dev/ttyS0" will search multiple serial ports. It'll start with adding a "0" on the end ("/dev/ttyS0") then a "1" ("/dev/ttyS1") and so on. It stops the first time a device to check does not exist, then moves on to the next type. This can be helpful on systems with a number of serial port adaptors on USB connetions, since specifying "/dev/ttyUSB" will automatically check all the devices starting with "/dev/ttyUSB0" and continue to the first non-existant device. Device types are searched *after* devices.

Parameters:
devicetype device type to search.

void LinuxPort::toggledtr ( bool  newstate  ) 

Another debugging routine. Call with true to turn DTR on, false to turn it off.

Parameters:
state to set DTR to

void LinuxPort::printdtr (  ) 

Overload with no argument for debugging DTR issues.

void LinuxPort::printdtr ( string  msg  ) 

Mainly for debugging, this will print out the state of the DTR line.

bool LinuxPort::getdtr (  ) 

Mainly for debugging, get DTR state.

Returns:
true for high, false for low.

void LinuxPort::hanguponexit ( bool  hangup  ) 

Normally we do hang up, or turn off the radio, on exit, but in some systems it may be desireable to leave the radio on on exit, so that can be done by calling here to override the default with "false".

Parameters:
hangup true to turn off the radio on exit, false to leave it on

void LinuxPort::chout ( unsigned char  cIn  )  [protected]

Simple routine to output the character in a readable 0x00 format, followed by an int version, followed by a printable character (if it is printable). There is one subtlity: if we have a code for the current characters (as in we know we're getting specific data), then the separator between the hex and dec numbers is ":", if we don't have a code, it's "-". The A4 code saying we're starting data will always have a "-" in it.

Parameters:
cIn the character to print


Member Data Documentation

bool LinuxPort::isOpen [private]

bool LinuxPort::verbose [private]

int LinuxPort::portfd [private]

int LinuxPort::lastread [private]

int LinuxPort::cflag [private]

float LinuxPort::autodiscoverwait [private]

float LinuxPort::defautodiscwait [private]

unsigned int LinuxPort::testparm[11] [private]

unsigned long LinuxPort::naptime [private]

long LinuxPort::BAUD [private]

long LinuxPort::DATABITS [private]

long LinuxPort::STOPBITS [private]

long LinuxPort::PARITYON [private]

long LinuxPort::PARITY [private]

string LinuxPort::serialdevice [private]

string LinuxPort::testdata [private]

vector<string> LinuxPort::devlist [private]

vector<string> LinuxPort::devtype [private]

struct termios options LinuxPort::oldios [read, private]

ConfigFile* LinuxPort::mainConfig [private]


The documentation for this class was generated from the following files:
Generated on Sun Apr 6 01:13:23 2008 for HDRadioController by  doxygen 1.5.3