mirror of
https://github.com/eddyem/eddys_snippets.git
synced 2026-03-20 08:41:02 +03:00
Add short list to HSFV_manage
This commit is contained in:
@@ -23,18 +23,16 @@ given turret.
|
||||
|
||||
## Usage examples
|
||||
|
||||
#### List all devices connected
|
||||
Свойства подключенного колеса
|
||||
Wheel ID 'A', name 'UBVRI', serial '00000563', 5 filters:
|
||||
1: 'U'
|
||||
2: 'B'
|
||||
3: 'V'
|
||||
4: 'R'
|
||||
5: 'I'
|
||||
current position: 1
|
||||
#### Short list of connected devices (wheel ID, turret serial and current position):
|
||||
HSFW_manage
|
||||
'B' '00000563' 1
|
||||
'A' '00000532' 1
|
||||
|
||||
Свойства подключенного колеса
|
||||
Wheel ID 'B', name 'Sloan', serial '00000532', 5 filters:
|
||||
#### List all devices connected
|
||||
HSFW_manage --list
|
||||
|
||||
Connected wheel properties
|
||||
Wheel ID 'B' , name 'Sloan', serial '00000563' , 5 filters:
|
||||
1: '1'
|
||||
2: '2'
|
||||
3: '3'
|
||||
@@ -42,6 +40,15 @@ given turret.
|
||||
5: '5'
|
||||
current position: 1
|
||||
|
||||
Connected wheel properties
|
||||
Wheel ID 'A' , name 'UBVRI', serial '00000532' , 5 filters:
|
||||
1: 'U'
|
||||
2: 'B'
|
||||
3: 'V'
|
||||
4: 'R'
|
||||
5: 'I'
|
||||
current position: 1
|
||||
|
||||
#### Move wheel by turret's serial and position number
|
||||
HSFW_manage -s 00000563 -p 3
|
||||
|
||||
|
||||
@@ -36,54 +36,54 @@
|
||||
int help;
|
||||
glob_pars G;
|
||||
|
||||
int listNms = 0 // list names
|
||||
,gohome = 0 // first go home
|
||||
,reName = 0 // rename wheels/positions
|
||||
,showpos = 0 // show current position (if none args)
|
||||
,setdef = 0 // reset all names to default values
|
||||
int listNms = LIST_NONE // list names
|
||||
,gohome = 0 // first go home
|
||||
,reName = 0 // rename wheels/positions
|
||||
,showpos = 0 // show current position (if none args)
|
||||
,setdef = 0 // reset all names to default values
|
||||
;
|
||||
|
||||
|
||||
// DEFAULTS
|
||||
// default global parameters
|
||||
glob_pars const Gdefault = {
|
||||
NULL // wheelID
|
||||
,NULL // wheelName
|
||||
,NULL // serial
|
||||
,0 // filterPos ( 0 - get current position)
|
||||
,NULL // filterName
|
||||
,NULL // filterId
|
||||
NULL // wheelID
|
||||
,NULL // wheelName
|
||||
,NULL // serial
|
||||
,0 // filterPos ( 0 - get current position)
|
||||
,NULL // filterName
|
||||
,NULL // filterId
|
||||
};
|
||||
|
||||
/*
|
||||
* Define command line options by filling structure:
|
||||
* name has_arg flag val type argptr help
|
||||
* name has_arg flag val type argptr help
|
||||
*/
|
||||
myoption cmdlnopts[] = {
|
||||
/// "ÏÔÏÂÒÁÚÉÔØ ÜÔÕ ÓÐÒÁ×ËÕ"
|
||||
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), N_("show this help")},
|
||||
/// "ÂÕË×ÅÎÎÙÊ ÉÄÅÎÔÉÆÉËÁÔÏÒ ËÏÌÅÓÁ"
|
||||
{"wheel-id",NEED_ARG, NULL, 'W', arg_string, APTR(&G.wheelID), N_("letter wheel identificator")},
|
||||
/// "ÎÁÚ×ÁÎÉÅ ËÏÌÅÓÁ"
|
||||
{"wheel-name",NEED_ARG, NULL, 'N', arg_string, APTR(&G.wheelName), N_("wheel name")},
|
||||
/// "ÓÅÒÉÊÎÙÊ ÎÏÍÅÒ ÔÕÒÅÌÉ (Ó ÎÁÞÁÌØÎÙÍÉ ÎÕÌÑÍÉ)"
|
||||
{"serial", NEED_ARG, NULL, 's', arg_string, APTR(&G.serial), N_("turret serial (with leading zeros)")},
|
||||
/// "ÎÏÍÅÒ ÐÏÚÉÃÉÉ ÆÉÌØÔÒÁ"
|
||||
{"f-position",NEED_ARG, NULL, 'p', arg_int, APTR(&G.filterPos), N_("filter position number")},
|
||||
/// "ÎÁÚ×ÁÎÉÅ ÆÉÌØÔÒÁ"
|
||||
{"filter-name",NEED_ARG,NULL, 'n', arg_string, APTR(&G.filterName),N_("filter name")},
|
||||
/// "ÉÄÅÎÔÉÆÉËÁÔÏÒ ÆÉÌØÔÒÁ, ÎÁÐÒÉÍÅÒ, \"A3\""
|
||||
{"filter-id",NEED_ARG, NULL, 'i', arg_string, APTR(&G.filterId), N_("filter identificator like \"A3\"")},
|
||||
/// "ÓÐÉÓÏË ×ÓÅÈ ÓÏÈÒÁÎÅÎÎÙÈ ÉÍÅÎ"
|
||||
{"list-all",NO_ARGS, &listNms,LIST_ALL,arg_none, NULL, N_("list all stored names")},
|
||||
/// "ÓÐÉÓÏË ÉÍÅÎ ÔÏÌØËÏ ÐÒÉÓÕÔÓÔ×ÕÀÝÉÈ ÕÓÔÒÏÊÓÔ×"
|
||||
{"list", NO_ARGS, &listNms,LIST_PRES,arg_none,NULL, N_("list only present devices' names")},
|
||||
/// "ÐÅÒÅÍÅÓÔÉÔØÓÑ × ÓÔÁÒÔÏ×ÕÀ ÐÏÚÉÃÉÀ"
|
||||
{"home", NO_ARGS, NULL, 'H', arg_none, &gohome, N_("move to home position")},
|
||||
/// "ÐÅÒÅÉÍÅÎÏ×ÁÔØ ÓÏÈÒÁÎÅÎÎÙÅ ÉÍÅÎÁ ËÏÌÅÓ/ÆÉÌØÔÒÏ×"
|
||||
{"rename", NO_ARGS, &reName,1, arg_none, NULL, N_("rename stored wheels/filters names")},
|
||||
{"resetnames",NO_ARGS, &setdef,1, arg_none, NULL, N_("reset all names to default values")},
|
||||
end_option
|
||||
/// "ÏÔÏÂÒÁÚÉÔØ ÜÔÕ ÓÐÒÁ×ËÕ"
|
||||
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), N_("show this help")},
|
||||
/// "ÂÕË×ÅÎÎÙÊ ÉÄÅÎÔÉÆÉËÁÔÏÒ ËÏÌÅÓÁ"
|
||||
{"wheel-id",NEED_ARG, NULL, 'W', arg_string, APTR(&G.wheelID), N_("letter wheel identificator")},
|
||||
/// "ÎÁÚ×ÁÎÉÅ ËÏÌÅÓÁ"
|
||||
{"wheel-name",NEED_ARG, NULL, 'N', arg_string, APTR(&G.wheelName), N_("wheel name")},
|
||||
/// "ÓÅÒÉÊÎÙÊ ÎÏÍÅÒ ÔÕÒÅÌÉ (Ó ÎÁÞÁÌØÎÙÍÉ ÎÕÌÑÍÉ)"
|
||||
{"serial", NEED_ARG, NULL, 's', arg_string, APTR(&G.serial), N_("turret serial (with leading zeros)")},
|
||||
/// "ÎÏÍÅÒ ÐÏÚÉÃÉÉ ÆÉÌØÔÒÁ"
|
||||
{"f-position",NEED_ARG, NULL, 'p', arg_int, APTR(&G.filterPos), N_("filter position number")},
|
||||
/// "ÎÁÚ×ÁÎÉÅ ÆÉÌØÔÒÁ"
|
||||
{"filter-name",NEED_ARG,NULL, 'n', arg_string, APTR(&G.filterName),N_("filter name")},
|
||||
/// "ÉÄÅÎÔÉÆÉËÁÔÏÒ ÆÉÌØÔÒÁ, ÎÁÐÒÉÍÅÒ, \"A3\""
|
||||
{"filter-id",NEED_ARG, NULL, 'i', arg_string, APTR(&G.filterId), N_("filter identificator like \"A3\"")},
|
||||
/// "ÓÐÉÓÏË ×ÓÅÈ ÓÏÈÒÁÎÅÎÎÙÈ ÉÍÅÎ"
|
||||
{"list-all",NO_ARGS, &listNms,LIST_ALL,arg_none, NULL, N_("list all stored names")},
|
||||
/// "ÓÐÉÓÏË ÉÍÅÎ ÔÏÌØËÏ ÐÒÉÓÕÔÓÔ×ÕÀÝÉÈ ÕÓÔÒÏÊÓÔ×"
|
||||
{"list", NO_ARGS, &listNms,LIST_PRES,arg_none,NULL, N_("list only present devices' names")},
|
||||
/// "ÐÅÒÅÍÅÓÔÉÔØÓÑ × ÓÔÁÒÔÏ×ÕÀ ÐÏÚÉÃÉÀ"
|
||||
{"home", NO_ARGS, NULL, 'H', arg_none, &gohome, N_("move to home position")},
|
||||
/// "ÐÅÒÅÉÍÅÎÏ×ÁÔØ ÓÏÈÒÁÎÅÎÎÙÅ ÉÍÅÎÁ ËÏÌÅÓ/ÆÉÌØÔÒÏ×"
|
||||
{"rename", NO_ARGS, &reName,1, arg_none, NULL, N_("rename stored wheels/filters names")},
|
||||
{"resetnames",NO_ARGS, &setdef,1, arg_none, NULL, N_("reset all names to default values")},
|
||||
end_option
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -94,45 +94,46 @@ myoption cmdlnopts[] = {
|
||||
* @return TRUE if success
|
||||
*/
|
||||
bool myatod(double *num, const char *str){
|
||||
double res;
|
||||
char *endptr;
|
||||
assert(str);
|
||||
res = strtod(str, &endptr);
|
||||
if(endptr == str || *str == '\0' || *endptr != '\0'){
|
||||
/// "îÅÐÒÁ×ÉÌØÎÙÊ ÆÏÒÍÁÔ ÞÉÓÌÁ double!"
|
||||
WARNX(_("Wrong double number format!"));
|
||||
return FALSE;
|
||||
}
|
||||
*num = res;
|
||||
return TRUE;
|
||||
double res;
|
||||
char *endptr;
|
||||
assert(str);
|
||||
res = strtod(str, &endptr);
|
||||
if(endptr == str || *str == '\0' || *endptr != '\0'){
|
||||
/// "îÅÐÒÁ×ÉÌØÎÙÊ ÆÏÒÍÁÔ ÞÉÓÌÁ double!"
|
||||
WARNX(_("Wrong double number format!"));
|
||||
return FALSE;
|
||||
}
|
||||
*num = res;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse command line options and return dynamically allocated structure
|
||||
* to global parameters
|
||||
* to global parameters
|
||||
* @param argc - copy of argc from main
|
||||
* @param argv - copy of argv from main
|
||||
* @return allocated structure with global parameters
|
||||
*/
|
||||
glob_pars *parse_args(int argc, char **argv){
|
||||
int i, oldargc = argc - 1;
|
||||
void *ptr;
|
||||
ptr = memcpy(&G, &Gdefault, sizeof(G)); assert(ptr);
|
||||
/// "éÓÐÏÌØÚÏ×ÁÎÉÅ: %s [ÁÒÇÕÍÅÎÔÙ] [ÐÒÅÆÉËÓ ×ÙÈÏÄÎÏÇÏ ÆÁÊÌÁ]\n\n\tçÄÅ [ÁÒÇÕÍÅÎÔÙ]:\n"
|
||||
//change_helpstring(_("Usage: %s [args] [outfile prefix] [file list for group operations]\n\n\tWhere args are:\n"));
|
||||
// parse arguments
|
||||
parseargs(&argc, &argv, cmdlnopts);
|
||||
if(help) showhelp(-1, cmdlnopts);
|
||||
if(argc > 0){
|
||||
/// "éÇÎÏÒÉÒÕÀÔÓÑ ÐÁÒÁÍÅÔÒÙ: "
|
||||
WARNX(_("Ignore parameters:"));
|
||||
for (i = 0; i < argc; i++){
|
||||
printf("%s\n", argv[i]);
|
||||
}
|
||||
}
|
||||
if(argc == oldargc){ // no parameters given or given only wrong parameters
|
||||
showpos = 1;
|
||||
}
|
||||
return &G;
|
||||
int i, oldargc = argc - 1;
|
||||
void *ptr;
|
||||
ptr = memcpy(&G, &Gdefault, sizeof(G)); assert(ptr);
|
||||
/// "éÓÐÏÌØÚÏ×ÁÎÉÅ: %s [ÁÒÇÕÍÅÎÔÙ] [ÐÒÅÆÉËÓ ×ÙÈÏÄÎÏÇÏ ÆÁÊÌÁ]\n\n\tçÄÅ [ÁÒÇÕÍÅÎÔÙ]:\n"
|
||||
//change_helpstring(_("Usage: %s [args] [outfile prefix] [file list for group operations]\n\n\tWhere args are:\n"));
|
||||
// parse arguments
|
||||
parseargs(&argc, &argv, cmdlnopts);
|
||||
if(help) showhelp(-1, cmdlnopts);
|
||||
if(argc > 0){
|
||||
/// "éÇÎÏÒÉÒÕÀÔÓÑ ÐÁÒÁÍÅÔÒÙ: "
|
||||
WARNX(_("Ignore parameters:"));
|
||||
for (i = 0; i < argc; i++){
|
||||
printf("%s\n", argv[i]);
|
||||
}
|
||||
}
|
||||
if(argc == oldargc){ // no parameters given or given only wrong parameters
|
||||
//showpos = 1;
|
||||
listNms = LIST_SHORT; // short list of turrets present
|
||||
}
|
||||
return &G;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,17 +29,21 @@
|
||||
* here are some typedef's for global data
|
||||
*/
|
||||
typedef struct{
|
||||
char *wheelID; // ID of wheel to work with
|
||||
char *wheelName; // and/or its name
|
||||
char *serial; // turret's serial (string description)
|
||||
int filterPos; // position of filter
|
||||
char *filterName; // and/or its name
|
||||
char *filterId; // or full ID like "A2"
|
||||
char *wheelID; // ID of wheel to work with
|
||||
char *wheelName; // and/or its name
|
||||
char *serial; // turret's serial (string description)
|
||||
int filterPos; // position of filter
|
||||
char *filterName; // and/or its name
|
||||
char *filterId; // or full ID like "A2"
|
||||
} glob_pars;
|
||||
|
||||
// ids for "list all" & "list present"
|
||||
#define LIST_ALL (1)
|
||||
#define LIST_PRES (2)
|
||||
// ids for "list all", "list present", "list short"
|
||||
typedef enum{
|
||||
LIST_NONE = 0,
|
||||
LIST_ALL,
|
||||
LIST_PRES,
|
||||
LIST_SHORT
|
||||
} listopts;
|
||||
|
||||
// default & global parameters
|
||||
extern glob_pars const Gdefault;
|
||||
|
||||
@@ -66,9 +66,10 @@ void set_cur_wheel(int idx){
|
||||
* Check command line arguments, find filters/wheels by name, find max positions & so on
|
||||
*/
|
||||
void check_args(){
|
||||
FNAME();
|
||||
// here we fill value of wheel_id if no given and present only one turret
|
||||
list_hw(listNms); // also exit if no HW found
|
||||
if(listNms) return;
|
||||
if(listNms != LIST_NONE) return;
|
||||
int i;
|
||||
// add wheel ID to global parameters if there was nothing
|
||||
if(G.serial){ // HW given by its serial
|
||||
@@ -170,6 +171,7 @@ void check_args(){
|
||||
/// "úÁÄÁÎÎÏÅ ËÏÌÅÓÏ ÎÅ ÏÂÎÁÒÕÖÅÎÏ!"
|
||||
ERRX(_("Given wheel not found!"));
|
||||
}
|
||||
DBG("listNms = %d", listNms);
|
||||
if(reName && !G.wheelID){
|
||||
G.wheelID = calloc(2, 1);
|
||||
*G.wheelID = wheel_id;
|
||||
@@ -286,7 +288,7 @@ int poll_regstatus(int fd, int msg){
|
||||
ERRX(_("Error ocured, repeat again"));
|
||||
}
|
||||
usleep(50000);
|
||||
if(msg) printf("."); fflush(stdout);
|
||||
if(msg){printf("."); fflush(stdout);}
|
||||
}
|
||||
if(msg) printf("\n");
|
||||
return buf[4];
|
||||
@@ -339,6 +341,7 @@ void list_props(int verblevl, wheel_descr *wheel){
|
||||
wheel->ID = buf[5];
|
||||
wheel->maxpos = buf[4];
|
||||
DBG("Wheel with id '%c' and maxpos %d", wheel->ID, wheel->maxpos);
|
||||
DBG("Verblevl = %d", verblevl);
|
||||
char *getwname(int id){
|
||||
memset(buf, 0, sizeof(buf));
|
||||
buf[0] = REG_NAME;
|
||||
@@ -353,33 +356,40 @@ void list_props(int verblevl, wheel_descr *wheel){
|
||||
}
|
||||
else return NULL;
|
||||
}
|
||||
if(verblevl == LIST_PRES || !verblevl){ // list only presented devices or not list
|
||||
if(verblevl == LIST_PRES || verblevl == LIST_SHORT || verblevl == LIST_NONE){ // list only presented devices or not list
|
||||
char *nm;
|
||||
/// "\nó×ÏÊÓÔ×Á ÐÏÄËÌÀÞÅÎÎÏÇÏ ËÏÌÅÓÁ\n"
|
||||
if(verblevl) green(_("\nConnected wheel properties\n"));
|
||||
if(verblevl) printf("Wheel ID '%c'", wheel->ID);
|
||||
if(verblevl != LIST_NONE){
|
||||
if(verblevl == LIST_PRES){
|
||||
green(_("\nConnected wheel properties\n"));
|
||||
printf("Wheel ID ");
|
||||
}
|
||||
printf("'%c' ", wheel->ID);
|
||||
}
|
||||
nm = getwname(wheel->ID);
|
||||
if(nm){
|
||||
strncpy(wheel->name, nm, 9);
|
||||
if(verblevl) printf(", name '%s'", wheel->name);
|
||||
if(verblevl == LIST_PRES) printf(", name '%s'", wheel->name);
|
||||
DBG("Wheel name: %s", wheel->name);
|
||||
}
|
||||
if(wheel->serial && verblevl){
|
||||
printf(", serial '%s'", wheel->serial);
|
||||
if(wheel->serial && verblevl != LIST_NONE){
|
||||
if(verblevl == LIST_PRES) printf(", serial ");
|
||||
printf("'%s' ", wheel->serial);
|
||||
}
|
||||
if(verblevl) printf(", %d filters:\n", wheel->maxpos);
|
||||
else return;
|
||||
int i, m = wheel->maxpos + 1;
|
||||
// now get filter names
|
||||
for(i = 1; i < m; ++i){
|
||||
nm = get_filter_name(wheel, i);
|
||||
printf("\t%d", i);
|
||||
if(nm) printf(": '%s'", nm);
|
||||
printf("\n");
|
||||
}
|
||||
if(verblevl){
|
||||
printf("current position: %d\n", poll_regstatus(wheel->fd, 0));
|
||||
if(verblevl == LIST_NONE) return;
|
||||
if(verblevl == LIST_PRES){
|
||||
printf(", %d filters:\n", wheel->maxpos);
|
||||
int i, m = wheel->maxpos + 1;
|
||||
// now get filter names
|
||||
for(i = 1; i < m; ++i){
|
||||
nm = get_filter_name(wheel, i);
|
||||
printf("\t%d", i);
|
||||
if(nm) printf(": '%s'", nm);
|
||||
printf("\n");
|
||||
}
|
||||
printf("current position: ");
|
||||
}
|
||||
printf("%d\n", poll_regstatus(wheel->fd, 0));
|
||||
}
|
||||
if(verblevl != LIST_ALL) return;
|
||||
// now list all things stored in memory of turret driver
|
||||
|
||||
Reference in New Issue
Block a user