123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.IO;
- using System.Text;
- using System.Threading.Tasks;
- using UESTC.Auto.SCPIManager;
- using Uestc.Auto6.Dso.Hardware.Calibration.Data.Base;
- using Uestc.Auto6.Dso.ComModel;
- using Uestc.Auto6.Dso.Core;
- using Uestc.Auto6.Dso.Core.Hardware;
- using CalibrationData = Uestc.Auto6.Dso.Hardware.Calibration.Data.Base;
- namespace Uestc.Auto6.Dso.Scpi
- {
- partial class StubFunc
- {
- private static string ConvertParamToString(SCPICommandProcessFuncParam analyResult)
- {
- StringBuilder sb = new StringBuilder();
- if (analyResult.Params != null)
- {
- bool bFirst = true;
- foreach (byte[] param in analyResult.Params)
- {
- if (!bFirst)
- sb.Append(",");
- if (param != null)
- {
- foreach (byte b in param)
- {
- char c = (char)b;
- if (c != ' ' && c != '\r' && c != '\n')
- sb.Append(c);
- }
- }
- bFirst = false;
- }
- }
- return sb.ToString();
- }
- private static void PushCaliDataChangedHdCmd(CaliDataType caliDataType)
- {
- CaliDataManager.DataChangedCaliDataType = CaliDataManager.DataChangedCaliDataType | caliDataType;
- CalibrationPrsnt.Push(HdCmd.CaliDataChanged);
- }
- public static bool scpiQuy_FPGA_Version(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
- {
- sendMessage.IsDataBlock = false;
- sendMessage.SendData = System.Text.Encoding.UTF8.GetBytes(ExportHdFuncs.GetAllFPGAVersionInfo());
- return true;
- }
- public static bool scpiQuy_FPGA_AllWriteRegisterValue(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
- {
- sendMessage.IsDataBlock = false;
- sendMessage.SendData = System.Text.Encoding.UTF8.GetBytes(ExportHdFuncs.ReadbackAllWritedRegisterValue());
- return true;
- }
- public static bool scpiSet_FPGA_WriteRegister(SCPICommandProcessFuncParam analyResult)
- {
- string paramStr = ConvertParamToString(analyResult);
- string[] paramList = paramStr.Split(',');
- if (paramList.Length < 3)
- return false;
- if (!UInt32.TryParse(paramList[0], out UInt32 addr))
- return false;
- if (!UInt32.TryParse(paramList[1], out UInt32 data))
- return false;
- bool bIsAcq = paramList[2] == "1" ? true : false;
- return ExportHdFuncs.FPGARegister_WriteValue(addr, data, bIsAcq);
- }
- #region 校准数据
- public static bool scpiQuy_CaliData_Get(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
- {
- sendMessage.IsDataBlock = true;
- sendMessage.SendData = CalibrationData.Helper.GetICaliData((CaliDataType)analyResult.ChannelIndex).Serialize();
- PrintDebug(ConvertInputData(analyResult), ConvertOutputData(sendMessage.SendData, true));
- return true;
- }
- private static byte[] bigCaliData = new byte[128 * 1024];
- private static CaliDataType lastCaliDataType = CaliDataType.None;
- private static int bigCaliDataIndex = 0;
- public static bool scpiSet_CaliData_Set(SCPICommandProcessFuncParam analyResult)
- {
- PrintDebug(ConvertInputData(analyResult), null);
- if (lastCaliDataType == CaliDataType.None)
- {
- bigCaliDataIndex = 0;
- lastCaliDataType = (CaliDataType)analyResult.ChannelIndex;
- }
- if (analyResult.Params[0].Length == 0)
- {
- CaliDataType caliDataType = (CaliDataType)analyResult.ChannelIndex;
- CalibrationData.Helper.GetICaliData(caliDataType).Deserialize(bigCaliData);
- PushCaliDataChangedHdCmd(caliDataType);
- lastCaliDataType = CaliDataType.None;
- bigCaliDataIndex = 0;
- }
- else
- {
- byte[] data = ConvertBinDataFromScpiData(analyResult.Params[0]);
- Array.Copy(data, 0, bigCaliData, bigCaliDataIndex, data.Length);
- bigCaliDataIndex += data.Length;
- }
- return true;
- }
- public static bool scpiSet_CaliData_SaveToFile(SCPICommandProcessFuncParam analyResult)
- {
- PrintDebug(ConvertInputData(analyResult), null);
- CalibrationData.Helper.GetICaliData((CaliDataType)analyResult.ChannelIndex).SaveToFile();
- return true;
- }
- public static bool scpiSet_CaliData_LoadFromFile(SCPICommandProcessFuncParam analyResult)
- {
- PrintDebug(ConvertInputData(analyResult), null);
- CaliDataType caliDataType= (CaliDataType)analyResult.ChannelIndex;
- PushCaliDataChangedHdCmd(caliDataType);
- CalibrationData.Helper.GetICaliData((CaliDataType)analyResult.ChannelIndex).LoadFromFile();
- return true;
- }
- #endregion
- #region 波形数据
- static ushort[] allCoreData = new ushort[ChannelIdExt.AnaChnlNum * Constants.ADC_NUM * CaliConstants.PerAdcCoreCount * CaliConstants.PerAdcCoreWaveDots];
- public static bool scpiQuy_Factory_GetWaveData_Adc(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
- {
- if (ExportHdFuncs.TakeAdcWaveform(out List<List<ushort>> waveData))
- {
- Int64 posIndex = 0;
- for (int coreIndex = 0; coreIndex < ChannelIdExt.AnaChnlNum * Constants.ADC_NUM * CaliConstants.PerAdcCoreCount; coreIndex++)
- {
- Array.Copy(waveData[coreIndex].ToArray(), 0, allCoreData, posIndex, CaliConstants.PerAdcCoreWaveDots);
- posIndex += CaliConstants.PerAdcCoreWaveDots;
- }
- MemoryStream memoryStream = new MemoryStream();
- foreach (ushort s in allCoreData)
- memoryStream.Write(BitConverter.GetBytes(s));
- sendMessage.IsDataBlock = true;
- sendMessage.SendData = memoryStream.ToArray();
- memoryStream.Close();
- PrintDebug(ConvertInputData(analyResult), ConvertOutputData(sendMessage.SendData, true));
- return true;
- }
- else
- return false;
- }
- static ushort[] allChannelData = new ushort[CaliConstants.PerPhysicsChannelDotsCount * CaliConstants.MaxPhysicsChannelCount];
- public static bool scpiQuy_Factory_GetWaveData_Channel(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
- {
- if (ExportHdFuncs.TakeChannelWaveform(out List<List<ushort>> waveData))
- {
- Int64 posIndex = 0;
- for (int adcIndex = 0; adcIndex < CaliConstants.MaxPhysicsChannelCount; adcIndex++)
- {
- Array.Copy(waveData[adcIndex].ToArray(), 0, allChannelData, posIndex, CaliConstants.PerPhysicsChannelDotsCount);
- posIndex += CaliConstants.PerPhysicsChannelDotsCount;
- }
- MemoryStream memoryStream = new MemoryStream();
- foreach (ushort s in allChannelData)
- memoryStream.Write(BitConverter.GetBytes(s));
- sendMessage.IsDataBlock = true;
- sendMessage.SendData = memoryStream.ToArray();
- memoryStream.Close();
- PrintDebug(ConvertInputData(analyResult), ConvertOutputData(sendMessage.SendData, true));
- return true;
- }
- else
- return false;
- }
- #endregion
- #region 厂家校准用逻辑参数
- public static bool scpiQuy_FactoryCaliLogicValue(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
- {
- sendMessage.SendData = System.Text.Encoding.UTF8.GetBytes(ExportHdFuncs.FactoryCaliScpiProc_LogicValue_Get());
- return true;
- }
- public static bool scpiSet_FactoryCaliLogicValue(SCPICommandProcessFuncParam analyResult)
- {
- string paramStr = ConvertParamToString(analyResult);
- return ExportHdFuncs.FactoryCaliScpiProc_LogicValue_Set(paramStr);
- }
- #endregion 厂家校准用逻辑参数
- #region 厂家校准用特殊数据
- public static bool scpiQuy_FactoryCaliSpecialData(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
- {
- string paramStr = ConvertParamToString(analyResult);
- sendMessage.SendData = System.Text.Encoding.UTF8.GetBytes(ExportHdFuncs.FactoryCaliScpiProc_SpecialData_Get(paramStr));
- return true;
- }
- public static bool scpiSet_FactoryCaliSpecialData(SCPICommandProcessFuncParam analyResult)
- {
- string paramStr = ConvertParamToString(analyResult);
- return ExportHdFuncs.FactoryCaliScpiProc_SpecialData_Set(paramStr);
- }
- public static bool scpiQuy_FactoryCaliSpecialReadBackAdcRegister(SCPICommandProcessFuncParam analyResult, ref SCPISendMessage sendMessage)
- {
- string paramStr = ConvertParamToString(analyResult);
- sendMessage.SendData = System.Text.Encoding.UTF8.GetBytes(ExportHdFuncs.ReadbackAdcRegisterData());
- return true;
- }
- public static bool scpiSet_FactoryCaliApplySource(SCPICommandProcessFuncParam analyResult)
- {
- bool TryGetScaleIndex(int valueByuV, out Core.AnaChnlScaleIndex scaleIndex)
- {
- scaleIndex = Core.AnaChnlScaleIndex.Lv1;
- for (int i = 0; i < AnalogChannel.PhyChCoarseLevelTableByuV.Count; i++)
- {
- if (AnalogChannel.PhyChCoarseLevelTableByuV[i] == valueByuV)
- {
- scaleIndex = (Core.AnaChnlScaleIndex)i;
- return true;
- }
- }
- return false;
- }
- string paramStr = ConvertParamToString(analyResult);
- string[] paramList = paramStr.Split(',');
- //打开[0,1],幅度档(mv数),基线位置[0],耦合[0=DC,1=AC,2=DC50],阻抗[0=1M,1=50],带宽限制[0=关闭,1=20M,2=100M],偏置[mv数],探头倍率[枚举],反向[0=off,1=on],单位[0=V,1=A]
- // 0 1 2 3 4 5 6 7 8 9
- if (Presenter.TryGetChannel((ChannelId)(analyResult.ChannelIndex - 1), out var ch))
- {
- AnalogPrsnt anaChnlPrsnt = (AnalogPrsnt)ch;
- anaChnlPrsnt.Active = paramList[0] == "1";
- int scaleBymV = int.Parse(paramList[1]);
- if (TryGetScaleIndex(scaleBymV * 1_000, out Core.AnaChnlScaleIndex scaleIndex))
- anaChnlPrsnt.ScaleIndex = (int)scaleIndex;
- anaChnlPrsnt.PosIndexBymDiv = double.Parse(paramList[2]);
- anaChnlPrsnt.Coupling = (AnaChnlCoupling)int.Parse(paramList[3]);
- anaChnlPrsnt.Bandwidth = paramList[5] switch
- {
- "0" => AnaChnlBandwidth.Full,
- "1" => AnaChnlBandwidth.Bw20MHz,
- "2" => AnaChnlBandwidth.Bw500MHz,
- _ => AnaChnlBandwidth.Full
- };
- anaChnlPrsnt.Bias = double.Parse(paramList[6]) * 1000; //mV==>uV
- anaChnlPrsnt.IsInverted = (paramList[8] == "1");
- }
- else
- return false;
- return true;
- }
- public static bool scpiSet_FactoryCaliApplyAllSource(SCPICommandProcessFuncParam analyResult)
- {
- bool TryGetScaleIndex(int valueByuV, out Core.AnaChnlScaleIndex scaleIndex)
- {
- scaleIndex = Core.AnaChnlScaleIndex.Lv1;
- for (int i = 0; i < AnalogChannel.PhyChCoarseLevelTableByuV.Count; i++)
- {
- if (AnalogChannel.PhyChCoarseLevelTableByuV[i] == valueByuV)
- {
- scaleIndex = (Core.AnaChnlScaleIndex)i;
- return true;
- }
- }
- return false;
- }
- string paramStr = ConvertParamToString(analyResult);
- string[] paramList = paramStr.Split(',');
- //打开[0,1],幅度档(mv数),基线位置[0],耦合[直流、交流、接地,枚举],阻抗[0=1M_om,1=5O_om],带宽限制[0=关闭,1=20M,2=100M],偏置[mv数],探头倍率[枚举],反向[0=off,1=on],单位[0=V,1=A]
- // 0 1 2 3 4 5 6 7 8 9
- int scaleBymV = int.Parse(paramList[1]);
- if (!TryGetScaleIndex(scaleBymV * 1_000, out Core.AnaChnlScaleIndex scaleIndex))
- return false;
- AnaChnlCoupling anaChnlCoupling = (AnaChnlCoupling)int.Parse(paramList[3]);
- AnaChnlBandwidth anaChnlBandwidth = paramList[5] switch
- {
- "0" => AnaChnlBandwidth.Full,
- "1" => AnaChnlBandwidth.Bw20MHz,
- "2" => AnaChnlBandwidth.Bw500MHz,
- _ => AnaChnlBandwidth.Full
- };
- double bias = double.Parse(paramList[6]) * 1000; //mV==>uV
- bool IsInverted = (paramList[8] == "1");
- bool bActive = paramList[0] == "1";
- double posIndex = double.Parse(paramList[2]);
- for (ChannelId channelId = ChannelId.C1; channelId < ChannelId.C1 + ChannelIdExt.AnaChnlNum; channelId++)
- {
- if (Presenter.TryGetChannel(channelId, out var ch))
- {
- AnalogPrsnt anaChnlPrsnt = (AnalogPrsnt)ch;
- try
- {
- anaChnlPrsnt.Active = bActive;
- anaChnlPrsnt.ScaleIndex = (int)scaleIndex;
- anaChnlPrsnt.PosIndexBymDiv = posIndex;
- anaChnlPrsnt.Coupling = anaChnlCoupling;
- anaChnlPrsnt.Bandwidth = anaChnlBandwidth;
- anaChnlPrsnt.Bias = bias;
- anaChnlPrsnt.IsInverted = IsInverted;
- }
- catch
- {
- }
- }
- }
- return true;
- }
- #endregion 厂家校准用特殊数据
- }
- }
|