|
12 | 12 | import serial.tools.list_ports |
13 | 13 | import threading |
14 | 14 | import struct |
| 15 | +from enum import Enum |
15 | 16 | from multiprocessing import Pool, cpu_count |
16 | 17 | from typing import Union |
17 | 18 | from pathlib import Path |
@@ -754,6 +755,88 @@ def on_exec(self, args: argparse.Namespace): |
754 | 755 | print(f' - Chameleon {model}, Version: {fw_version} ({git_version})') |
755 | 756 |
|
756 | 757 |
|
| 758 | +@hf_14a.command('config') |
| 759 | +class HF14AConfig(DeviceRequiredUnit): |
| 760 | + class Config(Enum): |
| 761 | + def __new__(cls, value, desc): |
| 762 | + obj = object.__new__(cls) |
| 763 | + obj._value_ = value |
| 764 | + obj.desc = desc |
| 765 | + return obj |
| 766 | + |
| 767 | + @classmethod |
| 768 | + def choices(cls): |
| 769 | + return [elem.name for elem in cls] |
| 770 | + |
| 771 | + @classmethod |
| 772 | + def format(cls, index): |
| 773 | + item = cls(index) |
| 774 | + color = CG if index == 0 else CR |
| 775 | + return f' - {cls.__name__.upper()} override: {color_string((color, item.name))} ( {item.desc} )' |
| 776 | + |
| 777 | + @classmethod |
| 778 | + def help(cls): |
| 779 | + return ' / '.join([f'{elem.desc}' for elem in cls]) |
| 780 | + |
| 781 | + class Bcc(Config): |
| 782 | + std = (0, "follow standard") |
| 783 | + fix = (1, "fix bad BCC") |
| 784 | + ignore = (2, "ignore bad BCC, always use card BCC") |
| 785 | + |
| 786 | + class Cl2(Config): |
| 787 | + std = (0, "follow standard") |
| 788 | + force = (1, "always do CL2") |
| 789 | + skip = (2, "always skip CL2") |
| 790 | + |
| 791 | + class Cl3(Config): |
| 792 | + std = (0, "follow standard") |
| 793 | + force = (1, "always do CL3") |
| 794 | + skip = (2, "always skip CL3") |
| 795 | + |
| 796 | + class Rats(Config): |
| 797 | + std = (0, "follow standard") |
| 798 | + force = (1, "always do RATS") |
| 799 | + skip = (2, "always skip RATS") |
| 800 | + |
| 801 | + def args_parser(self) -> ArgumentParserNoExit: |
| 802 | + parser = ArgumentParserNoExit() |
| 803 | + parser.description = 'Configure 14a settings (use with caution)' |
| 804 | + parser.add_argument('--std', action='store_true', help='Reset default configuration (follow standard)') |
| 805 | + parser.add_argument('--bcc', type=str, choices=self.Bcc.choices(), help=self.Bcc.help()) |
| 806 | + parser.add_argument('--cl2', type=str, choices=self.Cl2.choices(), help=self.Cl2.help()) |
| 807 | + parser.add_argument('--cl3', type=str, choices=self.Cl3.choices(), help=self.Cl3.help()) |
| 808 | + parser.add_argument('--rats', type=str, choices=self.Rats.choices(), help=self.Rats.help()) |
| 809 | + return parser |
| 810 | + |
| 811 | + def on_exec(self, args: argparse.Namespace): |
| 812 | + change_requested = False |
| 813 | + if args.std: |
| 814 | + config = {'bcc': 0, 'cl2': 0, 'cl3': 0, 'rats': 0} |
| 815 | + change_requested = True |
| 816 | + else: |
| 817 | + config = self.cmd.hf14a_get_config() |
| 818 | + if args.bcc: |
| 819 | + config['bcc'] = self.Bcc[args.bcc].value |
| 820 | + change_requested = True |
| 821 | + if args.cl2: |
| 822 | + config['cl2'] = self.Cl2[args.cl2].value |
| 823 | + change_requested = True |
| 824 | + if args.cl3: |
| 825 | + config['cl3'] = self.Cl3[args.cl3].value |
| 826 | + change_requested = True |
| 827 | + if args.rats: |
| 828 | + config['rats'] = self.Rats[args.rats].value |
| 829 | + change_requested = True |
| 830 | + if change_requested: |
| 831 | + self.cmd.hf14a_set_config(config) |
| 832 | + config = self.cmd.hf14a_get_config() |
| 833 | + print('HF 14a config') |
| 834 | + print(self.Bcc.format(config['bcc'])) |
| 835 | + print(self.Cl2.format(config['cl2'])) |
| 836 | + print(self.Cl3.format(config['cl3'])) |
| 837 | + print(self.Rats.format(config['rats'])) |
| 838 | + |
| 839 | + |
757 | 840 | @hf_14a.command('scan') |
758 | 841 | class HF14AScan(ReaderRequiredUnit): |
759 | 842 | def args_parser(self) -> ArgumentParserNoExit: |
|
0 commit comments