diff --git a/src/main/java/ru/r2cloud/satellite/RotatorService.java b/src/main/java/ru/r2cloud/satellite/RotatorService.java index e5befa19..5ce67381 100644 --- a/src/main/java/ru/r2cloud/satellite/RotatorService.java +++ b/src/main/java/ru/r2cloud/satellite/RotatorService.java @@ -84,6 +84,10 @@ public void run() { throw new RuntimeException("observation stopped"); } Position currentPosition = predict.getSatellitePosition(current, groundStation, tlePropagator); + if (currentPosition.getElevation() < 0.0) { + LOG.info("[{}] negative elevation requested. most likely stale or invalid tle. cancelling rotation", req.getId()); + throw new RuntimeException("negative elevation"); + } if (previousPosition != null) { double tolerance = config.getTolerance(); double azimuthDelta = Math.abs(currentPosition.getAzimuth() - previousPosition.getAzimuth()); diff --git a/src/test/java/ru/r2cloud/satellite/RotatorServiceTest.java b/src/test/java/ru/r2cloud/satellite/RotatorServiceTest.java index d0153e44..856afe3b 100644 --- a/src/test/java/ru/r2cloud/satellite/RotatorServiceTest.java +++ b/src/test/java/ru/r2cloud/satellite/RotatorServiceTest.java @@ -58,6 +58,24 @@ public class RotatorServiceTest { private int serverPort; private CollectingRequestHandler requestHandler; + @Test + public void testStaleTle() throws Exception { + ObservationRequest req = createRequest(); + req.getTle().getRaw()[1] = "1 53376U 22096G 24125.30500733 .01222779 97906-3 12443-2 0 9998"; + req.getTle().getRaw()[2] = "2 53376 97.3733 46.7756 0008493 160.3534 199.8078 16.11052950 97692"; + req.setStartTimeMillis(1725198038000L); + req.setEndTimeMillis(1725199038000L); + int times = (int) ((req.getEndTimeMillis() - req.getStartTimeMillis()) / 70000); + service = new RotatorService(createValidConfig(), predict, new ScheduleFixedTimesTheadPoolFactory(times), new SteppingClock(req.getStartTimeMillis(), 70000)); + service.start(); + try { + assertNotNull(service.schedule(req, 1725198028000L, null)); + } catch (RuntimeException e) { + assertEquals("negative elevation", e.getMessage()); + } + assertPositions("expected/rotctrld-requests-stale-tle.txt", requestHandler.getRequests()); + } + @Test public void testRotctrldDuringPeriodOfUnavailability() { SequentialRequestHandler handler = new SequentialRequestHandler(new SimpleRequestHandler("test\n"), new SimpleRequestHandler("RPRT 0\n"), new SimpleRequestHandler("RPRT 1\n"), new SimpleRequestHandler("test\n"), new SimpleRequestHandler("RPRT 0\n")); @@ -114,14 +132,18 @@ public void testSuccess() throws Exception { service = new RotatorService(createValidConfig(), predict, new ScheduleFixedTimesTheadPoolFactory(times), new SteppingClock(req.getStartTimeMillis(), 1000)); service.start(); assertNotNull(service.schedule(req, req.getStartTimeMillis(), null)); - try (BufferedReader r = new BufferedReader(new InputStreamReader(RotatorService.class.getClassLoader().getResourceAsStream("expected/rotctrld-requests.txt"), StandardCharsets.UTF_8))) { + assertPositions("expected/rotctrld-requests.txt", requestHandler.getRequests()); + } + + private static void assertPositions(String expectedFile, List requests) throws Exception { + try (BufferedReader r = new BufferedReader(new InputStreamReader(RotatorServiceTest.class.getClassLoader().getResourceAsStream(expectedFile), StandardCharsets.UTF_8))) { String curLine = null; int i = 0; while ((curLine = r.readLine()) != null) { - assertPosition(curLine, requestHandler.getRequests().get(i)); + assertPosition(curLine, requests.get(i)); i++; } - assertEquals(i, requestHandler.getRequests().size()); + assertEquals(i, requests.size()); } } diff --git a/src/test/resources/expected/rotctrld-requests-stale-tle.txt b/src/test/resources/expected/rotctrld-requests-stale-tle.txt new file mode 100644 index 00000000..71497fb5 --- /dev/null +++ b/src/test/resources/expected/rotctrld-requests-stale-tle.txt @@ -0,0 +1,10 @@ +\set_pos 352.91692294756064 64.98025517525099 +\set_pos 349.69881272805304 58.18332105196653 +\set_pos 347.6137812645207 51.250694544049225 +\set_pos 346.1633530169924 44.21286500405056 +\set_pos 345.10232199719513 37.08555430799149 +\set_pos 344.29620634607767 29.87814935460905 +\set_pos 343.66475425736485 22.596968294139533 +\set_pos 343.15656291222 15.246690670925322 +\set_pos 342.7364638181337 7.831040504760989 +\set_pos 342.37865424271996 0.3531322367814761 \ No newline at end of file