Added a method to read RF Spectrums off an object storage.
Some checks failed
🚀 Pack skyscraper8 / make-zip (push) Failing after 43s

This commit is contained in:
feyris-tan 2026-05-03 21:31:47 +02:00
parent b7e2b50819
commit 0c0932e193
13 changed files with 112 additions and 7 deletions

View File

@ -8,7 +8,7 @@ using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using skyscraper5.src.Sophtainer; using skyscraper8.SophtainerIO;
namespace skyscraper8.Skyscraper.Drawing namespace skyscraper8.Skyscraper.Drawing
{ {

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using skyscraper5.Dvb.Descriptors; using skyscraper5.Dvb.Descriptors;
using skyscraper5.Skyscraper.IO; using skyscraper5.Skyscraper.IO;
using skyscraper5.src.Sophtainer; using skyscraper8.SophtainerIO;
namespace skyscraper8.Skyscraper.Drawing namespace skyscraper8.Skyscraper.Drawing
{ {
@ -60,6 +60,39 @@ namespace skyscraper8.Skyscraper.Drawing
SaveTo(ms); SaveTo(ms);
return ms.GetBuffer(); 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 public class RfSpectrumDataBlock

View File

@ -331,6 +331,16 @@ namespace skyscraper5.Skyscraper.IO
return result; 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) public static void WriteFloat64LE(this Stream stream, double value)
{ {
byte[] buffer = BitConverter.GetBytes(value); byte[] buffer = BitConverter.GetBytes(value);
@ -359,5 +369,23 @@ namespace skyscraper5.Skyscraper.IO
fileStream.Close(); fileStream.Close();
fileStream.Dispose(); 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;
}
} }
} }

View File

@ -1776,5 +1776,17 @@ namespace skyscraper5.Skyscraper.Scraper.Storage.Filesystem
{ {
throw new NotImplementedException(); 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;
}
} }
} }

View File

@ -163,5 +163,10 @@ namespace skyscraper8.Skyscraper.Scraper.Storage
{ {
return new byte[0] { }; return new byte[0] { };
} }
public RfSpectrumData GetRfSpectrum(Guid selectedGuid)
{
throw new NotImplementedException();
}
} }
} }

View File

@ -36,6 +36,8 @@ namespace skyscraper8.Skyscraper.Scraper.Storage
void StoreRfSpectrum(Guid jobGuid, RfSpectrumData rfSpectrum); void StoreRfSpectrum(Guid jobGuid, RfSpectrumData rfSpectrum);
void DeleteIqGraph(Guid selectedGuid, int frequencyItem1, SatelliteDeliverySystemDescriptor.PolarizationEnum frequencyItem2); void DeleteIqGraph(Guid selectedGuid, int frequencyItem1, SatelliteDeliverySystemDescriptor.PolarizationEnum frequencyItem2);
void DeleteRfSpectrum(Guid selectedGuid); void DeleteRfSpectrum(Guid selectedGuid);
RfSpectrumData GetRfSpectrum(Guid selectedGuid);
bool OtvSsuTestFile(int? currentNetworkId, int? currentTransportStreamId, int sourcePid, ushort tableIdExtension, uint fileId, uint unknown1, uint length); 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 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); void OnNdsSsuComplete(int? currentNetworkId, int? currentTransportStreamId, int pid, ushort tableIdExtension, NdsSsuDataMap dataMap);

View File

@ -228,5 +228,13 @@ namespace skyscraper8.Skyscraper.Scraper.Storage.Tar
string filename = "/nip/" + DvbNipUtilities.MakeFilename(path); string filename = "/nip/" + DvbNipUtilities.MakeFilename(path);
return tarArchive.ReadEntry(filename); 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;
}
} }
} }

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace skyscraper5.src.Sophtainer namespace skyscraper8.SophtainerIO
{ {
public interface IDisposer public interface IDisposer
{ {

View File

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace skyscraper5.src.Sophtainer namespace skyscraper8.SophtainerIO
{ {
internal class OffsetStream : Stream internal class OffsetStream : Stream
{ {

View File

@ -8,7 +8,7 @@ using System.Security.AccessControl;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace skyscraper5.src.Sophtainer namespace skyscraper8.SophtainerIO
{ {
internal class Sophtainer : IDisposable, IDisposer internal class Sophtainer : IDisposable, IDisposer
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace skyscraper5.src.Sophtainer namespace skyscraper8.SophtainerIO
{ {
[Serializable] [Serializable]

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
using System.IO; using System.IO;
namespace skyscraper5.src.Sophtainer namespace skyscraper8.SophtainerIO
{ {
public delegate void FileStreamPartSwitchDelegate(int readSoFar, int currentOffset, int remaining); public delegate void FileStreamPartSwitchDelegate(int readSoFar, int currentOffset, int remaining);

View 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))
{
}
}
}