DebugAppParam.cs 2.32 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Misc;
7 8
using System.IO;
using Newtonsoft.Json;
9
using System.Threading.Tasks;
潘栩锋's avatar
潘栩锋 committed
10 11 12 13 14

namespace Flyad7_WPF
{
    public class DebugAppParam : INotifyPropertyChanged
    {
潘栩锋's avatar
潘栩锋 committed
15
        
潘栩锋's avatar
潘栩锋 committed
16

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
        public string EPStr { get; set; } = "192.168.251.10:20006";

        public bool HasTimeGrid { get; set; }


        public bool HasGrid { get; set; }


        public bool HasGridAdv { get; set; }

        public bool HasCRC { get; set; }


        public int FB_Pos1 { get; set; } = 1000;

        public int FB_Pos2 { get; set; } = 3000;
潘栩锋's avatar
潘栩锋 committed
33 34


35 36 37 38 39 40
        public UInt32 Velocity { get; set; } = 3000;
        public UInt32 SVelocity { get; set; } = 100;
        public UInt32 ATime { get; set; } = 300;
        public UInt32 DTime { get; set; } = 300;
        public UInt32 HVelocity1 { get; set; } = 1000;
        public UInt32 HVelocity2 { get; set; } = 300;
潘栩锋's avatar
潘栩锋 committed
41

42 43
        public int PosLen { get; set; } = 8900;
        public int ADLag { get; set; } = 0;
44
       
45

潘栩锋's avatar
潘栩锋 committed
46 47
        public event PropertyChangedEventHandler PropertyChanged;

48 49 50 51 52 53 54 55 56 57 58 59
        public DebugAppParam() 
        {
            Load();
            this.PropertyChanged += AutoSave;
        }

        private bool isIgnoreSave;
        private async void AutoSave(object sender, PropertyChangedEventArgs e)
        {
            if (isIgnoreSave)
                return;

潘栩锋's avatar
潘栩锋 committed
60
            //if (this.GetType().GetProperty(e.PropertyName).GetCustomAttributes(typeof(JsonPropertyAttribute), false).Count() > 0)
61 62 63 64 65 66 67
            {
                isIgnoreSave = true;
                await Task.Delay(5000);//Task.Yield();
                Save();
                isIgnoreSave = false;
            }
        }
潘栩锋's avatar
潘栩锋 committed
68 69
        public void Save()
        {
70 71
            try
            {
潘栩锋's avatar
潘栩锋 committed
72
                string json = JsonConvert.SerializeObject(this, Formatting.Indented);
73 74 75 76 77
                File.WriteAllText("param.json", json);
            }
            catch {
            
            }
潘栩锋's avatar
潘栩锋 committed
78 79 80 81
        }

        public void Load()
        {
82 83 84 85 86 87 88 89 90 91
            try
            {
                string json = File.ReadAllText("param.json");
                isIgnoreSave = true;
                JsonConvert.PopulateObject(json, this);
                isIgnoreSave = false;
            }
            catch { 
            
            }
潘栩锋's avatar
潘栩锋 committed
92
        }
潘栩锋's avatar
潘栩锋 committed
93 94


潘栩锋's avatar
潘栩锋 committed
95 96 97 98
    }


}