Skip to content

Commit 189afee

Browse files
committed
**breaking API** Distinguish SI and II Codes
AllCallReply contains either an SI or II as interrogator code, depending on the CL field. - *breaking change:* removed `getInterrogatorID()` and `hasValidInterrogatorID()` methods - added new set of methods: `getInterrogatorCode()`, `isSurveillanceID()` and `hasValidInterrogatorCode()` to be more consistent with the standard Updated to version 3.1.0 due to API changes
1 parent 01d497d commit 189afee

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.opensky-network</groupId>
66
<artifactId>libadsb</artifactId>
7-
<version>3.0.2</version>
7+
<version>3.1.0</version>
88
<packaging>jar</packaging>
99

1010
<name>libadsb</name>

src/main/java/org/opensky/example/ExampleDecoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ else if (msg.getDownlinkFormat() != 17) { // CRC failed
317317
break;
318318
case ALL_CALL_REPLY:
319319
AllCallReply allcall = (AllCallReply)msg;
320-
System.out.println("["+icao24+"]: All-call reply for "+tools.toHexString(allcall.getInterrogatorID())+
321-
" ("+(allcall.hasValidInterrogatorID()?"valid":"invalid")+")");
320+
System.out.println("["+icao24+"]: All-call reply for "+tools.toHexString(allcall.getInterrogatorCode())+
321+
" ("+(allcall.hasValidInterrogatorCode()?"valid":"invalid")+")");
322322
break;
323323
case LONG_ACAS:
324324
LongACAS long_acas = (LongACAS)msg;

src/main/java/org/opensky/libadsb/msgs/AllCallReply.java

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public class AllCallReply extends ModeSReply implements Serializable {
3131
private static final long serialVersionUID = -1156158096293306435L;
3232

3333
private byte capabilities;
34-
private byte[] interrogator; // 3 bytes
34+
private byte[] parity_interrogator; // 3 bytes
35+
private int code_label;
3536

3637
/** protected no-arg constructor e.g. for serialization with Kryo **/
3738
protected AllCallReply() { }
@@ -70,7 +71,9 @@ public AllCallReply(ModeSReply reply) throws BadFormatException {
7071
capabilities = getFirstField();
7172

7273
// extract interrogator ID
73-
interrogator = tools.xor(calcParity(), getParity());
74+
this.parity_interrogator = tools.xor(calcParity(), getParity());
75+
76+
code_label = (parity_interrogator[2]>>4)&0x7;
7477
}
7578

7679
/**
@@ -84,33 +87,50 @@ public byte getCapabilities() {
8487
* Some receivers already subtract the crc checksum
8588
* from the parity field right after reception.
8689
* In that case, use {@link #getParity()} to get the interrogator ID.<br><br>
87-
* Note: Use {@link #hasValidInterrogatorID()} to check the validity of this field.
88-
* @return the interrogator ID as a 3-byte array
90+
* Note: Use {@link #hasValidInterrogatorCode()} to check the validity of this field.
91+
* @return the interrogator code which can either be the interrogator id or the surveillance id.
92+
* Check {@link #isSurveillanceID()} for interpretation of the result.
93+
*/
94+
public byte getInterrogatorCode() {
95+
96+
switch (code_label) {
97+
case 0:
98+
case 1:
99+
return (byte) (parity_interrogator[2]&0xF);
100+
case 2:
101+
return (byte) (parity_interrogator[2]&0xF + 15);
102+
case 3:
103+
return (byte) (parity_interrogator[2]&0xF + 31);
104+
default: // 4 and >= 4 (illegal)
105+
return (byte) (parity_interrogator[2]&0xF + 47);
106+
}
107+
108+
}
109+
110+
/**
111+
* If true, {@link #getInterrogatorCode()} returns the SI-Code, otherwise it returns the II-Code.
112+
* @return true if the interrogator has a surveillance identifier, false if it has an interrogator identifier.
89113
*/
90-
public byte[] getInterrogatorID() {
91-
return interrogator;
114+
public boolean isSurveillanceID() {
115+
return code_label > 0;
92116
}
93117

94118
/**
95119
* Note: this can be used as an accurate check whether the all call reply
96120
* has been received correctly without knowing the interrogator in advance.
97121
* @return true if the interrogator ID is conformant with Annex 10 V4
98122
*/
99-
public boolean hasValidInterrogatorID() {
100-
assert(interrogator.length == 3);
123+
public boolean hasValidInterrogatorCode() {
124+
assert(parity_interrogator.length == 3);
101125

102126
// 3.1.2.3.3.2
103127
// the first 17 bits have to be zero
104-
if (interrogator[0] != 0 ||
105-
interrogator[1] != 0 ||
106-
(interrogator[2]&0x80) != 0)
128+
if (parity_interrogator[0] != 0 || parity_interrogator[1] != 0 || (parity_interrogator[2]&0x80) != 0)
107129
return false;
108130

109-
int cl = (interrogator[2]>>4)&0x7;
110-
111131
// 3.1.2.5.2.1.3
112132
// code label is only defined for 0-4
113-
if (cl>4) return false;
133+
if (code_label > 4) return false;
114134

115135
// Note: seems to be used by ACAS
116136
// int ii = interrogator[2]&0xF;
@@ -125,8 +145,9 @@ public String toString() {
125145
return super.toString()+"\n"+
126146
"All-call Reply:\n"+
127147
"\tCapabilities:\t\t"+getCapabilities()+"\n"+
128-
"\tValid Interrogator ID:\t\t"+hasValidInterrogatorID()+"\n"+
129-
"\tInterrogator:\t\t"+tools.toHexString(getInterrogatorID());
148+
"\tValid Interrogator ID:\t\t"+hasValidInterrogatorCode()+"\n"+
149+
(isSurveillanceID() ? "\tSI-Code:\t\t" : "\tII-Code:\t\t")+
150+
getInterrogatorCode();
130151
}
131152

132153
}

0 commit comments

Comments
 (0)