lpcmanager

Parents dfe1fb9a0917
Children 17e71d6ad597
MC9 : Added Buttons, re-enabled PLC configuration tabs disabled for MC8, added some right bus declarations in LPCBus, disabled SetOnline Mode command.
  • +210 -62
    LPCManager.py
  • --- a/LPCManager.py Wed Mar 26 13:15:50 2014 +0100
    +++ b/LPCManager.py Fri Nov 21 18:15:53 2014 +0100
    @@ -48,7 +48,8 @@
    if len(args) > 3:
    arch = args[3]
    else:
    - arch = "MC8"
    + arch = "MC9"
    + # XXX arch = "MC8"
    __builtin__.__dict__["BMZ_DBG"] = os.path.exists("LPC_DEBUG")
    @@ -152,8 +153,8 @@
    LOCATION_SIZES = {}
    for size, types in LOCATIONDATATYPES.iteritems():
    - for type in types:
    - LOCATION_SIZES[type] = size
    + for _type in types:
    + LOCATION_SIZES[_type] = size
    def _GetModuleChildren(module):
    children = []
    @@ -202,7 +203,8 @@
    if group["type"] == LOCATION_GROUP and child in group["children"]:
    group["children"].remove(child)
    -BUS_TEXT = """/* Code generated by LPCBus confnode */
    +bus_template_code = {"MC8":"""
    +/* Code generated by LPCBus confnode */
    /* LPCBus confnode includes */
    #include "app_glue.h"
    @@ -237,7 +239,106 @@
    {
    %(publish_code)s
    }
    -"""
    +""",
    +#############################
    +"MC9":"""
    +/* Code generated by LPCBus confnode */
    +
    +#ifdef _WINDOWS_H
    + #include "iec_types.h"
    +#else
    + #include "iec_std_lib.h"
    +#endif
    +
    +static inline int16_t getWord(char *buffer)
    +{
    + return *((int16_t*)buffer);
    +}
    +
    +static inline void setWord(char *buffer, int16_t word)
    +{
    + *((int16_t*)buffer) = word;
    +}
    +
    +static inline int8_t getBit(char *buffer, unsigned char bitOffset)
    +{
    + return (*buffer & (0x01 << bitOffset)) && 1;
    +}
    +
    +static inline void setBit(char *buffer, unsigned char bitOffset, int8_t bit)
    +{
    + unsigned char msk = (0x01 << bitOffset);
    + if(bit)
    + *buffer |= msk;
    + else
    + *buffer &= ~msk;
    +}
    +
    +%(bus_code)s
    +
    +%(declare_code)s
    +
    +/* LPCBus confnode user variables definition */
    +%(var_decl)s
    +
    +/* LPCBus confnode functions */
    +int __init_%(location_str)s(int argc,char **argv)
    +{
    +%(init_code)s
    + return 0;
    +}
    +
    +void __cleanup_%(location_str)s(void)
    +{
    +}
    +
    +void __retrieve_%(location_str)s(void)
    +{
    +%(retrieve_code)s
    +}
    +
    +void __publish_%(location_str)s(void)
    +{
    +%(publish_code)s
    +}
    +"""}
    +
    +bus_code = {
    + "MC9:Right":"""
    +/* LPCBus confnode includes */
    +#define RIGHT_READ_BUFSIZE 30 /**< Right bus read buffer size */
    +#define RIGHT_WRITE_BUFSIZE 30 /**< Right bus write buffer size */
    +
    +#define MAX_RIGHT_MODULES 8
    +
    +/**< Buffers for reading data from right bus modules */
    +typedef char rightReadBuf_t[MAX_RIGHT_MODULES][RIGHT_READ_BUFSIZE];
    +
    +/**< Buffers for writing data to right bus modules */
    +typedef char rightWriteBuf_t[MAX_RIGHT_MODULES][RIGHT_WRITE_BUFSIZE];
    +
    +/**< Tables containing information about connected modules
    + on right bus (initialized by Composer) */
    +typedef char rightI2CMod_t[MAX_RIGHT_MODULES][2];
    +
    +#define RTIOC_TYPE_SMT RTDM_CLASS_EXPERIMENTAL
    +
    +#define RTSMT_RTIOC_INIT _IOR(RTIOC_TYPE_SMT, 0x00, rightI2CMod_t)
    +//#define RTSMT_RTIOC_CLEAN _IOR(RTIOC_TYPE_SMT, 0x01, int)
    +#define RTSMT_RTIOC_READ _IOR(RTIOC_TYPE_SMT, 0x02, rightReadBuf_t)
    +#define RTSMT_RTIOC_WRITE _IOR(RTIOC_TYPE_SMT, 0x03, rightWriteBuf_t)
    +
    +rightReadBuf_t rightReadBuf;
    +rightWriteBuf_t rightWriteBuf;
    +rightI2CMod_t rightI2CMod;
    +
    +/* XXX TODO #include "smarteh.h" */
    +""",
    + "MC9:On Board":"""
    +#define MAX_ONBOARD_DEVICES 2
    +unsigned char onBoardDev[MAX_ONBOARD_DEVICES][2]; /**< Tables containing information about enabled on-board devices (initialized by Composer) */
    +"""}
    +
    class LPCBus(object):
    @@ -359,12 +460,15 @@
    # define a unique name for the generated C file
    location_str = "_".join(map(str, current_location))
    + BusName = arch + ":" + self.BaseParams.getName()
    +
    code_str = {"location_str": location_str,
    "var_decl": "",
    "declare_code": "",
    "init_code": "",
    "retrieve_code": "",
    "publish_code": "",
    + "bus_code":bus_code.get(BusName,"")
    }
    for module in _GetModuleChildren(self):
    @@ -412,9 +516,12 @@
    if var["Publish"] != "":
    code_str["publish_code"] += " " + var["Publish"] % ("*" + var["location"]) + "\n"
    + if arch not in bus_template_code:
    + raise Exception, "Unknown arch %s. Please use %s"%(
    + arch,repr(bus_template_code.keys()))
    Gen_Module_path = os.path.join(buildpath, "Bus_%s.c"%location_str)
    module = open(Gen_Module_path,'w')
    - module.write(BUS_TEXT % code_str)
    + module.write(bus_template_code[arch] % code_str)
    module.close()
    matiec_flags = '"-I%s" -Wno-unused-function'%os.path.abspath(self.GetCTRoot().GetIECLibPath())
    @@ -558,38 +665,84 @@
    [SIMULATION_MODE, TRANSFER_MODE] = range(2)
    -class LPCProjectNodeEditor(ProjectNodeEditor):
    - SHOW_PARAMS = False
    - ENABLE_REQUIRED = False
    +if arch == "MC9" :
    + class LPCProjectNodeEditor(ProjectNodeEditor):
    + pass
    +else:
    + class LPCProjectNodeEditor(ProjectNodeEditor):
    + SHOW_PARAMS = False
    + ENABLE_REQUIRED = False
    +
    +
    +_StatusMethods = [
    + {"bitmap" : "Debug",
    + "name" : _("Simulate"),
    + "tooltip" : _("Simulate PLC"),
    + "method" : "_Simulate"},
    + {"bitmap" : "Run",
    + "name" : _("Run"),
    + "shown" : False,
    + "tooltip" : _("Start PLC"),
    + "method" : "_Run"},
    + {"bitmap" : "Stop",
    + "name" : _("Stop"),
    + "shown" : False,
    + "tooltip" : _("Stop Running PLC"),
    + "method" : "_Stop"},
    + {"bitmap" : "Build",
    + "name" : _("Build"),
    + "tooltip" : _("Build project into build folder"),
    + "method" : "_Build"},
    + {"bitmap" : "Transfer",
    + "name" : _("Transfer"),
    + "shown" : False,
    + "tooltip" : _("Transfer PLC"),
    + "method" : "_Transfer"},
    +]
    +_MethodFromPLCState = {
    + "Started" : [("_Simulate", False),
    + ("_Run", False),
    + ("_Stop", True),
    + ("_Build", True),
    + ("_Transfer", True)],
    + "Stopped" : [("_Simulate", False),
    + ("_Run", True),
    + ("_Stop", False),
    + ("_Build", True),
    + ("_Transfer", True)],
    + "Connected" : [("_Simulate", "not simulating"),
    + ("_Run", True),
    + ("_Stop", True if arch=="MC9" else "simulating"),
    + ("_Build", True),
    + ("_Transfer", True)],
    + "Disconnected" :[("_Simulate", "not simulating"),
    + ("_Run", False),
    + ("_Stop", True if arch=="MC9" else "simulating"),
    + ("_Build", True),
    + ("_Transfer", False)],
    +}
    +
    +if arch == "MC9" :
    + _StatusMethods += [
    + {"bitmap" : "Connect",
    + "name" : _("Connect"),
    + "shown" : True,
    + "tooltip" : _("Connect to the target PLC"),
    + "method" : "_Connect"},
    + {"bitmap" : "Disconnect",
    + "name" : _("Disconnect"),
    + "shown" : False,
    + "tooltip" : _("Disconnect from PLC"),
    + "method" : "_Disconnect"},
    + ]
    + _MethodFromPLCState["Disconnected"] += [("_Connect", True),
    + ("_Disconnect", False)]
    +
    + _MethodFromPLCState["Connected"] += [("_Connect", False),
    + ("_Disconnect", True)]
    class LPCProjectController(ProjectController):
    -
    - StatusMethods = [
    - {"bitmap" : "Debug",
    - "name" : _("Simulate"),
    - "tooltip" : _("Simulate PLC"),
    - "method" : "_Simulate"},
    - {"bitmap" : "Run",
    - "name" : _("Run"),
    - "shown" : False,
    - "tooltip" : _("Start PLC"),
    - "method" : "_Run"},
    - {"bitmap" : "Stop",
    - "name" : _("Stop"),
    - "shown" : False,
    - "tooltip" : _("Stop Running PLC"),
    - "method" : "_Stop"},
    - {"bitmap" : "Build",
    - "name" : _("Build"),
    - "tooltip" : _("Build project into build folder"),
    - "method" : "_Build"},
    - {"bitmap" : "Transfer",
    - "name" : _("Transfer"),
    - "shown" : False,
    - "tooltip" : _("Transfer PLC"),
    - "method" : "_Transfer"},
    - ]
    -
    + StatusMethods = _StatusMethods
    ConfNodeMethods = []
    EditorType = LPCProjectNodeEditor
    @@ -605,7 +758,7 @@
    self.CTNChildrenTypes += [("LPCBus", LPCBus, "LPC bus")]
    self.CTNType = "LPC"
    - self.OnlineMode = "OFF"
    + self.OnlineMode = "NORMAL" if arch=="MC9" else "OFF"
    self.LPCConnector = None
    self.ConnectorPath = None
    @@ -666,7 +819,7 @@
    def SetProjectName(self, name):
    return self.Project.setname(name)
    - def SetOnlineMode(self, mode, path=None):
    + def _SetOnlineMode(self, mode, path=None):
    mode = mode.upper()
    if self.OnlineMode != mode:
    if mode not in ["OFF", ""]:
    @@ -691,6 +844,8 @@
    self.ApplyOnlineMode()
    + SetOnlineMode = lambda *x:None if arch=="MC9" else _SetOnlineMode
    +
    def ApplyOnlineMode(self):
    if self.CurrentMode != SIMULATION_MODE:
    self.KillDebugThread()
    @@ -832,6 +987,17 @@
    def IsPLCStarted(self):
    return self.previous_plcstate == "Started" or self.previous_mode == SIMULATION_MODE
    + def ShowMethod(self, name, val):
    + simulating = self.CurrentMode == SIMULATION_MODE
    + if type(val) == str :
    + if val.endswith("simulating"):
    + if val.startswith("not"):
    + val = not simulating
    + else :
    + val = simulating
    +
    + ProjectController.ShowMethod(self, name, val)
    +
    def UpdateMethodsFromPLCStatus(self):
    simulating = self.CurrentMode == SIMULATION_MODE
    if self.OnlineMode == "OFF":
    @@ -851,28 +1017,7 @@
    else:
    status = "Disconnected"
    if self.previous_plcstate != status or self.previous_mode != self.CurrentMode:
    - for args in {
    - "Started" : [("_Simulate", False),
    - ("_Run", False),
    - ("_Stop", True),
    - ("_Build", True),
    - ("_Transfer", True)],
    - "Stopped" : [("_Simulate", False),
    - ("_Run", True),
    - ("_Stop", False),
    - ("_Build", True),
    - ("_Transfer", True)],
    - "Connected" : [("_Simulate", not simulating),
    - ("_Run", True),
    - ("_Stop", simulating),
    - ("_Build", True),
    - ("_Transfer", True)],
    - "Disconnected" :[("_Simulate", not simulating),
    - ("_Run", False),
    - ("_Stop", simulating),
    - ("_Build", True),
    - ("_Transfer", False)],
    - }.get(status,[]):
    + for args in _MethodFromPLCState.get(status,[]):
    self.ShowMethod(*args)
    self.previous_plcstate = status
    self.previous_mode = self.CurrentMode
    @@ -1142,16 +1287,19 @@
    def ResetBuildMD5(self):
    builder=self.GetBuilder()
    if builder is not None:
    - builder.ResetBinaryCodeMD5(self.OnlineMode)
    + builder.ResetBinaryCodeMD5(*([] if arch=="MC9" else [self.OnlineMode]))
    def GetLastBuildMD5(self):
    builder=self.GetBuilder()
    if builder is not None:
    - return builder.GetBinaryCodeMD5(self.OnlineMode)
    + return builder.GetBinaryCodeMD5(*([] if arch=="MC9" else [self.OnlineMode]))
    else:
    return None
    def _Transfer(self):
    + if self.OnlineMode == "NORMAL":
    + ProjectController._Transfer(self)
    + return
    if self.CurrentMode is None and self.OnlineMode != "OFF":
    self.CurrentMode = TRANSFER_MODE