svghmi.c : deduplicated variable access code borrowed from plc_debug.c. Added targets/var_access.c.
--- a/ProjectController.py Fri Aug 23 14:01:31 2019 +0200
+++ b/ProjectController.py Mon Aug 26 08:54:02 2019 +0200
@@ -1053,7 +1053,8 @@
"FB": "extern %(type)s %(C_path)s;"
}[v["vartype"]] % v
for v in self._VariablesList if v["C_path"].find('.') < 0]),
- "variable_decl_array": ",\n".join(variable_decl_array)
+ "variable_decl_array": ",\n".join(variable_decl_array),
+ "var_access_code": targets.GetCode("var_access.c")
}
return debug_code
--- a/svghmi/svghmi.c Fri Aug 23 14:01:31 2019 +0200
+++ b/svghmi/svghmi.c Mon Aug 26 08:54:02 2019 +0200
@@ -39,39 +39,9 @@
}
}
-/* TODO : deduplicate that code with plc_debug.c */
+#define __Unpack_desc_type hmi_tree_item_t
-#define __Unpack_case_t(TYPENAME) \
- case TYPENAME##_ENUM :\
- *flags = ((__IEC_##TYPENAME##_t *)varp)->flags;\
- forced_value_p = *real_value_p = &((__IEC_##TYPENAME##_t *)varp)->value;\
- break;
-
-#define __Unpack_case_p(TYPENAME)\
- case TYPENAME##_O_ENUM :\
- *flags = __IEC_OUTPUT_FLAG;\
- case TYPENAME##_P_ENUM :\
- *flags |= ((__IEC_##TYPENAME##_p *)varp)->flags;\
- *real_value_p = ((__IEC_##TYPENAME##_p *)varp)->value;\
- forced_value_p = &((__IEC_##TYPENAME##_p *)varp)->fvalue;\
- break;
-
-static void* UnpackVar(hmi_tree_item_t *dsc, void **real_value_p, char *flags)
-{
- void *varp = dsc->ptr;
- void *forced_value_p = NULL;
- *flags = 0;
- /* find data to copy*/
- switch(dsc->type){
- __ANY(__Unpack_case_t)
- __ANY(__Unpack_case_p)
- default:
- break;
- }
- if (*flags & __IEC_FORCE_FLAG)
- return forced_value_p;
- return *real_value_p;
-}
+%(var_access_code)s
void write_iterator(hmi_tree_item_t *dsc)
{
--- a/svghmi/svghmi.py Fri Aug 23 14:01:31 2019 +0200
+++ b/svghmi/svghmi.py Mon Aug 26 08:54:02 2019 +0200
@@ -21,6 +21,7 @@
from util.ProcessLogger import ProcessLogger
from runtime.typemapping import DebugTypesSize
+import targets
HMI_TYPES_DESC = {
"HMI_CLASS":{},
@@ -206,7 +207,8 @@
svghmi_c_code = svghmi_c_code % {
"variable_decl_array": ",\n".join(variable_decl_array),
"extern_variables_declarations": "\n".join(extern_variables_declarations),
- "buffer_size": buf_index
+ "buffer_size": buf_index,
+ "var_access_code": targets.GetCode("var_access.c")
}
gen_svghmi_c_path = os.path.join(buildpath, "svghmi.c")
--- a/targets/plc_debug.c Fri Aug 23 14:01:31 2019 +0200
+++ b/targets/plc_debug.c Mon Aug 26 08:54:02 2019 +0200
@@ -71,37 +71,9 @@
}
}
-#define __Unpack_case_t(TYPENAME) \
- case TYPENAME##_ENUM :\
- *flags = ((__IEC_##TYPENAME##_t *)varp)->flags;\
- forced_value_p = *real_value_p = &((__IEC_##TYPENAME##_t *)varp)->value;\
- break;
-
-#define __Unpack_case_p(TYPENAME)\
- case TYPENAME##_O_ENUM :\
- *flags = __IEC_OUTPUT_FLAG;\
- case TYPENAME##_P_ENUM :\
- *flags |= ((__IEC_##TYPENAME##_p *)varp)->flags;\
- *real_value_p = ((__IEC_##TYPENAME##_p *)varp)->value;\
- forced_value_p = &((__IEC_##TYPENAME##_p *)varp)->fvalue;\
- break;
-
-void* UnpackVar(dbgvardsc_t *dsc, void **real_value_p, char *flags)
-{
- void *varp = dsc->ptr;
- void *forced_value_p = NULL;
- *flags = 0;
- /* find data to copy*/
- switch(dsc->type){
- __ANY(__Unpack_case_t)
- __ANY(__Unpack_case_p)
- default:
- break;
- }
- if (*flags & __IEC_FORCE_FLAG)
- return forced_value_p;
- return *real_value_p;
-}
+#define __Unpack_desc_type dbgvardsc_t
+
+%(var_access_code)s
void Remind(unsigned int offset, unsigned int count, void * p);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/targets/var_access.c Mon Aug 26 08:54:02 2019 +0200
@@ -0,0 +1,33 @@
+
+#define __Unpack_case_t(TYPENAME) \
+ case TYPENAME##_ENUM :\
+ *flags = ((__IEC_##TYPENAME##_t *)varp)->flags;\
+ forced_value_p = *real_value_p = &((__IEC_##TYPENAME##_t *)varp)->value;\
+ break;
+
+#define __Unpack_case_p(TYPENAME)\
+ case TYPENAME##_O_ENUM :\
+ *flags = __IEC_OUTPUT_FLAG;\
+ case TYPENAME##_P_ENUM :\
+ *flags |= ((__IEC_##TYPENAME##_p *)varp)->flags;\
+ *real_value_p = ((__IEC_##TYPENAME##_p *)varp)->value;\
+ forced_value_p = &((__IEC_##TYPENAME##_p *)varp)->fvalue;\
+ break;
+
+static void* UnpackVar(__Unpack_desc_type *dsc, void **real_value_p, char *flags)
+{
+ void *varp = dsc->ptr;
+ void *forced_value_p = NULL;
+ *flags = 0;
+ /* find data to copy*/
+ switch(dsc->type){
+ __ANY(__Unpack_case_t)
+ __ANY(__Unpack_case_p)
+ default:
+ break;
+ }
+ if (*flags & __IEC_FORCE_FLAG)
+ return forced_value_p;
+ return *real_value_p;
+}
+