// 7k Data Format Definintions.
// NF and DRF definitions are based on protocol version 4

// 22-July-04 - Add 7511 "Console Active" message definition
//              (moved from 7k_YS2000.h, where it used to be
//              the 7911 message. -JSK
// 05 Nov 04    Update to 0.54 DFD   PR

#if !defined(DEFINITIONS7K)
#define DEFINITIONS7K

#define FILE_VERSION 54 // DFD 0.54

#define PROTOCOL_VERSION 5  // DFD 0.54
#define RECORDS_VERSION  1  // DFD 0.54 

#define     _7KINFO_MAX_RECORDTYPES    30
#define     _7KINFO_MAX_DEVICES        10 

#pragma pack(1)

// Time message
typedef struct tagTIME_7K
{ 
	WORD          year;                           // 
	WORD          day;                            //
	float         seconds;                        //
	BYTE          hours;                          //
	BYTE          minutes;                        //
} TIME_7K;

// Data Record Frame - DRF
typedef struct tagRECORD_FRAME
{ 
	WORD				version;                    //	version of the frame protocol, 1, 2, 3, or 4
	WORD				offset;                     //	offest in bytes from start of sync pattern to start of data section
	DWORD				sync_pattern;               //	
	DWORD				size;                       //
	DWORD				offset_optional;            //
	DWORD				identifier_optional;        //
	TIME_7K				time_stamp;                 //
	WORD				records_version;            //
	DWORD				record_type;                //
	DWORD				device_identifier;          //
	WORD				reserved2;					//
	WORD				system_enumerator;          //
	DWORD				record_count;               //
	WORD				flags;                      //
	WORD				reserved3;                  //
	DWORD				reserved4;					//	millisecond time stamp
	DWORD				total_records;				//	total number of records in fragmented data record set, if appropriate flag is set
	DWORD				fragment_number;			//  fragment number if appropriate flag is set
} RECORD_FRAME;

// Network Frame - NF
typedef struct tagNETWORK_FRAME
{
	WORD    version;                              //
	WORD    offset;                               //
	DWORD   total_packets;                        //
	WORD    total_records;                        //
	WORD    transmission_identifier;              //
	DWORD   packet_size;                          //
	DWORD   total_size;                           //
	DWORD   sequence_number;                      //
	DWORD   destination_device_identifier;        // 0 Unspecified, 0xFFFFFFFF Not used, any other number is a valid address.
	WORD    destination_system_enumerator;        // Destination enumerator unless destination device identifier is unspecified or not used. 
	WORD    source_system_enumerator;             // Source enumerator unless source device identifier is unspecified or not used. 
	DWORD   source_device_identifier;             // 0 Unspecified, 0xFFFFFFFF Not used, any other number is a valid address.
} NETWORK_FRAME;


// Sensor offset position information
typedef struct tagR1000
{
	float offset_x;
	float offset_y;
	float offset_z;
	float water_level;
} R1000;

typedef struct tagR1001
{
	float offset_x;
	float offset_y;
	float offset_z;
	float roll;
	float pitch;
	float yaw;
} R1001;

typedef struct tagR1002 // 1002 Calibrated Sensor Offset Position
{
	float offset_x;
	float offset_y;
	float offset_z;
	float roll;
	float pitch;
	float yaw; 
} R1002;

typedef struct tagR1003 // 1003 Position
{
	DWORD	datum_id;
	float   latency;
	double  latitude_northing;
	double  longitude_easting;
	double  height;
	BYTE    position_type_flag;
	BYTE    utm_zone;
	BYTE    quality_flag;
	BYTE	position_method;
} R1003;

typedef struct tagR1004 // 1004 Custom Attitude Information
{
	BYTE	field_mask;
	BYTE	reserved;
	WORD	samples;
	float	frequency;
} R1004;

typedef struct tagR1005	// 1005 Tide
{
	float	tide;
	WORD	source;
	BYTE	flags;
	WORD	gauge_id;
	DWORD	datum_id;
	float	latency;
	double	latitude_northing;
	double	longitude_easting;
	double	height;
	BYTE	position_type;
	BYTE    utm_zone;
} R1005;

typedef struct tagR1006	// 1006 Altitude
{
	float	distance;
} R1006;

typedef struct tagR1007	// 1007 Motion Over Ground
{
	BYTE	field_mask;
	BYTE	reserved;
	WORD	number_fields;
	float	frequency;
} R1007;

typedef struct tagR1008 // 1008 Depth
{
	BYTE	depth_descriptor;
	BYTE	correction_flag;
	WORD	reserved;
	float	depth;
} R1008;

typedef struct tagR1009	// 1009 SVP
{
	BYTE	position_flag;
	BYTE	reserved1;
	WORD	reserved2;
	double	latitude;
	double	longitude;
	DWORD	samples;
} R1009;

typedef struct tagR1009SVPDATA
{
	float	depth;
	float	sound_velocity;
} R1009SVPDATA;

typedef struct tagR1010	// 1010 CTD
{
	float   frequency;
	BYTE    sound_velocity_source_flag;
	BYTE    sound_velocity_algorithm;
	BYTE    conductivity_flag;
	BYTE    pressure_flag;
	BYTE    position_flag;
	BYTE    sample_content_validity;
	WORD    reserved;
	double  latitude;
	double  longitude;
	float   sample_rate;
	DWORD   samples;
} R1010;

typedef struct tagR1010CTDDATA
{
	float	conductivity_salinity;
	float	water_temp;
	float	pressure_depth;
	float	sound_velocity;
	float	absorption;
} R1010CTDDATA;

typedef struct tagR1011	// 1011 Geodesy
{
	BYTE	spheroid_name[32];
	double	semi_major_axis;
	double	inverse_flattening;
	BYTE	reserved1[16];
	BYTE	datum_name[32];
	DWORD	data_calculation_method;
	BYTE	parameter_transformation;
	double	shift_x;
	double	shift_y;
	double	shift_z;
	double	rotation_x;
	double	rotation_y;
	double	rotation_z;
	double	scale;
	BYTE	reserved2[35];
	BYTE	grid_name[32];
	BYTE	grid_distance_units;
	BYTE	grid_angular_units;
	double	latitude_of_origin;
	double	central_meridian;
	double	false_easting;
	double	false_northing;
	double	central_scale_factor;
	LONG	custom_id;
	BYTE	reserved3[50];
} R1011;

typedef struct tagR1012 // 1012 Roll Pitch Heave
{
	float	roll;
	float	pitch;
	float	heave;
} R1012;

typedef struct tagR1013	// 1013 Heading
{
	float	heading;
} R1013;

typedef struct tagR1014 // 1014 Survey Line
{
	WORD	way_point;
	WORD	position_type;
	float	radius;
	BYTE	line_name[64];
} R1014;

typedef struct tagR1015 // 1015 Navigation
{
//	WORD	length_datum;
//	BYTE	datum[256];
	BYTE	vertical_reference;
	double	latitude;
	double	longitude;
	float	horz_accuracy;
	float	vessel_height;
	float	height_accuracy;
	float	speed_over_ground;
	float	course_over_ground;
	float	heading;
} R1015;

typedef struct tagR1016 // 1016 Attitude
{
	BYTE	number_sets;
} R1016;

typedef struct tagR1016DATA
{
	WORD	time_difference;	// milliseconds
	float	roll;				// radians
	float	pitch;				// "
	float	heave;				// "
	float	heading;			// "
} R1016DATA;

typedef struct	R1050
{
	BYTE	reserved[16];	
} R1050;

typedef struct tagR1200	// 1200 Generic Side Scan Sonar
{
	DWORD	ping_number;
	DWORD	number_of_channels;
	DWORD	total_bytes;
	DWORD	data_type;
} R1200;

typedef struct tagR1200CH	// 1200 Channel Header
{
	BYTE	channel_number;
	BYTE	channel_type;
	BYTE	data_type;
	BYTE	polarity;
	BYTE	bytes_sample;
	BYTE	reserved1[3];
	DWORD	number_of_samples;
	DWORD	start_time;
	DWORD	sample_interval;
	float	range;
	float	voltage;
	BYTE	channel_name[16];
	WORD	custom_descriptor;
	BYTE	reserved2[18];
} R1200CH;

typedef struct tagR2000	// 2000 XYZ Data
{
	float	heading;
	DWORD	number_of_frames;
} R2000;

typedef struct tagR2000XYZDATA	// 2000 XYZ Data
{
	TIME_7K	time;
	double	x;
	double	y;
	double	z;
	float	tide;
	float	height;
	float	heave;
	BYTE	reserved[4];
} R2000XYZDATA;

// Volatile data
typedef struct tagR7000
{
	ULARGE_INTEGER   serial_number;               //
	DWORD            ping_number;
	WORD			 multiping_sequence;
	float            frequency;
	float            sample_rate;
	float            receiver_bandwidth;
	float            pulse_width;
	DWORD            pulse_type;
	DWORD            pulse_envelope_type;
	float            pulse_envelope_parameter;
	DWORD            pulse_reserved;
	float            max_ping_rate;
	float            ping_period;
	float            range;
	float            power;
	float            gain;
	DWORD            control_flags;
	DWORD            projector_magic_number;
	float            projector_beam_steer_x;  
	float            projector_beam_steer_z;	
	float            projector_beam_width_x;
	float            projector_beam_width_z;
	float            projector_beam_focal_point;
	DWORD            projector_beam_weighting_type;
	float            projector_beam_weighting_parameter;
	DWORD            transmit_flags;
	DWORD            hydrophone_magic_number;
	DWORD            hydrophone_beam_weighting_type;
	float            hydrophone_beam_weighting_parameter;
	DWORD            receive_flags;
	float			 receive_beam_width;
	float            bottom_detection_info1;
	float            bottom_detection_info2;
	float            bottom_detection_info3;
	float            bottom_detection_info4;
	float            absorption;
	float            sound_velocity;
	float            spreading_loss;
	WORD			 reserved;
} R7000;

// Configuration
typedef struct tagR7001
{
	ULARGE_INTEGER   serial_number;               //
	DWORD            systems;
} R7001;

// Configuration
typedef struct tagR7001MODULEINFO
{
	DWORD            unique_identifier;               //
	BYTE             string[64];
	ULARGE_INTEGER   serial_number;
	DWORD            info_length;
} R7001MODULEINFO;

// Match filter
typedef struct tagR7002
{
	ULARGE_INTEGER   serial_number;               //
	DWORD            ping_number;
	DWORD            operation;
	float            start_frequency;
	float            stop_frequency;
} R7002;

// Volatile data
typedef struct tagR7004
{
	ULARGE_INTEGER   serial_number;               //
	DWORD            beams;
} R7004;

// Calibration data
typedef struct tagR7005
{
	ULARGE_INTEGER   serial_number;               //
	WORD             elements;             
} R7005;


// Bathymetric data
typedef struct tagR7006
{
	ULARGE_INTEGER   serial_number;               //
	DWORD            ping_number;
	WORD			 multiping_sequence;
	DWORD            beams;
	BYTE			 layer_compensation_flag;
	BYTE			 sound_velocity_flag;
	float			 sound_velocity;
} R7006;

// Imagery data
typedef struct tagR7007
{
	ULARGE_INTEGER   serial_number;               //
	DWORD            ping_number;
	WORD			 multiping_sequence;
	float            beam_position;
	DWORD            control;
	DWORD            samples;
	float            port_beam_width_y;
	float            port_beam_width_z;
	float            star_beam_width_y;
	float            star_beam_width_z;
	float            port_beam_steer_angle_y;
	float            port_beam_steer_angle_z;
	float            star_beam_steer_angle_y;
	float            star_beam_steer_angle_z;
	WORD             beams_per_side;
	WORD             beam;
	char             bytes_per_sample;
	char             data_type;
} R7007;

// Beam data
typedef struct tagR7008
{
	ULARGE_INTEGER   serial_number;               //
	DWORD            ping_number;
	WORD			 multiping_sequence;
	WORD             beams;
	WORD             reserved1;
	DWORD            samples;
	char             subset_flag;
	char             rowcolumn_flag;
	WORD             sample_header_identifier;
	DWORD            sample_type;
} R7008;

typedef struct tagR7009 // vertical depth
{
	float	frequency;
	DWORD	ping_number;
	WORD	multiping_sequence;
	double	latitude;
	double	longitude;
	float	heading;
	float	along_track_distance;
	float	across_track_distance;
	float	vertical_depth;
} R7009;

// Image data
typedef struct tagR7011
{
	DWORD			ping_number;
	WORD			multiping_sequence;
	DWORD			width;
	DWORD			height;
	WORD			color_depth;            // In bytes.
	WORD			rotation_flag;
	WORD			compression_algorithm;	// reserved for compression algorithms		
} R7011;

typedef struct tagR7022  // 7KCenter version string
{
	char			version[32];
} R7022;

typedef struct tagR7030 // sonar installation parameters
{
	float			frequency;
	WORD			length_firmware;
	BYTE			firmware_version[128];
	WORD			length_software;
	BYTE			software_version[128];
	WORD			length_software7k;
	BYTE			software7k_version[128];
	WORD			length_protocol;
	BYTE			record_protocol[128];
	float			transmit_array_x;
	float			transmit_array_y;
	float			transmit_array_z;
	float			transmit_array_roll;
	float			transmit_array_pitch;
	float			transmit_array_heading;
	float			receive_array_x;
	float			receive_array_y;
	float			receive_array_z;
	float			receive_array_roll;
	float			receive_array_pitch;
	float			receive_array_heading;
	float			motion_sensor_x;
	float			motion_sensor_y;
	float			motion_sensor_z;
	float			motion_roll_calibration;
	float			motion_pitch_calibration;
	float			motion_heading_calibration;
	WORD			motion_sensor_delay;
	float			position_sensor_x;
	float			position_sensor_y;
	float			position_sensor_z;
	WORD			position_sensor_delay;
	float			water_line_v_offset;
} R7030;

// System events
typedef struct tagR7050
{
	ULARGE_INTEGER   serial_number;               //
	DWORD            events;
} R7050;

typedef struct tagRD7050
{
    WORD             event_type;
    WORD             event_identifier;
    DWORD            device_identifier;           //
    WORD             system_enumerator;           //
    WORD             message_length;
    TIME_7K          time_stamp; 
} RD7050;


// System message
typedef struct tagR7051
{
    ULARGE_INTEGER	serial_number;      // sonar id, serial number
    WORD			event_id;			// 0 = success, 1 = info, 2 = warning, 3 = error
    WORD			size;				// message length in bytes
    WORD			event_identifier;	// should be 0, currently undefined
} R7051;

typedef struct tagR7060	// 7060 Target data
{
	DWORD		local_track_id;
	DWORD		system_track_id;
	TIME_7K		time_of_contact;
	WORD		datum_id;
	float		position_latency;
	double		latitude_northing;
	double		longitude_easting;
	BYTE		utm_zone;
	double		height;
	WORD		position_type_flag;
	WORD		classification_type;
	float		bearing_to_target;
	DWORD		bearing_flag;
	float		range_to_target;
	float		holding_time;
	DWORD		detection_method;
	float		snr;
	float		target_strength;
	DWORD		confidence;
	float		altitude;
	float		depth;
	float		speed;
	float		heading;
	BYTE		reserved[16];
	DWORD       target_text_size;
} R7060;

// File header
typedef struct tagR7200
{
    BYTE        file_identifier[16];
    WORD        version_number;
    WORD        reserved;
    BYTE        session_identifier[16];
    DWORD       rd_size;
    DWORD       subsystems;
    BYTE        recording_name[64];
    BYTE        recording_program_version[16];
    BYTE        user_name[64];
    BYTE        notes[128];
} R7200;

typedef struct tagR7200DEVICE
{
	DWORD		device_id;
	WORD	    system_enumerator;
} R7200DEVICE;

typedef struct tagR7200_OD 
{
   DWORD			dwSize;
   LARGE_INTEGER	liOffset;
} R7200_OD;

typedef struct tagR7300
{
   DWORD			dwSize;
   WORD			wVersion;
   DWORD			dwNumRecords;
   DWORD			dwReserved;
} R7300;


typedef struct tagR7300DATA 
{
   DWORD			   dwSize;
   LARGE_INTEGER	liOffset;
   WORD				record_type;         // these five member names' are identical
   WORD				device_identifier;   // to the correpsonding members in the
   WORD				system_enumerator;   // RECORD_FRAME structure
   TIME_7K			time_stamp;
   DWORD			   record_count;
   WORD				ReservedWords[8];
} R7300DATA;


// Time message
typedef struct tagR7400
{
	char			leap_second;                          
	BYTE			pulse_flag;                           
	WORD			port_identifier;                      
	DWORD			reserved1;
	ULARGE_INTEGER	reserved2;
} R7400;

// Remote control
typedef struct tagR7500
{
	DWORD             rc_id;                      
	DWORD             ticket;
	ULARGE_INTEGER    tracking_number[2];
} R7500;

// Remote Control Ack
typedef struct tagR7501                                
{
  DWORD             ticket;
  ULARGE_INTEGER    tracking_number[2];
} R7501;

// Remote Control Nack
typedef struct tagR7502                                
{
	DWORD			ticket;
	ULARGE_INTEGER	tracking_number[2];
	DWORD			error_code;			
} R7502;

// Remote control settings.
// MODIFIED 7-July-05 - added equi-angle and more reserved fields.
typedef struct tagR7503
{
	ULARGE_INTEGER   serial_number;               
	DWORD            ping_number;
	float            frequency;
	float            sample_rate;
	float            receiver_bandwidth;
	float            pulse_width;
	DWORD            pulse_type;
	DWORD            pulse_envelope_type;
	float            pulse_envelope_parameter;
	DWORD            pulse_reserved;
	float            max_ping_rate;
	float            ping_period;
	float            range;
	float            power;
	float            gain;
	DWORD            control_flags;
	DWORD            projector_magic_number;
	float            projector_beam_steer_x;
	float            projector_beam_steer_z;
	float            projector_beam_width_x;
	float            projector_beam_width_z;
	float            projector_beam_focal_point;
	DWORD            projector_beam_weighting_type;
	float            projector_beam_weighting_parameter;
	DWORD            transmit_flags;
	DWORD            hydrophone_magic_number;
	DWORD            hydrophone_beam_weighting_type;
	float            hydrophone_beam_weighting_parameter;
	DWORD            receive_flags;
	float            bottom_detection_info1;
	float            bottom_detection_info2;
	float            bottom_detection_info3;
	float            bottom_detection_info4;
	float            absorption;
	float            sound_velocity;
	float            spreading_loss;
	WORD			     reserved;
	float			     tx_array_offset_x;
	float			     tx_array_offset_y;
	float			     tx_array_offset_z;
	float			     head_tilt_x;
	float			     head_tilt_y;
	float			     head_tilt_z;
	DWORD			     ping_on_off_state;    // 0 == off, 1 == on
   WORD             equi_distant_mode;    // 0 = equi-angle, 1 = equi-distant
   DWORD            dwReserved[20];       // filled with 0xFB in build function
} R7503;

// Generic 7-P settings
typedef struct tagR7504
{
	float  roll;
	float  pitch;
	float  heave;
	float  yaw;
	float  heading;
	float  sound_velocity;
	float  absorption;
	float  spreading_loss;
	DWORD  sequencer_control;
} R7504;

// Console active / not active
// ---------------------------
typedef struct tagR7511
{
	WORD	console_active;	// 0 == not active
} R7511;

typedef struct tagR7600
{
	float	roll;
} R7600;										// radians

typedef struct tagR7601
{
	float	pitch;								// radians
} R7601;

// Sound Velocity
typedef struct tagR7610
{
  float	sound_velocity;              // m/s
} R7610;

// Absorption
typedef struct tagR7611
{
	float	absorption;                  // dB / km
} R7611;

// Spreading loss
typedef struct tagR7612
{
	float	spreading_loss;              // dB
} R7612;

typedef struct tagR8100	// Embedded 8100 Series Sonar Data
{
	BYTE	type;
	BYTE	flags;
	WORD	data_size;
	WORD	packets;
	BYTE	reserved[10];
} R8100;

#pragma pack()

#endif