kopia lustrzana https://github.com/bertrik/ttnhabbridge
Fix spotbugs warnings and add port parameter.
rodzic
97cc277968
commit
1dc3101aff
|
@ -9,7 +9,8 @@ import java.util.Map;
|
|||
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 {
|
||||
|
||||
|
@ -22,33 +23,34 @@ public final class TtnUplinkMessage {
|
|||
private final byte[] payloadRaw;
|
||||
private final boolean isRetry;
|
||||
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.appId = appId;
|
||||
this.deviceId = deviceId;
|
||||
this.counter = counter;
|
||||
this.port = 1; // TODO port
|
||||
this.port = port;
|
||||
this.payloadRaw = payloadRaw.clone();
|
||||
this.isRetry = isRetry;
|
||||
}
|
||||
|
||||
|
||||
public void addField(String name, Object value) {
|
||||
payloadFields.put(name, value);
|
||||
}
|
||||
|
||||
|
||||
public Instant getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
}
|
||||
|
||||
|
||||
public String getDevId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
|
||||
public int getCounter() {
|
||||
return counter;
|
||||
}
|
||||
|
@ -64,7 +66,7 @@ public final class TtnUplinkMessage {
|
|||
public boolean isRetry() {
|
||||
return isRetry;
|
||||
}
|
||||
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
@ -72,19 +74,19 @@ public final class TtnUplinkMessage {
|
|||
public void addGateway(String id, double lat, double lon, double alt) {
|
||||
gateways.add(new GatewayInfo(id, new Location(lat, lon, alt)));
|
||||
}
|
||||
|
||||
|
||||
public List<GatewayInfo> getGateways() {
|
||||
return gateways;
|
||||
}
|
||||
|
||||
|
||||
public static final class GatewayInfo {
|
||||
|
||||
private final String id;
|
||||
private final Location location;
|
||||
|
||||
|
||||
public GatewayInfo(String id, Location location) {
|
||||
this.id = id;
|
||||
this.location = location;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
@ -94,7 +96,7 @@ public final class TtnUplinkMessage {
|
|||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ public final class Ttnv2UplinkMessage {
|
|||
}
|
||||
|
||||
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()) {
|
||||
message.addGateway(gw.getId(), gw.getLatitude(), gw.getLongitude(), gw.getAltitude());
|
||||
}
|
||||
|
|
|
@ -32,15 +32,6 @@ public final class Ttnv3UplinkMessage {
|
|||
|
||||
@JsonProperty("application_ids")
|
||||
ApplicationIds applicationIds = new ApplicationIds();
|
||||
|
||||
@JsonProperty("dev_eui")
|
||||
String deviceEui = "";
|
||||
|
||||
@JsonProperty("join_eui")
|
||||
String joinEui = "";
|
||||
|
||||
@JsonProperty("dev_addr")
|
||||
String deviceAddress = "";
|
||||
}
|
||||
|
||||
final static class ApplicationIds {
|
||||
|
@ -83,6 +74,7 @@ public final class Ttnv3UplinkMessage {
|
|||
String eui = "";
|
||||
}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
final static class Location {
|
||||
@JsonProperty("latitude")
|
||||
private double latitude = Double.NaN;
|
||||
|
@ -92,15 +84,12 @@ public final class Ttnv3UplinkMessage {
|
|||
|
||||
@JsonProperty("altitude")
|
||||
private double altitude = Double.NaN;
|
||||
|
||||
@JsonProperty("source")
|
||||
private String source = "";
|
||||
}
|
||||
|
||||
public TtnUplinkMessage toUplinkMessage() {
|
||||
TtnUplinkMessage uplink = new TtnUplinkMessage(Instant.parse(receivedAt),
|
||||
endDeviceIds.applicationIds.applicationId, endDeviceIds.deviceId, uplinkMessage.fcnt,
|
||||
uplinkMessage.payload, false);
|
||||
uplinkMessage.fport, uplinkMessage.payload, false);
|
||||
for (RxMetadata metadata : uplinkMessage.rxMetadata) {
|
||||
String id = metadata.gatewayIds.gatewayId;
|
||||
if (id.isBlank()) {
|
||||
|
|
|
@ -94,7 +94,7 @@ public final class PayloadDecoderTest {
|
|||
@Test
|
||||
public void testCayenne2() throws DecodeException {
|
||||
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
|
||||
PayloadDecoder decoder = new PayloadDecoder(EPayloadEncoding.CAYENNE);
|
||||
Sentence sentence = decoder.decode(message);
|
||||
|
|
Ładowanie…
Reference in New Issue