Doc comments

This commit is contained in:
mort5161 2014-11-11 17:44:02 -08:00
parent 8e6cc7b00b
commit 5f660c3343
6 changed files with 184 additions and 3 deletions

View file

@ -41,8 +41,16 @@ namespace NmeaParser
m_readSpeed = readSpeed;
}
/// <summary>
/// Gets the stream to perform buffer reads on.
/// </summary>
/// <returns></returns>
protected abstract Task<System.IO.Stream> GetStreamAsync();
/// <summary>
/// Opens the stream asynchronous.
/// </summary>
/// <returns></returns>
protected sealed async override Task<System.IO.Stream> OpenStreamAsync()
{
var stream = await GetStreamAsync();
@ -51,6 +59,11 @@ namespace NmeaParser
return m_stream;
}
/// <summary>
/// Closes the stream asynchronous.
/// </summary>
/// <param name="stream">The stream.</param>
/// <returns></returns>
protected override Task CloseStreamAsync(System.IO.Stream stream)
{
m_stream.Dispose();
@ -65,6 +78,11 @@ namespace NmeaParser
byte[] buffer = new byte[0];
System.Threading.Timer timer;
object lockObj = new object();
/// <summary>
/// Initializes a new instance of the <see cref="BufferedStream"/> class.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="readSpeed">The read speed.</param>
public BufferedStream(StreamReader stream, int readSpeed)
{
m_sr = stream;
@ -86,13 +104,46 @@ namespace NmeaParser
buffer = newBuffer;
}
}
/// <summary>
/// Gets a value indicating whether this instance can read.
/// </summary>
/// <value>
/// <c>true</c> if this instance can read; otherwise, <c>false</c>.
/// </value>
public override bool CanRead { get { return true; } }
/// <summary>
/// Gets a value indicating whether this instance can seek.
/// </summary>
/// <value>
/// <c>true</c> if this instance can seek; otherwise, <c>false</c>.
/// </value>
public override bool CanSeek { get { return false; } }
/// <summary>
/// Gets a value indicating whether this instance can write.
/// </summary>
/// <value>
/// <c>true</c> if this instance can write; otherwise, <c>false</c>.
/// </value>
public override bool CanWrite { get { return false; } }
/// <summary>
/// Flushes this instance.
/// </summary>
public override void Flush() { }
/// <summary>
/// Gets the length.
/// </summary>
/// <value>
/// The length.
/// </value>
public override long Length { get { return m_sr.BaseStream.Length; } }
/// <summary>
/// Gets or sets the position.
/// </summary>
/// <value>
/// The position.
/// </value>
/// <exception cref="System.NotSupportedException"></exception>
public override long Position
{
get { return m_sr.BaseStream.Position; }
@ -101,7 +152,13 @@ namespace NmeaParser
throw new NotSupportedException();
}
}
/// <summary>
/// Reads the specified buffer.
/// </summary>
/// <param name="buffer">The buffer.</param>
/// <param name="offset">The offset.</param>
/// <param name="count">The count.</param>
/// <returns></returns>
public override int Read(byte[] buffer, int offset, int count)
{
lock (lockObj)
@ -124,20 +181,44 @@ namespace NmeaParser
}
}
/// <summary>
/// Seeks the specified offset.
/// </summary>
/// <param name="offset">The offset.</param>
/// <param name="origin">The origin.</param>
/// <returns></returns>
/// <exception cref="System.NotSupportedException"></exception>
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException();
}
/// <summary>
/// Sets the length.
/// </summary>
/// <param name="value">The value.</param>
/// <exception cref="System.NotSupportedException"></exception>
public override void SetLength(long value)
{
throw new NotSupportedException();
}
/// <summary>
/// Writes the specified buffer.
/// </summary>
/// <param name="buffer">The buffer.</param>
/// <param name="offset">The offset.</param>
/// <param name="count">The count.</param>
/// <exception cref="System.NotSupportedException"></exception>
public override void Write(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}
/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

View file

@ -35,9 +35,16 @@ namespace NmeaParser
System.Threading.CancellationTokenSource m_cts;
TaskCompletionSource<bool> closeTask;
/// <summary>
/// Initializes a new instance of the <see cref="NmeaDevice"/> class.
/// </summary>
protected NmeaDevice()
{
}
/// <summary>
/// Opens the device connection.
/// </summary>
/// <returns></returns>
public async Task OpenAsync()
{
lock (m_lockObject)
@ -80,7 +87,15 @@ namespace NmeaParser
});
}
/// <summary>
/// Creates the stream the NmeaDevice is working on top off.
/// </summary>
/// <returns></returns>
protected abstract Task<Stream> OpenStreamAsync();
/// <summary>
/// Closes the device.
/// </summary>
/// <returns></returns>
public async Task CloseAsync()
{
if (m_cts != null)
@ -97,6 +112,11 @@ namespace NmeaParser
lock (m_lockObject)
IsOpen = false;
}
/// <summary>
/// Closes the stream the NmeaDevice is working on top off.
/// </summary>
/// <param name="stream">The stream.</param>
/// <returns></returns>
protected abstract Task CloseStreamAsync(Stream stream);
private void OnData(byte[] data)
@ -171,12 +191,22 @@ namespace NmeaParser
private Dictionary<string, Dictionary<int, Nmea.NmeaMessage>> MultiPartMessageCache
= new Dictionary<string,Dictionary<int,Nmea.NmeaMessage>>();
/// <summary>
/// Occurs when an NMEA message is received.
/// </summary>
public event EventHandler<NmeaMessageReceivedEventArgs> MessageReceived;
/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
public void Dispose()
{
Dispose(true);
}
/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="force"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected virtual void Dispose(bool force)
{
if (m_stream != null)
@ -191,16 +221,43 @@ namespace NmeaParser
}
}
/// <summary>
/// Gets a value indicating whether this device is open.
/// </summary>
/// <value>
/// <c>true</c> if this instance is open; otherwise, <c>false</c>.
/// </value>
public bool IsOpen { get; private set; }
}
/// <summary>
/// Event argument for the <see cref="NmeaDevice.MessageReceived" />
/// </summary>
public sealed class NmeaMessageReceivedEventArgs : EventArgs
{
internal NmeaMessageReceivedEventArgs(Nmea.NmeaMessage message) {
Message = message;
}
/// <summary>
/// Gets the nmea message.
/// </summary>
/// <value>
/// The nmea message.
/// </value>
public Nmea.NmeaMessage Message { get; private set; }
/// <summary>
/// Gets a value indicating whether this instance is a multi part message.
/// </summary>
/// <value>
/// <c>true</c> if this instance is multi part; otherwise, <c>false</c>.
/// </value>
public bool IsMultiPart { get; internal set; }
/// <summary>
/// Gets the message parts if this is a multi-part message and all message parts has been received.
/// </summary>
/// <value>
/// The message parts.
/// </value>
public Nmea.NmeaMessage[] MessageParts { get; internal set; }
}
}

View file

@ -35,7 +35,7 @@ namespace NmeaParser
#endif
int m_readSpeed;
/// <summary>
///
/// Initializes a new instance of the <see cref="NmeaFileDevice"/> class.
/// </summary>
/// <param name="filename"></param>
/// <param name="readSpeed">The time to wait between each line being read in milliseconds</param>
@ -48,6 +48,10 @@ namespace NmeaParser
m_filename = filename;
m_readSpeed = readSpeed;
}
/// <summary>
/// Gets the stream to perform buffer reads on.
/// </summary>
/// <returns></returns>
protected override Task<Stream> GetStreamAsync()
{
#if NETFX_CORE

View file

@ -28,16 +28,29 @@ namespace NmeaParser
public class StreamDevice : NmeaDevice
{
System.IO.Stream m_stream;
/// <summary>
/// Initializes a new instance of the <see cref="StreamDevice"/> class.
/// </summary>
/// <param name="stream">The stream.</param>
public StreamDevice(Stream stream) : base()
{
m_stream = stream;
}
/// <summary>
/// Opens the stream asynchronous.
/// </summary>
/// <returns></returns>
protected override Task<Stream> OpenStreamAsync()
{
return Task.FromResult(m_stream);
}
/// <summary>
/// Closes the stream asynchronous.
/// </summary>
/// <param name="stream">The stream.</param>
/// <returns></returns>
protected override Task CloseStreamAsync(System.IO.Stream stream)
{
return Task.FromResult(true); //do nothing

View file

@ -30,17 +30,30 @@ namespace NmeaParser
{
private System.IO.Ports.SerialPort m_port;
/// <summary>
/// Initializes a new instance of the <see cref="SerialPortDevice"/> class.
/// </summary>
/// <param name="port">The serial port.</param>
public SerialPortDevice(System.IO.Ports.SerialPort port)
{
m_port = port;
}
/// <summary>
/// Creates the stream the NmeaDevice is working on top off.
/// </summary>
/// <returns></returns>
protected override Task<System.IO.Stream> OpenStreamAsync()
{
m_port.Open();
return Task.FromResult<System.IO.Stream>(m_port.BaseStream);
}
/// <summary>
/// Closes the stream the NmeaDevice is working on top off.
/// </summary>
/// <param name="stream">The stream.</param>
/// <returns></returns>
protected override Task CloseStreamAsync(System.IO.Stream stream)
{
m_port.Close();

View file

@ -40,11 +40,19 @@ namespace NmeaParser
private BTDevice m_device;
private StreamSocket m_socket;
/// <summary>
/// Initializes a new instance of the <see cref="BluetoothDevice"/> class.
/// </summary>
/// <param name="device">The device.</param>
public BluetoothDevice(BTDevice device)
{
m_device = device;
}
/// <summary>
/// Creates the stream the NmeaDevice is working on top off.
/// </summary>
/// <returns></returns>
protected override async Task<System.IO.Stream> OpenStreamAsync()
{
var socket = new Windows.Networking.Sockets.StreamSocket();
@ -59,6 +67,11 @@ namespace NmeaParser
return socket.InputStream.AsStreamForRead();
}
/// <summary>
/// Closes the stream the NmeaDevice is working on top off.
/// </summary>
/// <param name="stream">The stream.</param>
/// <returns></returns>
protected override Task CloseStreamAsync(System.IO.Stream stream)
{
stream.Dispose();