diff --git a/CMakeLists.txt b/CMakeLists.txt index 147f5bd..66fb019 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/apogee_C_wrapper/CMakeLists.txt b/apogee_C_wrapper/CMakeLists.txt index 6f0827b..d6b5927 100644 --- a/apogee_C_wrapper/CMakeLists.txt +++ b/apogee_C_wrapper/CMakeLists.txt @@ -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 diff --git a/apogee_C_wrapper/src/60-apogee.rules b/apogee_C_wrapper/src/60-apogee.rules index c0c6a5c..a1001a6 100644 --- a/apogee_C_wrapper/src/60-apogee.rules +++ b/apogee_C_wrapper/src/60-apogee.rules @@ -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" diff --git a/apogee_C_wrapper/src/libapogee.cpp b/apogee_C_wrapper/src/libapogee.cpp index 80ee1d8..431e85c 100644 --- a/apogee_C_wrapper/src/libapogee.cpp +++ b/apogee_C_wrapper/src/libapogee.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -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 ∥ } +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 * 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 == "") - 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 */ diff --git a/apogee_C_wrapper/src/libapogee.h b/apogee_C_wrapper/src/libapogee.h index f30887a..a6d2ce8 100644 --- a/apogee_C_wrapper/src/libapogee.h +++ b/apogee_C_wrapper/src/libapogee.h @@ -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); diff --git a/takepic.c b/takepic.c index f930301..46e0f2c 100644 --- a/takepic.c +++ b/takepic.c @@ -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,15 +362,18 @@ DBG("open %d", Ncam); // "Адрес USB: " char *msg = NULL; msg = ApnGlueGetInfo(&pid, &vid); - printf("\n Camera info:\n%s\n", msg); - free(msg); + 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(); - reset_usb_port(pid, vid); + if(pid > 0 && vid > 0) + reset_usb_port(pid, vid); break; case Sleep: if(ApnGluePowerDown()) @@ -480,7 +489,8 @@ DBG("open %d", Ncam); ERR(_("malloc() failed!")); } if(ApnGlueStartExp(&E, 0)){ - reset_usb_port(pid, vid); + if(pid > 0 && vid > 0) + reset_usb_port(pid, vid); // "Ошибка экспозиции!" if(ApnGlueStartExp(&E, 0)) ERR("Error exposing frame!"); } @@ -532,7 +542,8 @@ DBG("open %d", Ncam); ignore_signals(); DBG("start exp"); if(ApnGlueStartExp(&E, shutter)){ - reset_usb_port(pid, vid); + if(pid > 0 && vid > 0) + reset_usb_port(pid, vid); // "Ошибка экспозиции!" if(ApnGlueStartExp(&E, shutter)) ERR("Error exposing frame!"); } diff --git a/usage.c b/usage.c index e205849..4a6b435 100644 --- a/usage.c +++ b/usage.c @@ -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){ diff --git a/usage.h b/usage.h index 7e41c2a..6cc877b 100644 --- a/usage.h +++ b/usage.h @@ -84,6 +84,8 @@ extern char ,*observers ,*prog_id ,*author + ,*subnet + ,*cammsgid ; void usage(char *fmt, ...); void parse_args(int argc, char **argv);