27 lines
1.1 KiB
Python
27 lines
1.1 KiB
Python
import argparse
|
|
from encdec8b10b import EncDec8B10B
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description='8b/10b Encoder/Decoder')
|
|
parser.add_argument('-m', '--mode', choices=['encode', 'decode'], required=True, help='Mode: encode or decode')
|
|
parser.add_argument('-i', '--input', required=True, help='Input data to encode or decode (in hex format)')
|
|
parser.add_argument('-c', '--ctrl', type=int, default=0, help='Control character (0 or 1)')
|
|
args = parser.parse_args()
|
|
|
|
input_data = int(args.input, 16) # 将输入数据从十六进制字符串转换为整数
|
|
running_disp = 0 # 假设初始运行差分为0
|
|
|
|
if args.mode == 'encode':
|
|
running_disp, encoded = EncDec8B10B.enc_8b10b(input_data, running_disp, args.ctrl)
|
|
print(f'Encoded: {encoded:02x}')
|
|
elif args.mode == 'decode':
|
|
try:
|
|
decoded = EncDec8B10B.dec_8b10b(input_data)
|
|
print(f'Decoded: {decoded[0]:02x}') # 假设 decoded 是一个包含多个值的元组
|
|
except ValueError as e:
|
|
print(f'Error decoding: {e}')
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
|