public void TestConstructor() { Subsystem ss = new Subsystem(Subsystem.SUB_1_2MHZ_4BEAM_20DEG_PISTON_2, 0); // 1200kHz SubsystemConfiguration ssConfig = new SubsystemConfiguration(ss, 0, 0); // 0 Config int cepoIndex = 0; AdcpSubsystemConfig asConfig = new AdcpSubsystemConfig(ssConfig); string asConfigStr = AdcpSubsystemConfig.GetString(ssConfig); Assert.AreEqual(asConfig.SubsystemConfig.CepoIndex, cepoIndex, "CepoIndex is incorrect."); //Assert.AreEqual(asConfig.Commands.CepoIndex, cepoIndex, "Commands CEPO index is incorrect."); Assert.AreEqual(asConfig.SubsystemConfig.SubSystem, ss, "Subsystem is incorrect."); Assert.AreEqual(asConfig.SubsystemConfig, ssConfig, "SubsystemConfiguration is incorrect."); Assert.AreEqual(asConfig.ToString(), "[0] 1.2 MHz 4 beam 20 degree piston", "ToString is incorrect."); Assert.AreEqual(asConfigStr, "[0] 1.2 MHz 4 beam 20 degree piston", "GetString is incorrect."); }
public void TestJSON() { Subsystem ss = new Subsystem(Subsystem.SUB_1_2MHZ_4BEAM_20DEG_PISTON_2, 0); // 1200kHz SubsystemConfiguration ssConfig = new SubsystemConfiguration(ss, 0, 0); // 0 Config int cepoIndex = 0; AdcpSubsystemConfig asConfig = new AdcpSubsystemConfig(ssConfig); string json = Newtonsoft.Json.JsonConvert.SerializeObject(asConfig); // Serialize object to JSON AdcpSubsystemConfig newConfig = Newtonsoft.Json.JsonConvert.DeserializeObject<AdcpSubsystemConfig>(json); // Deserialize the JSON Assert.AreEqual(asConfig.SubsystemConfig.CepoIndex, cepoIndex, "CepoIndex is incorrect."); //Assert.AreEqual(asConfig.Commands.CepoIndex, cepoIndex, "Commands CEPO index is incorrect."); Assert.AreEqual(asConfig.SubsystemConfig.SubSystem, ss, "Subsystem is incorrect."); Assert.AreEqual(asConfig.SubsystemConfig, ssConfig, "SubsystemConfiguration is incorrect."); Assert.AreEqual(asConfig.ToString(), "[0] 1.2 MHz 4 beam 20 degree piston", "ToString is incorrect."); Assert.AreEqual(newConfig.SubsystemConfig.CepoIndex, cepoIndex, "CepoIndex is incorrect."); //Assert.AreEqual(newConfig.Commands.CepoIndex, cepoIndex, "Commands CEPO index is incorrect."); Assert.AreEqual(newConfig.SubsystemConfig.SubSystem, ss, "Subsystem is incorrect."); Assert.AreEqual(newConfig.SubsystemConfig, ssConfig, "SubsystemConfiguration is incorrect."); Assert.AreEqual(newConfig.ToString(), "[0] 1.2 MHz 4 beam 20 degree piston", "ToString is incorrect."); }
/// <summary> /// Get the AdcpSubsystemCommands from the list of commands stored in the project. /// This will assume the list of AdcpSubsystemCommands has already been populated. /// It will then search for the AdcpSubsystemCommands for the given subsystem. /// If the AdcpSubsystemCommands cannot be found, a default set of commands will /// be returned. /// </summary> /// <param name="asConfig">AdcpSubsystemConfig for the commands that are requested.</param> /// <returns>Adcp Subsystem Commands from the list of AdcpSubsystemCommands.</returns> public AdcpSubsystemCommands GetAdcpSubsystemCommands(AdcpSubsystemConfig asConfig) { foreach (AdcpSubsystemConfig config in Configuration.SubsystemConfigDict.Values) { if (config == asConfig) { return config.Commands; } } return new AdcpSubsystemCommands(asConfig.SubsystemConfig); }
/// <summary> /// Add a configuration to the dictionary. This will create an AdcpSubsystemConfig based /// off the Subsystem and CEPO index given. It will then add it to the dictionary. It will /// then return the created AdcpSubsystemConfig. If the AdcpSubsystemConfig could not be /// created, null will be returned. /// </summary> /// <param name="ss">Subsystem to add a configuration.</param> /// <param name="cepoIndex">CEPO index.</param> /// <returns>AdcpSubsystemConfig created with the given settings or null if one could not be created.</returns> private AdcpSubsystemConfig AddConfig(Subsystem ss, int cepoIndex) { AdcpSubsystemConfig asConfig = null; // If a bad Subsystem is given, we cannot use it if (!ss.IsEmpty()) { // Determine how many of the given subsystem have been added to the dictionary // We need to generate SubsystemConfiguration index value. // SubsystemConfiguration index is based off the number of SubsystemConfigurations already // in the dictionary before this configuration is added. ushort ssCount = 0; foreach (AdcpSubsystemConfig configuration in SubsystemConfigDict.Values) { // If the subsystems are the same, then increment the value if (configuration.SubsystemConfig.SubSystem.Code == ss.Code) { ssCount++; } } // Create all the subsystem configurations and add to the dictionary SubsystemConfiguration ssConfig = new SubsystemConfiguration(ss, (byte)cepoIndex, (byte)ssCount); // SubsystemConfiguration with the Index of the SubsystemConfiguration asConfig = new AdcpSubsystemConfig(ssConfig); // AdcpSubsystemConfig with the Subsystem, SubsystemConfig and CEPO index if (!SubsystemConfigDict.ContainsKey(asConfig.ToString())) { SubsystemConfigDict.Add(asConfig.ToString(), asConfig); } } return asConfig; }
/// <summary> /// Add a given AdcpSubsystemConfig to the dictionary. This will determine /// how many of the given subsystem type have already been added to the dictionary /// and generate a new index value. It will then set the index value to the SubsysteConfiguration. /// It will then add the AdcpSubsystemConfig to the dictionary. /// </summary> /// <param name="asConfig">AdcpSubsystemConfig to add to the dictionary.</param> private void AddConfig(AdcpSubsystemConfig asConfig) { // Determine how many of the given subsystem have been added to the dictionary // We need to generate SubsystemConfiguration index value. // SubsystemConfiguration index is based off the number of SubsystemConfigurations already // in the dictionary before this configuration is added. ushort ssCount = 0; foreach (AdcpSubsystemConfig configuration in SubsystemConfigDict.Values) { // If the subsystems are the same, then increment the value if (configuration.SubsystemConfig.SubSystem.Code == asConfig.SubsystemConfig.SubSystem.Code) { ssCount++; } } // Set the new Configuration index asConfig.SubsystemConfig.SubsystemConfigIndex = (byte)ssCount; // Set the new CEPO index // This is the last index for the CEPO command asConfig.SubsystemConfig.CepoIndex = Convert.ToByte(SubsystemConfigDict.Values.Count); // Add it to the dictionary SubsystemConfigDict.Add(asConfig.ToString(), asConfig); }
/// <summary> /// Get the CEPO configuration character and index within the CEPO command. /// The configuration character is the Subsystem code for the configuration. It /// represents the system type. The Index represents where in teh CEPO command /// the configuration was located. This determines the ping order of the configurations. /// It also make the configuration unique for a SubsystemConfiguration for a Subsystem. /// Get the Subsystem using the serial number and subsystem code. /// /// SubsystemConfiguaration CommandSetup: Index of the Configuration within Subsystem. (Based off counting configurations for a subsystem) /// index: Location in CEPO for the Subsystem configuration. /// </summary> /// <param name="ssCode">Subsystem Code from the CEPO command.</param> /// <param name="cepoIndex">Location in the CEPO command of the Subsystem Code.</param> /// <param name="serial">Serial number for the ADCP.</param> /// <returns>Return the AdcpSubsystemConfig created or null if one could not be created.</returns> private AdcpSubsystemConfig AddConfig(byte ssCode, int cepoIndex, SerialNumber serial) { AdcpSubsystemConfig asConfig = null; // Get the Subsystem index from the serial number // If it cannot be found in the serial number, then it is // a bad Subsystem and we can not use the command. Subsystem ss = serial.GetSubsystem(ssCode); if (!ss.IsEmpty()) { // Determine how many of the given subsystem have been added to the dictionary // We need to generate SubsystemConfiguration index value. // SubsystemConfiguration index is based off the number of SubsystemConfigurations already // in the dictionary before this configuration is added. ushort ssCount = 0; foreach (AdcpSubsystemConfig configuration in SubsystemConfigDict.Values) { // If the subsystems are the same, then increment the value if (configuration.SubsystemConfig.SubSystem.Code == ssCode) { ssCount++; } } // Create all the subsystem configurations and add to the dictionary SubsystemConfiguration ssConfig = new SubsystemConfiguration(ss, (byte)cepoIndex, (byte)ssCount); // SubsystemConfiguration with the CEPO index and Index of the SubsystemConfiguration asConfig = new AdcpSubsystemConfig(ssConfig); // AdcpSubsystemConfig with the Subsystem, SubsystemConfig and CEPO index SubsystemConfigDict.Add(asConfig.ToString(), asConfig); // Add to the dictionary the configuration with the string as the key } return asConfig; }
/// <summary> /// Remove the AdcpSubsystemConfig from the dictionary. If it exist in the /// dictionary, the AdcpSubsystemConfigs in the dictionary have to reordered. /// If it did not exist in the dictionary, do nothing and return false. /// /// Create a temporary list of all the configurations in the order /// of the CEPO command. Then add the configurations back to the dictonary /// and create a new CEPO command. /// </summary> /// <param name="config">AdcpSubsystemConfig to remove.</param> /// <returns>TRUE = Config removed / FALSE = Config did not exist in the dictonary. Nothing done.</returns> public bool RemoveAdcpSubsystemConfig(AdcpSubsystemConfig config) { if (config != null) { // Remove the AdcpSubsystemConfig from the dict // If it is removed, all the remaining configurations needed // to be renumbered if (SubsystemConfigDict.Remove(config.ToString())) { // Remove all the configurations from the dictionary and put in an sorted list by CEPO index SortedList<int, AdcpSubsystemConfig> tempList = new SortedList<int, AdcpSubsystemConfig>(); //List<AdcpSubsystemConfig> tempList = new List<AdcpSubsystemConfig>(); foreach (AdcpSubsystemConfig asConfig in SubsystemConfigDict.Values) { tempList.Add(asConfig.SubsystemConfig.CepoIndex, asConfig); //tempList.Add(asConfig); } // Clear the dictionary and the CEPO command //CEPO = ""; Commands.CEPO = AdcpCommands.DEFAULT_CEPO; SubsystemConfigDict.Clear(); // Redo the CEPO command // and add the configuration back to the dictionary for (int x = 0; x < tempList.Count; x++) { // Redo the cepo value Commands.CEPO += Convert.ToChar(tempList.Values[x].SubsystemConfig.SubSystem.Code); // Add config to the dictionary AddConfig(tempList.Values[x]); } return true; } } // Config was not in the list so the configuration was not reordered return false; }
/// <summary> /// Add a configuration. This will take a Subsystem as a parameter. /// It will then create a new configuration for the given Subsystem. /// It will update the CEPO command and it will add the new Configuration /// to the dictionary. /// This will add a specific configuration but only update the CEPO command /// if the /// </summary> /// <param name="ss">Subsystem for the configuration.</param> /// <param name="asConfig">Return the AdcpSubsystemConfig created.</param> /// <param name="cepoIndex">The CEPO Index to use.</param> /// <returns>TRUE = Configuration Added. / FALSE = Configuration could not be added.</returns> public bool AddConfiguration(Subsystem ss, out AdcpSubsystemConfig asConfig, int cepoIndex) { // Initialize the AdcpSubsystemConfig to null asConfig = null; // Generate a new CEPO //string cepo = CEPO + Convert.ToChar(ss.Code); //string cepo = Commands.CEPO + Convert.ToChar(ss.Code); string cepo = AddConfigToCepo(ss.Code, cepoIndex); // Validate the new CEPO // If it pass, then add the new configuration to the dictionary if (ValidateCEPO(cepo, SerialNumber)) { // Set the CEPO //CEPO = cepo; Commands.CEPO = cepo; // Get the CEPO index // The index will be the last character in the CEPO command // Subtract 1 because it is 0 based //int cepoIndex = Commands.CEPO.Length - 1; // Add the configuration to the dictionary // Set the AdcpSubsystemConfig to give to the user asConfig = AddConfig(ss, cepoIndex); return true; } // If the data is DVL data, add the config if (SerialNumber == SerialNumber.DVL) { // Set the CEPO //CEPO = cepo; Commands.CEPO = cepo; // Get the CEPO index // The index will be the last character in the CEPO command // Subtract 1 because it is 0 based //int cepoIndex = Commands.CEPO.Length - 1; // Add the configuration to the dictionary // Set the AdcpSubsystemConfig to give to the user asConfig = AddConfig(ss, cepoIndex); return true; } return false; }
public void TestJSON1() { Subsystem ss = new Subsystem(Subsystem.SUB_1_2MHZ_VERT_PISTON_A, 0); // 1200kHz SubsystemConfiguration ssConfig = new SubsystemConfiguration(ss, 3, 3); // 3 Config int cepoIndex = 3; AdcpSubsystemConfig asConfig = new AdcpSubsystemConfig(ssConfig); string json = Newtonsoft.Json.JsonConvert.SerializeObject(asConfig); // Serialize object to JSON AdcpSubsystemConfig newConfig = Newtonsoft.Json.JsonConvert.DeserializeObject<AdcpSubsystemConfig>(json); // Deserialize the JSON Assert.AreEqual(asConfig.SubsystemConfig.CepoIndex, cepoIndex, "CepoIndex is incorrect."); Assert.AreEqual(asConfig.SubsystemConfig.SubSystem, ss, "Subsystem is incorrect."); Assert.AreEqual(asConfig.SubsystemConfig, ssConfig, "SubsystemConfiguration is incorrect."); Assert.AreEqual(asConfig.ToString(), "[3] 1.2 MHz vertical beam piston", "ToString is incorrect."); Assert.AreEqual(newConfig.SubsystemConfig.CepoIndex, cepoIndex, "CepoIndex is incorrect."); Assert.AreEqual(newConfig.SubsystemConfig.SubSystem, ss, "Subsystem is incorrect."); Assert.AreEqual(newConfig.SubsystemConfig, ssConfig, "SubsystemConfiguration is incorrect."); Assert.AreEqual(newConfig.ToString(), "[3] 1.2 MHz vertical beam piston", "ToString is incorrect."); }