2014-07-25 22:26:30 +02:00
|
|
|
|
//
|
|
|
|
|
|
// Copyright (c) 2014 Morten Nielsen
|
|
|
|
|
|
//
|
|
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL) (the "License");
|
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
//
|
|
|
|
|
|
// http://opensource.org/licenses/Ms-PL.html
|
|
|
|
|
|
//
|
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
|
// limitations under the License.
|
2014-07-25 22:27:11 +02:00
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2014-07-25 21:21:07 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NmeaParser
|
|
|
|
|
|
{
|
2014-11-12 02:36:38 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A file-based NMEA device reading from a NMEA log file.
|
|
|
|
|
|
/// </summary>
|
2014-11-11 23:42:53 +01:00
|
|
|
|
public class NmeaFileDevice : BufferedStreamDevice
|
2014-07-25 21:21:07 +02:00
|
|
|
|
{
|
|
|
|
|
|
#if NETFX_CORE
|
|
|
|
|
|
Windows.Storage.IStorageFile m_filename;
|
|
|
|
|
|
#else
|
|
|
|
|
|
string m_filename;
|
|
|
|
|
|
#endif
|
2014-11-15 02:36:46 +01:00
|
|
|
|
|
2014-07-25 21:21:07 +02:00
|
|
|
|
/// <summary>
|
2014-11-12 02:44:02 +01:00
|
|
|
|
/// Initializes a new instance of the <see cref="NmeaFileDevice"/> class.
|
2014-07-25 21:21:07 +02:00
|
|
|
|
/// </summary>
|
2014-11-15 02:36:46 +01:00
|
|
|
|
/// <param name="fileName"></param>
|
|
|
|
|
|
#if NETFX_CORE
|
|
|
|
|
|
public NmeaFileDevice(Windows.Storage.IStorageFile fileName) : this(fileName, 200)
|
|
|
|
|
|
#else
|
|
|
|
|
|
public NmeaFileDevice(string fileName) : this(fileName, 200)
|
|
|
|
|
|
#endif
|
|
|
|
|
|
{
|
|
|
|
|
|
m_filename = fileName;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initializes a new instance of the <see cref="NmeaFileDevice"/> class.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="fileName"></param>
|
2014-07-25 21:21:07 +02:00
|
|
|
|
/// <param name="readSpeed">The time to wait between each line being read in milliseconds</param>
|
|
|
|
|
|
#if NETFX_CORE
|
2014-11-15 02:36:46 +01:00
|
|
|
|
public NmeaFileDevice(Windows.Storage.IStorageFile fileName, int readSpeed)
|
|
|
|
|
|
: base(readSpeed)
|
2014-07-25 21:21:07 +02:00
|
|
|
|
#else
|
2014-11-15 02:36:46 +01:00
|
|
|
|
public NmeaFileDevice(string fileName, int readSpeed) : base(readSpeed)
|
2014-07-25 21:21:07 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
{
|
2014-11-15 02:36:46 +01:00
|
|
|
|
m_filename = fileName;
|
2014-07-25 21:21:07 +02:00
|
|
|
|
}
|
2014-11-15 02:36:46 +01:00
|
|
|
|
|
2014-11-12 02:44:02 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the stream to perform buffer reads on.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2014-11-15 02:36:46 +01:00
|
|
|
|
#if !NETFX_CORE
|
|
|
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
|
|
|
|
|
|
#endif
|
2014-11-11 23:42:53 +01:00
|
|
|
|
protected override Task<Stream> GetStreamAsync()
|
2014-07-25 21:21:07 +02:00
|
|
|
|
{
|
2014-11-11 23:42:53 +01:00
|
|
|
|
#if NETFX_CORE
|
|
|
|
|
|
return m_filename.OpenStreamForReadAsync();
|
2014-07-25 21:21:07 +02:00
|
|
|
|
#else
|
2014-11-15 02:36:46 +01:00
|
|
|
|
return Task.FromResult<Stream>(System.IO.File.OpenRead(m_filename));
|
2014-07-25 21:21:07 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|