Enum type for BMS Message Category
This commit is contained in:
parent
333fc6f83d
commit
5e109268db
1 changed files with 42 additions and 21 deletions
63
BmsApp.py
63
BmsApp.py
|
|
@ -6,6 +6,10 @@ import wx.propgrid
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
|
|
||||||
|
from pubsub import pub
|
||||||
|
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
import can
|
import can
|
||||||
import cantools
|
import cantools
|
||||||
|
|
||||||
|
|
@ -22,43 +26,59 @@ def parse_can_id (arbitration_id):
|
||||||
mtype = arbitration_id & 0xff
|
mtype = arbitration_id & 0xff
|
||||||
return mtag, mid, mtype
|
return mtag, mid, mtype
|
||||||
|
|
||||||
|
BMS_MSG_CAT = Enum(
|
||||||
|
"BMS_MSG_CAT",
|
||||||
|
"BMS_PROFILE "
|
||||||
|
"PACK_PROFILE "
|
||||||
|
"PACK_ALARM "
|
||||||
|
"PACK_DATA "
|
||||||
|
"MODULE_DATA "
|
||||||
|
"UNDEFINED "
|
||||||
|
"ERROR "
|
||||||
|
)
|
||||||
|
|
||||||
def findCategory (imsg, isignal):
|
def findCategory (imsg, isignal):
|
||||||
tag, id, type = parse_can_id(imsg)
|
tag, id, type = parse_can_id(imsg)
|
||||||
|
|
||||||
if tag != 0x14180:
|
if tag != 0x14180:
|
||||||
return None
|
return BMS_MSG_CAT.ERROR
|
||||||
|
|
||||||
if 0x00 <= type <= 0x06:
|
if 0x00 <= type <= 0x06:
|
||||||
return "bmsprofile"
|
return BMS_MSG_CAT.BMS_PROFILE
|
||||||
|
|
||||||
elif type == 0x11:
|
elif type == 0x11:
|
||||||
return "packprofile"
|
return BMS_MSG_CAT.PACK_PROFILE
|
||||||
|
|
||||||
elif type == 0x10:
|
elif type == 0x10:
|
||||||
if isignal < 4:
|
if isignal < 4:
|
||||||
return "packprofile"
|
return BMS_MSG_CAT.PACK_PROFILE
|
||||||
else:
|
else:
|
||||||
return "packalarms"
|
return BMS_MSG_CAT.PACK_ALARM
|
||||||
|
|
||||||
elif type == 0x15:
|
elif type == 0x15:
|
||||||
if isignal < 3:
|
if isignal < 3:
|
||||||
return "packdata"
|
return BMS_MSG_CAT.PACK_DATA
|
||||||
else:
|
else:
|
||||||
return "packalarms"
|
return BMS_MSG_CAT.PACK_ALARM
|
||||||
|
|
||||||
elif type == 0x14:
|
elif type == 0x14:
|
||||||
return "packdata"
|
return BMS_MSG_CAT.PACK_DATA
|
||||||
|
|
||||||
elif 0x16 <= type <= 0x20:
|
elif 0x16 <= type <= 0x20:
|
||||||
return "packdata"
|
return BMS_MSG_CAT.PACK_DATA
|
||||||
|
|
||||||
elif 0x07 <= type <= 0x0B:
|
elif 0x07 <= type <= 0x0B:
|
||||||
return "moduledata"
|
return BMS_MSG_CAT.MODULE_DATA
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# print("undefined category ", hex(imsg))
|
return BMS_MSG_CAT.UNDEFINED
|
||||||
return "undefined"
|
|
||||||
|
|
||||||
cat_propgrid = ["bmsprofile", "packprofile", "packdata", "packalarms",]
|
cat_propgrid = [
|
||||||
|
BMS_MSG_CAT.BMS_PROFILE,
|
||||||
|
BMS_MSG_CAT.PACK_PROFILE,
|
||||||
|
BMS_MSG_CAT.PACK_ALARM,
|
||||||
|
BMS_MSG_CAT.PACK_DATA
|
||||||
|
]
|
||||||
|
|
||||||
tohex = "{:#04X}-".format
|
tohex = "{:#04X}-".format
|
||||||
|
|
||||||
|
|
@ -74,7 +94,8 @@ class BmsMonitorView(BmsMonitorFrame):
|
||||||
|
|
||||||
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 c in cat_propgrid:
|
||||||
|
cat_name = c.name
|
||||||
cat = wx.propgrid.PropertyCategory(label=cat_name)
|
cat = wx.propgrid.PropertyCategory(label=cat_name)
|
||||||
self.property_grid_page_info.Append(cat)
|
self.property_grid_page_info.Append(cat)
|
||||||
|
|
||||||
|
|
@ -86,9 +107,9 @@ class BmsMonitorView(BmsMonitorFrame):
|
||||||
|
|
||||||
if id == 0x02:
|
if id == 0x02:
|
||||||
|
|
||||||
if findCategory(msg.frame_id, 0) == "bmsprofile":
|
if findCategory(msg.frame_id, 0) == BMS_MSG_CAT.BMS_PROFILE:
|
||||||
prop = wx.propgrid.StringProperty(label=msg.name)
|
prop = wx.propgrid.StringProperty(label=msg.name)
|
||||||
self.property_grid_page_info.AppendIn("bmsprofile", prop)
|
self.property_grid_page_info.AppendIn(BMS_MSG_CAT.BMS_PROFILE.name, prop)
|
||||||
|
|
||||||
for isig, signal in enumerate(msg.signals):
|
for isig, signal in enumerate(msg.signals):
|
||||||
plabel = tohex(type)+signal.name
|
plabel = tohex(type)+signal.name
|
||||||
|
|
@ -98,11 +119,11 @@ class BmsMonitorView(BmsMonitorFrame):
|
||||||
cat = findCategory(msg.frame_id, isig)
|
cat = findCategory(msg.frame_id, isig)
|
||||||
|
|
||||||
if cat in cat_propgrid:
|
if cat in cat_propgrid:
|
||||||
self.property_grid_page_info.AppendIn(cat, prop)
|
self.property_grid_page_info.AppendIn(cat.name, prop)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
if tag == 0x14180 and id == 0x2 and 0x00 <= type <= 0x06: # BMS Profile
|
if tag == 0x14180 and id == 0x2 and 0x00 <= type <= 0x06: # BMS Profile
|
||||||
self.property_grid_page_info.AppendIn("bmsprofile", prop)
|
self.property_grid_page_info.AppendIn(BMS_MSG_CAT.BMS_PROFILE, prop)
|
||||||
|
|
||||||
if tag == 0x14180 and id == 0x2 and 0x10 <= type <= 0x20: # Pack Profile and Data
|
if tag == 0x14180 and id == 0x2 and 0x10 <= type <= 0x20: # Pack Profile and Data
|
||||||
self.property_grid_page_info.AppendIn("packdata", prop)
|
self.property_grid_page_info.AppendIn("packdata", prop)
|
||||||
|
|
@ -149,7 +170,7 @@ class BmsMonitorView(BmsMonitorFrame):
|
||||||
master_id = int(self.choice_1.GetStringSelection(), 16)
|
master_id = int(self.choice_1.GetStringSelection(), 16)
|
||||||
|
|
||||||
if mid == master_id:
|
if mid == master_id:
|
||||||
if findCategory(fullid, 0) == "moduledata":
|
if findCategory(fullid, 0) == BMS_MSG_CAT.MODULE_DATA:
|
||||||
try:
|
try:
|
||||||
dmsg = db.decode_message(msg.arbitration_id, msg.data)
|
dmsg = db.decode_message(msg.arbitration_id, msg.data)
|
||||||
except KeyError as key:
|
except KeyError as key:
|
||||||
|
|
@ -157,7 +178,7 @@ class BmsMonitorView(BmsMonitorFrame):
|
||||||
else:
|
else:
|
||||||
self.__update_bm_state(dmsg)
|
self.__update_bm_state(dmsg)
|
||||||
|
|
||||||
elif findCategory(fullid, 0) == "bmsprofile":
|
elif findCategory(fullid, 0) == BMS_MSG_CAT.BMS_PROFILE:
|
||||||
try:
|
try:
|
||||||
print ("bmsprofile message raw", (dbmsg.name), msg.data, msg.data.decode())
|
print ("bmsprofile message raw", (dbmsg.name), msg.data, msg.data.decode())
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
|
|
@ -182,7 +203,7 @@ class BmsMonitorView(BmsMonitorFrame):
|
||||||
|
|
||||||
'''
|
'''
|
||||||
if tag == 0x14180 and id == 0x2 and 0x00 <= type <= 0x06: # BMS Profile
|
if tag == 0x14180 and id == 0x2 and 0x00 <= type <= 0x06: # BMS Profile
|
||||||
self.property_grid_page_info.AppendIn("bmsprofile", prop)
|
self.property_grid_page_info.AppendIn(BMS_MSG_CAT.BMS_PROFILE, prop)
|
||||||
|
|
||||||
if tag == 0x14180 and id == 0x2 and 0x10 <= type <= 0x20: # Pack Profile and Data
|
if tag == 0x14180 and id == 0x2 and 0x10 <= type <= 0x20: # Pack Profile and Data
|
||||||
self.property_grid_page_info.AppendIn("packdata", prop)
|
self.property_grid_page_info.AppendIn("packdata", prop)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue