This commit is contained in:
Eddy
2015-02-10 00:08:55 +03:00
parent 0188a9ad35
commit 4776ef09d1
27 changed files with 6869 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
# apogee.rules a udev rules file for apogee usb cameras
SUBSYSTEM!="usb", ACTION!="add", GOTO="apogee_rules_end"
# Apogee Alta-U
ATTRS{idVendor}=="125c", ATTRS{idProduct}=="0010", GROUP="users", MODE="666"
# Apogee Ascent
ATTRS{idVendor}=="125c", ATTRS{idProduct}=="0020",GROUP="users", MODE="666"
# Apogee USB Filter Wheel
ATTRS{idVendor}=="125c", ATTRS{idProduct}=="0100",GROUP="users", MODE="666"
LABEL="apogee_rules_end"

View File

@@ -0,0 +1,10 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: ApogeeU
Description: Apogee USB camera module (C wrapper for lib 3x)
Version: @APOGEE_VERSION@
Libs: -L${libdir} -lapogeeu
Cflags: -I${includedir}

View File

@@ -0,0 +1,697 @@
/*
* libapogee.cpp - libapogee C wrapper
*
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include "libapogee.h"
#include <Alta.h>
#include <AltaF.h>
#include <Ascent.h>
#include <Aspen.h>
#include <Quad.h>
#include <CameraInfo.h>
#include <FindDeviceUsb.h>
#include <ApogeeFilterWheel.h>
#include <ApogeeCam.h>
#if defined APOGEE_ASCENT
#define CCD Ascent
#elif defined APOGEE_ALTA
#define CCD Alta
#elif defined APOGEE_ALTAF
#define CCD AltaF
#elif defined APOGEE_ASPEN
#define CCD Aspen
#elif defined APOGEE_QUAD
#define CCD Quad
#else
#error "You must define camera type: APOGEE_ASCENT, APOGEE_ALTA, \
APOGEE_ALTAF, APOGEE_ASPEN or APOGEE_QUAD"
#endif
// static class for CCD device
static CCD *alta = NULL;
// static variable with last error
CCDerr altaerr = ALTA_OK;
typedef struct{
std::string address;
uint16_t FirmwareRev;
uint16_t Id;
std::string deviceType;
std::string model;
} CamParams;
// last camera parameters
static CamParams par;
#define TRY altaerr=ALTA_OK; try
#ifdef EBUG
#define SHOWEX() do{std::cout << "ERROR! " << err.what() << std::endl;}while(0)
#define DBG(msg) do{std::cout << msg << std::endl;}while(0)
#else
#define SHOWEX()
#define DBG(msg)
#endif
#define CATCH(ERR) catch(std::exception & err){altaerr=ERR;SHOWEX();}catch(...){altaerr=ALTA_UNDEF;}
#define RETERR(ERR) do{altaerr=ERR; return altaerr;}while(0)
static void checkalta(){
if(!alta){
fprintf(stderr, "Bug! Alta used before open\n");
exit(1);
}
}
// Functions for getting camera parameters from discovery string
// first two functions are from apogee's library
std::vector<std::string> MakeTokens(const std::string &str, const std::string &separator){
std::vector<std::string> returnVector;
std::string::size_type start = 0;
std::string::size_type end = 0;
while((end = str.find(separator, start)) != std::string::npos){
returnVector.push_back (str.substr(start, end-start));
start = end + separator.size();
}
returnVector.push_back( str.substr(start) );
return returnVector;
}
std::string GetItemFromFindStr( const std::string & msg, const std::string & item ){
std::vector<std::string> params = MakeTokens(msg, "," );
std::vector<std::string>::iterator iter;
for(iter = params.begin(); iter != params.end(); ++iter){
if( std::string::npos != (*iter).find( item )){
std::string result = MakeTokens((*iter), "=" ).at(1);
return result;
}
}
fprintf(stderr, "Bug! Can't find parameter in description string!\n");
exit(1);
std::string noOp;
return noOp;
}
uint16_t readUI(const std::string & msg, const std::string & key){
std::string str = GetItemFromFindStr(msg, key);
unsigned int x;
if(sscanf(str.c_str(), "%x", &x) < 1){
fprintf(stderr, "Bug! Can't convert parameter from hex!\n");
exit(1);
}
return (uint16_t) x;
}
CamParams *getCamParams(std::string & msg){
par.address = GetItemFromFindStr(msg, "address=");
par.FirmwareRev = readUI(msg, "firmwareRev=");
par.Id = readUI(msg, "id=");
par.deviceType = GetItemFromFindStr(msg, "deviceType=");
par.model = GetItemFromFindStr(msg, "model=");
return &par;
}
/**
* Open camera device and assign it to variable <alta>
* IT DON'T WORK WITH MULTIPLE CAMERAS SIMULTANEOUSLY!
* @param id - camera identificator (number)
* @return 0 in case of success
*/
int ApnGlueOpen(_U_ unsigned int id){
TRY{
alta = (CCD*) new CCD();
std::string ioInterface("usb");
FindDeviceUsb look4cam;
std::string msg = look4cam.Find();
DBG(msg);
if(msg == "<d></d>")
RETERR(ALTA_NO_SUCH_DEVICE); // empty string
CamParams *par = getCamParams(msg);
alta->OpenConnection(ioInterface, par->address, par->FirmwareRev, par->Id);
alta->Init();
}CATCH(ALTA_NO_SUCH_DEVICE);
return(altaerr);
}
/**
* Close connection and destroy camera object
*/
void ApnGlueClose(){
if(!alta) return;
TRY{
alta->CloseConnection();
delete alta;
}CATCH(ALTA_CANT_CLOSE);
}
/**
* Camera sensor and model
* @param sensor, model (o) - dinamically allocated strings or NULL
*/
void ApnGlueGetName(char **sensor, char **camera){
checkalta();
TRY{
if(camera) *camera = (char *)alta->GetModel().c_str();
if(sensor) *sensor = (char *)alta->GetSensor().c_str();
}CATCH(ALTA_UNDEF);
}
/**
* Set fan speed
* @param speed: 0 - turn fan off; 1 - slowest, 3 - fastest
*/
void ApnGlueSetFan(int speed){
checkalta();
TRY{
Apg::FanMode mode = (Apg::FanMode)(speed % 4);
alta->SetFanMode(mode);
}CATCH(ALTA_BAD_FANSPD);
}
/**
* Get fan speed
* @return fan speed
*/
int ApnGlueGetFan(){
int mode = -1;
checkalta();
TRY{
mode = alta->GetFanMode();
}CATCH(ALTA_BAD_FANSPD);
return mode;
}
/**
* Set parameters for subsequent exposures.
* In case of error return -1 or altaerr with explanation in whynot[], else 0.
* Also return final image size in net binned pixels, allowing for overscan,
* binning etc.
* @param roiw, roih - image width & height in unbinned pixels
* @param osw, osh - (USED only their sign) width & height of saved overscan part (should be less than max OS)
* @param binw, binh - binning by X and Y
* @param roix, roiy - coordinate of image angle on CCD
* @param impixw, impixh (o) - size of output image (binned) or NULL
* @param whynot[] - error explanation or NULL
* @return In case of error return -1 or altaerr with explanation in whynot[], else 0.
*/
int ApnGlueSetExpGeom(int roiw, int roih, int osw, int osh, int binw,
int binh, int roix, int roiy, int *impixw, int *impixh, char whynot[]){
uint16_t maxw, maxh, maxtotw;
//uint16_t maxtoth;
checkalta();
TRY{
maxw = alta->GetMaxImgCols();
maxh = alta->GetMaxImgRows();
maxtotw = alta->GetTotalRows();
//maxtoth = alta->GetTotalCols();
if(binw < 1) binw = 1;
if(binh < 1) binh = 1;
if(roiw < 1 || roiw > (int)maxw) roiw = maxw;
if(roih < 1 || roih > (int)maxh) roih = maxh;
if(osw > 0 || osh > 0){
int maxosw = alta->GetNumOverscanCols();
//int maxosh = ApogeeCam::m_CamCfgData->m_MetaData.OverscanRows;
if (osw > maxosw){
if(whynot) sprintf (whynot, "Max overscan columns is %d", maxosw);
RETERR(ALTA_BAD_GEOMETRY);
}
/*if (osh > maxosh) {
sprintf (whynot, "Max overscan rows is %d", maxosh);
return (-1);
}*/
if (roix > 0 || roiw < maxw || roiy > 0 || roih < maxh) {
if(whynot) sprintf (whynot, "Can not overscan with windowing");
RETERR(ALTA_BAD_GEOMETRY);
}
roiw += osw;
//roih += osh;
if(roiw > (int)maxtotw) roiw = maxtotw;
//if(roih > (int)maxtoth) roih = maxtoth;
roiw = maxtotw;
//roih = maxtoth;
alta->SetDigitizeOverscan(true);
}else alta->SetDigitizeOverscan(false);
alta->SetRoiBinCol(binw);
alta->SetRoiBinRow(binh);
if(roix > 0 || roiy > 0){
if((roix + roiw > maxw) || (roiy + roih > maxh)){
if(whynot) sprintf (whynot, "Windowed image too large");
RETERR(ALTA_BAD_GEOMETRY);
}
alta->SetRoiStartCol(roix);
alta->SetRoiStartRow(roiy);
}else{
alta->SetRoiStartCol(0);
alta->SetRoiStartRow(0);
}
alta->SetRoiNumCols(roiw / binw);
alta->SetRoiNumRows(roih / binh);
if(impixw) *impixw = roiw / binw;
if(impixh) *impixh = roih / binh;
}CATCH(ALTA_BAD_GEOMETRY);
return altaerr;
}
/**
* Get pixel size
* @param pixX, pixY (o) - pixel size in mkm or NULL
*/
void ApnGlueGetGeom(double *pixX, double *pixY){
checkalta();
TRY{
if(pixX) *pixX = alta->GetPixelWidth();
if(pixY) *pixY = alta->GetPixelHeight();
}CATCH(ALTA_UNDEF);
}
/**
* Get extremal values
* @param exptime - exposition time (array: [min, max]) or NULL
* @param roiw, roih - ROI image size or NULL
* @param osw, osh - overscan size (used only osw) or NULL
* @param binw, binh - binning size or NULL
* @param shutter - shutter presence or NULL
* @param mintemp - minimal temperature or NULL
*/
void ApnGlueGetMaxValues(double *exptime, int *roiw, int *roih, int *osw,
_U_ int *osh, int *binw, int *binh, int *shutter, double *mintemp){
checkalta();
TRY{
if(exptime){
exptime[0] = alta->GetMinExposureTime();
exptime[1] = alta->GetMaxExposureTime();
}
if(roiw) *roiw = alta->GetTotalRows();
if(roih) *roih = alta->GetMaxImgRows();
if(osw) *osw = alta->GetNumOverscanCols();
if(binw) *binw = alta->GetMaxBinCols();
if(binh) *binh = alta->GetMaxBinRows();
if(shutter) *shutter = 1; // !!!TODO!!!
if(mintemp) *mintemp = -30.; // !!!TODO!!!
}CATCH(ALTA_UNDEF);
}
/**
* Get sensor temperature and cooler status
* @param Cp - current sensor temperature
* @return Cooler_Status value
*/
int ApnGlueGetTemp(double *Cp){
int status = -1;
checkalta();
TRY{
*Cp = alta->GetTempCcd();
status = alta->GetCoolerStatus();
}CATCH(ALTA_COOLER);
return status;
}
/**
* Get heatsink temperature (in degC)
* @return hot side of Peltier temperature value
*/
double ApnGlueGetHotTemp(){
checkalta();
double temp = 1000.;
TRY{
temp = alta->GetTempHeatsink();
}CATCH(ALTA_COOLER);
return temp;
}
/**
* Set CCD temperature (in degC)
* @param C - new temperature, !!! value C == 0, disables cooler !!!
* @return
*/
void ApnGlueSetTemp(double C){
checkalta();
TRY{
if (C == 0) {
alta->SetCooler(0);
} else {
alta->SetCooler(1);
alta->SetCoolerSetPoint(C);
}
}CATCH(ALTA_COOLER);
}
/* Get setpoint temperature; return 1 if cooler is on, 0 if cooler is off;
stat == 0 - clamp to setpoint, 1 - at setpoint*/
/**
* Get temperature setpoint
* @param temp (o) - temperature setpoint or NULL
* @param stat (o) - ==1 if cooler is at setpoint or NULL
* @return cooler status
*/
int ApnGlueReadSetPoint(double *temp, int *stat){
checkalta();
Apg::CoolerStatus S = Apg::CoolerStatus_Suspended;
TRY{
S = alta->GetCoolerStatus();
if(S == Apg::CoolerStatus_Off) return S;
if(stat) *stat = (S == Apg::CoolerStatus_AtSetPoint) ? 1:0;
if(temp) *temp = alta->GetCoolerSetPoint();
}CATCH(ALTA_COOLER);
return S;
}
/**
* Read shutter state
* @return 1 if shutter opened, 0 if closed
*/
int ApnGlueReadShutter(){
checkalta();
int state = 0;
TRY{
Apg::ShutterState shtr = alta->GetShutterState();
if(shtr == Apg::ShutterState_ForceOpen)
state = 1;
}CATCH(ALTA_SHTR);
return state;
}
/**
* Force open/close shutter
* @param flag - == 0 to close, != 0 to open
*/
void ApnGlueOpenShutter(int flag){
checkalta();
TRY{
Apg::ShutterState shtr = (flag) ? Apg::ShutterState_ForceOpen : Apg::ShutterState_ForceClosed;
alta->SetShutterState(shtr);
}CATCH(ALTA_SHTR);
}
/**
* Get ADC speed
* @return Adc_Speed value
*/
unsigned short ApnGlueGetSpeed(){
checkalta();
Apg::AdcSpeed spd = Apg::AdcSpeed_Unknown;
TRY{
spd = alta->GetCcdAdcSpeed();
}CATCH(ALTA_BADSPD);
return (unsigned short)spd;
}
/**
* Set ADC speed
* @param Sp - speed (Adc_Speed)
*/
void ApnGlueSetSpeed(unsigned short Sp){
checkalta();
TRY{
if(Sp != AdcSpeed_Normal && Sp != AdcSpeed_Fast && Sp != AdcSpeed_Video){
altaerr = ALTA_BADSPD;
return;
}
alta->SetCcdAdcSpeed((Apg::AdcSpeed)Sp);
}CATCH(ALTA_BADSPD);
}
/**
* Reset camera
*/
void ApnGlueReset(){
checkalta();
TRY{
alta->Reset();
}CATCH(ALTA_POWER);
}
/**
* Power down/resume - just a stub for backward compability
*/
int ApnGluePowerDown(){return -1;}
void ApnGluePowerResume(){}
/**
* Disable (flag!=1) or enable post expose flushing
* @param flag == 1 to disable post-flushing
*/
void ApnGlueDisablePostExpFlushing(int flag){
checkalta();
TRY{
alta->SetPostExposeFlushing(flag);
}CATCH(ALTA_UNDEF);
}
/**
* Set (flag!=0) or reset preexposure IR-flashing
* @param flag != 1 to enable pre-flash
* @return
*/
void ApnGluePreFlash(int flag){
checkalta();
TRY{
alta->SetPreFlash(flag);
}CATCH(ALTA_UNDEF);
}
/**
* Set ADC databits (16/12)
* !!!DEPRECATED!!! Use ApnGlueSetSpeed() instead!
* @param BitResolution - ADC resolution
*/
void ApnGlueSetDatabits(Apn_Resolution BitResolution){
checkalta();
TRY{
Adc_Speed sp = AdcSpeed_Normal;
if(BitResolution != Resolution_SixteenBit)
sp = AdcSpeed_Fast;
ApnGlueSetSpeed(sp);
}CATCH(ALTA_UNDEF);
}
/**
* Set camera mode
* @param CameraMode - one of camera mode
*/
void ApnGlueWriteCamMode(Apn_CameraMode CameraMode){
checkalta();
TRY{
alta->SetCameraMode((Apg::CameraMode)CameraMode);
}CATCH(ALTA_UNDEF);
}
/* start an exposure with the given duration (secs) and whether to open shutter.
* update *exptime with the actual exposure time (may have been bumped to min).
* return 0 if ok, else -1
*/
/**
* Start an exposure with the given duration (secs)
* Update *exptime with the actual exposure time
* @param exptime (i/o) - exposition time in secs
* @param shutter - shutter state (1 - object, 0 - dark)
* @return ALTA_OK if ok
*/
int ApnGlueStartExp(double *exptime, int shutter){
checkalta();
if(!exptime) return ALTA_EXPOSURE;
TRY{
double maxtime; // ,mintime
//mintime = alta->GetMinExposureTime();
maxtime = alta->GetMaxExposureTime();
if(*exptime > maxtime) *exptime = maxtime;
else if(*exptime < 0.) *exptime = 0.;
alta->SetImageCount(1);
alta->StartExposure(*exptime, shutter);
}CATCH(ALTA_EXPOSURE);
return altaerr;
}
/**
* Pause or resume timer
* @param flag - !=0 to pause, ==0 to resume
* @return
*/
void ApnGluePauseTimer(int flag){
checkalta();
TRY{
alta->PauseTimer(flag);
}CATCH(ALTA_EXPOSURE);
}
/**
* These two functions makes similar work: aborts exposition
* ApnGlueExpAbort() fully aborts it, whith sensor cleaning
* ApnGlueStopExposure() allows to read stored image
* @return ApnGlueStopExposure() returns value of altaerr
*/
void ApnGlueExpAbort(){
checkalta();
TRY{
alta->StopExposure(false);
}CATCH(ALTA_EXPOSURE);
}
int ApnGlueStopExposure(){
checkalta();
TRY{
alta->StopExposure(true);
}CATCH(ALTA_EXPOSURE);
return altaerr;
}
/**
* Check whether exposition is done
* @return 1 if exposition is over
*/
int ApnGlueExpDone(){
checkalta();
TRY{
Apg::Status st = alta->GetImagingStatus();
if(st == Apg::Status_ImageReady) return 1;
}CATCH(ALTA_EXPOSURE);
return 0;
}
/**
* read pixels from the camera into the given buffer of length nbuf.
* @param buf - image buffer
* @param nbuf - buf size
* @param whynot - error explanation or NULL
* @return ALTA_OK if OK
*/
int ApnGlueReadPixels(unsigned short *buf, int nbuf, char whynot[]){
checkalta();
if(!buf || nbuf < 1) RETERR(ALTA_GETIMAGE);
printf("READ\n");
TRY{
std::vector<uint16_t> v;
alta->GetImage(v);
if(nbuf < alta->GetRoiNumCols() * (int)alta->GetRoiNumRows() || nbuf < (int)v.size()){
if(whynot) sprintf(whynot, "Buffer size less than image size");
RETERR(ALTA_GETIMAGE);
}
std::copy(v.begin(), v.end(), buf);
}CATCH(ALTA_GETIMAGE);
printf("DONE\n");
return altaerr;
}
/*
******************************** FILTER WHEEL ********************************
*/
static ApogeeFilterWheel *wheel;
static void checkwheel();
/**
* Open and initialise filter wheel device
* @param id - number of wheel
* @param type - wheel type
* @return 0 if init OK, else return !0 and set altaerr
*/
int ApnGlueWheelOpen(_U_ unsigned int id, Apn_Filter type){
TRY{
FindDeviceUsb look4FilterWheel;
std::string msg = look4FilterWheel.Find();
DBG(msg);
if(msg == "<d></d>")
RETERR(ALTA_NO_SUCH_DEVICE);
std::string str = GetItemFromFindStr(msg, "deviceType=");
if(str.compare("filterWheel"))
RETERR(ALTA_NOTWHEEL);
wheel = (ApogeeFilterWheel*) new ApogeeFilterWheel();
std::string addr = GetItemFromFindStr(msg, "address=");
wheel->Init((ApogeeFilterWheel::Type)type, addr);
}CATCH(ALTA_NO_SUCH_DEVICE);
return 0;
}
/**
* Close filter device
*/
void ApnGlueWheelClose(){
TRY{
if(wheel) wheel->Close();
delete wheel;
}CATCH(ALTA_CANT_CLOSE);
}
/**
* Get current filter wheel status
* @param
* @return 0 if ready, 1 if moving or absent
*/
int ApnGlueWheelGetStatus(){
checkwheel();
TRY{
ApogeeFilterWheel::Status st = wheel->GetStatus();
if(st != ApogeeFilterWheel::READY) return 1;
}CATCH(ALTA_NOTWHEEL);
if(altaerr != ALTA_OK) return 1;
return 0;
}
/**
* Get maximum position number
* @return amount of positions or -1 if err
*/
int ApnGlueWheelGetMaxPos(){
uint16_t m = 0;
checkwheel();
TRY{
m = wheel->GetMaxPositions();
}CATCH(ALTA_NOTWHEEL);
if(altaerr != ALTA_OK) return -1;
return (int) m;
}
/**
* Set position
* @param pos - new position number (1..max)
* @return 0 on success or !0 in case of error
*/
int ApnGlueWheelSetPos(int pos){
checkwheel();
TRY{
if(pos < 1 || wheel->GetMaxPositions() < pos) RETERR(ALTA_BADWHEELPOS);
wheel->SetPosition((uint16_t) pos);
}CATCH(ALTA_BADWHEELPOS);
if(altaerr != ALTA_OK) return ALTA_BADWHEELPOS;
return 0;
}
/**
* Get current position (1..max)
* @return current position or -1 on error
*/
int ApnGlueWheelGetPos(){
uint16_t m = 0;
checkwheel();
TRY{
m = wheel->GetPosition();
}CATCH(ALTA_BADWHEELPOS);
if(altaerr != ALTA_OK) return -1;
return (int)m;
}
/**
* Check wheel
*/
static void checkwheel(){
if(!wheel){
fprintf(stderr, "Bug! Wheel used before open\n");
exit(1);
}
}

View File

@@ -0,0 +1,170 @@
/*
* libapogee.h - header for libapogee C wrapper
*
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#pragma once
#ifndef __LIBAPOGEE_H__
#define __LIBAPOGEE_H__
#ifndef _U_
#define _U_ __attribute__((unused))
#endif
// errors:
typedef enum{
ALTA_OK = 0 // all good
,ALTA_UNDEF // undefined error
,ALTA_NO_SUCH_DEVICE // can't open: no such device
,ALTA_CANT_CLOSE // error when closing device
,ALTA_BAD_FANSPD // bad fan speed (should be 0..3)
,ALTA_BAD_GEOMETRY // bad geometry parameter
,ALTA_COOLER // something wrong with cooler
,ALTA_SHTR // something wrong with shutter
,ALTA_BADSPD // error setting speed
,ALTA_POWER // error when working with power modes
,ALTA_EXPOSURE // error when exposing image
,ALTA_GETIMAGE // error getting image
,ALTA_NOTWHEEL // device isn't a filter wheel
,ALTA_BADWHEELPOS // bad wheel position
}CCDerr;
extern CCDerr altaerr;
// some definitions from CameraInfo.h ==================>
typedef enum{
CameraMode_Normal = 0,
CameraMode_TDI,
CameraMode_Test,
CameraMode_ExternalTrigger,
CameraMode_ExternalShutter,
CameraMode_Kinetics,
CameraMode_Unknown
}Apn_CameraMode;
typedef enum{
Resolution_SixteenBit = 0,
Resolution_TwelveBit
}Apn_Resolution;
typedef enum{
Status_ConnectionError = -3,
Status_DataError = -2,
Status_PatternError = -1,
Status_Idle = 0,
Status_Exposing = 1,
Status_ImagingActive = 2,
Status_ImageReady = 3,
Status_Flushing = 4,
Status_WaitingOnTrigger = 5
}Apn_Status;
typedef enum{
UNKNOWN_TYPE = 0,
FW50_9R = 1,
FW50_7S = 2,
AFW25_4R = 3,
AFW30_7R = 4,
AFW50_5R = 5,
AFW50_10S = 6,
AFW31_17R = 9
}Apn_Filter;
typedef enum{
CoolerStatus_Off = 0,
CoolerStatus_RampingToSetPoint = 1,
CoolerStatus_AtSetPoint = 2,
CoolerStatus_Revision = 3,
CoolerStatus_Suspended = 4
}Cooler_Status;
typedef enum{
AdcSpeed_Unknown,
AdcSpeed_Normal,
AdcSpeed_Fast,
AdcSpeed_Video
}Adc_Speed;
// For back-compatible
#define Apn_CameraMode_Normal CameraMode_Normal
#define Apn_CameraMode_TDI CameraMode_TDI
#define Apn_CameraMode_Test CameraMode_Test
#define Apn_CameraMode_ExternalTrigger CameraMode_ExternalTrigger
#define Apn_CameraMode_ExternalShutter CameraMode_ExternalShutter
#define Apn_CameraMode_Kinetics CameraMode_Kinetics
#define Apn_Resolution_SixteenBit Resolution_SixteenBit
#define Apn_Resolution_TwelveBit Resolution_TwelveBit
#define Apn_Filter_Unknown UNKNOWN_TYPE
#define Apn_Filter_FW50_9R FW50_9R
#define Apn_Filter_FW50_7S FW50_7S
#define Apn_Filter_AFW25_4R AFW25_4R
#define Apn_Filter_AFW30_7R AFW30_7R
#define Apn_Filter_AFW50_5R AFW50_5R
#define Apn_Filter_AFW50_10S AFW50_10S
#define Apn_Filter_AFW31_17R AFW31_17R
#define Apn_FilterStatus_NotConnected 0
#define Apn_FilterStatus_Ready 1
#define Apn_FilterStatus_Active 2
// <================== some definitions from CameraInfo.h
#ifdef __cplusplus
extern "C" {
#endif
// Camera
int ApnGlueOpen(unsigned int id);
void ApnGlueClose();
void ApnGlueGetName(char **sensor, char **camera);
void ApnGlueSetFan(int speed);
int ApnGlueGetFan();
int ApnGlueSetExpGeom (int roiw, int roih, int osw, int osh, int binw,
int binh, int roix, int roiy, int *impixw, int *impixh, char whynot[]);
void ApnGlueGetGeom(double *pixX, double *pixY);
void ApnGlueGetMaxValues (double *exptime, int *roiw, int *roih, int *osw,
int *osh, int *binw, int *binh, int *shutter, double *mintemp);
int ApnGlueGetTemp(double *Cp);
double ApnGlueGetHotTemp();
void ApnGlueSetTemp(double C);
int ApnGlueReadSetPoint(double *temp, int *stat);
int ApnGlueReadShutter();
void ApnGlueOpenShutter(int flag);
unsigned short ApnGlueGetSpeed();
void ApnGlueSetSpeed(unsigned short Sp);
void ApnGlueReset();
int ApnGluePowerDown();
void ApnGluePowerResume();
void ApnGlueDisablePostExpFlushing(int flag);
void ApnGluePreFlash(int flag);
void ApnGlueSetDatabits(Apn_Resolution BitResolution);
void ApnGlueWriteCamMode(Apn_CameraMode CameraMode);
int ApnGlueStartExp (double *exptime, int shutter);
void ApnGluePauseTimer(int flag);
int ApnGlueExpDone();
void ApnGlueExpAbort(void);
int ApnGlueStopExposure();
int ApnGlueReadPixels(unsigned short *buf, int nbuf, char whynot[]);
// Wheel
int ApnGlueWheelOpen(unsigned int id, Apn_Filter type);
void ApnGlueWheelClose();
int ApnGlueWheelGetStatus();
int ApnGlueWheelGetMaxPos();
int ApnGlueWheelSetPos(int pos);
int ApnGlueWheelGetPos();
#ifdef __cplusplus
}
#endif
#endif // __LIBAPOGEE_H__

107
apogee_C_wrapper/src/test.c Normal file
View File

@@ -0,0 +1,107 @@
/*
* test.c - file for wrapper testing
*
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include "libapogee.h"
#define ERREND() do{printf("Error!"); if(*errmsg) printf(" %s", errmsg); printf("\n"); goto theend;}while(0)
int main(_U_ int argc, _U_ char **argv){
char errmsg[256];
*errmsg = 0;
int W, H;
int res = ApnGlueOpen(0);
if(res == ALTA_NO_SUCH_DEVICE || altaerr != ALTA_OK){
printf("Can't open! No such device.\n");
return 1;
}
char *sen, *cam;
ApnGlueGetName(&sen, &cam);
printf("Camera: %s with sensor %s\n", cam, sen);
printf("Speed: %d\n", ApnGlueGetSpeed());
int fanSpeed = ApnGlueGetFan();
if(ALTA_OK != altaerr) ERREND();
printf("Current fan speed: %d\n", fanSpeed);
ApnGlueSetFan(0);
if(ALTA_OK != altaerr) ERREND();
double pixH, pixW;
ApnGlueGetGeom(&pixW, &pixH);
if(ALTA_OK != altaerr) ERREND();
printf("Pixel size: %gx%g mkm\n", pixW, pixH);
double exp[2];
int roiw, roih, osw, binw, binh;
ApnGlueGetMaxValues(exp, &roiw, &roih, &osw, NULL, &binw, &binh, NULL, NULL);
if(ALTA_OK != altaerr) ERREND();
printf("Extremal expositions (seconds): min = %g, max = %g\n", exp[0], exp[1]);
printf("ROI maximum size: %dx%d\n", roiw, roih);
printf("Number of overscan columns: %d\n", osw);
printf("Maximum binning: %dx%d\n", binw, binh);
double currtemp;
int status = ApnGlueGetTemp(&currtemp);
if(ALTA_OK != altaerr) ERREND();
char *msg;
switch(status){
case CoolerStatus_Off:
msg = "Off";
break;
case CoolerStatus_RampingToSetPoint:
msg = "Ramping to setpoint";
break;
case CoolerStatus_AtSetPoint:
msg = "At setpoint";
break;
case CoolerStatus_Revision:
msg = "Revision";
break;
case CoolerStatus_Suspended:
msg = "Suspended";
break;
default:
msg = "Undefined";
}
printf("Cooler status: %s, CCD temperature: %g, Heatsing temperature: %g\n",
msg, currtemp, ApnGlueGetHotTemp());
ApnGlueReadSetPoint(&currtemp, NULL);
if(ALTA_OK != altaerr) ERREND();
printf("Temperature setpoint: %g\n", currtemp);
// ApnGlueSetTemp(30.);
if(ALTA_OK != altaerr) ERREND();
// ApnGlueOpenShutter(0);
printf("Shutter: %s\n", ApnGlueReadShutter() ? "opened" : "closed");
*errmsg = 0;
printf("Current speed: %u\n", ApnGlueGetSpeed());
if(ALTA_OK != ApnGlueSetExpGeom(5000, 5000, 1, 0, 8, 8, 0, 0, &W, &H, errmsg))
ERREND();
printf("Image parameters: W = %d, H = %d\n", W, H);
double exptime = 1.;
if(ALTA_OK != ApnGlueStartExp(&exptime, 0)) ERREND();
printf("start exposition for %g s\n", exptime);
while(!ApnGlueExpDone());
printf("Exposition done.\n");
unsigned short *buf = (unsigned short *) calloc(W*H, sizeof(unsigned short));
if(ALTA_OK != ApnGlueReadPixels(buf, W*H, NULL)) ERREND();
printf("\nimage value in pixel (W/2, H/2): %u\n", buf[(W+1)*H/2]);
theend:
ApnGlueClose();
return 0;
}

View File

@@ -0,0 +1,52 @@
/*
* test.c - file for wrapper testing
*
* Copyright 2013 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include "libapogee.h"
#define ERREND() do{printf("Error!"); if(altaerr != ALTA_OK) printf(" errno: %d", altaerr); printf("\n"); goto theend;}while(0)
int main(_U_ int argc, _U_ char **argv){
char errmsg[256];
*errmsg = 0;
int res = ApnGlueWheelOpen(0, FW50_7S);
if(res || altaerr != ALTA_OK){
printf("Can't open! No such device.\n");
return 1;
}
int maxpos, curpos;
maxpos = ApnGlueWheelGetMaxPos();
if(maxpos < 1) ERREND();
curpos = ApnGlueWheelGetPos();
if(curpos < 0) ERREND();
printf("Found a wheel, which have %d positions, current position is %d\n", maxpos, curpos);
if(curpos == maxpos) curpos = 1;
else curpos++;
printf("Go to position %d\n", curpos);
if(ApnGlueWheelSetPos(curpos)) ERREND();
while(ApnGlueWheelGetStatus()); // wait while moving
curpos = ApnGlueWheelGetPos();
if(curpos < 0) ERREND();
printf("Now wheel is on position %d\n", curpos);
theend:
ApnGlueWheelClose();
return 0;
}