added support for network cameras

This commit is contained in:
eddyem 2015-05-12 14:28:15 +03:00
parent ec8afa327d
commit 68721f30e2
8 changed files with 158 additions and 20 deletions

View File

@ -106,10 +106,15 @@ if(DEFINED EBUG)
COMMAND [ -f ${RU_FILE} ] && ${GETTEXT_MSGMERGE_EXECUTABLE} -Uis ${RU_FILE} ${PO_FILE} || cp ${PO_FILE} ${RU_FILE} COMMAND [ -f ${RU_FILE} ] && ${GETTEXT_MSGMERGE_EXECUTABLE} -Uis ${RU_FILE} ${PO_FILE} || cp ${PO_FILE} ${RU_FILE}
DEPENDS ${PO_FILE} ${SOURCES} DEPENDS ${PO_FILE} ${SOURCES}
) )
add_custom_target(
MO_FILE
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} ${RU_FILE} -o ${MO_FILE}
DEPENDS ${RU_FILE} ${SOURCES}
)
add_custom_command( add_custom_command(
OUTPUT ${MO_FILE} OUTPUT ${MO_FILE}
COMMAND make RU_FILE && ${GETTEXT_MSGFMT_EXECUTABLE} ${RU_FILE} -o ${MO_FILE} COMMAND make RU_FILE && make MO_FILE
DEPENDS ${PO_FILE} ${SOURCES} DEPENDS ${RU_FILE} ${SOURCES}
) )
endif() endif()

View File

@ -27,7 +27,7 @@ find_path(APOGEE_LIB_INCLUDE_DIR NAMES Alta.h
PATH_SUFFIXES libapogee-3.0/apogee PATH_SUFFIXES libapogee-3.0/apogee
) )
find_library(APOGEE_LIB NAMES apogee apogee-3.0.2865 apogeeu find_library(APOGEE_LIB NAMES apogee apogeeu
PATHS /lib PATHS /lib
/usr/lib /usr/lib
/usr/local/lib /usr/local/lib

View File

@ -2,8 +2,10 @@
SUBSYSTEM!="usb", ACTION!="add", GOTO="apogee_rules_end" SUBSYSTEM!="usb", ACTION!="add", GOTO="apogee_rules_end"
# Apogee Alta-U # Apogee Alta-U
ATTRS{idVendor}=="125c", ATTRS{idProduct}=="0010", GROUP="users", MODE="666" ATTRS{idVendor}=="125c", ATTRS{idProduct}=="0010", GROUP="users", MODE="666"
# Apogee Ascent # Apogee Ascent and AltaF
ATTRS{idVendor}=="125c", ATTRS{idProduct}=="0020",GROUP="users", MODE="666" ATTRS{idVendor}=="125c", ATTRS{idProduct}=="0020",GROUP="users", MODE="666"
# Apogee Aspen
ATTRS{idVendor}=="125c", ATTRS{idProduct}=="0030",GROUP="users", MODE="666"
# Apogee USB Filter Wheel # Apogee USB Filter Wheel
ATTRS{idVendor}=="125c", ATTRS{idProduct}=="0100",GROUP="users", MODE="666" ATTRS{idVendor}=="125c", ATTRS{idProduct}=="0100",GROUP="users", MODE="666"
LABEL="apogee_rules_end" LABEL="apogee_rules_end"

View File

@ -32,6 +32,7 @@
#include <Quad.h> #include <Quad.h>
#include <CameraInfo.h> #include <CameraInfo.h>
#include <FindDeviceUsb.h> #include <FindDeviceUsb.h>
#include <FindDeviceEthernet.h>
#include <ApogeeFilterWheel.h> #include <ApogeeFilterWheel.h>
#include <ApogeeCam.h> #include <ApogeeCam.h>
@ -52,6 +53,15 @@ APOGEE_ALTAF, APOGEE_ASPEN or APOGEE_QUAD"
// static class for CCD device // static class for CCD device
static CCD *alta = NULL; static CCD *alta = NULL;
static bool isethernet = false;
int ApnGlueIsEthernet(){
if(isethernet) return 1;
else return 0;
}
static std::string cam_msg_id = "";
void ApnGlueSetMsgId(char *str){
cam_msg_id = str;
}
// static variable with last error // static variable with last error
CCDerr altaerr = ALTA_OK; CCDerr altaerr = ALTA_OK;
@ -106,8 +116,8 @@ std::string GetItemFromFindStr( const std::string & msg, const std::string & ite
return result; return result;
} }
} }
fprintf(stderr, "Bug! Can't find parameter in description string!\n"); // fprintf(stderr, "Bug! Can't find parameter in description string!\n");
exit(1); // exit(1);
std::string noOp; std::string noOp;
return noOp; return noOp;
} }
@ -121,7 +131,12 @@ uint16_t readUI(const std::string & msg, const std::string & key){
return (uint16_t) x; return (uint16_t) x;
} }
CamParams *getCamParams(std::string & msg){ CamParams *getCamParams(std::string & msg){
std::string port = GetItemFromFindStr(msg, "port=");
par.address = GetItemFromFindStr(msg, "address="); par.address = GetItemFromFindStr(msg, "address=");
if(port.size()){ // there's an network device
par.address.append(":");
par.address.append(port);
}
par.FirmwareRev = readUI(msg, "firmwareRev="); par.FirmwareRev = readUI(msg, "firmwareRev=");
par.Id = readUI(msg, "id="); par.Id = readUI(msg, "id=");
par.deviceType = GetItemFromFindStr(msg, "deviceType="); par.deviceType = GetItemFromFindStr(msg, "deviceType=");
@ -129,12 +144,32 @@ CamParams *getCamParams(std::string & msg){
return &par; return &par;
} }
static bool IsProperDevice(const std::string & msg){
std::string model = GetItemFromFindStr(msg, "model=");
std::string
#if defined APOGEE_ASCENT
cam("Ascent");
#elif defined APOGEE_ALTA
cam("Alta");
#elif defined APOGEE_ALTAF
cam("AltaF");
#elif defined APOGEE_ASPEN
cam("Aspen");
#elif defined APOGEE_QUAD
cam("Quad");
#else
return false;
#endif
return(0 == model.compare(0, cam.size(), cam) ? true : false );
}
/** /**
* return camera info * return camera info
* Don't forget to call FREE!!! * Don't forget to call FREE!!!
* @param pid, vid - device PID and VID * @param pid, vid - device PID and VID
*/ */
char *ApnGlueGetInfo(int *pid, int *vid){ char *ApnGlueGetInfo(int *pid, int *vid){
if(!alta || isethernet) return NULL;
if(pid || vid){ if(pid || vid){
uint16_t v = 1, p = 2, d = 3; uint16_t v = 1, p = 2, d = 3;
alta->GetUsbVendorInfo(v, p, d); alta->GetUsbVendorInfo(v, p, d);
@ -148,6 +183,44 @@ char *ApnGlueGetInfo(int *pid, int *vid){
return writable; return writable;
} }
std::string subnet = "";
/**
* Set subnet name to use network camera
*/
void ApnGlueSetSubnet(char *val){
subnet = std::string(val);
}
/**
* try to find USB device
* return pointer to CamParams of found device or NULL
*/
static CamParams *findUSB(){
FindDeviceUsb look4cam;
std::string msg = look4cam.Find();
if(!IsProperDevice(msg)) // device not found
return NULL;
std::cout << "Camera MSG_ID=" << msg << std::endl;
isethernet = false;
return getCamParams(msg);
}
/**
* try to find ethernet device
* return pointer to CamParams of found device or NULL
*/
static CamParams *findNET(){
if(subnet.size() == 0) return NULL; // subnet wasn't defined
FindDeviceEthernet look4cam;
DBG(subnet);
clearenv(); // clear all proxy & other data
std::string msg = look4cam.Find(subnet);
if(!IsProperDevice(msg)) // device not found
return NULL;
std::cout << "Camera MSG_ID=" << msg << std::endl;
isethernet = true;
return getCamParams(msg);
}
/** /**
* Open camera device and assign it to variable <alta> * Open camera device and assign it to variable <alta>
* IT DON'T WORK WITH MULTIPLE CAMERAS SIMULTANEOUSLY! * IT DON'T WORK WITH MULTIPLE CAMERAS SIMULTANEOUSLY!
@ -155,21 +228,44 @@ char *ApnGlueGetInfo(int *pid, int *vid){
* @return 0 in case of success * @return 0 in case of success
*/ */
int ApnGlueOpen(_U_ unsigned int id){ int ApnGlueOpen(_U_ unsigned int id){
bool found = false;
CamParams *campar = NULL;
std::string ioInterface;
TRY{ TRY{
if(cam_msg_id.size()){ // user had set MSG param, try it
DBG("Try to find camera by given id");
if(IsProperDevice(cam_msg_id) && (campar = getCamParams(cam_msg_id))){
found = true;
if(GetItemFromFindStr(cam_msg_id, "interface=") == "ethernet"){
clearenv(); // clear all proxy & other data
isethernet = true;
}else
isethernet = false;
}
}
if(!found && subnet.size()){ // there's an ability of network camera presence
DBG("Try to find network camera");
if((campar = findNET())){
found = true;
}else std::cerr << "Network camera not found, try USB" << std::endl;
}
if(!found){
DBG("Try to find USB camera");
if(!(campar = findUSB()))
RETERR(ALTA_NO_SUCH_DEVICE);
}
if(isethernet)
ioInterface = "ethernet";
else
ioInterface = "usb";
alta = (CCD*) new CCD(); alta = (CCD*) new CCD();
std::string ioInterface("usb"); alta->OpenConnection(ioInterface, campar->address, campar->FirmwareRev, campar->Id);
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(); alta->Init();
}CATCH(ALTA_NO_SUCH_DEVICE); }CATCH(ALTA_NO_SUCH_DEVICE);
return(altaerr); return(altaerr);
} }
/** /**
* Close connection and destroy camera object * Close connection and destroy camera object
*/ */

View File

@ -122,6 +122,9 @@ extern "C" {
#endif #endif
// Camera // Camera
void ApnGlueSetSubnet(char *val);
int ApnGlueIsEthernet();
void ApnGlueSetMsgId(char *str);
int ApnGlueOpen(unsigned int id); int ApnGlueOpen(unsigned int id);
void ApnGlueClose(); void ApnGlueClose();
void ApnGlueGetName(char **sensor, char **camera); void ApnGlueGetName(char **sensor, char **camera);

View File

@ -342,9 +342,15 @@ int main(int argc, char **argv){
// And camera block // And camera block
// First - open camera devise // First - open camera devise
if(subnet) ApnGlueSetSubnet(subnet); // set subnet name if there's an ethernet camera
if(cammsgid) ApnGlueSetMsgId(cammsgid); // set msgid given by user
if(ApnGlueOpen(Ncam)){ if(ApnGlueOpen(Ncam)){
// "îÅ ÍÏÇÕ ÏÔËÒÙÔØ ËÁÍÅÒÕ, ÚÁ×ÅÒÛÁÀ" // "îÅ ÍÏÇÕ ÏÔËÒÙÔØ ËÁÍÅÒÕ, ÚÁ×ÅÒÛÁÀ"
ERR(_("Can't open camera device, exit")); ERR(_("Can't open camera device, exit"));
if(ApnGlueIsEthernet()){
// "ðÏÐÙÔÁÊÔÅÓØ ÐÅÒÅÚÁÇÒÕÚÉÔØ ËÁÍÅÒÕ ÞÅÒÅÚ ×ÅÂ-ÉÎÔÅÒÆÅÊÓ"
info(_("Try to reboot camera from web-interface"));
}
exit(9); exit(9);
} }
DBG("open %d", Ncam); DBG("open %d", Ncam);
@ -356,14 +362,17 @@ DBG("open %d", Ncam);
// "áÄÒÅÓ USB: " // "áÄÒÅÓ USB: "
char *msg = NULL; char *msg = NULL;
msg = ApnGlueGetInfo(&pid, &vid); msg = ApnGlueGetInfo(&pid, &vid);
if(msg){
printf("\n Camera info:\n%s\n", msg); printf("\n Camera info:\n%s\n", msg);
free(msg); free(msg);
}
// Second - check whether we want do a simple power operations // Second - check whether we want do a simple power operations
if(StopRes){ if(StopRes){
switch(StopRes){ switch(StopRes){
case Reset: case Reset:
ApnGlueReset(); ApnGlueReset();
if(pid > 0 && vid > 0)
reset_usb_port(pid, vid); reset_usb_port(pid, vid);
break; break;
case Sleep: case Sleep:
@ -480,6 +489,7 @@ DBG("open %d", Ncam);
ERR(_("malloc() failed!")); ERR(_("malloc() failed!"));
} }
if(ApnGlueStartExp(&E, 0)){ if(ApnGlueStartExp(&E, 0)){
if(pid > 0 && vid > 0)
reset_usb_port(pid, vid); reset_usb_port(pid, vid);
// "ïÛÉÂËÁ ÜËÓÐÏÚÉÃÉÉ!" // "ïÛÉÂËÁ ÜËÓÐÏÚÉÃÉÉ!"
if(ApnGlueStartExp(&E, 0)) ERR("Error exposing frame!"); if(ApnGlueStartExp(&E, 0)) ERR("Error exposing frame!");
@ -532,6 +542,7 @@ DBG("open %d", Ncam);
ignore_signals(); ignore_signals();
DBG("start exp"); DBG("start exp");
if(ApnGlueStartExp(&E, shutter)){ if(ApnGlueStartExp(&E, shutter)){
if(pid > 0 && vid > 0)
reset_usb_port(pid, vid); reset_usb_port(pid, vid);
// "ïÛÉÂËÁ ÜËÓÐÏÚÉÃÉÉ!" // "ïÛÉÂËÁ ÜËÓÐÏÚÉÃÉÉ!"
if(ApnGlueStartExp(&E, shutter)) ERR("Error exposing frame!"); if(ApnGlueStartExp(&E, shutter)) ERR("Error exposing frame!");

21
usage.c
View File

@ -41,6 +41,8 @@ char
,*observers = NULL // observers name ,*observers = NULL // observers name
,*prog_id = NULL // program identificator ,*prog_id = NULL // program identificator
,*author = NULL // author of program ,*author = NULL // author of program
,*subnet = NULL // subnet for ethernet camera discovery
,*cammsgid = NULL // MSG-ID of camera
; ;
int int
exptime = -1 // exposition time (in ms), -1 means no exposition exptime = -1 // exposition time (in ms), -1 means no exposition
@ -138,6 +140,9 @@ void usage(char *fmt, ...){
printf("\t-D,\t--display-image\t\t%s\n", printf("\t-D,\t--display-image\t\t%s\n",
// "ïÔÏÂÒÁÚÉÔØ ÎÁ ÜËÒÁÎÅ ÐÏÌÕÞÅÎÎÏÅ ÉÚÏÂÒÁÖÅÎÉÅ" // "ïÔÏÂÒÁÚÉÔØ ÎÁ ÜËÒÁÎÅ ÐÏÌÕÞÅÎÎÏÅ ÉÚÏÂÒÁÖÅÎÉÅ"
_("Display last image")); _("Display last image"));
printf("\t-E,\t--ether-subnet\t\t%s\n",
// "ðÏÄÓÅÔØ ÄÌÑ ÐÏÉÓËÁ ethernet-ËÁÍÅÒÙ"
_("Subnet fot ethernet camera discovery"));
printf("\t-f,\t--no-flash\t\t%s\n", printf("\t-f,\t--no-flash\t\t%s\n",
// "ÎÅ ÚÁÓ×ÅÞÉ×ÁÔØ ÍÁÔÒÉÃÕ ÐÅÒÅÄ ÜËÓÐÏÚÉÃÉÅÊ" // "ÎÅ ÚÁÓ×ÅÞÉ×ÁÔØ ÍÁÔÒÉÃÕ ÐÅÒÅÄ ÜËÓÐÏÚÉÃÉÅÊ"
_("Don't flash CCD chip before expose")); _("Don't flash CCD chip before expose"));
@ -168,6 +173,9 @@ void usage(char *fmt, ...){
printf("\t-l,\t--tlog\t\t\t%s\n", printf("\t-l,\t--tlog\t\t\t%s\n",
// "×ÅÓÔÉ ÚÁÐÉÓØ ÒÁÂÏÞÉÈ ÔÅÍÐÅÒÁÔÕÒ × ÆÁÊÌ temp_log" // "×ÅÓÔÉ ÚÁÐÉÓØ ÒÁÂÏÞÉÈ ÔÅÍÐÅÒÁÔÕÒ × ÆÁÊÌ temp_log"
_("make temperatures logging to file temp_log")); _("make temperatures logging to file temp_log"));
printf("\t-M,\t--msg-id\t\t%s\n",
// "ÏÔËÒÙÔØ ËÁÍÅÒÕ ÐÏ MSG-ID"
_("open camera by its MSG-ID"));
printf("\t-N,\t--ncam=N\t\t%s\n", printf("\t-N,\t--ncam=N\t\t%s\n",
// "ÒÁÂÏÔÁÔØ Ó N-Ê ËÁÍÅÒÏÊ" // "ÒÁÂÏÔÁÔØ Ó N-Ê ËÁÍÅÒÏÊ"
_("work with Nth camera")); _("work with Nth camera"));
@ -253,7 +261,7 @@ void usage(char *fmt, ...){
void parse_args(int argc, char **argv){ void parse_args(int argc, char **argv){
FNAME(); FNAME();
int i; int i;
char short_options[] = "A:cdDfF:gG:H:h:I:i:LlN:n:O:o:P:p:Rr:SsTt:v:Ww:x:X:Y:"; char short_options[] = "A:cdDE:fF:gG:H:h:I:i:LlM:N:n:O:o:P:p:Rr:SsTt:v:Ww:x:X:Y:";
struct option long_options[] = { struct option long_options[] = {
/* { name, has_arg, flag, val }, ÇÄÅ: /* { name, has_arg, flag, val }, ÇÄÅ:
* name - name of long parameter * name - name of long parameter
@ -267,6 +275,7 @@ void parse_args(int argc, char **argv){
{"cooler-off", 0, 0, 'c'}, {"cooler-off", 0, 0, 'c'},
{"dark", 0, 0, 'd'}, {"dark", 0, 0, 'd'},
{"display-image",0, 0, 'D'}, {"display-image",0, 0, 'D'},
{"--ether-subnet",1,0, 'E'},
{"no-flash", 0, 0, 'f'}, {"no-flash", 0, 0, 'f'},
{"fan-speed", 1, 0, 'F'}, {"fan-speed", 1, 0, 'F'},
{"wheel-get", 0, 0, 'g'}, {"wheel-get", 0, 0, 'g'},
@ -277,6 +286,7 @@ void parse_args(int argc, char **argv){
{"instrument", 1, 0, 'i'}, {"instrument", 1, 0, 'i'},
{"log-only", 0, 0, 'L'}, {"log-only", 0, 0, 'L'},
{"tlog", 0, 0, 'l'}, {"tlog", 0, 0, 'l'},
{"msg-id", 1, 0, 'M'},
{"ncam", 1, 0, 'N'}, {"ncam", 1, 0, 'N'},
{"nframes", 1, 0, 'n'}, {"nframes", 1, 0, 'n'},
{"object", 1, 0, 'O'}, {"object", 1, 0, 'O'},
@ -343,6 +353,11 @@ void parse_args(int argc, char **argv){
ERR("%s was compiled without OpenGL support!", __progname); ERR("%s was compiled without OpenGL support!", __progname);
#endif #endif
break; break;
case 'E':
subnet = strdup(optarg);
// "ðÏÄÓÅÔØ: %s"
info(_("Subnet: %s"), subnet);
break;
case 'f': case 'f':
noflash = TRUE; noflash = TRUE;
// "îÅ ÚÁÓ×ÅÞÉ×ÁÔØ ËÁÍÅÒÕ ÄÏ ÜËÓÐÏÚÉÃÉÉ" // "îÅ ÚÁÓ×ÅÞÉ×ÁÔØ ËÁÍÅÒÕ ÄÏ ÜËÓÐÏÚÉÃÉÉ"
@ -405,6 +420,10 @@ void parse_args(int argc, char **argv){
// "óÏÈÒÁÎÅÎÉÅ ÖÕÒÎÁÌÁ ÔÅÍÐÅÒÁÔÕÒ" // "óÏÈÒÁÎÅÎÉÅ ÖÕÒÎÁÌÁ ÔÅÍÐÅÒÁÔÕÒ"
info(_("Save temperature log")); info(_("Save temperature log"));
break; break;
case 'M':
cammsgid = strdup(optarg);
info("MSG_ID: %s", cammsgid);
break;
case 'N': case 'N':
only_turret = FALSE; only_turret = FALSE;
if (myatoi(&Ncam, optarg) || Ncam < 1){ if (myatoi(&Ncam, optarg) || Ncam < 1){

View File

@ -84,6 +84,8 @@ extern char
,*observers ,*observers
,*prog_id ,*prog_id
,*author ,*author
,*subnet
,*cammsgid
; ;
void usage(char *fmt, ...); void usage(char *fmt, ...);
void parse_args(int argc, char **argv); void parse_args(int argc, char **argv);