Inheritance: AbstractUpdateableComponent
        public void UpdateFromString_InvalidUpdateString_ThrowException()
        {
            //This also tests the IsMatch method
            Motor m = new Motor(Motor.Location.MiddleRight);
            string updateString;

            updateString = "<M;M,R,23.12,45.0>";
            Assert.Throws<InvalidUpdateStringException>(() => m.UpdateFromString(updateString));
            updateString = "<MR;C,R,23.12,45.0>";
            Assert.Throws<InvalidUpdateStringException>(() => m.UpdateFromString(updateString));
            updateString = "MR;M,R,23.12,45.0";
            Assert.Throws<InvalidUpdateStringException>(() => m.UpdateFromString(updateString));
            updateString = "<MR;M,R,23.124453,45.0>";
            Assert.Throws<InvalidUpdateStringException>(() => m.UpdateFromString(updateString));
            updateString = "<MR;M,R,23.12,45.0145>";
            Assert.Throws<InvalidUpdateStringException>(() => m.UpdateFromString(updateString));
            updateString = "<MR;M,R,23.12,45.>";
            Assert.Throws<InvalidUpdateStringException>(() => m.UpdateFromString(updateString));
            updateString = "<MR;M,B,23.12,45.0>";
            Assert.Throws<InvalidUpdateStringException>(() => m.UpdateFromString(updateString));
            updateString = "<MR;M,R23.12,45.0>";
            Assert.Throws<InvalidUpdateStringException>(() => m.UpdateFromString(updateString));
            updateString = "<MRM,R,23.12,45.0>";
            Assert.Throws<InvalidUpdateStringException>(() => m.UpdateFromString(updateString));
            updateString = "<MR;F,R,23.12,45.0>";
            Assert.Throws<InvalidUpdateStringException>(() => m.UpdateFromString(updateString));
        }
        public void UpdateFromString_ValidUpdateString_ObjectUpdated()
        {
            Motor m = new Motor(Motor.Location.MiddleRight) { Current = 23.0f, Temperature = 50.0f };
            string updateString;

            updateString = "<MR;M,R,23.12,45.0>";
            m.UpdateFromString(updateString);

            Assert.AreEqual(23.12f, m.Current);
            Assert.AreEqual(45.0f, m.Temperature);
        }
        public MotorStatusViewModel(Motor.Location motorKey)
        {
            this.motorKey = motorKey;
            motor = StatusUpdater.Instance.RoverStatus.Motors[motorKey];

            motor.DangerousCurrentDetected += new MarsRover.DangerousCurrentDetectedDelegate<Motor>(CurrentStatusChanged);
            motor.WarningCurrentDetected += new MarsRover.WarningCurrentDetectedDelegate<Motor>(CurrentStatusChanged);
            motor.NormalCurrentDetected += new MarsRover.NormalCurrentDetectedDelegate<Motor>(CurrentStatusChanged);

            motor.DangerousTemperatureDetected += new MarsRover.DangerousTemperatureDetectedDelegate<Motor>(TemperatureStatusChanged);
            motor.WarningTemperatureDetected += new MarsRover.WarningTemperatureDetectedDelegate<Motor>(TemperatureStatusChanged);
            motor.NormalTemperatureDetected += new MarsRover.NormalTemperatureDetectedDelegate<Motor>(TemperatureStatusChanged);

            StatusUpdater.Instance.MotorsUpdated += new StatusUpdater.MotorsUpdatedDelegate(UpdateMotor);
        }
        public void GetUpdateString_ValidUpdateStringGenerated_ValidUpdateStringReturned()
        {
            Motor m = new Motor(Motor.Location.MiddleRight) { Current = 23.0239f, Temperature = 50.0423f };

            Assert.AreEqual(String.Format("<MR;M,R,{0},{1}>", Math.Round(m.Current, 3), Math.Round(m.Temperature, 3)), m.GetUpdateString());
        }
 public Motor(Motor.Location location)
 {
     LocationOnRover = location;
     Duty = 100.0f;
     regex = "<" + UpdateIdentifier + @";[MFB],[LR],\d+(\.\d{1,3})?,\d+(\.\d{1,3})?>";
 }
        public static string GetLocationFriendlyString(Motor.Location location)
        {
            switch (location)
            {
                case Motor.Location.FrontLeft:
                    return "Front Left";
                case Motor.Location.FrontRight:
                    return "Front Right";
                case Motor.Location.MiddleLeft:
                    return "Middle Left";
                case Motor.Location.MiddleRight:
                    return "Middle Right";
                case Motor.Location.BackLeft:
                    return "Back Left";
                case Motor.Location.BackRight:
                    return "Back Right";
            }

            return "";
        }
 private void UpdateMotor(Motor motor)
 {
     if (PropertyChanged != null)
     {
         PropertyChanged(this, new PropertyChangedEventArgs("Motor"));
     }
 }
        private void TemperatureStatusChanged(Motor motor)
        {
            if (motor.StatusTemperature == TemperatureStatus.Dangerous)
            {
                IsDangerousTemperature = true;
                IsWarningTemperature = false;
            }
            else if(motor.StatusTemperature == TemperatureStatus.Warning)
            {
                IsDangerousTemperature = false;
                IsWarningTemperature = true;
            }
            else
            {
                IsDangerousTemperature = false;
                IsWarningTemperature = false;
            }

            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("IsDangerousTemperature"));
                PropertyChanged(this, new PropertyChangedEventArgs("IsWarningTemperature"));
            }
        }
        private void CurrentStatusChanged(Motor motor)
        {
            if(motor.StatusCurrent == CurrentStatus.Dangerous)
            {
                IsDangerousCurrent = true;
                IsWarningCurrent = false;
            }
            else if (motor.StatusCurrent == CurrentStatus.Warning)
            {
                IsDangerousCurrent = false;
                IsWarningCurrent = true;
            }
            else
            {
                IsDangerousCurrent = false;
                IsWarningCurrent = false;
            }

            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("IsDangerousCurrent"));
                PropertyChanged(this, new PropertyChangedEventArgs("IsWarningCurrent"));
            }
        }