/* -*- c-file-style: "Ellemtel" -*- `cli_comlist.c' - cli_init, cli_help, cli_search, cli_execute This file is part of version 3 of the DIRECTOR cli client library. Read the `License' file for terms of use and distribution. Copyright 2001, Canada-France-Hawaii Telescope, daprog@cfht.hawaii.edu. ___This header automatically generated from `Index'. Do not edit it here!___ */ #include #include #include #include /* All of the commands' handlers that are out there, somewhere... * - these should probably be declared somewhere else. */ extern Function adc_app; extern Function bootp_app; extern Function clean_app; extern Function dev; extern Function clk; extern Function dac_app; extern Function dimm_info; extern Function dhack; extern Function do_daqserv; extern Function do_watchdog; extern Function do_dcache; extern Function do_mem_md; extern Function do_mem_mm; extern Function do_nvm; extern Function do_icache; extern Function pixbench; extern Function phy; extern Function ifconfig_app; extern Function arp_app; extern Function showfits_app; extern Function settrig_app; extern Function readout_app; extern Function readcal_app; extern Function otacal_app; extern Function fakeread; extern Function ce; extern Function clv; extern Function clvset_app; extern Function do_reset; extern Function do_run; extern Function selftest; extern Function temp; extern Function do_version; extern Function wrmem; extern Function mtest; extern Function mread; extern Function mwrite; extern Function ota_info_app; extern Function etime_app; extern Function etype_app; extern Function shutter_app; extern Function expose_app; extern Function serial_num_app; extern Function testdata_app; extern Function cell_designate_app; extern Function cell_select_app; extern Function overscan_app; extern Function prescan_app; extern Function detsize_app; extern Function adcflip_app; extern Function adczero_app; extern Function time_app; extern Function time_operations_app; #ifdef HAVE_OTAVIDEO extern Function pixtype_app; extern Function ot_app; #endif extern Function led_app; extern Function console_app; #ifdef HAVE_UPIRANI extern Function upirani_app; #endif extern Function dev_temp_override_app; extern Function dev_temp_corr_app; extern Function i2c_app; extern Function boardset_app; extern Function daq3u_boardtest_app; #if defined(HAVE_INTR_INTERRUPTS) extern Function intr_test_app; #endif /* Added for SGIR */ extern Function showme; extern Function acqmode_app; extern Function cbmode_app; extern Function coadd_app; extern Function darray_app; extern Function irinit_app; extern Function irdevice_app; extern Function itime_msec_app; extern Function ndr_app; extern Function num_darray_app; extern Function rsample_app; extern Function al_bgr_app; extern Function al_glr_app; extern Function al_slowcnt_app; extern Function go_app; extern Function show_app; extern Function t1_app; extern Function t2_app; extern Function t3_app; extern Function t4_app; extern Function t5_app; static Command cmd_table[] = { /*Command name */ /* Handler function */ /* Help */ {"*-[ Network ]-*", 0, 0}, #ifdef HAVE_NET {"bootp", bootp_app, "Configure IP network using BootP protocol"}, #ifdef HAVE_DAQSERV {"daqserv", do_daqserv, "Start|stop accepting network commands"}, #endif #endif #ifdef HAVE_BUILTIN_PHY {"phy", phy, "PHY control"}, #endif #ifdef HAVE_BUILTIN_IFCONFIG {"ifconfig", ifconfig_app, "Ethernet interface statistics"}, {"arp", arp_app, "Display Ethernet ARP table"}, #endif {"*-[ Processor ]-*", 0, 0}, #ifdef HAVE_WATCHDOG {"watchdog", do_watchdog, "Enable the watchdog timer"}, #endif {"dcache", do_dcache, "Enable or disable data cache"}, {"icache", do_icache, "Enable or disable instruction cache"}, {"reset", do_reset, "Perform RESET of the CPU"}, {"run", do_run, "Start application at address load_addr"}, {"*-[ Memory ]-*", 0, 0}, #ifdef HAVE_BUILTIN_MDMM {"md", do_mem_md, "Memory display"}, {"mm", do_mem_mm, "Memory modify (auto-incrementing)"}, #endif #if (defined(HAVE_DIMM_SPD) && (!defined(UBOOT_STAGE) || (UBOOT_STAGE != 1))) {"dimm", dimm_info, "Get information about installed DIMM"}, #endif #ifdef HAVE_BUILTIN_MEMTEST {"mtest", mtest, "Test memory"}, #endif #ifdef HAVE_BUILTIN_MEMRW {"mread", mread, "Read memory"}, {"mwrite", mwrite, "Write memory"}, #endif {"*-[ Analog ]-*", 0, 0}, #ifdef HAVE_BUILTIN_DEV {"dev", dev, "Select detector device 0 or 1"}, #endif #ifdef HAVE_BUILTIN_ADC {"adc", adc_app, "Set ADC operating modes"}, #endif #ifdef HAVE_BUILTIN_CLK {"clk", clk, "Get or set digital output bits"}, #endif #ifdef HAVE_BUILTIN_DAC {"dac", dac_app, "Get or set DAC channel"}, #endif #ifdef HAVE_BUILTIN_CLEAN {"clean", clean_app, "Clean the CCD of charge"}, #endif #ifdef HAVE_BUILTIN_EXPOSE {"etime", etime_app, "Set the next shutter exposure time"}, {"shutter open|close", shutter_app, "Manually open or close the shutter"}, {"etype", etype_app, "Set the next exposure type (o/b/d)"}, {"expose", expose_app, "Take a timed exposure"}, #endif #ifdef HAVE_BUILTIN_READOUT {"celldes", cell_designate_app, "Designate cell usage (Science, video, etc.)"}, {"cellsel", cell_select_app, "Set designated cells to select, standby or float"}, #ifdef HAVE_OTAVIDEO {"pixtype", pixtype_app, "Set OTA pixel type I or II (or 0 for CCD)"}, {"ot", ot_app, "Do an OT correction shift" }, #endif {"detsize", detsize_app, "Set (size per amp)"}, {"adcflip on|off", adcflip_app, "Turn on/off flipping of ADC7-ADC0" }, {"adczero 0-7", adczero_app, "Number of the first ADC that is wired" }, {"prescan ", prescan_app, "Set the number of prescan pixels" }, {"overscan ", overscan_app, "Set the number of overscan pixels" }, #ifdef HAVE_FITSHEAD {"showfits", showfits_app, "Show current FITS keywords provided by uboot" }, #endif {"settrig", settrig_app, "Set cross-trigger for synchronizing readouts"}, {"readout", readout_app, "Read pixels into memory buffer"}, #ifdef HAVE_BUILTIN_TESTDATA {"testdata", testdata_app, "Enable/disabled hardware test data"}, #endif #endif #ifdef HAVE_BUILTIN_READCAL {"readcal", readcal_app, "Calibrate readout parameters (measure noise)"}, {"otacal", otacal_app, "Calibrate pedestal offsets by cell (OTA only)"}, #endif #ifdef HAVE_BUILTIN_FAKEREAD {"fakeread", fakeread, "Read FAKE pixels into memory buffer"}, #endif #ifdef HAVE_BUILTIN_CE {"ce", ce, "Test the clocking engine"}, #endif #ifdef HAVE_BUILTIN_CLV {"clv", clv, "(Set parameter(s) from cestlavie)"}, {"clvset", clvset_app, "Set parameter(s) from cestlavie"}, #endif #ifdef HAVE_BUILTIN_WRMEM {"wrmem", wrmem, "Set HDL option bits"}, #endif {"*-[ Misc ]-*", 0, 0}, {"version", do_version, "Print monitor version"}, #ifdef HAVE_BUILTIN_SELFTEST {"selftest", selftest, "Run self-tests"}, #endif #ifdef HAVE_BUILTIN_PIXBENCH {"pixbench", pixbench, "Run some GPC benchmarks"}, #endif #ifdef HAVE_OTA_INFO {"dev_temp_override", dev_temp_override_app, "Overrides device temperature checking for short period"}, {"dev_temp_corr", dev_temp_corr_app, "Set device temperature correction factor"}, #endif #if (defined(HAVE_I2C_EEPROM) && (!defined(UBOOT_STAGE) || (UBOOT_STAGE != 1))) {"nvm", do_nvm, "Read/write NVM."}, #endif #ifdef HAVE_OTA_INFO {"ota_info", ota_info_app, "Read OTA package IDs and temps"}, #endif #ifdef HAVE_LM86 {"temp", temp, "Read FPGA and board temperatures"}, #endif #ifdef HAVE_SET_TIME {"time", time_app, "Read/set system timer"}, {"timeops", time_operations_app, "Time various operations"}, #endif #if (defined(HAVE_GRASP_LED) && defined(UBOOT_STAGE) && (UBOOT_STAGE != 1)) {"leds", led_app, "Allows/disallows board LEDs to be lit"}, #endif {"i2c", i2c_app, "Shows which known devices were found on the I2C bus"}, #ifdef HAVE_DAQ3U_BOARDTEST_APP {"daq3u_boardtest", daq3u_boardtest_app, "App for testing DAQ3u"}, #endif #ifdef HAVE_BOARDSET_APP {"boardset", boardset_app, "Displays information programmed into all boards in Stargrasp boardset"}, #endif #ifdef HAVE_SERIAL_NUM_APP {"serial_num", serial_num_app, "Test app to read/write serial numbers"}, #endif {"console", console_app, "Turn on/off serial console feedback"}, #ifdef HAVE_UPIRANI {"upirani", upirani_app, "Micropirani test command"}, #endif #if defined(HAVE_INTR_INTERRUPTS) {"intr_test", intr_test_app, "Intr interrupts test command"}, #endif {"help", cli_help, "Displays help information"}, {"?", cli_help, "Displays help information"}, /************************************* SGIR start *********************************/ /* ---------- SGIR controller commands - ir options -------------*/ { "acqmode", acqmode_app, " acqumode { basic | movie } ."}, { "cbmode", cbmode_app, " cbmode: { fs | fd | ramp } "}, { "coadd", coadd_app, " coadd - set the number of coadds."}, { "darray", darray_app, " darray I X Y W H - dimension of darray[i]."}, { "irinit", irinit_app, " irinit { al | h2 } - initialize stuff."}, { "irdevice", irdevice_app, " irdevice { al | h2 } - ID's The IR array."}, { "itime_msec", itime_msec_app, " itime_msec msec - set itime in msec."}, { "ndr", ndr_app, " ndr N - set non destructive read."}, { "numdarray", num_darray_app, " numdarray N - number of data arrays for readout."}, { "rsample", rsample_app, " rsample N - up-the-ramp samples."}, /* ---------- SGIR controller commands - aladdin options -------*/ { "al.bgr", al_bgr_app, " al.bgr - sets Background Reset parameters."}, { "al.glr", al_glr_app, " al.glr - sets Global Reset parameters."}, { "al.slowcnt", al_slowcnt_app, " al.slowcnt N - way of slowing down the waveform."}, /* ---------- SGIR controller commands - h2rg options ----------*/ /* ---------- SGIR controller commands - GO -------------------*/ { "go", go_app, " go - acquire images."}, { "show", show_app, " show - show HOST & GLOBAL DATA."}, /* ---------- SGIR controller - test commands -------------------*/ { "t1", t1_app, " t1 - test command 1."}, { "t2", t2_app, " t2 - test command 2."}, { "t3", t3_app, " t3 - test command 3."}, { "t4", t4_app, " t4 - test command 4."}, { "t5", t5_app, " t5 - test command 5."}, /************************************* SGIR end *********************************/ COMMAND_TABLE_END /* Add new commands above this line. */ }; static Command* comlist_ = cmd_table; #ifndef SIGWINCH #define SIGWINCH (0) #endif /* Look up NAME as the name of a command, and return a pointer to that command. Return a NULL pointer if NAME isn't a command name. */ static Command* find_command(const char* name, int namelen) { int i; if (comlist_==NULL) return ((Command*)NULL); for (i = 0; comlist_[i].name; i++) { int len; char* space = strchr(comlist_[i].name, ' '); if (space) len = space - comlist_[i].name; else len = strlen(comlist_[i].name); if (namelen==len && strncmp(name, comlist_[i].name, len) == 0) return &(comlist_[i]); } return ((Command*)NULL); } Command* cli_search(const char* line, Command* comlist) { Command* com; const char* name = line; int namelen = 0; if (line==NULL) return NULL; comlist_ = comlist; /* save comlist_ for the other routines */ /* Isolate the command word. */ while (*name && isspace((int)(*name))) name++; while (name[namelen] && !isspace((int)(name[namelen]))) namelen++; com = find_command(name, namelen); return com; } /**************************************************************************** * returns: * 1 - command executed, repeatable * 0 - command executed but not repeatable, interrupted commands are * always considered not repeatable * -1 - not executed (unrecognized, bootd recursion or too many args) * (If cmd is NULL or "" or longer than CFG_CBSIZE-1 it is * considered unrecognized) */ int cli_execute(const char* linearg) { Command *com; int status; int argc; char ** argv; com = cli_search(linearg, comlist_); if (com==NULL) { if (linearg && *linearg) { printf("error: Invalid command: `%s'; try `help'\n", linearg); } return FAIL; } if (!(com->func)) { printf("error: No function assigned to command.\n"); return FAIL; } /* Get the set of arguments to the command. */ argv = cli_argv(&argc, linearg); /* Call the handler for the command. */ status = (*(com->func)) (argc, (const char**)argv); /* Free up the space allocated for the individual arguments. */ cli_argv_free(argv); return status; } PASSFAIL cli_help(int argc, const char * argv[]) { int i; int longest = 14; if (comlist_==NULL) { printf("\nNo commands.\n"); return FAIL; } for (i = 0; comlist_[i].name; i++) { if (comlist_[i].help) printf("%s%*s: %s\n", comlist_[i].name, (int)(longest - strlen(comlist_[i].name)), "", comlist_[i].help); else if (!comlist_[i].func) printf("%s\n", comlist_[i].name); } return PASS; } /* End of cli_comlist.c */