Example #1
0
int
Xboxdrv::main(int argc, char** argv)
{
  try 
  {
    Options opts;

    CommandLineParser cmd_parser;
    cmd_parser.parse_args(argc, argv, &opts);

    set_scheduling(opts);

    switch(opts.mode)
    {
      case Options::PRINT_HELP_DEVICES:
        run_help_devices();
        break;

      case Options::RUN_LIST_SUPPORTED_DEVICES:
        run_list_supported_devices();
        break;

      case Options::RUN_LIST_SUPPORTED_DEVICES_XPAD:
        run_list_supported_devices_xpad();
        break;

      case Options::PRINT_VERSION:
        cmd_parser.print_version();
        break;

      case Options::PRINT_HELP:
        cmd_parser.print_help();
        break;

      case Options::PRINT_LED_HELP:
        cmd_parser.print_led_help();
        break;

      case Options::RUN_DEFAULT:
        run_main(opts);
        break;

      case Options::PRINT_ENUMS:
        run_list_enums(opts.list_enums);
        break;

      case Options::RUN_DAEMON:
        run_daemon(opts);
        break;

      case Options::RUN_LIST_CONTROLLER:
        run_list_controller();
        break;
    }
  }
  catch(const std::exception& err)
  {
    std::cout << "\n-- [ ERROR ] ------------------------------------------------------\n"
              << err.what() << std::endl;
  }

  return 0;
}
Example #2
0
File: sidc.c Project: sorki/sidc
int main( int argc, char *argv[])
{
   while( 1)
   {
      int c = getopt( argc, argv, "vfmic:p:");

      if( c == 'v') VFLAG++;
      else
      if( c == 'f') background = 0;
      else
      if( c == 'c') config_file = optarg;
      else
      if( c == 'p') pid_file = optarg;
      else
      if( c == -1) break;
      else bailout( "unknown option [%c]", c);
   }

   setup_signal_handling();
   load_config();

   if( CF_output_policy != OP_SPECTRUM)
   {
      int i;
      struct BAND *b;

      for( i=0, b=bands; i<nbands; i++, b++)
         report( 1, "band %s %d %d %s",
            b->ident, b->start, b->end, b->side->name);
   }

   if( background && !logfile)
      report( -1, "warning: no logfile specified for daemon");

   if( background) make_daemon();

   setup_input_stream();

   DF = (double) CF_sample_rate/(double) FFTWID;
   report( 1, "resolution: bins=%d fftwid=%d df=%f", CF_bins, FFTWID, DF);

   if( CF_uspec_file)
   {
      // Convert CF_uspec_secs seconds to uspec_max frames
      uspec_max = rint( CF_uspec_secs * CF_sample_rate / FFTWID);
      report( 2, "utility spectrum interval: %d frames", uspec_max);
      report( 2, "utility spectrum file: %s", CF_uspec_file); 
   }

   // Convert CF_output_interval seconds to output_int frames
   output_int = rint( CF_output_interval * CF_sample_rate / FFTWID);
   if( output_int == 0) output_int = 1;
   report( 2, "output interval: %d frames", output_int);

   if( CF_output_policy == OP_SPECTRUM)
   {
      // Convert range variables Hertz to bins
      cuton = CF_range1 / DF;
      cutoff = CF_range2 / DF;
      report( 2, "output bins: %d to %d", cuton, cutoff);
   }   

   // Both sets of channel data structures are initialised, even if mono
   initialise_channel( &left);
   initialise_channel( &right);

   setup_hamming_window();

   if( CF_card_delay) sleep( CF_card_delay);
   report( 0, "sidc version %s %s: starting work",
      PACKAGE_VERSION, soundsystem);
   alert_on = 1;
   if( CF_priority) set_scheduling();   // Setup real time scheduling

   process_signal();

   if( CF_output_policy != OP_SPECTRUM)
   {
      int i;
      struct BAND *b;

      for( i=0, b=bands; i<nbands; i++, b++)
         free( b->ident);
   }
   if( CF_uspec_file)
      free( CF_uspec_file);
   if( CF_mailaddr)
      free( CF_mailaddr);
   if( out_prefix)
      free( out_prefix);
   return 0;
}
Example #3
0
int main(int argc, char** args)
{
    set_scheduling();
    sqlite3_stmt *main_stmt;
    
    if(sqlite3_open_v2("gtfs.db", &handle, SQLITE_OPEN_READONLY, 0))
    {
        printf("Database connection failed\n");
        return -1;
    }

    // Calculate date offsets
    time_t now_time_t = time(NULL);
    char date[9];
    struct tm* now_tm;
    now_tm = localtime(&now_time_t);
    strftime(date, 100, "%Y%m%d", now_tm);

    now_tm->tm_hour = 12;
    now_tm->tm_min = 0;
    now_tm->tm_sec = 0;

    int64_t seconds_into_day = now_time_t - (mktime(now_tm) - 12*60*60);

    if(sqlite3_prepare_v2(handle, 
        // TODO: Handle midnight switchover appropriately.
        "select trips.trip_id, trips.shape_id, first_stop.departure_time, second_stop.departure_time, first_stop.shape_dist_traveled, second_stop.shape_dist_traveled "
        "from stop_times first_stop "
        "join stop_times second_stop on ( "
          "first_stop.stop_sequence+1=second_stop.stop_sequence "
          "and first_stop.trip_id = second_stop.trip_id "
        ") "
        "join trips on trips.trip_id = first_stop.trip_id "
        "join stops first_stop_info on first_stop_info.stop_id = first_stop.stop_id "
        "join stops second_stop_info on second_stop_info.stop_id = second_stop.stop_id "
        "where trips.service_id in (select service_id from calendar_dates where date=?1) "
        "and first_stop.departure_time <= ?2  "
        "and second_stop.departure_time > ?2 "
        ,-1, &main_stmt, NULL)) {
        printf("%s", "Error preparing main SQL statement.");
        exit(1);
    }

    #if DEBUG
    printf("Date is %s, time is %" PRId64 ".\n", date, seconds_into_day);
    #endif

    sqlite3_bind_text(main_stmt, 1, date, -1, SQLITE_STATIC);
    sqlite3_bind_int(main_stmt, 2, seconds_into_day);

    printf("{\"locs\": [");
    fflush(stdout);
    char delim = ' ';
    double lat, lon, dist_traveled, fraction_complete, second_dist_traveled, first_dist_traveled;
    int64_t shape_id, first_dept_time, second_dept_time;
    const char *from, *to, *trip;

    #if DEBUG
    int n = 0;
    #endif
    while(SQLITE_ROW == sqlite3_step(main_stmt)) {
        #if DEBUG
        n++;
        if (n > 5) break;
        #endif

        putchar(delim);
        delim = ',';

        first_dept_time = sqlite3_column_int64(main_stmt, 2);
        second_dept_time = sqlite3_column_int64(main_stmt, 3);
        first_dist_traveled = sqlite3_column_double(main_stmt, 4);
        second_dist_traveled = sqlite3_column_double(main_stmt, 5);
        shape_id = sqlite3_column_int64(main_stmt, 1);
        
        fraction_complete = (seconds_into_day - first_dept_time) * 1.0 / (second_dept_time - first_dept_time);
        dist_traveled = fraction_complete * (second_dist_traveled - first_dist_traveled) + first_dist_traveled;

        printf("%s", "{\"trip_id\":");
        printf("%" PRId64, (int64_t) sqlite3_column_int64(main_stmt, 0));

        #if DEBUG
        printf(",\"dist_traveled\":%f,\"fraction_complete\":%f", dist_traveled, fraction_complete);
        #endif

        // Calculate here so we get some debugging info if this call fails.
        calc_lat_lon(shape_id, dist_traveled, &lat, &lon);

        #if DEBUG
        printf(",\"lat\":%f,\"lon\":%f}\n", lat, lon);
        #else
        printf(",\"lat\":%f,\"lon\":%f}", lat, lon);
        #endif
    }
    puts("]}");

    
    // Close the handle to free memory
    sqlite3_finalize(main_stmt);
    sqlite3_close(handle);
    return 0;
}