/********************************************************************** * COPYRIGHT 2020 MULTI-TECH SYSTEMS, INC. * * ALL RIGHTS RESERVED BY AND FOR THE EXCLUSIVE BENEFIT OF * MULTI-TECH SYSTEMS, INC. * * MULTI-TECH SYSTEMS, INC. - CONFIDENTIAL AND PROPRIETARY * INFORMATION AND/OR TRADE SECRET. * * NOTICE: ALL CODE, PROGRAM, INFORMATION, SCRIPT, INSTRUCTION, * DATA, AND COMMENT HEREIN IS AND SHALL REMAIN THE CONFIDENTIAL * INFORMATION AND PROPERTY OF MULTI-TECH SYSTEMS, INC. * USE AND DISCLOSURE THEREOF, EXCEPT AS STRICTLY AUTHORIZED IN A * WRITTEN AGREEMENT SIGNED BY MULTI-TECH SYSTEMS, INC. IS PROHIBITED. * ***********************************************************************/ #include "Device.h" #define COMMMAND_EXTRA "--" #define COMMMAND_INIT "init" #define COMMMAND_JSON "json" #define COMMMAND_LOAD_FPGA "load-fpga" #define COMMMAND_SHOW "show" #define COMMMAND_SHOW_TRIGGER "show-trigger" #define COMMMAND_STORE "store" #define COMMMAND_STORE_TRIGGER "store-trigger" #define COMMMAND_VERSION "version" enum action_code { ACTION_NONE, ACTION_VERSION, ACTION_INIT, ACTION_JSON, ACTION_LOAD_FPGA, ACTION_CHECK_FPGA, ACTION_SHOW, ACTION_SHOW_TRIGGER, ACTION_STORE, ACTION_STORE_TRIGGER, }; static enum action_code action; int main(int argc, char **argv) { Device m; action = ACTION_NONE; if (argc < 2) { m.printUsage(argv[0]); } std::string fpgaFilePath = ""; std::string forcedAP = ""; std::string name = ""; std::string data = ""; int duration = 0; MTS::Logger::setPrintLevel(MTS::Logger::PrintLevel::INFO_LEVEL, true); int c; static struct option long_options[] = { {"help", no_argument, nullptr, 'h'}, {"check", no_argument, nullptr, 'c'}, {"data", required_argument, nullptr, 'd'}, {"input", required_argument, nullptr, 'i'}, {"init", no_argument, nullptr, 'I'}, {"json", no_argument, nullptr, 'j'}, {"load-fpga", no_argument, nullptr, 'l'}, {"path", required_argument, nullptr, 'p'}, {"show", required_argument, nullptr, 's'}, {"show-trigger", required_argument, nullptr, 'S'}, {"store", required_argument, nullptr, 't'}, {"duration", required_argument, nullptr, 'u'}, {"store-trigger", required_argument, nullptr, 'T'}, {"version", no_argument, nullptr, 'v'}, {"verbose", no_argument, nullptr, 'V'}, {nullptr, no_argument, nullptr, 0}}; for (;;) { int option_index = 0; c = getopt_long(argc, argv, "cd:hi:Ijlp:s:St:T:vVu:", long_options, &option_index); if (c == -1) break; switch (c) { case 'v': { action = ACTION_VERSION; break; } case 'V': { MTS::Logger::setPrintLevel(MTS::Logger::PrintLevel::DEBUG_LEVEL, true); break; } case 'c': { action = ACTION_CHECK_FPGA; break; } case 'd': { data = optarg; break; } case 'i': { fpgaFilePath = optarg; break; } case 'p': { forcedAP = std::string(optarg); break; } case 'I': { action = ACTION_INIT; break; } case 'j': { action = ACTION_JSON; break; } case 'l': { action = ACTION_LOAD_FPGA; break; } case 's': { action = ACTION_SHOW; name = optarg; break; } case 'S': { action = ACTION_SHOW_TRIGGER; name = optarg; break; } case 't': { action = ACTION_STORE; name = optarg; break; } case 'u': { duration = atoi(optarg); break; } case 'T': { action = ACTION_STORE_TRIGGER; name = optarg; break; } case ':': { printf("Missing arg for %c\n", optopt); exit(-1); } case 'h': { m.printUsage(argv[0]); exit(0); } default: m.printUsage(argv[0]); exit(-1); } } /* Handle old non POSIX compliant command names. */ int index; for (index = optind; index < argc; index++) { if (strcmp(argv[index], COMMMAND_INIT) == 0) { action = ACTION_INIT; } else if (strcmp(argv[index], COMMMAND_JSON) == 0) { action = ACTION_JSON; } else if (strcmp(argv[index], COMMMAND_SHOW) == 0) { if (argv[index + 1]) { action = ACTION_SHOW; name = argv[index + 1]; } else { action = ACTION_NONE; } } else if (strcmp(argv[index], COMMMAND_STORE) == 0) { if (argv[index + 1]) { action = ACTION_STORE; name = argv[index + 1]; if (argv[index + 2]) { data = argv[index + 2]; } } else { action = ACTION_NONE; } } else if (strcmp(argv[index], COMMMAND_SHOW_TRIGGER) == 0) { if (argv[index + 1]) { action = ACTION_SHOW_TRIGGER; name = argv[index + 1]; } else { action = ACTION_NONE; } } else if (strcmp(argv[index], COMMMAND_STORE_TRIGGER) == 0) { if (argv[index + 1]) { action = ACTION_STORE_TRIGGER; name = argv[index + 1]; if (argv[index + 2]) { data = argv[index + 2]; } } else { action = ACTION_NONE; } } else if (strcmp(argv[index], COMMMAND_LOAD_FPGA) == 0) { if (action != ACTION_CHECK_FPGA) { action = ACTION_LOAD_FPGA; } } else if (strcmp(argv[index], COMMMAND_VERSION) == 0) { action = ACTION_VERSION; } else if (strcmp(argv[index], COMMMAND_EXTRA) == 0) { if (argv[index + 1]) { data = argv[index + 1]; } } } switch (action) { case ACTION_NONE: { m.printUsage(argv[0]); } case ACTION_SHOW: { m.show(name); } case ACTION_SHOW_TRIGGER: { m.showTrigger(name); } case ACTION_STORE: { m.store(name, data); if (duration) { usleep(1000 * duration); data = data == "0" ? "1" : "0"; m.store(name, data); } m.storeOutputStateToNonvolatile(name, data); break; } case ACTION_STORE_TRIGGER: { m.storeTrigger(name, data); } case ACTION_INIT: { m.init(); } case ACTION_JSON: { m.json(); } case ACTION_CHECK_FPGA: { Mtac15Fpga mtac15Fpga(fpgaFilePath, forcedAP); mtac15Fpga.printFpgaVersion(); } case ACTION_LOAD_FPGA: { Mtac15Fpga mtac15Fpga(fpgaFilePath, forcedAP); return mtac15Fpga.upgradeFpga(); } case ACTION_VERSION: { m.printVersion(argv[0]); } default: { m.printUsage(argv[0]); } } return 0; }