16 #include "../../common/paths.hpp"
55 template<
class derivedT>
101 const std::
string & command
242 return *
static_cast<derivedT *
>(
this);
246 template<
class derivedT>
252 template<
class derivedT>
255 if(m_pdv) pdv_close(m_pdv);
261 #define MAGAOX_PDV_SERBUFSIZE 512
263 template<
class derivedT>
265 const std::string & command
274 if( pdv_serial_command(m_pdv, command.c_str()) < 0)
276 derivedT::template log<software_error>({__FILE__, __LINE__,
"PDV: error sending serial command"});
282 ret = pdv_serial_wait(m_pdv, m_readTimeout, 1);
286 if(derived().powerState() != 1 || derived().powerStateTarget() != 1)
return -1;
288 derivedT::template log<software_error>({__FILE__, __LINE__,
"PDV: timeout, no serial response"});
292 u_char lastbyte, waitc;
300 if(ret > 0) response += buf;
303 if (*buf) lastbyte = (u_char)buf[strnlen(buf,
sizeof(buf))-1];
305 if (pdv_get_waitchar(m_pdv, &waitc) && (lastbyte == waitc))
307 else ret = pdv_serial_wait(m_pdv, m_readTimeout/2, 1);
311 if(ret == 0 && pdv_get_waitchar(m_pdv, &waitc))
313 derivedT::template log<software_error>({__FILE__, __LINE__,
"PDV: timeout in serial response"});
320 template<
class derivedT>
324 EdtDev *edt_p = NULL;
334 derived().m_modeName = modeName;
341 if(derived().m_cameraModes.count(modeName) != 1)
347 std::string configFile;
349 if(derivedT::c_edtCamera_relativeConfigPath)
351 configFile = derived().configDir() +
"/";
354 configFile += derived().m_cameraModes[modeName].m_configFile;
357 derivedT::template log<text_log>(
"Loading EDT PDV config file: " + configFile);
359 if ((dd_p = pdv_alloc_dependent()) == NULL)
361 return derivedT::template
log<
software_error, -1>({__FILE__, __LINE__,
"EDT PDV alloc_dependent FAILED"});
364 if (pdv_readcfg(configFile.c_str(), dd_p, &edtinfo) != 0)
367 return derivedT::template
log<
software_error, -1>({__FILE__, __LINE__,
"EDT PDV readcfg FAILED"});
371 char edt_devname[128];
372 strncpy(edt_devname, EDT_INTERFACE,
sizeof(edt_devname));
374 if ((edt_p = edt_open_channel(edt_devname, m_unit, m_channel)) == NULL)
379 return derivedT::template
log<
software_error, -1>({__FILE__, __LINE__, std::string(
"EDT PDV edt_open_channel FAILED: ") + errstr});
389 if (pdv_initcam(edt_p, dd_p, m_unit, &edtinfo, configFile.c_str(), bitdir, pdv_debug) != 0)
393 return derivedT::template
log<
software_error, -1>({__FILE__, __LINE__,
"initcam failed. Run with '--logLevel=DBG' to see complete debugging output."});
400 if ((m_pdv = pdv_open_channel(edt_devname, m_unit, m_channel)) == NULL)
402 std::string errstr = std::string(
"pdv_open_channel(") + edt_devname + std::to_string(m_unit) +
"_" + std::to_string(m_channel) +
")";
404 derivedT::template log<software_error>({__FILE__, __LINE__, errstr});
405 derivedT::template log<software_error>({__FILE__, __LINE__, errno});
410 pdv_flush_fifo(m_pdv);
412 pdv_serial_read_enable(m_pdv);
414 m_raw_width = pdv_get_width(m_pdv);
415 m_raw_height = pdv_get_height(m_pdv);
416 m_raw_depth = pdv_get_depth(m_pdv);
417 m_cameraType = pdv_get_cameratype(m_pdv);
419 derivedT::template log<text_log>(
"Initialized framegrabber: " + m_cameraType);
420 derivedT::template log<text_log>(
"WxHxD: " + std::to_string(m_raw_width) +
" X " + std::to_string(m_raw_height) +
" X " + std::to_string(m_raw_depth));
426 pdv_multibuf(m_pdv, m_numBuffs);
427 derivedT::template log<text_log>(
"allocated " + std::to_string(m_numBuffs) +
" buffers");
435 template<
class derivedT>
438 config.add(
"framegrabber.pdv_unit",
"",
"framegrabber.pdv_unit", argType::Required,
"framegrabber",
"pdv_unit",
false,
"int",
"The EDT PDV framegrabber unit number. Default is 0.");
439 config.add(
"framegrabber.pdv_channel",
"",
"framegrabber.pdv_channel", argType::Required,
"framegrabber",
"pdv_channel",
false,
"int",
"The EDT PDV framegrabber channel number. Default is 0.");
440 config.add(
"framegrabber.numBuffs",
"",
"framegrabber.numBuffs", argType::Required,
"framegrabber",
"numBuffs",
false,
"int",
"The EDT PDV framegrabber DMA buffer size [images]. Default is 4.");
445 template<
class derivedT>
448 config(m_unit,
"framegrabber.pdv_unit");
449 config(m_channel,
"framegrabber.pdv_channel");
450 config(m_numBuffs,
"framegrabber.numBuffs");
452 m_readTimeout = 1000;
453 m_writeTimeout = 1000;
459 template<
class derivedT>
462 if(pdvConfig(derived().m_startupMode) < 0)
464 derivedT::template log<software_error>({__FILE__, __LINE__});
472 template<
class derivedT>
479 template<
class derivedT>
485 template<
class derivedT>
491 template<
class derivedT>
497 template<
class derivedT>
500 pdv_start_images(m_pdv, m_numBuffs);
505 template<
class derivedT>
509 uint dmaTimeStamp[2];
510 m_image_p = pdv_wait_last_image_timed(m_pdv, dmaTimeStamp);
512 pdv_start_image(m_pdv);
514 currImageTimestamp.tv_sec = dmaTimeStamp[0];
515 currImageTimestamp.tv_nsec = dmaTimeStamp[1];
521 template<
class derivedT>
525 if(pdvConfig(derived().m_nextMode) < 0)
527 derivedT::template log<text_log>(
"error trying to re-configure with " + derived().m_nextMode,
logPrio::LOG_ERROR);
532 derived().m_nextMode =
"";
540 template<
class derivedT>
MagAO-X EDT framegrabber interface.
int m_channel
EDT PDV board channel number.
int m_raw_depth
The bit-depth of the frame, according to the framegrabber.
int appLogic()
Application logic.
u_char * m_image_p
The image data grabbed.
int m_raw_height
The height of the frame, according to the framegrabber.
PdvDev * m_pdv
The EDT PDV device handle.
int pdvConfig(std::string &cfgname)
Configure the EDT framegrabber.
int pdvAcquire(timespec &currImageTimestamp)
int pdvSerialWriteRead(std::string &response, const std::string &command)
Send a serial command over cameralink and retrieve the response.
int m_unit
EDT PDV board unit number.
std::string m_cameraType
The camera type according to the framegrabber.
~edtCamera() noexcept
Destructor, destroys the PdvDev structure.
edtCamera()
C'tor, sets up stdCamera.
int appStartup()
Startup function.
void setupConfig(mx::app::appConfigurator &config)
Setup the configuration system.
void loadConfig(mx::app::appConfigurator &config)
load the configuration system results
int onPowerOff()
Actions on power off.
int updateINDI()
The static callback function to be registered for the channel properties.
int m_raw_width
The width of the frame, according to the framegrabber.
int pdvStartAcquisition()
int m_numBuffs
EDT PDV DMA buffer size, indicating number of images.
int appShutdown()
Application the shutdown.
int whilePowerOff()
Actions while powered off.
#define MAGAOX_PDV_SERBUFSIZE
Configuration and control of an input and output device.
constexpr static logPrioT LOG_ERROR
An error has occured which the software will attempt to correct.
constexpr static logPrioT LOG_INFO
Informational. The info log level is the lowest level recorded during normal operations.
Standard camera interface.
An input/output capable device.
int loadConfig(mx::app::appConfigurator &config)
Load the device section from an application configurator.
int setupConfig(mx::app::appConfigurator &config)
Setup an application configurator for the device section.
A simple text log, a string-type log.