WIP: intermediate parsing
This commit is contained in:
parent
ef70a3d592
commit
d3095755a8
3 changed files with 101 additions and 2 deletions
72
BmsApp.py
72
BmsApp.py
|
|
@ -6,6 +6,7 @@ import wx.propgrid
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
|
|
||||||
|
import can
|
||||||
import cantools
|
import cantools
|
||||||
|
|
||||||
db = cantools.database.load_file('res/EBUS_Host.dbc')
|
db = cantools.database.load_file('res/EBUS_Host.dbc')
|
||||||
|
|
@ -60,6 +61,9 @@ class BmsMonitorView(BmsMonitorFrame):
|
||||||
def __init__(self, *args, **kwds):
|
def __init__(self, *args, **kwds):
|
||||||
BmsMonitorFrame.__init__(self, *args, **kwds)
|
BmsMonitorFrame.__init__(self, *args, **kwds)
|
||||||
|
|
||||||
|
self.timer = wx.Timer(self)
|
||||||
|
self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
|
||||||
|
|
||||||
self.property_grid_page_info = self.property_grid_1.AddPage("Info")
|
self.property_grid_page_info = self.property_grid_1.AddPage("Info")
|
||||||
|
|
||||||
for cat_name in cat_propgrid:
|
for cat_name in cat_propgrid:
|
||||||
|
|
@ -100,6 +104,74 @@ class BmsMonitorView(BmsMonitorFrame):
|
||||||
self.property_grid_page_info.AppendIn("packdata", prop)
|
self.property_grid_page_info.AppendIn("packdata", prop)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
def OnToggle(self, event):
|
||||||
|
btnLabel = self.button_1.GetLabel()
|
||||||
|
if self.button_1.Value:
|
||||||
|
print ("starting timer...")
|
||||||
|
self.bus = can.Bus()
|
||||||
|
|
||||||
|
self.timer.Start(10)
|
||||||
|
self.button_1.SetLabel("Stop")
|
||||||
|
else:
|
||||||
|
print ( "timer stopped!" )
|
||||||
|
self.bus.shutdown()
|
||||||
|
self.bus = None
|
||||||
|
|
||||||
|
self.timer.Stop()
|
||||||
|
self.button_1.SetLabel("Start")
|
||||||
|
|
||||||
|
event.Skip()
|
||||||
|
|
||||||
|
def OnTimer(self, event):
|
||||||
|
# print("Read CAN Message!")
|
||||||
|
msg = self.bus.recv(timeout=1.)
|
||||||
|
mtag, mid, mtype = parse_can_id(msg.frame_id)
|
||||||
|
if 0x07 <= mtype <= 0x0b:
|
||||||
|
try:
|
||||||
|
dmsg = self.candb.decode_message(msg.arbitration_id, msg.data)
|
||||||
|
except KeyError as key:
|
||||||
|
print(key, " does not exist")
|
||||||
|
else:
|
||||||
|
print(hex(mtag), hex(mid), hex(mtype), msg.data, dmsg)
|
||||||
|
self.__update_bm_state(dmsg)
|
||||||
|
|
||||||
|
for k in self.battery_module_state[0]:
|
||||||
|
if self.property_grid_1.GetProperty(k):
|
||||||
|
self.property_grid_1.SetPropertyValue(k, self.battery_module_state[0][k])
|
||||||
|
else:
|
||||||
|
self.property_grid_1.Append(wx.propgrid.StringProperty(label=k, value=str(self.battery_module_state[0][k])))
|
||||||
|
|
||||||
|
master_id = int(self.choice_1.GetStringSelection())
|
||||||
|
|
||||||
|
if mid == master_id:
|
||||||
|
|
||||||
|
if findCategory(msg.frame_id, 0) == "bmsprofile":
|
||||||
|
prop = wx.propgrid.StringProperty(label=msg.name)
|
||||||
|
self.property_grid_page_info.AppendIn("bmsprofile", prop)
|
||||||
|
|
||||||
|
for isig, signal in enumerate(msg.signals):
|
||||||
|
plabel = tohex(type) + signal.name
|
||||||
|
if signal.is_float:
|
||||||
|
prop = wx.propgrid.FloatProperty(label=plabel)
|
||||||
|
else:
|
||||||
|
prop = wx.propgrid.IntProperty(label=plabel)
|
||||||
|
prop.SetHelpString(signal.comment)
|
||||||
|
|
||||||
|
cat = findCategory(msg.frame_id, isig)
|
||||||
|
|
||||||
|
if cat in cat_propgrid:
|
||||||
|
self.property_grid_page_info.AppendIn(cat, prop)
|
||||||
|
|
||||||
|
'''
|
||||||
|
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)
|
||||||
|
'''
|
||||||
|
|
||||||
|
event.Skip()
|
||||||
|
|
||||||
|
|
||||||
# end of class BmsMonitorFrame
|
# end of class BmsMonitorFrame
|
||||||
|
|
||||||
|
|
|
||||||
11
BmsView.py
11
BmsView.py
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
#
|
#
|
||||||
# generated by wxGlade 0.9.5 on Fri Feb 21 16:44:13 2020
|
# generated by wxGlade 0.9.6 on Mon Aug 3 16:52:33 2020
|
||||||
#
|
#
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
|
|
@ -22,6 +22,7 @@ class BmsMonitorFrame(wx.Frame):
|
||||||
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((831, 774))
|
self.SetSize((831, 774))
|
||||||
|
self.button_1 = wx.ToggleButton(self, wx.ID_ANY, _("Start"))
|
||||||
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=[_("0x02"), _("0x03"), _("0x04"), _("0x05"), _("0x06"), _("0x07"), _("0x08"), _("0x09")])
|
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_AUTO_SORT | wx.propgrid.PG_DESCRIPTION | wx.propgrid.PG_TOOLBAR)
|
self.property_grid_1 = wx.propgrid.PropertyGridManager(self, wx.ID_ANY, style=wx.propgrid.PG_AUTO_SORT | wx.propgrid.PG_DESCRIPTION | wx.propgrid.PG_TOOLBAR)
|
||||||
|
|
@ -32,6 +33,8 @@ class BmsMonitorFrame(wx.Frame):
|
||||||
|
|
||||||
self.__set_properties()
|
self.__set_properties()
|
||||||
self.__do_layout()
|
self.__do_layout()
|
||||||
|
|
||||||
|
self.Bind(wx.EVT_TOGGLEBUTTON, self.OnToggle, self.button_1)
|
||||||
# end wxGlade
|
# end wxGlade
|
||||||
|
|
||||||
def __set_properties(self):
|
def __set_properties(self):
|
||||||
|
|
@ -68,6 +71,8 @@ class BmsMonitorFrame(wx.Frame):
|
||||||
sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
|
sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
sizer_3 = wx.BoxSizer(wx.VERTICAL)
|
sizer_3 = wx.BoxSizer(wx.VERTICAL)
|
||||||
sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
|
sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
|
sizer_2.Add(self.button_1, 0, 0, 0)
|
||||||
|
sizer_2.Add((20, 20), 0, 0, 0)
|
||||||
label_1 = wx.StaticText(self, wx.ID_ANY, _("CAN Device"))
|
label_1 = wx.StaticText(self, wx.ID_ANY, _("CAN Device"))
|
||||||
sizer_2.Add(label_1, 0, 0, 0)
|
sizer_2.Add(label_1, 0, 0, 0)
|
||||||
sizer_2.Add((20, 20), 0, 0, 0)
|
sizer_2.Add((20, 20), 0, 0, 0)
|
||||||
|
|
@ -94,6 +99,10 @@ class BmsMonitorFrame(wx.Frame):
|
||||||
self.Layout()
|
self.Layout()
|
||||||
# end wxGlade
|
# end wxGlade
|
||||||
|
|
||||||
|
def OnToggle(self, event): # wxGlade: BmsMonitorFrame.<event_handler>
|
||||||
|
print("Event handler 'OnToggle' not implemented!")
|
||||||
|
event.Skip()
|
||||||
|
|
||||||
# end of class BmsMonitorFrame
|
# end of class BmsMonitorFrame
|
||||||
|
|
||||||
class BmsApp(wx.App):
|
class BmsApp(wx.App):
|
||||||
|
|
|
||||||
20
BmsView.wxg
20
BmsView.wxg
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<!-- generated by wxGlade 0.9.5 on Fri Feb 21 16:44:12 2020 -->
|
<!-- generated by wxGlade 0.9.6 on Mon Aug 3 16:52:29 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">
|
||||||
|
|
@ -20,6 +20,24 @@
|
||||||
<flag>wxEXPAND</flag>
|
<flag>wxEXPAND</flag>
|
||||||
<object class="wxBoxSizer" name="sizer_2" base="EditBoxSizer">
|
<object class="wxBoxSizer" name="sizer_2" base="EditBoxSizer">
|
||||||
<orient>wxHORIZONTAL</orient>
|
<orient>wxHORIZONTAL</orient>
|
||||||
|
<object class="sizeritem">
|
||||||
|
<option>0</option>
|
||||||
|
<border>0</border>
|
||||||
|
<object class="wxToggleButton" name="button_1" base="EditToggleButton">
|
||||||
|
<events>
|
||||||
|
<handler event="EVT_TOGGLEBUTTON">OnToggle</handler>
|
||||||
|
</events>
|
||||||
|
<label>Start</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">
|
<object class="sizeritem">
|
||||||
<option>0</option>
|
<option>0</option>
|
||||||
<border>0</border>
|
<border>0</border>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue