Skip to content

Commit

Permalink
Message Handler handleSync returns the DF instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglasdc3 committed Nov 16, 2020
1 parent e6e6c89 commit 259d3fe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/aero/t2s/modes/ModeSHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void onMessage(Consumer<DownlinkFormat> onMessage) {
}

public abstract void handle(String data);
public abstract void handleSync(String data);
public abstract DownlinkFormat handleSync(String data);


protected short[] toData(final String input) throws EmptyMessageException {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/aero/t2s/modes/ModeSMessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,23 @@ public void handle(final String input) {
executor.execute(() -> handleSync(input));
}

public void handleSync(final String input) {
public DownlinkFormat handleSync(final String input) {
try {
DownlinkFormat df = decoder.decode(toData(input));

if (onMessage != null) {
onMessage.accept(df);
}

return df;
} catch (EmptyMessageException ignored) {
} catch (InvalidExtendedSquitterTypeCodeException | UnknownDownlinkFormatException e) {
LOGGER.error(e.getMessage());
} catch (Throwable throwable) {
LOGGER.error("Message could not be parsed", throwable);
}

return null;
}


Expand Down
8 changes: 6 additions & 2 deletions src/main/java/aero/t2s/modes/ModeSTrackHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public void handle(final String input) {
executor.execute(() -> handleSync(input));
}

public void handleSync(final String input) {
public DownlinkFormat handleSync(final String input) {
try {
DownlinkFormat df = decoder.decode(toData(input));
Track track = decoder.getTrack(df.getIcao());

if (track == null) {
return;
return null;
}

df.apply(track);
Expand All @@ -66,12 +66,16 @@ public void handleSync(final String input) {
if (onMessage != null) {
onMessage.accept(df);
}

return df;
} catch (EmptyMessageException ignored) {
} catch (InvalidExtendedSquitterTypeCodeException | UnknownDownlinkFormatException e) {
LOGGER.error(e.getMessage());
} catch (Throwable throwable) {
LOGGER.error("Message could not be parsed", throwable);
}

return null;
}

public void enableCleanup() {
Expand Down

0 comments on commit 259d3fe

Please sign in to comment.