sync
This commit is contained in:
36
tool/core/cmd/crc32.py
Normal file
36
tool/core/cmd/crc32.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# tool/core/cmd/crc32.py
|
||||
import struct
|
||||
from core.utils import console, console_err
|
||||
from core.protocol import COMMANDS, ERRORS
|
||||
|
||||
class crc32:
|
||||
def __init__(self, bus):
|
||||
self.bus = bus
|
||||
|
||||
def get(self, path: str):
|
||||
path_bytes = path.encode('utf-8')
|
||||
payload = struct.pack('B', len(path_bytes)) + path_bytes
|
||||
self.bus.send_request(COMMANDS['crc_32'], payload)
|
||||
|
||||
# 1 Byte Type + 4 Byte Size = 5
|
||||
data = self.bus.receive_response(length=8, timeout=5)
|
||||
|
||||
if not data or data.get('type') == 'error':
|
||||
return None
|
||||
|
||||
payload = data['data']
|
||||
crc_value = struct.unpack('<I', payload[0:4])[0]
|
||||
audio_crc_value = struct.unpack('<I', payload[4:8])[0]
|
||||
result = {
|
||||
'crc32': crc_value,
|
||||
'audio_crc32': audio_crc_value
|
||||
}
|
||||
return result
|
||||
|
||||
def print(self, result, path: str):
|
||||
if not result:
|
||||
return
|
||||
|
||||
console.print(f"[info_title]CRC32[/info_title] für [info]{path}[/info]:")
|
||||
console.print(f" • CRC32 Datei: [info]{result['crc32']:08X}[/info]")
|
||||
console.print(f" • CRC32 Audio: [info]{result['audio_crc32']:08X}[/info]")
|
||||
Reference in New Issue
Block a user