Created
June 5, 2021 12:26
-
-
Save FoxCouncil/c4e2cce88d621e30c76ed47f769134ee to your computer and use it in GitHub Desktop.
vcgencmd is a command line utility that can get various pieces of information from the VideoCore GPU on the Raspberry Pi. This is for the command get_throttled part of that.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Text; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var parsableOutput = "0x3000F"; | |
var parsedInt = Convert.ToInt32(parsableOutput, 16); | |
var bitArray = new BitArray(new int[] { parsedInt }); | |
var top = new StringBuilder(); | |
var bottom = new StringBuilder(); | |
for (int i = 0; i < bitArray.Count; i++) | |
{ | |
top.Append(i.ToString().PadLeft(3)); | |
bottom.Append(string.Concat(" ", bitArray[i] ? '1' : '0')); | |
} | |
Console.WriteLine(top.ToString()); | |
Console.WriteLine(bottom.ToString()); | |
Console.WriteLine(); | |
var tStatus = new ThrottledStatus(parsedInt); | |
Console.WriteLine(tStatus); | |
Console.WriteLine(); | |
TestThrottledStatus(); | |
} | |
public static void TestThrottledStatus() | |
{ | |
var testCases = new Dictionary<string, List<bool>> { | |
{ "0x0", new List<bool> { false, false, false, false, false, false, false, false } }, | |
{ "0x1", new List<bool> { true, false, false, false, false, false, false, false } }, | |
{ "0x2", new List<bool> { false, true, false, false, false, false, false, false } }, | |
{ "0x3", new List<bool> { true, true, false, false, false, false, false, false } }, | |
{ "0x4", new List<bool> { false, false, true, false, false, false, false, false } }, | |
{ "0x5", new List<bool> { true, false, true, false, false, false, false, false } }, | |
{ "0x6", new List<bool> { false, true, true, false, false, false, false, false } }, | |
{ "0x7", new List<bool> { true, true, true, false, false, false, false, false } }, | |
{ "0x8", new List<bool> { false, false, false, true, false, false, false, false } }, | |
{ "0x9", new List<bool> { true, false, false, true, false, false, false, false } }, | |
{ "0xA", new List<bool> { false, true, false, true, false, false, false, false } }, | |
{ "0xB", new List<bool> { true, true, false, true, false, false, false, false } }, | |
{ "0xC", new List<bool> { false, false, true, true, false, false, false, false } }, | |
{ "0xD", new List<bool> { true, false, true, true, false, false, false, false } }, | |
{ "0xE", new List<bool> { false, true, true, true, false, false, false, false } }, | |
{ "0xF", new List<bool> { true, true, true, true, false, false, false, false } }, | |
{ "0x10000", new List<bool> { false, false, false, false, true, false, false, false } }, | |
{ "0x20000", new List<bool> { false, false, false, false, false, true, false, false } }, | |
{ "0x30000", new List<bool> { false, false, false, false, true, true, false, false } }, | |
{ "0x40000", new List<bool> { false, false, false, false, false, false, true, false } }, | |
{ "0x50000", new List<bool> { false, false, false, false, true, false, true, false } }, | |
{ "0x60000", new List<bool> { false, false, false, false, false, true, true, false } }, | |
{ "0x70000", new List<bool> { false, false, false, false, true, true, true, false } }, | |
{ "0x80000", new List<bool> { false, false, false, false, false, false, false, true } }, | |
{ "0x90000", new List<bool> { false, false, false, false, true, false, false, true } }, | |
{ "0xA0000", new List<bool> { false, false, false, false, false, true, false, true } }, | |
{ "0xB0000", new List<bool> { false, false, false, false, true, true, false, true } }, | |
{ "0xC0000", new List<bool> { false, false, false, false, false, false, true, true } }, | |
{ "0xD0000", new List<bool> { false, false, false, false, true, false, true, true } }, | |
{ "0xE0000", new List<bool> { false, false, false, false, false, true, true, true } }, | |
{ "0xF0000", new List<bool> { false, false, false, false, true, true, true, true } }, | |
{ "0xF000F", new List<bool> { true, true, true, true, true, true, true, true } }, | |
}; | |
foreach(var test in testCases) | |
{ | |
var parsedInt = Convert.ToInt32(test.Key, 16); | |
var testThrottledStatus = new ThrottledStatus(parsedInt); | |
if (test.Value[0] != testThrottledStatus.UnderVoltageDetected || | |
test.Value[1] != testThrottledStatus.ArmFrequencyCapped || | |
test.Value[2] != testThrottledStatus.CurrentlyThrottled || | |
test.Value[3] != testThrottledStatus.SoftTempLimitActive || | |
test.Value[4] != testThrottledStatus.UnderVoltageHasOccured || | |
test.Value[5] != testThrottledStatus.ArmFrequencyCappingHasOccured || | |
test.Value[6] != testThrottledStatus.ThrottlingHasOccured || | |
test.Value[7] != testThrottledStatus.SoftTempLimitHasOccured) { | |
throw new Exception("Something brokey"); | |
} | |
} | |
} | |
} | |
public class ThrottledStatus | |
{ | |
public bool UnderVoltageDetected { get; } | |
public bool ArmFrequencyCapped { get; } | |
public bool CurrentlyThrottled { get; } | |
public bool SoftTempLimitActive { get; } | |
public bool UnderVoltageHasOccured { get; } | |
public bool ArmFrequencyCappingHasOccured { get; } | |
public bool ThrottlingHasOccured { get; } | |
public bool SoftTempLimitHasOccured { get; } | |
public ThrottledStatus(int data) | |
{ | |
var bitArray = new BitArray(new int[] { data }); | |
UnderVoltageDetected = bitArray[0]; | |
ArmFrequencyCapped = bitArray[1]; | |
CurrentlyThrottled = bitArray[2]; | |
SoftTempLimitActive = bitArray[3]; | |
UnderVoltageHasOccured = bitArray[16]; | |
ArmFrequencyCappingHasOccured = bitArray[17]; | |
ThrottlingHasOccured = bitArray[18]; | |
SoftTempLimitHasOccured = bitArray[19]; | |
} | |
public override string ToString() | |
{ | |
var output = new List<string>(); | |
if (UnderVoltageDetected) output.Add("UnderVoltageDetected"); | |
if (ArmFrequencyCapped) output.Add("ArmFrequencyCapped"); | |
if (CurrentlyThrottled) output.Add("CurrentlyThrottled"); | |
if (SoftTempLimitActive) output.Add("SoftTempLimitActive"); | |
if (UnderVoltageHasOccured) output.Add("UnderVoltageHasOccured"); | |
if (ArmFrequencyCappingHasOccured) output.Add("ArmFrequencyCappingHasOccured"); | |
if (ThrottlingHasOccured) output.Add("ThrottlingHasOccured"); | |
if (SoftTempLimitHasOccured) output.Add("SoftTempLimitHasOccured"); | |
return string.Join("\n", output); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment