You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.7 KiB
C#

using ServiceStack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StartServerWPF.Modules.MseedChart
{
public class Mseed2asciiApi
{
public delegate void LoopCallbackHandler(AsciiDataStruct asciiData);
[DllImport("mseedC.dll", EntryPoint = "MseedDatas")]
public extern static int MseedDatas(int a, string[] name);
//public extern static int MseedDatas(Byte[] bytes, int lenght);
[DllImport("mseedC.dll", EntryPoint = "bufferMseedData")]
public extern static int bufferMseedData(int argc, Byte[] argv);
[DllImport("mseedC.dll", EntryPoint = "testc")]
public extern static int testc(int a, int b);
[DllImport("mseedC.dll")]
public static extern void MseedDatasCallFun(LoopCallbackHandler callback);
}
[StructLayout(LayoutKind.Sequential)]
public struct AsciiDataStruct
{
public string sid;
// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
public string starttime; //!< Time of first sample
// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
public string endtime; //!< Time of last sample
public double samprate; //!< Nominal sample rate (Hz)
public Int64 samplecnt; //!< Number of samples in trace coverage
public UInt64 datasize; //!< Size of datasamples buffer in bytes
public Int64 numsamples; //!< Number of data samples in datasamples
public char sampletype; //!< Sample type code, see @ref sample-types
public char samplesize;
public System.IntPtr datasamples; //!< Data samples, \a numsamples of type \a sampletype
}
public class ASCiiData
{
public int Index { set; get; }
public string sid { set; get; }
public double samprate { set; get; }
public double StartOATime { set; get; }
public Int64 numsamples { set; get; }
public double Average { set; get; } = 0;
public List<double[]> datas { get; }=new List<double[]>();
public void AddData(double aoTime, double[] da)
{
StartOATime = aoTime;
if (datas.Count >= 30)
{
datas.RemoveAt(0);
}
if (da[0] == 0)
{
if (datas.Count!= 0)
{
double[] temp = datas.Last();
Average = temp.Average();
da = Enumerable.Repeat(Average, temp.Length).ToArray();
}
}
datas.Add(da);
}
}
}