LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
authoredouard
Tue, 15 Dec 2009 18:24:50 +0100
changeset 521 02cb9e5fb6f6
parent 520 ca5a2047e0ed
child 522 6bd373f930f2
LPC transfer tested, added PLCInfo along MD5 checksum while invoking makefile
LPCBeremiz.py
connectors/LPC/LPCObject.py
targets/LPC/plc_LPC_main.c
targets/Win32/plc_Win32_main.c
targets/plc_debug.c
targets/toolchain_makefile.py
--- a/LPCBeremiz.py	Tue Dec 15 16:04:28 2009 +0100
+++ b/LPCBeremiz.py	Tue Dec 15 18:24:50 2009 +0100
@@ -561,7 +561,7 @@
             if self._connector is not None:
                 simulating = self._connector.GetPLCstatus() == "Started"
             status = "Disconnected"
-        elif self.OnlineMode == 1:
+        elif self.OnlineMode == 2:
             if self._connector is not None:
                 simulating = self._connector.GetPLCstatus() == "Started"
             status = "Connected"
--- a/connectors/LPC/LPCObject.py	Tue Dec 15 16:04:28 2009 +0100
+++ b/connectors/LPC/LPCObject.py	Tue Dec 15 18:24:50 2009 +0100
@@ -93,11 +93,31 @@
         return self.PLCStatus
     
     def NewPLC(self, md5sum, data, extrafiles):
-        pass
+        if os.path.exists(self.StorageConnection):
+            firmwarepath = os.path.join(
+                    self.StorageConnection, 
+                    "firmware.bin")
+            try:
+                if os.path.exists(firmwarepath ):
+                    os.unlink(firmwarepath)
+                f = open(firmwarepath, "wb")
+                f.write(data)
+                f.close()
+                return True
+            except LPCError,e:
+                self.StorageConnection = None
+                self.PLCStatus = "Disconnected"
+                self.pluginsroot.logger.write_error(
+                                    "LPC transfer error : "+
+                                    str(e)+"\n")
 
     def MatchMD5(self, MD5):
-        data = self.HandleSerialTransaction(PLCIDTransaction())
-        return data == MD5
+        data = self.HandleSerialTransaction(GET_PLCIDTransaction())
+        return data[:32] == MD5
+
+    def GetPLCInfo(self, MD5):
+        data = self.HandleSerialTransaction(GET_PLCIDTransaction())
+        return data[32:]
 
     class IEC_STRING(ctypes.Structure):
         """
--- a/targets/LPC/plc_LPC_main.c	Tue Dec 15 16:04:28 2009 +0100
+++ b/targets/LPC/plc_LPC_main.c	Tue Dec 15 18:24:50 2009 +0100
@@ -82,10 +82,18 @@
     __DEBUG = 1;
 }
 
+int CheckRetainBuffer(void)
+{
+	/* TODO : compare RETAIN buffer start with MD5 */
+	return 0;
+}
+
 void Retain(unsigned int offset, unsigned int count, void *p)
 {
+	/* TODO : write in RETAIN buffer at offset*/
 }
 
 void Remind(unsigned int offset, unsigned int count, void *p)
 {
+	/* TODO : read at offset in RETAIN buffer */
 }
--- a/targets/Win32/plc_Win32_main.c	Tue Dec 15 16:04:28 2009 +0100
+++ b/targets/Win32/plc_Win32_main.c	Tue Dec 15 18:24:50 2009 +0100
@@ -227,6 +227,11 @@
 	WaitForSingleObject(python_sem, INFINITE);
 }
 
+int CheckRetainBuffer(void)
+{
+	return 1;
+}
+
 void Retain(unsigned int offset, unsigned int count, void * p)
 {
     unsigned int position;
--- a/targets/plc_debug.c	Tue Dec 15 16:04:28 2009 +0100
+++ b/targets/plc_debug.c	Tue Dec 15 18:24:50 2009 +0100
@@ -102,6 +102,8 @@
     }
 }
 
+int CheckRetainBuffer(void);
+
 void __init_debug(void)
 {
     /* init local static vars */
@@ -109,7 +111,8 @@
     retain_offset = 0;
     buffer_state = BUFFER_FREE;
     /* Iterate over all variables to fill debug buffer */
-    __for_each_variable_do(RemindIterator);
+    if(CheckRetainBuffer())
+    	__for_each_variable_do(RemindIterator);
     retain_offset = 0;
 }
 
--- a/targets/toolchain_makefile.py	Tue Dec 15 16:04:28 2009 +0100
+++ b/targets/toolchain_makefile.py	Tue Dec 15 18:24:50 2009 +0100
@@ -2,6 +2,8 @@
 from wxPopen import ProcessLogger
 import hashlib
 
+import time
+
 includes_re =  re.compile('\s*#include\s*["<]([^">]*)[">].*')
 
 class toolchain_makefile():
@@ -48,6 +50,11 @@
                     cflags.append(CFLAGS)
                     
             self.md5key = hashlib.md5(wholesrcdata).hexdigest()
+            props = self.PluginsRootInstance.GetProjectProperties()
+            self.md5key += '|'.join([props[key] for key in ['companyName',
+                                                            'projectName',
+                                                            'productName']])
+            self.md5key += '|'+','.join(map(str,time.localtime()))
             # Store new PLC filename based on md5 key
             f = open(self._GetMD5FileName(), "w")
             f.write(self.md5key)