14 #ifndef PULSERDRIVERNIDAQMX_H_
15 #define PULSERDRIVERNIDAQMX_H_
17 #include "pulserdriver.h"
19 #include "nidaqmxdriver.h"
24 typedef ptrdiff_t ssize_t;
30 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas);
34 virtual double resolution()
const {
return m_resolutionDO;}
37 enum { NUM_AO_CH = 2};
38 enum { CAL_POLY_ORDER = 4};
41 typedef uInt16 tRawDO;
44 pattern(pat),
tonext(next) {}
55 shared_ptr<std::vector<tRawAOSet> > m_genPulseWaveNextAO[PAT_QAM_MASK / PAT_QAM_PHASE];
60 virtual
void close() throw (XKameError &);
62 double resolutionQAM()
const {
return m_resolutionAO;}
66 virtual const shared_ptr<XNIDAQmxInterface> &intfDO()
const {
return interface();}
67 virtual const shared_ptr<XNIDAQmxInterface> &intfAO()
const {
return interface();}
68 virtual const shared_ptr<XNIDAQmxInterface> &intfCtr()
const {
return interface();}
78 void openDO(
bool use_ao_clock =
false) throw (
XKameError &);
79 void openAODO() throw (XKameError &);
81 void startPulseGen(const
Snapshot &shot) throw (XKameError &);
85 void stopPulseGenFreeRunning(
unsigned int blankpattern);
86 void startPulseGenFromFreeRun(const
Snapshot &shot);
89 void setupTasksDO(
bool use_ao_clock);
90 void setupTasksAODO();
92 static int32 onTaskDone_(TaskHandle task, int32 status,
void*);
93 void onTaskDone(TaskHandle task, int32 status);
95 shared_ptr<std::vector<GenPattern> > m_genPatternList;
97 typedef std::vector<GenPattern>::iterator GenPatternIterator;
98 GenPatternIterator m_genLastPatIt;
103 unsigned int m_aswBit;
104 unsigned int m_pausingCount;
109 unsigned int m_preFillSizeAO;
111 unsigned int m_transferSizeHintAO;
121 double m_resolutionDO, m_resolutionAO;
122 TaskHandle m_taskAO, m_taskDO,
123 m_taskDOCtr, m_taskGateCtr;
125 enum {PORTSEL_PAUSING = 17};
127 template <
typename T>
129 enum {CHUNK_DIVISOR = 16};
130 void reserve(ssize_t s) {m_data.resize(s); m_curReadPos = 0; m_endOfWritten = 0; m_end = s;}
131 const T*curReadPos() {
132 if((m_endOfWritten < m_curReadPos) && (m_curReadPos == m_end))
134 return &m_data[m_curReadPos];
136 ssize_t writtenSize()
const {
137 ssize_t end_of_written = m_endOfWritten;
138 if(m_curReadPos <= end_of_written) {
139 return end_of_written - m_curReadPos;
141 return m_end - m_curReadPos;
145 ssize_t p = m_curReadPos + size_read;
150 return m_data.size() / CHUNK_DIVISOR;
153 ssize_t readpos = m_curReadPos;
154 ssize_t write_reserve_end = m_endOfWritten +
chunkSize();
155 if(write_reserve_end > m_data.size()) {
158 m_end = (ssize_t)m_endOfWritten;
160 write_reserve_end = m_endOfWritten +
chunkSize();
162 if((readpos > m_endOfWritten) && (readpos <= write_reserve_end))
164 return &m_data[m_endOfWritten];
168 assert(pend - &m_data[m_endOfWritten] <=
chunkSize());
169 ssize_t pos = pend - &m_data[0];
170 m_endOfWritten = pos;
175 std::vector<T> m_data;
181 shared_ptr<std::vector<tRawAOSet> > m_genPulseWaveAO[PAT_QAM_MASK / PAT_QAM_PHASE];
184 double m_coeffAODev[NUM_AO_CH][CAL_POLY_ORDER];
185 double m_upperLimAO[NUM_AO_CH];
186 double m_lowerLimAO[NUM_AO_CH];
188 inline tRawAOSet aoVoltToRaw(
const double poly_coeff[NUM_AO_CH][CAL_POLY_ORDER],
const std::complex<double> &volt);
190 shared_ptr<XThread<XNIDAQmxPulser> > m_threadWriter;
193 template <
bool UseAO>
195 void rewindBufPos(
double ms_from_gen_pos);
198 ssize_t writeToDAQmxAO(
const tRawAOSet *pAO, ssize_t samps);
199 void startBufWriter();
200 void stopBufWriter();
203 void preparePatternGen(
const Snapshot &shot,
204 bool use_dummypattern,
unsigned int blankpattern);
206 int makeWaveForm(
int num,
double pw, tpulsefunc func,
double dB,
double freq = 0.0,
double phase = 0.0);
209 typedef std::deque<std::pair<uint64_t, uint64_t> > QueueTimeGenCnt;