host/btle-tools/src/btle_rx.c
//----------------------------------command line parameters----------------------------------
// Parse the command line arguments and return optional parameters as
// variables.
// Also performs some basic sanity checks on the parameters.
command line parameters
Parse the command line arguments and return optional parameters as
variables.
Also performs some basic sanity checks on the parameters.
command line parameters Parse the command line arguments and return optional parameters as variables . Also performs some basic sanity checks on the parameters .
void parse_commandline(
  int argc,
  char * const argv[],
  int* chan,
  int* gain,
  int* lnaGain,
  uint8_t* amp,
  uint32_t* access_addr,
  uint32_t* crc_init,
  int* verbose_flag,
  int* raw_flag,
  uint64_t* freq_hz, 
  uint32_t* access_mask, 
  int* hop_flag,
  char** filename_pcap
) {
  printf("BLE sniffer. Xianjun Jiao. putaoshu@msn.com\n\n");
  (*chan) = DEFAULT_CHANNEL;
  (*gain) = DEFAULT_GAIN;
  (*lnaGain) = 32;
  (*amp) = 0;
  (*access_addr) = DEFAULT_ACCESS_ADDR;
  (*crc_init) = 0x555555;
  (*verbose_flag) = 0;
  (*raw_flag) = 0;
  (*freq_hz) = 123;
  (*access_mask) = 0xFFFFFFFF;
  (*hop_flag) = 0;
  (*filename_pcap) = 0;
  while (1) {
    static struct option long_options[] = {
      {"help",         no_argument,       0, 'h'},
      {"chan",   required_argument, 0, 'c'},
      {"gain",         required_argument, 0, 'g'},
      {"lnaGain",         required_argument, 0, 'l'},
      {"amp",         no_argument, 0, 'b'},
      {"access",         required_argument, 0, 'a'},
      {"crcinit",           required_argument, 0, 'k'},
      {"verbose",         no_argument, 0, 'v'},
      {"raw",         no_argument, 0, 'r'},
      {"freq_hz",           required_argument, 0, 'f'},
      {"access_mask",         required_argument, 0, 'm'},
      {"hop",         no_argument, 0, 'o'},
      {"filename",         required_argument, 0, 's'},
      {0, 0, 0, 0}
    };
    int option_index = 0;
    int c = getopt_long (argc, argv, "hc:g:l:ba:k:vrf:m:os:",
                     long_options, &option_index);
    if (c == -1)
      break;
    switch (c) {
      char * endp;
      case 0:
        printf("Check code!\n");
        goto abnormal_quit;
        break;
      case 'v':
        (*verbose_flag) = 1;
        break;
      case 'r':
        (*raw_flag) = 1;
        break;
      case 'o':
        (*hop_flag) = 1;
        break;
      case 'h':
        goto abnormal_quit;
        break;
      case 'c':
        (*chan) = strtol(optarg,&endp,10);
        break;
      case 'g':
        (*gain) = strtol(optarg,&endp,10);
        break;
      case 'l':
        (*lnaGain) = strtol(optarg,&endp,10);
        break;
      case 'b':
        (*amp) = 1;
        break;
      case 'f':
        (*freq_hz) = strtol(optarg,&endp,10);
        break;
      case 'a':
        (*access_addr) = strtol(optarg,&endp,16);
        break;
      case 'm':
        (*access_mask) = strtol(optarg,&endp,16);
        break;
      case 'k':
        (*crc_init) = strtol(optarg,&endp,16);
        break;
      case 's':
        (*filename_pcap) = (char*)optarg;
        break;
      case '?':
        goto abnormal_quit;
      default:
        goto abnormal_quit;
    }
  }
  if ( (*chan)<0 || (*chan)>MAX_CHANNEL_NUMBER ) {
    printf("channel number must be within 0~%d!\n", MAX_CHANNEL_NUMBER);
    goto abnormal_quit;
  }
  if ( (*gain)<0 || (*gain)>MAX_GAIN ) {
    printf("rx gain must be within 0~%d!\n", MAX_GAIN);
    goto abnormal_quit;
  }
if ( (*lnaGain)<0 || (*lnaGain)>40 ) {
    printf("lna gain must be within 0~%d!\n", 40);
    goto abnormal_quit;
  }
  if (optind < argc) {
    printf("Error: unknown/extra arguments specified on command line!\n");
    goto abnormal_quit;
  }
  return;
abnormal_quit:
  print_usage();
  exit(-1);
}
void parse_commandline ( int argc , char * const argv [ ] , int * chan , int * gain , int * lnaGain , uint8_t * amp , uint32_t * access_addr , uint32_t * crc_init , int * verbose_flag , int * raw_flag , uint64_t * freq_hz , uint32_t * access_mask , int * hop_flag , char * * filename_pcap ) { printf ( " \n \n " ) ; ( * chan ) = DEFAULT_CHANNEL ; ( * gain ) = DEFAULT_GAIN ; ( * lnaGain ) = 32 ; ( * amp ) = 0 ; ( * access_addr ) = DEFAULT_ACCESS_ADDR ; ( * crc_init ) = 0x555555 ; ( * verbose_flag ) = 0 ; ( * raw_flag ) = 0 ; ( * freq_hz ) = 123 ; ( * access_mask ) = 0xFFFFFFFF ; ( * hop_flag ) = 0 ; ( * filename_pcap ) = 0 ; while ( 1 ) { static struct option long_options [ ] = { { " " , no_argument , 0 , ' ' } , { " " , required_argument , 0 , ' ' } , { " " , required_argument , 0 , ' ' } , { " " , required_argument , 0 , ' ' } , { " " , no_argument , 0 , ' ' } , { " " , required_argument , 0 , ' ' } , { " " , required_argument , 0 , ' ' } , { " " , no_argument , 0 , ' ' } , { " " , no_argument , 0 , ' ' } , { " " , required_argument , 0 , ' ' } , { " " , required_argument , 0 , ' ' } , { " " , no_argument , 0 , ' ' } , { " " , required_argument , 0 , ' ' } , { 0 , 0 , 0 , 0 } } ; int option_index = 0 ; int c = getopt_long ( argc , argv , " " , long_options , & option_index ) ; if ( c == -1 ) break ; switch ( c ) { char * endp ; case 0 : printf ( " \n " ) ; goto abnormal_quit ; break ; case ' ' : ( * verbose_flag ) = 1 ; break ; case ' ' : ( * raw_flag ) = 1 ; break ; case ' ' : ( * hop_flag ) = 1 ; break ; case ' ' : goto abnormal_quit ; break ; case ' ' : ( * chan ) = strtol ( optarg , & endp , 10 ) ; break ; case ' ' : ( * gain ) = strtol ( optarg , & endp , 10 ) ; break ; case ' ' : ( * lnaGain ) = strtol ( optarg , & endp , 10 ) ; break ; case ' ' : ( * amp ) = 1 ; break ; case ' ' : ( * freq_hz ) = strtol ( optarg , & endp , 10 ) ; break ; case ' ' : ( * access_addr ) = strtol ( optarg , & endp , 16 ) ; break ; case ' ' : ( * access_mask ) = strtol ( optarg , & endp , 16 ) ; break ; case ' ' : ( * crc_init ) = strtol ( optarg , & endp , 16 ) ; break ; case ' ' : ( * filename_pcap ) = ( char * ) optarg ; break ; case ' ' : goto abnormal_quit ; default : goto abnormal_quit ; } } if ( ( * chan ) < 0 || ( * chan ) > MAX_CHANNEL_NUMBER ) { printf ( " \n " , MAX_CHANNEL_NUMBER ) ; goto abnormal_quit ; } if ( ( * gain ) < 0 || ( * gain ) > MAX_GAIN ) { printf ( " \n " , MAX_GAIN ) ; goto abnormal_quit ; } if ( ( * lnaGain ) < 0 || ( * lnaGain ) > 40 ) { printf ( " \n " , 40 ) ; goto abnormal_quit ; } if ( optind < argc ) { printf ( " \n " ) ; goto abnormal_quit ; } return ; abnormal_quit : print_usage ( ) ; exit ( -1 ) ; }
command line parameters
Parse the command line arguments and return optional parameters as
variables.
command line parameters Parse the command line arguments and return optional parameters as variables .
// Inputs // Outputs // Default values /* getopt_long stores the option index here. */ /* Detect the end of the options. */ // Code should only get here if a long option was given a non-null // flag value. /* getopt_long already printed an error message. */ // Error if extra arguments are found on the command line