ProjectController.py
changeset 1430 754fa90c8b27
parent 1427 e01b52d948c3
child 1432 8872223a675b
equal deleted inserted replaced
1429:7e00c406d346 1430:754fa90c8b27
   814         Generate trace/debug code out of PLC variable list
   814         Generate trace/debug code out of PLC variable list
   815         """
   815         """
   816         self.GetIECProgramsAndVariables()
   816         self.GetIECProgramsAndVariables()
   817 
   817 
   818         # prepare debug code
   818         # prepare debug code
   819         debug_code = targets.GetCode("plc_debug") % {
   819         debug_code = targets.GetCode("plc_debug.c") % {
   820            "buffer_size": reduce(lambda x, y: x + y, [DebugTypesSize.get(v["type"], 0) for v in self._VariablesList], 0),
   820            "buffer_size": reduce(lambda x, y: x + y, [DebugTypesSize.get(v["type"], 0) for v in self._VariablesList], 0),
   821            "programs_declarations":
   821            "programs_declarations":
   822                "\n".join(["extern %(type)s %(C_path)s;"%p for p in self._ProgramList]),
   822                "\n".join(["extern %(type)s %(C_path)s;"%p for p in self._ProgramList]),
   823            "extern_variables_declarations":"\n".join([
   823            "extern_variables_declarations":"\n".join([
   824               {"EXT":"extern __IEC_%(type)s_p %(C_path)s;",
   824               {"EXT":"extern __IEC_%(type)s_p %(C_path)s;",
   857         locstrs = map(lambda x:"_".join(map(str,x)),
   857         locstrs = map(lambda x:"_".join(map(str,x)),
   858            [loc for loc,Cfiles,DoCalls in self.LocationCFilesAndCFLAGS if loc and DoCalls])
   858            [loc for loc,Cfiles,DoCalls in self.LocationCFilesAndCFLAGS if loc and DoCalls])
   859 
   859 
   860         # Generate main, based on template
   860         # Generate main, based on template
   861         if not self.BeremizRoot.getDisable_Extensions():
   861         if not self.BeremizRoot.getDisable_Extensions():
   862             plc_main_code = targets.GetCode("plc_main_head") % {
   862             plc_main_code = targets.GetCode("plc_main_head.c") % {
   863                 "calls_prototypes":"\n".join([(
   863                 "calls_prototypes":"\n".join([(
   864                       "int __init_%(s)s(int argc,char **argv);\n"+
   864                       "int __init_%(s)s(int argc,char **argv);\n"+
   865                       "void __cleanup_%(s)s(void);\n"+
   865                       "void __cleanup_%(s)s(void);\n"+
   866                       "void __retrieve_%(s)s(void);\n"+
   866                       "void __retrieve_%(s)s(void);\n"+
   867                       "void __publish_%(s)s(void);")%{'s':locstr} for locstr in locstrs]),
   867                       "void __publish_%(s)s(void);")%{'s':locstr} for locstr in locstrs]),
   877                 "cleanup_calls":"\n    ".join([
   877                 "cleanup_calls":"\n    ".join([
   878                       "if(init_level >= %d) "%i+
   878                       "if(init_level >= %d) "%i+
   879                       "__cleanup_%s();"%locstrs[i-1] for i in xrange(len(locstrs), 0, -1)])
   879                       "__cleanup_%s();"%locstrs[i-1] for i in xrange(len(locstrs), 0, -1)])
   880                 }
   880                 }
   881         else:
   881         else:
   882             plc_main_code = targets.GetCode("plc_main_head") % {
   882             plc_main_code = targets.GetCode("plc_main_head.c") % {
   883                 "calls_prototypes":"\n",
   883                 "calls_prototypes":"\n",
   884                 "retrieve_calls":"\n",
   884                 "retrieve_calls":"\n",
   885                 "publish_calls":"\n",
   885                 "publish_calls":"\n",
   886                 "init_calls":"\n",
   886                 "init_calls":"\n",
   887                 "cleanup_calls":"\n"
   887                 "cleanup_calls":"\n"
   888                 }
   888                 }
   889         plc_main_code += targets.GetTargetCode(self.GetTarget().getcontent().getLocalTag())
   889         plc_main_code += targets.GetTargetCode(self.GetTarget().getcontent().getLocalTag())
   890         plc_main_code += targets.GetCode("plc_main_tail")
   890         plc_main_code += targets.GetCode("plc_main_tail.c")
   891         return plc_main_code
   891         return plc_main_code
   892 
   892 
   893 
   893 
   894     def _Build(self):
   894     def _Build(self):
   895         """
   895         """
  1265 
  1265 
  1266     def GetDebugIECVariableType(self, IECPath):
  1266     def GetDebugIECVariableType(self, IECPath):
  1267         Idx, IEC_Type = self._IECPathToIdx.get(IECPath,(None,None))
  1267         Idx, IEC_Type = self._IECPathToIdx.get(IECPath,(None,None))
  1268         return IEC_Type
  1268         return IEC_Type
  1269 
  1269 
  1270     def SubscribeDebugIECVariable(self, IECPath, callableobj, buffer_list=False, *args, **kwargs):
  1270     def SubscribeDebugIECVariable(self, IECPath, callableobj, buffer_list=False):
  1271         """
  1271         """
  1272         Dispatching use a dictionnary linking IEC variable paths
  1272         Dispatching use a dictionnary linking IEC variable paths
  1273         to a WeakKeyDictionary linking
  1273         to a WeakKeyDictionary linking
  1274         weakly referenced callables to optionnal args
  1274         weakly referenced callables
  1275         """
  1275         """
  1276         if IECPath != "__tick__" and not self._IECPathToIdx.has_key(IECPath):
  1276         if IECPath != "__tick__" and not self._IECPathToIdx.has_key(IECPath):
  1277             return None
  1277             return None
  1278 
  1278 
  1279         self.IECdebug_lock.acquire()
  1279         self.IECdebug_lock.acquire()
  1288                     buffer_list]                # Forced value
  1288                     buffer_list]                # Forced value
  1289             self.IECdebug_datas[IECPath] = IECdebug_data
  1289             self.IECdebug_datas[IECPath] = IECdebug_data
  1290         else:
  1290         else:
  1291             IECdebug_data[4] |= buffer_list
  1291             IECdebug_data[4] |= buffer_list
  1292 
  1292 
  1293         IECdebug_data[0][callableobj]=(buffer_list, args, kwargs)
  1293         IECdebug_data[0][callableobj]=buffer_list
  1294 
  1294 
  1295         self.IECdebug_lock.release()
  1295         self.IECdebug_lock.release()
  1296 
  1296 
  1297         self.ReArmDebugRegisterTimer()
  1297         self.ReArmDebugRegisterTimer()
  1298 
  1298 
  1305             IECdebug_data[0].pop(callableobj,None)
  1305             IECdebug_data[0].pop(callableobj,None)
  1306             if len(IECdebug_data[0]) == 0:
  1306             if len(IECdebug_data[0]) == 0:
  1307                 self.IECdebug_datas.pop(IECPath)
  1307                 self.IECdebug_datas.pop(IECPath)
  1308             else:
  1308             else:
  1309                 IECdebug_data[4] = reduce(
  1309                 IECdebug_data[4] = reduce(
  1310                     lambda x, y: x|y,
  1310                     lambda x, y: x|y, 
  1311                     [buffer_list for buffer_list,args,kwargs
  1311                     IECdebug_data[0].itervalues(),
  1312                      in IECdebug_data[0].itervalues()],
       
  1313                     False)
  1312                     False)
  1314         self.IECdebug_lock.release()
  1313         self.IECdebug_lock.release()
  1315 
  1314 
  1316         self.ReArmDebugRegisterTimer()
  1315         self.ReArmDebugRegisterTimer()
  1317 
  1316 
  1355     def CallWeakcallables(self, IECPath, function_name, *cargs):
  1354     def CallWeakcallables(self, IECPath, function_name, *cargs):
  1356         data_tuple = self.IECdebug_datas.get(IECPath, None)
  1355         data_tuple = self.IECdebug_datas.get(IECPath, None)
  1357         if data_tuple is not None:
  1356         if data_tuple is not None:
  1358             WeakCallableDict, data_log, status, fvalue, buffer_list = data_tuple
  1357             WeakCallableDict, data_log, status, fvalue, buffer_list = data_tuple
  1359             #data_log.append((debug_tick, value))
  1358             #data_log.append((debug_tick, value))
  1360             for weakcallable,(buffer_list,args,kwargs) in WeakCallableDict.iteritems():
  1359             for weakcallable,buffer_list in WeakCallableDict.iteritems():
  1361                 function = getattr(weakcallable, function_name, None)
  1360                 function = getattr(weakcallable, function_name, None)
  1362                 if function is not None:
  1361                 if function is not None:
  1363                     if buffer_list:
  1362                     if buffer_list:
  1364                         function(*(cargs + args), **kwargs)
  1363                         function(*cargs)
  1365                     else:
  1364                     else:
  1366                         function(*(tuple([lst[-1] for lst in cargs]) + args), **kwargs)
  1365                         function(*tuple([lst[-1] for lst in cargs]))
  1367 
  1366 
  1368     def GetTicktime(self):
  1367     def GetTicktime(self):
  1369         return self._Ticktime
  1368         return self._Ticktime
  1370 
  1369 
  1371     def RemoteExec(self, script, **kwargs):
  1370     def RemoteExec(self, script, **kwargs):