1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using Avalonia;
- using Avalonia.Controls.ApplicationLifetimes;
- using Avalonia.Data.Core.Plugins;
- using Avalonia.Markup.Xaml;
- using FxpConvert.Common;
- #if DEBUG
- using HotAvalonia;
- #endif
- using ShakerApp.ViewModels;
- using ShakerApp.Views;
- using System;
- using System.Globalization;
- using System.Linq;
- using System.Runtime.InteropServices;
- namespace ShakerApp;
- public partial class App : Application
- {
- public unsafe override void Initialize()
- {
- Test();
- #if DEBUG
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- this.EnableHotReload();
- }
- #endif
- AvaloniaXamlLoader.Load(this);
- }
- private void Test()
- {
- IFxpConvert convert = new SIMDFxpConvert.SIMDFxpConverter();
- uint count = 4;
- double[] f = new double[] { -1, -2, 1, 2 };
- ulong[] f2 = new ulong[count];
- NiFpga_FxpTypeInfo typeInfo = new NiFpga_FxpTypeInfo()
- {
- integerWordLength = 5,
- Delta = 0.000031,
- isSigned = true,
- Max = 15.999969,
- Min = -16,
- wordLength = 20
- };
- convert.DoubleConvertToDxp(ref f[0], typeInfo, ref f2[0], count);
- byte[] bytes = new byte[(int)Math.Ceiling(typeInfo.wordLength * count / 8.0)];
- string s = string.Empty;
-
- for(int i=0;i<f2.Length;i++)
- {
- s += f2[i].ToString("b").PadLeft(64,'0').Substring(64 - typeInfo.wordLength, typeInfo.wordLength);
- }
- for(int i = 0; i < bytes.Length;i++)
- {
- bytes[i] = System.Convert.ToByte(s.Substring(i * 8, Math.Min(8, s.Length - i * 8)), 2);
- }
- s = string.Empty;
- for(int i=0;i<bytes.Length;i++)
- {
- s += bytes[i].ToString("b").PadLeft(8, '0');
- }
- ulong[] f3 = new ulong[count];
- for(int i=0;i<f3.Length;i++)
- {
- f3[i] = System.Convert.ToUInt64(s.Substring(i * typeInfo.wordLength, typeInfo.wordLength),2);
- }
- double[] f4 = new double[count];
- convert.FxpConvertToDouble(ref f3[0], typeInfo, ref f4[0], count);
- }
- public override void OnFrameworkInitializationCompleted()
- {
- BindingPlugins.DataValidators.RemoveAt(0);
- ShakerSettingViewModel.Instance.Init();
- if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
- {
- if (desktop.Args!.Contains("-debug"))
- {
- ViewModels.MainViewModel.Default.CanDebug = true;
- }
- desktop.MainWindow = new MainWindow();
- }
- base.OnFrameworkInitializationCompleted();
- }
- }
|