--- a/Beremiz.py Thu Feb 03 18:23:24 2011 +0100
+++ b/Beremiz.py Thu Feb 17 10:11:04 2011 +0100
@@ -65,7 +65,12 @@
+ if os.path.exists("BEREMIZ_DEBUG"): + __builtins__.BMZ_DBG = True + __builtins__.BMZ_DBG = False + app = wx.PySimpleApp(redirect=BMZ_DBG) app.SetAppName('beremiz')
wx.InitAllImageHandlers()
--- a/LPCBeremiz.py Thu Feb 03 18:23:24 2011 +0100
+++ b/LPCBeremiz.py Thu Feb 17 10:11:04 2011 +0100
@@ -42,7 +42,12 @@
+ if os.path.exists("LPC_DEBUG"): + __builtins__.BMZ_DBG = True + __builtins__.BMZ_DBG = False +app = wx.PySimpleApp(redirect=BMZ_DBG) app.SetAppName('beremiz')
wx.InitAllImageHandlers()
@@ -370,7 +375,7 @@
elif os.path.isfile(srcpath):
shutil.copy2(srcpath, dstpath)
-[SIMULATION_MODE, TRANSFER_MODE] = range(2)
+[SIMULATION_MODE, ONLINE_MODE] = range(2) class LPCPluginsRoot(PluginsRoot):
@@ -489,19 +494,20 @@
if self.StatusTimer and not self.StatusTimer.IsRunning():
- self.StatusTimer.Start(milliseconds=500, oneShot=False)
+ self.StatusTimer.Start(milliseconds=1000, oneShot=False) if self.previous_plcstate=="Started":
if self.DebugAvailable() and self.GetIECProgramsAndVariables():
self.logger.write(_("Debug connect matching running PLC\n"))
self.logger.write_warning(_("Debug do not match PLC - stop/transfert/start to re-enable\n"))
elif self.StatusTimer and self.StatusTimer.IsRunning():
- if self.CurrentMode == TRANSFER_MODE:
+ if self.CurrentMode == ONLINE_MODE: if self.OnlineMode == "BOOTLOADER":
@@ -607,7 +613,7 @@
"Connected" : [("_Simulate", not simulating),
@@ -780,9 +786,16 @@
# warns controller that program match
self.ProgramTransferred()
+ def GetLastBuildMD5(self): + builder=self.GetBuilder() + if builder is not None: + return builder.GetBinaryCodeMD5(self.OnlineMode) if self.CurrentMode is None and self.OnlineMode != "OFF":
- self.CurrentMode = TRANSFER_MODE
+ self.CurrentMode = ONLINE_MODE @@ -814,6 +827,19 @@
self.AbortTransferTimer = None
+ if self.GetIECProgramsAndVariables(): + self._connector.StartPLC() + self.logger.write(_("Starting PLC\n")) + self.logger.write_error(_("Couldn't start PLC !\n")) + self.UpdateMethodsFromPLCStatus() #-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
@@ -1090,6 +1116,8 @@
line = self.Buffer[:idx+1]
self.Buffer = self.Buffer[idx+1:]
@@ -1132,8 +1160,8 @@
# Command log for debug, for viewing from wxInspector
- __builtins__.cmdlog = []
- #cmdlogf=open("bmzcmdlog.txt","w")
+ __builtins__.cmdlog = [] class LPCBeremiz_Cmd(cmd.Cmd):
@@ -1421,19 +1449,13 @@
- #cmdlogf.write(str((function,line))+'\n')
func = getattr(self, function)
res = evaluator(func,*args)
- #cmdlogf.write("--->"+str(res)+'\n')
- cmdlog.append((function,line,res))
- if len(cmdlog) > 100: #prevent debug log to grow too much
+ cmdlog.append((function,line,res)) + if len(cmdlog) > 100: #prevent debug log to grow too much if isinstance(res, (StringType, UnicodeType)):
--- a/connectors/LPC/LPCAppProto.py Thu Feb 03 18:23:24 2011 +0100
+++ b/connectors/LPC/LPCAppProto.py Thu Feb 17 10:11:04 2011 +0100
@@ -96,6 +96,7 @@
ExchangeData = LPCAppTransaction.GetData
if __name__ == "__main__":
+ __builtins__.BMZ_DBG = True TestConnection = LPCAppProto(6,115200,2)
# TestConnection.HandleTransaction(GET_PLCIDTransaction())
TestConnection.HandleTransaction(STARTTransaction())
--- a/connectors/LPC/LPCBootObject.py Thu Feb 03 18:23:24 2011 +0100
+++ b/connectors/LPC/LPCBootObject.py Thu Feb 17 10:11:04 2011 +0100
@@ -37,12 +37,16 @@
self.HandleSerialTransaction(KEEPBOOTINGTransaction())
self.PLCStatus = "Stopped"
+ def StartPLC(self, debug=False): + self.HandleSerialTransaction(STARTTransaction()) def NewPLC(self, md5sum, data, extrafiles):
self.successfully_transfered = self.HandleSerialTransaction(LOADTransaction(data, self.PLCprint))
return self.successfully_transfered
- return self.successfully_transfered
+ res = self.HandleSerialTransaction(CHECKMD5Transaction(MD5)) + return "".join(res).find('FAILED') == -1 def SetTraceVariablesList(self, idxs):
--- a/connectors/LPC/LPCBootProto.py Thu Feb 03 18:23:24 2011 +0100
+++ b/connectors/LPC/LPCBootProto.py Thu Feb 17 10:11:04 2011 +0100
@@ -18,27 +18,31 @@
def SetPseudoFile(self, pseudofile):
self.pseudofile = pseudofile
- res = self.pseudofile.write(self.OptData)
+ self.pseudofile.write(self.OptData) + return map(lambda x:self.pseudofile.readline(), xrange(self.expectedlines)) class KEEPBOOTINGTransaction(LPCBootTransaction):
LPCBootTransaction.__init__(self, "md5\n")
- ExchangeData = LPCBootTransaction.SendData
+class STARTTransaction(LPCBootTransaction): + LPCBootTransaction.__init__(self, "go\n") +class CHECKMD5Transaction(LPCBootTransaction): + def __init__(self, md5ref): + LPCBootTransaction.__init__(self, md5ref+"md5\n") class LOADTransaction(LPCBootTransaction):
def __init__(self, data, PLCprint):
LPCBootTransaction.__init__(self, data)
- def sendDataHook(self):
+ def ExchangeData(self): #file("fw.bin","w").write(self.OptData)
loptdata = len(self.OptData)
@@ -54,9 +58,9 @@
- ExchangeData = sendDataHook
if __name__ == "__main__":
+ __builtins__.BMZ_DBG = True TestConnection = LPCBootProto(2,115200,1200)
mystr=file("fw.bin").read()
--- a/connectors/LPC/LPCProto.py Thu Feb 03 18:23:24 2011 +0100
+++ b/connectors/LPC/LPCProto.py Thu Feb 17 10:11:04 2011 +0100
@@ -1,6 +1,7 @@
from threading import Lock
class LPCProtoError(exceptions.Exception):
@@ -14,29 +15,45 @@
def __init__(self, port, rate, timeout):
self.TransactionLock = Lock()
-# self.serialPort = serial.Serial( port, rate, timeout = timeout )
- # Debugging serial stuff
- self.serialPort = serial.Serial( port, rate, timeout = timeout )
-# res = self._serialPort.read(cnt)
-# print "Recv :", map(hex,map(ord,res[:16])), "[...]"
-# print "Recv :", map(hex,map(ord,res))
-# def write(self_, str):
-# print "Send :", map(hex,map(ord,str[:16])), "[...]"
-# print "Send :", map(hex,map(ord,str))
-# self._serialPort.write(str)
-# self._serialPort.flush()
-# self.serialPort = myser()
+ # Debugging serial stuff + self._serialPort = serial.Serial( port, rate, timeout = timeout, writeTimeout = timeout ) + res = self._serialPort.readline() + print 'Recv :"', res, '"' + res = self._serialPort.read(cnt) + print "Recv :", map(hex,map(ord,res[:16])), "[...]" + print "Recv :", map(hex,map(ord,res)) + def write(self_, string): + print "Send :", map(hex,map(ord,string[:16])), "[...]" + print "Send :", map(hex,map(ord,string)) + return self._serialPort.write(string) + # i = self._serialPort.write(string[:4096]) + return self._serialPort.flush() + self._serialPort.close() + self.serialPort = myser() + self.serialPort = serial.Serial( port, rate, timeout = timeout ) + # start with empty buffer --- a/targets/LPC/__init__.py Thu Feb 03 18:23:24 2011 +0100
+++ b/targets/LPC/__init__.py Thu Feb 17 10:11:04 2011 +0100
@@ -1,22 +1,56 @@
-from subprocess import Popen,PIPE
-from .. import toolchain_makefile
-class LPC_target(toolchain_makefile):
- def GetBinaryCode(self):
- """Returns ready to send signed + sized intel formated hex program"""
- ['arm-elf-size','-B',os.path.join(self.buildpath,"ArmPLC_rom.elf")],
- stdout=PIPE).communicate()[0].splitlines()[1].split()[0])
- res = "&" + hashlib.md5(open(os.path.join(self.buildpath, "ArmPLC_rom.bin"), "rb").read(size)).hexdigest() + '\n' +\
- "$" + str(size) + '\n' +\
- open(os.path.join(self.buildpath, "ArmPLC_rom.hex"), "r").read()
+from subprocess import Popen,PIPE +from .. import toolchain_makefile +class LPC_target(toolchain_makefile): + def __init__(self, PluginsRootInstance): + toolchain_makefile.__init__(self, PluginsRootInstance) + def _GetBinMD5FileName(self): + return os.path.join(self.buildpath, "lastbuildPLCbin.md5") + def _get_md5_header(self): + """Returns signature header""" + ['arm-elf-size','-B',os.path.join(self.buildpath,"ArmPLC_rom.elf")], + stdout=PIPE).communicate()[0].splitlines()[1].split()[0]) + res = "&" + hashlib.md5(open(os.path.join(self.buildpath, "ArmPLC_rom.bin"), "rb").read(size)).hexdigest() + '\n' +\ + def GetBinaryCode(self): + """Returns ready to send signed + sized intel formated hex program""" + res = self._get_md5_header() +\ + open(os.path.join(self.buildpath, "ArmPLC_rom.hex"), "r").read() + def _get_cached_md5_header(self): + if self.binmd5key is not None: + return open(self._GetMD5FileName(), "r").read() + def GetBinaryCodeMD5(self, mode): + if mode == "BOOTLOADER": + return self._get_cached_md5_header() + return toolchain_makefile.GetBinaryCodeMD5(self) + res = toolchain_makefile.build(self) + self.binmd5key = self._get_md5_header() + f = open(self._GetBinMD5FileName(), "w") + f.write(self.binmd5key) --- a/targets/toolchain_makefile.py Thu Feb 03 18:23:24 2011 +0100
+++ b/targets/toolchain_makefile.py Thu Feb 17 10:11:04 2011 +0100
@@ -1,74 +1,74 @@
-from wxPopen import ProcessLogger
-includes_re = re.compile('\s*#include\s*["<]([^">]*)[">].*')
-class toolchain_makefile():
- def __init__(self, PluginsRootInstance):
- self.PluginsRootInstance = PluginsRootInstance
- self.SetBuildPath(self.PluginsRootInstance._getBuildPath())
- def SetBuildPath(self, buildpath):
- self.buildpath = buildpath
- def GetBinaryCode(self):
- def _GetMD5FileName(self):
- return os.path.join(self.buildpath, "lastbuildPLC.md5")
- def GetBinaryCodeMD5(self):
- if self.md5key is not None:
- return open(self._GetMD5FileName(), "r").read()
- for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS:
- # Get CFiles list to give it to makefile
- for CFile, CFLAGS in CFilesAndCFLAGS:
- CFileName = os.path.basename(CFile)
- wholesrcdata += open(CFile, "r").read()
- srcfiles.append(CFileName)
- if CFLAGS not in cflags:
- self.md5key = hashlib.md5(wholesrcdata).hexdigest()
- props = self.PluginsRootInstance.GetProjectProperties()
- self.md5key += '#'.join([props[key] for key in ['companyName',
- self.md5key += '#'+','.join(map(str,time.localtime()))
- # Store new PLC filename based on md5 key
- f = open(self._GetMD5FileName(), "w")
- beremizcommand = {"src": ' '.join(srcfiles),
- "cflags": ' '.join(cflags),
- "md5": '"'+self.md5key+'"'
- target = self.PluginsRootInstance.GetTarget().getcontent()["value"]
- command = target.getCommand().split(' ') +\
- [target.getBuildPath()] +\
- [arg % beremizcommand for arg in target.getArguments().split(' ')] +\
- target.getRule().split(' ')
- # Call Makefile to build PLC code and link it with target specific code
- status, result, err_result = ProcessLogger(self.PluginsRootInstance.logger,
- self.PluginsRootInstance.logger.write_error(_("C compilation of %s failed.\n"))
+from wxPopen import ProcessLogger +includes_re = re.compile('\s*#include\s*["<]([^">]*)[">].*') +class toolchain_makefile(): + def __init__(self, PluginsRootInstance): + self.PluginsRootInstance = PluginsRootInstance + self.SetBuildPath(self.PluginsRootInstance._getBuildPath()) + def SetBuildPath(self, buildpath): + self.buildpath = buildpath + def GetBinaryCode(self): + def _GetMD5FileName(self): + return os.path.join(self.buildpath, "lastbuildPLC.md5") + def GetBinaryCodeMD5(self): + if self.md5key is not None: + return open(self._GetMD5FileName(), "r").read() + for Location, CFilesAndCFLAGS, DoCalls in self.PluginsRootInstance.LocationCFilesAndCFLAGS: + # Get CFiles list to give it to makefile + for CFile, CFLAGS in CFilesAndCFLAGS: + CFileName = os.path.basename(CFile) + wholesrcdata += open(CFile, "r").read() + srcfiles.append(CFileName) + if CFLAGS not in cflags: + self.md5key = hashlib.md5(wholesrcdata).hexdigest() + props = self.PluginsRootInstance.GetProjectProperties() + self.md5key += '#'.join([props[key] for key in ['companyName', + self.md5key += '#' #+','.join(map(str,time.localtime())) + # Store new PLC filename based on md5 key + f = open(self._GetMD5FileName(), "w") + beremizcommand = {"src": ' '.join(srcfiles), + "cflags": ' '.join(cflags), + "md5": '"'+self.md5key+'"' + target = self.PluginsRootInstance.GetTarget().getcontent()["value"] + command = target.getCommand().split(' ') +\ + [target.getBuildPath()] +\ + [arg % beremizcommand for arg in target.getArguments().split(' ')] +\ + target.getRule().split(' ') + # Call Makefile to build PLC code and link it with target specific code + status, result, err_result = ProcessLogger(self.PluginsRootInstance.logger, + self.PluginsRootInstance.logger.write_error(_("C compilation of %s failed.\n"))