Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read installed capacity at startup #594

Merged
merged 1 commit into from
Apr 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions etc/dbus-serialbattery/bms/daly.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, port, baud, address):
command_temp = b"\x96"
command_cell_balance = b"\x97"
command_alarm = b"\x98"
command_rated_params = b"\x50"
BATTERYTYPE = "Daly"
LENGTH_CHECK = 1
LENGTH_POS = 3
Expand All @@ -56,6 +57,9 @@ def test_connection(self):

def get_settings(self):
self.capacity = utils.BATTERY_CAPACITY
with open_serial_port(self.port, self.baud_rate) as ser:
self.read_capacity(ser)

self.max_battery_charge_current = utils.MAX_BATTERY_CHARGE_CURRENT
self.max_battery_discharge_current = utils.MAX_BATTERY_DISCHARGE_CURRENT
return True
Expand Down Expand Up @@ -361,6 +365,20 @@ def read_fed_data(self, ser):
self.capacity_remain = capacity_remain / 1000
return True

def read_capacity(self, ser):
capa_data = self.read_serial_data_daly(ser, self.command_rated_params)
# check if connection success
if capa_data is False:
logger.warning("read_capacity")
return False

(
capacity,
cell_volt
) = unpack_from(">LL", capa_data)
self.capacity = capacity / 1000
return True

def generate_command(self, command):
buffer = bytearray(self.command_base)
buffer[1] = self.command_address[0] # Always serial 40 or 80
Expand Down