Exemplo n.º 1
0
        public static Options FromByteArray(byte[] data)
        {
            Options res = null;

            if (data != null)
            {
                using (MemoryStream xmlStream = new MemoryStream(data))
                {
                    XmlReaderSettings ss = new XmlReaderSettings();
                    ss.IgnoreWhitespace = true;
                    ss.IgnoreComments = true;
                    using (XmlReader reader = XmlReader.Create(xmlStream, ss))
                    {
                        while (!reader.EOF)
                        {
                            reader.Read();
                            if (reader.NodeType == XmlNodeType.Element && reader.Name == "Options")
                            {
                                res = new Options();

                                //if (!Utils.StringIsNullOrEmpty(reader.GetAttribute("MainBridgeCurrentThreshould")))
                                //    res.MainBridgeCurrentThreshould = int.Parse(reader.GetAttribute("MainBridgeCurrentThreshould"));
                                //if (!Utils.StringIsNullOrEmpty(reader.GetAttribute("ProgBridgeCurrentThreshould")))
                                //    res.ProgBridgeCurrentThreshould = int.Parse(reader.GetAttribute("ProgBridgeCurrentThreshould"));
                                //if (!Utils.StringIsNullOrEmpty(reader.GetAttribute("BroadcastBoostersCurrent")))
                                //    res.BroadcastBoostersCurrent = reader.GetAttribute("BroadcastBoostersCurrent") == bool.TrueString;

                                if (!Utils.StringIsNullOrEmpty(reader.GetAttribute("UseWiFi")))
                                    res.UseWiFi = reader.GetAttribute("UseWiFi") == bool.TrueString;
                                if (!Utils.StringIsNullOrEmpty(reader.GetAttribute("WiFiSSID")))
                                    res.WiFiSSID = reader.GetAttribute("WiFiSSID");
                                if (!Utils.StringIsNullOrEmpty(reader.GetAttribute("WiFiPassword")))
                                    res.WiFiPassword = reader.GetAttribute("WiFiPassword");

                            }
                        }
                    }
                }
            }

            return res;
        }
Exemplo n.º 2
0
        //public static void DeleteFromFlash()
        //{
        //    // Data recovering and storing must be kept in pairs.
        //    // Calling Recover without setting Target frees the FLASH completely from this EWR.
        //    ExtendedWeakReference.Recover(typeof(Options), 0);
        //}
        //public static void RestoreLastSaved() // Use this method to rewrite current settings using last saved data.
        //{
        //    // First, mark the stored data as unrecovered so we can Recover them.
        //    optionsReference.PushBackIntoRecoverList();
        //    // Try to recover them, but do not create them if they do not exist.
        //    ExtendedWeakReference restoreReference = ExtendedWeakReference.Recover(typeof(Options), 0);
        //    if (restoreReference != null && restoreReference.Target != null)
        //    {
        //        options = (Options)restoreReference.Target; // If they do, use them to refresh current settings.
        //        restoreReference.PushBackIntoRecoverList(); // Since we found the data, we have to put them back.
        //    }
        //    else
        //        Debug.Print("Could not restore settings.");
        //}
        public static Options LoadFromSD(string root)
        {
            Options res = new Options();

            byte[] data = DriveManager.LoadFromSD(root + fileName);
            if (data == null)
                res.SaveToSD(root);
            else
                res = Options.FromByteArray(data);

            return res;
        }
Exemplo n.º 3
0
        private void InitHardware()
        {
            HWConfig.Indicators.TurnAllLedsOff();

            timerNetworkConnect = new GT.Timer(500);
            timerNetworkConnect.Tick += delegate(GT.Timer t) { HWConfig.Indicators[HWConfig.LEDNetwork] = !HWConfig.Indicators[HWConfig.LEDNetwork]; };

            HWConfig.SDCard.SDCardMounted += sdCard_Mounted;
            HWConfig.SDCard.SDCardUnmounted += sdCard_Unmounted;
            if (HWConfig.SDCard.IsCardInserted)
            {
                HWConfig.SDCard.MountSDCard();
                Thread.Sleep(500);

                options = Options.LoadFromSD(HWConfig.SDCard.GetStorageDevice().RootDirectory);
                //ApplyOptions();
            }

            // UART on socket 4:
            string portName = GT.Socket.GetSocket(4, true, null, null).SerialPortName;
            uart = new SerialPort(portName, 115200);
            uart.DataReceived += uart_DataReceived;
            uart.ErrorReceived += uart_ErrorReceived;
            uart.Open();

            //mainBooster = new Booster(
            //    true,
            //    HardwareConfiguration.PinMainBoosterEnable,
            //    HardwareConfiguration.PinMainBoosterEnableLED,
            //    HardwareConfiguration.PinMainBoosterSense,
            //    HardwareConfiguration.PinMainBoosterOverloadLED,
            //    HardwareConfiguration.SenseResistor,
            //    options.MainBridgeCurrentThreshould,
            //    HardwareConfiguration.PinMainOutputGenerator,
            //    DCCCommand.Idle().ToTimings()
            //    );
            //mainBooster.PropertyChanged += new PropertyChangedEventHandler(Booster_PropertyChanged);

            //progBooster = new Booster(
            //    true,
            //    HardwareConfiguration.PinProgBoosterEnable,
            //    HardwareConfiguration.PinProgBoosterEnableLED,
            //    HardwareConfiguration.PinProgBoosterSense,
            //    HardwareConfiguration.PinProgBoosterOverloadLED,
            //    HardwareConfiguration.SenseResistor,
            //    options.ProgBridgeCurrentThreshould,
            //    HardwareConfiguration.PinProgOutputGenerator,
            //    DCCCommand.Idle().ToTimings(true)
            //    );
            //progBooster.PropertyChanged += new PropertyChangedEventHandler(Booster_PropertyChanged);

            //if (options.BroadcastBoostersCurrent)
            //    timerBoostersCurrent = new Timer(TimerBustersCurrent_Tick, null, 0, 1000);

            //btns = new Buttons();
        }