package gmt.protocol.ais;

import gmt.protocol.ais.sensor.*;

public class Message06_440_41 extends Messages {
	
	int		sequence;
	long	destid;
	int		retransmit;
	int		spare;
	int		app_id;
	
	int		sensor_static_cnt;
	SensorStatic[] sensor_static;
	
	int		sensor_gps_cnt;
	SensorGPS[] sensor_gps;
	
	int 	sensor_gyro_cnt;
	SensorGyro[] sensor_gyro;
	
	int		sensor_rudder_cnt;
	SensorRudder[] sensor_rudder;
	
	int 	sensor_engine_cnt;
	SensorEngine[] sensor_engine;
	
	int 	sensor_ballast_cnt;
	SensorBallast[] sensor_ballast;
	
	int 	sensor_wind_cnt;
	SensorWind[] sensor_wind;
	
	int		sensor_echo_cnt;
	SensorEcho[] sensor_echo;
	
	int		sensor_tilt_cnt;
	SensorTilt[] sensor_tilt;
	
	int		sensor_fire_cnt;
	SensorFire[] sensor_fire;
	
	int		sensor_speedlog_cnt;
	SensorSpeedLog[] sensor_speedlog;
	
	int		sensor_ups_cnt;
	SensorUPS[] sensor_ups;
	
	public int sequence() { return this.sequence; }
	public long destid() { return this.destid; }
	public int retransmit() { return this.retransmit; }
	public int spare() { return this.spare; }
	public int app_id() { return this.app_id; }
	
	public int sensor_static_cnt() { return this.sensor_static_cnt; }
	public SensorStatic sensor_static(int idx) { return this.sensor_static[idx]; }
	
	public int sensor_gps_cnt() { return this.sensor_gps_cnt; }
	public SensorGPS sensor_gps(int idx) { return this.sensor_gps[idx]; }
	
	public int sensor_gyro_cnt() {return this.sensor_gyro_cnt; }
	public SensorGyro sensor_gyro(int idx) { return this.sensor_gyro[idx]; }
	
	public int sensor_rudder_cnt() { return this.sensor_rudder_cnt; }
	public SensorRudder sensor_rudder(int idx) { return this.sensor_rudder[idx]; }
	
	public int sensor_engine_cnt() { return this.sensor_engine_cnt; }
	public SensorEngine sensor_engine(int idx) { return this.sensor_engine[idx]; }
	
	public int sensor_ballast_cnt() { return this.sensor_ballast_cnt; }
	public SensorBallast sensor_ballast(int idx) { return this.sensor_ballast[idx]; }
	
	public int sensor_wind_cnt() { return this.sensor_wind_cnt; }
	public SensorWind sensor_wind(int idx) { return this.sensor_wind[idx]; }
	
	public int sensor_tilt_cnt() { return this.sensor_tilt_cnt; }
	public SensorTilt sensor_tilt(int idx) { return this.sensor_tilt[idx]; }
	
	public int sensor_fire_cnt() { return this.sensor_fire_cnt; }
	public SensorFire sensor_fire(int idx) { return this.sensor_fire[idx]; }
	
	public int sensor_speedlog_cnt() { return this.sensor_speedlog_cnt; }
	public SensorSpeedLog sensor_speedlog(int idx) { return this.sensor_speedlog[idx]; }
	
	public int sensor_ups_cnt() { return this.sensor_ups_cnt; }
	public SensorUPS sensor_ups(int idx) { return this.sensor_ups[idx]; }
	
	public Message06_440_41() {
		super();
		
		sensor_static_cnt = 0;
		sensor_static = new SensorStatic[8];
		
		sensor_gps_cnt = 0;
		sensor_gps = new SensorGPS[8];
		
		sensor_gyro_cnt = 0;
		sensor_gyro = new SensorGyro[8];
		
		sensor_rudder_cnt = 0;
		sensor_rudder = new SensorRudder[8];
		
		sensor_engine_cnt = 0;
		sensor_engine = new SensorEngine[8];
		
		sensor_ballast_cnt = 0;
		sensor_ballast = new SensorBallast[8];
		
		sensor_wind_cnt = 0;
		sensor_wind = new SensorWind[8];
		
		sensor_echo_cnt = 0;
		sensor_echo = new SensorEcho[8];
		
		sensor_tilt_cnt = 0;
		sensor_tilt = new SensorTilt[8];
		
		sensor_fire_cnt = 0;
		sensor_fire = new SensorFire[8];
		
		sensor_speedlog_cnt = 0;
		sensor_speedlog = new SensorSpeedLog[8];
		
		sensor_ups_cnt = 0;
		sensor_ups = new SensorUPS[8];
	}
	
	public void parse( Sixbit six_state )
			throws SixbitsExhaustedException, AISMessageException
	{
//		if (six_state.bit_length() != 424 )
//			throw new AISMessageException("Message 5 wrong length");
		
		super.parse( 6, six_state );
    
		this.sequence 	= (int)  six_state.get( 2 );
		this.destid   	= (long) six_state.get( 30 );
		this.retransmit = (int)  six_state.get( 1 );
		this.spare 		= (int)  six_state.get( 1 );
		this.app_id 	= (int)  six_state.get( 16 );
			
	    int len = six_state.length() * 6; 
	    
	    len = len - 88;
	    
	    int sensortype;
	    int idx;
	   
	    
	    while (len >= 155) {	    	
	    	sensortype = (int) six_state.get(4);
	    	
	    	switch(sensortype) {
	    	case(0) :
	    		idx = sensor_static_cnt;
	    		sensor_static[idx].setSensorType(sensortype);
	    		sensor_static[idx].setUtcDay(		(int) six_state.get(  5 ) );
	    		sensor_static[idx].setUtcHour(		(int) six_state.get(  5 ) );
	    		sensor_static[idx].setUtcMinute(	(int) six_state.get(  6 ) );
	    		sensor_static[idx].setUtcSecond(	(int) six_state.get(  6 ) );
	    		sensor_static[idx].setSequence( 	(int) six_state.get( 10 ) );	    		
	    		
	    		sensor_static[idx].setName(six_state.get_string(12));
	    		sensor_static[idx].setStatus(		(int) six_state.get(  4 ) );
	    		sensor_static[idx].setSpare(		(int) six_state.get(  3 ) );
	    		
	    		sensor_static_cnt = sensor_static_cnt + 1;	    		
	    		break;
	    	case(1) :
	    		idx = sensor_gps_cnt;
		    	sensor_gps[idx].setSensorType(sensortype);
		    	sensor_gps[idx].setUtcDay(		(int) six_state.get(  5 ) );
		    	sensor_gps[idx].setUtcHour(		(int) six_state.get(  5 ) );
		    	sensor_gps[idx].setUtcMinute(	(int) six_state.get(  6 ) );
		    	sensor_gps[idx].setUtcSecond(	(int) six_state.get(  6 ) );
		    	sensor_gps[idx].setSequence( 	(int) six_state.get( 10 ) );
		    	
		    	sensor_gps[idx].setLongitude(	(int) six_state.get( 28 ));
		    	sensor_gps[idx].setLatitude(	(int) six_state.get( 27 ));
		    	sensor_gps[idx].setSog(			(int) six_state.get( 10 ));
		    	sensor_gps[idx].setCog(			(int) six_state.get( 12 ));
		    	sensor_gps[idx].setQulity(		(int) six_state.get(  2 ));
		    	
		    	sensor_gps_cnt = sensor_gps_cnt + 1;
	    		break;
	    	case(2) :
	    		idx = sensor_gyro_cnt;
	    		sensor_gyro[idx].setSensorType(sensortype);
	    		sensor_gyro[idx].setUtcDay(		(int) six_state.get(  5 ) );
	    		sensor_gyro[idx].setUtcHour(	(int) six_state.get(  5 ) );
	    		sensor_gyro[idx].setUtcMinute(	(int) six_state.get(  6 ) );
	    		sensor_gyro[idx].setUtcSecond(	(int) six_state.get(  6 ) );
	    		sensor_gyro[idx].setSequence( 	(int) six_state.get( 10 ) );
	    		
	    		sensor_gyro[idx].setTrueHeading((int) six_state.get( 12 ) );
	    		six_state.get(67);
	    		
	    		sensor_gyro_cnt = sensor_gyro_cnt + 1;
	    		break;
	    	case(3) :
	    		idx = sensor_rudder_cnt;
	    		sensor_rudder[idx].setSensorType(sensortype);
	    		sensor_rudder[idx].setUtcDay(	(int) six_state.get(  5 ) );
	    		sensor_rudder[idx].setUtcHour(	(int) six_state.get(  5 ) );
	    		sensor_rudder[idx].setUtcMinute((int) six_state.get(  6 ) );
	    		sensor_rudder[idx].setUtcSecond((int) six_state.get(  6 ) );
	    		sensor_rudder[idx].setSequence( (int) six_state.get( 10 ) );
	    		
	    		sensor_rudder[idx].setSign(		(int) six_state.get(  1 ) );
	    		sensor_rudder[idx].setAngle(	(int) six_state.get( 10 ) );
	    		six_state.get(68);
	    		
	    		sensor_rudder_cnt = sensor_rudder_cnt + 1;	    		
	    		break;
	    	case(4) :
	    		idx = sensor_engine_cnt;
	    		sensor_engine[idx].setSensorType(sensortype);
	    		sensor_engine[idx].setUtcDay(	(int) six_state.get(  5 ) );
	    		sensor_engine[idx].setUtcHour(	(int) six_state.get(  5 ) );
	    		sensor_engine[idx].setUtcMinute((int) six_state.get(  6 ) );
	    		sensor_engine[idx].setUtcSecond((int) six_state.get(  6 ) );
	    		sensor_engine[idx].setSequence( (int) six_state.get( 10 ) );
	    		
	    		sensor_engine[idx].setRPM(		(int) six_state.get( 12 ) );
	    		six_state.get(67);
	    		
	    		sensor_engine_cnt = sensor_engine_cnt +1;
	    		break;
	    	case(5) :
	    		idx = sensor_ballast_cnt;
    			sensor_ballast[idx].setSensorType(sensortype);
    			sensor_ballast[idx].setUtcDay(	 (int) six_state.get(  5 ) );
    			sensor_ballast[idx].setUtcHour(	 (int) six_state.get(  5 ) );
    			sensor_ballast[idx].setUtcMinute((int) six_state.get(  6 ) );
    			sensor_ballast[idx].setUtcSecond((int) six_state.get(  6 ) );
    			sensor_ballast[idx].setSequence( (int) six_state.get( 10 ) );
    			
    			sensor_ballast[idx].setDepth(	 (int) six_state.get( 13 ) );
    			six_state.get(66);
    			
		    	sensor_ballast_cnt = sensor_ballast_cnt + 1;
	    		break;
	    	case(6) :
	    		idx = sensor_wind_cnt;
				sensor_wind[idx].setSensorType(sensortype);
				sensor_wind[idx].setUtcDay(	 	 		(int) six_state.get(  5 ) );
				sensor_wind[idx].setUtcHour(	 		(int) six_state.get(  5 ) );
				sensor_wind[idx].setUtcMinute(	 		(int) six_state.get(  6 ) );
				sensor_wind[idx].setUtcSecond(	 		(int) six_state.get(  6 ) );
				sensor_wind[idx].setSequence( 	 		(int) six_state.get( 10 ) );
				
				sensor_wind[idx].setTrueDirection(		(int) six_state.get(  9 ) );
				sensor_wind[idx].setTrueSpeed(			(int) six_state.get(  7 ) );
				sensor_wind[idx].setRelativeDirection(	(int) six_state.get(  9 ) );
				sensor_wind[idx].setRelativeSpeed(		(int) six_state.get(  7 ) );
				six_state.get(47);
				
				sensor_wind_cnt = sensor_wind_cnt + 1;
	    		break;
	    	case(7) :
	    		idx = sensor_echo_cnt;
				sensor_echo[idx].setSensorType(sensortype);
				sensor_echo[idx].setUtcDay(	  (int) six_state.get(  5 ) );
				sensor_echo[idx].setUtcHour(  (int) six_state.get(  5 ) );
				sensor_echo[idx].setUtcMinute((int) six_state.get(  6 ) );
				sensor_echo[idx].setUtcSecond((int) six_state.get(  6 ) );
				sensor_echo[idx].setSequence( (int) six_state.get( 10 ) );
				
				sensor_echo[idx].setSounding( (int) six_state.get( 10 ) );
				six_state.get(69);
				
				sensor_echo_cnt = sensor_echo_cnt + 1;
	    		break;
	    	case(8) :
	    		idx = sensor_tilt_cnt;
				sensor_tilt[idx].setSensorType(sensortype);
				sensor_tilt[idx].setUtcDay(	 	(int) six_state.get(  5 ) );
				sensor_tilt[idx].setUtcHour(	(int) six_state.get(  5 ) );
				sensor_tilt[idx].setUtcMinute(	(int) six_state.get(  6 ) );
				sensor_tilt[idx].setUtcSecond(	(int) six_state.get(  6 ) );
				sensor_tilt[idx].setSequence( 	(int) six_state.get( 10 ) );
				
				sensor_tilt[idx].setSign_Roll1(	(int) six_state.get(  1 ) );
				sensor_tilt[idx].setRoll1(		(int) six_state.get(  8 ) );				
				sensor_tilt[idx].setSign_Pitch1((int) six_state.get(  1 ) );
				sensor_tilt[idx].setPitch1(		(int) six_state.get(  8 ) );
				
				sensor_tilt[idx].setSign_Roll2(	(int) six_state.get(  1 ) );				
				sensor_tilt[idx].setRoll2(		(int) six_state.get(  8 ) );				
				sensor_tilt[idx].setSign_Pitch2((int) six_state.get(  1 ) );
				sensor_tilt[idx].setPitch2(		(int) six_state.get(  8 ) );
				
				sensor_tilt[idx].setSign_Roll3(	(int) six_state.get(  1 ) );
				sensor_tilt[idx].setRoll3(		(int) six_state.get(  8 ) );				
				sensor_tilt[idx].setSign_Pitch3((int) six_state.get(  1 ) );
				sensor_tilt[idx].setPitch3(		(int) six_state.get(  8 ) );
				
				sensor_tilt[idx].setSign_Roll4(	(int) six_state.get(  1 ) );
				sensor_tilt[idx].setRoll4(		(int) six_state.get(  8 ) );				
				sensor_tilt[idx].setSign_Pitch4((int) six_state.get(  1 ) );
				sensor_tilt[idx].setPitch4(		(int) six_state.get(  8 ) );
				
				six_state.get(3);
				
				sensor_tilt_cnt = sensor_tilt_cnt + 1;
	    		break;
	    	case(9) :
	    		idx = sensor_fire_cnt;
				sensor_fire[idx].setSensorType(sensortype);
				sensor_fire[idx].setUtcDay(	 	(int) six_state.get(  5 ) );
				sensor_fire[idx].setUtcHour(	(int) six_state.get(  5 ) );
				sensor_fire[idx].setUtcMinute(	(int) six_state.get(  6 ) );
				sensor_fire[idx].setUtcSecond(	(int) six_state.get(  6 ) );
				sensor_fire[idx].setSequence( 	(int) six_state.get( 10 ) );
				
				sensor_fire[idx].setStatus(		(int) six_state.get(  4 ) );
				sensor_fire[idx].setFireType(	(int) six_state.get(  1 ) );
				sensor_fire[idx].setAlarm(	 	(int) six_state.get(  2 ) );				
				six_state.get(72);
				
				sensor_fire_cnt = sensor_fire_cnt + 1;
	    		break;
	    	case(10) :
	    		idx = sensor_speedlog_cnt;
	    		sensor_speedlog[idx].setSensorType(sensortype);
	    		sensor_speedlog[idx].setUtcDay(	 	(int) six_state.get(  5 ) );
	    		sensor_speedlog[idx].setUtcHour(	(int) six_state.get(  5 ) );
	    		sensor_speedlog[idx].setUtcMinute(	(int) six_state.get(  6 ) );
	    		sensor_speedlog[idx].setUtcSecond(	(int) six_state.get(  6 ) );
	    		sensor_speedlog[idx].setSequence( 	(int) six_state.get( 10 ) );
				
	    		sensor_speedlog[idx].setStw(		(int) six_state.get( 10 ) );
	    		sensor_speedlog[idx].setSOG(		(int) six_state.get( 10 ) );
				six_state.get(59);
				
				sensor_speedlog_cnt = sensor_speedlog_cnt + 1;
	    		break;
	    	case(11) :
	    		idx = sensor_ups_cnt;
	    		sensor_ups[idx].setSensorType(sensortype);
	    		sensor_ups[idx].setUtcDay(	 	(int) six_state.get(  5 ) );
	    		sensor_ups[idx].setUtcHour(	 	(int) six_state.get(  5 ) );
	    		sensor_ups[idx].setUtcMinute(	(int) six_state.get(  6 ) );
	    		sensor_ups[idx].setUtcSecond(	(int) six_state.get(  6 ) );
	    		sensor_ups[idx].setSequence( 	(int) six_state.get( 10 ) );
				
	    		sensor_ups[idx].setBattery(		(int) six_state.get( 10 ) );
	    		sensor_ups[idx].setRemainTime(	(int) six_state.get( 28 ) );
				six_state.get(41);
				
				sensor_ups_cnt = sensor_ups_cnt + 1;
	    		break;
	    	}	    	
	    	len = len - 115;
	    }
	}
	
 }
