Fix spotbugs warnings and add port parameter.

master
Bertrik Sikken 2021-03-06 12:09:00 +01:00
rodzic 97cc277968
commit 1dc3101aff
4 zmienionych plików z 21 dodań i 30 usunięć

Wyświetl plik

@ -9,7 +9,8 @@ import java.util.Map;
import nl.sikken.bertrik.hab.habitat.Location; import nl.sikken.bertrik.hab.habitat.Location;
/** /**
* Uplink message, TTN stack version independent, containing all information needed to create a habhub sentence * Uplink message, TTN stack version independent, containing all information
* needed to create a habhub sentence
*/ */
public final class TtnUplinkMessage { public final class TtnUplinkMessage {
@ -22,33 +23,34 @@ public final class TtnUplinkMessage {
private final byte[] payloadRaw; private final byte[] payloadRaw;
private final boolean isRetry; private final boolean isRetry;
private final List<GatewayInfo> gateways = new ArrayList<>(); private final List<GatewayInfo> gateways = new ArrayList<>();
public TtnUplinkMessage(Instant time, String appId, String deviceId, int counter, byte[] payloadRaw, boolean isRetry) { public TtnUplinkMessage(Instant time, String appId, String deviceId, int counter, int port, byte[] payloadRaw,
boolean isRetry) {
this.time = time; this.time = time;
this.appId = appId; this.appId = appId;
this.deviceId = deviceId; this.deviceId = deviceId;
this.counter = counter; this.counter = counter;
this.port = 1; // TODO port this.port = port;
this.payloadRaw = payloadRaw.clone(); this.payloadRaw = payloadRaw.clone();
this.isRetry = isRetry; this.isRetry = isRetry;
} }
public void addField(String name, Object value) { public void addField(String name, Object value) {
payloadFields.put(name, value); payloadFields.put(name, value);
} }
public Instant getTime() { public Instant getTime() {
return time; return time;
} }
public String getAppId() { public String getAppId() {
return appId; return appId;
} }
public String getDevId() { public String getDevId() {
return deviceId; return deviceId;
} }
public int getCounter() { public int getCounter() {
return counter; return counter;
} }
@ -64,7 +66,7 @@ public final class TtnUplinkMessage {
public boolean isRetry() { public boolean isRetry() {
return isRetry; return isRetry;
} }
public int getPort() { public int getPort() {
return port; return port;
} }
@ -72,19 +74,19 @@ public final class TtnUplinkMessage {
public void addGateway(String id, double lat, double lon, double alt) { public void addGateway(String id, double lat, double lon, double alt) {
gateways.add(new GatewayInfo(id, new Location(lat, lon, alt))); gateways.add(new GatewayInfo(id, new Location(lat, lon, alt)));
} }
public List<GatewayInfo> getGateways() { public List<GatewayInfo> getGateways() {
return gateways; return gateways;
} }
public static final class GatewayInfo { public static final class GatewayInfo {
private final String id; private final String id;
private final Location location; private final Location location;
public GatewayInfo(String id, Location location) { public GatewayInfo(String id, Location location) {
this.id = id; this.id = id;
this.location = location; this.location = location;
} }
public String getId() { public String getId() {
@ -94,7 +96,7 @@ public final class TtnUplinkMessage {
public Location getLocation() { public Location getLocation() {
return location; return location;
} }
} }
} }

Wyświetl plik

@ -89,7 +89,7 @@ public final class Ttnv2UplinkMessage {
} }
public TtnUplinkMessage toUplinkMessage() { public TtnUplinkMessage toUplinkMessage() {
TtnUplinkMessage message = new TtnUplinkMessage(metaData.getTime(), appId, devId, counter, payloadRaw, isRetry); TtnUplinkMessage message = new TtnUplinkMessage(metaData.getTime(), appId, devId, counter, port, payloadRaw, isRetry);
for (TtnMessageGateway gw : metaData.getMqttGateways()) { for (TtnMessageGateway gw : metaData.getMqttGateways()) {
message.addGateway(gw.getId(), gw.getLatitude(), gw.getLongitude(), gw.getAltitude()); message.addGateway(gw.getId(), gw.getLatitude(), gw.getLongitude(), gw.getAltitude());
} }

Wyświetl plik

@ -32,15 +32,6 @@ public final class Ttnv3UplinkMessage {
@JsonProperty("application_ids") @JsonProperty("application_ids")
ApplicationIds applicationIds = new ApplicationIds(); ApplicationIds applicationIds = new ApplicationIds();
@JsonProperty("dev_eui")
String deviceEui = "";
@JsonProperty("join_eui")
String joinEui = "";
@JsonProperty("dev_addr")
String deviceAddress = "";
} }
final static class ApplicationIds { final static class ApplicationIds {
@ -83,6 +74,7 @@ public final class Ttnv3UplinkMessage {
String eui = ""; String eui = "";
} }
@JsonIgnoreProperties(ignoreUnknown = true)
final static class Location { final static class Location {
@JsonProperty("latitude") @JsonProperty("latitude")
private double latitude = Double.NaN; private double latitude = Double.NaN;
@ -92,15 +84,12 @@ public final class Ttnv3UplinkMessage {
@JsonProperty("altitude") @JsonProperty("altitude")
private double altitude = Double.NaN; private double altitude = Double.NaN;
@JsonProperty("source")
private String source = "";
} }
public TtnUplinkMessage toUplinkMessage() { public TtnUplinkMessage toUplinkMessage() {
TtnUplinkMessage uplink = new TtnUplinkMessage(Instant.parse(receivedAt), TtnUplinkMessage uplink = new TtnUplinkMessage(Instant.parse(receivedAt),
endDeviceIds.applicationIds.applicationId, endDeviceIds.deviceId, uplinkMessage.fcnt, endDeviceIds.applicationIds.applicationId, endDeviceIds.deviceId, uplinkMessage.fcnt,
uplinkMessage.payload, false); uplinkMessage.fport, uplinkMessage.payload, false);
for (RxMetadata metadata : uplinkMessage.rxMetadata) { for (RxMetadata metadata : uplinkMessage.rxMetadata) {
String id = metadata.gatewayIds.gatewayId; String id = metadata.gatewayIds.gatewayId;
if (id.isBlank()) { if (id.isBlank()) {

Wyświetl plik

@ -94,7 +94,7 @@ public final class PayloadDecoderTest {
@Test @Test
public void testCayenne2() throws DecodeException { public void testCayenne2() throws DecodeException {
TtnUplinkMessage message = new TtnUplinkMessage(Instant.parse("2020-02-05T22:00:58.930936Z"), "test", "test", TtnUplinkMessage message = new TtnUplinkMessage(Instant.parse("2020-02-05T22:00:58.930936Z"), "test", "test",
123, Base64.getDecoder().decode("AYgH1ecAzV4AC7gCZwArAwIBhg=="), false); 123, 1, Base64.getDecoder().decode("AYgH1ecAzV4AC7gCZwArAwIBhg=="), false);
// decode payload // decode payload
PayloadDecoder decoder = new PayloadDecoder(EPayloadEncoding.CAYENNE); PayloadDecoder decoder = new PayloadDecoder(EPayloadEncoding.CAYENNE);
Sentence sentence = decoder.decode(message); Sentence sentence = decoder.decode(message);