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}
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(
OUTPUT ${MO_FILE}
COMMAND make RU_FILE && ${GETTEXT_MSGFMT_EXECUTABLE} ${RU_FILE} -o ${MO_FILE}
DEPENDS ${PO_FILE} ${SOURCES}
COMMAND make RU_FILE && make MO_FILE
DEPENDS ${RU_FILE} ${SOURCES}
)
endif()

View File

@ -27,7 +27,7 @@ find_path(APOGEE_LIB_INCLUDE_DIR NAMES Alta.h
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
/usr/lib
/usr/local/lib

View File

@ -2,8 +2,10 @@
SUBSYSTEM!="usb", ACTION!="add", GOTO="apogee_rules_end"
# Apogee Alta-U
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"
# Apogee Aspen
ATTRS{idVendor}=="125c", ATTRS{idProduct}=="0030",GROUP="users", MODE="666"
# Apogee USB Filter Wheel
ATTRS{idVendor}=="125c", ATTRS{idProduct}=="0100",GROUP="users", MODE="666"
LABEL="apogee_rules_end"

View File

@ -32,6 +32,7 @@
#include <Quad.h>
#include <CameraInfo.h>
#include <FindDeviceUsb.h>
#include <FindDeviceEthernet.h>
#include <ApogeeFilterWheel.h>
#include <ApogeeCam.h>
@ -52,6 +53,15 @@ APOGEE_ALTAF, APOGEE_ASPEN or APOGEE_QUAD"
// static class for CCD device
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
CCDerr altaerr = ALTA_OK;
@ -106,8 +116,8 @@ std::string GetItemFromFindStr( const std::string & msg, const std::string & ite
return result;
}
}
fprintf(stderr, "Bug! Can't find parameter in description string!\n");
exit(1);
// fprintf(stderr, "Bug! Can't find parameter in description string!\n");
// exit(1);
std::string noOp;
return noOp;
}
@ -121,7 +131,12 @@ uint16_t readUI(const std::string & msg, const std::string & key){
return (uint16_t) x;
}
CamParams *getCamParams(std::string & msg){
std::string port = GetItemFromFindStr(msg, "port=");
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.Id = readUI(msg, "id=");
par.deviceType = GetItemFromFindStr(msg, "deviceType=");
@ -129,12 +144,32 @@ CamParams *getCamParams(std::string & msg){
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
* Don't forget to call FREE!!!
* @param pid, vid - device PID and VID
*/
char *ApnGlueGetInfo(int *pid, int *vid){
if(!alta || isethernet) return NULL;
if(pid || vid){
uint16_t v = 1, p = 2, d = 3;
alta->GetUsbVendorInfo(v, p, d);
@ -148,6 +183,44 @@ char *ApnGlueGetInfo(int *pid, int *vid){
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>
* IT DON'T WORK WITH MULTIPLE CAMERAS SIMULTANEOUSLY!
@ -155,21 +228,44 @@ char *ApnGlueGetInfo(int *pid, int *vid){
* @return 0 in case of success
*/
int ApnGlueOpen(_U_ unsigned int id){
bool found = false;
CamParams *campar = NULL;
std::string ioInterface;
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();
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->OpenConnection(ioInterface, campar->address, campar->FirmwareRev, campar->Id);
alta->Init();
}CATCH(ALTA_NO_SUCH_DEVICE);
return(altaerr);
}
/**
* Close connection and destroy camera object
*/

View File

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

View File

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

21
usage.c
View File

@ -41,6 +41,8 @@ char
,*observers = NULL // observers name
,*prog_id = NULL // program identificator
,*author = NULL // author of program
,*subnet = NULL // subnet for ethernet camera discovery
,*cammsgid = NULL // MSG-ID of camera
;
int
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",
// "ïÔÏÂÒÁÚÉÔØ ÎÁ ÜËÒÁÎÅ ÐÏÌÕÞÅÎÎÏÅ ÉÚÏÂÒÁÖÅÎÉÅ"
_("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",
// "ÎÅ ÚÁÓ×ÅÞÉ×ÁÔØ ÍÁÔÒÉÃÕ ÐÅÒÅÄ ÜËÓÐÏÚÉÃÉÅÊ"
_("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",
// "×ÅÓÔÉ ÚÁÐÉÓØ ÒÁÂÏÞÉÈ ÔÅÍÐÅÒÁÔÕÒ × ÆÁÊÌ 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",
// "ÒÁÂÏÔÁÔØ Ó N-Ê ËÁÍÅÒÏÊ"
_("work with Nth camera"));
@ -253,7 +261,7 @@ void usage(char *fmt, ...){
void parse_args(int argc, char **argv){
FNAME();
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[] = {
/* { name, has_arg, flag, val }, ÇÄÅ:
* name - name of long parameter
@ -267,6 +275,7 @@ void parse_args(int argc, char **argv){
{"cooler-off", 0, 0, 'c'},
{"dark", 0, 0, 'd'},
{"display-image",0, 0, 'D'},
{"--ether-subnet",1,0, 'E'},
{"no-flash", 0, 0, 'f'},
{"fan-speed", 1, 0, 'F'},
{"wheel-get", 0, 0, 'g'},
@ -277,6 +286,7 @@ void parse_args(int argc, char **argv){
{"instrument", 1, 0, 'i'},
{"log-only", 0, 0, 'L'},
{"tlog", 0, 0, 'l'},
{"msg-id", 1, 0, 'M'},
{"ncam", 1, 0, 'N'},
{"nframes", 1, 0, 'n'},
{"object", 1, 0, 'O'},
@ -343,6 +353,11 @@ void parse_args(int argc, char **argv){
ERR("%s was compiled without OpenGL support!", __progname);
#endif
break;
case 'E':
subnet = strdup(optarg);
// "ðÏÄÓÅÔØ: %s"
info(_("Subnet: %s"), subnet);
break;
case 'f':
noflash = TRUE;
// "îÅ ÚÁÓ×ÅÞÉ×ÁÔØ ËÁÍÅÒÕ ÄÏ ÜËÓÐÏÚÉÃÉÉ"
@ -405,6 +420,10 @@ void parse_args(int argc, char **argv){
// "óÏÈÒÁÎÅÎÉÅ ÖÕÒÎÁÌÁ ÔÅÍÐÅÒÁÔÕÒ"
info(_("Save temperature log"));
break;
case 'M':
cammsgid = strdup(optarg);
info("MSG_ID: %s", cammsgid);
break;
case 'N':
only_turret = FALSE;
if (myatoi(&Ncam, optarg) || Ncam < 1){

View File

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