// Use this for initialization void Start() { SmallMultiplesManagerScript smms = GameObject.Find("SmallMultiplesManager").GetComponent <SmallMultiplesManagerScript>(); ToolTipPrefab = smms.tooltipPrefab; silhouetteShader = smms.silhouetteShader; bs = this.transform.parent.parent.parent.GetComponent <BuildingScript>(); si = transform.Find("sensorInfo").gameObject.GetComponent <SensorInfo>(); ReadDataFromManager(); if (hasInfo) { //si.getMonthlySensorReadings (); if (smms.dateType == DateType.Monthly) { si.getMonthlySensorReadings(); } if (smms.dateType == DateType.Fornightly) { si.getSensorReadings(smms.smallMultiplesNumber, 14); } if (smms.dateType == DateType.Weekly) { si.getSensorReadings(smms.smallMultiplesNumber, 7); } ChangeColor(); SendTempTag(); } }
public static void UpdateAlarm(PlotterDisplayEx pdeGraph, SensorInfo sensor, bool autoRefresh = true) { int limitGraph = sensor.Alarm_Value; if (pdeGraph == null || pdeGraph.DataSources == null || pdeGraph.DataSources.Count == 0) { return; } var limitSet = pdeGraph.DataSources[pdeGraph.DataSources.Count - 1].YD1 > limitGraph ? limitGraph : 0; pdeGraph.drawAlarmLine = pdeGraph.DataSources[pdeGraph.DataSources.Count - 1].YD1 > limitGraph; if (sensor.MeasureType == clsConst.MeasureMode_Decay) { pdeGraph.drawAlarmLine = false; } pdeGraph.DataSources[pdeGraph.DataSources.Count - 1].maxValue = limitSet; pdeGraph.DataSources[pdeGraph.DataSources.Count - 1].UpLimit = limitSet; pdeGraph.DataSources[pdeGraph.DataSources.Count - 1].DownLimit = -limitSet; if (autoRefresh) { RefreshGraph(pdeGraph); } }
public void AddSensor(SensorInfo sensor) { if (sensor == null) { throw new ArgumentNullException("sensor"); } var sensorDriver = sensor.Driver; Action <Event> driverEventCallback = (Event se) => { if (!SystemContext.ZoneManagement.IsZoneDisabled(sensor.Zone)) { SystemContext.SensorEventsHandler.HandleSensorEvent(sensor, se); } }; Action <SensorState> driverStateCallback = (SensorState ss) => { if (!SystemContext.ZoneManagement.IsZoneDisabled(sensor.Zone)) { SystemContext.SensorEventsHandler.HandleStateChangedEvent(sensor, ss); } }; sensorDriver.EventCallback = driverEventCallback; sensorDriver.StateChangedCallback = driverStateCallback; _sensors[sensor.SensorId] = sensor; }
public bool CheckAdd(SensorInfo sensorInfo) { bool flag = false; int groupId = 0; List <SensorInfo> sensorInfosList = sensorInfos.Values.ToList(); for (int i = 0; i < sensorInfosList.Count; i++) { if (sensorInfosList[i].ChannelId == sensorInfo.ChannelId && sensorInfosList[i].ModuleNo == sensorInfo.ModuleNo && sensorInfosList[i].Safetyfactortypeid == sensorInfo.Safetyfactortypeid && sensorInfosList[i].DataBaseId == sensorInfo.DataBaseId) { flag = true; break; } } if (!flag) { var bll = new SensorInfoBll(); int id = bll.AddSensorInfo(sensorInfo); if (id > 0) { sensorInfo.ID = id; sensorInfoDic.sensorInfos.Add(id, sensorInfo); return(true); } } return(false); }
public Form1() { InitializeComponent(); EnvMeta = new EnvironmentInfo(MapPanel.Height, MapPanel.Width, decimal.ToInt32(MapScaleSpinBttn.Value), (double)ObstacleWidthSpinBttn.Value); SensorMeta = new SensorInfo(decimal.ToInt32(SensorAngleSpinBttn.Value), (double)SensorDistanceSpinBttn.Value, (double)SigmaHitSpinBttn.Value, (double)ZHitSpinBttn.Value, (double)ZRandSpinBttn.Value, (double)ZMaxSpinBttn.Value); RobotMeta = new RobotInfo((double)a1SpinBttn.Value, (double)a2SpinBttn.Value, (double)a3SpinBttn.Value, (double)a4SpinBttn.Value, (double)RobotRadiusSpinBttn.Value, (double)RobotTransStepSpinBttn.Value, (double)RobotRotStepSpinBttn.Value, new Point(EnvMeta.Width / 2, EnvMeta.Height / 2)); ParticleMeta = new ParticleInfo(0, ResampleMethod.Multinomial); ParticleList.View = View.Details; }
public void DisplaySensorInfo() { if (BlockInfo == null) { return; } var lstSensor = AppManager.ListSensor.Where(s => s.OfBlock == BlockInfo.BlockId).ToList(); var w_sensor = 133; pnSensor.Controls.Clear(); for (var j = 0; j < lstSensor.Count; j++) { SensorInfo inf = lstSensor[j]; var objPanelContent = new SensorItemView() { Info = inf, Location = new Point(j * w_sensor, 0), Anchor = (((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right) }; pnSensor.Controls.Add(objPanelContent); //event click label objPanelContent.OnClick += new EventHandler((sender, e) => { SensorInfo itemSelected = sender as SensorInfo; OnSelectedItem?.Invoke(itemSelected); }); } }
private static void DescribeVideoModes(SensorInfo sensorInfo) { foreach (var videoMode in sensorInfo.VideoModes) { Console.WriteLine("{0} {1}x{2} @ {3} fps.", videoMode.PixelFormat, videoMode.ResolutionX, videoMode.ResolutionY, videoMode.Fps); } }
IEnumerator GetInfoCR(string url) { string deviceTypeString = "/sensors/"; switch(deviceType) { case (DeviceType.Display): deviceTypeString = "displays/"; break; default: deviceTypeString = "/sensors/"; break; } if (debug) Debug.Log(url + deviceTypeString + sensorName); WWW www = new WWW(url + deviceTypeString + sensorName); yield return www; if (www.error == null) { sensorInfo = JsonUtility.FromJson<SensorInfo>(www.text); if (debug) { Debug.Log(www.text); } } else { Debug.Log("ERROR: " + www.error); } }
private void DrawValue(SensorInfo inf) { var oldInfo = this.Tag as SensorInfo; if (inf.SensorId != oldInfo.SensorId) { return; } var dvc = AppManager.ListBlock.FirstOrDefault(b => b.BlockId == oldInfo.OfBlock); Color backColor = Color.LightGray; if (inf.Active == clsConst.ACTIVE && dvc != null && dvc.Active == clsConst.ACTIVE) { if (inf.Alarm) { backColor = Color.Red; } else { backColor = Color.FromArgb(112, 173, 71); } } this.Tag = inf; this.Text = inf.SensorName; BackColor = backColor; }
private static async Task <string> sendData(DeviceClient deviceClient, Dht11Reading data) { Logger.LogInfo($"Temp:{data.Temperature} Hum:{data.Humidity} Time:{DateTime.UtcNow}"); var info = new SensorInfo { Guid = GUID, Organization = ORGANIZATION, DisplayName = DISPLAYNAME, Location = LOCATION, MeasureName = TEMPMEASURE, UnitOfMeasure = TEMPUNITS, Value = data.Temperature, TimeCreated = DateTime.UtcNow }; string dataBuffer = JsonConvert.SerializeObject(info); Message eventMessage = new Message(Encoding.UTF8.GetBytes(dataBuffer)); await deviceClient.SendEventAsync(eventMessage); info.MeasureName = HUMIDMEASURE; info.UnitOfMeasure = HUMIDUNITS; info.Value = data.Humidity; dataBuffer = JsonConvert.SerializeObject(info); eventMessage = new Message(Encoding.UTF8.GetBytes(dataBuffer)); await deviceClient.SendEventAsync(eventMessage); return(dataBuffer); }
/// <summary> /// 获取所有信息集合 /// </summary> /// <returns>List集合</returns> public static List <SensorInfo> GetSensorInfoList(string where) { List <SensorInfo> infoList = new List <SensorInfo>(); SqlDataReader reader = null; try { reader = GetSensorInfo(where); } catch (Exception) { throw; } while (reader.Read()) { SensorInfo info = new SensorInfo(); info.DataID = int.Parse(reader["DataID"].ToString()); info.TypeOfSensor = reader["TypeOfSensor"].ToString(); info.Granary = int.Parse(reader["Granary"].ToString()); info.Group = int.Parse(reader["Group"].ToString()); info.Line = int.Parse(reader["Line"].ToString()); info.Floor = int.Parse(reader["Floor"].ToString()); info.Data = decimal.Parse(reader["Data"].ToString()); info.Time = reader["Time"].ToString(); infoList.Add(info); } reader.Close(); return(infoList); }
public void ReadData() { try { button1.Enabled = HartDevice != null && HartDevice.IsConnected; button3.Enabled = HartDevice != null && HartDevice.IsConnected; if (HartDevice != null && HartDevice.IsConnected) { OutputInfo oi = HartDevice.ReadOutput(); lblRangeUnit.Text = oi != null?UnitCodeDescr.GetDescr(oi.PVUnitCode) : null; txtPVLower.Text = oi != null?oi.LowerRangeValue.ToString() : null; txtPVUpper.Text = oi != null?oi.UpperRangeValue.ToString() : null; SensorInfo si = HartDevice.ReadPVSensor(); txtSensorLower.Text = si != null?si.LowerLimit.ToString() : null; txtSensorUpper.Text = si != null?si.UpperLimit.ToString() : null; lblUnit1.Text = si != null?UnitCodeDescr.GetDescr((UnitCode)si.UnitCode) : null; SensorMode?sm = HartDevice.ReadSensorMode(); SensorCode?sc = HartDevice.ReadSensorCode(); cmbSensorMode.SelectedIndex = sm != null ? (int)sm.Value : -1; cmbSensorCode.SelectedIndex = sc != null ? (int)sc.Value - 2 : -1; } } catch (Exception) { } }
private void button1_Click(object sender, EventArgs e) { if (cmbSensorCode.SelectedIndex < 0) { MessageBox.Show("没有选择传感器代码", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (cmbSensorMode.SelectedIndex < 0) { MessageBox.Show("没有选择工作模式", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } bool ret = HartDevice.WritePVSensorMode((SensorMode)cmbSensorMode.SelectedIndex, (SensorCode)(cmbSensorCode.SelectedIndex + 2)); MessageBox.Show(ret ? "设置成功" : HartDevice.GetLastError(), "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); if (ret) { OutputInfo oi = HartDevice.ReadOutput(); lblRangeUnit.Text = oi != null?UnitCodeDescr.GetDescr(oi.PVUnitCode) : null; txtPVLower.Text = oi != null?oi.LowerRangeValue.ToString() : null; txtPVUpper.Text = oi != null?oi.UpperRangeValue.ToString() : null; SensorInfo si = HartDevice.ReadPVSensor(); txtSensorLower.Text = si != null?si.LowerLimit.ToString() : null; txtSensorUpper.Text = si != null?si.UpperLimit.ToString() : null; lblUnit1.Text = si != null?UnitCodeDescr.GetDescr((UnitCode)si.UnitCode) : null; } }
/// <summary> /// Gets sensor information. /// </summary> /// <returns>Sensor information.</returns> public SensorInfo GetSensorInfo() { SensorInfo info = new SensorInfo(); info.Type = SensorTypes.PedometerType; try { sensor = new Pedometer { Interval = 100, PausePolicy = SensorPausePolicy.None }; info.Name = sensor.Name; info.Vendor = sensor.Vendor; info.MinRange = sensor.MinValue; info.MaxRange = sensor.MaxValue; info.Resolution = sensor.Resolution; info.MinInterval = sensor.MinInterval; } catch (Exception e) { global::Tizen.Log.Info(Log.LogTag, e.Message); info.Status = "Permission Denied"; } return(info); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { do { var products = _productManager.Products; var productNamesList = products.Select(p => p.Name).ToList(); var cachedValues = _cache.GetValues(productNamesList); DateTime utcNow = DateTime.UtcNow; foreach (var cachedValue in cachedValues) { var lastUpdateInterval = utcNow - cachedValue.Time; if (lastUpdateInterval < _minimumUpdateInterval) { continue; } SensorInfo info = _sensorsInterface.GetSensorInfo(cachedValue.Product, cachedValue.Path); if (info.ExpectedUpdateInterval == TimeSpan.Zero) { continue; } if (lastUpdateInterval < info.ExpectedUpdateInterval) { continue; } SensorData statusObject = CreateStatusUpdateObject(cachedValue); _updatesReceiver.AddUpdate(statusObject); } await Task.Delay(_checkInterval, stoppingToken); } while (!stoppingToken.IsCancellationRequested); }
private static void RandomizeMotionValue(object state) { bool motionDetected = Convert.ToBoolean(Random.Next(0, 2)); SensorInfo sensorInfo = SensorInfosByDataType[MotionDataType]; sensorInfo.UpdateCurrentValue(motionDetected); }
public override void ReturnSensorInfo(int TunnelCode, out SensorInfo m_SensorInfo) { m_SensorInfo = new SensorInfo(); m_SensorInfo.m_Type = "QueryFailed"; m_SensorInfo.m_SN = "QueryFailed"; m_SensorInfo.m_PowerRangeMax = "QueryFailed"; m_SensorInfo.m_PowerRangeMin = "QueryFailed"; m_SensorInfo.m_FreqRangeMax = "QueryFailed"; m_SensorInfo.m_FreqRangeMin = "QueryFailed"; try { m_SensorInfo.m_Type = this.Query("SERVice:SENSor" + TunnelCode.ToString() + ":TYPE?"); } catch { m_SensorInfo.m_Type = "QueryFailed"; } try { m_SensorInfo.m_SN = this.Query("SERVice:SENSor" + TunnelCode.ToString() + ":SNUMber?"); } catch { m_SensorInfo.m_SN = "QueryFailed"; } if (m_SensorInfo.m_Type == "E4413A") { m_SensorInfo.m_PowerRangeMax = "20"; m_SensorInfo.m_PowerRangeMin = "-70"; m_SensorInfo.m_FreqRangeMax = "26.5e9"; m_SensorInfo.m_FreqRangeMin = "50e6"; } else if (m_SensorInfo.m_Type == "N8481B") { m_SensorInfo.m_PowerRangeMax = "44"; m_SensorInfo.m_PowerRangeMin = "-5"; m_SensorInfo.m_FreqRangeMax = "18e9"; m_SensorInfo.m_FreqRangeMin = "10e6"; } }
public int AddSensorInfo(SensorInfo sensorInfo) { using (DbConnection conn = new DbConnection()) { return(sensorInfo.Save()); } }
public void SenseOnce(uint m_localID, UUID m_itemID, string name, UUID keyID, int type, double range, double arc, SceneObjectPart host) { // Add to timer SensorInfo ts = new SensorInfo(); ts.localID = m_localID; ts.itemID = m_itemID; ts.interval = 0; ts.name = name; ts.keyID = keyID; ts.type = type; if (range > maximumRange) { ts.range = maximumRange; } else { ts.range = range; } ts.arc = arc; ts.host = host; SensorSweep(ts); }
public Sensor(SensorInfo sensorInfo) { Meta = sensorInfo; MinAngle = Deg2rad(-sensorInfo.SweepAngle / 2); MaxAngle = Deg2rad(sensorInfo.SweepAngle / 2); CreateUnitVectors(); }
private void Lbl_Click(object sender, EventArgs e) { Label lbl = sender as Label; SensorInfo info = lbl.Tag as SensorInfo; AppManager.OnSensorSelected?.Invoke(info, e); }
public override SensorInfo GetSensorInfo() { SensorInfo info = base.GetSensorInfo(); info.IsDeployedIntermediateDepth = this.IsDeployedIntermediateDepth; return(info); }
public static SensorData Convert(this SensorDataEntity dataEntity, SensorInfo sensorInfo, string productName) { var data = Convert(dataEntity, productName); data.Description = sensorInfo.Description; return(data); }
public void HandleStateChangedEvent(SensorInfo sensorInfo, SensorState newState) { if (sensorInfo == null) { throw new ArgumentNullException("sensorInfo"); } _LogSensorStateChanged(sensorInfo, newState); }
public uint GetSensorZone(SensorInfo sensorInfo) { if (sensorInfo == null) { throw new SensorMissingException("sensorInfo"); } return(sensorInfo.Zone); }
//儲存偵測結果 //[param] cdn = 座標編號 , type = 圖格類型 public void AddResult(Vector2 cdn, ElementImageType type) { SensorInfo _info = new SensorInfo(); _info.coordinate = cdn; _info.elementType = type; SpinResultList.Add(_info); }
public override void ReturnSensorInfo(int TunnelCode, out SensorInfo m_SensorInfo) { m_SensorInfo = new SensorInfo(); m_SensorInfo.m_Type = "QueryFailed"; m_SensorInfo.m_SN = "QueryFailed"; m_SensorInfo.m_PowerRangeMax = "QueryFailed"; m_SensorInfo.m_PowerRangeMin = "QueryFailed"; m_SensorInfo.m_FreqRangeMax = "QueryFailed"; m_SensorInfo.m_FreqRangeMin = "QueryFailed"; string channelGate = ""; if (TunnelCode == 1) { channelGate = "A"; } else if (TunnelCode == 2) { channelGate = "B"; } else { throw new Exception("错误的探头编号!"); } try { m_SensorInfo.m_Type = this.Query("SNTYPE " + channelGate); this.WaitOpc(); } catch { m_SensorInfo.m_Type = "QueryFailed"; m_SensorInfo.m_SN = "QueryFailed"; } string[] typeAndSN = m_SensorInfo.m_Type.Split(','); m_SensorInfo.m_Type = typeAndSN[0]; m_SensorInfo.m_SN = typeAndSN[1]; if (m_SensorInfo.m_Type == "E4413A") { m_SensorInfo.m_PowerRangeMax = "20"; m_SensorInfo.m_PowerRangeMin = "-70"; m_SensorInfo.m_FreqRangeMax = "26.5e9"; m_SensorInfo.m_FreqRangeMin = "50e6"; } else if (m_SensorInfo.m_Type == "N8481B") { m_SensorInfo.m_PowerRangeMax = "44"; m_SensorInfo.m_PowerRangeMin = "-5"; m_SensorInfo.m_FreqRangeMax = "18e9"; m_SensorInfo.m_FreqRangeMin = "10e6"; } else if (m_SensorInfo.m_Type == "MA2473D") { m_SensorInfo.m_PowerRangeMax = "20"; m_SensorInfo.m_PowerRangeMin = "-70"; m_SensorInfo.m_FreqRangeMax = "32e9"; m_SensorInfo.m_FreqRangeMin = "10e6"; } }
public Dictionary <string, string> GetDeviceInfo() { const float MAX_VOL_CUR = 999; //Max value of Voltage and current, if read value is larger than it, then it is meaningless Dictionary <string, string> deviceInfo = new Dictionary <string, string>(); deviceInfo.Add("Board Name", mBoardName); uint readInfo = 0; //F0 Info Qworks.F0Info(ref readInfo, (uint)EnumF0Info.F0Info_Elf, mDeviceID); deviceInfo.Add("F0 ELF Version", F0VersionString(readInfo)); Qworks.F0Info(ref readInfo, (uint)EnumF0Info.F0Info_Bit, mDeviceID); deviceInfo.Add("F0 bit Version", F0VersionString(readInfo)); //F1 Info Qworks.F1Info(ref readInfo, (uint)EnumF1Info.F1Info_Version, mDeviceID); deviceInfo.Add("F1 Version", F1VersionString(readInfo)); Qworks.F1Info(ref readInfo, (uint)EnumF1Info.F1Info_StandingTime, mDeviceID); deviceInfo.Add("F1 Run Time", F1RunTimeString(readInfo)); Qworks.F1Info(ref readInfo, (uint)EnumF1Info.F1Info_ClockFreq, mDeviceID); deviceInfo.Add("F1 Clock Rate", string.Format("{0:F1} (MHz)", (float)readInfo * 1.024 / 1000)); Qworks.F1Info(ref readInfo, (uint)EnumF1Info.F1Info_BitState, mDeviceID); deviceInfo.Add("F1 Bit State", (readInfo == 1) ? "Loaded" : "Unloaded"); Qworks.F1Info(ref readInfo, (uint)EnumF1Info.F1Info_F1F0Link, mDeviceID); deviceInfo.Add("F0 and F1 Link", (readInfo == 1)? "Linked":"Unlinked"); //F1 Ram Size Qworks.F1RamSize(ref readInfo, mDeviceID); deviceInfo.Add("F1 RAM Capacity", string.Format("{0:F1} (kB)", (float)readInfo / 1024)); //Sensor Info SensorInfo sensorInfo = new SensorInfo(); Qworks.SensorInfo(ref sensorInfo, mDeviceID); deviceInfo.Add("F0 VCC INT", string.Format("{0:F2} V", sensorInfo.F0VCCINT > MAX_VOL_CUR? 0.0 : sensorInfo.F0VCCINT)); deviceInfo.Add("F0 VCC AUX", string.Format("{0:F2} V", sensorInfo.F0VCCAUX > MAX_VOL_CUR ? 0.0 : sensorInfo.F0VCCAUX)); deviceInfo.Add("F0 Temperature", string.Format("{0:F2} C", sensorInfo.F0Temperature)); deviceInfo.Add("F1 VCC INT", string.Format("{0:F2} V(Max {1:F2} V)", sensorInfo.F1VCCINT > MAX_VOL_CUR ? 0.0 : sensorInfo.F1VCCINT, sensorInfo.F1VCCINTMAX > MAX_VOL_CUR ? 0.0 : sensorInfo.F1VCCINTMAX)); deviceInfo.Add("F1 VCC AUX", string.Format("{0:F2} V(Max {1:F2} V)", sensorInfo.F1VCCAUX > MAX_VOL_CUR ? 0.0 : sensorInfo.F1VCCAUX, sensorInfo.F1VCCAUXMAX > MAX_VOL_CUR ? 0.0 : sensorInfo.F1VCCAUXMAX)); deviceInfo.Add("F1 Temperature", string.Format("{0:F2} C", sensorInfo.F1Temperature)); deviceInfo.Add("F1 Temperature Max", string.Format("{0:F2} C", sensorInfo.F1TemperatureMax)); deviceInfo.Add("Voltage 12V", string.Format("{0:F2} V", sensorInfo.QGFVoltage12 > MAX_VOL_CUR ? 0.0 : sensorInfo.QGFVoltage12)); deviceInfo.Add("Current of 12V", string.Format("{0:F2} A", sensorInfo.QGFCurrent12 > MAX_VOL_CUR ? 0.0 : sensorInfo.QGFCurrent12)); deviceInfo.Add("Voltage 5V", string.Format("{0:F2} V", sensorInfo.QGFVoltage5 > MAX_VOL_CUR ? 0.0 : sensorInfo.QGFVoltage5)); deviceInfo.Add("Current of 5V", string.Format("{0:F2} A", sensorInfo.QGFCurrent5 > MAX_VOL_CUR ? 0.0 : sensorInfo.QGFCurrent5)); deviceInfo.Add("Temperature 0", string.Format("{0:F2} C", sensorInfo.QGFTemperature0)); deviceInfo.Add("Temperature 1", string.Format("{0:F2} C", sensorInfo.QGFTemperature1)); deviceInfo.Add("Temperature 2", string.Format("{0:F2} C", sensorInfo.QGFTemperature2)); deviceInfo.Add("Temperature 3", string.Format("{0:F2} C", sensorInfo.QGFTemperature3)); return(deviceInfo); }
private void AddSenseRepeater(SensorInfo senseRepeater) { lock (SenseRepeatListLock) { List <SensorInfo> newSenseRepeaters = new List <SensorInfo>(SenseRepeaters); newSenseRepeaters.Add(senseRepeater); SenseRepeaters = newSenseRepeaters; } }
public SensorInfoViewModel(SensorInfo info) { Path = info.Path; ProductName = info.ProductName; Description = info.Description; ExpectedUpdateInterval = info.ExpectedUpdateInterval.ToString(); Unit = info.Unit; SensorType = info.SensorType.ToString(); }
public SensorClientData(SensorInfo ci, SensorData sd) { this.SensorId = ci.SensorId.ToString(); this.Lat = ci.Lat; this.Lng = ci.Lng; this.Name = ci.Name; this.Organization = ci.Organization; this.Humidity = sd.Humidity; this.Temperature = sd.Temperature; }
protected SensorInfo AddSensor( Data.DbDataStore store = null, string name = "Sensor", SpeedUnit speedUnit = SpeedUnit.MetersPerSec, TemperatureUnit tempUnit = TemperatureUnit.Celsius, PressureUnit pressUnit = PressureUnit.KiloPascals ) { if (null == store) store = Store; Assert.IsNotNull(store, "no store"); var sensor = new SensorInfo(name, speedUnit, tempUnit, pressUnit); var sensorAdded = store.AddSensor(sensor); Assert.IsTrue(sensorAdded, "sensor add failed"); return sensor; }
public void CreateFromData(uint localID, UUID itemID, UUID objectID, Object[] data) { SceneObjectPart part = m_CmdManager.m_ScriptEngine.World.GetSceneObjectPart( objectID); if (part == null) return; int idx = 0; while (idx < data.Length) { SensorInfo ts = new SensorInfo(); ts.localID = localID; ts.itemID = itemID; ts.interval = (double)data[idx]; ts.name = (string)data[idx+1]; ts.keyID = (UUID)data[idx+2]; ts.type = (int)data[idx+3]; ts.range = (double)data[idx+4]; ts.arc = (double)data[idx+5]; ts.host = part; ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); AddSenseRepeater(ts); idx += 6; } }
private List<SensedEntity> doObjectSensor(SensorInfo ts) { List<EntityBase> Entities; List<SensedEntity> sensedEntities = new List<SensedEntity>(); // If this is an object sense by key try to get it directly // rather than getting a list to scan through if (ts.keyID != UUID.Zero) { EntityBase e = null; m_CmdManager.m_ScriptEngine.World.Entities.TryGetValue(ts.keyID, out e); if (e == null) return sensedEntities; Entities = new List<EntityBase>(); Entities.Add(e); } else { Entities = new List<EntityBase>(m_CmdManager.m_ScriptEngine.World.GetEntities()); } SceneObjectPart SensePoint = ts.host; Vector3 fromRegionPos = SensePoint.GetWorldPosition(); // pre define some things to avoid repeated definitions in the loop body Vector3 toRegionPos; double dis; int objtype; SceneObjectPart part; float dx; float dy; float dz; Quaternion q = SensePoint.GetWorldRotation(); if (SensePoint.ParentGroup.IsAttachment) { // In attachments, rotate the sensor cone with the // avatar rotation. This may include a nonzero elevation if // in mouselook. // This will not include the rotation and position of the // attachment point (e.g. your head when a sensor is in your // hair attached to your scull. Your hair will turn with // your head but the sensor will stay with your (global) // avatar rotation and position. // Position of a sensor in a child prim attached to an avatar // will be still wrong. ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); q = avatar.GetWorldRotation() * q; } LSL_Types.Quaternion r = new LSL_Types.Quaternion(q); LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r); double mag_fwd = LSL_Types.Vector3.Mag(forward_dir); Vector3 ZeroVector = new Vector3(0, 0, 0); bool nameSearch = (ts.name != null && ts.name != ""); foreach (EntityBase ent in Entities) { bool keep = true; if (nameSearch && ent.Name != ts.name) // Wrong name and it is a named search continue; if (ent.IsDeleted) // taken so long to do this it has gone from the scene continue; if (!(ent is SceneObjectGroup)) // dont bother if it is a pesky avatar continue; toRegionPos = ent.AbsolutePosition; // Calculation is in line for speed dx = toRegionPos.X - fromRegionPos.X; dy = toRegionPos.Y - fromRegionPos.Y; dz = toRegionPos.Z - fromRegionPos.Z; // Weed out those that will not fit in a cube the size of the range // no point calculating if they are within a sphere the size of the range // if they arent even in the cube if (Math.Abs(dx) > ts.range || Math.Abs(dy) > ts.range || Math.Abs(dz) > ts.range) dis = ts.range + 1.0; else dis = Math.Sqrt(dx * dx + dy * dy + dz * dz); if (keep && dis <= ts.range && ts.host.UUID != ent.UUID) { // In Range and not the object containing the script, is it the right Type ? objtype = 0; part = ((SceneObjectGroup)ent).RootPart; if (part.ParentGroup.AttachmentPoint != 0) // Attached so ignore continue; if (part.Inventory.ContainsScripts()) { objtype |= ACTIVE | SCRIPTED; // Scripted and active. It COULD have one hidden ... } else { if (ent.Velocity.Equals(ZeroVector)) { objtype |= PASSIVE; // Passive non-moving } else { objtype |= ACTIVE; // moving so active } } // If any of the objects attributes match any in the requested scan type if (((ts.type & objtype) != 0)) { // Right type too, what about the other params , key and name ? if (ts.arc < Math.PI) { // not omni-directional. Can you see it ? // vec forward_dir = llRot2Fwd(llGetRot()) // vec obj_dir = toRegionPos-fromRegionPos // dot=dot(forward_dir,obj_dir) // mag_fwd = mag(forward_dir) // mag_obj = mag(obj_dir) // ang = acos(dot /(mag_fwd*mag_obj)) double ang_obj = 0; try { Vector3 diff = toRegionPos - fromRegionPos; double dot = LSL_Types.Vector3.Dot(forward_dir, diff); double mag_obj = LSL_Types.Vector3.Mag(diff); ang_obj = Math.Acos(dot / (mag_fwd * mag_obj)); } catch { } if (ang_obj > ts.arc) keep = false; } if (keep == true) { // add distance for sorting purposes later sensedEntities.Add(new SensedEntity(dis, ent.UUID)); } } } } return sensedEntities; }
private List<SensedEntity> doAgentSensor(SensorInfo ts) { List<SensedEntity> sensedEntities = new List<SensedEntity>(); // If nobody about quit fast if (m_CmdManager.m_ScriptEngine.World.GetRootAgentCount() == 0) return sensedEntities; SceneObjectPart SensePoint = ts.host; Vector3 fromRegionPos = SensePoint.GetWorldPosition(); Quaternion q = SensePoint.GetWorldRotation(); if (SensePoint.ParentGroup.IsAttachment) { // In attachments, rotate the sensor cone with the // avatar rotation. This may include a nonzero elevation if // in mouselook. // This will not include the rotation and position of the // attachment point (e.g. your head when a sensor is in your // hair attached to your scull. Your hair will turn with // your head but the sensor will stay with your (global) // avatar rotation and position. // Position of a sensor in a child prim attached to an avatar // will be still wrong. ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); q = avatar.GetWorldRotation() * q; } LSL_Types.Quaternion r = new LSL_Types.Quaternion(q); LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r); double mag_fwd = LSL_Types.Vector3.Mag(forward_dir); bool attached = (SensePoint.ParentGroup.AttachmentPoint != 0); Vector3 toRegionPos; double dis; Action<ScenePresence> senseEntity = new Action<ScenePresence>(presence => { // m_log.DebugFormat( // "[SENSOR REPEAT]: Inspecting scene presence {0}, type {1} on sensor sweep for {2}, type {3}", // presence.Name, presence.PresenceType, ts.name, ts.type); if ((ts.type & NPC) == 0 && (ts.type & OS_NPC) == 0 && presence.PresenceType == PresenceType.Npc) { INPC npcData = m_npcModule.GetNPC(presence.UUID, presence.Scene); if (npcData == null || !npcData.SenseAsAgent) { // m_log.DebugFormat( // "[SENSOR REPEAT]: Discarding NPC {0} from agent sense sweep for script item id {1}", // presence.Name, ts.itemID); return; } } if ((ts.type & AGENT) == 0) { if (presence.PresenceType == PresenceType.User) { return; } else { INPC npcData = m_npcModule.GetNPC(presence.UUID, presence.Scene); if (npcData != null && npcData.SenseAsAgent) { // m_log.DebugFormat( // "[SENSOR REPEAT]: Discarding NPC {0} from non-agent sense sweep for script item id {1}", // presence.Name, ts.itemID); return; } } } if (presence.IsDeleted || presence.IsChildAgent || presence.GodLevel > 0.0) return; // if the object the script is in is attached and the avatar is the owner // then this one is not wanted if (attached && presence.UUID == SensePoint.OwnerID) return; toRegionPos = presence.AbsolutePosition; dis = Math.Abs(Util.GetDistanceTo(toRegionPos, fromRegionPos)); // Disabled for now since all osNpc* methods check for appropriate ownership permission. // Perhaps could be re-enabled as an NPC setting at some point since being able to make NPCs not // sensed might be useful. // if (presence.PresenceType == PresenceType.Npc && npcModule != null) // { // UUID npcOwner = npcModule.GetOwner(presence.UUID); // if (npcOwner != UUID.Zero && npcOwner != SensePoint.OwnerID) // return; // } // are they in range if (dis <= ts.range) { // Are they in the required angle of view if (ts.arc < Math.PI) { // not omni-directional. Can you see it ? // vec forward_dir = llRot2Fwd(llGetRot()) // vec obj_dir = toRegionPos-fromRegionPos // dot=dot(forward_dir,obj_dir) // mag_fwd = mag(forward_dir) // mag_obj = mag(obj_dir) // ang = acos(dot /(mag_fwd*mag_obj)) double ang_obj = 0; try { LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3( toRegionPos - fromRegionPos); double dot = LSL_Types.Vector3.Dot(forward_dir, obj_dir); double mag_obj = LSL_Types.Vector3.Mag(obj_dir); ang_obj = Math.Acos(dot / (mag_fwd * mag_obj)); } catch { } if (ang_obj <= ts.arc) { sensedEntities.Add(new SensedEntity(dis, presence.UUID)); } } else { sensedEntities.Add(new SensedEntity(dis, presence.UUID)); } } }); // If this is an avatar sense by key try to get them directly // rather than getting a list to scan through if (ts.keyID != UUID.Zero) { ScenePresence sp; // Try direct lookup by UUID if (!m_CmdManager.m_ScriptEngine.World.TryGetScenePresence(ts.keyID, out sp)) return sensedEntities; senseEntity(sp); } else if (ts.name != null && ts.name != "") { ScenePresence sp; // Try lookup by name will return if/when found if (((ts.type & AGENT) != 0) && m_CmdManager.m_ScriptEngine.World.TryGetAvatarByName(ts.name, out sp)) senseEntity(sp); if ((ts.type & AGENT_BY_USERNAME) != 0) { m_CmdManager.m_ScriptEngine.World.ForEachRootScenePresence( delegate (ScenePresence ssp) { if (ssp.Lastname == "Resident") { if (ssp.Firstname.ToLower() == ts.name) senseEntity(ssp); return; } if (ssp.Name.Replace(" ", ".").ToLower() == ts.name) senseEntity(ssp); } ); } return sensedEntities; } else { m_CmdManager.m_ScriptEngine.World.ForEachRootScenePresence(senseEntity); } return sensedEntities; }
public void SenseOnce(uint m_localID, UUID m_itemID, string name, UUID keyID, int type, double range, double arc, SceneObjectPart host) { // Add to timer SensorInfo ts = new SensorInfo(); ts.localID = m_localID; ts.itemID = m_itemID; ts.interval = 0; ts.name = name; ts.keyID = keyID; ts.type = type; if (range > maximumRange) ts.range = maximumRange; else ts.range = range; ts.arc = arc; ts.host = host; SensorSweep(ts); }
private void SensorSweep(SensorInfo ts) { if (ts.host == null) { return; } List<SensedEntity> sensedEntities = new List<SensedEntity>(); // Is the sensor type is AGENT and not SCRIPTED then include agents if ((ts.type & (AGENT | AGENT_BY_USERNAME | NPC | OS_NPC)) != 0 && (ts.type & SCRIPTED) == 0) { sensedEntities.AddRange(doAgentSensor(ts)); } // If SCRIPTED or PASSIVE or ACTIVE check objects if ((ts.type & SCRIPTED) != 0 || (ts.type & PASSIVE) != 0 || (ts.type & ACTIVE) != 0) { sensedEntities.AddRange(doObjectSensor(ts)); } lock (SenseLock) { if (sensedEntities.Count == 0) { // send a "no_sensor" // Add it to queue m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID, new EventParams("no_sensor", new Object[0], new DetectParams[0])); } else { // Sort the list to get everything ordered by distance sensedEntities.Sort(); int count = sensedEntities.Count; int idx; List<DetectParams> detected = new List<DetectParams>(); for (idx = 0; idx < count; idx++) { try { DetectParams detect = new DetectParams(); detect.Key = sensedEntities[idx].itemID; detect.Populate(m_CmdManager.m_ScriptEngine.World); detected.Add(detect); } catch (Exception) { // Ignore errors, the object has been deleted or the avatar has gone and // there was a problem in detect.Populate so nothing added to the list } if (detected.Count == maximumToReturn) break; } if (detected.Count == 0) { // To get here with zero in the list there must have been some sort of problem // like the object being deleted or the avatar leaving to have caused some // difficulty during the Populate above so fire a no_sensor event m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID, new EventParams("no_sensor", new Object[0], new DetectParams[0])); } else { m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID, new EventParams("sensor", new Object[] {new LSL_Types.LSLInteger(detected.Count) }, detected.ToArray())); } } } }
private void AddSenseRepeater(SensorInfo senseRepeater) { lock (SenseRepeatListLock) { List<SensorInfo> newSenseRepeaters = new List<SensorInfo>(SenseRepeaters); newSenseRepeaters.Add(senseRepeater); SenseRepeaters = newSenseRepeaters; } }
public void SetSenseRepeatEvent(uint m_localID, UUID m_itemID, string name, UUID keyID, int type, double range, double arc, double sec, SceneObjectPart host) { // Always remove first, in case this is a re-set UnSetSenseRepeaterEvents(m_localID, m_itemID); if (sec == 0) // Disabling timer return; // Add to timer SensorInfo ts = new SensorInfo(); ts.localID = m_localID; ts.itemID = m_itemID; ts.interval = sec; ts.name = name; ts.keyID = keyID; ts.type = type; if (range > maximumRange) ts.range = maximumRange; else ts.range = range; ts.arc = arc; ts.host = host; ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); AddSenseRepeater(ts); }
public SensorDevice(IDevice parent, SensorInfo info) { _parent = parent; _info = info; }
public void IrTempNotify(SensorInfo sensorInfo) { this.InvokeTo<Monitor>(p => p.TempLimit <= sensorInfo.lastValue.obj || p.TempLimit <= sensorInfo.lastValue.amb, sensorInfo, "irtempchange"); }
public Sensor() { this.SensorInfo = new SensorInfo("N/A - Waiting for sensor input"); }
private void AddZibaseToCollection(string sZibaseName, long lIpAddress) { var seInfo = new SensorInfo(); if ((string.IsNullOrEmpty(sZibaseName))) { sZibaseName = "Unknown"; } if ((!m_ZibaseList.Keys.Contains(sZibaseName))) { var zb = new ZibaseInfo {sLabelBase = sZibaseName, lIpAddress = lIpAddress}; m_ZibaseList.Add(sZibaseName, zb); if (NewZibaseDetected != null) NewZibaseDetected(zb); if (WriteMessage != null) WriteMessage("New Zibase Detected : " + sZibaseName, MSG_INFO); // Creation d'un sensor virtuel pour la detection de l'availability de la Zibase seInfo.sName = "Zibase State"; seInfo.sID = sZibaseName; seInfo.sType = "lnk"; seInfo.sValue = "Online"; seInfo.sHTMLValue = "Online"; seInfo.dwValue = 2; if ((_SensorList.Keys.Contains(sZibaseName + "lnk"))) { seInfo.sHSName = _SensorList[sZibaseName + "lnk"].sHSName; seInfo.sDevice = _SensorList[sZibaseName + "lnk"].sDevice; _SensorList[sZibaseName + "lnk"] = seInfo; } else { _SensorList.Add(sZibaseName + "lnk", seInfo); if (NewSensorDetected != null) NewSensorDetected(seInfo); } if (UpdateSensorInfo != null) UpdateSensorInfo(seInfo); } }
private void AddSenseRepeater(SensorInfo senseRepeater) { SenseRepeaters.Add(senseRepeater); }
// Traitement des messages envoyés dans private void AfterReceive(byte[] _data) { try { var seInfo = new SensorInfo(); if (_data.Length >= 70 & _data[5] == 3) { // On récupére d'abord les info générales sur le message m_Zbs.SetData(_data); string sZibaseName = Encoding.Default.GetString(m_Zbs.label_base); int iPos = Strings.InStr(sZibaseName, Strings.Chr(0)); if (iPos > 0) sZibaseName = sZibaseName.Substring(0,iPos - 1); // Strings.Left(sZibaseName, iPos - 1); AddZibaseToCollection(sZibaseName, m_Zbs.my_ip); string s = ""; int i = 0; for (i = 70; i <= _data.Length - 2; i++) { s = s + Strings.Chr(_data[i]); } if (WriteMessage != null) WriteMessage(sZibaseName + ":" + s, MSG_DEBUG); LOG(s); //s = "Received radio ID (<rf>433Mhz</rf> Noise=<noise>2564</noise> Level=<lev>4.6</lev>/5 <dev>Oregon THWR288A-THN132N</dev> Ch=<ch>1</ch> T=<tem>+15.4</tem>°C (+59.7°F) Batt=<bat>Ok</bat>): <id>OS3930910721</id>"; if ((s.Substring(0, 17).ToUpper() == "RECEIVED RADIO ID")) { seInfo.sID = GetValue(s, "id"); seInfo.sName = GetValue(s, "dev"); seInfo.sDate = DateTime.Now; #region Remote Control if ((Strings.Asc(seInfo.sID[0]) >= Strings.Asc('A') && Strings.Asc(seInfo.sID[0]) <= Strings.Asc('P') && (Char.IsNumber(seInfo.sID, 1)) /*| LPL ?? Information.IsNumeric(seInfo.sID.Substring(1).Replace("_OFF", ""))))*/)) { seInfo.sName = "Remote Control"; // Traitement de la donnée reçu // On parcours la liste des passerelles for (i = 0; i <= 15; i++) { seInfo.sDevice = Strings.Chr(65 + i) + seInfo.sID.Substring(1); seInfo.sValue = ""; switch (seInfo.sID.IndexOf("_OFF")) { case -1: seInfo.dwValue = 2; seInfo.sValue = "On"; break; default: seInfo.dwValue = 3; seInfo.sValue = "Off"; break; } seInfo.sID = seInfo.sID.Replace("_OFF", ""); if (UpdateSensorInfo != null) UpdateSensorInfo(seInfo); } // On remet l'id d'origine version Zibase // seInfo.sID = GetValue(s, "id").Replace("_OFF", "") } #endregion // On modifie l'id pour Chacon et Visonic pour qui correspondent à l'actionneur (ON et OFF) if ((seInfo.sID.Substring(0, 2) == "CS")) { seInfo.sID = "CS" + ((Convert.ToInt32(seInfo.sID.Substring(2), System.Globalization.CultureInfo.InvariantCulture) & ~0x10)); seInfo.sName = "Chacon"; } if ((seInfo.sID.Substring(0, 2) == "VS")) { seInfo.sID = "VS" + ((Convert.ToInt32(seInfo.sID.Substring(2), System.Globalization.CultureInfo.InvariantCulture)) & ~0xf); seInfo.sName = "Visonic"; } if ((seInfo.sID.Substring(0, 2) == "DX")) { seInfo.sID = "DX" + seInfo.sID.Substring(2); seInfo.sName = "X2D"; } if ((seInfo.sID.Substring(0, 2) == "WS")) { LOG(seInfo.sID); seInfo.sID = "WS" + ((Convert.ToInt32(seInfo.sID.Substring(2), System.Globalization.CultureInfo.InvariantCulture)) & ~0xf); seInfo.sName = "OWL"; } string sId = null; string sValue = null; string sType = null; #region XS Security Device if ((seInfo.sID.Substring(0, 2) == "XS")) { sValue = ((Convert.ToInt64(seInfo.sID.Substring(2), System.Globalization.CultureInfo.InvariantCulture)) & 0xff).ToString(); seInfo.sID = "XS" + ((Convert.ToInt64(seInfo.sID.Substring(2))) & ~0xff); seInfo.sName = "X10 Secured"; sType = "xse"; seInfo.sType = sType; seInfo.sDevice = ""; // Declaration d'une variable de type état if ((!string.IsNullOrEmpty(sValue))) { seInfo.dwValue = Convert.ToInt32(sValue, System.Globalization.CultureInfo.InvariantCulture); switch (seInfo.dwValue) { case 0x20: case 0x30: seInfo.sValue = "ALERT"; seInfo.sHTMLValue = "ALERT"; break; case 0x21: case 0x31: seInfo.sValue = "NORMAL"; seInfo.sHTMLValue = "NORMAL"; break; case 0x40: seInfo.sValue = "ARM AWAY (max)"; seInfo.sHTMLValue = "ARM AWAY (max)"; break; case 0x41: case 0x61: seInfo.sValue = "DISARM"; seInfo.sHTMLValue = "DISARM"; break; case 0x42: seInfo.sValue = "SEC. LIGHT ON"; seInfo.sHTMLValue = "SEC. LIGHT ON"; break; case 0x43: seInfo.sValue = "SEC. LIGHT OFF"; seInfo.sHTMLValue = "SEC. LIGHT OFF"; break; case 0x44: seInfo.sValue = "PANIC"; seInfo.sHTMLValue = "PANIC"; break; case 0x50: seInfo.sValue = "ARM HOME"; seInfo.sHTMLValue = "ARM HOME"; break; case 0x60: seInfo.sValue = "ARM"; seInfo.sHTMLValue = "ARM"; break; case 0x62: seInfo.sValue = "LIGHTS ON"; seInfo.sHTMLValue = "LIGHTS ON"; break; case 0x63: seInfo.sValue = "LIGHTS OFF"; seInfo.sHTMLValue = "LIGHTS OFF"; break; case 0x70: seInfo.sValue = "ARM HOME (min)"; seInfo.sHTMLValue = "ARM HOME (min)"; break; } sId = seInfo.sID; if ((_SensorList.Keys.Contains(sId + sType))) { seInfo.sHSName = _SensorList[sId + sType].sHSName; seInfo.sDevice = _SensorList[sId + sType].sDevice; _SensorList[sId + sType] = seInfo; } else { _SensorList.Add(sId + sType, seInfo); } if (UpdateSensorInfo != null) UpdateSensorInfo(seInfo); } } #endregion #region sta sId = seInfo.sID; sType = "sta"; seInfo.sType = sType; seInfo.sDevice = ""; sValue = GetValue(s, sType); // Declaration d'une variable de type état if ((!string.IsNullOrEmpty(sValue))) { seInfo.sValue = sValue; seInfo.sHTMLValue = sValue; seInfo.dwValue = sValue == "ON" ? 2 : 3; if ((_SensorList.Keys.Contains(sId + sType))) { seInfo.sHSName = _SensorList[sId + sType].sHSName; seInfo.sDevice = _SensorList[sId + sType].sDevice; _SensorList[sId + sType] = seInfo; } else { _SensorList.Add(sId + sType, seInfo); if (NewSensorDetected != null) NewSensorDetected(seInfo); } if (UpdateSensorInfo != null) UpdateSensorInfo(seInfo); } #endregion #region lev sType = "lev"; seInfo.sType = sType; seInfo.sDevice = ""; sValue = GetValue(s, sType); // Declaration d'une variable de type strength level if ((!string.IsNullOrEmpty(sValue))) { seInfo.dwValue = (int) (Convert.ToDouble(sValue,System.Globalization.CultureInfo.InvariantCulture)*10); seInfo.sValue = (seInfo.dwValue/10.0) + "/5"; seInfo.sHTMLValue = sValue; if ((_SensorList.Keys.Contains(sId + sType))) { seInfo.sHSName = _SensorList[sId + sType].sHSName; seInfo.sDevice = _SensorList[sId + sType].sDevice; _SensorList[sId + sType] = seInfo; } else { _SensorList.Add(sId + sType, seInfo); if (NewSensorDetected != null) NewSensorDetected(seInfo); } if (UpdateSensorInfo != null) UpdateSensorInfo(seInfo); } #endregion #region temc sType = "temc"; seInfo.sType = sType; seInfo.sDevice = ""; sValue = GetValue(s, sType); // Declaration d'une variable de type consigne de température if ((!string.IsNullOrEmpty(sValue))) { seInfo.dwValue = Convert.ToInt32(sValue, System.Globalization.CultureInfo.InvariantCulture); seInfo.sValue = seInfo.dwValue + "°C"; seInfo.sHTMLValue = sValue; if ((_SensorList.Keys.Contains(sId + sType))) { seInfo.sHSName = _SensorList[sId + sType].sHSName; seInfo.sDevice = _SensorList[sId + sType].sDevice; _SensorList[sId + sType] = seInfo; } else { _SensorList.Add(sId + sType, seInfo); if (NewSensorDetected != null) NewSensorDetected(seInfo); if (NewSensorDetected != null) NewSensorDetected(seInfo); } if (UpdateSensorInfo != null) UpdateSensorInfo(seInfo); } #endregion #region kwh sType = "kwh"; seInfo.sType = sType; seInfo.sDevice = ""; sValue = GetValue(s, sType); if ((!string.IsNullOrEmpty(sValue))) { LOG(DateTime.Now + " KWh :" + sValue); seInfo.dwValue = (long) (Convert.ToDouble(sValue, CultureInfo.InvariantCulture)*100); seInfo.sValue = (seInfo.dwValue/100.0) + " kWh"; seInfo.sHTMLValue = sValue; LOG(DateTime.Now + " Trace1"); if ((_SensorList.Keys.Contains(sId + sType))) { seInfo.sHSName = _SensorList[sId + sType].sHSName; seInfo.sDevice = _SensorList[sId + sType].sDevice; _SensorList[sId + sType] = seInfo; } else { _SensorList.Add(sId + sType, seInfo); if (NewSensorDetected != null) NewSensorDetected(seInfo); } if (UpdateSensorInfo != null) UpdateSensorInfo(seInfo); } #endregion #region kw sType = "kw"; seInfo.sType = sType; seInfo.sDevice = ""; sValue = GetValue(s, sType); if ((!string.IsNullOrEmpty(sValue))) { seInfo.dwValue = (long) (Convert.ToDouble(sValue, CultureInfo.InvariantCulture)*100); seInfo.sValue = (seInfo.dwValue/100.0) + " kW"; seInfo.sHTMLValue = sValue; if ((_SensorList.Keys.Contains(sId + sType))) { seInfo.sHSName = _SensorList[sId + sType].sHSName; seInfo.sDevice = _SensorList[sId + sType].sDevice; _SensorList[sId + sType] = seInfo; } else { _SensorList.Add(sId + sType, seInfo); if (NewSensorDetected != null) NewSensorDetected(seInfo); } if (UpdateSensorInfo != null) UpdateSensorInfo(seInfo); } #endregion #region tra sType = "tra"; seInfo.sType = sType; seInfo.sDevice = ""; sValue = GetValue(s, sType); if ((!string.IsNullOrEmpty(sValue))) { seInfo.dwValue = Convert.ToInt32(sValue, System.Globalization.CultureInfo.InvariantCulture) * 100; seInfo.sValue = seInfo.dwValue + " mm"; seInfo.sHTMLValue = sValue; if ((_SensorList.Keys.Contains(sId + sType))) { seInfo.sHSName = _SensorList[sId + sType].sHSName; seInfo.sDevice = _SensorList[sId + sType].sDevice; _SensorList[sId + sType] = seInfo; } else { _SensorList.Add(sId + sType, seInfo); if (NewSensorDetected != null) NewSensorDetected(seInfo); } if (UpdateSensorInfo != null) UpdateSensorInfo(seInfo); } #endregion #region cra sType = "cra"; seInfo.sType = sType; seInfo.sDevice = ""; sValue = GetValue(s, sType); if ((!string.IsNullOrEmpty(sValue))) { seInfo.dwValue = Convert.ToInt32(sValue, System.Globalization.CultureInfo.InvariantCulture) * 100; seInfo.sValue = seInfo.dwValue + " mm/h"; seInfo.sHTMLValue = sValue; if ((_SensorList.Keys.Contains(sId + sType))) { seInfo.sHSName = _SensorList[sId + sType].sHSName; seInfo.sDevice = _SensorList[sId + sType].sDevice; _SensorList[sId + sType] = seInfo; } else { _SensorList.Add(sId + sType, seInfo); if (NewSensorDetected != null) NewSensorDetected(seInfo); } if (UpdateSensorInfo != null) UpdateSensorInfo(seInfo); } #endregion #region awi sType = "awi"; seInfo.sType = sType; seInfo.sDevice = ""; sValue = GetValue(s, sType); if ((!string.IsNullOrEmpty(sValue))) { seInfo.dwValue = (long) (Convert.ToDouble(sValue, CultureInfo.InvariantCulture)*100); seInfo.sValue = seInfo.dwValue + " m/s"; seInfo.sHTMLValue = sValue; if ((_SensorList.Keys.Contains(sId + sType))) { seInfo.sHSName = _SensorList[sId + sType].sHSName; seInfo.sDevice = _SensorList[sId + sType].sDevice; _SensorList[sId + sType] = seInfo; } else { _SensorList.Add(sId + sType, seInfo); if (NewSensorDetected != null) NewSensorDetected(seInfo); } if (UpdateSensorInfo != null) UpdateSensorInfo(seInfo); } #endregion #region drt sType = "drt"; seInfo.sType = sType; seInfo.sDevice = ""; sValue = GetValue(s, sType); if ((!string.IsNullOrEmpty(sValue))) { seInfo.dwValue = Convert.ToInt32(sValue, System.Globalization.CultureInfo.InvariantCulture) * 100; seInfo.sValue = seInfo.dwValue + " °"; seInfo.sHTMLValue = sValue; if ((_SensorList.Keys.Contains(sId + sType))) { seInfo.sHSName = _SensorList[sId + sType].sHSName; seInfo.sDevice = _SensorList[sId + sType].sDevice; _SensorList[sId + sType] = seInfo; } else { _SensorList.Add(sId + sType, seInfo); if (NewSensorDetected != null) NewSensorDetected(seInfo); } if (UpdateSensorInfo != null) UpdateSensorInfo(seInfo); } #endregion #region uvl sType = "uvl"; seInfo.sType = sType; seInfo.sDevice = ""; sValue = GetValue(s, sType); if ((!string.IsNullOrEmpty(sValue))) { seInfo.dwValue = Convert.ToInt32(sValue, System.Globalization.CultureInfo.InvariantCulture) * 100; seInfo.sValue = seInfo.dwValue + ""; seInfo.sHTMLValue = sValue; if ((_SensorList.Keys.Contains(sId + sType))) { seInfo.sHSName = _SensorList[sId + sType].sHSName; seInfo.sDevice = _SensorList[sId + sType].sDevice; _SensorList[sId + sType] = seInfo; } else { _SensorList.Add(sId + sType, seInfo); if (NewSensorDetected != null) NewSensorDetected(seInfo); } if (UpdateSensorInfo != null) UpdateSensorInfo(seInfo); } #endregion #region bat sType = "bat"; seInfo.sType = sType; seInfo.sDevice = ""; sValue = GetValue(s, sType); // Declaration d'une variable de type battery if ((!string.IsNullOrEmpty(sValue) & sValue != "?")) { seInfo.sValue = sValue; seInfo.sHTMLValue = sValue; seInfo.dwValue = sValue == "Low" ? 0 : 1; if ((_SensorList.Keys.Contains(sId + sType))) { seInfo.sHSName = _SensorList[sId + sType].sHSName; seInfo.sDevice = _SensorList[sId + sType].sDevice; _SensorList[sId + sType] = seInfo; } else { _SensorList.Add(sId + sType, seInfo); if (NewSensorDetected != null) NewSensorDetected(seInfo); } if (UpdateSensorInfo != null) UpdateSensorInfo(seInfo); } #endregion #region tem // Gestion du type de sonde sType = "tem"; seInfo.sType = sType; seInfo.sDevice = ""; sValue = GetValue(s, sType); // Declaration d'une variable de type temperature if ((!string.IsNullOrEmpty(sValue))) { seInfo.dwValue = (long) (Convert.ToDouble(sValue, CultureInfo.InvariantCulture)*100); seInfo.sValue = String.Format("{0:0.0} °C", seInfo.dwValue/100.0); // "#.#") + "°C"; seInfo.sHTMLValue = sValue; if ((_SensorList.Keys.Contains(sId + sType))) { seInfo.sHSName = _SensorList[sId + sType].sHSName; seInfo.sDevice = _SensorList[sId + sType].sDevice; _SensorList[sId + sType] = seInfo; } else { _SensorList.Add(sId + sType, seInfo); if (NewSensorDetected != null) NewSensorDetected(seInfo); } if (UpdateSensorInfo != null) UpdateSensorInfo(seInfo); } #endregion #region hum sType = "hum"; seInfo.sType = sType; seInfo.sDevice = ""; sValue = GetValue(s, sType); // Declaration d'une variable de type humidity if ((!string.IsNullOrEmpty(sValue))) { seInfo.dwValue = Convert.ToInt32(sValue, System.Globalization.CultureInfo.InvariantCulture); seInfo.sValue = seInfo.dwValue + "%"; seInfo.sHTMLValue = sValue; if ((_SensorList.Keys.Contains(sId + sType))) { seInfo.sHSName = _SensorList[sId + sType].sHSName; seInfo.sDevice = _SensorList[sId + sType].sDevice; _SensorList[sId + sType] = seInfo; } else { _SensorList.Add(sId + sType, seInfo); if (NewSensorDetected != null) NewSensorDetected(seInfo); } if (UpdateSensorInfo != null) UpdateSensorInfo(seInfo); } #endregion } } } catch(Exception ex) { LOG(ex.Message); } }
public SensorInfo GetSensor(int sensorNum, int sensorAddress) { SensorInfo sensor; if (DataBase.Sensors.Count(s => s.SensorAddress == sensorAddress) > 0) { sensor = DataBase.Sensors.Single(s => s.SensorAddress == sensorAddress); } else { sensor = new SensorInfo { SensorAddress = sensorAddress, SensorNumber = sensorNum }; DataBase.Sensors.Add(sensor); } IsSaved = false; return sensor; }