Example #1
0
void
OZBoundary::GenerateArcExcluding(const GeoPoint &center, double radius,
                                 Angle start_radial, Angle end_radial)
{
  const unsigned steps = 20;
  const Angle delta = Angle::FullCircle() / steps;
  const Angle start = start_radial.AsBearing();
  Angle end = end_radial.AsBearing();
  if (end <= start + Angle::FullCircle() / 512)
    end += Angle::FullCircle();

  GeoVector vector(radius, start + delta);
  for (; vector.bearing < end; vector.bearing += delta)
    push_front(vector.EndPoint(center));
}
Example #2
0
void
PolygonRotateShift(RasterPoint *poly, const int n,
                   const PixelScalar xs, const PixelScalar ys,
                   Angle angle, const int scale)
{
  static Angle lastangle = Angle::Native(fixed(-1));
  static int cost = 1024, sint = 0;
  static int last_scale = 0;
  angle = angle.AsBearing();

  if ((angle != lastangle) || (last_scale != scale)) {
    lastangle = angle;
    last_scale = scale;
    if (scale == 100) {
      cost = FastScale(angle.ifastcosine());
      sint = FastScale(angle.ifastsine());
    } else {
      cost = FastScale(angle.ifastcosine() * scale) / 100;
      sint = FastScale(angle.ifastsine() * scale) / 100;
    }
  }

  RasterPoint *p = poly;
  const RasterPoint *pe = poly + n;

  while (p < pe) {
    int x = p->x;
    int y = p->y;
    p->x = roundshift(x * cost - y * sint) + xs;
    p->y = roundshift(y * cost + x * sint) + ys;
    p++;
  }
}
Example #3
0
void
DigitEntry::SetLongitude(Angle value)
{
  // TODO: support all CoordinateFormats

  value = value.AsBearing();

  assert(length == 9);
  assert(columns[0].type == Column::Type::EAST_WEST);
  assert(columns[1].type == Column::Type::DIGIT19);
  assert(columns[2].type == Column::Type::DIGIT);
  assert(columns[4].type == Column::Type::DIGIT6);
  assert(columns[5].type == Column::Type::DIGIT);
  assert(columns[7].type == Column::Type::DIGIT6);
  assert(columns[8].type == Column::Type::DIGIT);

  columns[0].value = negative(value.Native());

  const fixed degrees = fabs(value.Degrees());
  const unsigned i_degrees = std::min(unsigned(degrees), 180u);
  const unsigned full_seconds = unsigned(degrees * 3600u) % 3600u;
  const unsigned minutes = std::min(full_seconds / 60u, 59u);
  const unsigned seconds = full_seconds % 60u;

  columns[1].value = i_degrees / 10;
  columns[2].value = i_degrees % 10;

  columns[4].value = minutes / 10;
  columns[5].value = minutes % 10;

  columns[7].value = seconds / 10;
  columns[8].value = seconds % 10;

  Invalidate();
}
Example #4
0
/**
 * Converts a given bearing to the bearing part of the teamcode
 * @param bearing Bearing to the reference waypoint
 * @param code The teamcode (pointer)
 */
static void
ConvertBearingToTeamCode(const Angle bearing, TCHAR *code)
{
  const fixed bamValue = bearing.AsBearing().Degrees() / 360
                          * TEAMCODE_COMBINATIONS;
  NumberToTeamCode(bamValue, code, 2);
}
Example #5
0
void
FlarmTrafficControl::UpdateTaskDirection(bool show_task_direction, Angle bearing)
{
  if (!show_task_direction)
    task_direction = Angle::Degrees(-1);
  else
    task_direction = bearing.AsBearing();
}
Example #6
0
/**
 * Sets the TrackBearing to val
 *
 * not in use
 * @param val New TrackBearing
 */
void
DeviceBlackboard::SetTrack(Angle val)
{
  ScopeLock protect(mutex);
  simulator.Touch(simulator_data);
  simulator_data.track = val.AsBearing();

  ScheduleMerge();
}
Example #7
0
gcc_const
static unsigned
AngleToIndex(Angle a)
{
  fixed i = ROUTEPOLAR_POINTS * (fixed(1.25)
                                 - a.AsBearing().Radians() / fixed_two_pi);
  assert(positive(i));
  return uround(i) % ROUTEPOLAR_POINTS;
}
Example #8
0
/**
 * Sets the TrackBearing to val
 *
 * not in use
 * @param val New TrackBearing
 */
void
DeviceBlackboard::SetTrack(Angle val)
{
  std::lock_guard<Mutex> lock(mutex);
  simulator.Touch(simulator_data);
  simulator_data.track = val.AsBearing();

  ScheduleMerge();
}
Example #9
0
void
FastIntegerRotation::SetAngle(Angle _angle)
{
  _angle = _angle.AsBearing();
  if (_angle == angle)
    return;

  angle = _angle;
  cost = angle.ifastcosine();
  sint = angle.ifastsine();
}
Example #10
0
/**
 * This function creates some simulated traffic for FLARM debugging
 * @param GPS_INFO Pointer to the NMEA_INFO struct
 */
void
Simulator::GenerateFLARMTraffic(NMEAInfo &basic)
{
  static int i = 90;

  i++;
  if (i > 255)
    i = 0;

  if (i > 80)
    return;

  const Angle angle = Angle::Degrees(fixed((i * 360) / 255)).AsBearing();
  Angle dangle = (angle + Angle::Degrees(fixed(120))).AsBearing();
  Angle hangle = dangle.Flipped().AsBearing();

  int alt = (angle.ifastsine()) / 7;
  int north = (angle.ifastsine()) / 2 - 200;
  int east = (angle.ifastcosine()) / 1.5;
  int track = -(int)angle.AsBearing().Degrees();
  unsigned alarm_level = (i % 30 > 13 ? 0 : (i % 30 > 5 ? 2 : 1));

  NMEAParser parser(true);
  char buffer[50];

  // PFLAA,<AlarmLevel>,<RelativeNorth>,<RelativeEast>,<RelativeVertical>,
  //   <IDType>,<ID>,<Track>,<TurnRate>,<GroundSpeed>,<ClimbRate>,<AcftType>
  sprintf(buffer, "$PFLAA,%d,%d,%d,%d,2,DDA85C,%d,0,35,0,1",
          alarm_level, north, east, alt, track);
  parser.ParseLine(buffer, basic);

  alt = (angle.ifastcosine()) / 10;
  north = (dangle.ifastsine()) / 1.20 + 300;
  east = (dangle.ifastcosine()) + 500;
  track = (int)hangle.Degrees();

  // PFLAA,<AlarmLevel>,<RelativeNorth>,<RelativeEast>,<RelativeVertical>,
  //   <IDType>,<ID>,<Track>,<TurnRate>,<GroundSpeed>,<ClimbRate>,<AcftType>
  sprintf(buffer, "$PFLAA,0,%d,%d,%d,2,AA9146,,,,,1",
          north, east, alt);
  parser.ParseLine(buffer, basic);

  // PFLAU,<RX>,<TX>,<GPS>,<Power>,<AlarmLevel>,<RelativeBearing>,<AlarmType>,
  //   <RelativeVertical>,<RelativeDistance>(,<ID>)
  sprintf(buffer, "$PFLAU,2,1,2,1,%d", alarm_level);
  parser.ParseLine(buffer, basic);
}
Example #11
0
bool
LiveTrack24::SendPosition(SessionID session, unsigned packet_id,
                          GeoPoint position, unsigned altitude,
                          unsigned ground_speed, Angle track,
                          int64_t timestamp_utc)
{
  // http://www.livetrack24.com/track.php?leolive=4&sid=42664778&pid=321&
  //   lat=22.3&lon=40.2&alt=23&sog=40&cog=160&tm=1241422845

  StaticString<2048> url;
  url.Format(_T("http://%s/track.php?leolive=4&sid=%u&pid=%u&"
                "lat=%f&lon=%f&alt=%d&sog=%d&cog=%d&tm=%lld"),
             GetServer(), session, packet_id,
             (double)position.latitude.Degrees(),
             (double)position.longitude.Degrees(),
             altitude, ground_speed,
             (unsigned)track.AsBearing().Degrees(),
             (long long int)timestamp_utc);

  return SendRequest(url);
}
Example #12
0
bool
LiveTrack24::Client::SendPosition(GeoPoint position, unsigned altitude,
                          unsigned ground_speed, Angle track,
                          int64_t timestamp_utc,
                          OperationEnvironment &env)
{
  // http://www.livetrack24.com/track.php?leolive=4&sid=42664778&pid=321&
  //   lat=22.3&lon=40.2&alt=23&sog=40&cog=160&tm=1241422845

  NarrowString<2048> url;
  url.Format("http://%s/track.php?leolive=4&sid=%u&pid=%u&"
             "lat=%f&lon=%f&alt=%d&sog=%d&cog=%d&tm=%lld",
             (const char *)server, session_id, packet_id,
             (double)position.latitude.Degrees(),
             (double)position.longitude.Degrees(),
             altitude, ground_speed,
             (unsigned)track.AsBearing().Degrees(),
             (long long int)timestamp_utc);

  bool success = SendRequest(url, env);
  packet_id++;
  return success;
}
Example #13
0
void
WindStore::NewWind(const NMEAInfo &info, DerivedInfo &derived,
                   Vector &wind) const
{
  auto mag = wind.Magnitude();
  Angle bearing;

  if (wind.y == 0 && wind.x == 0)
    bearing = Angle::Zero();
  else
    bearing = Angle::FromXY(wind.x, wind.y);

  if (mag < 30) { // limit to reasonable values
    derived.estimated_wind = SpeedVector(bearing.AsBearing(), mag);
    derived.estimated_wind_available.Update(update_clock);
  } else {
    // TODO code: give warning, wind estimate bogus or very strong!
  }

  #ifdef DEBUG_WIND
  LogDebug(_T("%f %f 0 # wind estimate\n"), wind.x, wind.y);
  #endif

}
Example #14
0
void
WindStore::NewWind(const NMEAInfo &info, DerivedInfo &derived,
                   Vector &wind) const
{
  fixed mag = hypot(wind.x, wind.y);
  Angle bearing;

  if (wind.y == fixed_zero && wind.x == fixed_zero)
    bearing = Angle::Zero();
  else
    bearing = Angle::Radians(atan2(wind.y, wind.x));

  if (mag < fixed(30)) { // limit to reasonable values
    derived.estimated_wind = SpeedVector(bearing.AsBearing(), mag);
    derived.estimated_wind_available.Update(update_clock);
  } else {
    // TODO code: give warning, wind estimate bogus or very strong!
  }

  #ifdef DEBUG_WIND
  LogDebug(_T("%f %f 0 # wind estimate\n"), wind.x, wind.y);
  #endif

}
Example #15
0
void
FormatBearing(TCHAR *buffer, size_t size, Angle value, const TCHAR *suffix)
{
  FormatBearing(buffer, size, lround(value.AsBearing().Degrees()), suffix);
}
Example #16
0
 gcc_const
 static unsigned Import(Angle value) {
   return uround(value.AsBearing().Degrees()) % 360u;
 }
Example #17
0
 void SetDirection(Angle _direction) {
   direction = iround(_direction.AsBearing().Degrees());
 }