Add Readme

This commit is contained in:
xinb 2024-08-15 22:31:20 +08:00
parent 3906d70243
commit 1e22280b02
2 changed files with 32 additions and 7 deletions

View File

@ -1,5 +1,10 @@
[![Build Status](https://travis-ci.com/olagrottvik/encdec8b10b.svg?token=jVu3gMDvjaqfNCVgNVai&branch=master)](https://travis-ci.com/olagrottvik/encdec8b10b)
# 运行
运行工具: 运行你的命令行工具时,输入数据需要以十六进制格式提供,并且可以指定控制字符:
```bash
python main.py -m encode -i "16A" -c 1
python main.py -m decode -i "16A"
```
# encdec8b10b
Encode and decode 8B10B encoding
@ -80,9 +85,3 @@ Output >> Decoded: A0 - Control: 0
- [Original article](https://ieeexplore.ieee.org/document/5390392)
- [Wikipedia](https://en.wikipedia.org/wiki/8b/10b_encoding)
### Thanks
- [Ryu Shinhyung](https://opencores.org/projects/async_8b10b_encoder_decoder) for creating the tables used in this module
- [Chuck Benz](http://asics.chuckbenz.com/) for creating awesome combinational 8B10B modules
- [Alex Forencich](http://www.alexforencich.com/wiki/en/scripts/matlab/enc8b10b) for his 8B10B Matlab script

26
main.py Normal file
View File

@ -0,0 +1,26 @@
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()