示例#1
0
        /// <summary>
        /// Gets information about the CPU and returns the value
        /// from the specified target field.
        /// </summary>
        /// <returns>
        /// The value of the specified CPU info attribute.
        /// </returns>
        /// <param name="target">
        /// The target attribute to get the value of.
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// The specified target is invalid.
        /// </exception>
        private static String GetCpuInfo(String target)
        {
            if (_cpuInfo == null)
            {
                _cpuInfo = new Dictionary <String, String>();
                String[] result = ExecUtil.ExecuteCommand("cat /proc/cpuinfo");
                if (result != null)
                {
                    String[] parts = { };
                    foreach (String line in result)
                    {
                        parts = line.Split(new Char[] { ':' }, 2);
                        if ((parts.Length >= 2) &&
                            (!String.IsNullOrEmpty(parts[0].Trim())) &&
                            (!String.IsNullOrEmpty(parts[1].Trim())))
                        {
                            _cpuInfo.Add(parts[0].Trim(), parts[1].Trim());
                        }
                    }
                }
            }

            if (_cpuInfo.ContainsKey(target))
            {
                return(_cpuInfo[target]);
            }

            throw new InvalidOperationException("Invalid target: " + target);
        }
示例#2
0
        /// <summary>
        /// This method will obtain a specified tag value from the elf
        /// info in the '/proc/self/exe' program (this method is used
        /// to help determine the HARD-FLOAT / SOFT-FLOAT ABI of the system)
        /// </summary>
        /// <returns>
        /// The ABI tag value.
        /// </returns>
        /// <param name="tag">
        /// The tag to get the value of.
        /// </param>
        private static String GetReadElfTag(String tag)
        {
            String tagVal = String.Empty;

            try {
                String[] result = ExecUtil.ExecuteCommand("/usr/bin/readelf -A /proc/self/exe");
                if (result != null)
                {
                    String[] lineParts = { };
                    String   part      = String.Empty;
                    foreach (String line in result)
                    {
                        part = line.Trim();
                        if ((line.StartsWith(tag)) && (part.Contains(":")))
                        {
                            lineParts = part.Split(new Char[] { ':' }, 2);
                            if (lineParts.Length > 1)
                            {
                                tagVal = lineParts[1].Trim();
                            }
                            break;
                        }
                    }
                }
            }
            catch {
            }
            return(tagVal);
        }
示例#3
0
        /// <summary>
        /// Gets the bash version info. This method is used to help
        /// determine the HARD-FLOAT / SOFT-FLOAT ABI of the system.
        /// </summary>
        /// <returns>
        /// The bash version info.
        /// </returns>
        private static String GetBashVersionInfo()
        {
            String ver = String.Empty;

            try {
                String[] result = ExecUtil.ExecuteCommand("bash --version");
                foreach (String line in result)
                {
                    if (!String.IsNullOrEmpty(line))
                    {
                        ver = line;                          // Return only the first line.
                        break;
                    }
                }
            }
            catch {
            }
            return(ver);
        }
示例#4
0
        /// <summary>
        /// Gets the clock frequency for the specified target.
        /// </summary>
        /// <returns>
        /// The clock frequency, if successful; Otherwise, -1.
        /// </returns>
        /// <param name="target">
        /// The target clock to get the frequency of.
        /// </param>
        private static long GetClockFrequency(String target)
        {
            long val = -1;

            String[] result = ExecUtil.ExecuteCommand("/opt/vc/bin/vcgencmd measure_clock " + target.Trim());
            if (result != null)
            {
                String[] parts = { };
                foreach (String line in result)
                {
                    parts = line.Split(new Char[] { '=' }, 2);
                    if (long.TryParse(parts[1].Trim(), out val))
                    {
                        break;
                    }
                }
            }
            return(val);
        }
示例#5
0
 /// <summary>
 /// Gets the voltage.
 /// </summary>
 /// <returns>
 /// The voltage.
 /// </returns>
 /// <param name="id">
 /// The ID of the voltage type to get (core, sdram_c, etc).
 /// </param>
 /// <exception cref="InvalidOperationException">
 /// Invalid command ("measure_volts") or response.
 /// </exception>
 private static float GetVoltage(String id)
 {
     String[] result = ExecUtil.ExecuteCommand("/opt/vc/bin/vcgencmd measure_volts " + id);
     if (result != null)
     {
         float    val   = -1f;
         String[] parts = { };
         foreach (String line in result)
         {
             parts = line.Split(new Char[] { '[', '=', 'V', ']' }, 3);
             if (float.TryParse(parts[1], out val))
             {
                 break;
             }
         }
         return(val);
     }
     throw new InvalidOperationException("Invalid command or response.");
 }
示例#6
0
        /// <summary>
        /// Gets whether or not the specified codec is enabled.
        /// </summary>
        /// <returns>
        /// <c>true</c>, if the codec is enabled; Otherwise, <code>false</code>.
        /// </returns>
        /// <param name="codec">
        /// The codec to get.
        /// </param>
        private static Boolean GetCodecEnabled(String codec)
        {
            Boolean enabled = false;

            String[] result = ExecUtil.ExecuteCommand("/opt/vc/bin/vcgencmd codec_enabled " + codec);
            if (result != null)
            {
                String[] parts = { };
                foreach (String line in result)
                {
                    parts = line.Split(new Char[] { '=' }, 2);
                    if (String.Equals(parts[1].Trim(), "enabled", StringComparison.InvariantCultureIgnoreCase))
                    {
                        enabled = true;
                        break;
                    }
                }
            }
            return(enabled);
        }
示例#7
0
        /// <summary>
        /// Gets the OS firmware date.
        /// </summary>
        /// <returns>
        /// The OS firmware date.
        /// </returns>
        /// <exception cref="InvalidOperationException">
        /// Invalid command ("version") or response.
        /// </exception>
        public static String GetOsFirmwareDate()
        {
            String[] results = ExecUtil.ExecuteCommand("/opt/vc/bin/vcgencmd version");
            String   val     = String.Empty;

            if (results != null)
            {
                foreach (String line in results)
                {
                    val = line;
                    break;
                }
            }

            if (!String.IsNullOrEmpty(val))
            {
                return(val);
            }
            throw new InvalidOperationException("Invalid command or response.");
        }
示例#8
0
        /// <summary>
        /// Gets the system memory info.
        /// </summary>
        /// <returns>
        /// The memory info.
        /// </returns>
        private static List <long> GetMemory()
        {
            // Memory information is in the form
            // root@mypi:/home/pi# free -b
            //              total       used       free     shared    buffers     cached
            // Mem:     459771904  144654336  315117568          0   21319680   63713280
            // -/+ buffers/cache:   59621376  400150528
            // Swap:    104853504          0  104853504
            List <long> values = new List <long>();

            String[] result = ExecUtil.ExecuteCommand("free -b");
            if (result != null)
            {
                String[] parts    = { };
                String   linePart = String.Empty;
                long     val      = 0;
                foreach (String line in result)
                {
                    if (line.StartsWith("Mem:"))
                    {
                        parts = line.Split(' ');
                        foreach (String part in parts)
                        {
                            linePart = part.Trim();
                            if ((!String.IsNullOrEmpty(linePart)) &&
                                (String.Equals(line, "Mem:", StringComparison.InvariantCultureIgnoreCase)))
                            {
                                if (long.TryParse(linePart, out val))
                                {
                                    values.Add(val);
                                }
                            }
                        }
                    }
                }
                Array.Clear(parts, 0, parts.Length);
            }
            Array.Clear(result, 0, result.Length);
            return(values);
        }
示例#9
0
 /// <summary>
 /// Gets the CPU temperature.
 /// </summary>
 /// <returns>
 /// The CPU temperature.
 /// </returns>
 /// <exception cref="InvalidOperationException">
 /// Invalid command ("measure_temp") or response.
 /// </exception>
 public static float GetCpuTemperature()
 {
     // CPU temperature is in the form
     // pi@mypi$ /opt/vc/bin/vcgencmd measure_temp
     // temp=42.3'C
     // Support for this was added around firmware version 3357xx per info
     // at http://www.raspberrypi.org/phpBB3/viewtopic.php?p=169909#p169909
     String[] result = ExecUtil.ExecuteCommand("/opt/vc/bin/vcgencmd measure_temp");
     if (result != null)
     {
         String[] parts = { };
         float    val   = -1f;
         foreach (String line in result)
         {
             parts = line.Split(new Char[] { '[', '=', ']', "'".ToCharArray()[0] }, 3);
             if (float.TryParse(parts[1], out val))
             {
                 break;
             }
         }
         return(val);
     }
     throw new InvalidOperationException("Invalid command or response.");
 }
示例#10
0
 /// <summary>
 /// Gets the IP address of the local system's hostname. This only works
 /// if the hostname can be resolved.
 /// </summary>
 /// <returns>
 /// The IP address.
 /// </returns>
 public static String GetIPAddress()
 {
     return(ExecUtil.ExecuteCommand("hostname --ip-address")[0]);
 }
示例#11
0
        /// <summary>
        /// Gets all FQDNs of the machine. This enumerates all configured
        /// network addresses on all configured network interfaces, and
        /// translates them to DNS domain names. Addresses that cannot be
        /// translated (i.e. because they do not have an appropriate reverse
        /// DNS entry) are skipped. Note that different addresses may resolve
        /// to the same name, therefore the return value may contain duplicate
        /// entries. Do not make any assumptions about the order of the items
        /// in the array.
        /// </summary>
        /// <returns>
        /// An array of FQDNS associated with the host.
        /// </returns>
        public static String[] GetAllFQDNs()
        {
            String names = ExecUtil.ExecuteCommand("hostname --all-fqdns")[0];

            return(names.Split(new Char[] { ' ' }));
        }