public virtual IEnumerator<ITask> ReplaceHandler(pxanalogsensor.Replace replace)
 {
     replace.ResponsePort.Post(Fault.FromException(new InvalidOperationException("The HiTechnic Compass sensor is updated from hardware.")));
     yield break;
 }
 public virtual IEnumerator<ITask> SubscribeHandler(pxanalogsensor.Subscribe subscribe)
 {
     yield return (Choice)base.SubscribeHelper(_subMgrPort, subscribe.Body, subscribe.ResponsePort);
     if (_state.Heading.TimeStamp != DateTime.MinValue)
     {
         SendNotificationToTarget<CompassSensorUpdate>(subscribe.Body.Subscriber, _subMgrPort, _state.Heading);
     }
 }
 public virtual IEnumerator<ITask> GetAnalogSensorHandler(pxanalogsensor.Get get)
 {
     get.ResponsePort.Post(SyncGenericState());
     yield break;
 }
        public virtual IEnumerator<ITask> GenericSubscribeHandler(pxanalogsensor.Subscribe subscribe)
        {
            yield return (Choice)base.SubscribeHelper(_genericSubMgrPort, subscribe.Body, subscribe.ResponsePort);

            if (_state.Heading.TimeStamp != DateTime.MinValue)
            {
                SendNotificationToTarget<pxanalogsensor.Replace>(subscribe.Body.Subscriber, _genericSubMgrPort, SyncGenericState());
            }
        }
 public virtual IEnumerator<ITask> SubscribeHandler(pxanalogsensor.Subscribe subscribe)
 {
     base.SubscribeHelper(_subMgrPort, subscribe.Body, subscribe.ResponsePort);
     yield break;
 }
 public virtual IEnumerator<ITask> AnalogReplaceHandler(pxanalogsensor.Replace replace)
 {
     _state.SensorPort = NxtCommon.GetNxtSensorPortFromHardwareIdentifier(replace.Body.HardwareIdentifier);
     SendNotification<pxanalogsensor.Replace>(_genericSubMgrPort, replace);
     replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
     yield break;
 }
        /// <summary>
        /// Analog Sensor Notification Handler
        /// </summary>
        /// <param name="notification"></param>
        private void AnalogSensorNotificationHandler(analog.Replace notification)
        {
            LogVerbose(LogGroups.Console, string.Format("Sensor Notification: {0} {1}", notification.Body.HardwareIdentifier, notification.Body.RawMeasurement));

            foreach (SensorRange key in _state.RuntimeConfiguration.Keys)
            {
                if (key.HardwareIdentifier != notification.Body.HardwareIdentifier)
                    continue;

                PortConfiguration sensorConfig = _state.RuntimeConfiguration[key];
                string contactSensorName = key.ContactSensorName;

                int priorIx = _contactSensorArrayState.Sensors.FindIndex(
                    delegate(bumper.ContactSensor gencs)
                    {
                        return gencs.HardwareIdentifier == notification.Body.HardwareIdentifier
                            && gencs.Name == contactSensorName;
                    });
                bool priorPressed = (priorIx < 0) ? false : _contactSensorArrayState.Sensors[priorIx].Pressed;

                // Send a ContactSensor notification here.
                bumper.ContactSensor cs = new bumper.ContactSensor(sensorConfig.HardwareIdentifier, contactSensorName);
                cs.Pressed = sensorConfig.Pressed(notification.Body.RawMeasurement);
                sensorConfig.Contact = cs.Pressed;

                if (priorIx < 0)
                    _contactSensorArrayState.Sensors.Add(cs);

                if (priorIx < 0 || priorPressed != cs.Pressed)
                {
                    if (priorIx >= 0)
                        _contactSensorArrayState.Sensors[priorIx].Pressed = cs.Pressed;

                    SendNotification<bumper.Update>(_subMgrPort, new bumper.Update(cs));
                }
            }
        }