Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

15 refactor duplicate code #16

Merged
merged 6 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactoring: removed duplicate code
  • Loading branch information
fixje committed Oct 1, 2023
commit 725f95387178323555ed0e354c9b3ab3001650a7
155 changes: 155 additions & 0 deletions src/main/java/de/serosystems/lib1090/decoding/AirbornePosition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package de.serosystems.lib1090.decoding;

import de.serosystems.lib1090.msgs.adsb.AirborneOperationalStatusV1Msg;

/**
* @author Markus Fuchs ([email protected])
*/
public final class AirbornePosition {

private AirbornePosition() {}

/**
* Values according to DO-260B Table N-11
* @return Navigation integrity category. A NIC of 0 means "unkown".
*/
public static byte decodeNIC(byte formatTypeCode, boolean nicSupplA) {
switch (formatTypeCode) {
case 9: case 20: return 11;
case 10: case 21: return 10;
case 11: return (byte) (nicSupplA ? 9 : 8);
case 12: return 7;
case 13: return 6;
case 14: return 5;
case 15: return 4;
case 16: return (byte) (nicSupplA ? 3 : 2);
case 17: return 1;
// case 0: case 18: case 22: return 0;
default: return 0;
}
}

/**
* The position error, i.e., 95% accuracy for the horizontal position. For the navigation accuracy category
* (NACp) see {@link AirborneOperationalStatusV1Msg}. Values according to DO-260B Table N-11.
*
* The horizontal containment radius is also known as "horizontal protection level".
*
* @return horizontal containment radius limit in meters. A return value of -1 means "unknown".
* If aircraft uses ADS-B version 1+, set NIC supplement A from Operational Status Message
* for better precision.
*/
public static double decodeHCR(byte formatTypeCode, boolean nicSupplA) {
switch (formatTypeCode) {
case 9: case 20: return 7.5;
case 10: case 21: return 25;
case 11: return nicSupplA ? 75.0 : 185.2;
case 12: return 370.4;
case 13: return nicSupplA ? 1111.2 : 926;
case 14: return 1852;
case 15: return 3704;
case 16: return nicSupplA ? 7408 : 14816;
case 17: return 37040;
// case 0: case 18: case 22: return -1;
default: return -1;
}
}

/**
* According to DO-260B Table N-4
*
* @param formatTypeCode the messages' format type code
* @return the derived HCR
*/
public static double typeCodeToHCR(byte formatTypeCode) {
switch (formatTypeCode) {
case 9: case 20: return 7.5;
case 10: case 21: return 25;
case 11: return 185.2;
case 12: return 370.4;
case 13: return 926;
case 14: return 1852;
case 15: return 3704;
case 16: return 18520;
case 17: return 37040;
// case 0: case 18: case 22: return -1;
default: return -1;
}
}

/**
* According to DO-260B Table N-7
*
* @param formatTypeCode the messages' format type code
* @return the derived NACp
*/
public static byte typeCodeToNACp(byte formatTypeCode) {
switch (formatTypeCode) {
case 9: case 20: return 11;
case 10: case 21: return 10;
case 11: return 8;
case 12: return 7;
case 13: return 6;
case 14: return 5;
case 15: return 4;
case 16: case 17: return 1;
// case 0: case 18: case 22: return 0;
default: return 0;
}
}

/**
* According to DO-260B Table N-7
*
* @param formatTypeCode the messages' format type code
* @return the derived position uncertainty in meters
*/
public static double typeCodeToPositionUncertainty(byte formatTypeCode) {
switch (formatTypeCode) {
case 9: return 3;
case 10: return 10;
case 11: return 92.6;
case 12: return 185.2;
case 13: return 463;
case 14: return 926;
case 15: return 1852;
case 16: return 9260;
case 17: return 18520;
// case 0: case 18: case 22: return -1;
default: return -1;
}
}

/**
* According to DO-260B Table 2-200.
*
* @param formatTypeCode the messages' format type code
* @return the derived NIC
*/
public static byte typeCodeToNIC(byte formatTypeCode) {
switch (formatTypeCode) {
case 9: case 20: return 11;
case 6: case 10: case 21: return 10;
case 7: case 11: return 8;
case 12: return 7;
case 13: return 6;
case 14: return 5;
case 15: return 4;
case 16: case 17: return 1;
// case 0: case 18: case 22: return 0;
default: return 0;
}
}

/**
* According to DO-260B Table N-8.
* @param formatTypeCode the messages' format type code
* @return the derived SIL
*/
public static byte typeCodeToSIL(byte formatTypeCode) {
switch (formatTypeCode) {
case 0: case 18: case 22: return 0;
default: return 2;
}
}
}
30 changes: 30 additions & 0 deletions src/main/java/de/serosystems/lib1090/decoding/Airspeed.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package de.serosystems.lib1090.decoding;

/**
* @author Markus Fuchs ([email protected])
*/
public final class Airspeed {

private Airspeed() {}

/**
* The 95% accuracy for horizontal velocity. We interpret the coding according to
* DO-260B Table 2-22 for all ADS-B versions.
* @return Navigation Accuracy Category for velocity according to RTCA DO-260B 2.2.3.2.6.1.5 in m/s, -1 means
* "unknown" or >10m
*/
public static double decodeNACv(byte navigationAccuracyCategory) {
switch(navigationAccuracyCategory) {
case 1:
fixje marked this conversation as resolved.
Show resolved Hide resolved
return 10;
case 2:
return 3;
case 3:
return 1;
case 4:
return 0.3F;
default:
return -1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,63 @@ public static double nacPtoEPU(byte nacPos) {
default: return -1;
}
}

/**
* According to DO-260B Table 2-74. Compatible with ADS-B version 1 and 2
* @return the airplane's length in meters; -1 for unknown
*/
public static int decodeAirplaneLength(byte airplaneLenWidth) {
switch (airplaneLenWidth) {
case 1:
return 15;
fixje marked this conversation as resolved.
Show resolved Hide resolved
case 2:
case 3:
return 25;
case 4:
case 5:
return 35;
case 6:
case 7:
return 45;
case 8:
case 9:
return 55;
case 10:
case 11:
return 65;
case 12:
case 13:
return 75;
case 14:
case 15:
return 85;
default:
return -1;
}
}

/**
* According to DO-260B Table 2-74. Compatible with ADS-B version 1 and 2.
* @return the airplane's width in meters
*/
public static double decodeAirplaneWidth(byte airplaneLenWidth) {
switch (airplaneLenWidth) {
case 1: return 23;
case 2: return 28.5;
case 3: return 34;
case 4: return 33;
case 5: return 38;
case 6: return 39.5;
case 7: return 45;
case 8: return 45;
case 9: return 52;
case 10: return 59.5;
case 11: return 67;
case 12: return 72.5;
case 13: return 80;
case 14: return 80;
case 15: return 90;
default: return -1;
}
}
}
Loading