add edmund HSFW management

This commit is contained in:
eddyem
2016-05-13 20:51:13 +03:00
parent c6cc40baec
commit 1360054a53
25 changed files with 4350 additions and 12 deletions

135
HSFW_management/cmdlnopts.c Normal file
View File

@@ -0,0 +1,135 @@
/*
* cmdlnopts.c - the only function that parse cmdln args and returns glob parameters
*
* 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 <assert.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <math.h>
#include "cmdlnopts.h"
#include "usefull_macros.h"
#define RAD 57.2957795130823
#define D2R(x) ((x) / RAD)
#define R2D(x) ((x) * RAD)
/*
* here are global parameters initialisation
*/
int help;
glob_pars G;
int listNms = 0 // list names
,gohome = 0 // first go home
,reName = 0 // rename wheels/positions
;
// DEFAULTS
// default global parameters
glob_pars const Gdefault = {
NULL // wheelID
,NULL // wheelName
,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
*/
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")},
/// "ÎÏÍÅÒ ÐÏÚÉÃÉÉ ÆÉÌØÔÒÁ"
{"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")},
end_option
};
/**
* Safely convert data from string to double
*
* @param num (o) - double number read from string
* @param str (i) - input string
* @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;
}
/**
* Parse command line options and return dynamically allocated structure
* 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
listNms = LIST_PRES;
/// "îÅ ÐÅÒÅÄÁÎÏ ÎÉËÁËÉÈ ÁÒÇÕÍÅÎÔÏ×, ×Ù×ÏÖÕ ÓÐÉÓÏË ÐÏÄËÌÀÞÅÎÎÙÈ ÕÓÔÒÏÊÓÔ×!"
WARNX(_("No arguments given, list all devices connected!"));
return &G;
}
return &G;
}