Пример #1
0
void gps_mtk_read_message(void) {
  if (gps_mtk.msg_class == MTK_DIY14_ID) {
    if (gps_mtk.msg_id == MTK_DIY14_NAV_ID) {
#ifdef GPS_TIMESTAMP
      /* get hardware clock ticks */
      SysTimeTimerStart(gps.t0);
      gps.t0_tow      = MTK_DIY14_NAV_ITOW(gps_mtk.msg_buf);
      gps.t0_tow_frac = 0;
#endif
      gps.lla_pos.lat = RadOfDeg(MTK_DIY14_NAV_LAT(gps_mtk.msg_buf))*10;
      gps.lla_pos.lon = RadOfDeg(MTK_DIY14_NAV_LON(gps_mtk.msg_buf))*10;
      // FIXME: with MTK you do not receive vertical speed
      if (cpu_time_sec - gps.last_fix_time < 2) {
        gps.ned_vel.z  = ((gps.hmsl -
            MTK_DIY14_NAV_HEIGHT(gps_mtk.msg_buf)*10)*OUTPUT_RATE)/10;
      } else gps.ned_vel.z = 0;
      gps.hmsl        = MTK_DIY14_NAV_HEIGHT(gps_mtk.msg_buf)*10;
      // FIXME: with MTK you do not receive ellipsoid altitude
      gps.lla_pos.alt = gps.hmsl;
      gps.gspeed      = MTK_DIY14_NAV_GSpeed(gps_mtk.msg_buf);
      // FIXME: with MTK you do not receive speed 3D
      gps.speed_3d    = gps.gspeed;
      gps.course      = (RadOfDeg(MTK_DIY14_NAV_Heading(gps_mtk.msg_buf)))*10;
      gps.num_sv      = MTK_DIY14_NAV_numSV(gps_mtk.msg_buf);
      switch (MTK_DIY14_NAV_GPSfix(gps_mtk.msg_buf)) {
      case MTK_DIY_FIX_3D:
        gps.fix = GPS_FIX_3D;
        break;
      case MTK_DIY_FIX_2D:
        gps.fix = GPS_FIX_2D;
        break;
      default:
        gps.fix = GPS_FIX_NONE;
      }
      gps.tow         = MTK_DIY14_NAV_ITOW(gps_mtk.msg_buf);;
      // FIXME: with MTK DIY 1.4 you do not receive GPS week
      gps.week        = 0;
      /* Computes from (lat, long) in the referenced UTM zone */
      struct LlaCoor_f lla_f;
      lla_f.lat = ((float) gps.lla_pos.lat) / 1e7;
      lla_f.lon = ((float) gps.lla_pos.lon) / 1e7;
      struct UtmCoor_f utm_f;
      utm_f.zone = nav_utm_zone0;
      /* convert to utm */
      utm_of_lla_f(&utm_f, &lla_f);
      /* copy results of utm conversion */
      gps.utm_pos.east = utm_f.east*100;
      gps.utm_pos.north = utm_f.north*100;
      gps.utm_pos.alt = utm_f.alt*1000;
      gps.utm_pos.zone = nav_utm_zone0;
#ifdef GPS_LED
      if (gps.fix == GPS_FIX_3D) {
        LED_ON(GPS_LED);
      }
      else {
        LED_TOGGLE(GPS_LED);
      }
#endif
    }
  }

  if (gps_mtk.msg_class == MTK_DIY16_ID) {
    if (gps_mtk.msg_id == MTK_DIY16_NAV_ID) {
      uint32_t gps_date, gps_time;
      gps_date = MTK_DIY16_NAV_UTC_DATE(gps_mtk.msg_buf);
      gps_time = MTK_DIY16_NAV_UTC_TIME(gps_mtk.msg_buf);
      gps_mtk_time2itow(gps_date, gps_time, &gps.week, &gps.tow);
#ifdef GPS_TIMESTAMP
      /* get hardware clock ticks */
      SysTimeTimerStart(gps.t0);
      gps.t0_tow      = gps.tow;
      gps.t0_tow_frac = 0;
#endif
      gps.lla_pos.lat = RadOfDeg(MTK_DIY16_NAV_LAT(gps_mtk.msg_buf))*10;
      gps.lla_pos.lon = RadOfDeg(MTK_DIY16_NAV_LON(gps_mtk.msg_buf))*10;
      // FIXME: with MTK you do not receive vertical speed
      if (cpu_time_sec - gps.last_fix_time < 2) {
        gps.ned_vel.z  = ((gps.hmsl -
            MTK_DIY16_NAV_HEIGHT(gps_mtk.msg_buf)*10)*OUTPUT_RATE)/10;
      } else gps.ned_vel.z = 0;
      gps.hmsl        = MTK_DIY16_NAV_HEIGHT(gps_mtk.msg_buf)*10;
      // FIXME: with MTK you do not receive ellipsoid altitude
      gps.lla_pos.alt = gps.hmsl;
      gps.gspeed      = MTK_DIY16_NAV_GSpeed(gps_mtk.msg_buf);
      // FIXME: with MTK you do not receive speed 3D
      gps.speed_3d    = gps.gspeed;
      gps.course      = (RadOfDeg(MTK_DIY16_NAV_Heading(gps_mtk.msg_buf)*10000)) * 10;
      gps.num_sv      = MTK_DIY16_NAV_numSV(gps_mtk.msg_buf);
      switch (MTK_DIY16_NAV_GPSfix(gps_mtk.msg_buf)) {
      case MTK_DIY_FIX_3D:
        gps.fix = GPS_FIX_3D;
        break;
      case MTK_DIY_FIX_2D:
        gps.fix = GPS_FIX_2D;
        break;
      default:
        gps.fix = GPS_FIX_NONE;
      }
      /* HDOP? */
      /* Computes from (lat, long) in the referenced UTM zone */
      struct LlaCoor_f lla_f;
      lla_f.lat = ((float) gps.lla_pos.lat) / 1e7;
      lla_f.lon = ((float) gps.lla_pos.lon) / 1e7;
      struct UtmCoor_f utm_f;
      utm_f.zone = nav_utm_zone0;
      /* convert to utm */
      utm_of_lla_f(&utm_f, &lla_f);
      /* copy results of utm conversion */
      gps.utm_pos.east = utm_f.east*100;
      gps.utm_pos.north = utm_f.north*100;
      gps.utm_pos.alt = utm_f.alt*1000;
      gps.utm_pos.zone = nav_utm_zone0;
#ifdef GPS_LED
      if (gps.fix == GPS_FIX_3D) {
        LED_ON(GPS_LED);
      }
      else {
        LED_TOGGLE(GPS_LED);
      }
#endif
    }
  }
}
Пример #2
0
void gps_mtk_read_message(void)
{
  if (gps_mtk.msg_class == MTK_DIY14_ID) {
    if (gps_mtk.msg_id == MTK_DIY14_NAV_ID) {
      /* get hardware clock ticks */
      gps_time_sync.t0_ticks      = sys_time.nb_tick;
      gps_time_sync.t0_tow      = MTK_DIY14_NAV_ITOW(gps_mtk.msg_buf);
      gps_time_sync.t0_tow_frac = 0;
      gps.lla_pos.lat = MTK_DIY14_NAV_LAT(gps_mtk.msg_buf) * 10;
      gps.lla_pos.lon = MTK_DIY14_NAV_LON(gps_mtk.msg_buf) * 10;
      SetBit(gps.valid_fields, GPS_VALID_POS_LLA_BIT);
      // FIXME: with MTK you do not receive vertical speed
      if (sys_time.nb_sec - gps.last_3dfix_time < 2) {
        gps.ned_vel.z  = ((gps.hmsl -
                           MTK_DIY14_NAV_HEIGHT(gps_mtk.msg_buf) * 10) * OUTPUT_RATE) / 10;
      } else { gps.ned_vel.z = 0; }
      gps.hmsl        = MTK_DIY14_NAV_HEIGHT(gps_mtk.msg_buf) * 10;
      SetBit(gps.valid_fields, GPS_VALID_HMSL_BIT);
      // FIXME: with MTK you do not receive ellipsoid altitude
      gps.lla_pos.alt = gps.hmsl;
      gps.gspeed      = MTK_DIY14_NAV_GSpeed(gps_mtk.msg_buf);
      // FIXME: with MTK you do not receive speed 3D
      gps.speed_3d    = gps.gspeed;
      gps.course      = (RadOfDeg(MTK_DIY14_NAV_Heading(gps_mtk.msg_buf))) * 10;
      SetBit(gps.valid_fields, GPS_VALID_COURSE_BIT);
      gps.num_sv      = MTK_DIY14_NAV_numSV(gps_mtk.msg_buf);
      switch (MTK_DIY14_NAV_GPSfix(gps_mtk.msg_buf)) {
        case MTK_DIY_FIX_3D:
          gps.fix = GPS_FIX_3D;
          break;
        case MTK_DIY_FIX_2D:
          gps.fix = GPS_FIX_2D;
          break;
        default:
          gps.fix = GPS_FIX_NONE;
      }
      gps.tow         = MTK_DIY14_NAV_ITOW(gps_mtk.msg_buf);;
      // FIXME: with MTK DIY 1.4 you do not receive GPS week
      gps.week        = 0;
#ifdef GPS_LED
      if (gps.fix == GPS_FIX_3D) {
        LED_ON(GPS_LED);
      } else {
        LED_TOGGLE(GPS_LED);
      }
#endif
    }
  }

  if (gps_mtk.msg_class == MTK_DIY16_ID) {
    if (gps_mtk.msg_id == MTK_DIY16_NAV_ID) {
      uint32_t gps_date, gps_time;
      gps_date = MTK_DIY16_NAV_UTC_DATE(gps_mtk.msg_buf);
      gps_time = MTK_DIY16_NAV_UTC_TIME(gps_mtk.msg_buf);
      gps_mtk_time2itow(gps_date, gps_time, &gps.week, &gps.tow);
#ifdef GPS_TIMESTAMP
      /* get hardware clock ticks */
      SysTimeTimerStart(gps.t0);
      gps.t0_tow      = gps.tow;
      gps.t0_tow_frac = 0;
#endif
      gps.lla_pos.lat = MTK_DIY16_NAV_LAT(gps_mtk.msg_buf) * 10;
      gps.lla_pos.lon = MTK_DIY16_NAV_LON(gps_mtk.msg_buf) * 10;
      // FIXME: with MTK you do not receive vertical speed
      if (sys_time.nb_sec - gps.last_3dfix_time < 2) {
        gps.ned_vel.z  = ((gps.hmsl -
                           MTK_DIY16_NAV_HEIGHT(gps_mtk.msg_buf) * 10) * OUTPUT_RATE) / 10;
      } else { gps.ned_vel.z = 0; }
      gps.hmsl        = MTK_DIY16_NAV_HEIGHT(gps_mtk.msg_buf) * 10;
      SetBit(gps.valid_fields, GPS_VALID_HMSL_BIT);
      // FIXME: with MTK you do not receive ellipsoid altitude
      gps.lla_pos.alt = gps.hmsl;
      gps.gspeed      = MTK_DIY16_NAV_GSpeed(gps_mtk.msg_buf);
      // FIXME: with MTK you do not receive speed 3D
      gps.speed_3d    = gps.gspeed;
      gps.course      = (RadOfDeg(MTK_DIY16_NAV_Heading(gps_mtk.msg_buf) * 10000)) * 10;
      SetBit(gps.valid_fields, GPS_VALID_COURSE_BIT);
      gps.num_sv      = MTK_DIY16_NAV_numSV(gps_mtk.msg_buf);
      switch (MTK_DIY16_NAV_GPSfix(gps_mtk.msg_buf)) {
        case MTK_DIY_FIX_3D:
          gps.fix = GPS_FIX_3D;
          break;
        case MTK_DIY_FIX_2D:
          gps.fix = GPS_FIX_2D;
          break;
        default:
          gps.fix = GPS_FIX_NONE;
      }
      /* HDOP? */
#ifdef GPS_LED
      if (gps.fix == GPS_FIX_3D) {
        LED_ON(GPS_LED);
      } else {
        LED_TOGGLE(GPS_LED);
      }
#endif
    }
  }
}