Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Determine if the AdcpSubsystemConfig exist in the dictionary.  This will generate
        /// a key based off the Subsystem and SubsystemConfiguration given.  It will then
        /// check if the key exist in the dictionary.
        /// </summary>
        /// <param name="ssConfig">SubsystemConfiguration.</param>
        /// <returns>TRUE = Subsystem and SubsystemConfiguration key found.  /  FALSE = No AdcpSubsystemConfig key.</returns>
        public bool AdcpSubsystemConfigExist(SubsystemConfiguration ssConfig)
        {
            // Check for null
            if (ssConfig == null)
            {
                return(false);
            }

            string str = ssConfig.DescString();

            //return SubsystemConfigDict.ContainsKey(AdcpSubsystemConfig.GetString(ssConfig));
            return(SubsystemConfigDict.ContainsKey(str));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Decode the CEPO command and populate the dictionary.
        ///
        /// Ex:
        /// CEPO 222
        /// 1 Subsystem
        /// 3 SubsystemConfigurations for Subsystem 2
        ///
        /// CEPO 232
        /// 2 Subsystems
        /// 2 SubsystemConfigurations for Subsystem 2 and
        /// 1 SubsystemConfiguration for Subsystem 3
        ///
        /// </summary>
        /// <param name="cepo">CEPO command to decode.</param>
        /// <param name="serial">Serial number to determine the system type.</param>
        /// <returns>Dictionary of all subsystem configurations found.</returns>
        private Dictionary <string, AdcpSubsystemConfig> DecodeCepo(string cepo, SerialNumber serial)
        {
            // Clear the current dictionary
            SubsystemConfigDict.Clear();

            // Add each configuration in the command
            for (int x = 0; x < cepo.Length; x++)
            {
                AddConfig(Subsystem.ConvertSubsystemCode(cepo, x), x, serial);
            }

            // Return the populated dictionary
            return(SubsystemConfigDict);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get the AdcpSubsystemConfig from the dictionary if it exist.  If it does not
        /// exist in the dictionary, null will be returned.
        /// </summary>
        /// <param name="ssConfig">SubsystemConfiguration.</param>
        /// <returns>If the AdcpSubystemConfig is found, it will return the AdcpSubsystemConfig.  If it is not found, it will return null.</returns>
        public AdcpSubsystemConfig GetAdcpSubsystemConfig(SubsystemConfiguration ssConfig)
        {
            // Check for null
            if (ssConfig == null)
            {
                return(null);
            }

            // Generate the key for the Subsystem and SubsystemConfiguration
            string key = AdcpSubsystemConfig.GetString(ssConfig);

            // If the key exist, return the object
            if (SubsystemConfigDict.ContainsKey(key))
            {
                return(SubsystemConfigDict[key]);
            }

            // The key did not exist so return null
            return(null);
        }
Ejemplo n.º 7
0
        /// <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);
        }