| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- def decode_psu_status(hex_input):
- """
- PSU Decoder by Parv Ashwani
- ---------------------------
- Decodes a PSU status hex value into human-readable descriptions
- based on standard IPMI bitmask definitions.
- """
- bitmask_definitions = {
- 1: "Presence Detected",
- 2: "Failure Detected",
- 4: "Predictive Failure",
- 8: "Input Lost",
- 16: "Out of Range",
- 32: "Detected Out of Range",
- 64: "Configuration Error",
- 128: "Reserved"
- }
- print("\n" + "="*50)
- print(f"DECODING INPUT: {hex_input}")
- print("="*50)
- try:
- decimal_value = int(hex_input, 16)
- except ValueError:
- print("Error: Invalid hex input.")
- return
- print(f"\n[Step 1] Hex to Decimal Conversion:")
- print(f" Hex '{hex_input}' --> Decimal {decimal_value}")
- active_flags = []
- math_parts = []
- print(f"\n[Step 2] Bitwise Analysis (Checking switches):")
- for bit_value, description in sorted(bitmask_definitions.items(), reverse=True):
- if (decimal_value & bit_value) == bit_value:
- status = "ON"
- active_flags.append(description)
- math_parts.append(str(bit_value))
- print(f" - Checking Bit {bit_value:>3}: {status} --> Found: {description}")
- else:
- # Optional: Uncomment below line to see checks that failed
- # print(f" - Checking Bit {bit_value:>3}: OFF")
- pass
- print(f"\n[Step 3] Calculation Explanation:")
- if math_parts:
- equation = " + ".join(math_parts)
- print(f" Math: {equation} = {decimal_value}")
- else:
- print(" No active flags found (Value is 0).")
- print(f"\n[RESULT]:")
- if active_flags:
- for flag in active_flags:
- print(f" >> {flag}")
- else:
- print(" >> No active status flags.")
- # ==========================================
- # MAIN LOOP
- # ==========================================
- if __name__ == "__main__":
- print("--- PSU Status Decoder Tool ---")
- while True:
- user_input = input("\nEnter Hex value (e.g., 0xb) or 'q' to quit: ").strip()
- if user_input.lower() == 'q':
- print("Exiting...")
- print("Made with ☕︎ by Parv")
- break
- if user_input:
- decode_psu_status(user_input)
|