#include <hdcontrol.h>
Public Member Functions | |
HDControl () | |
void | setArguments (int, char **) |
void | setSerialPort (string) |
ConfigFile * | getConfig () |
void | activate () |
void | close () |
void | setVerbose (bool) |
void | changeMonitor () |
void | startChangeMonitor () |
void | saveState () |
void | restoreState () |
void | addToFavorites () |
void | addToFavorites (string) |
void | CreateFavorite (string) |
void | createFavorite (string, string) |
void | createFavorite (string, string, string) |
void | saveFavorites () |
void | getFavorites () |
void | removeFavorite (string) |
void | renameFavorite (string, string) |
void | setToFavorite (string) |
vector< string > | getAllKeys () |
bool | command_line (string) |
bool | command (string) |
bool | command (string, string) |
bool | command (string, int) |
bool | command (string, string, string) |
bool | command (string, int, string) |
void | radioOn () |
void | radioOff () |
void | muteOn () |
void | muteOff () |
void | hd_setvolume (int) |
void | hd_setvolume (string) |
void | hd_setbass (int) |
void | hd_setbass (string) |
void | hd_settreble (int) |
void | hd_settreble (string) |
void | tunetodefault () |
void | hd_tuneup () |
void | hd_tunedown () |
void | hd_subchannel (int) |
void | hd_subchannel (string) |
void | hd_seekup () |
void | hd_seekdown () |
void | hd_seekall () |
void | hd_seekhd () |
void | request_power () |
void | request_volume () |
void | request_mute () |
void | request_bass () |
void | request_treble () |
void | request_tune () |
void | request_hdsubchannelcount () |
void | request_hdsubchannel () |
void | request_hdstationname () |
void | request_hdcallsign () |
void | request_hduniqueid () |
void | request_hdtitle () |
void | request_hdartist () |
void | request_hdsignalstrenth () |
void | request_hdstreamlock () |
void | request_hdactive () |
void | request_hdtunerenabled () |
void | request_apiversion () |
void | request_hwversion () |
void | request_rdsenable () |
void | request_rdsservice () |
void | request_rdstext () |
void | request_rdsgenre () |
void | showdtr () |
void | toggledtr (string) |
void | hanguponexit (bool) |
string | getValue (string) |
string | getPower () |
string | getVolume () |
string | getBass () |
string | getTreble () |
string | getMute () |
string | getFrequency () |
string | getBand () |
string | getHDSubchannel () |
string | getTune () |
string | getHDActive () |
string | getHDStreamlock () |
string | getHDSignalStrength () |
string | getHDSubchannelCount () |
string | getHDEnableTuner () |
string | getHDCallSign () |
string | getHDStationName () |
string | getHDUniqueID () |
string | getHDAPIVersion () |
string | getHDHWVersion () |
string | getRDSEnable () |
string | getRDSGenre () |
string | getRDSProgramService () |
string | getRDSRadioText () |
string | getHDTitle () |
string | getHDTitle (int) |
map< int, string > | getHDTitles () |
string | getHDArtist () |
string | getHDArtist (int) |
map< int, string > | getHDArtists () |
Private Member Functions | |
void | parseDevices (string, bool) |
string | intToString (int) |
Private Attributes | |
bool | verbose |
string | deffreq |
string | defband |
string | mainconfigfile |
string | sessionconfigfile |
string | defaultserial |
vector< string > | defkeys |
vector< string > | defcmds |
vector< string > | favorites |
map< string, string > | favcall |
map< string, string > | favname |
map< string, string > | favnameback |
pthread_t | t_ChangeMonitor |
LinuxPort | ioPort |
ConfigFile | mainConfig |
HDListen | hdListen |
HDVals | hdValues |
HDCommands | hdCommand |
HDControl::HDControl | ( | ) |
This is the main control class for controlling HD Radios and for getting data back from them to determine their current state. It depends on other classes, but the entire interface for all functions and settings is here. There is no need to create any other classes, all that is done automatically.
By default the system config file is /ect/HRDadio.cfg and there is a user config file in the home directory .hdradio/HDRadioSession.cfg. The user file overrides the system one and includes user specific settings including favorite channels.
It is important to note there is a difference between commands that allow one to get settings like the volume level from the radio and the ones that get data to return. While almost every time a command asking for data is sent to the radio it responds immediately, that is not guarenteed to be the case. To solve this problem, there is a thread that runs continuously getting any data returned by the radio and storing it in our own structure. Getting a value in our structure returns the current value. Getting it form the radio tells the radio to send it to us so we can have a current value.
The commands that ask the radio for data start with "request_" and the ones that get data from our settings start with "get_".
The current setting of the radio is saved in the user config file whenever the radio is tuned or certain other changes are made so when the program is run again, the radio can be returned to the last saved state. (This is not automatic, since it might not always be wanted.)
Be sure to look at the info about autodiscovery in the linuxio.cpp file, which includs the LinuxPort object. Autodiscovery helps find the radio and provides the current serial port, but it can also cause problems with other devices communicating through serial ports. To avoid most problems with autodiscovery, once the radio is found on a particular device, that device is saved in the config file.
The constructor does not start this class, it just sets it up. To start the radio connection, call activate(). By separating the functions, that allows modification and changes in settings from class creation until actual startup and use. For example, command line args can be passed on to override config settings, then activate() can be called.
void HDControl::setArguments | ( | int | count, | |
char ** | args | |||
) |
Setup the arguments in the config file. This is available to allow the use of command line settings that will override the config file. To use it, just pass argc and argv here and it'll be used in the config class.
count | the same as argc | |
args | the same as argv |
void HDControl::setSerialPort | ( | string | serialDevice | ) |
Specify the serial device to use. If done after the command line args are parsed, it'll over ride any command line or config file speficiations. Otherwise, the device is specifed from the config file.
serialdev | the serial device to use |
ConfigFile * HDControl::getConfig | ( | ) |
Get a copy of the main config object for settings access
void HDControl::activate | ( | ) |
Actually start the communications with the device. If we've never been run before on this computer, then find the radio. Also start the listener thread to make sure the output of the device is processed.
void HDControl::close | ( | ) |
Close the port to the radio.
void HDControl::setVerbose | ( | bool | verbosity | ) |
Set verbosity. True means debugging messages will be sent to the console.
verbosity | set to true to get debugging messages |
void HDControl::changeMonitor | ( | ) |
Public only because it has to be. This is expected to be called as part of a separate thread to monitor when settings on the radio are changed. If they have changed and have stayed that way for at least 2 seconds, the change is saved to disc.
void HDControl::startChangeMonitor | ( | ) |
Start the separate thread that monitors whether or not settings have been changed.
void HDControl::saveState | ( | ) |
Save the current state, including favorites, to the user config file.
void HDControl::restoreState | ( | ) |
Load the state from the user config file and set the radio to match that state. This lets us start up in the same state we were shut down in.
void HDControl::addToFavorites | ( | ) |
Add the current station to the favorites list without specifying a specific call sign or station name. The HD callsign and name will be used if available, if not, the RDS program service will be used for the call sign and the RDS text will be used for the name.
void HDControl::addToFavorites | ( | string | name | ) |
Add the current station to the list of favorits with the specified name. For more info, see hd_addtofavorites().
void HDControl::CreateFavorite | ( | string | tuneinfo | ) |
Create a new favorite. This can be done by specifying the tune info in our standard tune format (like "88.9:1 FM", with or without the decimal point and the colon and subchannel number are optional). This allows defining a favorite even if we're not tuned to it.
tuneinfo | the tuning info specifying the frequency, subchannel, and band |
void HDControl::createFavorite | ( | string | tuneinfo, | |
string | callsign | |||
) |
Create a new favorite. This can be done by specifying the tune info in our standard tune format (like "88.9:1 FM", with or without the decimal point and the colon and subchannel number are optional). This allows defining a favorite even if we're not tuned to it.
tuneinfo | the tuning info specifying the frequency, subchannel, and band | |
callsign | the call sign to be used (which will default to being the station name, too) |
void HDControl::createFavorite | ( | string | tuneinfo, | |
string | callsign, | |||
string | name | |||
) |
Create a new favorite. This can be done by specifying the tune info in our standard tune format (like "88.9:1 FM", with or without the decimal point and the colon and subchannel number are optional). This allows defining a favorite even if we're not tuned to it.
tuneinfo | the tuning info specifying the frequency, subchannel, and band | |
callsign | the call sign to be used | |
name | the name to use for this station |
void HDControl::saveFavorites | ( | ) |
Save all the favorites by setting them in the config object then saving it to the config file.
void HDControl::getFavorites | ( | ) |
Get the favorites from the config object and set up the values so we can access them easily.
void HDControl::removeFavorite | ( | string | name | ) |
Remove a favorite from the list, then save the favorites so it won't appear again when the radio is turned on again.
name | the name of the favorite to remove |
void HDControl::renameFavorite | ( | string | oldname, | |
string | newname | |||
) |
Rename a favorite station to a different name.
oldname | the current name of the favorite | |
newname | the new name to use for this favorite |
void HDControl::setToFavorite | ( | string | favname | ) |
Set the radio to the named favorite station.
favname | name of favorite to set to |
vector< string > HDControl::getAllKeys | ( | ) |
Get a list of all the keys to all the variables that we have currently.
bool HDControl::command_line | ( | string | commandLine | ) |
Parses the command given it. Args are separated by spaces. Returns false only if command was to exit the radio, which could include turning if off, but it's up to the caller to make that decision. Shutting down the program and leaving the radio on could be a Bad Thing (tm) unless provisions are made to be sure it can be easily turned off otherwise.
This allows easy parsing of commands from a keyboard but can also be used instead of calling individual commands to automatically count the arguments and dispatch the proper command.
commandline | a line, as if typed in from the keyboard, containing a command and arguments |
bool HDControl::command | ( | string | cmd | ) |
Dispatch commands with no arguments to the appropriate function. This and the other command() functions can be used instead of the individual command functions as a quick way to dispatch various commands.
bool HDControl::command | ( | string | cmd, | |
string | arg1 | |||
) |
Dispatch commands with 1 argument to the proper function.
cmd | the command to send to the radio | |
arg1 | the only argument to pass on with the command |
bool HDControl::command | ( | string | cmd, | |
int | arg1 | |||
) |
Take an argument given to us with an int as the arg and convert it to a string so it can be processed like all other commands.
cmd | the command to send to the radio | |
arg1 | the only argument to pass on with the command |
bool HDControl::command | ( | string | cmd, | |
string | arg1, | |||
string | arg2 | |||
) |
Dispatch commands with 2 arguments to the proper function.
cmd | the command to send to the radio | |
arg1 | the first argument to pass on with the command | |
arg2 | the 2nd argument to pass on |
bool HDControl::command | ( | string | cmd, | |
int | arg1, | |||
string | arg2 | |||
) |
Take an argument given to us with an int as the 1st arg and convert it to a string so it can be processed like all other commands.
cmd | the command to send to the radio | |
arg1 | the first argument to pass on with the command | |
arg2 | the 2nd argument to pass on |
void HDControl::radioOn | ( | ) |
Turn the radio on.
void HDControl::radioOff | ( | ) |
Turn the radio off.
void HDControl::muteOn | ( | ) |
Turn the mute on.
void HDControl::muteOff | ( | ) |
Turn the mute off
void HDControl::hd_setvolume | ( | int | newlevel | ) |
Set the volume. We take a scale of 0-100, but it is internally converted to a scale of 0-90, which is what the radio accepts. That means some values, such as 9 and 10, 19 and 20, and so on (each ending in 9 and the next one) will result in the same level. (This is because integer division is used in the conversion.)
newlevel | the level to set the volume to |
void HDControl::hd_setvolume | ( | string | newlevel | ) |
Set the volume. We take a scale of 0-100, but it is internally converted to a scale of 0-90, which is what the radio accepts. That means some values, such as 9 and 10, 19 and 20, and so on (each ending in 9 and the next one) will result in the same level. (This is because integer division is used in the conversion.)
newlevel | the level to set the volume to (will be converted to an int) |
void HDControl::hd_setbass | ( | int | newlevel | ) |
Set the bass. We take a scale of 0-100, but it is internally converted to a scale of 0-90, which is what the radio accepts. That means some values, such as 9 and 10, 19 and 20, and so on (each ending in 9 and the next one) will result in the same level. (This is because integer division is used in the conversion.)
newlevel | the level to set the bass to |
void HDControl::hd_setbass | ( | string | newlevel | ) |
Set the bass. We take a scale of 0-100, but it is internally converted to a scale of 0-90, which is what the radio accepts. That means some values, such as 9 and 10, 19 and 20, and so on (each ending in 9 and the next one) will result in the same level. (This is because integer division is used in the conversion.)
newlevel | the level to set the bass to (will be converted to an int) |
void HDControl::hd_settreble | ( | int | newlevel | ) |
Set the treble. We take a scale of 0-100, but it is internally converted to a scale of 0-90, which is what the radio accepts. That means some values, such as 9 and 10, 19 and 20, and so on (each ending in 9 and the next one) will result in the same level. (This is because integer division is used in the conversion.)
newlevel | the level to set the treble to |
void HDControl::hd_settreble | ( | string | newlevel | ) |
Set the treble. We take a scale of 0-100, but it is internally converted to a scale of 0-90, which is what the radio accepts. That means some values, such as 9 and 10, 19 and 20, and so on (each ending in 9 and the next one) will result in the same level. (This is because integer division is used in the conversion.)
newlevel | the level to set the treble to (will be converted to an int) |
void HDControl::tunetodefault | ( | ) |
Tune directly to the default station and subchannel. By default this is set to WCVE-FM (classical and jazz) in Richmond, VA, where the original program author lives. The values can be changed in the config files. The main purpose was to make it easier to tune to a station while testing and debugging.
void HDControl::hd_tuneup | ( | ) |
Tune one unit up. If there are hdsubchannels, it'll turn up to the next subchannel, otherwise it'll turn up to the next frequency.
void HDControl::hd_tunedown | ( | ) |
Tune one unit down. If there are hdsubchannels, it'll turn down to the next subchannel, otherwise it'll turn down to the next frequency.
void HDControl::hd_subchannel | ( | int | newchannel | ) |
Specify an HD subchannel. If there is no HD streamlock or if that subchannel does not exist or can't be locked on to, nothing will happen.
newchannel | channel to tune to in string form |
void HDControl::hd_subchannel | ( | string | newchannel | ) |
Specify an HD subchannel. If there is no HD streamlock or if that subchannel does not exist or can't be locked on to, nothing will happen.
newchannel | channel to tune to |
void HDControl::hd_seekup | ( | ) |
Seek up the dial for the next subchannel or frequency.
void HDControl::hd_seekdown | ( | ) |
Seek down the dial for the next subchannel or frequency.
void HDControl::hd_seekall | ( | ) |
Specify to seek all stations when seeking (the default). Any station with a strong enough signal will be sought.
void HDControl::hd_seekhd | ( | ) |
Specify to seek only HD stations when seeking. (Not the default.)
void HDControl::request_power | ( | ) |
Ask the radio to send us its power setting.
void HDControl::request_volume | ( | ) |
Ask the radio to send us its volume setting.
void HDControl::request_mute | ( | ) |
Ask the radio to send us its mute setting.
void HDControl::request_bass | ( | ) |
Ask the radio to send us its bass setting.
void HDControl::request_treble | ( | ) |
Ask the radio to send us its treble setting.
void HDControl::request_tune | ( | ) |
Ask the radio to send us its current tuner setting.
void HDControl::request_hdsubchannelcount | ( | ) |
Ask the radio to send us the subchannel count for this station.
void HDControl::request_hdsubchannel | ( | ) |
Ask the radio to send us the current subchannel.
void HDControl::request_hdstationname | ( | ) |
Ask the radio to send us the current station name
void HDControl::request_hdcallsign | ( | ) |
Ask the radio to send us the current station call sign
void HDControl::request_hduniqueid | ( | ) |
Ask the radio to send us its HD unique ID.
void HDControl::request_hdtitle | ( | ) |
Ask the radio to send us the current HD title info
void HDControl::request_hdartist | ( | ) |
Ask the radio to send us the current HD artist info
void HDControl::request_hdsignalstrenth | ( | ) |
Ask the radio to send us the strength of the current HD signal
void HDControl::request_hdstreamlock | ( | ) |
Ask the radio to send us the status of the HD stream lock
void HDControl::request_hdactive | ( | ) |
Ask the radio to send us whether HD is active on this station or not
void HDControl::request_hdtunerenabled | ( | ) |
Ask the radio to send us whether the HD tuner is enabled or not
void HDControl::request_apiversion | ( | ) |
Ask the radio to send us its API version.
void HDControl::request_hwversion | ( | ) |
Ask the radio to send us its hardware version.
void HDControl::request_rdsenable | ( | ) |
Ask the radio to send us whether RDS is enabled on this station
void HDControl::request_rdsservice | ( | ) |
Ask the radio to send us the RDS programming service for this station
void HDControl::request_rdstext | ( | ) |
Ask the radio to send us the current RDS text for this station
void HDControl::request_rdsgenre | ( | ) |
Ask the radio to send us the RDS genre for this station.
void HDControl::showdtr | ( | ) |
void HDControl::toggledtr | ( | string | arg | ) |
Mainly for debugging: switch the DTR to a specific state
arg | set to true/1/high to turn DTR on, anything else for off |
void HDControl::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".
hangup | true to turn off the radio on exit, false to leave it on |
string HDControl::getValue | ( | string | valname | ) |
Get a specified value from OUR current variables. This does not ask the radio to send us a value, it asks for our current value of the specified variable.
valname | name of variable/value wanted |
string HDControl::getPower | ( | ) |
Get the power status from our current settings list.
string HDControl::getVolume | ( | ) |
Get the volume status from our current settings list. The radio uses a scale of 0-90 but we conver to a scale of 0-100.
string HDControl::getBass | ( | ) |
Get the bass status from our current settings list. The radio uses a scale of 0-90 but we conver to a scale of 0-100.
string HDControl::getTreble | ( | ) |
Get the treble status from our current settings list. The radio uses a scale of 0-90 but we conver to a scale of 0-100.
string HDControl::getMute | ( | ) |
Get the mute status from our current settings list.
string HDControl::getFrequency | ( | ) |
Get the frequency status from our current settings list. (Only the frequency, not the band or a subchannel.) This is returned as a string, but it's an int in style since the decimal point on any FM frequencies is removed.
string HDControl::getBand | ( | ) |
Get the band status from our current settings list.
string HDControl::getHDSubchannel | ( | ) |
Get the subchannel status from our current settings list.
string HDControl::getTune | ( | ) |
Get the tune setting from our current settings list. It'll be in a format like "88.9:1 FM". This string could also be given to tune() to tune to a station. The first 3 digits (and decimal point) are the frequency, the digit after the colon (could be 2, but not by today's standards) is the hdsubchannel and the last 2 characters are the band.
string HDControl::getHDActive | ( | ) |
Get the ative status for the hd signal from our current settings list.
string HDControl::getHDStreamlock | ( | ) |
Get the streamlock status from our current settings list. If this is true, we have a lock on the hdsubchannel, if not, we don't.
string HDControl::getHDSignalStrength | ( | ) |
Get the strength of the hd signal from our current settings list.
string HDControl::getHDSubchannelCount | ( | ) |
Get the number of subchannels available for the current frequency.
string HDControl::getHDEnableTuner | ( | ) |
Get if the tuner is currently hd enabled. It's unclear if this means the tuner can get an hd signal or is receiving it.
string HDControl::getHDCallSign | ( | ) |
Get the call sign as provided by hd data from the current station.
string HDControl::getHDStationName | ( | ) |
Get the station name as provided by hd data from the current station.
string HDControl::getHDUniqueID | ( | ) |
Get the HD unique ID. It is unclear if this is a radio model number, a serial number, or something else.
string HDControl::getHDAPIVersion | ( | ) |
Get the API version of the radio.
string HDControl::getHDHWVersion | ( | ) |
Get the hardware version for this radio.
string HDControl::getRDSEnable | ( | ) |
Get info on whether the RDS is available for this channel.
string HDControl::getRDSGenre | ( | ) |
Get the RDS genre string describing the current station from our settings. It is reset with each tune change so it is either an empty string or current. RDS data is not as reliable as HD data and can often drop characters or have incorrect characters.
string HDControl::getRDSProgramService | ( | ) |
Get the RDS programming service string describing the current station from our settings. It is reset with each tune change so it is either an empty string or current. RDS data is not as reliable as HD data and can often drop characters or have incorrect characters.
string HDControl::getRDSRadioText | ( | ) |
Get the RDS radio text describing the current station from our settings. It is reset with each tune change so it is either an empty string or current. RDS data is not as reliable as HD data and can often drop characters or have incorrect characters.
string HDControl::getHDTitle | ( | ) |
Get the title on the current hd channel.
string HDControl::getHDTitle | ( | int | channel | ) |
Get the title on a specific hd channel.
channel | the channel to get the title name for |
map< int, string > HDControl::getHDTitles | ( | ) |
The test radio returned the artist and title for all the hdsubchannels on a particular frequency, not just the current one. This returns a list of all the titles on all the subchannels;
string HDControl::getHDArtist | ( | ) |
Get the artist on the current hd channel.
string HDControl::getHDArtist | ( | int | channel | ) |
Get the artist on a specific hd channel.
channel | to get the artist name for |
map< int, string > HDControl::getHDArtists | ( | ) |
The test radio returned the artist and title for all the hdsubchannels on a particular frequency, not just the current one. This returns a list of all the artists on all the subchannels;
void HDControl::parseDevices | ( | string | devline, | |
bool | isdev | |||
) | [private] |
Parse any list of dev info. Used only during activation.
devline | the line listing all the devices or device types | |
isdev | true if it's devices, false for device types |
string HDControl::intToString | ( | int | num | ) | [private] |
Utility function to convert an integer to a string.
num | the number to conver to to a string. |
bool HDControl::verbose [private] |
string HDControl::deffreq [private] |
string HDControl::defband [private] |
string HDControl::mainconfigfile [private] |
string HDControl::sessionconfigfile [private] |
string HDControl::defaultserial [private] |
vector<string> HDControl::defkeys [private] |
vector<string> HDControl::defcmds [private] |
vector<string> HDControl::favorites [private] |
map<string,string> HDControl::favcall [private] |
map<string,string> HDControl::favname [private] |
map<string,string> HDControl::favnameback [private] |
pthread_t HDControl::t_ChangeMonitor [private] |
LinuxPort HDControl::ioPort [private] |
ConfigFile HDControl::mainConfig [private] |
HDListen HDControl::hdListen [private] |
HDVals HDControl::hdValues [private] |
HDCommands HDControl::hdCommand [private] |