/** * \brief execute a subcommand */ void guiderportcommand::operator()(const std::string& /* commandname */, const std::vector<std::string>& arguments) { debug(LOG_DEBUG, DEBUG_LOG, 0, "guiderport command"); if (arguments.size() < 2) { throw command_error("guiderport command requires 2 arguments"); } std::string guiderportid = arguments[0]; std::string subcommandname = arguments[1]; if (subcommandname == "activate") { activate(guiderportid, arguments); return; } if (subcommandname == "release") { release(guiderportid, arguments); return; } if (subcommandname == "assign") { assign(guiderportid, arguments); return; } throw command_error("guiderport subcommand not known"); }
void filterwheelcommand::operator()(const std::string& /* commandname */, const std::vector<std::string>& arguments) { if (arguments.size() < 2) { throw command_error("filterwheel command requires 2 arguments"); } std::string filterwheelid = arguments[0]; std::string subcommandname = arguments[1]; debug(LOG_DEBUG, DEBUG_LOG, 0, "filterwheel command for FW %s, subcommand %s", filterwheelid.c_str(), subcommandname.c_str()); if (subcommandname == "release") { release(filterwheelid, arguments); return; } if (subcommandname == "assign") { assign(filterwheelid, arguments); return; } Filterwheels filterwheels; FilterwheelWrapper filterwheel = filterwheels.byname(filterwheelid); if (subcommandname == "info") { info(filterwheel, arguments); return; } if (subcommandname == "position") { position(filterwheel, arguments); return; } if (subcommandname == "wait") { wait(filterwheel, arguments); return; } throw command_error("unknown command"); }
/** * \brief start command * * This command initiates a calibration or guiding process. The command * takes an optional argument for the focallength or the gain */ void guidercommand::start(GuiderWrapper& guider, const std::vector<std::string>& arguments) { if (arguments.size() < 3) { throw command_error("start command requires 2 arguments"); } std::string what = arguments[2]; if (what == "calibration") { float focallength = 0.600; if (arguments.size() >= 4) { focallength = stod(arguments[3]); debug(LOG_DEBUG, DEBUG_LOG, 0, "using focal length %f", focallength); } guider->startCalibration(focallength); return; } if (what == "guiding") { if (guider->getState() == Astro::Guider::GUIDER_GUIDING) { std::cout << "already guiding, ignored" << std::endl; return; } double interval = 10; if (arguments.size() >= 4) { interval = stod(arguments[3]); } interval = std::max(1., interval); guider->startGuiding(interval); return; } }
/** * \brief calibration command * * This command can be used to force a calibration, without actually going * through the calibration process on the server side. This allows to * reuse calibration settings when the next guide process is based on a * guide star close to the one previously used. */ void guidercommand::calibration(GuiderWrapper& guider, const std::vector<std::string>& arguments) { if (arguments.size() < 3) { throw command_error("calibration command requires an argument"); } long cal = stod(arguments[2]); guider->useCalibration(cal); }
/** * \brief Set exposure time command * * This command allows to change the exposure time */ void guidercommand::exposuretime(GuiderWrapper& guider, const std::vector<std::string>& arguments) { if (arguments.size() < 3) { throw command_error("exposure time missing"); } Astro::Exposure exposure = guider->getExposure(); exposure.exposuretime = stof(arguments[2]); guider->setExposure(exposure); }
void sleepcommand::operator()(const std::string& /* commandname */, const std::vector<std::string>& arguments) { if (arguments.size() < 1) { throw command_error("sleep command requires time argument"); } std::string timestring = arguments[0]; useconds_t sleeptime = 1000000 * stof(timestring); usleep(sleeptime); }
void filterwheelcommand::assign(const std::string& filterwheelid, const std::vector<std::string>& arguments) { debug(LOG_DEBUG, DEBUG_LOG, 0, "assign %s", filterwheelid.c_str()); try { Filterwheels filterwheels; filterwheels.assign(filterwheelid, arguments); } catch (std::exception& x) { throw command_error(x.what()); } }
/** * \brief star command * * This command sets the star point. The star point is used as a reference * during calibration, the calibration computes offsets from this point. * The guiding process then guides the telescope in such a way that the * guide star is at this position as precisely as possible. */ void guidercommand::star(GuiderWrapper& guider, const std::vector<std::string>& arguments) { if (arguments.size() < 4) { throw command_error("star coordinates missing"); } Astro::Point point; point.x = stoi(arguments[2]); point.y = stoi(arguments[3]); guider->setStar(point); }
/** * \brief size command * * This command sets the size of the rectangle to track the guide star */ void guidercommand::size(GuiderWrapper& guider, const std::vector<std::string>& arguments) { if (arguments.size() < 4) { throw command_error("viewport window missing"); } Astro::Exposure exposure = guider->getExposure(); exposure.frame.size.width = stoi(arguments[2]); exposure.frame.size.height = stoi(arguments[3]); guider->setExposure(exposure); }
/** * \brief Binning command * * This command allows to change the binning mode of the guiding exposure. * This is only reasonable if the guide camera has rather small pixels. */ void guidercommand::binning(GuiderWrapper& guider, const std::vector<std::string>& arguments) { if (arguments.size() < 4) { throw command_error("binning mode missing"); } Astro::Exposure exposure = guider->getExposure(); exposure.mode.x = stoi(arguments[2]); exposure.mode.y = stoi(arguments[3]); guider->setExposure(exposure); }
command_fn find_command_fn (const string& cmd) { // Note: value_type is pair<const key_type, mapped_type> // So: iterator->first is key_type (string) // So: iterator->second is mapped_type (command_fn) const auto result = cmd_hash.find (cmd); if (result == cmd_hash.end()) { throw command_error (cmd + ": no such function"); } return result->second; }
void on_message(connection_ptr connection,websocketpp::message::data_ptr msg) { typename std::set<connection_ptr>::iterator it; wscmd::cmd command = wscmd::parse(msg->get_payload()); if (command.command == "close") { handle_close(connection,command); } else { command_error(connection,"Invalid Command"); } }
void fn_cat (inode_state& state, const wordvec& words){ DEBUGF ('c', state); DEBUGF ('c', words); string filename = *(words.end()-1); inode_ptr ogcwd = state.getCwd(); inode_ptr res = resolvePath(words[1], state.getCwd()); if (res == nullptr){ throw command_error ("cat: " + filename + ": file does not exist"); return; } if (res->isDirectory()) return; //error here cout << res->getContents()->readfile() << endl; }
static void help() { int i; char *tok = strtok(NULL, DELIMS); if (tok != NULL) { Command *c = find_command(tok); if (c != NULL) printf("%s\n", c->help); else command_error(tok); return; } for (i = 0; commands[i].name != NULL; ++i) printf("%s: %s\n", commands[i].name, commands[i].help); }
void guiderfactorycommand::operator()(const std::string& /* command */, const std::vector<std::string>& arguments) { if (arguments.size() < 2) { throw command_error("guiderfactory command requires more " "arguments"); } std::string guiderid = arguments[0]; std::string subcommand = arguments[1]; debug(LOG_DEBUG, DEBUG_LOG, 0, "guiderid: %s", guiderid.c_str()); if (subcommand == "release") { release(guiderid, arguments); return; } if (subcommand == "assign") { assign(guiderid, arguments); return; } }
/** * \brief wait command * * This command waits for the completion of the calibration process on the * server. It does not use the waitCalibration method, because this would * block a thread on the server side. */ void guidercommand::wait(GuiderWrapper& guider, const std::vector<std::string>& arguments) { if (arguments.size() < 3) { throw command_error("stop command requires 2 arguments"); } std::string what = arguments[2]; double timeout = 60; if (arguments.size() >= 4) { timeout = stod(arguments[3]); } double timeouttime = astro::Timer::gettime() + timeout; if (what == "calibration") { while ((guider->getState() == Astro::Guider::GUIDER_CALIBRATING) && (astro::Timer::gettime() < timeouttime)) { usleep(1000000); } switch (guider->getState()) { case Astro::Guider::GUIDER_CALIBRATED: std::cout << "calibration complete" << std::endl; break; default: std::cout << "calibration failed" << std::endl; break; } return; } if (what == "guiding") { while ((guider->getState() == Astro::Guider::GUIDER_GUIDING) && (astro::Timer::gettime() < timeouttime)) { usleep(1000000); } if (guider->getState() == Astro::Guider::GUIDER_GUIDING) { std::cout << "still guiding" << std::endl; } return; } }
/** * \brief stop command * * The stop command can be used to stop a calibraiton or guiding process. */ void guidercommand::stop(GuiderWrapper& guider, const std::vector<std::string>& arguments) { if (arguments.size() < 3) { throw command_error("start command requires 2 arguments"); } std::string what = arguments[2]; if (what == "calibration") { if (guider->getState() != Astro::Guider::GUIDER_CALIBRATING) { std::cout << "not currently calibrating" << std::endl; return; } guider->cancelCalibration(); return; } if (what == "guiding") { if (guider->getState() != Astro::Guider::GUIDER_GUIDING) { std::cout << "not currently guiding" << std::endl; return; } guider->stopGuiding(); return; } }
int _start (int a1, int a2) { char buf[100]; for (;;) { printf ("sendexample> "); lineinput (buf, 100); switch (buf[0]) { case 'h': print_help (buf); break; case 's': sendex (buf); break; case 'q': exitprocess (0); break; default: command_error (); break; } } }
/** * \brief Main command interpreter function * * This operator analyzes the command arguments and calls the appropriate * subcommand method. */ void guidercommand::operator()(const std::string& /* command */, const std::vector<std::string>& arguments) { if (arguments.size() < 2) { throw command_error("guider command requires more " "arguments"); } std::string guiderid = arguments[0]; std::string subcommand = arguments[1]; debug(LOG_DEBUG, DEBUG_LOG, 0, "guiderid: %s", guiderid.c_str()); Guiders guiders; GuiderWrapper guider = guiders.byname(guiderid); if (subcommand == "info") { info(guider, arguments); return; } if (subcommand == "exposure") { exposure(guider, arguments); return; } if (subcommand == "exposuretime") { exposuretime(guider, arguments); return; } if (subcommand == "binning") { binning(guider, arguments); return; } if (subcommand == "size") { size(guider, arguments); return; } if (subcommand == "offset") { offset(guider, arguments); return; } if (subcommand == "star") { star(guider, arguments); return; } if (subcommand == "calibration") { calibration(guider, arguments); return; } if (subcommand == "start") { start(guider, arguments); return; } if (subcommand == "stop") { stop(guider, arguments); return; } if (subcommand == "wait") { wait(guider, arguments); return; } if (subcommand == "image") { image(guider, arguments); return; } }
/* Read and execute commands until EOF is reached. This assumes that the input source has already been initialized. */ int reader_loop () { //printf("reader_loop ------> Start\n"); int our_indirection_level; COMMAND * volatile current_command; USE_VAR(current_command); current_command = (COMMAND *)NULL; our_indirection_level = ++indirection_level; while (EOF_Reached == 0) { //printf("EOF_Reached == 0 =======> Start\n"); int code; code = setjmp_nosigs (top_level); #if defined (PROCESS_SUBSTITUTION) unlink_fifo_list (); #endif /* PROCESS_SUBSTITUTION */ /* XXX - why do we set this every time through the loop? */ if (interactive_shell && signal_is_ignored (SIGINT) == 0) { //printf("if (interactive_shell && signal_is_ignored (SIGINT) == 0)\n"); set_signal_handler (SIGINT, sigint_sighandler); } if (code != NOT_JUMPED) { //printf("if (code != NOT_JUMPED)\n"); indirection_level = our_indirection_level; switch (code) { /* Some kind of throw to top_level has occurred. */ case FORCE_EOF: case ERREXIT: case EXITPROG: //printf("case EXITPROG:\n"); current_command = (COMMAND *)NULL; if (exit_immediately_on_error) { //printf("if (exit_immediately_on_error)\n"); variable_context = 0; /* not in a function */ } EOF_Reached = EOF; goto exec_done; case DISCARD: //printf("case DISCARD:\n"); /* Make sure the exit status is reset to a non-zero value, but leave existing non-zero values (e.g., > 128 on signal) alone. */ if (last_command_exit_value == 0) { //printf("if (last_command_exit_value == 0)\n"); last_command_exit_value = EXECUTION_FAILURE; } if (subshell_environment) { //printf("if (subshell_environment)\n"); current_command = (COMMAND *)NULL; EOF_Reached = EOF; goto exec_done; } /* Obstack free command elements, etc. */ if (current_command) { //printf("if (current_command)\n"); dispose_command (current_command); current_command = (COMMAND *)NULL; } #if defined (HAVE_POSIX_SIGNALS) sigprocmask (SIG_SETMASK, &top_level_mask, (sigset_t *)NULL); #endif break; default: command_error ("reader_loop", CMDERR_BADJUMP, code, 0); } } executing = 0; if (temporary_env) { //printf("if (temporary_env)\n"); dispose_used_env_vars (); } #if (defined (ultrix) && defined (mips)) || defined (C_ALLOCA) /* Attempt to reclaim memory allocated with alloca (). */ (void) alloca (0); #endif if (read_command () == 0) { //printf("read_command () == 0\n"); if (interactive_shell == 0 && read_but_dont_execute) { //printf("if (interactive_shell == 0 && read_but_dont_execute)"); last_command_exit_value = EXECUTION_SUCCESS; dispose_command (global_command); global_command = (COMMAND *)NULL; } else if (current_command = global_command) { //printf("else if (current_command:%d = global_command:%d)\n",current_command, global_command); global_command = (COMMAND *)NULL; current_command_number++; executing = 1; stdin_redir = 0; execute_command (current_command); exec_done: QUIT; if (current_command) { //printf("if (current_command)\n"); dispose_command (current_command); current_command = (COMMAND *)NULL; } } } else { /* Parse error, maybe discard rest of stream if not interactive. */ if (interactive == 0) { //printf("if (interactive == 0)\n"); EOF_Reached = EOF; } } if (just_one_command) { //printf("just_one_command\n"); EOF_Reached = EOF; } //printf("EOF_Reached == 0 =======> Exit\n"); } indirection_level--; //printf("reader_loop ------> Exit\n"); return (last_command_exit_value); }