]> rtime.felk.cvut.cz Git - CanFestival-3.git/commitdiff
Bugs on cfile generation fixed
authorlbessard <lbessard>
Mon, 25 Jun 2007 15:01:39 +0000 (15:01 +0000)
committerlbessard <lbessard>
Mon, 25 Jun 2007 15:01:39 +0000 (15:01 +0000)
objdictgen/eds_utils.py
objdictgen/gen_cfile.py
objdictgen/node.py
objdictgen/objdictedit.py

index 41e23c6f65742e3963e0dcb2f03b49e8d1ad3301..4bd443d6371872573579444b2b32edb09492630a 100644 (file)
@@ -377,7 +377,21 @@ def ParseEDSFile(filepath):
                 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
 
 
index 0a01bcbfb1f076e227dd915eb30b6c18c8e6cd41..ebe81c699bdca2085d9fbd16b7cdc8091bb5c9d9 100644 (file)
@@ -42,12 +42,7 @@ internal_types = {}
 # 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 @@ def GenerateFileContent(Manager, headerfilepath):
     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 @@ def GenerateFileContent(Manager, headerfilepath):
                                 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 @@ def GenerateFileContent(Manager, headerfilepath):
                         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"])
index fab44f053c0d5e7e97e02aef3dcebddc3bf2a5fc..768a6a4c74309470e8340608e9bc3a99a492f60b 100755 (executable)
@@ -625,7 +625,7 @@ class Node:
                         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 @@ class Node:
         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):
index 1150d4b090ea1583a38f95d713d3091bd243b233..75ae876afe256d07e149c25949603472b676bbc1 100755 (executable)
@@ -29,7 +29,7 @@ import wx.grid
 from types import *
 import os, re, platform, sys, time, traceback, getopt
 
-__version__ = "$Revision: 1.22 $"
+__version__ = "$Revision: 1.23 $"
 
 from node import OD_Subindex, OD_MultipleSubindexes, OD_IdenticalSubindexes, OD_IdenticalIndexes
 
@@ -782,7 +782,7 @@ class objdictedit(wx.Frame):
         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)):