--- 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 @@
__builtin__.__dict__["BMZ_DBG"] = os.path.exists("LPC_DEBUG")
@@ -152,8 +153,8 @@
for size, types in LOCATIONDATATYPES.iteritems():
- LOCATION_SIZES[type] = size
+ LOCATION_SIZES[_type] = size def _GetModuleChildren(module):
@@ -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 */
@@ -237,7 +239,106 @@
+############################# +/* Code generated by LPCBus confnode */ + #include "iec_std_lib.h" +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); +/* LPCBus confnode user variables definition */ +/* LPCBus confnode functions */ +int __init_%(location_str)s(int argc,char **argv) +void __cleanup_%(location_str)s(void) +void __retrieve_%(location_str)s(void) +void __publish_%(location_str)s(void) +/* 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" */ +#define MAX_ONBOARD_DEVICES 2 +unsigned char onBoardDev[MAX_ONBOARD_DEVICES][2]; /**< Tables containing information about enabled on-board devices (initialized by Composer) */ @@ -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,
+ "bus_code":bus_code.get(BusName,"") for module in _GetModuleChildren(self):
@@ -412,9 +516,12 @@
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) 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):
- ENABLE_REQUIRED = False
+ class LPCProjectNodeEditor(ProjectNodeEditor): + class LPCProjectNodeEditor(ProjectNodeEditor): + ENABLE_REQUIRED = False + "name" : _("Simulate"), + "tooltip" : _("Simulate PLC"), + "method" : "_Simulate"}, + "tooltip" : _("Start PLC"), + "tooltip" : _("Stop Running PLC"), + "tooltip" : _("Build project into build folder"), + {"bitmap" : "Transfer", + "name" : _("Transfer"), + "tooltip" : _("Transfer PLC"), + "method" : "_Transfer"}, + "Started" : [("_Simulate", False), + "Stopped" : [("_Simulate", False), + "Connected" : [("_Simulate", "not simulating"), + ("_Stop", True if arch=="MC9" else "simulating"), + "Disconnected" :[("_Simulate", "not simulating"), + ("_Stop", True if arch=="MC9" else "simulating"), + "tooltip" : _("Connect to the target PLC"), + "method" : "_Connect"}, + {"bitmap" : "Disconnect", + "name" : _("Disconnect"), + "tooltip" : _("Disconnect from PLC"), + "method" : "_Disconnect"}, + _MethodFromPLCState["Disconnected"] += [("_Connect", True), + ("_Disconnect", False)] + _MethodFromPLCState["Connected"] += [("_Connect", False), class LPCProjectController(ProjectController):
- "name" : _("Simulate"),
- "tooltip" : _("Simulate PLC"),
- "method" : "_Simulate"},
- "tooltip" : _("Start PLC"),
- "tooltip" : _("Stop Running PLC"),
- "tooltip" : _("Build project into build folder"),
- {"bitmap" : "Transfer",
- "name" : _("Transfer"),
- "tooltip" : _("Transfer PLC"),
- "method" : "_Transfer"},
+ StatusMethods = _StatusMethods EditorType = LPCProjectNodeEditor
@@ -605,7 +758,7 @@
self.CTNChildrenTypes += [("LPCBus", LPCBus, "LPC bus")]
- self.OnlineMode = "OFF"
+ self.OnlineMode = "NORMAL" if arch=="MC9" else "OFF" 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): if self.OnlineMode != mode:
if mode not in ["OFF", ""]:
@@ -691,6 +844,8 @@
+ SetOnlineMode = lambda *x:None if arch=="MC9" else _SetOnlineMode def ApplyOnlineMode(self):
if self.CurrentMode != SIMULATION_MODE:
@@ -832,6 +987,17 @@
return self.previous_plcstate == "Started" or self.previous_mode == SIMULATION_MODE
+ def ShowMethod(self, name, val): + simulating = self.CurrentMode == SIMULATION_MODE + if val.endswith("simulating"): + if val.startswith("not"): + ProjectController.ShowMethod(self, name, val) def UpdateMethodsFromPLCStatus(self):
simulating = self.CurrentMode == SIMULATION_MODE
if self.OnlineMode == "OFF":
@@ -851,28 +1017,7 @@
if self.previous_plcstate != status or self.previous_mode != self.CurrentMode:
- "Started" : [("_Simulate", False),
- "Stopped" : [("_Simulate", False),
- "Connected" : [("_Simulate", not simulating),
- "Disconnected" :[("_Simulate", not simulating),
+ for args in _MethodFromPLCState.get(status,[]): self.previous_plcstate = status
self.previous_mode = self.CurrentMode
@@ -1142,16 +1287,19 @@
builder=self.GetBuilder()
- builder.ResetBinaryCodeMD5(self.OnlineMode)
+ builder.ResetBinaryCodeMD5(*([] if arch=="MC9" else [self.OnlineMode])) def GetLastBuildMD5(self):
builder=self.GetBuilder()
- return builder.GetBinaryCodeMD5(self.OnlineMode)
+ return builder.GetBinaryCodeMD5(*([] if arch=="MC9" else [self.OnlineMode])) + if self.OnlineMode == "NORMAL": + ProjectController._Transfer(self) if self.CurrentMode is None and self.OnlineMode != "OFF":
self.CurrentMode = TRANSFER_MODE