Esempio n. 1
0
 private void TimeRecieved(bool DataOk, ushort[] ParamRTU, object param)
 {
     if (this.InvokeRequired)
     {
         try
         {
             Invoke(new AsynchSerialPort.DataRecievedRTU(TimeRecieved), DataOk, ParamRTU, null);
         }
         catch
         {
         }
     }
     else
     {
         try
         {
             if (!DataOk)
             {
                 timeLabel.Text = "Нет связи";
             }
             else
             {
                 timeLabel.Text = TimeConfig.ExtractTimeFromArray(ParamRTU, systemConfiguration.TimeConfig);
             }
         }
         catch
         {
         }
     }
 }
Esempio n. 2
0
        public void LoadXml()
        {
            TimeConfig tc = new TimeConfig();

            tc.StartTime = System.DateTime.Now.TimeOfDay;
            tc.EndTime   = System.DateTime.Now.TimeOfDay;

            string xml = CommonUtiliy.SerializationHelper <TimeConfig> .Serialize(tc);
        }
Esempio n. 3
0
 //************************УСТАНОВКА ТЕКУЩЕГО ВРЕМЕНИ *********************************************//
 //************************************************************************************************//
 private void setClockBtn_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show(TextsParams.ParameterName(18), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
     {
         DateTime dt = DateTime.Now;
         TimeConfig.SendSetTimeRequest(serialPort, systemConfiguration.TimeConfig,
                                       dt.Hour, dt.Minute, dt.Second, dt.Day, dt.Month, dt.Year - 2000);
     }
 }
Esempio n. 4
0
        private void SynchronizateTimeConfig(string key)
        {
            TimeConfig tc = TimeConfigCollection.Single[key];

            if (tc != null)
            {
                effectiveHeartServerMap[key].SpanInfo = tc;
            }
        }
Esempio n. 5
0
 void info_OnTimeConfigChange(string key, TimeConfig tc)
 {
     if (TimeConfigCollection.Single[key] == null)
     {
         TimeConfigCollection.Single.Add(key, tc);
     }
     else
     {
         TimeConfigCollection.Single[key] = tc;
     }
 }
Esempio n. 6
0
 //************************ЗАПРОС ТЕКУЩЕГО ВРЕМЕНИ ************************************************//
 //************************************************************************************************//
 private void timeTimer_Tick(object sender, EventArgs e)
 {
     if (!serialPort.IsOpen)
     {
         timeLabel.Text = "Порт закрыт"; timeRequestNow = false; return;
     }
     if (timeRequestNow)
     {
         return;
     }
     TimeConfig.SendReadTimeRequest(serialPort, TimeRecieved, systemConfiguration.TimeConfig);
 }
Esempio n. 7
0
        /// <summary>
        /// 添加时间配置
        /// </summary>
        /// <param name="key"></param>
        /// <param name="config"></param>
        /// <returns>添加成功返回true, key已存在返回false</returns>
        public bool Add(string key, TimeConfig config)
        {
            lock (timeConfigMap)
            {
                if (!timeConfigMap.ContainsKey(key))
                {
                    timeConfigMap.Add(key, config);
                    SaveConfigToFile();
                    return(true);
                }

                return(false);
            }
        }
Esempio n. 8
0
        public void SerializeTimeConfigMapTest()
        {
            string     key = "aaa";
            TimeConfig tc  = new TimeConfig();
            DateTime   now = DateTime.Now;

            tc.StartTime = now.AddHours(-1).TimeOfDay;
            tc.EndTime   = now.AddHours(1).TimeOfDay;

            TimeConfigCollection.Single.Add(key, tc);

            tc.StartTime = now.AddHours(-2).TimeOfDay;

            TimeConfigCollection.Single.Add("dddd", tc);
        }
Esempio n. 9
0
        public async Task <IActionResult> Index()
        {
            var model = new EffectsConfig
            {
                LightGroups        = await _hueClient.GetGroupsAsync(),
                SunPhases          = TimeConfig.GetSunPhases(_options.Location),
                XmasEffectConfig   = await _storageService.LoadConfig <XmasEffectConfig>(),
                WarmupEffectConfig = await _storageService.LoadConfig <WarmupEffectConfig>()
            };

            model.XmasEffectConfig.Active               = _backgroundService.ActiveHandler != null && _backgroundService.ActiveHandler.GetType() == typeof(XmasHandler);
            model.WarmupEffectConfig.Active             = _backgroundService.ActiveHandler != null && _backgroundService.ActiveHandler.GetType() == typeof(WarmupHandler);
            model.WarmupEffectConfig.TurnOnAt.Location  = _options.Location; // TODO: It would be nice to have this injected into TimeConfig
            model.WarmupEffectConfig.TurnOffAt.Location = _options.Location;

            return(View(model));
        }
Esempio n. 10
0
        public IRouteComponent Limit(uint period)
        {
            if (source.attributes.length() <= 0)
            {
                throw new IllegalRouteOperationException("Cannot limit frequency of null data");
            }

            bool hasTimePassthrough = state.bridge.lookupModuleInfo(DATA_PROCESSOR).revision >= DataProcessor.TIME_PASSTHROUGH_REVISION;

            if (!hasTimePassthrough && source.eventConfig[0] == (byte)SENSOR_FUSION)
            {
                throw new IllegalRouteOperationException("Cannot limit frequency of sensor fusion data");
            }

            var config = new TimeConfig(source.attributes.length(), (byte)(hasTimePassthrough ? 2 : 0), period);
            var next   = source.transform(config, state.bridge.GetModule <IDataProcessor>() as DataProcessor);

            return(postCreate(next.Item2, new TimeEditorInner(config, next.Item1, state.bridge)));
        }
Esempio n. 11
0
        public void SynchronizeTimeConfigTest()
        {
            if (File.Exists(TimeConfigCollection.Single.configFilePath))
            {
                File.Delete(TimeConfigCollection.Single.configFilePath);
            }

            Assert.AreEqual(false, File.Exists(TimeConfigCollection.Single.configFilePath));

            TimeConfigCollection.Single.Clear();
            Assert.AreEqual(0, TimeConfigCollection.Single.Count);

            HeartServerDirMonitor.Single.RefreshDir();

            HeartServerInfo hsi = null;

            foreach (KeyValuePair <string, HeartServerInfo> item in HeartServerDirMonitor.Single)
            {
                hsi = item.Value;
                break;
            }

            DateTime   now = DateTime.Now;
            TimeConfig tc  = new TimeConfig()
            {
                StartTime = now.AddHours(-1).TimeOfDay,
                EndTime   = now.AddHours(1).TimeOfDay
            };

            if (hsi != null)
            {
                hsi.SpanInfo = tc;
            }

            Assert.AreEqual(true, File.Exists(TimeConfigCollection.Single.configFilePath));

            Assert.AreEqual(1, TimeConfigCollection.Single.Count);

            Assert.AreEqual(tc, TimeConfigCollection.Single[hsi.Name]);
        }
        public void CreateEventlogXMLFile(string FileName)
        {
            XmlDocument  document;
            XmlNode      element;
            XmlAttribute attribute;
            string       str;

            if (!CheckSystemConfiguration())
            {
                throw new Exception("Invalid Format!");
            }

            #region CreateFile
            try
            {
                XmlTextWriter textWritter = new XmlTextWriter(FileName, Encoding.UTF8);
                textWritter.WriteStartDocument();
                textWritter.WriteStartElement("Eventlog");
                textWritter.WriteEndElement();
                textWritter.Close();
            }
            catch
            {
                throw new Exception(appTexts.ParameterName(92));
            }

            document = new XmlDocument();
            try
            {
                document.Load(FileName);
            }
            catch
            {
                throw new Exception(appTexts.ParameterName(92));
            }

            #endregion

            #region EventLogSetup
            element = document.CreateElement("EventLogSetup");
            document.DocumentElement.AppendChild(element);            // указываем родителя

            attribute       = document.CreateAttribute("EventCount"); // создаём атрибут
            attribute.Value = systemConfiguration.EventCount.ToString();
            element.Attributes.Append(attribute);                     // добавляем атрибут
            #endregion

            for (int eventIndex = 0; eventIndex < systemConfiguration.EventCount; eventIndex++)
            {
                element = document.CreateElement("Event" + eventIndex.ToString());
                document.DocumentElement.AppendChild(element);
                ushort[] eventLine = eventLogData[eventIndex];

                #region EventType
                str       = "0x" + eventLine[systemConfiguration.EventCodeAddr].ToString("X4");
                attribute = document.CreateAttribute("Type");     // создаём атрибут
                try
                {
                    str = systemConfiguration.EventCodes[str].ToString();
                }
                catch
                {
                    str = "Нет данных";
                }
                attribute.Value = str;
                element.Attributes.Append(attribute);     // добавляем атрибут
                #endregion

                #region Time

                string strtt = "";
                int    ii    = systemConfiguration.EventTimeAddr;
                strtt = TimeConfig.ExtractTimeFromArray(eventLine, systemConfiguration.TimeConfig, ii);
//                    strtt = strtt + (eventLine[ii+2] & 0x00FF).ToString("X2") + ":";
//                    strtt = strtt + (eventLine[ii + 1] & 0x00FF).ToString("X2") + ":" + (eventLine[ii + 0] & 0x00FF).ToString("X2") + " ";

//                    strtt = strtt + (eventLine[ii + 4] & 0x00FF).ToString("X2") + "/" + (eventLine[ii + 5] & 0x001F).ToString("X2") + "/";
//                   strtt = strtt + "20" + (eventLine[ii + 6] & 0x00FF).ToString("X2");

                attribute       = document.CreateAttribute("Time"); // создаём атрибут
                attribute.Value = strtt;
                element.Attributes.Append(attribute);               // добавляем атрибут

                #endregion

                #region MeasureParams
                attribute       = document.CreateAttribute("MeasureCount"); // создаём атрибут
                attribute.Value = systemConfiguration.MeasureParams.Count.ToString();
                element.Attributes.Append(attribute);                       // добавляем атрибут

                for (int i = 0; i < systemConfiguration.MeasureParams.Count; i++)
                {
                    attribute       = document.CreateAttribute("MeasureName" + i.ToString()); // создаём атрибут
                    attribute.Value = systemConfiguration.MeasureParams[i].ParameterName;
                    element.Attributes.Append(attribute);                                     // добавляем атрибут

                    ushort u = eventLine[systemConfiguration.MeasureParams[i].Addr];
                    string d = u.ToFormatStr(systemConfiguration.MeasureParams[i].Format);
                    attribute       = document.CreateAttribute("Measure" + i.ToString()); // создаём атрибут
                    attribute.Value = d;
                    element.Attributes.Append(attribute);                                 // добавляем атрибут
                }

                #endregion

                #region digInputs
                int digInCount = 0;
                foreach (DigitPlate digitPlate in systemConfiguration.DigitPlates)
                {
                    if (digitPlate.DigitType == DigitType.DigInput)
                    {
                        ushort u    = eventLine[digitPlate.EventStructAddr];
                        ushort mask = digitPlate.UseMask;

                        for (int i = 0; i < 16; i++)
                        {
                            if (ConvertFuncs.GetBit(mask, i))
                            {
                                attribute       = document.CreateAttribute("DigInName" + digInCount.ToString());  // создаём атрибут
                                attribute.Value = digitPlate.DigitNames[i];
                                element.Attributes.Append(attribute);                                             // добавляем атрибут

                                attribute       = document.CreateAttribute("DigInValue" + digInCount.ToString()); // создаём атрибут
                                attribute.Value = ConvertFuncs.GetBit(u, i).ToString();
                                element.Attributes.Append(attribute);                                             // добавляем атрибут
                                digInCount++;
                            }
                        }
                    }
                }

                attribute       = document.CreateAttribute("DigInCount"); // создаём атрибут
                attribute.Value = digInCount.ToString();
                element.Attributes.Append(attribute);                     // добавляем атрибут


                #endregion

                #region digOutputs
                int digOutCount = 0;
                foreach (DigitPlate digitPlate in systemConfiguration.DigitPlates)
                {
                    if (digitPlate.DigitType == DigitType.DigOutput)
                    {
                        ushort u    = eventLine[digitPlate.EventStructAddr];
                        ushort mask = digitPlate.UseMask;

                        for (int i = 0; i < 16; i++)
                        {
                            if (ConvertFuncs.GetBit(mask, i))
                            {
                                attribute       = document.CreateAttribute("DigOutName" + digOutCount.ToString());  // создаём атрибут
                                attribute.Value = digitPlate.DigitNames[i];
                                element.Attributes.Append(attribute);                                               // добавляем атрибут

                                attribute       = document.CreateAttribute("DigOutValue" + digOutCount.ToString()); // создаём атрибут
                                attribute.Value = ConvertFuncs.GetBit(u, i).ToString();
                                element.Attributes.Append(attribute);                                               // добавляем атрибут
                                digOutCount++;
                            }
                        }
                    }
                }

                attribute       = document.CreateAttribute("DigOutCount"); // создаём атрибут
                attribute.Value = digOutCount.ToString();
                element.Attributes.Append(attribute);                      // добавляем атрибут


                #endregion

                #region Warnings
                int warnsCount = 0;
                foreach (WarningParam wp in systemConfiguration.WarningParams)
                {
                    ushort u = eventLine[wp.EventPosAddr];
                    // System.Windows.Forms.MessageBox.Show(wp.Titl+":  0x"+u.ToString("X4"));
                    for (int i = 0; i < 16; i++)
                    {
                        if (ConvertFuncs.GetBit(u, i))
                        {
                            attribute       = document.CreateAttribute("WarningName" + warnsCount.ToString()); // создаём атрибут
                            attribute.Value = wp.Names[i];
                            element.Attributes.Append(attribute);                                              // добавляем атрибут
                            warnsCount++;
                        }
                    }
                }

                attribute       = document.CreateAttribute("WarningsCount"); // создаём атрибут
                attribute.Value = warnsCount.ToString();
                element.Attributes.Append(attribute);                        // добавляем атрибут

                #endregion

                #region Alarms
                int alarmsCount = 0;
                foreach (WarningParam wp in systemConfiguration.AlarmParams)
                {
                    ushort u = eventLine[wp.EventPosAddr];
                    for (int i = 0; i < 16; i++)
                    {
                        if (ConvertFuncs.GetBit(u, i))
                        {
                            attribute       = document.CreateAttribute("AlarmName" + alarmsCount.ToString()); // создаём атрибут
                            attribute.Value = wp.Names[i];
                            element.Attributes.Append(attribute);                                             // добавляем атрибут
                            alarmsCount++;
                        }
                    }
                }

                attribute       = document.CreateAttribute("AlarmsCount"); // создаём атрибут
                attribute.Value = alarmsCount.ToString();
                element.Attributes.Append(attribute);                      // добавляем атрибут

                #endregion
            }

            try
            {
                document.Save(FileName);
            }
            catch
            {
                throw new Exception(appTexts.ParameterName(92));
            }
        }