Browse Source

compiling now, never tested if it actually works

Stasik0 11 years ago
parent
commit
aaf26a5fcc
3 changed files with 34 additions and 6 deletions
  1. 24 3
      tool/generate_builtin.py
  2. 5 0
      tool/opcua_basictypes.c
  3. 5 3
      tool/opcua_basictypes.h

+ 24 - 3
tool/generate_builtin.py

@@ -136,9 +136,13 @@ def createStructured(element):
     print("Int32 " + name + "_decode(char const * src, UInt32* pos, " + name + "* dst);", end='\n', file=fh)
 
     if "Response" in name[len(name)-9:]:
-        print("Int32 "  + name + "_calcSize(" + name + " const * ptr) {\n\treturn UA_ResponseHeader_getSize()", end='', file=fc) 
+		#Sten: not sure how to get it, actually we need to solve it on a higher level
+        #print("Int32 "  + name + "_calcSize(" + name + " const * ptr) {\n\treturn UA_ResponseHeader_getSize()", end='', file=fc)
+		print("Int32 "  + name + "_calcSize(" + name + " const * ptr) {\n\treturn 0", end='', file=fc)  
     elif "Request" in name[len(name)-9:]:
-        print("Int32 "  + name + "_calcSize(" + name + " const * ptr) {\n\treturn UA_RequestHeader_getSize()", end='', file=fc) 
+		#Sten: dito
+        #print("Int32 "  + name + "_calcSize(" + name + " const * ptr) {\n\treturn UA_RequestHeader_getSize()", end='', file=fc) 
+		print("Int32 "  + name + "_calcSize(" + name + " const * ptr) {\n\treturn 0", end='', file=fc) 
     else:
 	# code 
         print("Int32 "  + name + "_calcSize(" + name + " const * ptr) {\n\treturn 0", end='', file=fc)
@@ -167,7 +171,7 @@ def createStructured(element):
             print('\tretval |= UA_'+t+'_encode(&(src->'+n+'),pos,dst);', end='\n', file=fc)
         else:
             if t in enum_types:
-                print('\tretval |= UA_'+t+'_encode(&(src->'+n+'));', end='\n', file=fc)
+                print('\tretval |= UA_'+t+'_encode(&(src->'+n+'),pos,dst);', end='\n', file=fc)
             elif t.find("**") != -1:
                 print('\tretval |= UA_Int32_encode(&(src->'+n+'_size),pos,dst); // encode size', end='\n', file=fc)
 		print("\tretval |= UA_Array_encode((void const**) (src->"+n+"),src->"+n+"_size, UA_" + t[0:t.find("*")].upper()+",pos,dst);", end='\n', file=fc)
@@ -176,6 +180,23 @@ def createStructured(element):
             else:
                 print('\tretval |= UA_'+t+"_encode(&(src->"+n+"),pos,dst);", end='\n', file=fc)
     print("\treturn retval;\n};\n", end='\n', file=fc)
+
+    print("Int32 "+name+"_decode(char const * src, UInt32* pos, " + name + "* dst) {\n\tInt32 retval = UA_SUCCESS;", end='\n', file=fc)
+    # code _decode
+    for n,t in valuemap.iteritems():
+        if t in elementary_size:
+            print('\tretval |= UA_'+t+'_decode(src,pos,&(dst->'+n+'));', end='\n', file=fc)
+        else:
+            if t in enum_types:
+                print('\tretval |= UA_'+t+'_decode(src,pos,&(dst->'+n+'));', end='\n', file=fc)
+            elif t.find("**") != -1:
+                print('\tretval |= UA_Int32_decode(src,pos,&(dst->'+n+'_size)); // decode size', end='\n', file=fc)
+		print("\tretval |= UA_Array_decode(src,dst->"+n+"_size, UA_" + t[0:t.find("*")].upper()+",pos,(void const**) (dst->"+n+"));", end='\n', file=fc) #not tested
+            elif t.find("*") != -1:
+                print('\tretval |= UA_' + t[0:t.find("*")] + "_decode(src,pos,dst->"+ n +");", end='\n', file=fc)
+            else:
+                print('\tretval |= UA_'+t+"_decode(src,pos,&(dst->"+n+"));", end='\n', file=fc)
+    print("\treturn retval;\n};\n", end='\n', file=fc)
         
 def createOpaque(element):
     name = "UA_" + element.get("Name")

+ 5 - 0
tool/opcua_basictypes.c

@@ -32,6 +32,11 @@ Int32 UA_Array_encode(void const **src, Int32 noElements, Int32 type, Int32* pos
 	return UA_ERR_NOT_IMPLEMENTED;
 }
 
+Int32 UA_Array_decode(char const * src, Int32 noElements, Int32 type, Int32* pos, void const **dst) {
+	//TODO: Implement
+	return UA_ERR_NOT_IMPLEMENTED;
+}
+
 Int32 UA_free(void * ptr){
 	free(ptr);
 	return UA_SUCCESS;

+ 5 - 3
tool/opcua_basictypes.h

@@ -43,6 +43,11 @@ Int32 UA_free(void * ptr);
 Int32 UA_memcpy(void *dst, void const *src, int size);
 Int32 UA_alloc(void ** dst, int size);
 
+/* Array operations */
+Int32 UA_Array_calcSize(Int32 noElements, Int32 type, void const ** ptr);
+Int32 UA_Array_encode(void const **src, Int32 noElements, Int32 type, Int32* pos, char * dst);
+Int32 UA_Array_decode(char const * src, Int32 noElements, Int32 type, Int32* pos, void const **dst);
+
 #define UA_NULL ((void*)0)
 // #define NULL UA_NULL
 
@@ -321,7 +326,4 @@ enum UA_DiagnosticInfoEncodingMaskType_enum
 	DIEMT_INNER_DIAGNOSTIC_INFO = 	0x40
 };
 
-Int32 UA_Array_calcSize(Int32 noElements, Int32 type, void const ** ptr);
-Int32 UA_Array_encode(void const **src, Int32 noElements, Int32 type, Int32* pos, char * dst);
-
 #endif /* OPCUA_BASICTYPES_H_ */