示例#1
0
        /// <summary>
        /// Receive Battery Notifications
        /// </summary>
        /// <param name="update"></param>
        private void NotificationHandler(brick.LegoSensorUpdate update)
        {
            nxtcmd.LegoResponseGetBatteryLevel batteryLevel = new nxtcmd.LegoResponseGetBatteryLevel(update.Body.CommandData);
            if (batteryLevel != null && batteryLevel.Success)
            {
                if (_state.MaxVoltage < batteryLevel.Voltage)
                {
                    _state.TimeStamp  = update.Body.TimeStamp;
                    _state.MaxVoltage = batteryLevel.Voltage;
                    SaveState(_state);
                }

                if (batteryLevel.Voltage != 0 &&
                    _state.MinVoltage > batteryLevel.Voltage)
                {
                    _state.TimeStamp  = update.Body.TimeStamp;
                    _state.MinVoltage = batteryLevel.Voltage;
                    SaveState(_state);
                }

                double percentBatteryPower = batteryLevel.Voltage / _state.MaxVoltage;
                if (_state.PercentBatteryPower != percentBatteryPower ||
                    _state.CurrentBatteryVoltage != batteryLevel.Voltage)
                {
                    _state.TimeStamp             = update.Body.TimeStamp;
                    _state.CurrentBatteryVoltage = batteryLevel.Voltage;
                    _state.PercentBatteryPower   = percentBatteryPower;
                    SendNotification <pxbattery.Replace>(_subMgrPort, _state.SyncGenericState(ref _genericState));
                }

                if (_state.CurrentBatteryVoltage < _state.CriticalBatteryVoltage)
                {
                    pxbattery.UpdateCriticalBattery criticalBattery = new pxbattery.UpdateCriticalBattery();
                    criticalBattery.PercentCriticalBattery = _state.PercentBatteryPower;
                    SendNotification <pxbattery.SetCriticalLevel>(_subMgrPort, criticalBattery);
                }
            }
        }
        /// <summary>
        /// Receive Battery Notifications
        /// </summary>
        /// <param name="update"></param>
        private void NotificationHandler(brick.LegoSensorUpdate update)
        {
            nxtcmd.LegoResponseGetBatteryLevel batteryLevel = new nxtcmd.LegoResponseGetBatteryLevel(update.Body.CommandData);
            if (batteryLevel != null && batteryLevel.Success)
            {
                if (_state.MaxVoltage < batteryLevel.Voltage)
                {
                    _state.TimeStamp = update.Body.TimeStamp;
                    _state.MaxVoltage = batteryLevel.Voltage;
                    SaveState(_state);
                }

                if (batteryLevel.Voltage != 0 &&
                    _state.MinVoltage > batteryLevel.Voltage)
                {
                    _state.TimeStamp = update.Body.TimeStamp;
                    _state.MinVoltage = batteryLevel.Voltage;
                    SaveState(_state);
                }

                double percentBatteryPower = batteryLevel.Voltage / _state.MaxVoltage;
                if (_state.PercentBatteryPower != percentBatteryPower
                    || _state.CurrentBatteryVoltage != batteryLevel.Voltage)
                {
                    _state.TimeStamp = update.Body.TimeStamp;
                    _state.CurrentBatteryVoltage = batteryLevel.Voltage;
                    _state.PercentBatteryPower = percentBatteryPower;
                    SendNotification<pxbattery.Replace>(_subMgrPort, _state.SyncGenericState(ref _genericState));
                }

                if (_state.CurrentBatteryVoltage < _state.CriticalBatteryVoltage)
                {
                    pxbattery.UpdateCriticalBattery criticalBattery = new pxbattery.UpdateCriticalBattery();
                    criticalBattery.PercentCriticalBattery = _state.PercentBatteryPower;
                    SendNotification<pxbattery.SetCriticalLevel>(_subMgrPort, criticalBattery);
                }
            }
        }