Skip to content

Commit

Permalink
Use one timestamp for all the buffer data.
Browse files Browse the repository at this point in the history
Especially important for wifi Dexdrip where packets might be delayed by the receivers.

Signed-off-by: Tzachi Dar <[email protected]>

Conflicts:
	app/src/main/java/com/eveningoutpost/dexdrip/Services/DexCollectionService.java
  • Loading branch information
tzachi-dar committed Feb 17, 2015
1 parent a6db394 commit b0025e7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.eveningoutpost.dexdrip;

import java.util.Date;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
Expand Down Expand Up @@ -37,7 +39,7 @@ public void onClick(View v) {
EditText value = (EditText) findViewById(R.id.bg_value);
int intValue = Integer.parseInt(value.getText().toString());

BgReading bgReading = BgReading.create(intValue * 1000, getApplicationContext());
BgReading bgReading = BgReading.create(intValue * 1000, getApplicationContext(), new Date().getTime());
Intent intent = new Intent(getApplicationContext(), Home.class);
startActivity(intent);
finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static double activePrediction() {
}

//*******CLASS METHODS***********//
public static BgReading create(double raw_data, Context context) {
public static BgReading create(double raw_data, Context context, Long timestamp) {
BgReading bgReading = new BgReading();
Sensor sensor = Sensor.currentSensor();
if (sensor != null) {
Expand All @@ -164,7 +164,7 @@ public static BgReading create(double raw_data, Context context) {
bgReading.sensor = sensor;
bgReading.sensor_uuid = sensor.uuid;
bgReading.raw_data = (raw_data / 1000);
bgReading.timestamp = new Date().getTime();
bgReading.timestamp = timestamp;
bgReading.uuid = UUID.randomUUID().toString();
bgReading.time_since_sensor_started = bgReading.timestamp - sensor.started_at;
bgReading.synced = false;
Expand All @@ -181,7 +181,7 @@ public static BgReading create(double raw_data, Context context) {
bgReading.calibration = calibration;
bgReading.calibration_uuid = calibration.uuid;
bgReading.raw_data = (raw_data/1000);
bgReading.timestamp = new Date().getTime();
bgReading.timestamp = timestamp;
bgReading.uuid = UUID.randomUUID().toString();
bgReading.time_since_sensor_started = bgReading.timestamp - sensor.started_at;
bgReading.synced = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class TransmitterData extends Model {
@Column(name = "uuid", index = true)
public String uuid;

public static TransmitterData create(byte[] buffer, int len) {
public static TransmitterData create(byte[] buffer, int len, Long timestamp) {
StringBuilder data_string = new StringBuilder();
if (len < 6) { return null; };

Expand All @@ -45,7 +45,7 @@ public static TransmitterData create(byte[] buffer, int len) {

randomDelay(100, 2000);
TransmitterData lastTransmitterData = TransmitterData.last();
if (lastTransmitterData != null && lastTransmitterData.raw_data == Integer.parseInt(data[0]) && Math.abs(lastTransmitterData.timestamp - new Date().getTime()) < (10000)) { //Stop allowing duplicate data, its bad!
if (lastTransmitterData != null && lastTransmitterData.raw_data == Integer.parseInt(data[0]) && Math.abs(lastTransmitterData.timestamp - timestamp) < (10000)) { //Stop allowing duplicate data, its bad!
return null;
}

Expand All @@ -55,7 +55,7 @@ public static TransmitterData create(byte[] buffer, int len) {
}
if (Integer.parseInt(data[0]) < 1000) { return null; } // Sometimes the HM10 sends the battery level and readings in separate transmissions, filter out these incomplete packets!
transmitterData.raw_data = Integer.parseInt(data[0]);
transmitterData.timestamp = new Date().getTime();
transmitterData.timestamp = timestamp;
transmitterData.uuid = UUID.randomUUID().toString();

transmitterData.save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,15 @@ public void setCharacteristicNotification(BluetoothGattCharacteristic characteri
public void setSerialDataToTransmitterRawData(byte[] buffer, int len) {

Log.w(TAG, "received some data!");
TransmitterData transmitterData = TransmitterData.create(buffer, len);
Long timestamp = new Date().getTime();
TransmitterData transmitterData = TransmitterData.create(buffer, len, timestamp);
if (transmitterData != null) {
Sensor sensor = Sensor.currentSensor();
if (sensor != null) {
sensor.latest_battery_level = transmitterData.sensor_battery_level;
sensor.save();

BgReading bgReading = BgReading.create(transmitterData.raw_data, this);
BgReading bgReading = BgReading.create(transmitterData.raw_data, this, timestamp);
} else {
Log.w(TAG, "No Active Sensor, Data only stored in Transmitter Data");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public void setSerialDataToTransmitterRawData(int raw_data ,int sensor_battery_l
if (transmitterData != null) {
Sensor sensor = Sensor.currentSensor();
if (sensor != null) {
BgReading bgReading = BgReading.create(transmitterData.raw_data, mContext);
BgReading bgReading = BgReading.create(transmitterData.raw_data, mContext, CaptureTime);
sensor.latest_battery_level = transmitterData.sensor_battery_level;
sensor.save();
} else {
Expand Down

0 comments on commit b0025e7

Please sign in to comment.