Bugs on cfile generation fixed
authorlbessard
Mon, 25 Jun 2007 17:01:39 +0200
changeset 227 f76c64f66097
parent 226 abf63d732a84
child 228 c6e9fc22de5c
Bugs on cfile generation fixed
objdictgen/eds_utils.py
objdictgen/gen_cfile.py
objdictgen/node.py
objdictgen/objdictedit.py
--- a/objdictgen/eds_utils.py	Fri Jun 22 17:46:18 2007 +0200
+++ b/objdictgen/eds_utils.py	Mon Jun 25 17:01:39 2007 +0200
@@ -377,7 +377,21 @@
                 else:
                     attributes = "Attribute \"%s\" is"%unsupported[0]
                 raise SyntaxError, "Error on section \"[%s]\":\n%s unsupported for a%s entry"%(section_name, attributes, ENTRY_TYPES[objecttype]["name"])
-        
+            
+            if "DEFAULTVALUE" in values:
+                try:
+                    if values["DATATYPE"] in (0x09, 0x0A, 0x0B, 0x0F):
+                        values["DEFAULTVALUE"] = str(values["DEFAULTVALUE"])
+                    elif values["DATATYPE"] in (0x08, 0x11):
+                        values["DEFAULTVALUE"] = float(values["DEFAULTVALUE"])
+                    elif values["DATATYPE"] == 0x01:
+                        values["DEFAULTVALUE"] = {0 : True, 1 : False}[values["DEFAULTVALUE"]]
+                    else:
+                        if type(values["DEFAULTVALUE"]) != IntType and values["DEFAULTVALUE"].find("self.ID") == -1:
+                            raise
+                except:
+                    raise SyntaxError, "Error on section \"[%s]\":\nDefaultValue incompatible with DataType"%section_name
+            
     return eds_dict
 
 
--- a/objdictgen/gen_cfile.py	Fri Jun 22 17:46:18 2007 +0200
+++ b/objdictgen/gen_cfile.py	Mon Jun 25 17:01:39 2007 +0200
@@ -42,12 +42,7 @@
 # Format a string for making a C++ variable
 def FormatName(name):
     wordlist = [word for word in word_model.findall(name) if word != '']
-    result = ''
-    sep = ''
-    for word in wordlist:
-        result += "%s%s"%(sep,word)
-        sep = '_'
-    return result
+    return "_".join(wordlist)
 
 # Extract the informations from a given type name
 def GetValidTypeInfos(typename):
@@ -142,11 +137,12 @@
     strDeclareCallback = ""
     indexContents = {}
     indexCallbacks = {}
+    translate_characters = "".join([chr(i) for i in xrange(128)] + ["_" for i in xrange(128)])
     for index in listIndex:
         texts["index"] = index
         strIndex = ""
         entry_infos = Manager.GetEntryInfos(index)
-        texts["EntryName"] = entry_infos["name"]
+        texts["EntryName"] = entry_infos["name"].translate(translate_characters)
         values = Manager.GetCurrentEntry(index)
         callbacks = Manager.HasCurrentEntryCallbacks(index)
         if index in variablelist:
@@ -211,7 +207,7 @@
                                 value = "\"%s\""%value
                             elif typeinfos[2] == "domain":
                                 value = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
-			    else:
+                            else:
                                 comment = "\t/* %s */"%str(value)
                                 value = "0x%X"%value
                             mappedVariableContent += "    %s%s%s\n"%(value, sep, comment)
@@ -251,7 +247,7 @@
                         elif typeinfos[2] == "domain":
                             texts["value"] = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value])
                             texts["comment"] = ""			
-			else:
+                        else:
                             texts["value"] = "0x%X"%value
                             texts["comment"] = "\t/* %s */"%str(value)
                         texts["name"] = FormatName(subentry_infos["name"])
--- a/objdictgen/node.py	Fri Jun 22 17:46:18 2007 +0200
+++ b/objdictgen/node.py	Mon Jun 25 17:01:39 2007 +0200
@@ -625,7 +625,7 @@
                         values.append(self.CompileValue(value, index))
                     return values
                 else:
-                    return self.Dictionary[index]
+                    return self.CompileValue(self.Dictionary[index], index)
             elif subIndex == 0:
                 if type(self.Dictionary[index]) == ListType:
                     return len(self.Dictionary[index])
@@ -834,10 +834,10 @@
         for mapping in self.GetMappings():
             result = FindIndex(index, mapping)
             if result != None:
-                return (index - result) / mapping[result]["incr"]
+                return (index - result) / mapping[result].get("incr", 1)
         result = FindIndex(index, MappingDictionary)
         if result != None:
-            return (index - result) / MappingDictionary[result]["incr"]
+            return (index - result) / MappingDictionary[result].get("incr", 1)
         return 0
 
     def GetCustomisedTypeValues(self, index):
--- a/objdictgen/objdictedit.py	Fri Jun 22 17:46:18 2007 +0200
+++ b/objdictgen/objdictedit.py	Mon Jun 25 17:01:39 2007 +0200
@@ -782,7 +782,7 @@
         event.Skip()
 
     def OnExportCMenu(self, event):
-        dialog = wxFileDialog(self, "Choose a file", os.getcwd(), self.Manager.GetCurrentNodeInfos()[0],  "CANFestival OD files (*.c)|*.c|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR)
+        dialog = wxFileDialog(self, "Choose a file", os.getcwd(), self.Manager.GetCurrentNodeInfos()[0],  "CANFestival C files (*.c)|*.c|All files|*.*", wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR)
         if dialog.ShowModal() == wxID_OK:
             filepath = dialog.GetPath()
             if os.path.isdir(os.path.dirname(filepath)):