diff --git a/Configurator/Configurator.Net/ArducopterConfigurator.csproj b/Configurator/Configurator.Net/ArducopterConfigurator.csproj index cb99a2106f..be5dd441b7 100644 --- a/Configurator/Configurator.Net/ArducopterConfigurator.csproj +++ b/Configurator/Configurator.Net/ArducopterConfigurator.csproj @@ -44,7 +44,7 @@ - + diff --git a/Configurator/Configurator.Net/ArducopterConfigurator.sln b/Configurator/Configurator.Net/ArducopterConfigurator.sln index 61b4efd6d9..5272827f68 100644 --- a/Configurator/Configurator.Net/ArducopterConfigurator.sln +++ b/Configurator/Configurator.Net/ArducopterConfigurator.sln @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 10.00 # Visual Studio 2008 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArducopterConfigurator", "ArducopterConfigurator.csproj", "{AF26391C-7E45-4401-8984-96139A67FF31}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArducopterConfiguratorTest", "Test\ArducopterConfiguratorTest.csproj", "{36B62E9F-668C-45BF-AD72-CFF0C0A65898}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -13,6 +15,10 @@ Global {AF26391C-7E45-4401-8984-96139A67FF31}.Debug|Any CPU.Build.0 = Debug|Any CPU {AF26391C-7E45-4401-8984-96139A67FF31}.Release|Any CPU.ActiveCfg = Release|Any CPU {AF26391C-7E45-4401-8984-96139A67FF31}.Release|Any CPU.Build.0 = Release|Any CPU + {36B62E9F-668C-45BF-AD72-CFF0C0A65898}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {36B62E9F-668C-45BF-AD72-CFF0C0A65898}.Debug|Any CPU.Build.0 = Debug|Any CPU + {36B62E9F-668C-45BF-AD72-CFF0C0A65898}.Release|Any CPU.ActiveCfg = Release|Any CPU + {36B62E9F-668C-45BF-AD72-CFF0C0A65898}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Configurator/Configurator.Net/CommsSession.cs b/Configurator/Configurator.Net/CommsSession.cs index 8ed2429928..408667d473 100644 --- a/Configurator/Configurator.Net/CommsSession.cs +++ b/Configurator/Configurator.Net/CommsSession.cs @@ -8,13 +8,22 @@ using ArducopterConfigurator.PresentationModels; namespace ArducopterConfigurator { + public interface IComms + { + event Action LineOfDataReceived; + string CommPort { get; set; } + void Send(string send); + bool Connect(); + bool DisConnect(); + } + /// /// Represents a session of communication with the Arducopter /// /// /// Looks after connection state etc /// - public class CommsSession + public class CommsSession : IComms { private readonly SerialPort _sp; private BackgroundWorker _bgWorker; @@ -103,4 +112,6 @@ namespace ArducopterConfigurator _sp.Write(send); } } + + } diff --git a/Configurator/Configurator.Net/PresentationModels/DelegateCommand.cs b/Configurator/Configurator.Net/Core/DelegateCommand.cs similarity index 100% rename from Configurator/Configurator.Net/PresentationModels/DelegateCommand.cs rename to Configurator/Configurator.Net/Core/DelegateCommand.cs diff --git a/Configurator/Configurator.Net/PresentationModels/AcroModeConfigVm.cs b/Configurator/Configurator.Net/PresentationModels/AcroModeConfigVm.cs index 5645bba451..e04ed937b6 100644 --- a/Configurator/Configurator.Net/PresentationModels/AcroModeConfigVm.cs +++ b/Configurator/Configurator.Net/PresentationModels/AcroModeConfigVm.cs @@ -4,7 +4,7 @@ namespace ArducopterConfigurator.PresentationModels { public class AcroModeConfigVm : ConfigWithPidsBase { - public AcroModeConfigVm(CommsSession sp) : base(sp) + public AcroModeConfigVm(IComms sp) : base(sp) { PropsInUpdateOrder = new[] { diff --git a/Configurator/Configurator.Net/PresentationModels/AltitudeHoldConfigVm.cs b/Configurator/Configurator.Net/PresentationModels/AltitudeHoldConfigVm.cs index 346a2974fc..b0a85b6ac4 100644 --- a/Configurator/Configurator.Net/PresentationModels/AltitudeHoldConfigVm.cs +++ b/Configurator/Configurator.Net/PresentationModels/AltitudeHoldConfigVm.cs @@ -2,7 +2,7 @@ namespace ArducopterConfigurator.PresentationModels { public class AltitudeHoldConfigVm : MonitorVm { - public AltitudeHoldConfigVm(CommsSession sp) + public AltitudeHoldConfigVm(IComms sp) : base(sp) { PropsInUpdateOrder = new[] { "P", "I", "D", }; @@ -14,9 +14,9 @@ namespace ArducopterConfigurator.PresentationModels public ICommand RefreshCommand { get; private set; } public ICommand UpdateCommand { get; private set; } - public float P { get; protected set; } - public float I { get; protected set; } - public float D { get; protected set; } + public float P { get; set; } + public float I { get; set; } + public float D { get; set; } private void RefreshValues() diff --git a/Configurator/Configurator.Net/PresentationModels/CalibrationOffsetsDataVm.cs b/Configurator/Configurator.Net/PresentationModels/CalibrationOffsetsDataVm.cs index ee99bdef05..7b999ab144 100644 --- a/Configurator/Configurator.Net/PresentationModels/CalibrationOffsetsDataVm.cs +++ b/Configurator/Configurator.Net/PresentationModels/CalibrationOffsetsDataVm.cs @@ -6,7 +6,7 @@ namespace ArducopterConfigurator.PresentationModels { public class CalibrationOffsetsDataVm : MonitorVm { - public CalibrationOffsetsDataVm(CommsSession sp) : base(sp) + public CalibrationOffsetsDataVm(IComms sp) : base(sp) { PropsInUpdateOrder = new[] { diff --git a/Configurator/Configurator.Net/PresentationModels/ConfigWithPidsBase.cs b/Configurator/Configurator.Net/PresentationModels/ConfigWithPidsBase.cs index bd2279e334..34191ea2f2 100644 --- a/Configurator/Configurator.Net/PresentationModels/ConfigWithPidsBase.cs +++ b/Configurator/Configurator.Net/PresentationModels/ConfigWithPidsBase.cs @@ -19,7 +19,7 @@ namespace ArducopterConfigurator.PresentationModels public float YawD { get; set; } - public ConfigWithPidsBase(CommsSession sp) : base(sp) + public ConfigWithPidsBase(IComms sp) : base(sp) { } diff --git a/Configurator/Configurator.Net/PresentationModels/FlightDataMonitorVm.cs b/Configurator/Configurator.Net/PresentationModels/FlightDataMonitorVm.cs index e11cf73350..53cea90686 100644 --- a/Configurator/Configurator.Net/PresentationModels/FlightDataMonitorVm.cs +++ b/Configurator/Configurator.Net/PresentationModels/FlightDataMonitorVm.cs @@ -7,7 +7,7 @@ namespace ArducopterConfigurator.PresentationModels { public class FlightDataVm : MonitorVm { - public FlightDataVm(CommsSession _sp) : base(_sp) + public FlightDataVm(IComms _sp) : base(_sp) { } diff --git a/Configurator/Configurator.Net/PresentationModels/MainVm.cs b/Configurator/Configurator.Net/PresentationModels/MainVm.cs index 20516cdf99..892baa2c7e 100644 --- a/Configurator/Configurator.Net/PresentationModels/MainVm.cs +++ b/Configurator/Configurator.Net/PresentationModels/MainVm.cs @@ -9,17 +9,17 @@ namespace ArducopterConfigurator.PresentationModels { public class MainVm : NotifyProperyChangedBase, IPresentationModel { - private readonly CommsSession _session; + private readonly IComms _session; private bool _isConnected; private MonitorVm _selectedVm; private string _selectedPort; private string _apmVersion; - private System.Windows.Forms.Timer _connectionAttemptsTimer; + private Timer _connectionAttemptsTimer; private SessionStates _connectionState; - public MainVm(CommsSession session) + public MainVm(IComms session) { _session = session; _session.LineOfDataReceived += _session_LineOfDataReceived; @@ -157,7 +157,6 @@ namespace ArducopterConfigurator.PresentationModels _session.Send("!"); } - public void Disconnect() { _session.Send("X"); @@ -165,9 +164,6 @@ namespace ArducopterConfigurator.PresentationModels ConnectionState = SessionStates.Disconnected; } - - - public string ApmVersion { get { return _apmVersion; } diff --git a/Configurator/Configurator.Net/PresentationModels/MonitorVm.cs b/Configurator/Configurator.Net/PresentationModels/MonitorVm.cs index ba2b7fabcb..f665a741a1 100644 --- a/Configurator/Configurator.Net/PresentationModels/MonitorVm.cs +++ b/Configurator/Configurator.Net/PresentationModels/MonitorVm.cs @@ -12,11 +12,11 @@ namespace ArducopterConfigurator /// public abstract class MonitorVm : NotifyProperyChangedBase, IPresentationModel { - private CommsSession _sp; + private IComms _sp; protected bool isActive; protected string[] PropsInUpdateOrder; - protected MonitorVm(CommsSession sp) + protected MonitorVm(IComms sp) { _sp = sp; _sp.LineOfDataReceived += sp_LineOfDataReceived; diff --git a/Configurator/Configurator.Net/PresentationModels/MotorCommandsVm.cs b/Configurator/Configurator.Net/PresentationModels/MotorCommandsVm.cs index 3495e1c765..971c85c74d 100644 --- a/Configurator/Configurator.Net/PresentationModels/MotorCommandsVm.cs +++ b/Configurator/Configurator.Net/PresentationModels/MotorCommandsVm.cs @@ -2,7 +2,7 @@ namespace ArducopterConfigurator.PresentationModels { public class MotorCommandsVm : MonitorVm { - public MotorCommandsVm(CommsSession _sp) + public MotorCommandsVm(IComms _sp) : base(_sp) { } diff --git a/Configurator/Configurator.Net/PresentationModels/PositionHoldConfigVm.cs b/Configurator/Configurator.Net/PresentationModels/PositionHoldConfigVm.cs index f0bd99c532..8ed7aa4c84 100644 --- a/Configurator/Configurator.Net/PresentationModels/PositionHoldConfigVm.cs +++ b/Configurator/Configurator.Net/PresentationModels/PositionHoldConfigVm.cs @@ -2,7 +2,7 @@ namespace ArducopterConfigurator.PresentationModels { public class PositionHoldConfigVm : ConfigWithPidsBase { - public PositionHoldConfigVm(CommsSession sp) + public PositionHoldConfigVm(IComms sp) : base(sp) { PropsInUpdateOrder = new[] diff --git a/Configurator/Configurator.Net/PresentationModels/SerialMonitorVm.cs b/Configurator/Configurator.Net/PresentationModels/SerialMonitorVm.cs index c6f304b8d7..42c38cf9fb 100644 --- a/Configurator/Configurator.Net/PresentationModels/SerialMonitorVm.cs +++ b/Configurator/Configurator.Net/PresentationModels/SerialMonitorVm.cs @@ -7,7 +7,7 @@ namespace ArducopterConfigurator.PresentationModels { private string _text; - public SerialMonitorVm(CommsSession _sp) : base(_sp) + public SerialMonitorVm(IComms _sp) : base(_sp) { _sp.LineOfDataReceived += new Action(_sp_DataReceived); diff --git a/Configurator/Configurator.Net/PresentationModels/StableModeConfigVm.cs b/Configurator/Configurator.Net/PresentationModels/StableModeConfigVm.cs index 6e8d54a0b7..a9f41db113 100644 --- a/Configurator/Configurator.Net/PresentationModels/StableModeConfigVm.cs +++ b/Configurator/Configurator.Net/PresentationModels/StableModeConfigVm.cs @@ -2,7 +2,7 @@ namespace ArducopterConfigurator.PresentationModels { public class StableModeConfigVm : ConfigWithPidsBase { - public StableModeConfigVm(CommsSession sp) + public StableModeConfigVm(IComms sp) : base(sp) { PropsInUpdateOrder = new[] @@ -28,9 +28,9 @@ namespace ArducopterConfigurator.PresentationModels public ICommand UpdateCommand { get; private set; } - public float KPrate { get; private set; } + public float KPrate { get; set; } - public bool MagnetometerEnable { get; private set; } + public bool MagnetometerEnable { get; set; } private void RefreshValues() { diff --git a/Configurator/Configurator.Net/PresentationModels/TransmitterChannelsVm.cs b/Configurator/Configurator.Net/PresentationModels/TransmitterChannelsVm.cs index c6f602ff01..46b81db01a 100644 --- a/Configurator/Configurator.Net/PresentationModels/TransmitterChannelsVm.cs +++ b/Configurator/Configurator.Net/PresentationModels/TransmitterChannelsVm.cs @@ -5,7 +5,7 @@ namespace ArducopterConfigurator.PresentationModels { public class TransmitterChannelsVm : MonitorVm { - public TransmitterChannelsVm(CommsSession sp) : base(sp) + public TransmitterChannelsVm(IComms sp) : base(sp) { PropsInUpdateOrder = new[] { diff --git a/Configurator/Configurator.Net/Test/AltitudeHoldVmTest.cs b/Configurator/Configurator.Net/Test/AltitudeHoldVmTest.cs new file mode 100644 index 0000000000..9c084d7753 --- /dev/null +++ b/Configurator/Configurator.Net/Test/AltitudeHoldVmTest.cs @@ -0,0 +1,48 @@ +using ArducopterConfigurator.PresentationModels; +using NUnit.Framework; + +namespace ArducopterConfiguratorTest +{ + [TestFixture] + public class AltitudeHoldVmTest + { + private FakeComms _fakeComms; + private AltitudeHoldConfigVm _vm; + + [SetUp] + public void Setup() + { + _fakeComms = new FakeComms(); + _vm = new AltitudeHoldConfigVm(_fakeComms); + } + + [Test] + public void UpdateStringSentIsCorrect() + { + _vm.P = 1.0F; + _vm.I = 2.0F; + _vm.D = 3.0F; + + _vm.UpdateCommand.Execute(null); + + Assert.AreEqual(1, _fakeComms.SentItems.Count); + + Assert.AreEqual("E1;3;2", _fakeComms.SentItems[0]); + + } + + [Test] + // For whatever reason, for Altitude the properties are sent in P, D ,I + // order, but received in P,I,D order + public void UpdateStringReceivedPopulatesValuesCorrectly() + { + _fakeComms.FireLineRecieve("F1;2;3"); + + Assert.AreEqual(1f, _vm.P); + Assert.AreEqual(2f, _vm.I); + Assert.AreEqual(3f, _vm.D); + } + + + } +} \ No newline at end of file diff --git a/Configurator/Configurator.Net/Test/ArducopterConfiguratorTest.csproj b/Configurator/Configurator.Net/Test/ArducopterConfiguratorTest.csproj new file mode 100644 index 0000000000..00768dd935 --- /dev/null +++ b/Configurator/Configurator.Net/Test/ArducopterConfiguratorTest.csproj @@ -0,0 +1,62 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {36B62E9F-668C-45BF-AD72-CFF0C0A65898} + Library + Properties + ArducopterConfiguratorTest + ArducopterConfiguratorTest + v2.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\Lib3\nunit.framework.dll + + + + + + + + + + + + + + {AF26391C-7E45-4401-8984-96139A67FF31} + ArducopterConfigurator + + + + + \ No newline at end of file diff --git a/Configurator/Configurator.Net/Test/MainVmTests.cs b/Configurator/Configurator.Net/Test/MainVmTests.cs new file mode 100644 index 0000000000..f09a2c9eb2 --- /dev/null +++ b/Configurator/Configurator.Net/Test/MainVmTests.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Text; +using ArducopterConfigurator; +using ArducopterConfigurator.PresentationModels; +using NUnit.Framework; + +namespace ArducopterConfiguratorTest +{ + internal class FakeComms : IComms + { + public event Action LineOfDataReceived; + public string CommPort { get; set; } + public List SentItems = new List(); + + public void Send(string send) + { + SentItems.Add(send); + } + + public bool Connect() + { + return true; + } + + public bool DisConnect() + { + return true; + } + + public void FireLineRecieve(string s) + { + if (LineOfDataReceived != null) + LineOfDataReceived(s); + } + } + + [TestFixture] + public class MainVmTests + { + private FakeComms _fakeComms; + private MainVm _vm; + + [SetUp] + public void Setup() + { + _fakeComms = new FakeComms(); + _vm = new MainVm(_fakeComms); + } + + [Test] + public void StateInitiallyDisconnected() + { + Assert.AreEqual(MainVm.SessionStates.Disconnected,_vm.ConnectionState); + } + + + } + + + [TestFixture] + public class StableModeConfigVmTest + { + private FakeComms _fakeComms; + private StableModeConfigVm _vm; + + [SetUp] + public void Setup() + { + _fakeComms = new FakeComms(); + _vm = new StableModeConfigVm(_fakeComms); + + + } + + [Test] + public void UpdateStringSentIsCorrect() + { + _vm.PitchP = 1.0F; + _vm.PitchI = 2.0F; + _vm.PitchD = 3.0F; + _vm.RollP = 5.0F; + _vm.RollI = 6.0F; + _vm.RollD = 7.0F; + _vm.YawP = 8.0F; + _vm.YawI = 9.0F; + _vm.YawD = 10.0F; + _vm.MagnetometerEnable = true; + _vm.KPrate = 4.0F; + + _vm.UpdateCommand.Execute(null); + + + Assert.AreEqual(1,_fakeComms.SentItems.Count); + + //A[KP Quad Roll];[KI Quad Roll];[KP RATE ROLL]; + // [KP Quad Pitch];[KI Quad Pitch];[KP RATE PITCH]; + // [KP Quad Yaw];[KI Quad Yaw];[KP Rate Yaw]; + // [KP Rate];[Magneto] + Assert.AreEqual("A5;6;7;1;2;3;8;9;10;4;1", _fakeComms.SentItems[0]); + } + + [Test] + public void UpdateStringReceivedPopulatesValuesCorrectly() + { + _fakeComms.FireLineRecieve("B5;6;7;1;2;3;8;9;10;4;1"); + + Assert.AreEqual(1.0f,_vm.PitchP); + Assert.AreEqual(2f,_vm.PitchI); + Assert.AreEqual(3f,_vm.PitchD); + Assert.AreEqual(5f,_vm.RollP); + Assert.AreEqual(6f,_vm.RollI); + Assert.AreEqual(7f,_vm.RollD); + Assert.AreEqual(8f,_vm.YawP); + Assert.AreEqual(9f,_vm.YawI); + Assert.AreEqual(10f,_vm.YawD); + Assert.AreEqual(1f,_vm.MagnetometerEnable); + Assert.AreEqual(4f,_vm.KPrate); + } + + + } +} diff --git a/Configurator/Configurator.Net/Test/MotorCommandsVmTest.cs b/Configurator/Configurator.Net/Test/MotorCommandsVmTest.cs new file mode 100644 index 0000000000..17e998d48d --- /dev/null +++ b/Configurator/Configurator.Net/Test/MotorCommandsVmTest.cs @@ -0,0 +1,23 @@ +using ArducopterConfigurator.PresentationModels; +using NUnit.Framework; + +namespace ArducopterConfiguratorTest +{ + [TestFixture] + public class MotorCommandsVmTest + { + private FakeComms _fakeComms; + private MotorCommandsVm _vm; + + [SetUp] + public void Setup() + { + _fakeComms = new FakeComms(); + _vm = new MotorCommandsVm(_fakeComms); + } + + + + + } +} \ No newline at end of file diff --git a/Configurator/Configurator.Net/Test/Properties/AssemblyInfo.cs b/Configurator/Configurator.Net/Test/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..453116723d --- /dev/null +++ b/Configurator/Configurator.Net/Test/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ArducopterConfiguratorTest")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("TOSHIBA")] +[assembly: AssemblyProduct("ArducopterConfiguratorTest")] +[assembly: AssemblyCopyright("Copyright © TOSHIBA 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("19d172a3-8241-459a-bee7-3318a20fce16")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]