#include <hdlisten.h>
Public Member Functions | |
HDListen () | |
void | setverbose (bool) |
void | setdefs (HDVals *) |
void | setioport (LinuxPort *) |
void | listenthread () |
void | listentoradio () |
vector< string > | getallkeys () |
double | getelapsedchangetime () |
string | gethdvalue (string) |
int | gethdintval (string) |
bool | gethdboolval (string) |
string | gethdtitle (int) |
map< int, string > | gethdtitles () |
string | gethdartist (int) |
map< int, string > | gethdartists () |
void | stopreading () |
Protected Member Functions | |
void | sethdval (string, string) |
void | chout (unsigned char) |
int | hexbytestoint (string) |
string | hexbytestostring (string) |
string | decodemsg () |
void | procmsg () |
void | handlebyte (unsigned char) |
void | readinfile () |
Private Member Functions | |
void | sethdtitle (int, string) |
void | sethdartist (int, string) |
Private Attributes | |
bool | verbose |
bool | keepReading |
bool | havecode |
bool | valueset |
bool | escChar |
bool | lengthWait |
char | msgcode [16] |
char | msgtype [16] |
char | curmsg [1024] |
int | msglen |
int | msgin |
int | currentsubchannel |
int | lastsubchannel |
int | lastsubchannelcount |
unsigned int | cktotal |
unsigned long | naptime |
string | ctype |
string | currentmsg |
string | currfreq |
string | currband |
string | lasttune |
vector< int > | bq |
map< string, string > | radiovals |
map< int, string > | hdtitles |
map< int, string > | hdartists |
pthread_t | listenThread |
pthread_mutex_t | valLock |
pthread_mutex_t | trackLock |
time_t | changetimer |
HDVals * | hdvals |
LinuxPort * | ioport |
HDListen::HDListen | ( | ) |
Constructor to set vals for the listener. After the listener is constructed, it still needs the definitions and the port. Once those are provided through setdefs() and setioport(), call listentoradio(). This will start a thread that will listen for any input from the radio and process it. After that is working, call gethdval(), gethdintval(), or gethdboolval to get any values we have received from the radio. If a value does not exist or has not been set by the radio yet, then an empty string will be returned. (If an int or bool value has not been set a -1 or false will be returned.)
Every time the station or frequency is changed, the station dependent values (like station name or hdtitle) will be set to an empty string. In most cases this information will be reset quickly on reaching a new, valid station.
The title and artist info is kept for all HD channels supplied for the current station. The values for "hdtitle" and "hdartist" will alwyas reflect the info for the current subchannel.
void HDListen::setverbose | ( | bool | verbosity | ) |
Set the verbosity of this class to true if debugging statements are desired.
verbosity | true for debugging output to the console |
void HDListen::setdefs | ( | HDVals * | hdv | ) |
Provide the class full of common variables.
hdv | the HDValue object we use for common variables |
void HDListen::setioport | ( | LinuxPort * | iop | ) |
Provide the port so we can read data from it.
iop | the LinuxPort class |
void HDListen::listenthread | ( | ) |
Public only because it has to be accessed from outside the class, but it would not be if not so. Used to start the independent thread to listen to the radio port.
void HDListen::listentoradio | ( | ) |
Call here to start the listener. It spins off a separate thread to listen to the radio output.
vector< string > HDListen::getallkeys | ( | ) |
Get a list of all the keys currently in the settings.
double HDListen::getelapsedchangetime | ( | ) |
Get the time elapsed since the last time a change was made to any of the settings we keep stored in the config file.
string HDListen::gethdvalue | ( | string | hdkey | ) |
Get a value from our settings. These values are set from the data retrieved from the radio. There is no guarentee that all the values will be set because they may not have been received. All get routines use this to get the original value before converting it to a bool or int. This is thread safe (uses a pthread_mutex) so there won't be problems with getting a value that is in the process of being set.
hdkey | the name of the value to get |
int HDListen::gethdintval | ( | string | hdkey | ) |
Get an int value from our settings.
hdkey | the name of the value to get |
bool HDListen::gethdboolval | ( | string | hdkey | ) |
Get a boolean value from our settings.
hdkey | the name of the value to get |
string HDListen::gethdtitle | ( | int | channel | ) |
Get the title for a particular hd subchannel
channel | the subchannel to get the title for |
map< int, string > HDListen::gethdtitles | ( | ) |
Get a list of all the hdtitle tags current for this station.
string HDListen::gethdartist | ( | int | channel | ) |
Get the artist for a particular hd subchannel
channel | the subchannel to get the artist for |
map< int, string > HDListen::gethdartists | ( | ) |
Get a list of all the hdartist tags current for this station.
void HDListen::stopreading | ( | ) |
Set the flag to tell the listener to stop reading from the port.
void HDListen::sethdval | ( | string | hdkey, | |
string | hdval | |||
) | [protected] |
Set a particular HD value from data incoming from the radio. This is thread safe so there won't be confusion between values being set or got. If the subchannel is changed, the hdtitle and hdartist are changed to match the current subchannel. If the frequency or band are changed, then all the station data is reset to empty so it won't lag behind the station being changed.
hdkey | name of value to set | |
hdval | value to set it to |
void HDListen::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.
cIn | the character to print |
int HDListen::hexbytestoint | ( | string | inbytes | ) | [protected] |
Convert a string of hex represented bytes (like "0xAC 0x1C") into an integer.
inbytes | the string to be converted to an integer |
string HDListen::hexbytestostring | ( | string | inbytes | ) | [protected] |
Convert a string of hex represented bytes in the form of "0xAB 0x12" and convert it into a string of readable characters.
inbytes | the string to convert |
string HDListen::decodemsg | ( | ) | [protected] |
Process a complete message we've received from the radio. See what kind of format it is in, what the message name is, and what the data is. Store the result as the proper key/value pair in the map of values.
void HDListen::procmsg | ( | ) | [protected] |
Take the bytes that have come in for an entire message and do the basic processing to put them in a form that can be easily decoded.
void HDListen::handlebyte | ( | unsigned char | cIn | ) | [protected] |
Process an incoming character. If it's 0xA4 and not escaped, it's part of an incoming message. Also check for bytes indicating message length, the checksum at the end of the message, and so on. Basically make sure we get an entire message and when we do, pass it on for further processing to determine the type of message and content. If a message is incomplete or doesn't have the right checksum (rare), then it is just discarded. When we call procmessage() we don't pass it on, since the variables need to be accessed by different subroutines, they're global to this class.
cIn | a character to be processed as part of the incoming stream of data from the radio. |
void HDListen::readinfile | ( | ) | [protected] |
Read input from the serial port, then pass each byte to the byte handling routine. Every byte that is read in is passed to handlebyte() so it can process it.
void HDListen::sethdtitle | ( | int | channel, | |
string | title | |||
) | [private] |
Set the HD title for a specific channel.
channel | channel to set the title for | |
title | new title info |
void HDListen::sethdartist | ( | int | channel, | |
string | artist | |||
) | [private] |
Set the HD artist for a specific channel.
channel | channel to set the artist for | |
artist | artist info |
bool HDListen::verbose [private] |
bool HDListen::keepReading [private] |
bool HDListen::havecode [private] |
bool HDListen::valueset [private] |
bool HDListen::escChar [private] |
bool HDListen::lengthWait [private] |
char HDListen::msgcode[16] [private] |
char HDListen::msgtype[16] [private] |
char HDListen::curmsg[1024] [private] |
int HDListen::msglen [private] |
int HDListen::msgin [private] |
int HDListen::currentsubchannel [private] |
int HDListen::lastsubchannel [private] |
int HDListen::lastsubchannelcount [private] |
unsigned int HDListen::cktotal [private] |
unsigned long HDListen::naptime [private] |
string HDListen::ctype [private] |
string HDListen::currentmsg [private] |
string HDListen::currfreq [private] |
string HDListen::currband [private] |
string HDListen::lasttune [private] |
vector<int> HDListen::bq [private] |
map<string,string> HDListen::radiovals [private] |
map<int,string> HDListen::hdtitles [private] |
map<int,string> HDListen::hdartists [private] |
pthread_t HDListen::listenThread [private] |
pthread_mutex_t HDListen::valLock [private] |
pthread_mutex_t HDListen::trackLock [private] |
time_t HDListen::changetimer [private] |
HDVals* HDListen::hdvals [private] |
LinuxPort* HDListen::ioport [private] |