コード例 #1
0
ファイル: data.c プロジェクト: bristol-seds/pico-tracker
/**
 * Collects data synchronously and return datapoint
 */
struct tracker_datapoint* collect_data(void)
{
  /**
   * ---- Analogue ----
   */
  datapoint.battery = get_battery(); /* Will return zero by default */
  datapoint.solar = get_solar();     /* Will return zero by default */
  datapoint.radio_die_temperature = telemetry_si_temperature();
  datapoint.thermistor_temperature = thermistor_voltage_to_temperature(get_thermistor());

  /**
   * ---- Barometer ----
   */
  struct barometer* b = get_barometer();
  datapoint.main_pressure = b->pressure;
  datapoint.bmp180_temperature = (float)b->temperature;

  /**
   * ---- GPS ----
   */
  if (gps_update_position_pending() || (gps_get_error_state() != GPS_NOERROR)) {
    /* Error updating GPS position */

    /* TODO: Hit reset on the GPS? */
    /* In the meantime just wait for the watchdog */
    while (1);

  } else {                      /* GPS position updated correctly */

    /* GPS Status */
    struct ubx_nav_sol sol = gps_get_nav_sol();
    datapoint.satillite_count = sol.payload.numSV;

    /* GPS Position */
    if (gps_is_locked()) {
      struct ubx_nav_posllh pos = gps_get_nav_posllh();

      datapoint.latitude = pos.payload.lat;
      datapoint.longitude = pos.payload.lon;
      datapoint.altitude = pos.payload.height;
    }

    /* GPS Powersave */
    gps_set_powersave_auto();
  }

  return &datapoint;
}
コード例 #2
0
ファイル: main.c プロジェクト: richardeoin/buseds-hab
/**
 * Main system entry point
 */
int main (void) {
  SystemInit();

  /* Initialise Pins */
  CUTDOWN_OFF();
  HEATER_OFF();
  MBED_OFF();
  GREEN_OFF();

  /* Update the value of SystemCoreClock */
  SystemCoreClockUpdate();

  /* Initialise Interfaces */
  i2c_init();
  spi_init(process_imu_frame); // IMU
  sd_spi_init(); // SD
  uart_init(); // GPS
  pwrmon_init(); // ADC

  /* Initialise Sensors */
  init_barometer();

  /* SD Card */
  if (initialise_card()) { // Initialised to something
    if (disk_initialize() == 0) { // Disk initialisation was successful
      sd_good = 1;
    }
  }

  GREEN_ON();

  /* Configure the SysTick */
  NVIC_SetPriority(SysTick_IRQn, 0); // Highest Priority Interrupt
  SysTick_Config(SystemCoreClock / RTTY_BAUD);

  /* Watchdog - Disabled for debugging */
#ifndef WATCHDOG_DISABLED
  init_watchdog();
#endif

  struct barometer* b;
  struct imu_raw ir;
  struct gps_data gd;
  struct gps_time gt;
  double alt, ext_temp;
  int tx_length; // The length of the built tx string

  char tx_string[TX_STRING_LENGTH];

  while (1) {
    /* Grab Data */
    pwrmon_start(pwrmon_callback);
    b = get_barometer();
    get_imu_raw_data(&ir);
    get_gps_data(&gd);
    get_gps_time(&gt);
    ext_temp = get_temperature();

    /* Data Processing */
    if (b->valid) {
      alt = pressure_to_altitude(b->pressure);
    } else {
      alt = -1;
      b->temperature = -1;
    }

    /* Act on the data */
    control_gsm(alt);
    control_cutdown(ticks_until_cutdown, alt);
    control_heater(b->temperature);

    /* Create a protocol string */
    int cutstat;
    if (ticks_until_cutdown == 0) {
      cutstat = -1;
    } else {
      cutstat = ticks_until_cutdown / (RTTY_BAUD*60);
    }
    tx_length = build_communications_frame(tx_string, TX_STRING_LENGTH,
					   &gt, b, &gd, alt, ext_temp, &ir,
					   cutstat,  cutdown_voltage);

    /* Transmit - Quietly fails if another transmission is ongoing */
    rtty_set_string(tx_string, tx_length);

    /* Store */
    if (sd_good) {
      tx_length -= 2; // Remove \n\0
      tx_length += communications_frame_add_extra(tx_string + tx_length,
				     TX_STRING_LENGTH - tx_length, &ir);

      disk_write_next_block((uint8_t*)tx_string, tx_length+1); // Include null terminator
    }

    /* Housekeeping */
    GREEN_TOGGLE();
    feed_watchdog();
  }
}