Go to the documentation of this file.00001
00027 #ifndef URSA_DRIVER_H_
00028 #define URSA_DRIVER_H_
00029
00030
00031
00032 #include <boost/lexical_cast.hpp>
00033 #include <boost/array.hpp>
00034 #include <boost/thread/mutex.hpp>
00035 #include <boost/algorithm/string/trim.hpp>
00036 #include <boost/thread/lock_guard.hpp>
00037
00038 #include <stdint.h>
00039 #include <queue>
00040 #include <iostream>
00041 #include <sstream>
00042
00043 #include <serial/serial.h>
00044
00045 namespace serial
00046 {
00047 class Serial;
00048 }
00049
00051 namespace ursa
00052 {
00057 enum inputs
00058 {
00059 INPUT1NEG = 0,
00060 INPUT1POS,
00061 INPUT2NEG,
00062 INPUT2POS,
00063 INPUTXPOS
00064 };
00065
00070 enum shaping_time
00071 {
00072 TIME0_25uS = 0,
00073 TIME0_5uS,
00074 TIME1uS,
00075 TIME2uS,
00076 TIME4uS,
00077 TIME6uS,
00078 TIME8uS,
00079 TIME10uS
00080 };
00081
00083 class Interface
00084 {
00085
00086 private:
00087 const char *port_;
00088 int baud_;
00089 bool connected_;
00090 bool responsive_;
00091 bool acquiring_;
00092 bool gmMode_;
00093 serial::Serial *serial_;
00094 std::stringstream tx_buffer_;
00095 std::deque<uint8_t> rx_buffer_;
00096
00097 float battV_;
00098
00099 int ramp_;
00100 int voltage_;
00101
00102 boost::mutex array_mutex_;
00103 boost::array<uint32_t, 4096> pulses_;
00104
00109 bool checkComms();
00110
00111 void transmit();
00112 void processData();
00113 void processBatt(uint16_t input);
00114
00115 public:
00121 Interface(const char *port, int baud);
00122 ~Interface();
00123
00124 void read();
00125
00128 void getSpectra(boost::array<uint32_t, 4096>* array);
00129 void clearSpectra();
00130
00131 void connect();
00132
00138 bool connected() {
00139 if (connected_)
00140 {
00141 if (responsive_)
00142 return (true);
00143 else
00144 return (checkComms());
00145 }
00146 else
00147 return (false);
00148 }
00150 bool acquiring() {
00151 return (acquiring_);
00152 }
00153
00154 void startAcquire();
00155 void stopAcquire();
00156
00157 void startGM();
00158 void stopGM();
00159
00163 uint32_t requestCounts();
00164
00165 void stopVoltage();
00166
00167 void requestBatt();
00168
00171 float getBatt();
00172
00177 void startASCII();
00178 void stopASCII();
00179
00183 int requestSerialNumber();
00184
00185 void requestMaxHV();
00186 #ifdef ADMIN_ // These functions should normally only be executed by factory personal.
00187
00190 void setSerialNumber(int serial);
00194 void setSmudgeFactor(int smudge);
00199 void setMaxHV(int HV);
00200 #endif
00201
00202 void loadPrevSettings();
00203 void setNoSave();
00204 void setVoltage(int voltage);
00205 void setGain(double gain);
00206 void setInput(inputs input);
00207 void setShapingTime(shaping_time time);
00208 void setThresholdOffset(int mVolts);
00209
00210 void setBitMode(int bits);
00211 void setRamp(int seconds);
00212 void noRamp();
00213
00218 void setAlarm0(bool enable);
00223 void setAlarm1(bool enable);
00224 };
00225
00226 }
00227
00228 #endif