The interface class implements a link to the ursa hardware. More...
#include <ursa_driver.h>
Public Member Functions | |
bool | acquiring () |
A utility function to check if the driver is acquiring. | |
void | clearSpectra () |
A utility function to clear the internal Interface::pulses_ array. | |
void | connect () |
Opens the serial port and attempts to confirm communication to the Ursa. | |
bool | connected () |
A utility function to check the status of the connection to the Ursa. | |
float | getBatt () |
An access function which returns the last successful battery voltage reading. | |
void | getSpectra (boost::array< uint32_t, 4096 > *array) |
Access function which returns by reference a copy of the spectra data. | |
Interface (const char *port, int baud) | |
Interface constructor. | |
void | loadPrevSettings () |
A function to load previously set settings from EEPROM. | |
void | noRamp () |
Disables ramping of high voltage. | |
void | read () |
A utility function to flush the input buffer and process the data. | |
void | requestBatt () |
Sends a request to the Ursa to report the batteries voltage. | |
uint32_t | requestCounts () |
In GM mode; Returns the number of counts since the last call to requestCounts(). | |
void | requestMaxHV () |
This is a utility function to request the maximum HV capable by the Ursa. | |
int | requestSerialNumber () |
Requests the serial number of the connected Ursa. | |
void | setAlarm0 (bool enable) |
void | setAlarm1 (bool enable) |
void | setBitMode (int bits) |
This function sets the number of bits used for acquisition. | |
void | setGain (double gain) |
This function will set the gain of the MCA. | |
void | setInput (inputs input) |
This function sets the input and polarity of the ursa. | |
void | setNoSave () |
This function instructs the Ursa to not save the next instructed HV to EEPROM. | |
void | setRamp (int seconds) |
This function will set the ramping time for the HV. | |
void | setShapingTime (shaping_time time) |
This function sets the shaping time of the ursa. | |
void | setThresholdOffset (int mVolts) |
This function sets the threshold and offset of the ursa. | |
void | setVoltage (int voltage) |
This function instructs the ursa to enable high voltage. | |
void | startAcquire () |
Instructs the Ursa to start acquiring. | |
void | startASCII () |
Instructs Ursa to run in ASCII mode. | |
void | startGM () |
Instructs the Ursa to start acquiring in Gieger Muller mode. | |
void | stopAcquire () |
Instructs the Ursa to stop acquiring. | |
void | stopASCII () |
Switches Ursa out of ASCII mode. | |
void | stopGM () |
Instructs the Ursa to stop acquiring and to switch out of Geiger Muller Mode. | |
void | stopVoltage () |
Immediately sets High Voltage to zero. This is not stored to EEPROM. | |
~Interface () | |
Interface destructor. | |
Private Member Functions | |
bool | checkComms () |
Private function which checks to see if Ursa will respond to communication. | |
void | processBatt (uint16_t input) |
Private utility function which processes a battery voltage message if in acquire mode. | |
void | processData () |
Private utility function which processes incoming data. | |
void | transmit () |
Private utility function for flushing the transmit buffer down the line. | |
Private Attributes | |
bool | acquiring_ |
A boolean which marks when the ursa is acquiring. | |
boost::mutex | array_mutex_ |
The locking mechanism for the spectrum array. | |
float | battV_ |
The current Battery voltage. This is NOT the 12v input voltage. | |
int | baud_ |
The baud rate that Ursa communicates at. This is always 115200. | |
bool | connected_ |
A boolean signaling if the Interface successfully connected. | |
bool | gmMode_ |
A boolean which reports if the ursa is in GM mode. | |
const char * | port_ |
The Serial port that the Ursa is connected to. | |
boost::array< uint32_t, 4096 > | pulses_ |
An array of the pulses received in each bin. This consists of 4096 32 bit unsigned integers. | |
int | ramp_ |
The ramp time in seconds per 100 volts. | |
bool | responsive_ |
A boolean signaling if the Ursa has responded to the Interface. | |
std::deque< uint8_t > | rx_buffer_ |
A Character buffer for incoming data. | |
serial::Serial * | serial_ |
A serial object which controls comunication to the serial port. | |
std::stringstream | tx_buffer_ |
A String buffer for output commands. | |
int | voltage_ |
The currently set high voltage. |
The interface class implements a link to the ursa hardware.
Definition at line 83 of file ursa_driver.h.
ursa::Interface::Interface | ( | const char * | port, |
int | baud | ||
) |
Interface constructor.
All private variables are initialized to zero or there initial values. The pulses_ array is filled with zeros.
port | The port that the Ursa hardware is connected to. |
baud | Baud rate to communicate to the Ursa with. |
Definition at line 34 of file ursa_driver.cpp.
Interface destructor.
Stops acquire mode and immediately disables voltage if still enabled.
Definition at line 44 of file ursa_driver.cpp.
bool ursa::Interface::acquiring | ( | ) | [inline] |
A utility function to check if the driver is acquiring.
Definition at line 150 of file ursa_driver.h.
bool ursa::Interface::checkComms | ( | ) | [private] |
Private function which checks to see if Ursa will respond to communication.
This function requires that the serial port be already opened. It sends a "U" and the correct response from the Ursa is URSA2. If this is what is received the function responds true otherwise it returns false.
Definition at line 245 of file ursa_driver.cpp.
void ursa::Interface::clearSpectra | ( | ) |
A utility function to clear the internal Interface::pulses_ array.
This function sets all elements in the pulses_ array to zero using a boost:lock_gaurd to prevent multiple access errors.
Definition at line 222 of file ursa_driver.cpp.
void ursa::Interface::connect | ( | ) |
Opens the serial port and attempts to confirm communication to the Ursa.
This function first creates a new serial object. Then sets the timeout, port and baud rate. The timeout is a global attribute for the serial port. Changing it will change the behavior of waitReadable and therefore the function of many of the Interfaces functions.
The function then tries 5 times to open the port and if successful it sends a stop acquire command down the line then checks to see that the port is still open. If this is successful Interface::connected_ is set to true
It then tries calling checkComms 5 times. If this is successful Interface::responsive_ is set to true.
If either fail an error is writen to cout.
Definition at line 60 of file ursa_driver.cpp.
bool ursa::Interface::connected | ( | ) | [inline] |
A utility function to check the status of the connection to the Ursa.
The function will attempt to check responsiveness if Interface::responsive_ is false using the Interface::checkComms() function.
Definition at line 138 of file ursa_driver.h.
float ursa::Interface::getBatt | ( | ) |
An access function which returns the last successful battery voltage reading.
Definition at line 374 of file ursa_driver.cpp.
void ursa::Interface::getSpectra | ( | boost::array< uint32_t, 4096 > * | array | ) |
Access function which returns by reference a copy of the spectra data.
array | The array to fill with spectra data. |
The function uses a boost::lock_gaurd before copying to protect against multiple access errors. This should help in the future if multithreading is implemented.
Definition at line 214 of file ursa_driver.cpp.
void ursa::Interface::loadPrevSettings | ( | ) |
A function to load previously set settings from EEPROM.
This will set the high voltage, gain, input and polarity, shaping time, and threshold and offset.
This function will then wait for the ursa to become responsive after its call because the high voltage could be ramping.
See: setVoltage().
Definition at line 498 of file ursa_driver.cpp.
void ursa::Interface::noRamp | ( | ) |
Disables ramping of high voltage.
Definition at line 763 of file ursa_driver.cpp.
void ursa::Interface::processBatt | ( | uint16_t | input | ) | [private] |
Private utility function which processes a battery voltage message if in acquire mode.
Called from processData(). The reading is multiplied by 12/1024 to get volts.
input | The 10 bit battery voltage data |
Definition at line 231 of file ursa_driver.cpp.
void ursa::Interface::processData | ( | ) | [private] |
Private utility function which processes incoming data.
This function processes incoming data in acquire mode. The spectra data comes in as 3 bytes starting with 0xFF then a 4 bit count and then 12 bits of energy. The 12 bit energy is used as an index for the Interface::pulses_ array which is incremented by the 4 bit count.
If the top 6 bits of the second byte is 0 the data is 10bit battery data and can be treated as such. This function loops until there is less than 3 bytes in the receive buffer.
If the first byte is not 0xFF then bytes are dropped until there is a 0xFF on the front of the buffer.
If DEBUG_ is enabled then each increment of the pulses_ array is reported to std::cout.
Definition at line 165 of file ursa_driver.cpp.
void ursa::Interface::read | ( | ) |
A utility function to flush the input buffer and process the data.
This uses a while loop to read a buffer of length max_line_length from the serial buffer. This is copied into the rx_buffer buffer.
If DEBUG_ enable prints out the length of the rx_buffer after filling it.
Commented out line will print the input buffer straight to cout.
Definition at line 138 of file ursa_driver.cpp.
void ursa::Interface::requestBatt | ( | ) |
Sends a request to the Ursa to report the batteries voltage.
The battery voltage is reported to the driver differently depending on if the driver is in acquire mode. When not acquiring the battery voltage is updated immediately. When acquiring the voltage will be processed as part of the Interface::read() call.
In either case to get the voltage see: Interface::getBatt.
Definition at line 348 of file ursa_driver.cpp.
uint32_t ursa::Interface::requestCounts | ( | ) |
In GM mode; Returns the number of counts since the last call to requestCounts().
This function will only work in GM mode and while acquiring. The number of counts counted since the last time this function was called is returned via serial as 4 bytes. This function then combines the 4 bytes into one 32 but number and returns the number.
If the number of bytes in the serial buffer is not 4 an error is written to cout.
Definition at line 308 of file ursa_driver.cpp.
void ursa::Interface::requestMaxHV | ( | ) |
This is a utility function to request the maximum HV capable by the Ursa.
This function is mainly used by the original software to determine the ratio for setting the high voltage. The max HV is almost always 2000.
Definition at line 424 of file ursa_driver.cpp.
Requests the serial number of the connected Ursa.
Definition at line 400 of file ursa_driver.cpp.
void ursa::Interface::setAlarm0 | ( | bool | enable | ) |
Enables or disables alarm 0 output on the ursa.
enable | Enable or disable as a bool. |
Definition at line 774 of file ursa_driver.cpp.
void ursa::Interface::setAlarm1 | ( | bool | enable | ) |
Enables or disables alarm 1 output on the ursa.
enable | Enable or disabel as a bool. |
Definition at line 779 of file ursa_driver.cpp.
void ursa::Interface::setBitMode | ( | int | bits | ) |
This function sets the number of bits used for acquisition.
The ursa can use between 8 and 12 bits of resolution for energy readings. The power up condition of the usra is 12 bits.
This function can only be used when not in acquire mode.
bits | The number of bits to use as an int. |
Definition at line 727 of file ursa_driver.cpp.
void ursa::Interface::setGain | ( | double | gain | ) |
This function will set the gain of the MCA.
This function takes a gain between 0 and 250 x and commands the ursa to adjust its internal gain.
This function can only be used when not in acquire mode.
This parameter is stored to EEPROM.
gain | the desired gain as a double |
Definition at line 585 of file ursa_driver.cpp.
void ursa::Interface::setInput | ( | inputs | input | ) |
This function sets the input and polarity of the ursa.
This function takes in a ursa::inputs and commands the ursa to change its input and polarity. The input can be 1 or 2 positive or negative. The input can also be either input with a preshaped pulse. See: ursa::INPUTXPOS.
This function can only be used when not in acquire mode.
This parameter is stored to EEPROM.
input | The desired input and polarity as a ursa:inputs. |
Definition at line 655 of file ursa_driver.cpp.
void ursa::Interface::setNoSave | ( | ) |
This function instructs the Ursa to not save the next instructed HV to EEPROM.
Definition at line 521 of file ursa_driver.cpp.
void ursa::Interface::setRamp | ( | int | seconds | ) |
This function will set the ramping time for the HV.
This function will take in a ramping time in seconds per 100 volts. So that a ramp of 6 seconds to 900 volts will take 54 seconds. The time must be between 6 and 219 seconds.
This function can only be used when not in acquire mode.
seconds | The ramping time in seconds as an int. |
Definition at line 747 of file ursa_driver.cpp.
void ursa::Interface::setShapingTime | ( | shaping_time | time | ) |
This function sets the shaping time of the ursa.
This function takes a ursa::shaping_time and instructs the ursa to change its internal shaping time. A 1uS shaping time is appropriate for most sensors used with the ursa.
This function can only be used when not in acquire mode.
This parameter is stored to EEPROM.
time | The shaping time as an ursa::shaping_time |
Definition at line 677 of file ursa_driver.cpp.
void ursa::Interface::setThresholdOffset | ( | int | mVolts | ) |
This function sets the threshold and offset of the ursa.
This function takes in a threshold as millivolts and calculates the offset. It then instructs the ursa to change its internal value. The voltage must be between 25 and 1024 mV.
This function can only be used when not in acquire mode.
This parameter is stored to EEPROM
mVolts | The threshold in millivolts as an int. |
Definition at line 697 of file ursa_driver.cpp.
void ursa::Interface::setVoltage | ( | int | voltage | ) |
This function instructs the ursa to enable high voltage.
This function will send a command to the ursa to enable high voltage. The ursa will use the ramping time which must be set prior to calling this function. If no ramping time is set the high voltage will ramp as fast as it can.
While the ursa is ramping it cannot respond to any command. This function will block and wait till the ursa is responsive again. While it waits an approximation of the time remaining will be printed to std::cout.
This function can only be called when not in acquire mode.
This parameter is stored to EEPROM.
voltage | The voltage to ramp to as an int. |
Definition at line 545 of file ursa_driver.cpp.
void ursa::Interface::startAcquire | ( | ) |
Instructs the Ursa to start acquiring.
Definition at line 270 of file ursa_driver.cpp.
void ursa::Interface::startASCII | ( | ) |
Instructs Ursa to run in ASCII mode.
This driver can't process data in ASCII mode so this function is only included for completeness.
Definition at line 378 of file ursa_driver.cpp.
void ursa::Interface::startGM | ( | ) |
Instructs the Ursa to start acquiring in Gieger Muller mode.
Definition at line 281 of file ursa_driver.cpp.
void ursa::Interface::stopAcquire | ( | ) |
Instructs the Ursa to stop acquiring.
Definition at line 258 of file ursa_driver.cpp.
void ursa::Interface::stopASCII | ( | ) |
Switches Ursa out of ASCII mode.
Definition at line 389 of file ursa_driver.cpp.
void ursa::Interface::stopGM | ( | ) |
Instructs the Ursa to stop acquiring and to switch out of Geiger Muller Mode.
Definition at line 293 of file ursa_driver.cpp.
void ursa::Interface::stopVoltage | ( | ) |
Immediately sets High Voltage to zero. This is not stored to EEPROM.
Definition at line 338 of file ursa_driver.cpp.
void ursa::Interface::transmit | ( | ) | [private] |
Private utility function for flushing the transmit buffer down the line.
This function writes the whole output buffer to the serial port as a string. It will write an error to cout if a serial timeout occurs. With DEBUG_ enabled it will write the buffer to std::cout.
Definition at line 116 of file ursa_driver.cpp.
bool ursa::Interface::acquiring_ [private] |
A boolean which marks when the ursa is acquiring.
Definition at line 91 of file ursa_driver.h.
boost::mutex ursa::Interface::array_mutex_ [private] |
The locking mechanism for the spectrum array.
Definition at line 102 of file ursa_driver.h.
float ursa::Interface::battV_ [private] |
The current Battery voltage. This is NOT the 12v input voltage.
Definition at line 97 of file ursa_driver.h.
int ursa::Interface::baud_ [private] |
The baud rate that Ursa communicates at. This is always 115200.
Definition at line 88 of file ursa_driver.h.
bool ursa::Interface::connected_ [private] |
A boolean signaling if the Interface successfully connected.
Definition at line 89 of file ursa_driver.h.
bool ursa::Interface::gmMode_ [private] |
A boolean which reports if the ursa is in GM mode.
Definition at line 92 of file ursa_driver.h.
const char* ursa::Interface::port_ [private] |
The Serial port that the Ursa is connected to.
Definition at line 87 of file ursa_driver.h.
boost::array<uint32_t, 4096> ursa::Interface::pulses_ [private] |
An array of the pulses received in each bin. This consists of 4096 32 bit unsigned integers.
Definition at line 103 of file ursa_driver.h.
int ursa::Interface::ramp_ [private] |
The ramp time in seconds per 100 volts.
Definition at line 99 of file ursa_driver.h.
bool ursa::Interface::responsive_ [private] |
A boolean signaling if the Ursa has responded to the Interface.
Definition at line 90 of file ursa_driver.h.
std::deque<uint8_t> ursa::Interface::rx_buffer_ [private] |
A Character buffer for incoming data.
Definition at line 95 of file ursa_driver.h.
serial::Serial* ursa::Interface::serial_ [private] |
A serial object which controls comunication to the serial port.
Definition at line 93 of file ursa_driver.h.
std::stringstream ursa::Interface::tx_buffer_ [private] |
A String buffer for output commands.
Definition at line 94 of file ursa_driver.h.
int ursa::Interface::voltage_ [private] |
The currently set high voltage.
Definition at line 100 of file ursa_driver.h.