solax-py-library 1.0.0.2515__py3-none-any.whl → 1.0.0.2516__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,15 +3,15 @@ import struct
3
3
  from typing import List
4
4
 
5
5
  format_map = {
6
- "int8": "bb",
7
- "uint8": "BB",
8
- "int16": "h",
9
- "uint16": "H",
10
- "int32": "i",
11
- "uint32": "I",
12
- "int64": "q",
13
- "uint64": "Q",
14
- "float": "f",
6
+ "int8": {"format_str": "bb", "length": 1},
7
+ "uint8": {"format_str": "BB", "length": 1},
8
+ "int16": {"format_str": "h", "length": 1},
9
+ "uint16": {"format_str": "H", "length": 1},
10
+ "int32": {"format_str": "i", "length": 2},
11
+ "uint32": {"format_str": "I", "length": 2},
12
+ "int64": {"format_str": "q", "length": 4},
13
+ "uint64": {"format_str": "Q", "length": 4},
14
+ "float": {"format_str": "f", "length": 1},
15
15
  }
16
16
 
17
17
 
@@ -27,25 +27,16 @@ def unpack(data: List, data_format, reversed=False):
27
27
  raise Exception("暂不支持")
28
28
  pack_str = ("<" if reversed else ">") + "H" * len(cur_data)
29
29
  to_pack_data = struct.pack(pack_str, *cur_data)
30
- struct_format = ("<" if reversed else ">") + format_map[data_format]
30
+ struct_format = ("<" if reversed else ">") + format_map[data_format]["format_str"]
31
31
  return struct.unpack(struct_format, to_pack_data)
32
32
 
33
33
 
34
- def struct_transform(value, fmt, order="big"):
34
+ def pack(value, fmt, order="big"):
35
35
  """将10进制的原始值转换为modbus协议需要的精度与类型的值"""
36
36
  opt = "<" if order == "little" else ">"
37
- try:
38
- value = int(value)
39
- if fmt in format_map:
40
- ret = struct.pack(f"{opt}{format_map[fmt]}", value)
41
- ret_list = struct.unpack(f"{opt}H", ret)
42
- else:
43
- ret_list = [0]
44
- except Exception:
45
- if "16" in fmt:
46
- ret_list = [0]
47
- elif "32" in fmt:
48
- ret_list = [0, 0]
49
- else:
50
- ret_list = [0, 0, 0, 0]
37
+ if fmt not in format_map:
38
+ raise Exception("暂不支持")
39
+ value = int(value)
40
+ ret = struct.pack(f'{opt}{format_map[fmt]["format_str"]}', value)
41
+ ret_list = struct.unpack(f'{opt}{"H" * format_map[fmt]["length"]}', ret)
51
42
  return list(ret_list)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: solax-py-library
3
- Version: 1.0.0.2515
3
+ Version: 1.0.0.2516
4
4
  Summary: some common tool
5
5
  Author: shenlvyu
6
6
  Author-email: 13296718439@163.com
@@ -73,8 +73,8 @@ solax_py_library/upload/types/ftp.py,sha256=9kCeLB0g5Je19v4ifz8YYEsGOhJL1lKBO2C6
73
73
  solax_py_library/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
74
74
  solax_py_library/utils/cloud_client.py,sha256=5dZrc5fzrNFSXqTPZd7oHt-Y9Jj6RCigB7aXJQMJ8sQ,9610
75
75
  solax_py_library/utils/common.py,sha256=bfnZcX9uM-PjJrYAFv1UMmZgt6bGR7MaOd7jRPNHGxw,1238
76
- solax_py_library/utils/struct_util.py,sha256=nlMaopAWy5bN_NGiNph0Kou5wuuYprq5lTm7h1rXJCA,1477
76
+ solax_py_library/utils/struct_util.py,sha256=pL6L80GXIHasy1ZDIj89-5BzXW1BWI3TPitH7thGGIE,1577
77
77
  solax_py_library/utils/time_util.py,sha256=bY5kj9dmyOuLEQ6uYGQK7jU7y1RMiHZgevEKnkcQcSU,1461
78
- solax_py_library-1.0.0.2515.dist-info/METADATA,sha256=wXQlZNxou41J6NRtFQCV2qK8v1rzEKBUmF0J29qArW0,1827
79
- solax_py_library-1.0.0.2515.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
80
- solax_py_library-1.0.0.2515.dist-info/RECORD,,
78
+ solax_py_library-1.0.0.2516.dist-info/METADATA,sha256=02VMgK-1HvITxP4Saad4ObNnSSKdxh63R-NnvWMlxks,1827
79
+ solax_py_library-1.0.0.2516.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
80
+ solax_py_library-1.0.0.2516.dist-info/RECORD,,