Beispiel #1
0
void cmd_buf_handler()
{
  gchar **cmd_strv;
  gint strv_len, i;

  do
    {
      cmd_strv = g_strsplit(control_service_data.cmd_buf->str, "\n", CMD_BUF_PIECES);
      strv_len = g_strv_length(cmd_strv);
      if (strv_len == 0)
	{
	  g_strfreev(cmd_strv);
	  return;
	}
      for (i = 0; i < strv_len - 1; i++)
	{
	  if (strlen(cmd_strv[i]) > 0)
	    {
	      g_print("Cmd was : \"%s\"\n", cmd_strv[i]);
	      cmd_handler(cmd_strv[i]);
	    }
	}
      g_string_free(control_service_data.cmd_buf, TRUE);
      control_service_data.cmd_buf = g_string_new_len(cmd_strv[strv_len - 1], strlen(cmd_strv[strv_len -1]));
      g_strfreev(cmd_strv);
    } while (strv_len == CMD_BUF_PIECES);
}
Beispiel #2
0
void cmd_poll()
{
    while (HAL_OK == UART_WaitOnFlagUntilTimeout(&huart1, UART_FLAG_RXNE, RESET, 0))
    {
        cmd_handler();
    }
}
Beispiel #3
0
void cmdPoll()
{
    while (Serial.available())
    {
        cmd_handler();
    }
}
Beispiel #4
0
/*
 * Function: main
 * Description: main function calls functions for intialization and 
 * command verification, excution and finalization
*/
int main(int argc, char *argv[])
{
	int ret = 0;
	WIMAX_API_RET wmxStatus;
	
	parsed_cmd out_cmd;

	//checking user priviledge
	//Disabled permission checking so non-root can run it
	//      if (geteuid() != (uid_t) 0) {
	//              fprintf(stderr,
	//                      "ERROR: You do not possess sufficient privileges to perform this action.\n");
	//              return 1;
	//      }

	// validate user command
	if (validate_cmd(argc, argv, &out_cmd) != 0) {
		wimaxcu_main_help();
		return 1;
	}
	// If user requested to diplay the help
	if (out_cmd.cmd == CMD_HELP) {
		wimaxcu_main_help();
		return 0;
	}
	memset(&gbl_device_id, 0, sizeof(WIMAX_API_DEVICE_ID));
	// Request for READ_WRITE Permissions
	// TODO: Kalyan Can we request for permissions based on the command?
	// For example for status Read permission is sufficient.
	gbl_device_id.privilege = WIMAX_API_PRIVILEGE_READ_WRITE;

	//Signal to handle Ctrl+C
	signal(SIGINT, wimaxcu_stop_signal_handler);
	signal(SIGTERM, wimaxcu_stop_signal_handler);

	// Initialize the SDK (CommonAPI)
	wmxStatus = wimaxcu_initialize(&gbl_device_id);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		printf("ERROR: Make sure WiMAX Network Service is running.\n");
		return 1;
	}
	// Kalyan 5.0.09 merge
	// This delay will allow the Initialize to init everything in its threads
	// sleep(1);
	// Execute the command
	ret = cmd_handler(&gbl_device_id, &out_cmd);
	// Finalize the SDK
	wimaxcu_finalize(&gbl_device_id);

	return ret;
}
Beispiel #5
0
void ums_run_once()
{
    uint8_t nextByte;

    // disabled until complete enable string is received
    while (umsEnabled < UMS_ENABLE_LEN && pf_receive_byte(&nextByte) != 0) {
        if (nextByte == UMS_ENABLE[umsEnabled]) {
            ++umsEnabled;
            if (umsEnabled == UMS_ENABLE_LEN) {
            	ums_send_accept();
            }
        } else {
            umsEnabled = 0;
        }
    }

    // not disabled, normal operation
    if (umsEnabled == UMS_ENABLE_LEN) {
        // if the stepper queue is full, then we don't process any more commands
        while (!st_full()) {
            uint8_t *rx = cmd_receive();
            if (rx != NULL) {
                cmd_handler(rx);
            	commandCounter++;
            } else {
                break;
            }
        }
    }

    // send a status when limit switches change or ~1e6 stepper delay ticks have elapsed
    if (umsLimits != previousLimits || umsRunTime > nextStatusTime ||
    		(umsStatus & UMS_SEND_STATUS_NOW) != 0) {
    	previousLimits = umsLimits;
    	nextStatusTime += UMS_STATUS_INTERVAL;
    	ums_send_status();
    	umsStatus &= ~UMS_SEND_STATUS_NOW;
    }
}
Beispiel #6
0
void udp_rx2_handler(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
{
  int i;
  uint8_t* prx_udp_msg = (uint8_t*)&rx_udp_msg[SNTP];
  struct pbuf *pbuffer = p;
 
   if(p->tot_len <= rx_udp_msg_size) 
   {
     while(1)
     {
       for(i = 0; i < pbuffer->len; i++)
       {
         prx_udp_msg[i] = *(((uint8_t*)pbuffer->payload)+i);
       }
      
       if(pbuffer->next == NULL) break;
       else pbuffer = pbuffer->next;
     }
    
    cmd_handler(SNTP);   
   }
  pbuf_free(p);  
}
Beispiel #7
0
int main() {
  print_header();
  while (1) {
    printf("(aprime) ");
    char cmd[20];
    fgets(cmd, sizeof(cmd), stdin);
    bool integer = true;

    for (i=0; i < strlen(cmd)-1; i++) {
      if (!isdigit(cmd[i])) {
          integer = false;
          break;
      }
    }
    if (integer == true) {
      int input;
      sscanf(cmd, "%d", &input);
      assess_primality(input);    
    } else {  
      cmd_handler(cmd);
    }
  }
}
Beispiel #8
0
void ieee_mainloop(void) {
  int16_t cmd = 0;

  set_error(ERROR_DOSVERSION);

  ieee_data.bus_state = BUS_IDLE;
  ieee_data.device_state = DEVICE_IDLE;
  for(;;) {
    switch(ieee_data.bus_state) {
      case BUS_SLEEP:                               /* BUS_SLEEP */
        set_atn_irq(0);
        ieee_bus_idle();
        set_error(ERROR_OK);
        set_busy_led(0);
        uart_puts_P(PSTR("ieee.c/sleep ")); set_dirty_led(1);

        /* Wait until the sleep key is used again */
        while (!key_pressed(KEY_SLEEP))
          system_sleep();
        reset_key(KEY_SLEEP);

        set_atn_irq(1);
        update_leds();

        ieee_data.bus_state = BUS_IDLE;
        break;

      case BUS_IDLE:                                /* BUS_IDLE */
        ieee_bus_idle();
        while(IEEE_ATN) {   ;               /* wait for ATN */
          if (key_pressed(KEY_NEXT | KEY_PREV | KEY_HOME)) {
            change_disk();
          } else if (key_pressed(KEY_SLEEP)) {
            reset_key(KEY_SLEEP);
            ieee_data.bus_state = BUS_SLEEP;
            break;
          } else if (display_found && key_pressed(KEY_DISPLAY)) {
            display_service();
            reset_key(KEY_DISPLAY);
          }
          system_sleep();
      }

      if (ieee_data.bus_state != BUS_SLEEP)
        ieee_data.bus_state = BUS_FOUNDATN;
      break;

      case BUS_FOUNDATN:                            /* BUS_FOUNDATN */
        ieee_data.bus_state = BUS_ATNPROCESS;
        cmd = ieee_getc();
      break;

      case BUS_ATNPROCESS:                          /* BUS_ATNPROCESS */
        if(cmd < 0) {
          uart_putc('c');
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else cmd &= 0xFF;
        uart_puts_p("ATN "); uart_puthex(cmd);
        uart_putcrlf();

        if (cmd == 0x3f) {                                  /* UNLISTEN */
          if(ieee_data.device_state == DEVICE_LISTEN) {
            ieee_data.device_state = DEVICE_IDLE;
            uart_puts_p("UNLISTEN\r\n");
          }
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if (cmd == 0x5f) {                           /* UNTALK */
          if(ieee_data.device_state == DEVICE_TALK) {
            ieee_data.device_state = DEVICE_IDLE;
            uart_puts_p("UNTALK\r\n");
          }
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if (cmd == (0x40 + device_address)) {        /* TALK */
          uart_puts_p("TALK ");
          uart_puthex(device_address); uart_putcrlf();
          ieee_data.device_state = DEVICE_TALK;
          /* disk drives never talk immediatly after TALK, so stay idle
             and wait for a secondary address given by 0x60-0x6f DATA */
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if (cmd == (0x20 + device_address)) {        /* LISTEN */
          ieee_data.device_state = DEVICE_LISTEN;
          uart_puts_p("LISTEN ");
          uart_puthex(device_address); uart_putcrlf();
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if ((cmd & 0xf0) == 0x60) {                  /* DATA */
          /* 8250LP sends data while ATN is still active, so wait
             for bus controller to release ATN or we will misinterpret
             data as a command */
          while(!IEEE_ATN);
          if(ieee_data.device_state == DEVICE_LISTEN) {
            cmd = ieee_listen_handler(cmd);
            cmd_handler();
            break;
          } else if (ieee_data.device_state == DEVICE_TALK) {
            ieee_data.secondary_address = cmd & 0x0f;
            uart_puts_p("DATA T ");
            uart_puthex(ieee_data.secondary_address);
            uart_putcrlf();
            if(ieee_talk_handler() == TIMEOUT_ABORT) {
              ieee_data.device_state = DEVICE_IDLE;
            }
            ieee_data.bus_state = BUS_IDLE;
            break;
          } else {
            ieee_data.bus_state = BUS_IDLE;
            break;
          }
        } else if (ieee_data.device_state == DEVICE_IDLE) {
          ieee_data.bus_state = BUS_IDLE;
          break;
          /* ----- if we reach this, we're LISTENer or TALKer ----- */
        } else if ((cmd & 0xf0) == 0xe0) {                  /* CLOSE */
          ieee_data.secondary_address = cmd & 0x0f;
          uart_puts_p("CLOSE ");
          uart_puthex(ieee_data.secondary_address);
          uart_putcrlf();
          /* Close all buffers if sec. 15 is closed */
          if(ieee_data.secondary_address == 15) {
            free_multiple_buffers(FMB_USER_CLEAN);
          } else {
            /* Close a single buffer */
            buffer_t *buf;
            buf = find_buffer (ieee_data.secondary_address);
            if (buf != NULL) {
              buf->cleanup(buf);
              free_buffer(buf);
            }
          }
          ieee_data.bus_state = BUS_IDLE;
          break;
        } else if ((cmd & 0xf0) == 0xf0) {                  /* OPEN */
          cmd = ieee_listen_handler(cmd);
          cmd_handler();
          break;
        } else {
          /* Command for other device or unknown command */
          ieee_data.bus_state = BUS_IDLE;
        }
      break;
    }   /* switch   */
  }     /* for()    */
}
Beispiel #9
0
uint8_t cmd_interpret(uint8_t * cmd, uint8_t * result)
{
    return cmd_handler(cmd[0],cmd+1,result);
}
Beispiel #10
0
int run_shell()
{
    char *command;
    char *commandtmp;
    char *cmd_token;
    char *arg_token;
    int cmd_arr_length = sizeof(cmd_arr) / sizeof(char *);  /* gets length of command array */
    int prompt = '$';
    int i;
    int invalid_cmd;
    int bytes_read;
    int nbytes = BYTE_LIM;

    set_env_vars();

    printf("Welcome to failshell!\n");

    /* allocates appropriate mem to command, limiting user's command and setting up temporary container string to split */
    command = (char *) malloc(nbytes);
    commandtmp = (char *) malloc(sizeof(command));
    if (commandtmp == NULL)     return OOM;     /* if no space left to allocate (highly unlikely...) */

    /* the main loop that powers the shell */
    while (run_signal != EOF)
    {
        invalid_cmd = TRUE;
        printf("%s %s %c ", user, pwd, prompt);

        /* get command string from user and place into address pointed at by *command */
        bytes_read = getline(&command, (size_t *) &nbytes, stdin);
        if (bytes_read == EOF)      /* bytes_read will only = EOF if some IO error or interrupt (including Ctrl+D) */
            return EOF;

        strcpy(commandtmp, command);

        cmd_token = (char *) malloc(sizeof(command));
        arg_token = (char *) malloc(sizeof(command));

        /* split entered command into tokens for command argument and second argument i.e., $0 and $1 */
        cmd_token = strtok(commandtmp, DELIMITER);
        arg_token = strtok(NULL, DELIMITER);

        /* had problems with '\n' value being put into strings, which messed up comparisons later; this takes them out if they exist */
        if (arg_token == NULL)  trim_line_break(cmd_token);   /* if no argument */
        else                    trim_line_break(arg_token);

        /* compares entered command with all valid commands, allowing handler to execute command if valid */
        for (i = 0; i < cmd_arr_length; i++)
        {
            if (strcmp(cmd_token, cmd_arr[i]) == 0)
            {
                invalid_cmd = FALSE;
                cmd_handler(i, arg_token);
            }
        }

        /* don't print error message if user entered valid command or if they didn't enter anything */
        if (invalid_cmd && strlen(cmd_token) > 1)
            printf("Command \"%s\" is invalid. Type \"%s\" for assistance.\n", cmd_token, cmd_arr[4]);
    }
    return 0;
}