Beispiel #1
0
 public void onMesg(Mesg mesg) {
   if (!bRecvdFirstMesg && !mesg.getName().equals("file_id"))
     szError = "FileID missing from start of file";
   bRecvdFirstMesg = true;
 }
Beispiel #2
0
  @Override
  public void onMesg(Mesg mesg) {
    if ((mesg != null) && ("lap".equals(mesg.getName()))) {
      // System.out.println("got here");
    } else if ((mesg != null) && ("record".equals(mesg.getName()))) {
      Telemetry point = new Telemetry();

      // Search relevant info
      Collection<Field> fields = mesg.getFields();

      for (Field f : fields) {
        f.getName();
      }

      Field time = getField("timestamp", fields);

      Field cadence = getField("cadence", fields);
      if (cadence != null) {
        point.setCadence(cadence.getByteValue());
      }

      Field hr = getField("heart_rate", fields);
      if (hr != null) {
        point.setHeartRate(hr.getIntegerValue());
      }

      Field posLat = getField("position_lat", fields);
      Field posLon = getField("position_long", fields);

      // Convert semicircles latitude to decimals
      if (posLat != null) {
        BigDecimal posLatDec = semicircleToDms(posLat);
        point.setLatitude(posLatDec.doubleValue());
      }
      if (posLon != null) {
        BigDecimal posLonDec = semicircleToDms(posLon);
        point.setLongitude(posLonDec.doubleValue());
      }

      Field elevation = getField("altitude", fields);
      if (elevation != null) {
        point.setElevation(elevation.getDoubleValue());
      }

      Field distance = getField("distance", fields);
      if (distance != null) {
        point.setDistance(distance.getDoubleValue());
      }

      if (time != null) {
        point.setTime(time.getLongValue() * 1000 + OFFSET);
      }

      Field speed = getField("speed", fields);
      if (speed != null) {
        point.setSpeed(speed.getDoubleValue() * 3.6);
      }

      // use power from file
      Field power = getField("power", fields);
      if (power != null) {

        point.setPower(power.getShortValue());
        if (point.getPower() > 0) {
          isPower = true; // contains power values
        }
      }

      if (last != null) {
        if (distance == null) {
          if (posLat == null || posLon == null) {
            // no latitude or longitude, drop
            // point
            return;
          }
          // calculate distance from GPS points
          double d =
              GPXReader.distance(
                  point.getLatitude(),
                  last.getLatitude(),
                  point.getLongitude(),
                  last.getLongitude(),
                  point.getElevation(),
                  last.getElevation());

          if (d > 1000) {
            // large value, drop.
            return;
          }
          totalDistance += d;
          point.setDistance(totalDistance);

        } else if (point.getDistance() == last.getDistance()) {
          // no change to distance, drop point
          return;
        }

        if (speed == null) {
          // calculate speed, s = d / t
          // double speed = d * 3600
          // / ((point.getTime() - adjust) - last.getTime());
        }

        double gradient =
            (point.getElevation() - last.getElevation())
                / (point.getDistance() - last.getDistance());

        point.setGradient(gAve.add(gradient));
      } else {
        // first time through
        point.setResistance(WorkoutData.FIT);
      }
      last = point;
      data.add(point);
    }
  }