-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert HeliumUplinkMessage to record.
- Loading branch information
Showing
2 changed files
with
51 additions
and
62 deletions.
There are no files selected for viewing
83 changes: 36 additions & 47 deletions
83
sensor-data-bridge/src/main/java/nl/bertriksikken/helium/HeliumUplinkMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,48 @@ | ||
package nl.bertriksikken.helium; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public final class HeliumUplinkMessage { | ||
|
||
@JsonProperty("app_eui") | ||
String appEui = ""; | ||
|
||
@JsonProperty("dev_eui") | ||
String devEui = ""; | ||
|
||
// device address with bytes in reverse order | ||
@JsonProperty("devaddr") | ||
String devAddr = ""; | ||
|
||
@JsonProperty("fcnt") | ||
int fcnt; | ||
|
||
@JsonProperty("port") | ||
int port; | ||
|
||
@JsonProperty("name") | ||
String name = ""; | ||
|
||
@JsonProperty("payload") | ||
byte[] payload = new byte[0]; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
// milliseconds | ||
@JsonProperty("reported_at") | ||
long reportedAt; | ||
@SuppressWarnings("ArrayRecordComponent") | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public record HeliumUplinkMessage( | ||
@JsonProperty("app_eui") String appEui, | ||
@JsonProperty("dev_eui") String devEui, | ||
@JsonProperty("devaddr") String devAddr, // device address with bytes in reverse order | ||
@JsonProperty("fcnt") int fcnt, | ||
@JsonProperty("port") int port, | ||
@JsonProperty("name") String name, | ||
@JsonProperty("payload") byte[] payload, | ||
@JsonProperty("reported_at") long reportedAt, // milliseconds | ||
@JsonProperty("hotspots") List<HotSpot> hotSpots) { | ||
public HeliumUplinkMessage { | ||
appEui = Objects.requireNonNullElse(appEui, ""); | ||
devEui = Objects.requireNonNullElse(devEui, ""); | ||
devAddr = Objects.requireNonNullElse(devAddr, ""); | ||
name = Objects.requireNonNullElse(name, ""); | ||
payload = Objects.requireNonNullElse(payload.clone(), new byte[0]); | ||
hotSpots = Objects.requireNonNullElse(hotSpots, new ArrayList<>()); | ||
} | ||
|
||
@JsonProperty("hotspots") | ||
List<HotSpot> hotSpots = new ArrayList<>(); | ||
@Override | ||
public byte[] payload() { | ||
return payload.clone(); | ||
} | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
static final class HotSpot { | ||
@JsonProperty("name") | ||
String name = ""; | ||
|
||
@JsonProperty("lat") | ||
double latitude; | ||
|
||
@JsonProperty("long") | ||
double longitude; | ||
|
||
@JsonProperty("rssi") | ||
double rssi; | ||
|
||
@JsonProperty("snr") | ||
double snr; | ||
record HotSpot( | ||
@JsonProperty("name") String name, | ||
@JsonProperty("lat") double latitude, | ||
@JsonProperty("long") double longitude, | ||
@JsonProperty("rssi") double rssi, | ||
@JsonProperty("snr") double snr) { | ||
HotSpot { | ||
name = Objects.requireNonNullElse(name, ""); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters