Skip to content

Commit

Permalink
Rename GPS location property, add 0,0 check for lat/lon
Browse files Browse the repository at this point in the history
  • Loading branch information
bertrik committed Apr 21, 2024
1 parent e832915 commit 9d56167
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ SensorData decodeTtnMessage(DecoderConfig config, TtnUplinkMessage uplink) throw
}
if (cayenne.hasPosition()) {
double[] position = cayenne.getPosition();
sensorData.addValue(ESensorItem.POS_LAT, position[0]);
sensorData.addValue(ESensorItem.POS_LON, position[1]);
sensorData.addValue(ESensorItem.POS_ALT, position[2]);
sensorData.addValue(ESensorItem.GPS_LAT, position[0]);
sensorData.addValue(ESensorItem.GPS_LON, position[1]);
sensorData.addValue(ESensorItem.GPS_ALT, position[2]);
}
break;
case JSON:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public enum ESensorItem {
TEMPERATURE("Temperature", "degC", -100, 100),
PRESSURE("Atmospheric pressure", "Pa", 0, 1E6),

POS_LAT("Latitude", "deg", -90, 90),
POS_LON("Longitude", "deg", -180, 180),
POS_ALT("Altitude", "m"),
GPS_LAT("Latitude", "deg", -90, 90),
GPS_LON("Longitude", "deg", -180, 180),
GPS_ALT("Altitude", "m"),

NOISE_LA_EQ("Noise avg", "dBA", 0, 200),
NOISE_LA_MIN("Noise min", "dBA", 0, 200),
Expand All @@ -35,23 +35,23 @@ public enum ESensorItem {
LORA_SNR("Signal-to-noise ratio", "dB"),
LORA_RSSI("Signal strength", "dBm");

private String description;
private String unit;
private double minValue;
private double maxValue;
private final String description;
private final String unit;
private final double minValue;
private final double maxValue;

private ESensorItem(String description, String unit, double minValue, double maxValue) {
ESensorItem(String description, String unit, double minValue, double maxValue) {
this.description = description;
this.unit = unit;
this.minValue = minValue;
this.maxValue = maxValue;
}

private ESensorItem(String description, String unit, double minValue) {
ESensorItem(String description, String unit, double minValue) {
this(description, unit, minValue, Double.POSITIVE_INFINITY);
}

private ESensorItem(String description, String unit) {
ESensorItem(String description, String unit) {
this(description, unit, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public enum ESensComItem {
PRESSURE(ESensorItem.PRESSURE, "pressure"),

// location
GPS_LAT(ESensorItem.POS_LAT, "lat", 5),
GPS_LON(ESensorItem.POS_LON, "lon", 5),
GPS_ALT(ESensorItem.POS_ALT, "height");
GPS_LAT(ESensorItem.GPS_LAT, "lat", 5),
GPS_LON(ESensorItem.GPS_LON, "lon", 5),
GPS_ALT(ESensorItem.GPS_ALT, "height");

private final ESensorItem item;
private final String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ private void performUpload(AppDeviceId appDeviceId, SensorData data) {
}

// pin 9: position
if (data.hasValue(ESensorItem.POS_LAT) && data.hasValue(ESensorItem.POS_LON)) {
if (hasValidGps(data)) {
SensComMessage p9Message = new SensComMessage(softwareVersion);
addItem(p9Message, data, ESensComItem.GPS_LAT);
addItem(p9Message, data, ESensComItem.GPS_LON);
if (data.hasValue(ESensorItem.POS_ALT)) {
if (data.hasValue(ESensorItem.GPS_ALT)) {
addItem(p9Message, data, ESensComItem.GPS_ALT);
}
uploadMeasurement(ESensComPin.POSITION, sensorId, p9Message);
Expand Down Expand Up @@ -170,6 +170,24 @@ private void performUpload(AppDeviceId appDeviceId, SensorData data) {
}
}

private boolean hasValidGps(SensorData data) {
// are both latitude and longitude present?
if (!data.hasValue(ESensorItem.GPS_LAT) || !data.hasValue(ESensorItem.GPS_LON)) {
return false;
}
// are they in range?
double lat = data.getValue(ESensorItem.GPS_LAT);
double lon = data.getValue(ESensorItem.GPS_LON);
if (!ESensorItem.GPS_LAT.inRange(lat) || !ESensorItem.GPS_LON.inRange(lon)) {
return false;
}
// not equal to 0?
if ((Math.abs(lat) < 1E-6) && (Math.abs(lon) < 1E-6)) {
return false;
}
return true;
}

private void uploadMeasurement(ESensComPin pin, String sensorId, SensComMessage message) {
try {
LOG.info("Uploading for {} ({}) to pin {}: '{}'", appId, sensorId, pin, mapper.writeValueAsString(message));
Expand Down

0 comments on commit 9d56167

Please sign in to comment.