int main() { usb_init(); SetLogFilename("snooper.log"); g_return_on_error = 1; while(1) { while (!OpenProxmark(0)) { sleep(1); } while (1) { UsbCommand cmdbuf; CommandReceived("hf 14a snoop"); HANDLE_ERROR; ReceiveCommand(&cmdbuf); HANDLE_ERROR; for (int i = 0; i < 5; ++i) { ReceiveCommandPoll(&cmdbuf); } HANDLE_ERROR; CommandReceived("hf 14a list"); HANDLE_ERROR; } } CloseProxmark(); return 0; }
int main(int argc, char **argv) { if (argc != 3 && argc != 4) { printf("\n\tusage: cli <command 1> <command 2> [logfile (default cli.log)]\n"); printf("\n"); printf("\texample: cli hi14asnoop hi14alist h14a.log\n"); printf("\n"); return -1; } usb_init(); if (argc == 4) SetLogFilename(argv[3]); else SetLogFilename("cli.log"); return_on_error = 1; while (1) { while (!OpenProxmark(0)) { sleep(1); } while (1) { UsbCommand cmdbuf; CommandReceived(argv[1]); HANDLE_ERROR; ReceiveCommand(&cmdbuf); HANDLE_ERROR; for (int i = 0; i < 5; ++i) { ReceiveCommandPoll(&cmdbuf); } HANDLE_ERROR; CommandReceived(argv[2]); HANDLE_ERROR; } } CloseProxmark(); return 0; }
void QueueManager::run() { SetStatus(QM_STARTING); m_isRunning = true; m_ruleManager.Load(config.RULES_LOCATION); SetStatus(QM_LOADING); m_controllerLoaded = ControllerLoad(); int res = 0; // flush queue commented because of cmd line (will wake up queue) // m_queueCommands.clear(); struct x10_ha_command x10CmdRecv; Logger::Log(DEBUG, "** QueueManager Entering loop", qPrintable(StatusStr())); while (m_isRunning) { QMutexLocker locker(&m_mutex); unsigned int nbErrors = 0; // while nothing to send while (m_isRunning && !m_queueCommands.size()) { /// Read input. if (m_controllerLoaded) { res = m_X10Controller->x10_recv(&x10CmdRecv); if (res > 0) { nbErrors = 0; Logger::Log(INFO, "X10 command received on house %c unit %d, cmd:%s res:%d", house_code_to_char(x10CmdRecv.house), unit_code_to_int(x10CmdRecv.unit), cmd_code_to_str(x10CmdRecv.cmd), res); // emit CommandReceived(*cmd); QString address = QString("%1%2") .arg(house_code_to_char(x10CmdRecv.house)) .arg(unit_code_to_int(x10CmdRecv.unit)) .toUpper(); CheckContainerExist(address); switch (x10CmdRecv.cmd) { case X10CMD_ON: Containers[address]->SetOn(true); break; case X10CMD_OFF: Containers[address]->SetOn(false); break; case X10CMD_BRIGHT: Containers[address]->PushDirection(true); break; case X10CMD_DIM: Containers[address]->PushDirection(false); break; case X10CMD_UP: case X10CMD_RIGHT: case X10CMD_DOWN: case X10CMD_LEFT: break; case X10CMD_INVALID: break; } emit CommandReceived(); } else if (res && res != -110 /*&& res != -1*/) // first res is -1 { // Logger::Log(ERROR, "res = -1 !!", res); nbErrors++; Logger::Log(DEBUG, "ERROR: (%d)", res); if (nbErrors > config.MAX_ERRORS) break; } } queueNotEmpty.wait(&m_mutex, 1000); } if (nbErrors > config.MAX_ERRORS) // reload controller { ControllerUnload(); if (!config.RELOAD_ON_ERROR) { Logger::Log(ERROR, "X10 Interface died, quitting QueueManager thread"); break; } nbErrors = 0; ControllerLoad(); continue; } COMMAND* cmd = 0; if (m_isRunning && m_queueCommands.size()) // not supposed to be empty at this point { cmd = m_queueCommands.back(); // when receiving it, it is this engine role to figure out how if (cmd->command == CMD_SET) { COMMAND* intermCmd; int nbSteps = GetNextCommand(*cmd, &intermCmd); // unique step or nothing to do if (nbSteps <= 1) m_queueCommands.remove(cmd); if (nbSteps) { if (!cmd->notified) { emit CommandCompleted(*cmd); cmd->notified = true; } intermCmd->notified = true; // not to be resent by subcmd } // Logger::Log(DEBUG, "** SET to %d produced %d steps", cmd->value, nbSteps); cmd = intermCmd; // null if nothing to do } else { // Logger::Log(DEBUG, "** SEND command"); m_queueCommands.remove(cmd); // 1 step per command } } locker.unlock(); if (!cmd) continue; // end marker x10_ha_command* x10cmd = new_x10_ha_command(parse_cmd_code(cmd->command), cmd->channel, cmd->unit); if (x10cmd) // else params out of bound { QString address = cmd->address(); CheckContainerExist(address); // for read int currentValue = Containers[address]->Value(); switch (cmd->command) { case CMD_SET: Containers[address]->SetValue(cmd->value); break; case CMD_ON: Containers[address]->SetValue(currentValue < 0 ? MAX_VALUE : currentValue); break; case CMD_OFF: Containers[address]->SetValue(-1); break; case CMD_DIM: if (currentValue == -1) currentValue = MAX_VALUE; Containers[address]->SetValue(currentValue ? currentValue - 1 : 0); break; case CMD_BRIGHT: if (currentValue == -1) currentValue = MAX_VALUE; Containers[address]->SetValue(currentValue >= MAX_VALUE ? MAX_VALUE : currentValue + 1); break; default: break; } if (m_controllerLoaded) { // emit CommandCompleted if not SET if (!cmd->notified) emit CommandCompleted(*cmd); m_X10Controller->x10_send(x10cmd); } else { Logger::Log(ERROR, "NO Controller to send Command %s", qPrintable(cmd->commandStr())); } del_x10_ha_command(x10cmd); } delete cmd; } ControllerUnload(); SetStatus(QM_STOPPED); }
static void *main_loop(void *targ) { struct main_loop_arg *arg = (struct main_loop_arg*)targ; struct usb_receiver_arg rarg; char *cmd = NULL; pthread_t reader_thread; if (arg->usb_present == 1) { rarg.run=1; pthread_create(&reader_thread, NULL, &usb_receiver, &rarg); } FILE *script_file = NULL; char script_cmd_buf[256]; if (arg->script_cmds_file) { script_file = fopen(arg->script_cmds_file, "r"); if (script_file) { printf("using 'scripting' commands file %s\n", arg->script_cmds_file); } } read_history(".history"); while(1) { // If there is a script file if (script_file) { if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), script_file)) { fclose(script_file); script_file = NULL; } else { char *nl; nl = strrchr(script_cmd_buf, '\r'); if (nl) *nl = '\0'; nl = strrchr(script_cmd_buf, '\n'); if (nl) *nl = '\0'; if ((cmd = (char*) malloc(strlen(script_cmd_buf))) != NULL) { memset(cmd, 0, strlen(script_cmd_buf)); strcpy(cmd, script_cmd_buf); printf("%s\n", cmd); } } } if (!script_file) { cmd = readline(PROXPROMPT); } if (cmd) { while(cmd[strlen(cmd) - 1] == ' ') cmd[strlen(cmd) - 1] = 0x00; if (cmd[0] != 0x00) { if (strncmp(cmd, "quit", 4) == 0) { break; } CommandReceived(cmd); add_history(cmd); } free(cmd); } else { printf("\n"); break; } } write_history(".history"); if (arg->usb_present == 1) { rarg.run = 0; pthread_join(reader_thread, NULL); } if (script_file) { fclose(script_file); script_file = NULL; } ExitGraphics(); pthread_exit(NULL); return NULL; }
/** * @brief Calls the command line parser to deal with the command. This enables * lua-scripts to do stuff like "core.console('hf mf mifare')" * @param L * @return */ static int l_CmdConsole(lua_State *L) { CommandReceived((char *)luaL_checkstring(L, 1)); return 0; }
static void *main_loop(void *targ) { struct main_loop_arg *arg = (struct main_loop_arg*)targ; struct receiver_arg rarg; char *cmd = NULL; pthread_t reader_thread; if (arg->usb_present == 1) { rarg.run = 1; pthread_create(&reader_thread, NULL, &uart_receiver, &rarg); // cache Version information now: CmdVersion(NULL); } FILE *script_file = NULL; char script_cmd_buf[256] = {0x00}; // iceman, needs lua script the same file_path_buffer as the rest if (arg->script_cmds_file) { script_file = fopen(arg->script_cmds_file, "r"); if (script_file) printf("using 'scripting' commands file %s\n", arg->script_cmds_file); } read_history(".history"); while(1) { // If there is a script file if (script_file) { if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), script_file)) { fclose(script_file); script_file = NULL; } else { char *nl; nl = strrchr(script_cmd_buf, '\r'); if (nl) *nl = '\0'; nl = strrchr(script_cmd_buf, '\n'); if (nl) *nl = '\0'; int newlen = strlen(script_cmd_buf); if ((cmd = (char*) malloc( newlen + 1)) != NULL) { memset(cmd, 0x00, newlen); strcpy(cmd, script_cmd_buf); printf("%s\n", cmd); } } } else { cmd = readline(PROXPROMPT); } // this one should pick up all non-null cmd... // why is there a if (cmd) { while(cmd[strlen(cmd) - 1] == ' ') cmd[strlen(cmd) - 1] = 0x00; if (cmd[0] != 0x00) { int ret = CommandReceived(cmd); add_history(cmd); // exit or quit if (ret == 99) break; } free(cmd); cmd = 0; } else { printf("\n"); break; } } if (script_file) { fclose(script_file); script_file = NULL; } write_history(".history"); free(cmd); cmd = 0; if (arg->usb_present == 1) { rarg.run = 0; pthread_join(reader_thread, NULL); } ExitGraphics(); pthread_exit(NULL); return NULL; }