Android Open Source - android-weather-station Weather Logger






From Project

Back to project page android-weather-station.

License

The source code is released under:

Apache License

If you think the Android project android-weather-station listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.grundid.weather.sensor;
/*from   w w  w  .j a v a2  s .co  m*/
import de.grundid.weather.utils.Utils;
import android.util.Log;

public class WeatherLogger {

  private final byte PROT_STARTBYTE = 0x02;
  private final byte PROT_ENDBYTE = 0x03;
  private static final int BUFFER_SIZE = 8; // muss 8 sein
  private byte[] message = new byte[BUFFER_SIZE];
  private byte[] completeMsg = new byte[8];
  private int offset = 0;
  private SensorListener sensorListener;

  public WeatherLogger(SensorListener sensorListener) {
    this.sensorListener = sensorListener;
  }

  private void saveData(byte[] message) {
    try {
      Sensor sensor = SensorFactory.createSensor(message);
      sensorListener.onSensorData(sensor);
    }
    catch (Exception e) {
      Log.e("WEATHER", e.getMessage(), e);
    }
  }

  public void readData(byte[] buffer, int readData) {
    try {
      Log.d("WEATHER", "Data read: " + readData + " | " + Utils.bufferToString(buffer, readData));
      for (int x = 0; x < readData; x++) {
        message[offset] = buffer[x];
        if ((message[(offset + 1) % BUFFER_SIZE] == PROT_STARTBYTE) && (message[offset] == PROT_ENDBYTE)) {
          for (int i = 0; i < BUFFER_SIZE; i++) {
            completeMsg[i] = message[(offset + i + 1) % BUFFER_SIZE];
          }
          saveData(completeMsg);
          message[offset] = 0x00;
        }
        offset = ++offset % BUFFER_SIZE;
      }
    }
    catch (Exception e) {
      Log.e("WEATHER", e.getMessage(), e);
    }
  }
};




Java Source Code List

de.grundid.weather.Beeper.java
de.grundid.weather.Constants.java
de.grundid.weather.MainActivity.java
de.grundid.weather.SensorHandler.java
de.grundid.weather.SerialDataHandler.java
de.grundid.weather.io.AttachedDeviceHandler.java
de.grundid.weather.io.ConnectedUsbDevice.java
de.grundid.weather.io.PermissionBroadcastReceiver.java
de.grundid.weather.io.SerialReceiverListener.java
de.grundid.weather.io.SerialReceiver.java
de.grundid.weather.io.UsbConnectionException.java
de.grundid.weather.sensor.InsideSensor.java
de.grundid.weather.sensor.LightSensor.java
de.grundid.weather.sensor.OutsideSensor.java
de.grundid.weather.sensor.SensorFactory.java
de.grundid.weather.sensor.SensorListener.java
de.grundid.weather.sensor.Sensor.java
de.grundid.weather.sensor.WeatherLogger.java
de.grundid.weather.utils.Utils.java