Skip to content

Commit

Permalink
some documenting, cleanup and version increase
Browse files Browse the repository at this point in the history
  • Loading branch information
risty committed Nov 16, 2017
1 parent fd899d7 commit c01beeb
Show file tree
Hide file tree
Showing 14 changed files with 271 additions and 209 deletions.
3 changes: 3 additions & 0 deletions SonarLogAPI/CSV/CSVLogData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using System.Collections.Generic;
using System.IO;

/// <summary>
///Log data that consists of CSV entries.
/// </summary>
public class CsvLogData
{
/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion SonarLogAPI/Compass/CompassLogEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
using System;
using Primitives;

/// <inheritdoc />
/// <summary>
/// The log entry with information from compass.
/// </summary>
/// <seealso cref="http://en.wikipedia.org/wiki/Flight_dynamics_(fixed-wing_aircraft)"/>
/// <seealso cref="!:http://en.wikipedia.org/wiki/Flight_dynamics_(fixed-wing_aircraft)" />
public class CompassLogEntry : ICoordinatePointSource
{
/// <summary>
Expand Down
35 changes: 19 additions & 16 deletions SonarLogAPI/DepthAdjuster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,38 @@

using SonarLogAPI.Primitives;

/// <summary>
/// Depth adjuster.
/// </summary>
public class DepthAdjuster
{
private readonly object _syncRoot = new object();

/// <summary>
/// Base points sequence
/// Base points sequence.
/// </summary>
public IEnumerable<IDepthPointSource> BasePoints { get; set; }

/// <summary>
/// Adjustable points sequence
/// Adjustable points sequence.
/// </summary>
public IEnumerable<IDepthPointSource> AdjustablePoints { get; set; }

/// <summary>
/// Create instance of <see cref="DepthAdjuster"/>
/// Create instance of <see cref="DepthAdjuster"/>.
/// </summary>
/// <param name="basePoints">Base points sequence</param>
/// <param name="adjustablePoints">Adjustable points sequence</param>
/// <param name="basePoints">Base points sequence.</param>
/// <param name="adjustablePoints">Adjustable points sequence.</param>
public DepthAdjuster(IEnumerable<IDepthPointSource> basePoints, IEnumerable<IDepthPointSource> adjustablePoints)
{
BasePoints = basePoints;
AdjustablePoints = adjustablePoints;
}

/// <summary>
/// Ajust depth at <see cref="AdjustablePoints"/>
/// Ajust depth at <see cref="AdjustablePoints"/>.
/// </summary>
/// <returns><see cref="AdjustablePoints"/> after depth adjust</returns>
/// <returns><see cref="AdjustablePoints"/> after depth adjust.</returns>
public IEnumerable<IDepthPointSource> AdjustDepth()
{
var nearestPoint = FindNearestPoint(BasePoints, AdjustablePoints);
Expand All @@ -45,7 +48,7 @@ public IEnumerable<IDepthPointSource> AdjustDepth()
/// <summary>
/// Ajust depth at <see cref="AdjustablePoints"/> async.
/// </summary>
/// <returns><see cref="AdjustablePoints"/> after depth adjust</returns>
/// <returns><see cref="AdjustablePoints"/> after depth adjust.</returns>
public Task<IEnumerable<IDepthPointSource>> AdjustDepthAsync()
{
return Task.Run(() => AdjustDepth());
Expand All @@ -54,9 +57,9 @@ public Task<IEnumerable<IDepthPointSource>> AdjustDepthAsync()
/// <summary>
/// Find nearest points at two sequence.
/// </summary>
/// <param name="firstSequence">First points sequence</param>
/// <param name="secondSequence">Second points sequence</param>
/// <returns><see cref="NearestPointsEventArgs"/></returns>
/// <param name="firstSequence">First points sequence.</param>
/// <param name="secondSequence">Second points sequence.</param>
/// <returns><see cref="NearestPointsEventArgs"/>.</returns>
private NearestPointsEventArgs FindNearestPoint(IEnumerable<IDepthPointSource> firstSequence, IEnumerable<IDepthPointSource> secondSequence)
{
var uniqueBasePoints = firstSequence.GroupBy(point => point.Point)
Expand Down Expand Up @@ -113,11 +116,11 @@ private NearestPointsEventArgs FindNearestPoint(IEnumerable<IDepthPointSource> f
}

/// <summary>
/// Ajust depth at sequence of points/>
/// Ajust depth at sequence of points.
/// </summary>
/// <param name="innerSequence">Sequence of points to adjust depth</param>
/// <param name="ajustValue">Value to add to depth</param>
/// <returns>Sequence of points after depth adjust</returns>
/// <param name="innerSequence">Sequence of points to adjust depth.</param>
/// <param name="ajustValue">Value to add to depth.</param>
/// <returns>Sequence of points after depth adjust.</returns>
private static IEnumerable<IDepthPointSource> AdjustDepth(IEnumerable<IDepthPointSource> innerSequence, LinearDimension ajustValue)
{
var depthPointSources = innerSequence as IDepthPointSource[] ?? innerSequence.ToArray();
Expand All @@ -138,7 +141,7 @@ protected virtual void OnNearestPointFound(NearestPointsEventArgs e)
}

/// <summary>
/// EventArgs with information about two nearest points and distance between em
/// EventArgs with information about two nearest points and distance between em.
/// </summary>
public class NearestPointsEventArgs : EventArgs
{
Expand Down
2 changes: 1 addition & 1 deletion SonarLogAPI/Localization/ProjectDescriptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public class ProjectDescriptions
/// <summary>Gets copyright information.</summary>
public const string Copyright = "Copyright @ Bagrich Ivan 2016-2017";
/// <summary>Gets version information.</summary>
public const string Version = "0.4";
public const string Version = "0.5";
}
}
99 changes: 60 additions & 39 deletions SonarLogAPI/Lowrance/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

using Primitives;

/// <summary>
/// <see cref="ChannelType"/> from which frame is given.
/// </summary>
public enum ChannelType : byte
{
/// <summary>
Expand Down Expand Up @@ -293,6 +296,9 @@ public static IDictionary<int, Tuple<byte[], short, short, int, float, int, Chan
return dictionary;
}

/// <summary>
///Values, which are specific for sl2 frame type.
/// </summary>
private static IEnumerable<int> SpecificSL2FrameValues => new[]
{

Expand Down Expand Up @@ -321,6 +327,9 @@ public static IDictionary<int, Tuple<byte[], short, short, int, float, int, Chan

};

/// <summary>
/// Values, which are specific for sl3 frame type.
/// </summary>
private static IEnumerable<int> SpecificSL3FrameValues => new[]
{
/*Looking for the
Expand All @@ -340,11 +349,11 @@ public static IDictionary<int, Tuple<byte[], short, short, int, float, int, Chan
};

/// <summary>
/// Verify SL log file and create frames map
/// Verify SL log file and create frames map.
/// </summary>
/// <param name="reader"><see cref="BinaryReader"/></param>
/// <param name="readPosition">Offset of first frame (in bytes) in <see cref="BinaryReader"/>'s stream </param>
/// <param name="version"><see cref="FileVersion"/></param>
/// <param name="reader"><see cref="BinaryReader"/>.</param>
/// <param name="readPosition">Offset of first frame (in bytes) in <see cref="BinaryReader"/>'s stream.</param>
/// <param name="version"><see cref="FileVersion"/>.</param>
/// <param name="fileCreationTime">File creation time.</param>
/// <returns>Sequence(tuple) of frames offsets at reader and Timespans from logging start.</returns>
public static IEnumerable<Tuple<int, TimeSpan>> GetFramesMap(BinaryReader reader, int readPosition, FileVersion version, out DateTimeOffset fileCreationTime)
Expand Down Expand Up @@ -475,9 +484,9 @@ public static IEnumerable<Tuple<int, TimeSpan>> GetFramesMap(BinaryReader reader
}

/// <summary>
/// Read frame from Reader
/// Read frame from Reader.
/// </summary>
/// <param name="reader"><see cref="BinaryReader"/></param>
/// <param name="reader"><see cref="BinaryReader"/>.</param>
/// <param name="frameStartByteOffset">Frame offset in readers stream.</param>
/// <param name="version"><see cref="FileVersion"/>.</param>
/// <returns><see cref="Frame"/> object.</returns>
Expand Down Expand Up @@ -578,12 +587,12 @@ public static Frame ReadFrame(BinaryReader reader, int frameStartByteOffset, Fil
}

/// <summary>
/// Write sequence of frames to writer
/// Write sequence of frames to writer.
/// </summary>
/// <param name="writer"><see cref="BinaryWriter"/></param>
/// <param name="framesToWrite">Sequence of frames to write</param>
/// <param name="framesSetStartByteOffset">offset of first frame in Writers stream</param>
/// <param name="version">Outer stream version</param>
/// <param name="writer"><see cref="BinaryWriter"/>.</param>
/// <param name="framesToWrite">Sequence of frames to write.</param>
/// <param name="framesSetStartByteOffset">Offset of first frame in Writers stream.</param>
/// <param name="version">Outer stream version.</param>
public static void WriteFrames(BinaryWriter writer, List<Frame> framesToWrite, int framesSetStartByteOffset, FileVersion version)
{
switch (version)
Expand All @@ -600,6 +609,12 @@ public static void WriteFrames(BinaryWriter writer, List<Frame> framesToWrite, i
}
}

/// <summary>
/// Write sequence of SL3 frames to writer.
/// </summary>
/// <param name="writer"><see cref="BinaryWriter"/>.</param>
/// <param name="framesToWrite">Sequence of frames to write.</param>
/// <param name="framesSetStartByteOffset">Offset of first frame in Writers stream.</param>
private static void WriteSl3Frames(BinaryWriter writer, List<Frame> framesToWrite, int framesSetStartByteOffset)
{
//sort before writing
Expand All @@ -615,7 +630,7 @@ private static void WriteSl3Frames(BinaryWriter writer, List<Frame> framesToWrit
int lastSidescanCompositeChannelFrameOffset = 0;
int lastThreeDChannelFrameOffset = 0;

//take earlies date from frames and start writing from it
//take earliest date from frames and start writing from it
var firstFrameTime = framesToWrite.Select(frame => frame.DateTimeOffset).Min();
int lastFrameIndex = 0;
int timeOffsetMiliseconds = 0;
Expand Down Expand Up @@ -738,6 +753,12 @@ private static void WriteSl3Frames(BinaryWriter writer, List<Frame> framesToWrit

}

/// <summary>
/// Write sequence of SL2 frames to writer.
/// </summary>
/// <param name="writer"><see cref="BinaryWriter"/>.</param>
/// <param name="framesToWrite">Sequence of frames to write.</param>
/// <param name="framesSetStartByteOffset">Offset of first frame in Writers stream.</param>
private static void WriteSl2Frames(BinaryWriter writer, List<Frame> framesToWrite, int framesSetStartByteOffset)
{
//takes frame with channel type != ChannelType.ThreeD and sort it after
Expand All @@ -755,7 +776,7 @@ private static void WriteSl2Frames(BinaryWriter writer, List<Frame> framesToWrit
int lastSidescanCompositeChannelFrameOffset = 0;

//take earlies date from frames and start writing from it
var firstFrameTime = framesToWrite.Select(frame=> frame.DateTimeOffset).Min();
var firstFrameTime = framesToWrite.Select(frame => frame.DateTimeOffset).Min();
int lastFrameIndex = 0;
int timeOffsetMiliseconds = 0;

Expand Down Expand Up @@ -789,7 +810,7 @@ private static void WriteSl2Frames(BinaryWriter writer, List<Frame> framesToWrit
case ChannelType.SidescanComposite:
lastSidescanCompositeChannelFrameOffset = frameOffset;
break;
//sl2 cant contains ThreeD channel data
//sl2 can't contains ThreeD channel data
case ChannelType.ThreeD:
throw new ArgumentOutOfRangeException();
default:
Expand Down Expand Up @@ -878,10 +899,10 @@ private static void WriteSl2Frames(BinaryWriter writer, List<Frame> framesToWrit
}

/// <summary>
/// Converts Frames flags to two bytes
/// Converts Frames flags to two bytes.
/// </summary>
/// <param name="frame"><see cref="Frame"/></param>
/// <returns>Array of two bytes</returns>
/// <param name="frame"><see cref="Frame"/>.</param>
/// <returns>Array of two bytes.</returns>
private static byte[] TwoFlagsBytes(Frame frame)
{
var twoFlagsBytes = new byte[2];
Expand Down Expand Up @@ -950,10 +971,10 @@ private static byte[] TwoFlagsBytes(Frame frame)
}

/// <summary>
/// Gets offset map type for file version
/// Gets offset map type for file version.
/// </summary>
/// <param name="version"><see cref="SonarLogAPI.Lowrance.FileVersion"/></param>
/// <returns>Type of offset map</returns>
/// <param name="version"><see cref="SonarLogAPI.Lowrance.FileVersion"/>.</param>
/// <returns>Type of offset map.</returns>
private static Type GetOffsetsTypeForFileVersion(FileVersion version)
{
Type slType;
Expand All @@ -977,41 +998,41 @@ private static Type GetOffsetsTypeForFileVersion(FileVersion version)
}

/// <summary>
/// Parse property to enum and convert it to byte
/// Parse property to enum and convert it to byte.
/// </summary>
/// <param name="slType">Type of enum</param>
/// <param name="propertyName">Property name</param>
/// <returns>Property byte representation</returns>
/// <param name="slType">Type of enum.</param>
/// <param name="propertyName">Property name.</param>
/// <returns>Property byte representation.</returns>
private static byte GetOffset(Type slType, string propertyName)
{
return Convert.ToByte(Enum.Parse(slType, propertyName));
}

/// <summary>
/// Converts Longitude double degrees value in WGS84 to int value in Lowrance format
/// Converts Longitude double degrees value in WGS84 to int value in Lowrance format.
/// </summary>
/// <param name="longitudeWGS84">Longitude double degrees value in WGS84</param>
/// <returns>Longitude int value in Lowrance format</returns>
/// <param name="longitudeWGS84">Longitude double degrees value in WGS84.</param>
/// <returns>Longitude int value in Lowrance format.</returns>
private static int ConvertLongitudeToLowranceInt(double longitudeWGS84)
{
return Convert.ToInt32(longitudeWGS84 * _earthWGS84PolarRadius / _radConversion);
}

/// <summary>
/// Converts Longitude int value in Lowrance format to double degrees value in WGS84 format
/// Converts Longitude int value in Lowrance format to double degrees value in WGS84 format.
/// </summary>
/// <param name="lowranceIntValue">Longitude int value in Lowrance format</param>
/// <returns>Double degrees value in WGS84 format</returns>
/// <param name="lowranceIntValue">Longitude int value in Lowrance format.</param>
/// <returns>Double degrees value in WGS84 format.</returns>
private static double ConvertLongitudeToWGS84(int lowranceIntValue)
{
return lowranceIntValue / _earthWGS84PolarRadius * _radConversion;
}

/// <summary>
/// Converts <see cref="Latitude"/> double degrees value in WGS84 to int value in Lowrance(Spherical Mercator Projection) format
/// Converts <see cref="Latitude"/> double degrees value in WGS84 to int value in Lowrance(Spherical Mercator Projection) format.
/// </summary>
/// <param name="latitudeWGS84">Latitude double degrees value in WGS84</param>
/// <returns>Latitude int value in Lowrance format</returns>
/// <param name="latitudeWGS84">Latitude double degrees value in WGS84.</param>
/// <returns>Latitude int value in Lowrance format.</returns>
private static int ConvertLatitudeToLowranceInt(double latitudeWGS84)
{
var temp = latitudeWGS84 / _radConversion;
Expand All @@ -1028,10 +1049,10 @@ private static double ConvertLatitudeWGS84(int lowranceIntValue)
}

/// <summary>
/// Sets specific bit in ref byte
/// Sets specific bit in ref byte.
/// </summary>
/// <param name="refByte">Byte ref</param>
/// <param name="position">Bit position</param>
/// <param name="refByte">Byte ref.</param>
/// <param name="position">Bit position.</param>
private static void SetBitInByte(ref byte refByte, int position)
{
if (position > 7) throw new ArgumentOutOfRangeException(nameof(position));
Expand All @@ -1042,11 +1063,11 @@ private static void SetBitInByte(ref byte refByte, int position)
}

/// <summary>
/// Checks specific bit in byte set
/// Checks specific bit in byte set.
/// </summary>
/// <param name="b">Byte</param>
/// <param name="position">Bit position</param>
/// <returns>Is bit set or not</returns>
/// <param name="position">Bit position.</param>
/// <returns>Is bit set or not.</returns>
private static bool IsBitSet(byte b, int position)
{
if (position > 7) throw new ArgumentOutOfRangeException(nameof(position));
Expand Down
8 changes: 4 additions & 4 deletions SonarLogAPI/Lowrance/Header.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public static Header ReadHeader(BinaryReader reader, long headerFirstByteOffset)
{
if (reader.BaseStream.Length < headerFirstByteOffset + Lenght)
throw new ArgumentException("Stream length less then "
+ nameof(headerFirstByteOffset) + " + Header " + nameof(Lenght));
+ nameof(headerFirstByteOffset) + "+ " + nameof(Header) + " " + nameof(Lenght));

//seeking to header first byte
reader.BaseStream.Seek(headerFirstByteOffset, SeekOrigin.Begin);

Expand All @@ -106,7 +106,7 @@ public static Header ReadHeader(BinaryReader reader, long headerFirstByteOffset)
/// </summary>
/// <param name="writer"><see cref="BinaryWriter"/>.</param>
/// <param name="headerToWrite"><see cref="SonarLogAPI.Lowrance.Header"/> object to write.</param>
/// <param name="headerFirstByteOffset">Offset of <see cref="SonarLogAPI.Lowrance.Header"/> first byte</param>
/// <param name="headerFirstByteOffset">Offset of <see cref="SonarLogAPI.Lowrance.Header"/> first byte.</param>
public static void WriteHeader(BinaryWriter writer, Header headerToWrite, long headerFirstByteOffset)
{
//seeking to header first byte
Expand All @@ -117,7 +117,7 @@ public static void WriteHeader(BinaryWriter writer, Header headerToWrite, long h
writer.Write(headerToWrite.BlockSize);
//write zero from current position to lenght position
while (writer.BaseStream.Position < headerFirstByteOffset + Lenght)
writer.Write(new byte());
writer.Write(new byte());
}

public override string ToString()
Expand Down
Loading

0 comments on commit c01beeb

Please sign in to comment.