--- a/ProjectController.py Sun Jan 18 20:38:34 2015 +0100
+++ b/ProjectController.py Thu Jan 29 19:11:34 2015 +0100
@@ -732,6 +732,7 @@
self._VariablesList = None
+ self._DbgVariablesList = None @@ -750,6 +751,7 @@
VariablesListAttributeName = ["num", "vartype", "IEC_path", "C_path", "type"]
+ self._DbgVariablesList = [] @@ -774,6 +776,7 @@
# second section contains all variables
for line in ListGroup[1]:
# Split and Maps each field to dictionnary entries
attrs = dict(zip(VariablesListAttributeName,line.strip().split(';')))
@@ -790,12 +793,17 @@
attrs["C_path"] = '__'.join(parts)
if attrs["vartype"] == "FB":
config_FBs[tuple(parts)] = attrs["C_path"]
- # Push this dictionnary into result.
+ if attrs["vartype"] != "FB": + # Push this dictionnary into result. + self._DbgVariablesList.append(attrs) + # Fill in IEC<->C translation dicts + IEC_path=attrs["IEC_path"] + self._IECPathToIdx[IEC_path]=(Idx, attrs["type"]) + # Ignores numbers given in CSV file + # Idx=int(attrs["num"]) + # Count variables only, ignore FBs self._VariablesList.append(attrs)
- # Fill in IEC<->C translation dicts
- IEC_path=attrs["IEC_path"]
- self._IECPathToIdx[IEC_path]=(Idx, attrs["type"])
# third section contains ticktime
@@ -816,8 +824,21 @@
self.GetIECProgramsAndVariables()
+ variable_decl_array = [] + for v in self._DbgVariablesList : + sz = DebugTypesSize.get(v["type"], 0) + variable_decl_array += [ + {"EXT":"%(type)s_P_ENUM", + "IN":"%(type)s_P_ENUM", + "MEM":"%(type)s_O_ENUM", + "OUT":"%(type)s_O_ENUM", + "VAR":"%(type)s_ENUM"}[v["vartype"]]%v + debug_code = targets.GetCode("plc_debug.c") % {
- "buffer_size": reduce(lambda x, y: x + y, [DebugTypesSize.get(v["type"], 0) for v in self._VariablesList], 0),
"\n".join(["extern %(type)s %(C_path)s;"%p for p in self._ProgramList]),
"extern_variables_declarations":"\n".join([
@@ -828,22 +849,8 @@
"VAR":"extern __IEC_%(type)s_t %(C_path)s;",
"FB":"extern %(type)s %(C_path)s;"}[v["vartype"]]%v
for v in self._VariablesList if v["C_path"].find('.')<0]),
- "for_each_variable_do_code":"\n".join([
- {"EXT":" (*fp)((void*)&(%(C_path)s),%(type)s_P_ENUM);\n",
- "IN":" (*fp)((void*)&(%(C_path)s),%(type)s_P_ENUM);\n",
- "MEM":" (*fp)((void*)&(%(C_path)s),%(type)s_O_ENUM);\n",
- "OUT":" (*fp)((void*)&(%(C_path)s),%(type)s_O_ENUM);\n",
- "VAR":" (*fp)((void*)&(%(C_path)s),%(type)s_ENUM);\n"}[v["vartype"]]%v
- for v in self._VariablesList if v["vartype"] != "FB" and v["type"] in DebugTypesSize ]),
- "find_variable_case_code":"\n".join([
- " *varp = (void*)&(%(C_path)s);\n"%v+
- {"EXT":" return %(type)s_P_ENUM;\n",
- "IN":" return %(type)s_P_ENUM;\n",
- "MEM":" return %(type)s_O_ENUM;\n",
- "OUT":" return %(type)s_O_ENUM;\n",
- "VAR":" return %(type)s_ENUM;\n"}[v["vartype"]]%v
- for v in self._VariablesList if v["vartype"] != "FB" and v["type"] in DebugTypesSize ])}
+ "variable_decl_array": ",\n".join(variable_decl_array) @@ -1307,7 +1314,7 @@
self.IECdebug_datas.pop(IECPath)
IECdebug_data[4] = reduce(
IECdebug_data[0].itervalues(),
self.IECdebug_lock.release()
--- a/targets/plc_debug.c Sun Jan 18 20:38:34 2015 +0100
+++ b/targets/plc_debug.c Thu Jan 29 19:11:34 2015 +0100
@@ -39,19 +39,23 @@
%(extern_variables_declarations)s
-typedef void(*__for_each_variable_do_fp)(void*, __IEC_types_enum);
+static dbgvardsc_t dbgvardsc[] = { +typedef void(*__for_each_variable_do_fp)(dbgvardsc_t*); void __for_each_variable_do(__for_each_variable_do_fp fp)
-%(for_each_variable_do_code)s
-__IEC_types_enum __find_variable(unsigned int varindex, void ** varp)
-%(find_variable_case_code)s
+ for(i = 0; i < sizeof(dbgvardsc)/sizeof(dbgvardsc_t); i++){ + dbgvardsc_t *dsc = &dbgvardsc[i]; + if(dsc->type != UNKNOWN_ENUM) @@ -70,12 +74,13 @@
forced_value_p = &((__IEC_##TYPENAME##_p *)varp)->fvalue;\
-void* UnpackVar(void* varp, __IEC_types_enum vartype, void **real_value_p, char *flags)
+void* UnpackVar(dbgvardsc_t *dsc, void **real_value_p, char *flags) void *forced_value_p = NULL;
@@ -88,14 +93,14 @@
void Remind(unsigned int offset, unsigned int count, void * p);
-void RemindIterator(void* varp, __IEC_types_enum vartype)
+void RemindIterator(dbgvardsc_t *dsc) void *real_value_p = NULL;
- UnpackVar(varp, vartype, &real_value_p, &flags);
+ UnpackVar(dsc, &real_value_p, &flags); if(flags & __IEC_RETAIN_FLAG){
- USINT size = __get_type_enum_size(vartype);
+ USINT size = __get_type_enum_size(dsc->type); /* compute next cursor positon*/
unsigned int next_retain_offset = retain_offset + size;
@@ -136,23 +141,23 @@
void Retain(unsigned int offset, unsigned int count, void * p);
-inline void BufferIterator(void* varp, __IEC_types_enum vartype, int do_debug)
+inline void BufferIterator(dbgvardsc_t *dsc, int do_debug) void *real_value_p = NULL;
void *visible_value_p = NULL;
- visible_value_p = UnpackVar(varp, vartype, &real_value_p, &flags);
+ visible_value_p = UnpackVar(dsc, &real_value_p, &flags); if(flags & ( __IEC_DEBUG_FLAG | __IEC_RETAIN_FLAG)){
- USINT size = __get_type_enum_size(vartype);
+ USINT size = __get_type_enum_size(dsc->type); if(flags & __IEC_DEBUG_FLAG){
/* copy visible variable to buffer */;
/* compute next cursor positon.
No need to check overflow, as BUFFER_SIZE
is computed large enough */
- if(vartype == STRING_ENUM){
+ if(dsc->type == STRING_ENUM){ /* optimization for strings */
size = ((STRING*)visible_value_p)->len + 1;
@@ -178,12 +183,12 @@
-void DebugIterator(void* varp, __IEC_types_enum vartype){
- BufferIterator(varp, vartype, 1);
+void DebugIterator(dbgvardsc_t *dsc){ + BufferIterator(dsc, 1); -void RetainIterator(void* varp, __IEC_types_enum vartype){
- BufferIterator(varp, vartype, 0);
+void RetainIterator(dbgvardsc_t *dsc){ + BufferIterator(dsc, 0); extern void PLC_GetTime(IEC_TIME*);
@@ -251,13 +256,18 @@
void RegisterDebugVariable(int idx, void* force)
- unsigned char flags = force ? __IEC_DEBUG_FLAG | __IEC_FORCE_FLAG : __IEC_DEBUG_FLAG;
- switch(__find_variable(idx, &varp)){
- __ANY(__RegisterDebugVariable_case_t)
- __ANY(__RegisterDebugVariable_case_p)
+ if(idx < sizeof(dbgvardsc)/sizeof(dbgvardsc_t)){ + unsigned char flags = force ? + __IEC_DEBUG_FLAG | __IEC_FORCE_FLAG : + dbgvardsc_t *dsc = &dbgvardsc[idx]; + __ANY(__RegisterDebugVariable_case_t) + __ANY(__RegisterDebugVariable_case_p) @@ -272,10 +282,11 @@
((__IEC_##TYPENAME##_p *)varp)->flags &= ~(__IEC_DEBUG_FLAG|__IEC_FORCE_FLAG);\
-void ResetDebugVariablesIterator(void* varp, __IEC_types_enum vartype)
+void ResetDebugVariablesIterator(dbgvardsc_t *dsc) /* force debug flag to 0*/
__ANY(__ResetDebugVariablesIterator_case_t)
__ANY(__ResetDebugVariablesIterator_case_p)