public ResponseAPI Post([FromBody] SensorConfiguration configuration) { /* * Insert Sensor in table storage AZURE * * _sensorTable = _sensorRepository.insertTable(_connectionStringAzure, "CollariniVendrameSensor"); * var sensorEntity = new SensorEntity(Guid.NewGuid(), configuration.SensorId, configuration.SensorType, configuration.SensorMesurementUnit); * var result = _sensorRepository.Insert(sensorEntity, _sensorTable); * if (result != null) * { * return Ok("Sensor inserted correctly"); * } * else * { * return StatusCode(500); * } */ try { _sensorRepositorySQL.insertData(configuration, _connectionStringSQL); return(new ResponseAPI { StatusCode = 200, Message = "Sensor inserted" }); } catch (Exception e) { return(new ResponseAPI { StatusCode = 500, Message = e.Message }); } }
internal override string onSaving() { if (!Directory.Exists("Assets/Resources/Sensors")) { Directory.CreateDirectory("Assets/Resources/Sensors"); } if (AssetDatabase.LoadAssetAtPath("Assets/Resources/SensorsManager.asset", typeof(SensorsManager)) == null) { AssetDatabase.CreateAsset((SensorsManager)manager, "Assets/Resources/SensorsManager.asset"); } else { EditorUtility.SetDirty((SensorsManager)manager); foreach (AbstractConfiguration conf in ((SensorsManager)manager).getConfigurations()) { SensorConfiguration sensorConf = (SensorConfiguration)conf; if (AssetDatabase.LoadAssetAtPath("Assets/Resources/Sensors/" + sensorConf.configurationName + ".asset", typeof(SensorConfiguration)) == null) { AssetDatabase.CreateAsset(sensorConf, "Assets/Resources/Sensors/" + sensorConf.configurationName + ".asset"); } else { EditorUtility.SetDirty(sensorConf); } } AssetDatabase.SaveAssets(); } return(""); }
internal override void onDeleting(AbstractConfiguration c) { EditorUtility.SetDirty((SensorsManager)manager); AssetDatabase.SaveAssets(); SensorConfiguration sensorConf = (SensorConfiguration)c; if (!(AssetDatabase.LoadAssetAtPath("Assets/Resources/Sensors/" + sensorConf.configurationName + ".asset", typeof(SensorConfiguration)) is null)) { AssetDatabase.DeleteAsset("Assets/Resources/Sensors/" + sensorConf.configurationName + ".asset"); } }
/// <summary> /// Configures the Temp<![CDATA[&]]>Hum6 Click for measurement. /// </summary> /// <param name="configuration">The <see cref="SensorConfiguration"/> to use.</param> /// <example> /// <code language = "C#"> /// TempHum6Click.SensorConfiguration configuration = new TempHum6Click.SensorConfiguration /// { /// LowPower = false, /// EnableHumidityMeasurement = true, /// EnableTemperatureMeasurement = true, /// HumidityMeasurementMode = TempHum6Click.MeasurementMode.Continuous, /// TemperatureMeasurementMode = TempHum6Click.MeasurementMode.Continuous /// }; /// _sensor.ConfigureSensor(configuration); /// </code> /// </example> public void ConfigureSensor(SensorConfiguration configuration) { PowerMode = configuration.LowPower ? PowerModes.Low : PowerModes.On; Byte registerData = 0x00; if (_currentConfiguration != null) { if (_currentConfiguration.HumidityMeasurementMode == MeasurementMode.Continuous && configuration.HumidityMeasurementMode == MeasurementMode.OneShot) { registerData = ENS210_HUM_STOP_CONTINUOUS_MEASUREMENT; } if (_currentConfiguration.TemperatureMeasurementMode == MeasurementMode.Continuous && configuration.TemperatureMeasurementMode == MeasurementMode.OneShot) { registerData |= ENS210_TEMP_STOP_CONTINUOUS_MEASUREMENT; } WriteRegister(ENS210_REG_SENS_STOP, registerData); } registerData = configuration.HumidityMeasurementMode == MeasurementMode.Continuous ? ENS210_HUM_RUN_CONTINUOUS_MODE : ENS210_HUM_RUN_SINGLE_SHOT_MODE; registerData |= configuration.TemperatureMeasurementMode == MeasurementMode.Continuous ? ENS210_TEMP_RUN_CONTINUOUS_MODE : ENS210_TEMP_RUN_SINGLE_SHOT_MODE; WriteRegister(ENS210_REG_SENS_RUN, registerData); registerData = configuration.EnableHumidityMeasurement ? ENS210_HUM_START_MEASUREMENT : ENS210_DISABLE_MEASUREMENT; registerData |= configuration.EnableTemperatureMeasurement ? ENS210_TEMP_START_MEASUREMENT : ENS210_DISABLE_MEASUREMENT; WriteRegister(ENS210_REG_SENS_START, registerData); _currentConfiguration = configuration; }
protected override void updateConfiguredObject() { updateConfiguredObject(SensorConfiguration.CreateInstance <SensorConfiguration>()); }
private DeviceIndicationReport CreateIndicationReport(IndicationType[] detections, string sensorName = null) { List <IndicationType> indications = new List <IndicationType>(); int i = 0; double azimuth = 0; foreach (IndicationType indication in detections) { // add direction to aerial detections if (indication.Item is AerialTrackDetectionType trackDetectionType) { // calculate azimuth by previous location if (i > 0 && detections[i - 1].ID == indication.ID) { IndicationType previous = detections[i - 1]; if (previous.Item is AerialTrackDetectionType aerialTrack) { System.Windows.Point a = UnitConverter.LocationToPoint(trackDetectionType.Location); System.Windows.Point b = UnitConverter.LocationToPoint(aerialTrack.Location); azimuth = UnitConverter.DegreeToMils(UnitConverter.RadianToDegree(CalculateAzimuth(a, b))); } } // if no previous, look for the last aerial detection with the same ID else if (_lastDetectionReceived != null && _lastDetectionReceived.ID == indication.ID) { if (_lastDetectionReceived.Item is AerialTrackDetectionType aerialTrack) { System.Windows.Point a = UnitConverter.LocationToPoint(trackDetectionType.Location); System.Windows.Point b = UnitConverter.LocationToPoint(aerialTrack.Location); azimuth = UnitConverter.DegreeToMils(UnitConverter.RadianToDegree(CalculateAzimuth(a, b))); } } trackDetectionType.Direction = new AzimuthType { Units = AngularUnitsType.Mils, Value = azimuth, }; } indications.Add(indication); i++; } // create identification items DeviceIdentificationType deviceIdentificationType; SensorIdentificationType sensorIdentification; if (sensorName != null) { // if device hub if (DeviceConfiguration.DeviceConfiguration1 != null) { // find wanted device (sensorName == device name) DeviceConfiguration deviceConfiguration = DeviceConfiguration.DeviceConfiguration1.FirstOrDefault(x => x.DeviceIdentification.DeviceName == sensorName); deviceIdentificationType = deviceConfiguration?.DeviceIdentification; // take first sensor SensorConfiguration sensorConfiguration = deviceConfiguration?.SensorConfiguration.FirstOrDefault(); sensorIdentification = sensorConfiguration?.SensorIdentification; } else { // take first device deviceIdentificationType = DeviceConfiguration.DeviceIdentification; // find wanted sensor (sensorName == sensor name) SensorConfiguration sensorConfiguration = DeviceConfiguration.SensorConfiguration.FirstOrDefault(x => x.SensorIdentification.SensorName == sensorName); sensorIdentification = sensorConfiguration?.SensorIdentification; } } else { deviceIdentificationType = DeviceConfiguration.DeviceIdentification; SensorConfiguration sensorConfiguration = DeviceConfiguration.SensorConfiguration.FirstOrDefault(); sensorIdentification = sensorConfiguration?.SensorIdentification; } SensorIndicationReport sensorIndication = new SensorIndicationReport { IndicationType = indications.ToArray(), SensorIdentification = sensorIdentification }; object content; // if device hub if (DeviceConfiguration.DeviceConfiguration1 != null) { content = new DeviceIndicationReport { DeviceIdentification = deviceIdentificationType, ProtocolVersion = ProtocolVersionType.Item22, Items = new object[] { sensorIndication } }; } else { content = sensorIndication; } // main device DeviceIndicationReport indicationReport = new DeviceIndicationReport { DeviceIdentification = DeviceConfiguration.DeviceIdentification, Items = new[] { content, } }; return(indicationReport); }
private void configureSensor(object[] result, Type type, SensorConfiguration conf, string property, int currentOperationPerProperty, List <IMonoBehaviourSensor> generatedSensors) { //MyDebugger.MyDebug("configuring sensors for " + property); if (result != null) { type = (Type)result[0]; } if (type != null && currentPropertyType.Equals("VALUE")) { IMonoBehaviourSensor sensor = addSensor(conf.name, property, currentOperationPerProperty, type); //MyDebugger.MyDebug("AND IT'S VALUE"); sensor.done(); generatedSensors.Add(sensor); } else if (type != null) { List <int> currentSize = new List <int>(); if (currentPropertyType.Equals("LIST")) { //MyDebugger.MyDebug("AND IT'S LIST"); currentSize.Add((int)result[1]); for (int i = 0; i < (int)result[1]; i++) { IMonoBehaviourSensor sensor = addSensor(conf.name, property, currentOperationPerProperty, type); sensor.indexes.Add(i); sensor.collectionElementProperty = currentSubProperty; sensor.collectionElementType = ((Type)result[2]).Name; sensor.done(); generatedSensors.Add(sensor); } } else if (currentPropertyType.Equals("ARRAY2")) { MyDebugger.MyDebug("AND IT'S ARRAY2"); currentSize.Add((int)result[1]); currentSize.Add((int)result[2]); for (int i = 0; i < (int)result[1]; i++) { for (int j = 0; j < (int)result[2]; j++) { IMonoBehaviourSensor sensor = addSensor(conf.name, property, currentOperationPerProperty, type); sensor.indexes.Add(i); sensor.indexes.Add(j); sensor.collectionElementProperty = currentSubProperty; sensor.collectionElementType = ((Type)result[3]).Name; sensor.done(); generatedSensors.Add(sensor); } } } if (!sizeToTrack.ContainsKey(property)) { //MyDebugger.MyDebug("property " + property); //MyDebugger.MyDebug("size " + currentSize.Count); sizeToTrack.Add(property, currentSize); typeForCollectionProperty.Add(property, currentPropertyType); elementForCollectionProperty.Add(property, new List <string>()); sensorNameForCollectionProperty.Add(property, conf.name); } elementForCollectionProperty[property].Add(currentSubProperty); } }
public SensorMonitor(SensorConfiguration configuration, VR vr, MQTT mqtt) { _configuration = configuration; _vr = vr; _mqtt = mqtt; }