void ShieldGSM::executeATCommands(struct ATcommand *commandsList, int numCommands) { for (int i = 0; i < numCommands; i++) { struct ATcommand atc = commandsList[i]; int tocount=0; int state = INIT_WAIT_CODE; TMRArd_InitTimer(0, INIT_TIME); Serial.print(i); executeUserCommand(atc.cmd.c_str()); do { state = printShieldGSMResponse(atc.resp); if (state == INIT_WAIT_CODE && TMRArd_IsTimerExpired(0)) { state = INIT_TIMEOUT_CODE; TMRArd_InitTimer(0, INIT_TIME); } else if (state != INIT_WAIT_CODE) { TMRArd_InitTimer(0, INIT_TIME); } switch(state) { case INIT_TIMEOUT_CODE: Serial.println("COMMAND TIMEOUT: "+String(++tocount)); // intentionally no break case INIT_ERROR_CODE: executeUserCommand(atc.cmd.c_str()); break; default: break; } if(tocount>=3){ executeUserCommand(CTRL_Z.c_str()); return; } } while(state != INIT_SUCCESS_CODE); } }
void ShieldGSM::sendSMS_manual(String message, String phoneNumber){ String setPhone = "AT+CMGS="; setPhone+=phoneNumber; executeUserCommand(setPhone.c_str()); delay(100); executeUserCommand(message.c_str()); delay(100); executeUserCommand(String((char)26).c_str()); //the ASCII code of the ctrl+z is 26 delay(100); }
/* This method carries out the execution of the binary code in the file specified by the arguments at run time. The file is loaded into the memory of the structure processor and then the execution is carried out in the while loop. The execution of terminates when an instruction with opcode HALT is reached. @param argv : this specifies the arguements which were given through the terminal when the program was run. @param argc : this specifes the number of arguments provided @return : the method returns 0 when the method executes without any errors */ int main(int argc, char **argv) { assert("There are wrong number of arguents given" && argc==3); struct Processor *processor = malloc(sizeof(struct Processor)); char *filepath = argv[1]; memset(processor, 0, sizeof(struct Processor)); int lineNumber = 0 ; binaryFileLoader(filepath, processor); printWelcomeMessage(); char **tokens = malloc(sizeof(char) *BUFFER_SIZE); do { tokens = getUserCommand(); executeUserCommand(argv[2] , argv[1], processor, tokens); printf("token -> %s\n",tokens[0]); }while (strcmp(tokens[0],"q")==0); printf("Thanks for using JVG debugger\n"); fflush(stdout); return EXIT_SUCCESS; }
void executeCommand(const std::string& command, const std::vector<std::string>& commandArgs) { if (command == "help") { help(); } else if (command == "exit") { exit_ = true; } else if (executeUserCommand(command, commandArgs)) { return; } else if (executeDirCommand(command, commandArgs)) { return; } else if (executeBackupCommand(command, commandArgs)) { return; } else { std::cout << "Unknown command '" << command << "'" << std::endl; } }
void ShieldGSM::pollUserCommand() { char avail = Serial.available(); if (avail) { Serial.println(millis()); String buffer = Serial.readString(); executeUserCommand(buffer.c_str()); } }
int main(int argc, char **argv) { struct Processor *proc = malloc(sizeof(struct Processor)); assert("There are wrong number of arguents given" && argc==3); char *fBin = argv[2]; char *fAssembly = argv[1]; memset(proc,0,sizeof(struct Processor)); binaryFileLoader(fBin,proc); system("clear"); int *breakPoints = malloc(sizeof(int) *BREAKPOINTS_ARRAY_SIZE); memset(breakPoints,-1,sizeof(int) *BREAKPOINTS_ARRAY_SIZE); printWelcomeMessage(); char **tokens = malloc(sizeof(char) *BUFFER_SIZE); int returnVal = 0; do { tokens = getUserCommand(); returnVal = executeUserCommand(fAssembly,fBin,proc,tokens,breakPoints); free(tokens); } while (!returnVal); printf("Thanks for using JVG debugger\n"); system("clear"); free(proc); free(breakPoints); return EXIT_SUCCESS; }
int main(int argc, char const *argv[]) { //inicializacao if(initializeCommunication(argc, argv) != 0) exit(-1); //inicailizacao falhou putdebug("inicialização completa\n"); //inicializar conjunto de ligacoes initializeConnectionSet(); int maxFd = curNode.fd; //descritor com valor mais elevado char buffer[BUFSIZE]; //buffer utilizado para fazer a leitura dos descritores int inputReady = 0; //indica se existe input disponivel para ler int quit = FALSE; while(!quit) { //reinicializar conjunto de fds de leitura FD_ZERO(&readFds); //adicionar ligacoes no conjunto de fds copySet(&readFds); //adicionar listen fd ao conjunto de fds FD_SET(curNode.fd, &readFds); //adicionar stdin ao conjunto de fds FD_SET(STDIN_FILENO, &readFds); putdebug("CurNode - ring: %d id: %d ip: %s port: %s fd: %d", curRing, curNode.id, curNode.ip, curNode.port, curNode.fd); putdebug("SucciNode - id: %d ip: %s port: %s fd: %d", succiNode.id, succiNode.ip, succiNode.port, succiNode.fd); putdebug("PrediNode - id: %d ip: %s port: %s fd: %d", prediNode.id, prediNode.ip, prediNode.port, prediNode.fd); if(maxFd < getMaxConnection()) { maxFd = getMaxConnection(); } //esperar por descritor pronto para ler putmessage("\r> "); inputReady = select(maxFd + 1, &readFds, NULL, NULL, NULL); if(inputReady <= 0) { putdebugError("main", "select falhou"); continue; } if(FD_ISSET(curNode.fd, &readFds)) { //testar se o listen fd esta pronto para leitura struct sockaddr_in addr; socklen_t addrlen = sizeof(addr); bzero(&addr, addrlen); //aceitar ligacao int connectionFd; if( (connectionFd = accept(curNode.fd, (struct sockaddr*)&addr, &addrlen)) == -1) { putdebugError("main", "ligação não foi aceite"); } else { putdebug("nova ligação %d com endereço: %s", connectionFd, inet_ntoa(addr.sin_addr)); //adicionar descritor ao conjunto de descritores de ligacao addConnection(connectionFd); //definir um timeout para as comunicações struct timeval tv; tv.tv_sec = 5; setsockopt(connectionFd, SOL_SOCKET, SO_SNDTIMEO,(struct timeval *)&tv,sizeof(struct timeval)); setsockopt(connectionFd, SOL_SOCKET, SO_RCVTIMEO,(struct timeval *)&tv,sizeof(struct timeval)); } } if(FD_ISSET(STDIN_FILENO, &readFds)) { //testar se o utilizador executou um comando //ler comando do utilizador bzero(buffer, sizeof(buffer)); if(fgets(buffer, BUFSIZE, stdin) != NULL) { //executar comando do utilizador putdebug("processar comando do utilizador"); int errorCode = executeUserCommand(buffer); switch(errorCode) { case 0: putdebug("comando de utilizador processado com sucesso"); break; case -1: putdebugError("main", "falha no processamento do comando de utilizador"); break; case 1: { putmessage("programa vai sair\n"); //fechar todos os sockets int fd = getFirstConnection(); while(fd >= 0) { close(fd); rmConnection(fd); //proxima ligacao fd = getNextConnection(fd); } //fechar socket de escuta e socket do servidor de arranque closeSockets(); quit = TRUE; continue; } } } } //ler fds de ligacoes actuais com o nó int connectionFd = getFirstConnection(); while(connectionFd >= 0) { if(FD_ISSET(connectionFd, &readFds)) { //limpar buffer de rececao bzero(buffer, sizeof(buffer)); //ler mensagem if(readMessage(connectionFd, buffer, sizeof(buffer)) <= 0) { close(connectionFd); //fechar ligacao rmConnection(connectionFd); //remover no do conjunto de ligacoes putdebug("ligacao %d terminada", connectionFd); if(connectionFd == prediNode.fd) { prediNode.fd = -1; prediNode.id = -1; putdebug("ligação terminada com predi"); if(succiNode.fd == -1 && !iAmStartNode) { //estou sozinha mas não sou o nó de arranque //isto significa que houve uma saida abrupta //registar num novo anel if(registerNewRing() == -1) { putdebugError("handleEND", "não foi possível registar novo anel"); return -1; } } } if(connectionFd == succiNode.fd) { succiNode.fd = -1; succiNode.id = -1; putdebug("ligação terminada com succi"); //colocar um alarme de 2 segundos para garnatir que todas as ligações //que são par ser terminadas têm efeito no estado do nó signal(SIGALRM, rebuildSignal); alarm(REBUILD_INTERVAL); } } else { //tratar mensagem recebida putdebug("mensagem recebida pela ligacao %d: %s", connectionFd, buffer); //remover \n int length = strlen(buffer); if(buffer[length - 1] == '\n') buffer[length - 1] = '\0'; if(strcmp(buffer, "ERROR") == 0) { //houve um erro na comunicação TCP puterror("ocorreu um erro na comunicação entre nós\n"); closeConnection(&connectionFd); continue; } if(handleMessage(buffer, connectionFd) == -1) { //notificar quem enviou o pedido que ocorreu um erro char answer[] = "ERROR\n"; sendMessage(connectionFd, answer); if(connectionFd == prediNode.fd) { prediNode.fd = -1; prediNode.id = -1; putdebug("ligação terminada com predi por causa de erro"); } if(connectionFd == succiNode.fd) { succiNode.fd = -1; succiNode.id = -1; putdebug("ligação terminada com succi por causa de erro"); } //terminar ligacao closeConnection(&connectionFd); } } } //proxima ligacao connectionFd = getNextConnection(connectionFd); } } return 0; }