mirror of
https://github.com/janishutz/BiogasControllerApp.git
synced 2025-11-25 13:54:24 +00:00
Begin rewrite
This commit is contained in:
17
biogascontrollerapp/lib/decoder.py
Normal file
17
biogascontrollerapp/lib/decoder.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import struct
|
||||
|
||||
class Decoder:
|
||||
def decode_ascii(self, value: bytes) -> str:
|
||||
try:
|
||||
return value.decode()
|
||||
except:
|
||||
return 'Error'
|
||||
|
||||
def decode_float(self, value: bytes) -> float:
|
||||
return struct.unpack('>f', bytes.fromhex(str(value, 'ascii') + '00'))[0]
|
||||
|
||||
def decode_float_long(self, value: bytes) -> float:
|
||||
return struct.unpack('>f', bytes.fromhex(str(value, 'ascii') + '0000'))[0]
|
||||
|
||||
def decode_int(self, value: bytes) -> int:
|
||||
return int(value, base=16)
|
||||
Reference in New Issue
Block a user