--- a/LPCconnector/LPCAppObject.py Wed Mar 13 12:04:18 2013 +0900
+++ b/LPCconnector/LPCAppObject.py Tue Mar 19 17:22:27 2013 +0900
@@ -45,8 +45,11 @@
return self.PLCStatus
def GetPLCstatus(self):
- self.HandleSerialTransaction(GET_PLCIDTransaction())
- return self.PLCStatus
+ strcounts = self.HandleSerialTransaction(GET_LOGCOUNTSTransaction())
+ ccounts = ctypes.cast(
+ ctypes.c_char_p(strcounts),
+ ctypes.POINTER(ctypes.c_uint32))
+ return (self.PLCStatus,)+tuple(int(ccounts[idx]) for idx in range(4))
def MatchMD5(self, MD5):
data = self.HandleSerialTransaction(GET_PLCIDTransaction())
@@ -118,3 +121,11 @@
#PLCprint("Debug error - wrong buffer unpack !")
return self.PLCStatus, None, []
+ def GetLogMessage(self, level, msgid):
+ strbuf = self.HandleSerialTransaction(GET_LOGMSGTransaction(level, msgid))
+ if len(strbuf) > 12:
+ cbuf = ctypes.cast(
+ ctypes.c_char_p(strbuf[:12]),
+ ctypes.POINTER(ctypes.c_uint32))
+ return (strbuf[12:],)+tuple(int(cbuf[idx]) for idx in range(3))
+ return None
--- a/LPCconnector/LPCAppProto.py Wed Mar 13 12:04:18 2013 +0900
+++ b/LPCconnector/LPCAppProto.py Tue Mar 19 17:22:27 2013 +0900
@@ -23,9 +23,8 @@
return LPC_STATUS.get(current_plc_status,"Broken"), res
class LPCAppTransaction:
- def __init__(self, command, optdata = ""):
+ def __init__(self, command):
self.Command = command
- self.OptData = optdata
self.pseudofile = None
def SetPseudoFile(self, pseudofile):
@@ -46,12 +45,12 @@
return current_plc_status
return None
- def SendData(self):
- length = len(self.OptData)
+ def SendData(self, Data):
+ length = len(Data)
# transform length into a byte string
# we presuppose endianess of LPC same as PC
lengthstr = ctypes.string_at(ctypes.pointer(ctypes.c_int(length)),4)
- buffer = lengthstr + self.OptData
+ buffer = lengthstr + Data
return self.pseudofile.write(buffer)
def GetData(self):
@@ -82,8 +81,10 @@
class SET_TRACE_VARIABLETransaction(LPCAppTransaction):
def __init__(self, data):
- LPCAppTransaction.__init__(self, 0x04, data)
- ExchangeData = LPCAppTransaction.SendData
+ LPCAppTransaction.__init__(self, 0x04)
+ self.Data = data
+ def ExchangeData(self):
+ self.SendData(self.Data)
class GET_TRACE_VARIABLETransaction(LPCAppTransaction):
def __init__(self):
@@ -95,6 +96,21 @@
LPCAppTransaction.__init__(self, 0x07)
ExchangeData = LPCAppTransaction.GetData
+class GET_LOGCOUNTSTransaction(LPCAppTransaction):
+ def __init__(self):
+ LPCAppTransaction.__init__(self, 0x0B)
+ ExchangeData = LPCAppTransaction.GetData
+
+class GET_LOGMSGTransaction(LPCAppTransaction):
+ def __init__(self,level,msgid):
+ LPCAppTransaction.__init__(self, 0x0C)
+ msgidstr = ctypes.string_at(ctypes.pointer(ctypes.c_int(msgid)),4)
+ self.Data = chr(level)+msgidstr
+
+ def ExchangeData(self):
+ self.SendData(self.Data)
+ return self.GetData()
+
if __name__ == "__main__":
__builtins__.BMZ_DBG = True
TestConnection = LPCAppProto(6,115200,2)
--- a/LPCtarget/plc_LPC_main.c Wed Mar 13 12:04:18 2013 +0900
+++ b/LPCtarget/plc_LPC_main.c Tue Mar 19 17:22:27 2013 +0900
@@ -1,19 +1,18 @@
/**
- * Yagarto specific code
+ * LPC specific code
**/
#include <string.h>
#include <app_glue.h>
-/* provided by POUS.C */
-extern unsigned long long common_ticktime__;
-extern unsigned long __tick;
-
extern unsigned long idLen;
extern unsigned char *idBuf;
-static unsigned char RetainedIdBuf[128] __attribute__((section (".nvolatile")));
-static unsigned char retain_buffer[RETAIN_BUFFER_SIZE] __attribute__((section (".nvolatile")));
+static unsigned char RetainedIdBuf[128] NONVOLATILE;
+static unsigned char retain_buffer[RETAIN_BUFFER_SIZE] NONVOLATILE;
+
+#define LOG_BUFFER_SIZE (1<<10) /*1Ko*/
+#define LOG_BUFFER_ATTRS NONVOLATILE
static int debug_locked = 0;
static int _DebugDataAvailable = 0;
@@ -47,8 +46,7 @@
int startPLC(int argc,char **argv)
{
if(__init(argc,argv) == 0){
- /* sign retain buffer */
- PLC_SetTimer(0, common_ticktime__);
+ PLC_SetTimer(0, Ttick);
return 0;
}else{
return 1;