Ejemplo n.º 1
0
        /// <summary>
        /// For a given decision maker, get all sensor ranges which they currently have (max range per sensor object)
        /// </summary>
        /// <param name="dmID"></param>
        /// <returns></returns>
        public List <SensorRange> GetDecisionMakersSensorRanges(String dmID)
        {
            List <SensorRange> ranges = new List <SensorRange>();

            lock (GroundTruthLock)
            {
                DMView      view  = _dddConnection.GetDMView(dmID);
                SensorRange range = null;
                if (view != null)
                {
                    foreach (String s in view.MyObjects.Keys)
                    {
                        if (view.MyObjects[s].Location.exists)
                        {
                            double maxRange = 0;
                            foreach (SensorValue sv in view.MyObjects[s].Sensors.sensors)
                            {
                                if (sv.maxRange > maxRange)
                                {
                                    maxRange = sv.maxRange;
                                }
                            }
                            range = new SensorRange(DataValueFactory.BuildFromDataValue(view.MyObjects[s].Location) as LocationValue, maxRange);
                            ranges.Add(range);
                        }
                    }
                }
            }
            return(ranges);
        }
Ejemplo n.º 2
0
		public void TestCtor()
		{
			var info = new SensorRange(1, 2, 3);
			info.MaxAcceleration.Should().BeApproximately(1, 0);
			info.MaxRotationRate.Should().BeApproximately(2, 0);
			info.MaxMagneticField.Should().BeApproximately(3, 0);
		}
Ejemplo n.º 3
0
        public void TestCtor()
        {
            var info = new SensorRange(1, 2, 3);

            info.MaxAcceleration.Should().BeApproximately(1, 0);
            info.MaxRotationRate.Should().BeApproximately(2, 0);
            info.MaxMagneticField.Should().BeApproximately(3, 0);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// For a given decision maker, get all sensor ranges which they currently have (max range per sensor object)
 /// </summary>
 /// <param name="dmID"></param>
 /// <returns></returns>
 public List<SensorRange> GetDecisionMakersSensorRanges(String dmID)
 {
     List<SensorRange> ranges = new List<SensorRange>();
     lock (GroundTruthLock)
     {
         DMView view = _dddConnection.GetDMView(dmID);
         SensorRange range = null;
         if (view != null)
         {
             foreach (String s in view.MyObjects.Keys)
             {
                 if (view.MyObjects[s].Location.exists)
                 {
                     double maxRange = 0;
                     foreach (SensorValue sv in view.MyObjects[s].Sensors.sensors)
                     {
                         if (sv.maxRange > maxRange)
                         {
                             maxRange = sv.maxRange;
                         }
                     }
                     range = new SensorRange(DataValueFactory.BuildFromDataValue(view.MyObjects[s].Location) as LocationValue, maxRange);
                     ranges.Add(range);
                 }
             }
         }
     }
     return ranges;
 }
Ejemplo n.º 5
0
 public ComponentRangeSliderSensor(string name, string label, string path, SensorRange sensor = null) : base(ComponentType.TYPE_SENSOR, name, label, path)
 {
     Sensor = sensor;
 }
Ejemplo n.º 6
0
        public void GetSiteDetails(ref SiteModel site)
        {
            int  sn       = site.Sn;
            Site siteInfo = _siteService.Query(s => s.SiteSN == sn).FirstOrDefault();

            site.IsUpdate = siteInfo.SiteUpdateTag;
            site.RunState = siteInfo.SiteRunState;
            site.AearId   = siteInfo.AreaId;

            List <ConfigBindModel> configBindModelList = _configBindService.GetChannelStructInfo(site.Sn);
            List <ChannelStruct>   channelStructList   = new List <ChannelStruct>();

            foreach (ConfigBindModel item in configBindModelList)
            {
                ChannelStruct channel = _mapper.Map <ChannelStruct>(item);
                channel.SensorSensitivity = 100;
                channel.Bias_limit_low    = 0;
                channel.Bias_limit_high   = 0;
                channel.SensorStableTime  = -1;
                channel.SpeedRPM          = 0;
                channel.SpeedChannelNo    = 0;
                channel.RpmRatio          = 0;
                channel.Speed_limit_low   = -1;
                channel.Speed_limit_high  = -1;
                channel.Fmax           = -1;
                channel.Lines          = 1;
                channel.AverageTime    = 1;
                channel.AveragePercent = 1;
                channel.Amplification  = 1;
                channel.value4         = -40.0f;
                channel.value20        = 100.0f;
                channel.MeaValueUnit   = GetAttrName("");
                switch (channel.TypeSensor)
                {
                case 0:     //加速度
                    SensorAcc accSensor = _sensorAccService.QueryById(item.SensorId);
                    if (accSensor != null)
                    {
                        channel.SensorSensitivity = (float)accSensor.AccSensibility;
                        channel.Bias_limit_low    = (float)accSensor.AccBiasLow;
                        channel.Bias_limit_high   = (float)accSensor.AccBiasHigh;
                        channel.SensorStableTime  = accSensor.AccSettlingTime;
                    }
                    break;

                case 3:    //范围
                    SensorRange rangeSensor = _sensorRangeService.QueryById(item.SensorId);
                    if (rangeSensor != null)
                    {
                        channel.value4  = rangeSensor.RangeValue1;
                        channel.value20 = rangeSensor.RangeValue2;
                    }
                    break;
                }
                List <WorkStatus> workStatuesList = _workStatusService.GetWorkStatusByDirId(channel.AreaID, item.ChannelID);
                int[]             workStatues     = new int[5];

                for (int i = 0; i < 5; i++)
                {
                    workStatues[i] = workStatuesList.Count > i ? workStatuesList[i].WorkStatusValue : -1;
                }
                channel.StateStatus = workStatues;
                channel.SpeedSatus  = new int[5];
                channelStructList.Add(channel);
            }
            site.ChannelStructList = channelStructList;
            site.MeterageLibList   = _meterageLibService.GetMeterageLibListBySn(site.Sn);
            site.WorkStatusList    = _workStatusService.Query(w => w.AreaId == siteInfo.AreaId && w.IsUse == 1);
        }
        /// <summary>
        /// Process Brick State
        /// </summary>
        /// <param name="brickState"></param>
        private IEnumerator<ITask> ProcessBrickState(brick.NxtBrickState brickState)
        {
            foreach (string key in brickState.Runtime.Devices.Keys)
            {
                brick.AttachRequest device = brickState.Runtime.Devices[key];
                if (device.Registration.DeviceType != LegoDeviceType.AnalogSensor
                    && device.Registration.DeviceType != LegoDeviceType.DigitalSensor)
                {
                    continue;
                }

                PortSet<DsspDefaultLookup, DsspDefaultGet> lookupPort = ServiceForwarder<PortSet<DsspDefaultLookup, DsspDefaultGet>>(device.Registration.ServiceUri);
                DsspDefaultLookup lu = new DsspDefaultLookup();
                lookupPort.Post(lu);
                yield return Arbiter.Choice(lu.ResponsePort,
                    delegate(LookupResponse luResponse)
                    {
                        foreach(PartnerType pt in luResponse.PartnerList)
                        {
                            // See if this service supports the analog sensor contract
                            if (pt.Contract == analog.Contract.Identifier)
                            {
                                // Check if we have already processed this one.
                                if (_sensorList.ContainsKey(pt.Service))
                                    break;

                                string name = device.Registration.Name;
                                string model = device.Registration.DeviceModel;
                                int hardwareIdentifier = NxtCommon.HardwareIdentifier(device.Registration.Connection.Port);

                                LogVerbose(LogGroups.Console, string.Format("Configuring {0}:{1} on {2} with analog service at {3}", model, name, hardwareIdentifier, pt.Service));
                                analog.AnalogSensorOperations sensorPort = ServiceForwarder<analog.AnalogSensorOperations>(pt.Service);
                                Activate(Arbiter.Choice(sensorPort.Subscribe(_analogSensorNotificationsPort),
                                    delegate(SubscribeResponseType response)
                                    {
                                        // Keep track of the subscription manager response
                                        // so that we can unsubscribe later.
                                        _sensorList.Add(pt.Service, response);
                                    },
                                    delegate(Fault fault)
                                    {
                                        LogError(LogGroups.Console, string.Format("Failure subscribing to {0} on port {1}.", model, hardwareIdentifier));
                                    }));

                                foreach (SensorConfiguration cfg in _state.SensorConfiguration)
                                {
                                    if (cfg.DeviceModel != model)
                                        continue;

                                    SensorRange range = new SensorRange(hardwareIdentifier, model, name, cfg.RangeName);
                                    PortConfiguration portConfig = new PortConfiguration(hardwareIdentifier, range.ContactSensorName, cfg.SuccessRangeMin, cfg.SuccessRangeMax);
                                    portConfig.AnalogSensorServiceUri = pt.Service;

                                    if (portConfig != null)
                                        _state.RuntimeConfiguration.Add(range, portConfig);
                                }
                                break;
                            }
                        }
                    },
                    delegate(Fault f) { });

            }
        }