コード例 #1
0
  private void saveData(TelemetryData data) {
    PrintWriter out;
    boolean newFile = false;

    if (saveCnt > 25000) {
      File logFile;
      int i;

      logFile = new File(telemetryDir + 99 + ".log");
      logFile.delete();
      newFile = true;

      for (i = 99; i > 0; i--) {
        logFile = new File(telemetryDir + (i - 1) + ".log");
        logFile.renameTo(new File(telemetryDir + i + ".log"));
      }
      saveCnt = 0;
    }

    try {
      String text = "";
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMAN);

      saveCnt++;
      out = new PrintWriter(new FileOutputStream(telemetryDir + "0.log", true));
      if (newFile) {
        text =
            "Time\tLatitude\tLongitude\tSpeed\tAcceleration X\tAcceleration Y\tAcceleration Z\tCoG\tOrientation Y\tOrientation Z\n\n";
        out.print(text);
      }
      text = dateFormat.format(new Date(System.currentTimeMillis())) + "\t";
      if (posValid) text = text + lastLat + "\t" + lastLon + "\t" + m_lastSpeed + "\t";
      else text = text + "-\t-\t-\t";
      text =
          text
              + data.getAccelX()
              + "\t"
              + data.getAccelY()
              + "\t"
              + data.getAccelZ()
              + "\t"
              + data.CoG
              + "\t"
              + data.getOrientY()
              + "\t"
              + data.getOrientZ()
              + "\n\n";
      out.print(text);
      out.close();
    } catch (IOException ioe) {
    }
  }
コード例 #2
0
  public void onSensorChanged(SensorEvent event) {
    synchronized (this) {
      switch (event.sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
          scanData.getTelemetryData().addAccel(event.values[0], event.values[1], event.values[2]);
          break;
        case Sensor.TYPE_ORIENTATION:
          scanData.getTelemetryData().addOrient(event.values[0], event.values[1], event.values[2]);
          break;
      }
      if (lastTelemetryTime == 0) lastTelemetryTime = System.currentTimeMillis();
      else if (System.currentTimeMillis() - lastTelemetryTime > 750) {
        TelemetryData submitData = new TelemetryData();

        submitData.set(scanData.getTelemetryData());
        if (scanData.isStoreTele()) saveData(submitData);
        scanData.getTelemetryData().reset();
        OWMapAtAndroid.sendMessage(OWMapAtAndroid.ScannerHandler.MSG_TELEMETRY, 0, 0, submitData);
        lastTelemetryTime = System.currentTimeMillis();
      }
    }
  }