package gmt.protocol.ais;

/**
 * AIS Message 27 class
 * Long-range automatic identification system broadcast message
 * 
 */
public class Message27 extends Messages {    
    int            pos_acc;        //  1 bit  : Position Accuracy
    int            raim;           //  1 bit  : RAIM flag
    int            nav_status;     //  4 bits : Navigational Status
    Position       pos;      // Lat(28bit)/Long(27bit) 1/10000 minute
    int            sog;            //  6 bits : Speed Over Ground
    int            cog;            //  9 bits : Course over Ground
    int            pos_latency;    //  1 bit  : Position Latency
    int            spare;          //  1 bits : 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.pos_latency; }
    public int spare() { return this.spare; }
        
	public Message27()
	{
		super();
	}
	
	public void parse( Sixbit six_state )
		throws SixbitsExhaustedException, AISMessageException
	{
		int length = six_state.bit_length();
		if (length != 96)
			throw new AISMessageException("Message 24 wrong length");
		
		super.parse( 27, 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( 28 ));
	    this.pos.setLatitude((long)  six_state.get( 27 ));
	    
	    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 );

	}
}
