#!/usr/bin/env python3 """ The R10 status read command returns an integer, which needs to be interpreted bitwise for various status flags. This script prints out these status flags in human-readable formatting. To read the manual, simply run this script without any arguments. Stefan Mathis, December 2024 """ import platform from decodeCommon import interactive, decode, print_decoded # List of tuples which encodes the states given in the file description. # Index first with the bit index, then with the bit value interpretation = [ ("Not ready to be switched on", "Ready to be switched on"), # Bit 0 ("Not switched on", "Switched on"), # Bit 1 ("Disabled", "Enabled"), # Bit 2 ("Ok", "Fault condition set"), # Bit 3 ("Motor supply voltage absent ", "Motor supply voltage present"), # Bit 4 ("Motor performs quick stop", "Ok"), # Bit 5 ("Switch on enabled", "Switch on disabled"), # Bit 6 ("Ok", "Warning: Movement function was called while motor is still moving. The function call is ignored"), # Bit 7 ("Not specified", "Not specified"), # Bit 8 ("Motor does not execute command messages (local mode)", "Motor does execute command messages (remote mode)"), # Bit 9 ("Target not reached", "Target reached"), # Bit 10 ("Ok", "Internal limit active (current, voltage, velocity or position)"), # Bit 11 ("Not specified", "Not specified"), # Bit 12 ("Not specified", "Not specified"), # Bit 13 ("Not specified", "Not specified"), # Bit 14 ("Not specified", "Not specified"), # Bit 15 ] help = """ Decode R10 message of MasterMACs ------------------ MasterMACs returns its status message (R10) as a floating-point number. The bits of this float encode different states. These states are stored in the interpretation variable. This script can be used in two different ways: Option 1: Single Command ------------------------ Usage: decodeStatus.py value 'value' is the return value of a R10 command. This value is interpreted bit-wise and the result is printed out. Option 2: CLI Mode (Linux-only) ------------------------------- Usage: decodeStatus.py ONLY AVAILABLE ON LINUX! A prompt will be opened. Type in the return value of a R10 command, hit enter and the interpretation will be printed in the prompt. After that, the next value can be typed in. Type 'quit' to close the prompt. """ if __name__ == "__main__": from sys import argv if "-h" or "--help" in argv: print(help) if len(argv) == 1: # Start interactive mode if platform.system() == "Linux": interactive() else: print(help) else: number = None try: number = int(float(argv[1])) except: print(help) if number is not None: print("Motor status") print("============") (bit_list, interpreted) = decode(number, interpretation) print_decoded(bit_list, interpreted)