App.axaml.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using Avalonia;
  2. using Avalonia.Controls.ApplicationLifetimes;
  3. using Avalonia.Data.Core.Plugins;
  4. using Avalonia.Markup.Xaml;
  5. using FxpConvert.Common;
  6. #if DEBUG
  7. using HotAvalonia;
  8. #endif
  9. using ShakerApp.ViewModels;
  10. using ShakerApp.Views;
  11. using System;
  12. using System.Globalization;
  13. using System.Linq;
  14. using System.Runtime.InteropServices;
  15. namespace ShakerApp;
  16. public partial class App : Application
  17. {
  18. public unsafe override void Initialize()
  19. {
  20. Test();
  21. #if DEBUG
  22. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  23. {
  24. this.EnableHotReload();
  25. }
  26. #endif
  27. AvaloniaXamlLoader.Load(this);
  28. }
  29. private void Test()
  30. {
  31. IFxpConvert convert = new SIMDFxpConvert.SIMDFxpConverter();
  32. uint count = 4;
  33. double[] f = new double[] { -1, -2, 1, 2 };
  34. ulong[] f2 = new ulong[count];
  35. NiFpga_FxpTypeInfo typeInfo = new NiFpga_FxpTypeInfo()
  36. {
  37. integerWordLength = 5,
  38. Delta = 0.000031,
  39. isSigned = true,
  40. Max = 15.999969,
  41. Min = -16,
  42. wordLength = 20
  43. };
  44. convert.DoubleConvertToDxp(ref f[0], typeInfo, ref f2[0], count);
  45. byte[] bytes = new byte[(int)Math.Ceiling(typeInfo.wordLength * count / 8.0)];
  46. string s = string.Empty;
  47. for(int i=0;i<f2.Length;i++)
  48. {
  49. s += f2[i].ToString("b").PadLeft(64,'0').Substring(64 - typeInfo.wordLength, typeInfo.wordLength);
  50. }
  51. for(int i = 0; i < bytes.Length;i++)
  52. {
  53. bytes[i] = System.Convert.ToByte(s.Substring(i * 8, Math.Min(8, s.Length - i * 8)), 2);
  54. }
  55. s = string.Empty;
  56. for(int i=0;i<bytes.Length;i++)
  57. {
  58. s += bytes[i].ToString("b").PadLeft(8, '0');
  59. }
  60. ulong[] f3 = new ulong[count];
  61. for(int i=0;i<f3.Length;i++)
  62. {
  63. f3[i] = System.Convert.ToUInt64(s.Substring(i * typeInfo.wordLength, typeInfo.wordLength),2);
  64. }
  65. double[] f4 = new double[count];
  66. convert.FxpConvertToDouble(ref f3[0], typeInfo, ref f4[0], count);
  67. }
  68. public override void OnFrameworkInitializationCompleted()
  69. {
  70. BindingPlugins.DataValidators.RemoveAt(0);
  71. ShakerSettingViewModel.Instance.Init();
  72. if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
  73. {
  74. if (desktop.Args!.Contains("-debug"))
  75. {
  76. ViewModels.MainViewModel.Default.CanDebug = true;
  77. }
  78. desktop.MainWindow = new MainWindow();
  79. }
  80. base.OnFrameworkInitializationCompleted();
  81. }
  82. }