Fix Master ID Selector and force refreshing module data grid

This commit is contained in:
Yeongdo Park 2020-08-11 19:42:22 -07:00
parent ac36ef74a8
commit 915ca498fb
3 changed files with 29 additions and 8 deletions

View file

@ -96,6 +96,10 @@ class Controller:
pub.subscribe(self.model.start_can, "view.start") pub.subscribe(self.model.start_can, "view.start")
pub.subscribe(self.model.stop_can, "view.stop") pub.subscribe(self.model.stop_can, "view.stop")
pub.subscribe (self.view.update_battery_module_grid, "bms.module.update")
pub.subscribe (self.model.setter, "view.id_selector")
class PmgrowBms: class PmgrowBms:
def __init__(self, add_printer=True): def __init__(self, add_printer=True):
@ -104,6 +108,11 @@ class PmgrowBms:
self.notifier = None self.notifier = None
self.listeners = [can.Printer()] if add_printer else [] self.listeners = [can.Printer()] if add_printer else []
self.listeners.append(BmsListener(self)) self.listeners.append(BmsListener(self))
self.master_id = 0x02
def setter (self, id):
print ("updating master id")
self.master_id = id
@property @property
def bms_id (self): def bms_id (self):
@ -129,9 +138,8 @@ class PmgrowBms:
full_id = (msg_prefix, master_id, msg_type) full_id = (msg_prefix, master_id, msg_type)
db_msg = db.get_message_by_frame_id(msg.arbitration_id) db_msg = db.get_message_by_frame_id(msg.arbitration_id)
id_chosen = int(self.choice_1.GetStringSelection(), 16) print(master_id, self.master_id)
if master_id == self.master_id:
if master_id == id_chosen:
if find_category(full_id, 0) == BMS_MSG_CAT.MODULE_DATA: if find_category(full_id, 0) == BMS_MSG_CAT.MODULE_DATA:
try: try:
decoded = db.decode_message(msg.arbitration_id, msg.data) decoded = db.decode_message(msg.arbitration_id, msg.data)
@ -206,8 +214,6 @@ class BmsMonitorView(BmsMonitorFrame):
if cat in pgrid_category: if cat in pgrid_category:
self.property_grid_page_info.AppendIn(cat.name, prop) self.property_grid_page_info.AppendIn(cat.name, prop)
pub.subscribe (self.update_battery_module_grid, "bms.module.update")
def GetModuleVoltage(self, module_dict): def GetModuleVoltage(self, module_dict):
keyString = 'BatS_Cell{}_V' keyString = 'BatS_Cell{}_V'
return [module_dict.get(keyString.format(x), -1) for x in range(nCell)] return [module_dict.get(keyString.format(x), -1) for x in range(nCell)]
@ -218,12 +224,19 @@ class BmsMonitorView(BmsMonitorFrame):
def update_battery_module_grid(self, state): def update_battery_module_grid(self, state):
i_module = self.spin_ctrl_1.GetValue() i_module = self.spin_ctrl_1.GetValue()
module_dict = self.state[i_module] module_dict = state[i_module]
voltages = self.GetModuleVoltage(module_dict) voltages = self.GetModuleVoltage(module_dict)
bal_states = self.GetModuleBalState(module_dict) bal_states = self.GetModuleBalState(module_dict)
for i in range(nCell): for i in range(nCell):
self.grid_1.SetCellValue(i, 0, str(voltages[i])) self.grid_1.SetCellValue(i, 0, str(voltages[i]))
self.grid_1.SetCellValue(i, 2, str(bal_states[i])) self.grid_1.SetCellValue(i, 2, str(bal_states[i]))
self.grid_1.ForceRefresh()
def OnIdChoice(self, event):
print ("sending update request")
pub.sendMessage("view.id_selector", id=int(self.choice_1.GetStringSelection(), 16))
event.Skip()
def OnToggle(self, event): def OnToggle(self, event):
if self.button_1.Value: if self.button_1.Value:

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
# #
# generated by wxGlade 0.9.6 on Thu Aug 6 14:36:04 2020 # generated by wxGlade 0.9.6 on Tue Aug 11 19:12:46 2020
# #
import wx import wx
@ -35,6 +35,7 @@ class BmsMonitorFrame(wx.Frame):
self.__do_layout() self.__do_layout()
self.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle, self.button_1) self.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle, self.button_1)
self.Bind(wx.EVT_CHOICE, self.OnIdChoice, self.choice_1)
# end wxGlade # end wxGlade
def __set_properties(self): def __set_properties(self):
@ -106,6 +107,10 @@ class BmsMonitorFrame(wx.Frame):
print("Event handler 'OnToggle' not implemented!") print("Event handler 'OnToggle' not implemented!")
event.Skip() event.Skip()
def OnIdChoice(self, event): # wxGlade: BmsMonitorFrame.<event_handler>
print("Event handler 'OnIdChoice' not implemented!")
event.Skip()
# end of class BmsMonitorFrame # end of class BmsMonitorFrame
class BmsApp(wx.App): class BmsApp(wx.App):

View file

@ -1,5 +1,5 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!-- generated by wxGlade 0.9.6 on Thu Aug 6 14:36:03 2020 --> <!-- generated by wxGlade 0.9.6 on Tue Aug 11 19:12:43 2020 -->
<application class="BmsApp" encoding="UTF-8" for_version="3.0" header_extension=".h" indent_amount="4" indent_symbol="space" is_template="0" language="python" mark_blocks="1" name="app" option="0" overwrite="1" path="./BmsView.py" source_extension=".cpp" top_window="frame" use_gettext="1" use_new_namespace="1"> <application class="BmsApp" encoding="UTF-8" for_version="3.0" header_extension=".h" indent_amount="4" indent_symbol="space" is_template="0" language="python" mark_blocks="1" name="app" option="0" overwrite="1" path="./BmsView.py" source_extension=".cpp" top_window="frame" use_gettext="1" use_new_namespace="1">
<object class="BmsMonitorFrame" name="frame" base="EditFrame"> <object class="BmsMonitorFrame" name="frame" base="EditFrame">
@ -91,6 +91,9 @@
<option>0</option> <option>0</option>
<border>0</border> <border>0</border>
<object class="wxChoice" name="choice_1" base="EditChoice"> <object class="wxChoice" name="choice_1" base="EditChoice">
<events>
<handler event="EVT_CHOICE">OnIdChoice</handler>
</events>
<selection>0</selection> <selection>0</selection>
<choices> <choices>
<choice>0x02</choice> <choice>0x02</choice>