Skip to content

Commit

Permalink
save tle from satnogs satellites + propagate last update time
Browse files Browse the repository at this point in the history
  • Loading branch information
dernasherbrezon committed Nov 18, 2024
1 parent 1b51a20 commit 0b287e5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 112 deletions.
16 changes: 12 additions & 4 deletions src/main/java/ru/r2cloud/cloud/SatnogsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ public List<Satellite> loadSatellites() {
List<Satellite> result = loadAllSatellites(groupBySatelliteId);
for (Satellite cur : result) {
dedupTransmittersByKey(cur);
if (!cur.getPriority().equals(Priority.HIGH)) {
continue;
}
cur.setTle(loadTleBySatelliteId(cur.getId()));
}
LOG.info("satellites from satnogs were loaded: {}", result.size());
return result;
Expand Down Expand Up @@ -180,6 +176,8 @@ private List<Satellite> readSatellites(String body, Map<String, List<Transmitter
List<Satellite> result = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
SimpleDateFormat updatedFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
updatedFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
for (int i = 0; i < parsedArray.size(); i++) {
JsonValue jsonValue = parsedArray.get(i);
if (!jsonValue.isObject()) {
Expand Down Expand Up @@ -212,6 +210,16 @@ private List<Satellite> readSatellites(String body, Map<String, List<Transmitter
// thus disabled by default even if "new launch"
// https://gitlab.com/librespacefoundation/satnogs/satnogs-db/-/issues/551
cur.setEnabled(false);
cur.setTle(loadTleBySatelliteId(id));
String updatedStr = getStringSafely(satellite, "updated");
if (updatedStr != null) {
try {
updatedStr = updatedStr.substring(0, updatedStr.length() - 4);
cur.setLastUpdateTime(updatedFormat.parse(updatedStr).getTime());
} catch (java.text.ParseException e) {
// ignore
}
}
// schedule observations anyway
if (status.equalsIgnoreCase("future")) {
cur.setId(id);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/ru/r2cloud/model/Satellite.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ public static Satellite fromJson(JsonObject meta) {
if (transmitters.isEmpty()) {
return null;
}
JsonValue lastUpdateTimeJson = meta.get("lastUpdateTime");
if (lastUpdateTimeJson != null) {
result.setLastUpdateTime(lastUpdateTimeJson.asLong());
}
return result;
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ru/r2cloud/tle/Housekeeping.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,11 @@ private void reloadTle() {
continue;
}
if (oldTle == null && newTle != null) {
reloadTle = true;
cur.setTle(newTle);
}
if (oldTle != null && newTle == null) {
reloadTle = true;
cur.setTle(oldTle);
}
if (oldTle != null && newTle != null) {
Expand Down
25 changes: 8 additions & 17 deletions src/test/java/ru/r2cloud/cloud/SatnogsClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.lang.reflect.Type;
import java.util.Date;
import java.util.List;

import org.junit.After;
Expand All @@ -14,19 +12,13 @@
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import com.eclipsesource.json.Json;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.eclipsesource.json.JsonArray;

import ru.r2cloud.ClassAdapter;
import ru.r2cloud.DateAdapter;
import ru.r2cloud.FixedClock;
import ru.r2cloud.JsonHttpResponse;
import ru.r2cloud.SatnogsServerMock;
import ru.r2cloud.TestConfiguration;
import ru.r2cloud.TestUtil;
import ru.r2cloud.jradio.Beacon;
import ru.r2cloud.model.Satellite;

public class SatnogsClientTest {
Expand Down Expand Up @@ -55,7 +47,7 @@ public void testInvalidResponse() throws Exception {
List<Satellite> satellite = client.loadSatellites();
assertEquals(1, satellite.size());
assertNull(satellite.get(0).getTle());

server.setTransmittersMock(new JsonHttpResponse("satnogs/transmitters.json", 200));
server.setTleMockDirectory("satnogs");

Expand All @@ -65,7 +57,7 @@ public void testInvalidResponse() throws Exception {
assertTrue(client.loadSatellites().isEmpty());
server.setSatellitesMock("[ [1,2,3] ]", 200);
assertTrue(client.loadSatellites().isEmpty());

server.setSatellitesMock(new JsonHttpResponse("satnogs/satellites.json", 200));
server.setTransmittersMock("not a json", 200);
assertTrue(client.loadSatellites().isEmpty());
Expand All @@ -81,12 +73,11 @@ public void testSuccess() {
server.setTransmittersMock(new JsonHttpResponse("satnogs/transmitters.json", 200));
server.setTleMockDirectory("satnogs");
List<Satellite> actual = client.loadSatellites();
Gson GSON = new GsonBuilder().registerTypeAdapter(Date.class, new DateAdapter()).registerTypeAdapter(new TypeToken<Class<? extends Beacon>>() {
}.getType(), new ClassAdapter()).create();
Type listOfMyClassObject = new TypeToken<List<Satellite>>() {
}.getType();
String serialized = GSON.toJson(actual, listOfMyClassObject);
TestUtil.assertJson("expected/satnogsSatellites.json", Json.parse(serialized).asArray());
JsonArray array = new JsonArray();
for (Satellite cur : actual) {
array.add(cur.toJson());
}
TestUtil.assertJson("expected/satnogsSatellites.json", array);
}

@Before
Expand Down
107 changes: 16 additions & 91 deletions src/test/resources/expected/satnogsSatellites.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,29 @@
[
{
"id": "53464",
"name": "TUMnanoSAT",
"enabled": false,
"noradId": "53464",
"priority": "NORMAL",
"enabled": false,
"transmitters": [
{
"modulation": "GFSK",
"framing": "AX25",
"beaconClass": "ru.r2cloud.jradio.ax25.Ax25Beacon",
"beaconSizeBytes": 0,
"frequency": 436680000,
"bandwidth": 20000,
"baudRates": [
9600
],
"bpskDifferential": false,
"bpskCenterFrequency": 0.0,
"deviation": 5000,
"afCarrier": 0,
"transitionWidth": 2000.0,
"loraBandwidth": 0,
"loraSpreadFactor": 0,
"loraCodingRate": 0,
"loraSyncword": 0,
"loraPreambleLength": 0,
"loraLdro": 0,
"status": "ENABLED",
"updated": 1660259232836,
"enabled": false,
"satelliteId": "EUEU-0112-5297-2105-4789"
"status": "ENABLED"
}
],
"source": "SATNOGS"
"lastUpdateTime": 1660566222623
},
{
"id": "43908",
"name": "LUME-1",
"enabled": false,
"noradId": "43908",
"priority": "NORMAL",
"enabled": false,
"transmitters": [
{
"modulation": "GFSK",
Expand All @@ -51,110 +36,50 @@
9600,
4800
],
"bpskDifferential": false,
"bpskCenterFrequency": 0.0,
"deviation": 5000,
"afCarrier": 0,
"transitionWidth": 2000.0,
"loraBandwidth": 0,
"loraSpreadFactor": 0,
"loraCodingRate": 0,
"loraSyncword": 0,
"loraPreambleLength": 0,
"loraLdro": 0,
"status": "ENABLED",
"updated": 1616533349387,
"enabled": false,
"satelliteId": "QXDQ-9755-0160-9983-1765"
"status": "ENABLED"
}
],
"source": "SATNOGS"
"lastUpdateTime": 1650904308036
},
{
"id": "52950",
"name": "CTIM",
"enabled": false,
"noradId": "52950",
"priority": "NORMAL",
"enabled": false,
"transmitters": [
{
"modulation": "GFSK",
"framing": "AX25G3RUH",
"beaconClass": "ru.r2cloud.jradio.ax25.Ax25Beacon",
"beaconSizeBytes": 0,
"frequency": 437396000,
"bandwidth": 20000,
"baudRates": [
9600
],
"bpskDifferential": false,
"bpskCenterFrequency": 0.0,
"deviation": 5000,
"afCarrier": 0,
"transitionWidth": 2000.0,
"loraBandwidth": 0,
"loraSpreadFactor": 0,
"loraCodingRate": 0,
"loraSyncword": 0,
"loraPreambleLength": 0,
"loraLdro": 0,
"status": "ENABLED",
"updated": 1659891135340,
"enabled": false,
"satelliteId": "CSGC-5605-1718-3109-5402"
"status": "ENABLED"
}
],
"source": "SATNOGS"
"lastUpdateTime": 1659986870989
},
{
"id": "BDML-1083-7096-5526-2883",
"name": "Skoltech B2",
"enabled": false,
"tle": {
"raw": [
"0 OBJECT L",
"1 53380U 22096L 22229.57175693 .00005563 00000-0 22547-3 0 9990",
"2 53380 97.4353 130.9847 0005660 72.7520 287.4337 15.25041840 1267"
],
"lastUpdateTime": 1660816317365
},
"noradId": "BDML-1083-7096-5526-2883",
"priority": "HIGH",
"enabled": false,
"start": 1660816307365,
"transmitters": [
{
"modulation": "GFSK",
"framing": "USP",
"beaconClass": "ru.r2cloud.jradio.usp.UspBeacon",
"beaconSizeBytes": 0,
"frequency": 435598000,
"bandwidth": 20000,
"baudRates": [
9600
],
"bpskDifferential": false,
"bpskCenterFrequency": 0.0,
"deviation": 5000,
"afCarrier": 0,
"transitionWidth": 2000.0,
"loraBandwidth": 0,
"loraSpreadFactor": 0,
"loraCodingRate": 0,
"loraSyncword": 0,
"loraPreambleLength": 0,
"loraLdro": 0,
"status": "ENABLED",
"updated": 1660748306832,
"enabled": false,
"satelliteId": "BDML-1083-7096-5526-2883",
"tle": {
"raw": [
"0 OBJECT L",
"1 53380U 22096L 22229.57175693 .00005563 00000-0 22547-3 0 9990",
"2 53380 97.4353 130.9847 0005660 72.7520 287.4337 15.25041840 1267"
],
"lastUpdateTime": 1660816317365
}
"status": "ENABLED"
}
],
"source": "SATNOGS"
"lastUpdateTime": 1660152501110
}
]

0 comments on commit 0b287e5

Please sign in to comment.