/* this is really crappy */ int sscanf( const char *buffer, const char *fmt, ... ) { int cmd; int **arg; int count; arg = (int **)&fmt + 1; count = 0; while ( *fmt ) { if ( fmt[0] != '%' ) { fmt++; continue; } cmd = fmt[1]; fmt += 2; switch ( cmd ) { case 'i': case 'd': case 'u': **arg = _atoi( &buffer ); break; case 'f': *(gfixed *)*arg = _atof( &buffer ); break; } arg++; } return count; }
static void cliSet(char *cmdline) { int i; int len; const clivalue_t *val; char *eqptr = NULL; int value = 0; float valuef = 0; len = strlen(cmdline); if (len == 0 || (len == 1 && cmdline[0] == '*')) { cliPrint("Current settings: \r\n"); for (i = 0; i < VALUE_COUNT; i++) { val = &valueTable[i]; printf("%s = ", valueTable[i].name); cliPrintVar(val, len); // when len is 1 (when * is passed as argument), it will print min/max values as well, for gui cliPrint("\r\n"); } } else if ((eqptr = strstr(cmdline, "=")) != NULL) { // has equal, set var eqptr++; len--; value = atoi(eqptr); valuef = _atof(eqptr); for (i = 0; i < VALUE_COUNT; i++) { val = &valueTable[i]; if (strncasecmp(cmdline, valueTable[i].name, strlen(valueTable[i].name)) == 0) { if (valuef >= valueTable[i].min && valuef <= valueTable[i].max) { // here we compare the float value since... it should work, RIGHT? int_float_value_t tmp; if (valueTable[i].type == VAR_FLOAT) tmp.float_value = valuef; else tmp.int_value = value; cliSetVar(val, tmp); printf("%s set to ", valueTable[i].name); cliPrintVar(val, 0); } else { cliPrint("ERR: Value assignment out of range\r\n"); } return; } } cliPrint("ERR: Unknown variable name\r\n"); } else { // no equals, check for matching variables. for (i = 0; i < VALUE_COUNT; i++) { if (strstr(valueTable[i].name, cmdline)) { val = &valueTable[i]; printf("%s = ", valueTable[i].name); cliPrintVar(val, 0); printf("\r\n"); } } } }
void cliSet(char *cmdline) { uint32_t i; uint32_t len; const clivalue_t *val; char *eqptr = NULL; int32_t value = 0; float valuef = 0; len = strlen(cmdline); if (len == 3 && cmdline[0] == '*') { // printf("Current settings: \r\n"); for (i = 0; i < VALUE_COUNT; i++) { val = &valueTable[i]; printf("%s=", valueTable[i].name); // cliPrintVar(val, len); // when len is 1 (when * is passed as argument), it will print min/max values as well, for gui cliPrintVar(val, 0); printf("\r"); } // f.IMU_GRAPH_OUT=1; } else if (strstr(cmdline, "=")) { void (*Func) (void); eqptr = strstr(cmdline, "="); // has equal, set var eqptr++; len--; value= atoi(eqptr); valuef = _atof(eqptr); for (i = 0; i < VALUE_COUNT; i++) { val = &valueTable[i]; if (strncasecmp(cmdline, valueTable[i].name, strlen(valueTable[i].name)) == 0) { if (valuef >= valueTable[i].min && valuef <= valueTable[i].max) { // here we compare the float value since... it should work, RIGHT? cliSetVar(val, valueTable[i].type == VAR_FLOAT ? *(uint32_t *)&valuef : value); // this is a silly dirty hack. please fix me later. if(valueTable[i].function!=NULL) { Func = valueTable[i].function; //관련된 함수 호출 Func(); } printf("%s=", valueTable[i].name); // printf("%d ", value); cliPrintVar(val, 0); printf("\r"); // printf(" %d",cfg.gyroPitchKi); } else { printf("ERR: Value assignment out of range\r\n"); } return; } } printf("ERR: Unknown variable name\r\n"); } }
static void cliCMix(char *cmdline) { int i, check = 0; int num_motors = 0; uint8_t len; char buf[16]; float mixsum[3]; char *ptr; len = strlen(cmdline); if (len == 0) { cliPrint("Custom mixer: \r\nMotor\tThr\tRoll\tPitch\tYaw\r\n"); for (i = 0; i < MAX_MOTORS; i++) { if (mcfg.customMixer[i].throttle == 0.0f) break; num_motors++; printf("#%d:\t", i + 1); printf("%s\t", ftoa(mcfg.customMixer[i].throttle, buf)); printf("%s\t", ftoa(mcfg.customMixer[i].roll, buf)); printf("%s\t", ftoa(mcfg.customMixer[i].pitch, buf)); printf("%s\r\n", ftoa(mcfg.customMixer[i].yaw, buf)); } mixsum[0] = mixsum[1] = mixsum[2] = 0.0f; for (i = 0; i < num_motors; i++) { mixsum[0] += mcfg.customMixer[i].roll; mixsum[1] += mcfg.customMixer[i].pitch; mixsum[2] += mcfg.customMixer[i].yaw; } cliPrint("Sanity check:\t"); for (i = 0; i < 3; i++) cliPrint(fabsf(mixsum[i]) > 0.01f ? "NG\t" : "OK\t"); cliPrint("\r\n"); return; } else if (strncasecmp(cmdline, "reset", 5) == 0) { // erase custom mixer for (i = 0; i < MAX_MOTORS; i++) mcfg.customMixer[i].throttle = 0.0f; } else if (strncasecmp(cmdline, "load", 4) == 0) { ptr = strchr(cmdline, ' '); if (ptr) { len = strlen(++ptr); for (i = 0; ; i++) { if (mixerNames[i] == NULL) { cliPrint("Invalid mixer type...\r\n"); break; } if (strncasecmp(ptr, mixerNames[i], len) == 0) { mixerLoadMix(i); printf("Loaded %s mix...\r\n", mixerNames[i]); cliCMix(""); break; } } } } else { ptr = cmdline; i = atoi(ptr); // get motor number if (--i < MAX_MOTORS) { ptr = strchr(ptr, ' '); if (ptr) { mcfg.customMixer[i].throttle = _atof(++ptr); check++; } ptr = strchr(ptr, ' '); if (ptr) { mcfg.customMixer[i].roll = _atof(++ptr); check++; } ptr = strchr(ptr, ' '); if (ptr) { mcfg.customMixer[i].pitch = _atof(++ptr); check++; } ptr = strchr(ptr, ' '); if (ptr) { mcfg.customMixer[i].yaw = _atof(++ptr); check++; } if (check != 4) { cliPrint("Wrong number of arguments, needs idx thr roll pitch yaw\r\n"); } else { cliCMix(""); } } else { printf("Motor number must be between 1 and %d\r\n", MAX_MOTORS); } } }
int settings_set_variable(const char* key, const char* val, settings_t* sttngs) { char* _key = str_strip(key); upper_case(_key); char* _val = str_strip(val); int rv = 0; if (strcmp(_key, "START_OBSERVATION")==0) { sttngs->start += _atotime(_val, &rv); if (rv==-1) rv=0; } else if (strcmp(_key, "END_OBSERVATION")==0) { sttngs->stop += _atotime(_val, &rv); if (rv==-1) rv=0; } else if (strcmp(_key, "MAG")==0) { sttngs->mag_min = _atof(_val, &rv); } else if (strcmp(_key, "UM")==0) { sttngs->um_min = _atof(_val, &rv); } else if (strcmp(_key, "RA_RATE_MIN")==0) { sttngs->ra_rate_min = _atof(_val, &rv); } else if (strcmp(_key, "RA_RATE_MAX")==0) { sttngs->ra_rate_max = _atof(_val, &rv); } else if (strcmp(_key, "DECL_RATE_MIN")==0) { sttngs->decl_rate_min = _atof(_val, &rv); } else if (strcmp(_key, "DECL_RATE_MAX")==0) { sttngs->decl_rate_max = _atof(_val, &rv); } else if (strcmp(_key, "DAY")==0) { sttngs->start += _atodate(_val, &rv); sttngs->stop += _atodate(_val, &rv); } else if (strcmp(_key, "EFEM_DIR")==0) { sttngs->dir = strdup(_val); } else if (strcmp(_key, "BLACK_LIST")==0) { int i=0; char* str = _val; char* tmp; int len = strlen(_val); int flag=1; while (++i<len) { if (_val[i]==' ' || _val[i]=='\t' || _val[i]=='\n') { if (flag) { _val[i]='\0'; tmp = str_strip(str); if (strlen(tmp)) { vec_add((void **)&sttngs->black_list, (void *)&tmp); str = &(_val[i])+1; flag=0; } else { free(tmp); } } } else { flag=1; } } tmp = str_strip(str); if (strlen(tmp)) { vec_add((void **)&sttngs->black_list, (void *)&tmp); } else { free(tmp); } } else if (strcmp(_key, "RA_POSITION_MIN")==0) { sttngs->ra_position_min = _ra(_val, &rv); } else if (strcmp(_key, "RA_POSITION_MAX")==0) { sttngs->ra_position_max = _ra(_val, &rv); } else if (strcmp(_key, "REPORT_TYPE")==0) { if (strcmp(_val, "HTML")==0) { sttngs->report_type = report_type_html; } } else if (strcmp(_key, "REPORT_HTML_FONT_SIZE")==0) { sttngs->report_html_font_size = strdup(_val); } else if (strcmp(_key, "USE_ORB_FILE")==0) { sttngs->use_orb_file = (strcmp(_val, "NO")!=0); } else if (strcmp(_key, "ORB_FILE")==0) { sttngs->orb_file = strdup(_val); } sfree(_val); sfree(_key); return rv; }
static bool ParseParameters(int argc, char **argv) { static struct option long_options[] = { {"output", required_argument, NULL, 'o'}, {"distortion", no_argument, NULL, 'd'}, {"geometry", optional_argument, NULL, 'g'}, {"tca", no_argument, NULL, 't'}, {"vignetting", no_argument, NULL, 'v'}, {"all", no_argument, NULL, 'a'}, {"inverse", no_argument, NULL, 'i'}, {"scale", required_argument, NULL, 'S'}, {"lens", required_argument, NULL, 'L'}, {"camera", required_argument, NULL, 'C'}, {"crop", required_argument, NULL, 'c'}, {"focal", required_argument, NULL, 'F'}, {"aperture", required_argument, NULL, 'A'}, {"distance", required_argument, NULL, 'D'}, {"interpol", required_argument, NULL, 'I'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 4}, {"verbose", no_argument, NULL, 5}, {0, 0, 0, 0} }; opts.Program = argv [0]; int c; while ((c = getopt_long (argc, argv, "o:dg::tvaiS:L:C:c:F:A:D:I:h", long_options, NULL)) != EOF) { switch (c) { case 'o': opts.Output = optarg; break; case 'd': opts.ModifyFlags |= LF_MODIFY_DISTORTION; break; case 'g': opts.ModifyFlags |= LF_MODIFY_GEOMETRY; if (optarg) { if (!strcasecmp (optarg, "rectilinear")) opts.TargetGeom = LF_RECTILINEAR; else if (!strcasecmp (optarg, "fisheye")) opts.TargetGeom = LF_FISHEYE; else if (!strcasecmp (optarg, "panoramic")) opts.TargetGeom = LF_PANORAMIC; else if (!strcasecmp (optarg, "equirectangular")) opts.TargetGeom = LF_EQUIRECTANGULAR; else if (!strcasecmp (optarg, "orthographic")) opts.TargetGeom = LF_FISHEYE_ORTHOGRAPHIC; else if (!strcasecmp (optarg, "stereographic")) opts.TargetGeom = LF_FISHEYE_STEREOGRAPHIC; else if (!strcasecmp (optarg, "equisolid")) opts.TargetGeom = LF_FISHEYE_EQUISOLID; else if (!strcasecmp (optarg, "thoby")) opts.TargetGeom = LF_FISHEYE_THOBY; else { DisplayUsage(); g_print ("\nTarget lens geometry must be one of 'rectilinear', 'fisheye', 'panoramic', 'equirectangular'\n'orthographic', 'stereographic', 'equisolid', 'thoby'\n"); return false; } } break; case 't': opts.ModifyFlags |= LF_MODIFY_TCA; break; case 'v': opts.ModifyFlags |= LF_MODIFY_VIGNETTING; break; case 'a': opts.ModifyFlags |= LF_MODIFY_VIGNETTING; opts.ModifyFlags |= LF_MODIFY_TCA; opts.ModifyFlags |= LF_MODIFY_DISTORTION; break; case 'i': opts.Inverse = true; break; case 'S': opts.ModifyFlags |= LF_MODIFY_SCALE; opts.Scale = _atof (optarg); break; case'L': opts.Lens = optarg; break; case'C': opts.Camera = optarg; break; case 'c': opts.Crop = _atof (optarg); break; case 'F': opts.Focal = _atof (optarg); break; case 'A': opts.Aperture = _atof (optarg); break; case 'D': opts.Distance = _atof (optarg); break; case 'I': if (smartstreq (optarg, "nearest")) opts.Interpolation = Image::I_NEAREST; else if (smartstreq (optarg, "bilinear")) opts.Interpolation = Image::I_BILINEAR; else if (smartstreq (optarg, "lanczos")) opts.Interpolation = Image::I_LANCZOS; else { DisplayUsage(); g_print ("\nUnknown interpolation method `%s'\n", optarg); return false; } break; case 'h': DisplayUsage (); return false; case 4: DisplayVersion (); return false; case 5: opts.Verbose = true; break; default: return false; } } if (optind <= argc) opts.Input = argv [optind]; if (!opts.Lens && !opts.Camera) { DisplayUsage(); g_print ("\nAt least a lens or camera name is required to perform a database lookup!\n"); return false; } if (!opts.Lens && opts.Input) { DisplayUsage(); g_print ("\nNo lens information (-L) supplied to process specified input image!\n"); return false; } return true; }