# WARNING: ALL REGISTER IN THE DOCUMENTATION ARE SHIFTED BY ONE (NUMERATION STARTS BY ONE)
registers = {
    "Instrument type": [1 - 1, {"dt": "16bit_uint", }],
    "Test counter: FAILED": [2 - 1, {"dt": "32bit_uint", }],
    "Test counter: TOTAL TESTS": [4 - 1, {"dt": "32bit_uint", }],
    "Life counter: FAILED": [6 - 1, {"dt": "32bit_uint", }],
    "Life counter: TOTAL TESTS": [8 - 1, {"dt": "32bit_uint", }],
    "Real time test pressure output": [11 - 1, {"dt": "32bit_int", "f": 1501, }],
    "Real time differential pressure output": [13 - 1, {"dt": "32bit_int", "f": 1503, }],
    "Real time pressure line regulator": [15 - 1, {"dt": "16bit_int", "f": 1511}],
    "Active alarm flags": [16 - 1, {"dt": "16bit_uint", }],
    # | 15 | 14 | 13 | 12 | 11 | 10 |  9 |  8 |  7 |  6 |  5 |  4 |  3 |  2 |  1 |  0 |
    # |    |    |    |    |    |    | EA | E9 | E8 |    | E6 | E5 | E4 | E3 | E2 | E1 |
    # E1: Test program error
    # E2: Setting parameters memory error
    # E3: Sensor calibration memory error
    # E4: Emergency
    # E5: I2c bus
    # E6: Flow sensor
    # E8: A/D_FS points
    # E9: Sensor comm. Ch1
    # EA: Sensor comm. Ch2
    "Active not severe alarm flags": [21 - 1, {"dt": "16bit_uint", }],
    # | 15 | 14 | 13 | 12 | 11 | 10 |  9 |  8 |  7 |  6 |  5 |  4 |  3 |  2 |  1 |  0 |
    # |    |    |    |    |    |    |    |    | A8 | A7 | A6 | A5 | A4 | A3 | A2 | A1 |
    # A1: Discharge alarm (ch 1 for 2 channel model)
    # A2: Discharge alarm (ch 2 for 2 channel model)
    # A3: Acknowledgment
    # A4: Cage closing automation alarm
    # A5: Cage opening automation alarm
    # A6: Plug closing automation alarm
    # A7: Plug opening automation alarm
    # A8: I2C no stop
    "Running test: relative pressure scale": [1501 - 1, {"dt": "16bit_uint", }],  # red
    "Running test: relative pressure decimals": [1502 - 1, {"dt": "16bit_uint", }],  # red
    "Running test: differential pressure scale": [1503 - 1, {"dt": "16bit_uint", }],  # purple
    "Running test: differential pressure decimals": [1504 - 1, {"dt": "16bit_uint", }],  # purple
    "Running test: relative pressure scale (low resolution)": [1505 - 1, {"dt": "16bit_uint", }],  # yellow
    "Running test: relative pressure decimals (low resolution)": [1506 - 1, {"dt": "16bit_uint", }],  # yellow
    "Running test: calculated leak flow rate format": [1507 - 1, {"dt": "16bit_uint", }],  # blue
    "Running test: volume format": [1508 - 1, {"dt": "16bit_uint", }],  # green
    "Running test: time format": [1509 - 1, {"dt": "16bit_uint", }],  # orange
    "Running test: flow rate format": [1510 - 1, {"dt": "16bit_uint", }],  # white
    "Running test: line pressure format": [1511 - 1, {"dt": "16bit_uint", }],  # lp
    # 1531-1540 last test values formats ----- add if needed
    "Active test program number": [31 - 1, {"dt": "16bit_uint", }],
    "Running test: active phase": [32 - 1, {"dt": "16bit_uint", "decoding": {
        0: "ATTESA START",  # "WAITING START",
        10: "CONTROLLO BARCODE",  # "CHECK BARCODE",
        20: "ATTESA BARCODE",  # "WAITING BARCODE",
        30: "START TEST",
        35: "MOVE TABLE START",
        40: "START CAGE",
        50: "START PLUG",
        60: "START SEQUENCE PROGRAM",
        70: "WAIT DELAY ACKNOWLEDGE COMMAND",
        80: "WAIT DELAY",
        90: "WAIT ACKNOWLEDGE",
        100: "T0 PRE-RIEMPIMENTO",  # "T0 PRE-FILL",
        110: "T1 RIEMPIMENTO",  # "T1 FILLING",
        120: "T2 ASSESTAMENTO",  # "T2 SETTLING",
        130: "T3 MISURA",  # "T3 MEASURE",
        140: "WAITING OPERATOR RESULT ACKNOWLEDGE",
        150: "RESULT PRESENT",
        160: "MARKING",
        170: "DISCHARGE",
        180: "END SEQUENCE PROGRAM",
        181: "SEQUENCE DELAY",
        182: "PREPARE SEQUENCE PROGRAM",
        190: "END PLUG",
        200: "END CAGE",
        205: "MOVE TABLE END",
        210: "FINE TEST",  # "END TEST, WAITING THE START OF A NEW TEST",
    }, }],
    "Running test: phase backwards time": [33 - 1, {"dt": "16bit_uint", "f": 1509, }],
    "Running test: filling pressure": [34 - 1, {"dt": "32bit_int", "f": 1501, }],
    "Running test: pressure at the end of settling": [36 - 1, {"dt": "32bit_int", "f": 1501, }],
    "Running test: burst pressure": [38 - 1, {"dt": "32bit_int", "f": 1501, }],
    "Running test: measured leak": [40 - 1, {"dt": "32bit_int", "f": 1503, }],
    "Running test: calculated leak flow rate": [42 - 1, {"dt": "32bit_int", "f": 1507, }],
    "Running test: calculate RVP%": [44 - 1, {"dt": "32bit_int", }],
    "Running test: result": [46 - 1, {"dt": "16bit_uint", "decoding": {
        1: "LEAK TEST PASSED (also used in Volume+Leak tests)",
        2: "BURST TEST PASSED WITH BURST",
        3: "BURST TEST PASSED WITHOUT BURST",
        4: "APERTURE TEST PASSED",
        5: "BLOCKAGE TEST PASSED",
        6: "FLOW TEST PASSED",
        7: "LEAK with FLOW TEST PASSED",
        99: "PRODUCT PASSED",
        # 100: "LEAK TEST FAILED (T3D: Maximum leak in test port, T3P: Upper limit error with negative Q+ parameter)",
        100: "LEAK TEST FAILED (Upper limit error with negative Q+ parameter)",
        # 101: "LEAK TEST FAILED (only in T3P: Upper limit with positive Q+ parameter)",
        101: "LEAK TEST FAILED (Upper limit with positive Q+ parameter)",
        # 102: "LEAK TEST FAILED (T3D: Maximum leak in reference port, T3P: Maximum leak)",
        102: "LEAK TEST FAILED (Maximum leak)",
        103: "BURST TEST FAILED (Burst pressure under the minimum)",
        104: "VOLUME TEST FAILED (Maximum RVP tolerance)",
        105: "APERTURE TEST FAILED - MINIMUM (not used)",
        106: "APERTURE TEST FAILED - MAXIMUM (not used)",
        107: "BLOCKAGE TEST FAILED (Maximum pressure)",
        108: "BLOCKAGE TEST FAILED (Minimum pressure)",
        109: "BURST TEST FAILED (Minimum test pressure not reach)",
        110: "FLOW TEST - PRESSURE FAIL - (Pressure out of programmed tolerance)",
        111: "FLOW TEST - FLOW FAIL - (Flow out of programmed tolerance)",
        112: "FAILED - LEAKAGE MAX",
        113: "FAILED - LEAKAGE MIN",
        115: "FAILED MIN CH1",
        116: "FAILED ANOMALY CH2",
        117: "FAILED MIN CH2",
        118: "FAILED BOTH CHANNELS",
        119: "FAILED FLOW MAX",
        120: "FAILED FLOW MIN",
        121: "FAILED PEAK MAX",
        122: "FAILED PEAK MIN",
        123: "(FAILED, SERVICE ONLY)",
        199: "FAILED PRODUCT",
        200: "FAIL T1/T2 PRESSURE UNDER TOLERANCE",
        201: "FAIL T1/T2 PRESSURE OVER TOLERANCE",
        202: "FAIL BLOCKAGE START PRESSURE UNDER TOLERANCE",
        203: "FAIL BLOCKAGE START PRESSURE OVER TOLERANCE",
        204: "FAIL WITH ALARM",
        205: "FAIL RELATIVE PRESSURE OVER SCALE",
        206: "FAIL DIFFERENTIAL PRESSURE OVER SCALE",
        207: "FAIL PRE-FILL VALVE NOT OPENED",
        208: "FAIL INVALID PROGRAM PARAMETERS",
        209: "FAIL CONFIGURATION PARAMETERS",
        210: "FAIL ALL CALIBRATION",
        211: "FAIL I2C COMMUNICATION",
        212: "FAIL EMERGENCY",
        213: "FAIL BYPASS VALVE NOT OPEN",
        214: "FAIL FLOW OUT OF RANGE",
        215: "FAIL FLOW SENSOR ALARM",
        216: "FAIL AD SPI ALARM",
        217: "FAIL (SERVICE ONLY)",
        250: "TEST ABORTED",
    }, }],
    "Running test: test type": [47 - 1, {"dt": "16bit_uint", "decoding": {
        1: "LEAK",
        2: "BLOCKAGE",
        3: "LEAK + VOLUME CHECK",
        4: "BURST",
        5: "APERTURE (SERVICE ONLY)",
        6: "FLOW RATE",
        7: "LEAK + FLOW",
    }, }],
    "Running test: sequence index": [48 - 1, {"dt": "16bit_uint", }],
    "PRESSURE PLOT: Sampling frequency in 1/10 s": [49 - 1, {"dt": "16bit_uint", }],
    "PRESSURE PLOT: Number of available sampling": [50 - 1, {"dt": "16bit_uint", }],
    # Note: plot values are available from Modbus register 2001 to 8000 as signed 32 bit values. ----- add if needed
    # 81-86 real time clock ----- add if needed
    # 64-80 87-92 last test values ----- add if needed
    # ------------------------- COMMANDS -------------------------
    "Digital inputs status (mask)": [93 - 1, {"dt": "16bit_uint", }],
    # Bits mask: 1=active 0=not active
    "Digital outputs status (mask)": [94 - 1, {"dt": "16bit_uint", }],
    # Bits mask: 1=active 0=not active
    "Start test": [101 - 1, {"dt": "16bit_uint", }],
    # Write 0 to start the selected program
    # Write a different number from 1 to n max programs to start a specific program.
    "Reset running test": [102 - 1, {"dt": "16bit_uint", }],
    "Activate specific digital output": [103 - 1, {"dt": "16bit_uint", "o": 1, }],
    # Write the number from 1 to 16 of the digital output to activate (must be set as Free in Settings)
    "Reset specific digital output": [104 - 1, {"dt": "16bit_uint", "o": 1, }],
    # Write the number from 1 to 16 of the digital output to reset (must be set as Free in Settings)
    "Activate digital output (bit mask)": [105 - 1, {"dt": "16bit_uint", }],
    # Write 1 in the bit corresponding to the output to be activated
    "Reset digital output (bit mask)": [106 - 1, {"dt": "16bit_uint", }],
    # Write 1 in the bit corresponding to the output to be deactivated
    "Reset test counter": [107 - 1, {"dt": "16bit_uint", }],
    # Write any U16 number to reset tests counters
    # ------------------------------------------------------------
    "Max number of programs": [20042 - 1, {"dt": "16bit_uint", }],
    "Language": [601 - 1, {"dt": "16bit_uint", "encoding": {
        "ITALIAN": 0,
        "ENGLISH": 1,
        "FRENCH": 2,
        "SIMPLIFIED CHINESE": 3,
        "SPANISH": 4,
        "NOT AVAILABLE": 5,
        "GERMAN": 6,
        "JAPANESE": 7,
    }, "decoding": {
        0: "ITALIAN",
        1: "ENGLISH",
        2: "FRENCH",
        3: "SIMPLIFIED CHINESE",
        4: "SPANISH",
        5: "NOT AVAILABLE",
        6: "GERMAN",
        7: "JAPANESE",
    }, }],
    "Source of test program number selection": [602 - 1, {"dt": "16bit_uint", "encoding": {
        "FROM PARAMETER (SET BY LCD OR SERIAL LINE)": 0,
        "BCD BASE 1, FROM DIGITAL INPUTS (PLC INTERFACE)": 1,
        "BCD BASE 0, FROM DIGITAL INPUTS (PLC INTERFACE)": 2,
    }, "decoding": {
        0: "FROM PARAMETER (SET BY LCD OR SERIAL LINE)",
        1: "BCD BASE 1, FROM DIGITAL INPUTS (PLC INTERFACE)",
        2: "BCD BASE 0, FROM DIGITAL INPUTS (PLC INTERFACE)",
    }, }],
    "Selected program": [603 - 1, {"dt": "16bit_uint", }],
    # 1-n max programs
    "Use programs or use products": [604 - 1, {"dt": "16bit_uint", }],
    # 0: the Start command will run the active program (see reg. 101 to set the program number)
    # 1: the Start command will run the active product (see reg. 101 to set the product number)
    "Flag: Instrument settings": [605 - 1, {"dt": "16bit_uint", }],
    # | 15 | 14 | 13 | 12 | 11 | 10 |  9 |  8 |  7 |  6     |  5 |  4 |  3 |  2 |  1 |  0 |
    # |    |    |    |    |    |    |    |    |    | PID NR | QE | RF | RP |    | DM | SB |
    # Bit 0: 1= Start button
    # Bit 1: 1= Demo mode
    # Bit 3: 1= Reset if test passed
    # Bit 4: 1= Reset if test failed
    # Bit 5: 1= QLP Extra digit activated
    # Bit 6: 1= Leak in pressure per second
    # Bit 7: 1= Leak in flow rate unit
    "MEASURE UNITS: Relative pressure": [606 - 1, {"dt": "16bit_uint", }],
    # 0=mH2O 1=mbar 2=kPa 3=mmHg 4=inH2O 5=psi 6=mmH2O
    "MEASURE UNITS: Differential (leak) pressure": [607 - 1, {"dt": "16bit_uint", }],
    # 0=mmH2O 1=mbar 2=Pa 3=mmHg 4=inH2O 5=psi
    "MEASURE UNITS: Calculated leak flow rate": [608 - 1, {"dt": "16bit_uint", }],
    # 0=cm3/min 1=cm3/h
    "MEASURE UNITS: Volume": [609 - 1, {"dt": "16bit_uint", }],
    # 0=litre 1=cm3
    "MEASURE UNITS: Flow rate": [617 - 1, {"dt": "16bit_uint", }],
    # 0=liters/min 1=liters/h 2=m3/h
    "Cage automation: closing time": [618 - 1, {"dt": "16bit_uint", "g": 10, }],
    # Format: x.x seconds
    "Cage automation: opening time": [619 - 1, {"dt": "16bit_uint", "g": 10, }],
    # Format: x.x seconds
    "Maximum pressure limit": [620 - 1, {"dt": "16bit_uint", "f": 1505, }],
    "Plug automation: closing time": [621 - 1, {"dt": "16bit_uint", "g": 10, }],
    # Format: x.x seconds
    "Plug automation: opening time": [622 - 1, {"dt": "16bit_uint", "g": 10, }],
    # Format: x.x seconds
    "Marker: result based driving": [623 - 1, {"dt": "16bit_uint", }],
    # 0=Only passed
    # 1=Only failed
    # 2=All
    "Marker: driving time": [624 - 1, {"dt": "16bit_uint", "g": 10, }],
    # Format: x.x seconds
    "PASSWORD: Administration": [631 - 1, {"dt": "32bit_uint"}],
    # 1 - 999999
    "PASSWORD: Modify program": [633 - 1, {"dt": "32bit_uint"}],
    # 1 - 999999
    "PASSWORD: Select program": [635 - 1, {"dt": "32bit_uint"}],
    # 1 - 999999
    "Test program for read/write operation": [700 - 1, {"dt": "16bit_uint", }],
    # 1- n max programs
    "Test type": [701 - 1, {"dt": "16bit_uint", "encoding": {
        "Leak Test": 1,
        "Blockage": 2,
        "Volume+Leak": 3,
        "Burst": 4,
        "Aperture": 5,
        # "Flow (T3PF)": 6,
        "Flow": 6,
        # "Leak with Flow (T3PF)": 7,
        "Leak with Flow": 7,
    }, "decoding": {
        1: "Leak Test",
        2: "Blockage",
        3: "Volume+Leak",
        4: "Burst",
        5: "Aperture",
        # 6: "Flow (T3PF)",
        6: "Flow",
        # 7: "Leak with Flow (T3PF)",
        7: "Leak with Flow",
    }, }],
    "Test flags": [702 - 1, {"dt": "16bit_uint", }],
    # | 15 | 14 | 13 | 12 | 11 | 10 |   9 |   8 |  7 6 5 4 |    3 |   2 |     1 |     0 |
    # | CX | HR | AT | Q- | Q+ |  B | Pr- | P0- | PID MODE | T3/Q |     | T1/Pr | T0/Pr |
    # T0/Pr: Filling mode 0=TIME 1=PRESSURE (*)
    # T1/Pr: Filling mode 0=TIME 1=PRESSURE (*)
    # T1/Pr (T3LPQ) = 0 - 250 (seconds)
    # T3/Q: Fail mode 0=TIME 1=PRESSURE (*)
    # PID MODE: 0=FAST 1=MEDIUM 2=SLOW 4 = FIXED 5 = AUTOMATIC 6 = FLOW 7 = LEAK WITH
    # -----
    # FLOW
    # P0-: 0= P0 pre-filling pressure is positive 1=P0 pre-filling pressure is negative (vacuum)
    # Pr-: 0= Pr filling pressure is positive 1=Pr filling pressure is negative (vacuum)
    # B: = beep (not used)
    # Q+: Negative Q+ parameter
    # Q-: Negative Q- parameter
    # AT: Pressure tare
    # HR: Enable pressure high resolution (depends on the model) (QLP / QHD)(*)
    # CX: Test channel - Select used channel (in two channels models in T3P2C)
    # (*) = not available on T3LPQ model
    "T0 - Pre-filling time": [704 - 1, {"dt": "16bit_uint", "f": 1509, }],
    "P0 - Pre-filling pressure": [705 - 1, {"dt": "16bit_uint", "f": 1505, }],
    # To set a negative pressure (vacuum) this parameters must be written in absolute value and then set bit P0- in register 702
    "T1 - Filling time": [706 - 1, {"dt": "16bit_uint", "f": 1509, }],
    "T2 - Settling time": [707 - 1, {"dt": "16bit_uint", "f": 1509, }],
    "T3 - Measure time": [708 - 1, {"dt": "16bit_uint", "f": 1509, }],
    "PREL - Nominal test pressure": [709 - 1, {"dt": "16bit_uint", "f": 1505, }],
    # To set a negative pressure (vacuum) this parameters must be written in absolute value and then set bit Pr- in register 702
    "PR- - Min pressure tolerance %": [710 - 1, {"dt": "16bit_uint", "g": 10, }],
    # Format: x.x %
    # NOTE: In blockage test minimum final pressure (format as indicated in register 1505)
    "Q+ Upper test leak limit": [711 - 1, {"dt": "16bit_uint", "f": 1503, }],
    "Q- Lower test leak limit": [712 - 1, {"dt": "16bit_uint", "f": 1503, }],
    "FST - Discharge time": [713 - 1, {"dt": "16bit_uint", "f": 1509, }],
    "CV - Volumetric coefficient": [714 - 1, {"dt": "16bit_uint", "f": 1508, }],
    "P% Pressure tol. (blockage test)": [717 - 1, {"dt": "16bit_uint", "g": 10, }],
    "Nominal peak pressure": [718 - 1, {"dt": "16bit_uint", "f": 1505, }],
    # Format: x.x %
    "Print options": [739 - 1, {"dt": "16bit_uint", }],
    # | 15 14 13 12 | 11 10  9  8 |  7  6  5  4  3  2  1  0 |
    # |         STN |         STS |                     STM |
    # STN: print copies
    # STS: print failed test 0=NO 1=YES
    # STM: printer template
    "AW: Aperture weight time (AT)": [740 - 1, {"dt": "16bit_uint", }],
    "AN: Aperture number": [741 - 1, {"dt": "16bit_uint", }],
    # Format x
    "Pn - Nominal test pressure": [742 - 1, {"dt": "16bit_uint", "f": 1505, }],
    "PB - Burst pressure": [743 - 1, {"dt": "16bit_uint", "f": 1505, }],
    "BD - Burst drop / PD - Delta Aperture": [744 - 1, {"dt": "16bit_uint", "f": 1505, }],
    "FSL - Discharge limit": [745 - 1, {"dt": "16bit_uint", "f": 1505, }],
    "PID: pressure correction": [746 - 1, {"dt": "16bit_uint", "g": 100, }],
    # Offset electronic regulator Format: xx.xx%
    "PR+ - Max pressure tolerance % (P+)": [747 - 1, {"dt": "16bit_uint", "g": 10, }],
    # Format: x.x %
    # NOTE: In blockage test maximum final pressure (format as indicated in register 1505)
    "AV1: Advanced valve time": [748 - 1, {"dt": "16bit_uint", "g": 10, }],
    # Format: x.x seconds
    "AV2: Advanced valve time": [749 - 1, {"dt": "16bit_uint", "g": 10, }],
    # Format: x.x seconds
    "RVP%: volumetric ratio": [750 - 1, {"dt": "16bit_uint", "g": 100, }],
    # Format: x.xx (Range from 100.00 to 649.99)
    "RVP%: max tolerance": [751 - 1, {"dt": "16bit_uint", "g": 100, }],
    # Format: x.xx (Range from 0.10 to 50.00)
    "T0 Steps - T0 Step %": [752 - 1, {"dt": "16bit_uint", }],
    # | 15 14 13 12 11 10  9  8 |  7  6  5  4  3  2  1  0 |
    # |               Step % T0 |                T0 Steps |
    "T1 Steps - T1 Step %": [753 - 1, {"dt": "16bit_uint", }],
    # | 15 14 13 12 11 10  9  8 |  7  6  5  4  3  2  1  0 |
    # |               Step % T1 |                T1 Steps |
    "Sequence": [754 - 1, {"dt": "16bit_uint", }],
}
