|
10 | 10 |
|
11 | 11 | from . import util as cliutil |
12 | 12 | from ..bsm import config |
| 13 | +from ..bsm import util as bsmutil |
13 | 14 | from ..bsm.client import BsmClientDevice, SunSpecBsmClientDevice |
14 | 15 | from ..crypto import util as cryptoutil |
15 | 16 | from ..exporter import chargy, ocmf, registers |
@@ -181,35 +182,11 @@ def create_sunspec_client(args): |
181 | 182 | return create_client_backend(SunSpecBsmClientDevice, args) |
182 | 183 |
|
183 | 184 |
|
184 | | -def into_chunks(array, length): |
185 | | - for i in range(0, len(array), length): |
186 | | - yield array[i:i + length] |
187 | | - |
188 | | - |
189 | 185 | def md_trace_print(string): |
190 | 186 | for line in string.splitlines(): |
191 | 187 | print(line) |
192 | 188 |
|
193 | 189 |
|
194 | | -def register_hexdump_bytes(data, offset=0): |
195 | | - chunk_regs = 8 |
196 | | - chunk_length = 2 * chunk_regs |
197 | | - |
198 | | - start = offset |
199 | | - lines = [] |
200 | | - |
201 | | - for chunk in into_chunks(data, chunk_length): |
202 | | - # Hex data of registers. |
203 | | - hex_chunk = ' '.join(map(lambda x: '{:02x}{:02x}'.format(x[0], x[1]), zip(chunk[::2], chunk[1::2]))) |
204 | | - # Printable characters from data. |
205 | | - printable = ''.join(map(lambda x: chr(x) if x >= 32 and x < 127 else '.', chunk)) |
206 | | - |
207 | | - lines.append('{:8}: {:40} {}'.format(start, hex_chunk, printable)) |
208 | | - start += chunk_regs |
209 | | - |
210 | | - return '\n'.join(lines) |
211 | | - |
212 | | - |
213 | 190 | def trace_modbus_rtu(string): |
214 | 191 | # Attempt to logically group known Modbus frame formats in the trace output |
215 | 192 | # from pySunSpec. |
@@ -264,7 +241,7 @@ def dump_command(args): |
264 | 241 | client = create_client(args) |
265 | 242 |
|
266 | 243 | data = client.read(args.offset, args.length) |
267 | | - print(register_hexdump_bytes(data, args.offset)) |
| 244 | + print(bsmutil.register_hexdump_bytes(data, args.offset)) |
268 | 245 |
|
269 | 246 | client.close() |
270 | 247 |
|
|
0 commit comments