mirror of
https://github.com/janishutz/BiogasControllerApp.git
synced 2025-11-25 05:44:23 +00:00
Config, Lots of docs, Format
Added a config validator and documented code that was previously undocumented, for the plot_generator scripts, documented them.
This commit is contained in:
@@ -1,18 +1,24 @@
|
||||
import struct
|
||||
|
||||
|
||||
# Decoder to decode various sent values from the microcontroller
|
||||
class Decoder:
|
||||
# Decode an ascii character
|
||||
def decode_ascii(self, value: bytes) -> str:
|
||||
try:
|
||||
return value.decode()
|
||||
except:
|
||||
return 'Error'
|
||||
return "Error"
|
||||
|
||||
# Decode a float (6 bits)
|
||||
def decode_float(self, value: bytes) -> float:
|
||||
return struct.unpack('>f', bytes.fromhex(str(value, 'ascii') + '00'))[0]
|
||||
return struct.unpack(">f", bytes.fromhex(str(value, "ascii") + "00"))[0]
|
||||
|
||||
# Decode a float, but with additional offsets
|
||||
def decode_float_long(self, value: bytes) -> float:
|
||||
return struct.unpack('>f', bytes.fromhex(str(value, 'ascii') + '0000'))[0]
|
||||
return struct.unpack(">f", bytes.fromhex(str(value, "ascii") + "0000"))[0]
|
||||
|
||||
# Decode an int
|
||||
def decode_int(self, value: bytes) -> int:
|
||||
# return int.from_bytes(value, 'big')
|
||||
return int(value, base=16)
|
||||
|
||||
Reference in New Issue
Block a user