Example #1
0
int main(int argc, char *argv[])
{
  int i;
  int fd;
  int ret;
  int c;
  int argcount;
  int print_device_diagnostics = 0;
  const char *device;
  const char *script_file;

  int num_args = 0;
  int args[MAX_COMMAND_ARGS];
  char *line, *cmd, *arg;

  while ((c = getopt (argc, argv, "it")) != -1) {
    if (c=='t') {
      print_actions = 1;
    } else if (c=='i') {
      print_device_diagnostics = 1;
    } else {
      fprintf(stderr, "Unknown option: -%c\n", c);
    }
  }

  argcount = (argc - optind);
  if ((print_device_diagnostics && argcount != 1) ||
      (!print_device_diagnostics && argcount != 2)) {
    fprintf(stderr, "Usage: %s [options] <device> [script file]\n\n"
            "Options:\n"
            "  -i                  print device information\n"
            "  -t                  print event timings\n", argv[0]);
    return 1;
  }
  device = argv[optind];
  script_file = argv[optind + 1];

  fd = open(device, O_RDWR);
  if(fd < 0) {
    fprintf(stderr, "could not open %s, %s\n", device, strerror(errno));
    return 1;
  }

  uint32_t device_flags = figure_out_events_device_reports(fd);

  if (print_device_diagnostics) {
    if (device_flags & INPUT_DEVICE_CLASS_TOUCH) {
      printf("INPUT_DEVICE_CLASS_TOUCH\n");
    }
    if (device_flags & INPUT_DEVICE_CLASS_TOUCH_MT) {
      printf("INPUT_DEVICE_CLASS_TOUCH_MT\n");
    }
    if (device_flags & INPUT_DEVICE_CLASS_TOUCH_MT_SYNC) {
      printf("INPUT_DEVICE_CLASS_TOUCH_MT_SYNC\n");
    }

    // just exit
    return 0;
  }

  FILE *f = fopen(script_file, "r");
  if (!f) {
    printf("Unable to read file %s", script_file);
    return 1;
  }

  line = malloc(sizeof(char)*MAX_COMMAND_LEN);
  int lineCount = 0;
  while (fgets(line, MAX_COMMAND_LEN, f) != NULL) {
    // Remove end-of-line comments.
    char *comment = strstr(line, "#");
    if (comment != NULL)
      *comment = '\0';

    lineCount += 1;
    int hasNextCmd = 1;
    char *tempLine = line;
  commandLoop:
    while (hasNextCmd) {
      num_args = 0;
      hasNextCmd = 0;
      int errCode = 0;

      // Parse {-} comments before command names.
      do {
        if ((cmd = strtok(tempLine, " \n")) == NULL)
          goto commandLoop;
        tempLine = NULL;
      } while ((errCode = parseComment(cmd, lineCount)) == 1);
      if (errCode < 0)
        return 1;

      while ((arg = strtok(NULL, " \n")) != NULL) {
        // Parse comment {-} within arguments.
        if ((errCode = parseComment(arg, lineCount)) != 0) {
          if (errCode < 0)
            return 1;
          continue;
        }

        // If we enter a new command, we remember the position for the next iteration.
        if (*arg == ';') {
          hasNextCmd = 1;
          break;
        }

        assert(num_args < MAX_COMMAND_ARGS);

        args[num_args] = atoi(arg);
        num_args++;
      }

      if (strcmp(cmd, "tap") == 0) {
        checkArguments(cmd, num_args, 4, lineCount);
        execute_tap(fd, device_flags, args[0], args[1], args[2], args[3]);
      } else if (strcmp(cmd, "drag") == 0) {
        checkArguments(cmd, num_args, 6, lineCount);
        execute_drag(fd, device_flags, args[0], args[1], args[2],
                     args[3], args[4], args[5]);
      } else if (strcmp(cmd, "sleep") == 0) {
        checkArguments(cmd, num_args, 1, lineCount);
        execute_sleep(args[0]);
      } else if (strcmp(cmd, "pinch") == 0) {
        checkArguments(cmd, num_args, 10, lineCount);
        execute_pinch(fd, device_flags, args[0], args[1], args[2],
                      args[3], args[4], args[5], args[6], args[7], args[8],
                      args[9]);
      } else if (strcmp(cmd, "keyup") == 0) {
        checkArguments(cmd, num_args, 1, lineCount);
        execute_keyup(fd, args[0]);
      } else if (strcmp(cmd, "keydown") == 0) {
        checkArguments(cmd, num_args, 1, lineCount);
        execute_keydown(fd, args[0]);
      } else if (strcmp(cmd, "reset") == 0) {
        checkArguments(cmd, num_args, 0, lineCount);
        execute_reset(fd, device_flags);
      } else {
        printf("Unrecognized command at line %d: '%s'\n", lineCount, cmd);
        return 1;
      }
    }
  }
  free(line);

  return 0;
}
Example #2
0
int _tmain(int argc, _TCHAR* argv[])
{
    int chan_num = 0;
    int pattern = 0;
    int length = 0;

    if ((argc >= 2) && (_stricmp(argv[1], "reset") == 0))
    {
        if (argc == 3)
        {
            return (execute_reset(argv[2]));
        }
        print_usage_reset(true);
        return 0;
    }
    else if ((argc >= 2) && (_stricmp(argv[1], "le_receiver_test") == 0))
    {
        if (argc == 4)
        {
            chan_num = atoi(argv[3]);
            if ((chan_num >= 0) && (chan_num <= 39))
            {
                return (execute_le_receiver_test(argv[2], chan_num));
            }
        }
        print_usage_le_receiver_test(true);
        return 0;
    }
    else if ((argc >= 2) && (_stricmp(argv[1], "le_test_end") == 0))
    {
        if (argc == 3)
        {
            return (execute_le_test_end(argv[2]));
        }
        print_usage_le_test_end(true);
        return 0;
    }
    else if ((argc >= 2) && (_stricmp(argv[1], "le_transmitter_test") == 0))
    {
        if (argc == 6)
        {
            chan_num = atoi(argv[3]);
            if ((chan_num >= 0) && (chan_num <= 39))
            {
                length = atoi(argv[4]);
                if ((length > 0) && (chan_num <= 255))
                {
                    pattern = atoi(argv[5]);
                    if ((pattern >= 0) && (pattern < 7))
                    {
                        return (execute_le_transmitter_test(argv[2], chan_num, length, pattern));
                    }
                }
            }
        }
        print_usage_le_transmitter_test(true);
        return 0;
    }
    else if ((argc >= 2) && (_stricmp(argv[1], "set_tx_frequency_arm") == 0))
    {
        if (argc >= 3)
        {
            UINT8 carrier_on = atoi(argv[3]);
            if ((carrier_on == 0) || (carrier_on == 1))
            {
                if (carrier_on == 0)
                {
                    return execute_set_tx_frequency_arm(argv[2], carrier_on, 2402, 0);
                }
                else if (argc == 6)
                {
                    int tx_frequency = atoi(argv[4]);
                    if ((tx_frequency >= 2402) && (chan_num <= 2480))
                    {
                        int tx_power = atoi(argv[5]);
                        if ((tx_power >= -25) && (tx_power <= 3))
                        {
                            return execute_set_tx_frequency_arm(argv[2], carrier_on, tx_frequency, tx_power);
                        }
                    }
                }
            }
        }
        print_usage_set_tx_frequency_arm(true);
        return 0;
    }
    else
    {
        printf("Usage: mbt help\n");
        print_usage_reset(false);
        print_usage_le_receiver_test(false);
        print_usage_le_transmitter_test(false);
        print_usage_le_test_end(false);
        print_usage_set_tx_frequency_arm(false);
        printf("Check Bluetooth Core 4.1 spec vol. 2 Sections 7.8.28-7.2.30\nfor details of LE Transmitter and Receiver tests");
    }
	return 0;
}