Пример #1
0
            /// <summary>
            /// Decoding a command set is similar to decoding CSHOW except
            /// in the command set, each line is a command for a subsystem where
            /// in CSHOW each line contain multiple subsystems for 1 command line.
            /// 
            /// This will combine all the commands to make the command set similar
            /// to the CSHOW output.
            /// 
            /// </summary>
            /// <param name="buffer">Buffer of the command set.</param>
            /// <param name="serial">Serial number.</param>
            /// <returns>ADCP configuration.</returns>
            public static AdcpConfiguration DecodeCommandSet(string buffer, SerialNumber serial)
            {
                Dictionary<string, string> commands = new Dictionary<string, string>();

                // Convert the commandset in to CSHOW
                string[] results = buffer.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
                for (int x = 0; x < results.Length; x++)
                {
                    // Get the command for each line
                    string[] cmd = results[x].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    // Get the cmd
                    if(cmd.Length > 1)
                    {
                        // If the command is CEPO
                        // Get the subsystem code to add to the serial number
                        if(cmd[0] == CMD_CEPO)
                        {
                            var cepoList = cmd[1].ToCharArray();
                            for(int cepoIndex = 0; cepoIndex < cepoList.Length; cepoIndex++ )
                            {
                                var subsys = new Subsystem((byte)cepoList[cepoIndex]);
                                serial.AddSubsystem(subsys);
                            }
                        }

                        // Command all the parameters
                        string param = "";
                        for (int y = 1; y < cmd.Length; y++ )
                        {
                            param += cmd[y];
                        }

                        // Append to the end if the key exist
                        if (commands.ContainsKey(cmd[0]))
                        {
                            commands[cmd[0]] += param;
                        }
                        else
                        {
                            commands.Add(cmd[0], param);
                        }
                    }
                    else
                    {
                        // No command, just add it
                        commands.Add(results[x], "");
                    }
                }

                // Combine all the values into the same format as CSHOW
                StringBuilder sb = new StringBuilder();

                foreach(var val in commands.Keys)
                {
                    sb.AppendLine(string.Format("{0} {1}", val, commands[val]));
                }

                DecodeCSHOW decoder = new DecodeCSHOW();
                return decoder.Decode(sb.ToString(), serial);
            }
Пример #2
0
 /// <summary>
 /// Use the DecodeCSHOW decoder to decode the CSHOW command
 /// result.  It will return an AdcpConfiguration with all the
 /// Adcp configurations.
 /// </summary>
 /// <param name="buffer">Result string from CSHOW command.</param>
 /// <param name="serial">Serial number for the system.</param>
 /// <returns>AdcpConfiguration containing all the configurations found from CSHOW.</returns>
 public static AdcpConfiguration DecodeCSHOW(string buffer, SerialNumber serial)
 {
     DecodeCSHOW decoder = new DecodeCSHOW();
     return decoder.Decode(buffer, serial);
 }