Enum type for BMS Message Category

This commit is contained in:
Yeongdo Park 2020-08-06 16:56:05 -07:00
parent 333fc6f83d
commit 5e109268db

View file

@ -6,6 +6,10 @@ import wx.propgrid
import gettext
from pubsub import pub
from enum import Enum
import can
import cantools
@ -22,43 +26,59 @@ def parse_can_id (arbitration_id):
mtype = arbitration_id & 0xff
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):
tag, id, type = parse_can_id(imsg)
if tag != 0x14180:
return None
return BMS_MSG_CAT.ERROR
if 0x00 <= type <= 0x06:
return "bmsprofile"
return BMS_MSG_CAT.BMS_PROFILE
elif type == 0x11:
return "packprofile"
return BMS_MSG_CAT.PACK_PROFILE
elif type == 0x10:
if isignal < 4:
return "packprofile"
return BMS_MSG_CAT.PACK_PROFILE
else:
return "packalarms"
return BMS_MSG_CAT.PACK_ALARM
elif type == 0x15:
if isignal < 3:
return "packdata"
return BMS_MSG_CAT.PACK_DATA
else:
return "packalarms"
return BMS_MSG_CAT.PACK_ALARM
elif type == 0x14:
return "packdata"
return BMS_MSG_CAT.PACK_DATA
elif 0x16 <= type <= 0x20:
return "packdata"
return BMS_MSG_CAT.PACK_DATA
elif 0x07 <= type <= 0x0B:
return "moduledata"
return BMS_MSG_CAT.MODULE_DATA
else:
# print("undefined category ", hex(imsg))
return "undefined"
return BMS_MSG_CAT.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
@ -74,7 +94,8 @@ class BmsMonitorView(BmsMonitorFrame):
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)
self.property_grid_page_info.Append(cat)
@ -86,9 +107,9 @@ class BmsMonitorView(BmsMonitorFrame):
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)
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):
plabel = tohex(type)+signal.name
@ -98,11 +119,11 @@ class BmsMonitorView(BmsMonitorFrame):
cat = findCategory(msg.frame_id, isig)
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
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
self.property_grid_page_info.AppendIn("packdata", prop)
@ -149,7 +170,7 @@ class BmsMonitorView(BmsMonitorFrame):
master_id = int(self.choice_1.GetStringSelection(), 16)
if mid == master_id:
if findCategory(fullid, 0) == "moduledata":
if findCategory(fullid, 0) == BMS_MSG_CAT.MODULE_DATA:
try:
dmsg = db.decode_message(msg.arbitration_id, msg.data)
except KeyError as key:
@ -157,7 +178,7 @@ class BmsMonitorView(BmsMonitorFrame):
else:
self.__update_bm_state(dmsg)
elif findCategory(fullid, 0) == "bmsprofile":
elif findCategory(fullid, 0) == BMS_MSG_CAT.BMS_PROFILE:
try:
print ("bmsprofile message raw", (dbmsg.name), msg.data, msg.data.decode())
except UnicodeDecodeError:
@ -182,7 +203,7 @@ class BmsMonitorView(BmsMonitorFrame):
'''
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
self.property_grid_page_info.AppendIn("packdata", prop)