Пример #1
0
        private static double GetMajorStep(List <GraphData> graphData, SensorClass sensorClass)
        {
            var maxRange  = graphData.Max(t => t.Y) - graphData.Min(t => t.Y);
            var majorStep = maxRange / 4;

            switch (sensorClass)
            {
            case SensorClass.AccelerationX:
            case SensorClass.AccelerationY:
            case SensorClass.AccelerationZ:
            case SensorClass.BatteryVoltage:
            case SensorClass.LastCharged:
            case SensorClass.Pressure:
                return(majorStep);

            case SensorClass.Temperature:
                return(5);

            case SensorClass.Humidity:
                return(20);

            default:
                return(majorStep);
            }
        }
Пример #2
0
        private static double GetMinimumValue(List <GraphData> graphData, SensorClass category)
        {
            var dataMinValue = graphData.Min(t => t.Y);
            var dataMaxValue = graphData.Max(t => t.Y);
            var maxRange     = dataMaxValue - dataMinValue;

            var minValue = dataMinValue - maxRange * 0.3;

            switch (category)
            {
            case SensorClass.AccelerationX:
            case SensorClass.AccelerationY:
            case SensorClass.AccelerationZ:
            case SensorClass.BatteryVoltage:
            case SensorClass.LastCharged:
            case SensorClass.Pressure:
                return(minValue);

            case SensorClass.Temperature:
                return(minValue - 5);

            case SensorClass.Humidity:
                return(0);

            default:
                return(minValue);
            }
        }
Пример #3
0
        private static double GetMajorStep(double minValue, double maxValue, SensorClass sensorClass)
        {
            var maxRange  = maxValue - minValue;
            var majorStep = maxRange / 4;

            switch (sensorClass)
            {
            case SensorClass.AccelerationX:
            case SensorClass.AccelerationY:
            case SensorClass.AccelerationZ:
            case SensorClass.BatteryVoltage:
            case SensorClass.LastCharged:
            case SensorClass.Pressure:
                return(majorStep);

            case SensorClass.Temperature:
                return(5);

            case SensorClass.Humidity:
                return(20);

            default:
                return(majorStep);
            }
        }
Пример #4
0
        public static IPlotModel GetPlotModel(MeasurementHistory historyData, SensorClass sensorClass, string sensorName)
        {
            var graphDataPoints = new List <GraphData>();

            foreach (var item in historyData.Values.OrderBy(i => i.Timestamp))
            {
                graphDataPoints.Add(new GraphData()
                {
                    Y = double.Parse(item.Value, CultureInfo.InvariantCulture),
                    X = item.Timestamp
                });
            }

            var theme = (ColorThemeEnum)Preferences.Get(ColorTheme.ColorThemePreferenceName, 0);

            var plotModel = new ViewResolvingPlotModel()
            {
                Title = $"{sensorName} ({historyData.Unit})"
            };
            var ls = new AreaSeries()
            {
                DataFieldX = "X", DataFieldY = "Y", ItemsSource = graphDataPoints
            };

            plotModel.Series.Add(ls);

            // If values are all same, use custom min/max values to show graph
            var minValue = GetMinimumValue(graphDataPoints, sensorClass);
            var maxValue = GetMaximumValue(graphDataPoints, sensorClass);

            if (minValue == maxValue)
            {
                minValue = minValue - 5;
                maxValue = maxValue + 5;
            }

            plotModel.Axes.Add(GetLinearAxis(theme, AxisPosition.Left, minValue, maxValue, GetMajorStep(minValue, maxValue, sensorClass)));
            plotModel.Axes.Add(GetLinearAxis(theme, AxisPosition.Right, minValue, maxValue, GetMajorStep(minValue, maxValue, sensorClass)));
            plotModel.Axes.Add(GetDateTimeAxis(theme));

            switch (theme)
            {
            default:
            case ColorThemeEnum.Gray:
                plotModel.TitleColor                    = OxyColors.WhiteSmoke;
                plotModel.PlotAreaBorderColor           = OxyColors.DimGray;
                ((LineSeries)plotModel.Series[0]).Color = OxyColor.Parse("#FF9FA8DA");
                break;

            case ColorThemeEnum.Light:
                plotModel.TitleColor                    = OxyColors.Black;
                plotModel.PlotAreaBorderColor           = OxyColors.Black;
                ((LineSeries)plotModel.Series[0]).Color = OxyColor.Parse("#FF3F51B5");
                break;
            }
            return(plotModel);
        }
Пример #5
0
    public override void DockableWindowFunc(int id)
    {
        DoResizing();
        GUILayout.Space(GameManager.Instance.GUIManager.MinimizeButtonRect.height);

        if (_SelectedUnit != null)
        {
            foreach (SensorInfo si in _SelectedUnit.Info.Sensors)
            {
                SensorClass sc = GameManager.Instance.GetSensorClass(si.SensorClassId);
                if (sc != null && sc.IsPassiveActiveSensor)
                {
                    if (GUILayout.Button(si.Name))
                    {
                        _SelectedSensor = si;
                    }
                    else if (_SelectedSensor != null)
                    {
                        if (_SelectedSensor.Id == si.Id)
                        {
                            if (_SelectedSensor.IsActive != si.IsActive)
                            {
                                _SelectedSensor = si;
                            }
                        }
                        //~ _SelectedSensor = si;
                    }
                }
            }

            if (_SelectedSensor != null)
            {
                Separator.fixedWidth = WindowRect.width - this.PaddingLeft * 2;

                GUILayout.Label("", Separator);

                GUILayout.BeginVertical();

                GUILayout.Label(string.Format("Status: {0}", _SelectedSensor.IsOperational == true ? "Operational" : string.Format("Ready in : {0} seconds", _SelectedSensor.ReadyInSec)));

                if (GUILayout.Button(_SelectedSensor.IsActive == true ? "Set passive" : "Set active"))
                {
                    GameManager.Instance.OrderManager.SetSensorPassiveActive(_SelectedUnit.Info, _SelectedSensor, !_SelectedSensor.IsActive);
                }

                GUILayout.Label(_SelectedSensor.ToString());

                GUILayout.EndVertical();
            }
        }
        else
        {
            GUILayout.Label("Not Connected");
        }
    }
Пример #6
0
        public static PlotModel GetPlotModel(MeasurementHistory historyData, SensorClass sensorClass, string sensorName)
        {
            var graphDataPoints = new List <GraphData>();

            foreach (var item in historyData.Values.OrderBy(i => i.Timestamp))
            {
                graphDataPoints.Add(new GraphData()
                {
                    Y = double.Parse(item.Value, CultureInfo.InvariantCulture),
                    X = item.Timestamp
                });
            }

            var theme = (ColorThemeEnum)Preferences.Get(ColorTheme.ColorThemePreferenceName, 0);

            var plotModel = new PlotModel()
            {
                Title = $"{sensorName} ({historyData.Unit})"
            };
            var ls = new AreaSeries()
            {
                DataFieldX = "X", DataFieldY = "Y", ItemsSource = graphDataPoints
            };

            plotModel.Series.Add(ls);

            plotModel.Axes.Add(GetLinearAxis(theme, AxisPosition.Left, GetMinimumValue(graphDataPoints, sensorClass), GetMaximumValue(graphDataPoints, sensorClass), GetMajorStep(graphDataPoints, sensorClass)));
            plotModel.Axes.Add(GetLinearAxis(theme, AxisPosition.Right, GetMinimumValue(graphDataPoints, sensorClass), GetMaximumValue(graphDataPoints, sensorClass), GetMajorStep(graphDataPoints, sensorClass)));
            plotModel.Axes.Add(GetDateTimeAxis(theme));

            switch (theme)
            {
            default:
            case ColorThemeEnum.Gray:
                plotModel.TitleColor                    = OxyColors.WhiteSmoke;
                plotModel.PlotAreaBorderColor           = OxyColors.DimGray;
                ((LineSeries)plotModel.Series[0]).Color = OxyColors.LightBlue;
                break;

            case ColorThemeEnum.Green:
                plotModel.TitleColor                    = OxyColors.WhiteSmoke;
                plotModel.PlotAreaBorderColor           = OxyColors.DimGray;
                ((LineSeries)plotModel.Series[0]).Color = OxyColors.LightSkyBlue;
                break;

            case ColorThemeEnum.Light:
                plotModel.TitleColor                    = OxyColors.Black;
                plotModel.PlotAreaBorderColor           = OxyColors.Black;
                ((LineSeries)plotModel.Series[0]).Color = OxyColors.DimGray;
                break;
            }
            return(plotModel);
        }
Пример #7
0
        private void BtnSave(object sender, EventArgs e)
        {
            RegistryKey key = Registry.CurrentUser.OpenSubKey("sermed");

            key = Registry.CurrentUser.CreateSubKey("Software\\Classes\\" + "sermed");
            key.SetValue(string.Empty, "URL:sermed Protocol");
            key.SetValue("URL Protocol", string.Empty);
            key = key.CreateSubKey(@"shell\open\command");
            string applicationLocation = typeof(Program).Assembly.Location;

            key.SetValue("", "\"" + applicationLocation + "\" \"%1\"");
            key.Close();
            if (cmbPortName.SelectedIndex != -1 & cmbTimeout.SelectedIndex != -1)
            {
                if (!ComPort.IsOpen)
                {
                    connect();
                }
                var hexSexonds = Convert.ToString(long.Parse(cmbTimeout.SelectedItem.ToString()), 16);
                if (hexSexonds.Length == 1)
                {
                    hexSexonds = "0" + hexSexonds;
                }
                string command = new SensorClass().SetTimeout.Replace("[value]", hexSexonds.ToUpper());
                byte[] data    = new Shared().HexStringToByteArray(command);
                byte[] cheked  = new Shared().checksum(data);
                ComPort.Write(cheked, 0, cheked.Length);
                if (ComPort.IsOpen)
                {
                    ComPort.Close();
                }
                try
                {
                    sermed.Properties.Settings.Default.Port    = cmbPortName.SelectedItem.ToString();
                    sermed.Properties.Settings.Default.TimeOut = cmbTimeout.SelectedItem.ToString();
                    sermed.Properties.Settings.Default.Equipo  = equipo.Text.ToString();
                    sermed.Properties.Settings.Default.Save();
                    MessageBox.Show(this, "Configuración guardada", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    disconnect();
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, "Error al guardar configuración:", "", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    Console.WriteLine("Exception: " + ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Por favor seleccióne todos los parámetros requeridos.", "", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
Пример #8
0
        // CheckedListBox load
        private void LoadCheckedListBox()
        {
            List <SensorClass> lst = new List <SensorClass>();

            // Get sensors from Database
            foreach (var sensor in sensorNames)
            {
                lst.Add(new SensorClass(sensor, true));
            }
            ((ListBox)this.checkedListBox1).DataSource    = lst;
            ((ListBox)this.checkedListBox1).DisplayMember = "Name";
            ((ListBox)this.checkedListBox1).ValueMember   = "IsChecked";


            for (int i = 0; i < checkedListBox1.Items.Count; i++)
            {
                SensorClass obj = (SensorClass)checkedListBox1.Items[i];
                checkedListBox1.SetItemChecked(i, obj.IsChecked);
            }
        }
Пример #9
0
        public void WriteFP()
        {
            string command = new SensorClass().WriteStart;

            data = new Shared().HexStringToByteArray(command);
            ComPort.Write(data, 0, data.Length);
            byte[] byteBuffer = bufferRead();
            if (byteBuffer.Length > 1)
            {
                command = new SensorClass().FPBase.Replace("[value]", "1");
                data    = new Shared().HexStringToByteArray(command);
                byte[] huellaByte = System.Convert.FromBase64String(huella);
                byte[] concatData = new Shared().ConcatByte(data, huellaByte);
                byte[] cheked     = new Shared().checksum(concatData);
                ComPort.Write(cheked, 0, cheked.Length);
                byteBuffer = bufferRead();
                command    = new SensorClass().Verify;
                data       = new Shared().HexStringToByteArray(command);
                ComPort.Write(data, 0, data.Length);
                ReadProcess();
            }
        }
Пример #10
0
        private void EnviarHuella()
        {
            string command = new SensorClass().GetFP.Replace("[value]", "1");

            data = new Shared().HexStringToByteArray(command);
            byte[] cheked = new Shared().checksum(data);
            ComPort.Write(cheked, 0, cheked.Length);
            byte[] byteBuffer = bufferRead();
            byte[] huellaByte = new Shared().GetCleanFP(byteBuffer);
            String Base64     = Convert.ToBase64String(huellaByte);
            var    datos      = ApiCall.SendFPReq("INSERTAR", document, dedo, Base64, "enrol");

            if (datos.P_OK == "SI" || datos.P_OK == "1")
            {
                lblstep.Text = "Huella enrolada correctamente";
                retry.Invoke(new Action(() => retry.Visible = true));
            }
            else if (datos.P_OK == "NO" || datos.P_OK == "0")
            {
                label2.Text = "Error en el envío de huella a server";
            }
        }
Пример #11
0
        public void TestUnitDatabaseIntegrity()
        {
            Player player = new Player();

            player.Name             = "GoodGuy";
            player.IsComputerPlayer = true;
            GameManager.Instance.GameData.InitAllData();
            foreach (var uc in GameManager.Instance.GameData.UnitClasses)
            {
                foreach (var carried in uc.CarriedUnitClassses)
                {
                    var unitClass = GameManager.Instance.GetUnitClassById(carried.UnitClassId);
                    Assert.IsNotNull(unitClass, string.Format("UnitClass {0}, Carried Unitclass '{1}' not found",
                                                              uc.UnitClassShortName, carried.UnitClassId));
                }

                foreach (var sensorClassId in uc.SensorClassIdList)
                {
                    var sensor = GameManager.Instance.GetSensorClassById(sensorClassId);
                    Assert.IsNotNull(sensor, string.Format("UnitClass {0}, SensorClass '{1}' not found",
                                                           uc.UnitClassShortName, sensorClassId));
                }

                foreach (var wploads in uc.WeaponLoads)
                {
                    foreach (var wpload in wploads.WeaponLoads)
                    {
                        WeaponClass weaponClass = GameManager.Instance.GameData.GetWeaponClassById(wpload.WeaponClassId);
                        Assert.IsNotNull(weaponClass, string.Format("UnitClass {0}, Load {1}: WeaponClass '{2}' not found",
                                                                    uc.UnitClassShortName, wploads.Name, wpload.WeaponClassId));
                        Assert.IsTrue(!string.IsNullOrEmpty(weaponClass.WeaponClassShortName), "WeaponClass should have a ShortName");
                        if (weaponClass.SpawnsUnitOnFire)
                        {
                            var spawnUnitClass = GameManager.Instance.GetUnitClassById(weaponClass.SpawnUnitClassId);
                            Assert.IsNotNull(spawnUnitClass, string.Format("UnitClass {0}, Load {1}: SpawnedUnitClass '{2}' not found",
                                                                           uc.UnitClassShortName, wploads.Name, weaponClass.SpawnUnitClassId));
                        }
                    }
                }
            }
            foreach (var sc in GameManager.Instance.GameData.Scenarios)
            {
                foreach (var alliance in sc.Alliences)
                {
                    foreach (var pl in alliance.ScenarioPlayers)
                    {
                        foreach (var gr in pl.Groups)
                        {
                            foreach (var u in gr.Units)
                            {
                                var uc = GameManager.Instance.GameData.GetUnitClassById(u.UnitClassId);
                                Assert.IsNotNull(uc, "Unit class '" + u.UnitClassId + "' not found.");
                            }
                        }
                    }
                }
            }
            foreach (var camp in GameManager.Instance.GameData.Campaigns)
            {
                foreach (var campScen in camp.CampaignScenarios)
                {
                    var scen = GameManager.Instance.GameData.GetGameScenarioById(campScen.ScenarioId);
                    Assert.IsNotNull(scen,
                                     string.Format("Campaign {0}, Scenario {1} not found.", camp.Id, campScen.ScenarioId));
                    //foreach (var reqScenId in campScen.RequiresCompletedScenarioIds)
                    //{
                    //    var reqScen = GameManager.Instance.GameData.GetGameScenarioById(reqScenId);
                    //    Assert.IsNotNull(reqScen,
                    //        string.Format("Campaign {0}, Required Scenario {1} not found.", camp.Id, reqScenId));

                    //}
                }
            }

            //Test for duplicates

            var ucSorted = from ucs in GameManager.Instance.GameData.UnitClasses
                           orderby ucs.Id
                           select ucs;
            UnitClass prevUc = null;

            foreach (var uc in ucSorted)
            {
                if (prevUc != null)
                {
                    Assert.IsFalse(prevUc.Id == uc.Id, uc.Id + " is a duplicate UnitClass.");
                }
                prevUc = uc;
            }

            var wcSorted = from wpc in GameManager.Instance.GameData.WeaponClasses
                           orderby wpc.Id
                           select wpc;
            WeaponClass prevWc = null;

            foreach (var wc in wcSorted)
            {
                if (prevWc != null)
                {
                    Assert.IsFalse(prevWc.Id == wc.Id, wc.Id + " is a duplicate WeaponClass.");
                }
            }

            var scSorted = from sc in GameManager.Instance.GameData.SensorClasses
                           orderby sc.Id
                           select sc;
            SensorClass prevSc = null;

            foreach (var sc in scSorted)
            {
                if (prevSc != null)
                {
                    Assert.IsFalse(prevSc.Id == sc.Id, sc.Id + " is a duplicate SensorClass.");
                }
            }
        }
 public static async Task <ResourceResponse <Document> > NewTemperatureSampleDocumentAsync(this DocumentClient client, string link, string locationName, Region locationRegion, double lat, double lon, Guid sensorId, SensorClass sensorClass, double value)
 {
     return(await NewTemperatureSampleDocumentAsync(
                client
                , link
                , new Location
     {
         Name = locationName
         ,
         Region = locationRegion
         ,
         Latitude = lat
         ,
         Longitude = lon
     }
                , new Sensor
     {
         Id = sensorId
         ,
         Class = sensorClass
     }
                , value
                ));
 }
Пример #13
0
 // Constructor
 internal OffsetClass(SensorClass ParentSensor)
 {
     _parentSensor = ParentSensor;
 }
Пример #14
0
 // Constructor
 internal AveragingClass(SensorClass ParentSensor)
 {
     _parentSensor = ParentSensor;
 }