WIP: Categorizing CAN messages
This commit is contained in:
parent
e2ed7fce96
commit
ec41b6912b
4 changed files with 243 additions and 32 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,2 +1,4 @@
|
||||||
/venv/
|
/venv/
|
||||||
/#~wxg.autosave~BmsView.wxg#
|
/#~wxg.autosave~BmsView.wxg#
|
||||||
|
/BmsView.py.bak
|
||||||
|
/BmsView.wxg.bak
|
||||||
|
|
|
||||||
75
BmsApp.py
75
BmsApp.py
|
|
@ -4,13 +4,86 @@
|
||||||
import wx
|
import wx
|
||||||
import wx.propgrid
|
import wx.propgrid
|
||||||
|
|
||||||
|
import gettext
|
||||||
|
|
||||||
|
import cantools
|
||||||
|
|
||||||
|
db = cantools.database.load_file('res/EBUS_Host.dbc')
|
||||||
|
|
||||||
from BmsView import BmsMonitorFrame
|
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):
|
class BmsMonitorView(BmsMonitorFrame):
|
||||||
def __init__(self, *args, **kwds):
|
def __init__(self, *args, **kwds):
|
||||||
BmsMonitorFrame.__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
|
# end of class BmsMonitorFrame
|
||||||
|
|
||||||
class BmsApp(wx.App):
|
class BmsApp(wx.App):
|
||||||
|
|
@ -23,5 +96,7 @@ class BmsApp(wx.App):
|
||||||
# end of class BmsApp
|
# end of class BmsApp
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
gettext.install("app") # replace with the appropriate catalog name
|
||||||
|
|
||||||
app = BmsApp(0)
|
app = BmsApp(0)
|
||||||
app.MainLoop()
|
app.MainLoop()
|
||||||
|
|
|
||||||
55
BmsView.py
55
BmsView.py
|
|
@ -1,13 +1,15 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- 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
|
||||||
|
import wx.grid
|
||||||
import wx.propgrid
|
import wx.propgrid
|
||||||
|
|
||||||
# begin wxGlade: dependencies
|
# begin wxGlade: dependencies
|
||||||
|
import gettext
|
||||||
# end wxGlade
|
# end wxGlade
|
||||||
|
|
||||||
# begin wxGlade: extracode
|
# begin wxGlade: extracode
|
||||||
|
|
@ -19,10 +21,12 @@ class BmsMonitorFrame(wx.Frame):
|
||||||
# begin wxGlade: BmsMonitorFrame.__init__
|
# begin wxGlade: BmsMonitorFrame.__init__
|
||||||
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
|
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
|
||||||
wx.Frame.__init__(self, *args, **kwds)
|
wx.Frame.__init__(self, *args, **kwds)
|
||||||
self.SetSize((400, 576))
|
self.SetSize((798, 638))
|
||||||
self.choice_2 = wx.Choice(self, wx.ID_ANY, choices=["choice 1"])
|
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.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)
|
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.__set_properties()
|
||||||
self.__do_layout()
|
self.__do_layout()
|
||||||
|
|
@ -30,21 +34,48 @@ class BmsMonitorFrame(wx.Frame):
|
||||||
|
|
||||||
def __set_properties(self):
|
def __set_properties(self):
|
||||||
# begin wxGlade: BmsMonitorFrame.__set_properties
|
# begin wxGlade: BmsMonitorFrame.__set_properties
|
||||||
self.SetTitle("frame")
|
self.SetTitle(_("frame"))
|
||||||
self.choice_2.SetSelection(0)
|
self.choice_2.SetSelection(0)
|
||||||
self.choice_1.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
|
# end wxGlade
|
||||||
|
|
||||||
def __do_layout(self):
|
def __do_layout(self):
|
||||||
# begin wxGlade: BmsMonitorFrame.__do_layout
|
# 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)
|
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(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(self.choice_1, 0, 0, 0)
|
||||||
sizer_2.Add((0, 0), 0, 0, 0)
|
sizer_3.Add(sizer_2, 0, wx.EXPAND, 0)
|
||||||
sizer_2.Add((0, 0), 0, 0, 0)
|
sizer_3.Add(self.property_grid_1, 1, wx.EXPAND, 0)
|
||||||
sizer_1.Add(sizer_2, 0, wx.EXPAND, 0)
|
sizer_1.Add(sizer_3, 1, wx.EXPAND, 0)
|
||||||
sizer_1.Add(self.property_grid_1, 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.SetSizer(sizer_1)
|
||||||
self.Layout()
|
self.Layout()
|
||||||
# end wxGlade
|
# end wxGlade
|
||||||
|
|
@ -61,5 +92,7 @@ class BmsApp(wx.App):
|
||||||
# end of class BmsApp
|
# end of class BmsApp
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
gettext.install("app") # replace with the appropriate catalog name
|
||||||
|
|
||||||
app = BmsApp(0)
|
app = BmsApp(0)
|
||||||
app.MainLoop()
|
app.MainLoop()
|
||||||
|
|
|
||||||
143
BmsView.wxg
143
BmsView.wxg
|
|
@ -1,48 +1,149 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<!-- generated by wxGlade 0.9.5 on Wed Feb 19 14:56:52 2020 -->
|
<!-- generated by wxGlade 0.9.5 on Wed Feb 19 19:23:18 2020 -->
|
||||||
|
|
||||||
<application class="MyApp" 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="./wxglade_out.py" source_extension=".cpp" top_window="frame" use_gettext="0" 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">
|
||||||
<size>400, 576</size>
|
<size>798, 638</size>
|
||||||
<title>frame</title>
|
<title>frame</title>
|
||||||
<style>wxDEFAULT_FRAME_STYLE</style>
|
<style>wxDEFAULT_FRAME_STYLE</style>
|
||||||
<object class="wxBoxSizer" name="sizer_1" base="EditBoxSizer">
|
<object class="wxBoxSizer" name="sizer_1" base="EditBoxSizer">
|
||||||
<orient>wxVERTICAL</orient>
|
<orient>wxHORIZONTAL</orient>
|
||||||
<object class="sizeritem">
|
<object class="sizeritem">
|
||||||
<option>0</option>
|
<option>1</option>
|
||||||
<border>0</border>
|
<border>0</border>
|
||||||
<flag>wxEXPAND</flag>
|
<flag>wxEXPAND</flag>
|
||||||
<object class="wxBoxSizer" name="sizer_2" base="EditBoxSizer">
|
<object class="wxBoxSizer" name="sizer_3" base="EditBoxSizer">
|
||||||
<orient>wxHORIZONTAL</orient>
|
<orient>wxVERTICAL</orient>
|
||||||
<object class="sizeritem">
|
<object class="sizeritem">
|
||||||
<option>0</option>
|
<option>0</option>
|
||||||
<border>0</border>
|
<border>0</border>
|
||||||
<object class="wxChoice" name="choice_2" base="EditChoice">
|
<flag>wxEXPAND</flag>
|
||||||
<selection>0</selection>
|
<object class="wxBoxSizer" name="sizer_2" base="EditBoxSizer">
|
||||||
<choices>
|
<orient>wxHORIZONTAL</orient>
|
||||||
<choice>choice 1</choice>
|
<object class="sizeritem">
|
||||||
</choices>
|
<option>0</option>
|
||||||
|
<border>0</border>
|
||||||
|
<object class="wxStaticText" name="label_1" base="EditStaticText">
|
||||||
|
<label>CAN Device</label>
|
||||||
|
</object>
|
||||||
|
</object>
|
||||||
|
<object class="sizeritem">
|
||||||
|
<option>0</option>
|
||||||
|
<border>0</border>
|
||||||
|
<object class="spacer" name="spacer" base="EditSpacer">
|
||||||
|
<width>20</width>
|
||||||
|
<height>20</height>
|
||||||
|
</object>
|
||||||
|
</object>
|
||||||
|
<object class="sizeritem">
|
||||||
|
<option>0</option>
|
||||||
|
<border>0</border>
|
||||||
|
<object class="wxChoice" name="choice_2" base="EditChoice">
|
||||||
|
<selection>0</selection>
|
||||||
|
<choices>
|
||||||
|
<choice>choice 1</choice>
|
||||||
|
</choices>
|
||||||
|
</object>
|
||||||
|
</object>
|
||||||
|
<object class="sizeritem">
|
||||||
|
<option>0</option>
|
||||||
|
<border>0</border>
|
||||||
|
<object class="spacer" name="spacer" base="EditSpacer">
|
||||||
|
<width>20</width>
|
||||||
|
<height>20</height>
|
||||||
|
</object>
|
||||||
|
</object>
|
||||||
|
<object class="sizeritem">
|
||||||
|
<option>0</option>
|
||||||
|
<border>0</border>
|
||||||
|
<object class="wxStaticText" name="label_2" base="EditStaticText">
|
||||||
|
<label>Master BMS ID</label>
|
||||||
|
</object>
|
||||||
|
</object>
|
||||||
|
<object class="sizeritem">
|
||||||
|
<option>0</option>
|
||||||
|
<border>0</border>
|
||||||
|
<object class="spacer" name="spacer" base="EditSpacer">
|
||||||
|
<width>20</width>
|
||||||
|
<height>20</height>
|
||||||
|
</object>
|
||||||
|
</object>
|
||||||
|
<object class="sizeritem">
|
||||||
|
<option>0</option>
|
||||||
|
<border>0</border>
|
||||||
|
<object class="wxChoice" name="choice_1" base="EditChoice">
|
||||||
|
<selection>0</selection>
|
||||||
|
<choices>
|
||||||
|
<choice>0x02</choice>
|
||||||
|
<choice>0x03</choice>
|
||||||
|
<choice>0x04</choice>
|
||||||
|
<choice>0x05</choice>
|
||||||
|
<choice>0x06</choice>
|
||||||
|
<choice>0x07</choice>
|
||||||
|
<choice>0x08</choice>
|
||||||
|
<choice>0x09</choice>
|
||||||
|
</choices>
|
||||||
|
</object>
|
||||||
|
</object>
|
||||||
</object>
|
</object>
|
||||||
</object>
|
</object>
|
||||||
<object class="sizeritem">
|
<object class="sizeritem">
|
||||||
<option>0</option>
|
<option>1</option>
|
||||||
<border>0</border>
|
<border>0</border>
|
||||||
<object class="wxChoice" name="choice_1" base="EditChoice">
|
<flag>wxEXPAND</flag>
|
||||||
<selection>0</selection>
|
<object class="wxPropertyGridManager" name="property_grid_1" base="EditPropertyGridManager">
|
||||||
<choices>
|
<style>wxPG_TOOLBAR|wxPG_DESCRIPTION</style>
|
||||||
<choice>choice 1</choice>
|
|
||||||
</choices>
|
|
||||||
</object>
|
</object>
|
||||||
</object>
|
</object>
|
||||||
<object class="sizerslot" />
|
|
||||||
<object class="sizerslot" />
|
|
||||||
</object>
|
</object>
|
||||||
</object>
|
</object>
|
||||||
<object class="sizeritem">
|
<object class="sizeritem">
|
||||||
<option>1</option>
|
<option>1</option>
|
||||||
<border>0</border>
|
<border>0</border>
|
||||||
<flag>wxEXPAND</flag>
|
<flag>wxEXPAND</flag>
|
||||||
<object class="wxPropertyGridManager" name="property_grid_1" base="EditPropertyGridManager">
|
<object class="wxBoxSizer" name="sizer_4" base="EditBoxSizer">
|
||||||
|
<orient>wxVERTICAL</orient>
|
||||||
|
<object class="sizeritem">
|
||||||
|
<option>1</option>
|
||||||
|
<border>0</border>
|
||||||
|
<flag>wxEXPAND</flag>
|
||||||
|
<object class="wxTreeCtrl" name="tree_ctrl_1" base="EditTreeCtrl">
|
||||||
|
<style>wxTR_HAS_BUTTONS|wxTR_HIDE_ROOT</style>
|
||||||
|
</object>
|
||||||
|
</object>
|
||||||
|
<object class="sizeritem">
|
||||||
|
<option>1</option>
|
||||||
|
<border>0</border>
|
||||||
|
<flag>wxEXPAND</flag>
|
||||||
|
<object class="wxGrid" name="grid_1" base="EditGrid">
|
||||||
|
<create_grid>1</create_grid>
|
||||||
|
<columns>
|
||||||
|
<column size="-1">Voltage</column>
|
||||||
|
<column size="-1">Temperature</column>
|
||||||
|
<column size="-1">Balancing</column>
|
||||||
|
</columns>
|
||||||
|
<rows>
|
||||||
|
<row size="-1">Cell 1</row>
|
||||||
|
<row size="-1">Cell 2</row>
|
||||||
|
<row size="-1">Cell 3</row>
|
||||||
|
<row size="-1">Cell 4</row>
|
||||||
|
<row size="-1">Cell 5</row>
|
||||||
|
<row size="-1">Cell 6</row>
|
||||||
|
<row size="-1">Cell 7</row>
|
||||||
|
<row size="-1">Cell 8</row>
|
||||||
|
<row size="-1">Cell 9</row>
|
||||||
|
<row size="-1">Cell 10</row>
|
||||||
|
<row size="-1">Cell 11</row>
|
||||||
|
<row size="-1">Cell 12</row>
|
||||||
|
</rows>
|
||||||
|
<enable_editing>1</enable_editing>
|
||||||
|
<enable_grid_lines>1</enable_grid_lines>
|
||||||
|
<enable_col_resize>1</enable_col_resize>
|
||||||
|
<enable_row_resize>1</enable_row_resize>
|
||||||
|
<enable_grid_resize>1</enable_grid_resize>
|
||||||
|
<selection_mode>wxGrid.wxGridSelectCells</selection_mode>
|
||||||
|
</object>
|
||||||
|
</object>
|
||||||
</object>
|
</object>
|
||||||
</object>
|
</object>
|
||||||
</object>
|
</object>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue