@@ -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 "\t Capabilities:\t \t " +getCapabilities ()+"\n " +
128- "\t Valid Interrogator ID:\t \t " +hasValidInterrogatorID ()+"\n " +
129- "\t Interrogator:\t \t " +tools .toHexString (getInterrogatorID ());
148+ "\t Valid Interrogator ID:\t \t " +hasValidInterrogatorCode ()+"\n " +
149+ (isSurveillanceID () ? "\t SI-Code:\t \t " : "\t II-Code:\t \t " )+
150+ getInterrogatorCode ();
130151 }
131152
132153}
0 commit comments