using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Misc;
using System.IO;
using Newtonsoft.Json;

namespace Flyad7_WPF
{
    public class DebugAppParam : INotifyPropertyChanged
    {

        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;


        public UInt32 Velocity;
        public UInt32 SVelocity;
        public UInt32 ATime;
        public UInt32 DTime;
        public UInt32 HVelocity1;
        public UInt32 HVelocity2;

        public int PosLen;
        public int ADLag;

        #region INotifyPropertyChanged 成员
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion

        public void Save()
        {
            try
            {
                DebugAppParamJsonDB param = new DebugAppParamJsonDB()
                {
                    EPStr = EPStr,
                    HasTimeGrid = HasTimeGrid,
                    HasGrid = HasGrid,
                    HasGridAdv = HasGridAdv,
                    HasCRC = HasCRC,
                    FB_Pos1 = FB_Pos1,
                    FB_Pos2 = FB_Pos2
                };

                File.WriteAllText(file_path, JsonConvert.SerializeObject(param, Formatting.Indented));
            }
            catch
            {
                //异常，没有json 编码失败

            }
        }

        string file_path = "param.json";
        public void Load()
        {
            try
            {
                if (File.Exists(file_path))
                {
                    string json = File.ReadAllText(file_path);
                    var param = JsonConvert.DeserializeObject<DebugAppParamJsonDB>(json);
                    EPStr = param.EPStr;
                    HasTimeGrid = param.HasTimeGrid;
                    HasGrid = param.HasGrid;
                    HasGridAdv = param.HasGridAdv;
                    HasCRC = param.HasCRC;
                    FB_Pos1 = param.FB_Pos1;
                    FB_Pos2 = param.FB_Pos2;
                }
            }
            catch
            {
                //异常，没有json 解码失败
            }
        }
    }
    public class DebugAppParamJsonDB
    {
        public string EPStr;

        public bool HasTimeGrid;


        public bool HasGrid;


        public bool HasGridAdv;

        public bool HasCRC;


        public int FB_Pos1;

        public int FB_Pos2;
    }

}
