From ec41b6912b1d92cda97cdd0a1ee608c2520392eb Mon Sep 17 00:00:00 2001 From: Yeongdo Park Date: Wed, 19 Feb 2020 19:24:40 -0800 Subject: [PATCH] WIP: Categorizing CAN messages --- .gitignore | 2 + BmsApp.py | 75 +++++++++++++++++++++++++++ BmsView.py | 55 ++++++++++++++++---- BmsView.wxg | 143 ++++++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 243 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index 91afcc3..1d92bf8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /venv/ /#~wxg.autosave~BmsView.wxg# +/BmsView.py.bak +/BmsView.wxg.bak diff --git a/BmsApp.py b/BmsApp.py index c4a91e9..fdd1966 100644 --- a/BmsApp.py +++ b/BmsApp.py @@ -4,13 +4,86 @@ import wx import wx.propgrid +import gettext + +import cantools + +db = cantools.database.load_file('res/EBUS_Host.dbc') + from BmsView import BmsMonitorFrame +def parse_can_id (arbitration_id): + mtag = (arbitration_id & 0xfffff000) >> 12 + mid = (arbitration_id & 0xf00) >> 8 + mtype = arbitration_id & 0xff + return mtag, mid, mtype + +def findCategory (imsg, isignal): + tag, id, type = parse_can_id(imsg) + if tag != 0x14180: + return None + + if 0x00 <= type <= 0x06: + return "bmsprofile" + + elif type == 0x11: + return "packprofile" + + elif type == 0x10: + if isignal < 4: + return "packprofile" + else: + return "packalarms" + + elif type == 0x15: + if isignal < 3: + return "packdata" + else: + return "packalarms" + + elif type == 0x14: + return "packdata" + + elif 0x16 <= type <= 0x20: + return "packdata" + + elif 0x07 <= type <= 0x0B: + return "moduledata" + + else: + return "undefined" + class BmsMonitorView(BmsMonitorFrame): def __init__(self, *args, **kwds): BmsMonitorFrame.__init__(self, *args, **kwds) + self.property_grid_page_info = self.property_grid_1.AddPage("Info") + + for cat_name in ["bmsprofile", "packprofile", "packdata"]: + cat = wx.propgrid.PropertyCategory(label=cat_name) + self.property_grid_page_info.Append(cat) + + # bms_model = wx.propgrid.StringProperty(label="Model", name="bms_model", value="B3DWER32EW") + # self.property_grid_page_info.AppendIn("packdata", bms_model) + + for msg in db.messages: + tag, id, type = parse_can_id(msg.frame_id) + + for signal in msg.signals: + if signal.is_float: + prop = wx.propgrid.FloatProperty(label=signal.name) + else: + prop = wx.propgrid.IntProperty(label=signal.name) + prop.SetHelpString(signal.comment) + + if tag == 0x14180 and id == 0x2 and 0x00 <= type <= 0x06: # BMS Profile + self.property_grid_page_info.AppendIn("bmsprofile", prop) + + if tag == 0x14180 and id == 0x2 and 0x10 <= type <= 0x20: # Pack Profile and Data + self.property_grid_page_info.AppendIn("packdata", prop) + + # end of class BmsMonitorFrame class BmsApp(wx.App): @@ -23,5 +96,7 @@ class BmsApp(wx.App): # end of class BmsApp if __name__ == "__main__": + gettext.install("app") # replace with the appropriate catalog name + app = BmsApp(0) app.MainLoop() diff --git a/BmsView.py b/BmsView.py index d73fb7c..d529e43 100644 --- a/BmsView.py +++ b/BmsView.py @@ -1,13 +1,15 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- # -# generated by wxGlade 0.9.5 on Wed Feb 19 14:59:31 2020 +# generated by wxGlade 0.9.5 on Wed Feb 19 19:23:19 2020 # import wx +import wx.grid import wx.propgrid # begin wxGlade: dependencies +import gettext # end wxGlade # begin wxGlade: extracode @@ -19,10 +21,12 @@ class BmsMonitorFrame(wx.Frame): # begin wxGlade: BmsMonitorFrame.__init__ kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) - self.SetSize((400, 576)) - self.choice_2 = wx.Choice(self, wx.ID_ANY, choices=["choice 1"]) - self.choice_1 = wx.Choice(self, wx.ID_ANY, choices=["choice 1"]) - self.property_grid_1 = wx.propgrid.PropertyGridManager(self, wx.ID_ANY) + self.SetSize((798, 638)) + self.choice_2 = wx.Choice(self, wx.ID_ANY, choices=[_("choice 1")]) + self.choice_1 = wx.Choice(self, wx.ID_ANY, choices=[_("0x02"), _("0x03"), _("0x04"), _("0x05"), _("0x06"), _("0x07"), _("0x08"), _("0x09")]) + self.property_grid_1 = wx.propgrid.PropertyGridManager(self, wx.ID_ANY, style=wx.propgrid.PG_DESCRIPTION | wx.propgrid.PG_TOOLBAR) + self.tree_ctrl_1 = wx.TreeCtrl(self, wx.ID_ANY, style=wx.TR_HAS_BUTTONS | wx.TR_HIDE_ROOT) + self.grid_1 = wx.grid.Grid(self, wx.ID_ANY, size=(1, 1)) self.__set_properties() self.__do_layout() @@ -30,21 +34,48 @@ class BmsMonitorFrame(wx.Frame): def __set_properties(self): # begin wxGlade: BmsMonitorFrame.__set_properties - self.SetTitle("frame") + self.SetTitle(_("frame")) self.choice_2.SetSelection(0) self.choice_1.SetSelection(0) + self.grid_1.CreateGrid(12, 3) + self.grid_1.SetColLabelValue(0, _("Voltage")) + self.grid_1.SetColLabelValue(1, _("Temperature")) + self.grid_1.SetColLabelValue(2, _("Balancing")) + self.grid_1.SetRowLabelValue(0, _("Cell 1")) + self.grid_1.SetRowLabelValue(1, _("Cell 2")) + self.grid_1.SetRowLabelValue(2, _("Cell 3")) + self.grid_1.SetRowLabelValue(3, _("Cell 4")) + self.grid_1.SetRowLabelValue(4, _("Cell 5")) + self.grid_1.SetRowLabelValue(5, _("Cell 6")) + self.grid_1.SetRowLabelValue(6, _("Cell 7")) + self.grid_1.SetRowLabelValue(7, _("Cell 8")) + self.grid_1.SetRowLabelValue(8, _("Cell 9")) + self.grid_1.SetRowLabelValue(9, _("Cell 10")) + self.grid_1.SetRowLabelValue(10, _("Cell 11")) + self.grid_1.SetRowLabelValue(11, _("Cell 12")) # end wxGlade def __do_layout(self): # begin wxGlade: BmsMonitorFrame.__do_layout - sizer_1 = wx.BoxSizer(wx.VERTICAL) + sizer_1 = wx.BoxSizer(wx.HORIZONTAL) + sizer_4 = wx.BoxSizer(wx.VERTICAL) + sizer_3 = wx.BoxSizer(wx.VERTICAL) sizer_2 = wx.BoxSizer(wx.HORIZONTAL) + label_1 = wx.StaticText(self, wx.ID_ANY, _("CAN Device")) + sizer_2.Add(label_1, 0, 0, 0) + sizer_2.Add((20, 20), 0, 0, 0) sizer_2.Add(self.choice_2, 0, 0, 0) + sizer_2.Add((20, 20), 0, 0, 0) + label_2 = wx.StaticText(self, wx.ID_ANY, _("Master BMS ID")) + sizer_2.Add(label_2, 0, 0, 0) + sizer_2.Add((20, 20), 0, 0, 0) sizer_2.Add(self.choice_1, 0, 0, 0) - sizer_2.Add((0, 0), 0, 0, 0) - sizer_2.Add((0, 0), 0, 0, 0) - sizer_1.Add(sizer_2, 0, wx.EXPAND, 0) - sizer_1.Add(self.property_grid_1, 1, wx.EXPAND, 0) + sizer_3.Add(sizer_2, 0, wx.EXPAND, 0) + sizer_3.Add(self.property_grid_1, 1, wx.EXPAND, 0) + sizer_1.Add(sizer_3, 1, wx.EXPAND, 0) + sizer_4.Add(self.tree_ctrl_1, 1, wx.EXPAND, 0) + sizer_4.Add(self.grid_1, 1, wx.EXPAND, 0) + sizer_1.Add(sizer_4, 1, wx.EXPAND, 0) self.SetSizer(sizer_1) self.Layout() # end wxGlade @@ -61,5 +92,7 @@ class BmsApp(wx.App): # end of class BmsApp if __name__ == "__main__": + gettext.install("app") # replace with the appropriate catalog name + app = BmsApp(0) app.MainLoop() diff --git a/BmsView.wxg b/BmsView.wxg index 770abd3..4c0821a 100644 --- a/BmsView.wxg +++ b/BmsView.wxg @@ -1,48 +1,149 @@ - + - + - 400, 576 + 798, 638 frame - wxVERTICAL + wxHORIZONTAL - + 0 wxEXPAND - - wxHORIZONTAL + + wxVERTICAL 0 - - 0 - - choice 1 - + wxEXPAND + + wxHORIZONTAL + + + 0 + + + + + + + 0 + + 20 + 20 + + + + + 0 + + 0 + + choice 1 + + + + + + 0 + + 20 + 20 + + + + + 0 + + + + + + + 0 + + 20 + 20 + + + + + 0 + + 0 + + 0x02 + 0x03 + 0x04 + 0x05 + 0x06 + 0x07 + 0x08 + 0x09 + + + - + 0 - - 0 - - choice 1 - + wxEXPAND + + - - 0 wxEXPAND - + + wxVERTICAL + + + 0 + wxEXPAND + + + + + + + 0 + wxEXPAND + + 1 + + Voltage + Temperature + Balancing + + + Cell 1 + Cell 2 + Cell 3 + Cell 4 + Cell 5 + Cell 6 + Cell 7 + Cell 8 + Cell 9 + Cell 10 + Cell 11 + Cell 12 + + 1 + 1 + 1 + 1 + 1 + wxGrid.wxGridSelectCells + +