00001
00008 #include <iostream>
00009
00010
00011 #include "SctApi.h"
00012 #include "SctApiDebug.h"
00013
00014 using namespace SctApi;
00015
00016 Debug *Debug::instance = 0;
00017
00018 void Debug::setDebugOption(std::string opt) {
00019 if(find(debugList.begin(), debugList.end(), opt) == debugList.end()) {
00020
00021 if(find(debugOptionList.begin(), debugOptionList.end(), opt) != debugOptionList.end()) {
00022 debugList.push_back(opt);
00023 } else {
00024 std::cout << "Option: " << opt << " not known\n";
00025 }
00026 }
00027 }
00028
00029 void Debug::unsetDebugOption(std::string opt) {
00030 if(find(debugList.begin(), debugList.end(), opt) != debugList.end()) {
00031 debugList.erase(find(debugList.begin(), debugList.end(), opt));
00032 }
00033 }
00034
00035 std::list<std::string> Debug::listEnabledDebugOptions() {
00036 return debugList;
00037 }
00038
00039 std::vector<std::string> Debug::listDebugOptions() {
00040 return debugOptionList;
00041 }
00042
00043 bool Debug::checkDebugOption(std::string opt) {
00044 if(find(debugList.begin(), debugList.end(), opt) != debugList.end()) {
00045 return true;
00046 } else {
00047 return false;
00048 }
00049 }
00050
00051 bool Debug::checkDebugOption(DebugOptions intOpt) {
00052 std::string opt = debugOptionList[intOpt];
00053
00054 return checkDebugOption(opt);
00055 }
00056
00057 void Debug::setupDebugOptions() {
00058 debugOptionList.resize(DEBUG_END_OPTIONS);
00059
00060 for(int i=0; i<DEBUG_END_OPTIONS; i++) {
00061 std::string name;
00062 switch(i) {
00063 case DEBUG_DIAG:
00064 name = "diag";
00065 break;
00066 case DEBUG_DIAG2:
00067 name = "diag2";
00068 break;
00069 case DEBUG_DUMP_PRIM_BINARY:
00070 name = "dump_prim_binary";
00071 break;
00072 case DEBUG_SAVE_PRIM:
00073 name = "save_prim";
00074 break;
00075 case DEBUG_VERBOSE_PROBE:
00076 name = "verbose_probe";
00077 break;
00078 case DEBUG_PRINT_IN_PRIM:
00079 name = "print_in_prim";
00080 break;
00081 case DEBUG_PRINT_OUT_PRIM:
00082 name = "print_out_prim";
00083 break;
00084 case DEBUG_DIAG_RESPONSE:
00085 name = "diag_response";
00086 break;
00087 case DEBUG_MODULE_CONFIG:
00088 name = "module_config";
00089 break;
00090 case DEBUG_PRINT_CALIB:
00091 name = "print_calib";
00092 break;
00093 case DEBUG_PRINT_RAW:
00094 name = "print_raw";
00095 break;
00096 case DEBUG_LOG_PRINT_PRIM:
00097 name = "log_print_prim";
00098 break;
00099 case DEBUG_EXTRA_DUMPS:
00100 name = "extra_dumps";
00101 break;
00102 case DEBUG_PRINT_UNKNOWN:
00103 name = "print_unknown";
00104 break;
00105 case DEBUG_BOC_SETUP:
00106 name = "boc_setup";
00107 break;
00108 case DEBUG_DUMP_RAW_EVENT:
00109 name = "dump_raw_event";
00110 break;
00111 case DEBUG_SAVE_HISTOGRAM:
00112 name = "save_histogram";
00113 break;
00114 case DEBUG_SAVE_RAW_CAPTURE:
00115 name = "save_raw_capture";
00116 break;
00117 case DEBUG_SCAN_ERROR_TRAP:
00118 name = "scan_error_trap";
00119 break;
00120 case DEBUG_SCAN_ERROR_TRAP_ALL:
00121 name = "scan_error_trap_all";
00122 break;
00123 case DEBUG_SCAN_AUTO_STALL:
00124 name = "scan_auto_stall";
00125 break;
00126 case DEBUG_SCAN_STEP_MODE:
00127 name = "scan_step_mode";
00128 break;
00129 case DEBUG_SCAN_PAUSE_PULSE:
00130 name = "scan_pause_pulse";
00131 break;
00132 case DEBUG_SCAN_ROD_MODE_BITS:
00133 name = "scan_rod_mode_bits";
00134 break;
00135 case DEBUG_SCAN_USE_ASSEMBLER:
00136 name = "scan_use_assembler";
00137 break;
00138 case DEBUG_TIM_SCAN_STATUS:
00139 name = "tim_scan_status";
00140 break;
00141 default:
00142 std::cout << "Unexpected debug option (" << i << ") source code out of sync with itself\n";
00143 throw SctApiException("************ Failed to setup debug options (**************");
00144 }
00145
00146 debugOptionList[i] = name;
00147 }
00148 }
00149
00150 Debug *Debug::getInstance() {
00151 if(!instance) {
00152 instance = new Debug();
00153 }
00154
00155 return instance;
00156 }
00157
00158 Debug::Debug() {
00159 setupDebugOptions();
00160 }
00161