Skip to content

Commit

Permalink
fix temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrils committed Dec 16, 2022
1 parent 3ef2569 commit b15cef2
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,16 @@ def create_request_payload(device_id, function, regAddr, readWrd):
data.append(Int2Bytes(crc, 0))
logging.debug("{} {} => {}".format("create_read_request", regAddr, data))
return data


def parse_charge_controller_info(bs):
data = {}
data['function'] = FUNCTION[Bytes2Int(bs, 1, 1)]
data['battery_percentage'] = Bytes2Int(bs, 3, 2)
data['battery_voltage'] = Bytes2Int(bs, 5, 2) * 0.1
data['battery_current'] = Bytes2Int(bs, 7, 2) * 0.01
data['battery_temperature'] = Bytes2Int(bs, 10, 1)
data['controller_temperature'] = Bytes2Int(bs, 9, 1)
load_status = Bytes2Int(bs, 67, 1) >> 7
data['load_status'] = LOAD_STATE[load_status]
data['battery_temperature'] = parse_temperature(Bytes2Int(bs, 10, 1))
data['controller_temperature'] = parse_temperature(Bytes2Int(bs, 9, 1))
data['load_status'] = LOAD_STATE[Bytes2Int(bs, 67, 1) >> 7]
data['load_voltage'] = Bytes2Int(bs, 11, 2) * 0.1
data['load_current'] = Bytes2Int(bs, 13, 2) * 0.01
data['load_power'] = Bytes2Int(bs, 15, 2)
Expand All @@ -93,14 +91,15 @@ def parse_charge_controller_info(bs):
data['power_generation_today'] = Bytes2Int(bs, 41, 2)
data['power_consumption_today'] = Bytes2Int(bs, 43, 2)
data['power_generation_total'] = Bytes2Int(bs, 59, 4)
charging_status_code = Bytes2Int(bs, 68, 1)
data['charging_status'] = CHARGING_STATE[charging_status_code]

data['charging_status'] = CHARGING_STATE[Bytes2Int(bs, 68, 1)]
return data


def parse_set_load_response(bs):
data = {}
data['function'] = FUNCTION[Bytes2Int(bs, 1, 1)]
data['load_status'] = Bytes2Int(bs, 5, 1)
return data
return data

def parse_temperature(raw_value):
sign = raw_value >> 7
return -(raw_value - 128) if sign == 1 else raw_value

0 comments on commit b15cef2

Please sign in to comment.