Added a method to read RF Spectrums off an object storage.
Some checks failed
🚀 Pack skyscraper8 / make-zip (push) Failing after 43s
Some checks failed
🚀 Pack skyscraper8 / make-zip (push) Failing after 43s
This commit is contained in:
parent
b7e2b50819
commit
0c0932e193
@ -8,7 +8,7 @@ using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using skyscraper5.src.Sophtainer;
|
||||
using skyscraper8.SophtainerIO;
|
||||
|
||||
namespace skyscraper8.Skyscraper.Drawing
|
||||
{
|
||||
|
||||
@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using skyscraper5.Dvb.Descriptors;
|
||||
using skyscraper5.Skyscraper.IO;
|
||||
using skyscraper5.src.Sophtainer;
|
||||
using skyscraper8.SophtainerIO;
|
||||
|
||||
namespace skyscraper8.Skyscraper.Drawing
|
||||
{
|
||||
@ -60,6 +60,39 @@ namespace skyscraper8.Skyscraper.Drawing
|
||||
SaveTo(ms);
|
||||
return ms.GetBuffer();
|
||||
}
|
||||
|
||||
public static RfSpectrumData LoadFromStream(Stream fileStream)
|
||||
{
|
||||
Sophtainer sophtainer = Sophtainer.LoadSophtainer(fileStream);
|
||||
if (sophtainer.Application.Value != 538986066u)
|
||||
throw new WrongApplicationException(538986066u, sophtainer.Application.Value);
|
||||
|
||||
OffsetStream stream = sophtainer.GetStream();
|
||||
|
||||
RfSpectrumData result = new RfSpectrumData();
|
||||
|
||||
byte currentBlockType;
|
||||
while ((currentBlockType = stream.ReadUInt8()) == 0x58)
|
||||
{
|
||||
int minFreq = stream.ReadInt32LE();
|
||||
int maxFreq = stream.ReadInt32LE();
|
||||
int step = stream.ReadInt32LE();
|
||||
SatelliteDeliverySystemDescriptor.PolarizationEnum polarizazion = (SatelliteDeliverySystemDescriptor.PolarizationEnum)stream.ReadUInt8();
|
||||
RfSpectrumDataBlock block = result.CreateBlock(minFreq, maxFreq, step, polarizazion);
|
||||
for (int i = 0; i < block.Data.Length; i++)
|
||||
block.Data[i] = stream.ReadFloat64LE();
|
||||
}
|
||||
|
||||
stream.Close();
|
||||
sophtainer.Dispose();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public IEnumerable<RfSpectrumDataBlock> GetBlocks()
|
||||
{
|
||||
return blocks.AsReadOnly();
|
||||
}
|
||||
}
|
||||
|
||||
public class RfSpectrumDataBlock
|
||||
|
||||
@ -331,6 +331,16 @@ namespace skyscraper5.Skyscraper.IO
|
||||
return result;
|
||||
}
|
||||
|
||||
public static double ReadFloat64LE(this Stream stream)
|
||||
{
|
||||
byte[] buffer = new byte[8];
|
||||
if (stream.Read(buffer, 0, 8) != 8)
|
||||
throw new EndOfStreamException();
|
||||
if (!BitConverter.IsLittleEndian)
|
||||
Array.Reverse(buffer);
|
||||
return BitConverter.ToDouble(buffer, 0);
|
||||
}
|
||||
|
||||
public static void WriteFloat64LE(this Stream stream, double value)
|
||||
{
|
||||
byte[] buffer = BitConverter.GetBytes(value);
|
||||
@ -359,5 +369,23 @@ namespace skyscraper5.Skyscraper.IO
|
||||
fileStream.Close();
|
||||
fileStream.Dispose();
|
||||
}
|
||||
|
||||
public static int TryReadExactly(this Stream stream, byte[] buffer, int offset, int count)
|
||||
{
|
||||
int totalRead = 0;
|
||||
|
||||
while (totalRead < count)
|
||||
{
|
||||
int bytesRead = stream.Read(buffer, offset + totalRead, count - totalRead);
|
||||
if (bytesRead == 0)
|
||||
{
|
||||
// End of stream
|
||||
break;
|
||||
}
|
||||
|
||||
totalRead += bytesRead;
|
||||
}
|
||||
return totalRead;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1776,5 +1776,17 @@ namespace skyscraper5.Skyscraper.Scraper.Storage.Filesystem
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public RfSpectrumData GetRfSpectrum(Guid jobGuid)
|
||||
{
|
||||
string filename = Path.Combine(rootDirectory.FullName, "rf", jobGuid.ToString() + ".rf");
|
||||
FileInfo fi = new FileInfo(filename);
|
||||
if (!fi.Exists)
|
||||
throw new FileNotFoundException(fi.FullName);
|
||||
|
||||
FileStream fileStream = fi.OpenRead();
|
||||
RfSpectrumData result = RfSpectrumData.LoadFromStream(fileStream);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,5 +163,10 @@ namespace skyscraper8.Skyscraper.Scraper.Storage
|
||||
{
|
||||
return new byte[0] { };
|
||||
}
|
||||
|
||||
public RfSpectrumData GetRfSpectrum(Guid selectedGuid)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,6 +36,8 @@ namespace skyscraper8.Skyscraper.Scraper.Storage
|
||||
void StoreRfSpectrum(Guid jobGuid, RfSpectrumData rfSpectrum);
|
||||
void DeleteIqGraph(Guid selectedGuid, int frequencyItem1, SatelliteDeliverySystemDescriptor.PolarizationEnum frequencyItem2);
|
||||
void DeleteRfSpectrum(Guid selectedGuid);
|
||||
|
||||
RfSpectrumData GetRfSpectrum(Guid selectedGuid);
|
||||
bool OtvSsuTestFile(int? currentNetworkId, int? currentTransportStreamId, int sourcePid, ushort tableIdExtension, uint fileId, uint unknown1, uint length);
|
||||
void OnOtvSsuComplete(int? currentNetworkId, int? currentTransportStreamId, int sourcePid, Stream getStream, ushort tableIdExtension, uint fileId, uint unknown1, uint length);
|
||||
void OnNdsSsuComplete(int? currentNetworkId, int? currentTransportStreamId, int pid, ushort tableIdExtension, NdsSsuDataMap dataMap);
|
||||
|
||||
@ -228,5 +228,13 @@ namespace skyscraper8.Skyscraper.Scraper.Storage.Tar
|
||||
string filename = "/nip/" + DvbNipUtilities.MakeFilename(path);
|
||||
return tarArchive.ReadEntry(filename);
|
||||
}
|
||||
|
||||
public RfSpectrumData GetRfSpectrum(Guid selectedGuid)
|
||||
{
|
||||
string filename = String.Format("scandata/{0}/index.rf", selectedGuid);
|
||||
byte[] buffer = tarArchive.ReadEntry(filename);
|
||||
RfSpectrumData rfSpectrumData = RfSpectrumData.LoadFromStream(new MemoryStream(buffer));
|
||||
return rfSpectrumData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace skyscraper5.src.Sophtainer
|
||||
namespace skyscraper8.SophtainerIO
|
||||
{
|
||||
public interface IDisposer
|
||||
{
|
||||
|
||||
@ -5,7 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace skyscraper5.src.Sophtainer
|
||||
namespace skyscraper8.SophtainerIO
|
||||
{
|
||||
internal class OffsetStream : Stream
|
||||
{
|
||||
|
||||
@ -8,7 +8,7 @@ using System.Security.AccessControl;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace skyscraper5.src.Sophtainer
|
||||
namespace skyscraper8.SophtainerIO
|
||||
{
|
||||
internal class Sophtainer : IDisposable, IDisposer
|
||||
{
|
||||
|
||||
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace skyscraper5.src.Sophtainer
|
||||
namespace skyscraper8.SophtainerIO
|
||||
{
|
||||
|
||||
[Serializable]
|
||||
|
||||
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
|
||||
namespace skyscraper5.src.Sophtainer
|
||||
namespace skyscraper8.SophtainerIO
|
||||
{
|
||||
public delegate void FileStreamPartSwitchDelegate(int readSoFar, int currentOffset, int remaining);
|
||||
|
||||
|
||||
17
skyscraper8/Sophtainer/WrongApplicationException.cs
Normal file
17
skyscraper8/Sophtainer/WrongApplicationException.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace skyscraper8.SophtainerIO
|
||||
{
|
||||
internal class WrongApplicationException : Exception
|
||||
{
|
||||
public WrongApplicationException(uint expected, uint actual)
|
||||
: base(String.Format("The loaded Sophtainer file was written with application ID {0}, but we need one for application ID {1}", actual, expected))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user