Skip to content

Commit

Permalink
Introduce value objects for Lora meta data
Browse files Browse the repository at this point in the history
Added value objects to represent common meta data instead of using a
generic map.

Signed-off-by: Kai Hudalla <[email protected]>
  • Loading branch information
sophokles73 authored Jun 25, 2020
1 parent 4e62471 commit 5c455da
Show file tree
Hide file tree
Showing 34 changed files with 1,533 additions and 646 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/**
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/


package org.eclipse.hono.adapter.lora;

import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* A container for meta information about a Lora gateway.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GatewayInfo {

@JsonProperty(LoraConstants.APP_PROPERTY_SNR)
private Double snr;
@JsonProperty(LoraConstants.APP_PROPERTY_RSS)
private Integer rssi;
@JsonProperty(LoraConstants.GATEWAY_ID)
private String gatewayId;
@JsonProperty(LoraConstants.APP_PROPERTY_CHANNEL)
private Integer channel;
@JsonProperty(LoraConstants.LOCATION)
private Location location;

/**
* Gets the gateway's identifier.
*
* @return The identifier or {@code null} if unknown.
* @throws NullPointerException if id is {@code null}.
*/
public String getGatewayId() {
return gatewayId;
}

/**
* Sets the gateway's identifier.
*
* @param id The identifier or {@code null} if unknown.
* @throws NullPointerException if id is {@code null}.
*/
public void setGatewayId(final String id) {
this.gatewayId = Objects.requireNonNull(id);
}

/**
* Gets the concentrator IF channel that the gateway used for receiving
* the data.
*
* @return The channel or {@code null} if unknown.
*/
public Integer getChannel() {
return channel;
}

/**
* Sets the concentrator IF channel that the gateway used for receiving
* the data.
*
* @param channel The channel or {@code null} if unknown.
* @return This object for command chaining.
*/
public GatewayInfo setChannel(final Integer channel) {
this.channel = channel;
return this;
}

/**
* Gets the location of the receiving gateway.
*
* @return The location or {@code null} if unknown.
*/
public Location getLocation() {
return location;
}

/**
* Sets the location of the receiving gateway.
*
* @param location The location or {@code null} if unknown.
* @return This object for command chaining.
*/
public GatewayInfo setLocation(final Location location) {
this.location = location;
return this;
}

/**
* Gets the signal-to-noise ratio (SNR) detected by the
* gateway when receiving the data.
*
* @return The ratio in dB or {@code null} if unknown.
*/
public Double getSnr() {
return snr;
}

/**
* Sets the signal-to-noise ratio (SNR) detected by the
* gateway when receiving the data.
*
* @param snr The ratio in dB or {@code null} if unknown.
* @return This object for command chaining.
*/
public GatewayInfo setSnr(final Double snr) {
this.snr = snr;
return this;
}

/**
* Gets the received signal strength indicator (RSSI) detected by the
* gateway when receiving the data.
*
* @return The RSSI value in dBm or {@code null} if unknown.
*/
public Integer getRssi() {
return rssi;
}

/**
* Sets the received signal strength indicator (RSSI) detected by the
* gateway when receiving the data.
*
* @param rssi The RSSI value in dBm or {@code null} if unknown.
* @return This object for command chaining.
* @throws IllegalArgumentException if the rssi value is positive.
*/
public GatewayInfo setRssi(final Integer rssi) {
if (rssi != null && rssi.intValue() > 0) {
throw new IllegalArgumentException("RSSI value must be a negative integer");
}
this.rssi = rssi;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/


package org.eclipse.hono.adapter.lora;

import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* A 3D geo-location that consists of longitude, latitude and (optional) altitude.
*
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public final class Location {

@JsonProperty(LoraConstants.APP_PROPERTY_FUNCTION_LONGITUDE)
private Double longitude;
@JsonProperty(LoraConstants.APP_PROPERTY_FUNCTION_LATITUDE)
private Double latitude;
@JsonProperty(LoraConstants.APP_PROPERTY_FUNCTION_ALTITUDE)
private Double altitude;

/**
* Creates a new location for coordinates.
*
* @param longitude The longitude in decimal degrees.
* @param latitude The latitude in decimal degrees.
* @param altitude The altitude in meters or {@code null} if unknown.
* @throws NullPointerException if longitude or latitude are {@code null}.
*/
public Location(
@JsonProperty(value = LoraConstants.APP_PROPERTY_FUNCTION_LONGITUDE, required = true) final Double longitude,
@JsonProperty(value = LoraConstants.APP_PROPERTY_FUNCTION_LATITUDE, required = true) final Double latitude,
@JsonProperty(LoraConstants.APP_PROPERTY_FUNCTION_ALTITUDE) final Double altitude) {
this.longitude = Objects.requireNonNull(longitude);
this.latitude = Objects.requireNonNull(latitude);
this.altitude = altitude;
}

/**
* Gets the longitude of the location.
*
* @return The longitude in decimal degrees.
*/
public Double getLongitude() {
return longitude;
}

/**
* Gets the latitude of the location.
*
* @return The latitude in decimal degrees.
*/
public Double getLatitude() {
return latitude;
}

/**
* Gets the altitude of the location.
*
* @return The altitude in meters.
*/
public Double getAltitude() {
return altitude;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class LoraConstants {
* which an uploaded message has originally been received.
*/
public static final String APP_PROPERTY_ORIG_LORA_PROVIDER = "orig_lora_provider";

public static final String FIELD_PSK = "psk";
public static final String FIELD_VIA = "via";
public static final String FIELD_AUTH_ID = "auth-id";
Expand All @@ -37,8 +38,9 @@ public class LoraConstants {
public static final String EMPTY = "";
public static final String CONTENT_TYPE_LORA_POST_FIX = "+json";
public static final String CONTENT_TYPE_LORA_BASE = "application/vnd.eclipse-hono.lora.";
public static final String NORMALIZED_PROPERTIES = "normalized_properties";
public static final String META_DATA = "meta_data";
public static final String ADDITIONAL_DATA = "additional_data";

public static final String APP_PROPERTY_RSS = "rss";
public static final String APP_PROPERTY_TX_POWER = "tx_power";
public static final String APP_PROPERTY_CHANNEL = "channel";
Expand All @@ -47,15 +49,19 @@ public class LoraConstants {
public static final String APP_PROPERTY_BANDWIDTH = "bandwidth";
public static final String APP_PROPERTY_SNR = "snr";
public static final String APP_PROPERTY_FUNCTION_PORT = "function_port";
public static final String APP_PROPERTY_FUNCTION_ALTITUDE = "altitude";
public static final String APP_PROPERTY_FUNCTION_LATITUDE = "latitude";
public static final String APP_PROPERTY_FUNCTION_LONGITUDE = "longitude";
public static final String APP_PROPERTY_MIC = "mic";
public static final String ADAPTIVE_DATA_RATE_ENABLED = "adr_enabled";
public static final String GATEWAYS = "gateways";
public static final String GATEWAY_ID = "gateway_id";
public static final String DATA_RATE = "data_rate";
public static final String DATA_RATE_ID = "data_rate_id";
public static final String CODING_RATE = "coding_rate";
public static final String FREQUENCY = "frequency";
public static final String FRAME_COUNT = "frame_count";
public static final String LOCATION = "location";

private LoraConstants() {
// prevent instantiation
Expand Down
Loading

0 comments on commit 5c455da

Please sign in to comment.