Skip to content

Instantly share code, notes, and snippets.

@schwehr
Last active May 1, 2019 22:25
Show Gist options
  • Save schwehr/035c5d2f6d2977a45b8b3e2b0ff385c5 to your computer and use it in GitHub Desktop.
Save schwehr/035c5d2f6d2977a45b8b3e2b0ff385c5 to your computer and use it in GitHub Desktop.
Partial message 27 for aisparser
/**
* AIS Parser SDK AIS Message 27 - 'K'.
*
* <p>Copyright 2019 Google Inc. All Rights Reserved.
*
* @author Kurt Schwehr
*/
/** AIS Message 27 class Long-range Position Report */
public class Message27 extends Messages {
static final int MSG_ID = 27; // 'K'
int pos_acc; // 1 bit: Position Accuracy
int raim; // 1 bit: RAIM flag
int nav_status; // 4 bits: Navigational Status
Position pos; // 18 + 17 bits: Lat/Long in 1/10 minute
int sog; // 10 bits: Speed Over Ground in knots
int cog; // 12 bits: Course over Ground in degrees
int pos_latency; // 1 bit: 0 - less than 5 sec
int spare; // 1 bit : Spare
public int pos_acc() {
return this.pos_acc;
}
public int raim() {
return this.raim;
}
public int nav_status() {
return this.nav_status;
}
public long longitude() {
return this.pos.longitude();
}
public long latitude() {
return this.pos.latitude();
}
public int sog() {
return this.sog;
}
public int cog() {
return this.cog;
}
public int pos_latency() {
return this.spare;
}
public int spare() {
return this.spare;
}
public Message27() {
super();
}
public void parse(Sixbit six_state) throws SixbitsExhaustedException, AISMessageException {
if (six_state.bit_length() != 96) {
// Ignore invalid, but common, 168 bit messages.
throw new AISMessageException("Message 27 wrong length");
}
super.parse(MSG_ID, six_state);
this.pos_acc = (int) six_state.get(1);
this.raim = (int) six_state.get(1);
this.nav_status = (int) six_state.get(4);
this.pos = new Position();
this.pos.setLongitude((long) six_state.get(18));
this.pos.setLatitude((long) six_state.get(17));
// TODO(schwehr): Finish conversion of long lat
this.sog = (int) six_state.get(6);
this.cog = (int) six_state.get(9);
this.pos_latency = (int) six_state.get(1);
this.spare = (int) six_state.get(1);
}
}
package com.aisparser;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Tests for {@link Message27}. */
@RunWith(JUnit4.class)
public class Message27Test {
@Test
public void testParse() {
Message27 msg = new Message27();
try {
Vdm vdm_message = new Vdm();
int result = vdm_message.add("!AIVDM,1,1,,B,K815>P8=5EikdUet,0*6B");
assertEquals("vdm add failed", 0, result);
msg.parse(vdm_message.sixbit());
} catch (Exception e) {
fail(e.getMessage());
}
assertEquals("msgid", Message27.MSG_ID, msg.msgid());
assertEquals("repeat", 0, msg.repeat());
assertEquals("userid", 538005120, msg.userid());
assertEquals("pos_acc", 1, msg.pos_acc());
assertEquals("raim", 0, msg.raim());
assertEquals("nav_status", 0, msg.nav_status());
// TODO: Can't use pos
assertEquals("longitude", 214359, msg.longitude()); // -79.641667 deg
assertEquals("latitude", 14809, msg.latitude()); // 24.681667 deg
assertEquals("sog", 11, msg.sog());
assertEquals("cog", 223, msg.cog());
assertEquals("pos_latency", 0, msg.pos_latency());
assertEquals("spare", 0, msg.spare());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment