objdictgen/gen_cfile.py
changeset 289 a22ce0314063
parent 288 26015ee2c2c9
child 313 fed411af774a
equal deleted inserted replaced
288:26015ee2c2c9 289:a22ce0314063
    51     else:
    51     else:
    52         result = type_model.match(typename)
    52         result = type_model.match(typename)
    53         if result:
    53         if result:
    54             values = result.groups()
    54             values = result.groups()
    55             if values[0] == "UNSIGNED" and int(values[1]) in [i * 8 for i in xrange(1, 9)]:
    55             if values[0] == "UNSIGNED" and int(values[1]) in [i * 8 for i in xrange(1, 9)]:
    56                 typeinfos = ("UNS%s"%values[1], "", "uint%s"%values[1])
    56                 typeinfos = ("UNS%s"%values[1], "", "uint%s"%values[1], True)
    57             elif values[0] == "INTEGER" and int(values[1]) in [i * 8 for i in xrange(1, 9)]:
    57             elif values[0] == "INTEGER" and int(values[1]) in [i * 8 for i in xrange(1, 9)]:
    58                 typeinfos = ("INTEGER%s"%values[1], "", "int%s"%values[1])
    58                 typeinfos = ("INTEGER%s"%values[1], "", "int%s"%values[1], False)
    59             elif values[0] == "REAL" and int(values[1]) in (32, 64):
    59             elif values[0] == "REAL" and int(values[1]) in (32, 64):
    60                 typeinfos = ("%s%s"%(values[0], values[1]), "", "real%s"%values[1])
    60                 typeinfos = ("%s%s"%(values[0], values[1]), "", "real%s"%values[1], False)
    61             elif values[0] == "VISIBLE_STRING":
    61             elif values[0] == "VISIBLE_STRING":
    62                 if values[1] == "":
    62                 if values[1] == "":
    63                     typeinfos = ("UNS8", "[10]", "visible_string")
    63                     typeinfos = ("UNS8", "[10]", "visible_string", False)
    64                 else:
    64                 else:
    65                     typeinfos = ("UNS8", "[%s]"%values[1], "visible_string")
    65                     typeinfos = ("UNS8", "[%s]"%values[1], "visible_string", False)
    66             elif values[0] == "DOMAIN":
    66             elif values[0] == "DOMAIN":
    67                 typeinfos = ("UNS8*", "", "domain")
    67                 typeinfos = ("UNS8*", "", "domain", True)
    68             elif values[0] == "BOOLEAN":
    68             elif values[0] == "BOOLEAN":
    69                 typeinfos = ("UNS8", "", "boolean")
    69                 typeinfos = ("UNS8", "", "boolean", True)
    70             else:
    70             else:
    71                 raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename
    71                 raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename
    72             internal_types[typename] = typeinfos
    72             internal_types[typename] = typeinfos
    73         else:
    73         else:
    74             raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename
    74             raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename
   118             num += 1
   118             num += 1
   119             typeindex = Node.GetEntry(index, 1)
   119             typeindex = Node.GetEntry(index, 1)
   120             typename = Node.GetTypeName(typeindex)
   120             typename = Node.GetTypeName(typeindex)
   121             typeinfos = GetValidTypeInfos(typename)
   121             typeinfos = GetValidTypeInfos(typename)
   122             internal_types[rangename] = (typeinfos[0], typeinfos[1], "valueRange_%d"%num)
   122             internal_types[rangename] = (typeinfos[0], typeinfos[1], "valueRange_%d"%num)
   123             minvalue = str(Node.GetEntry(index, 2))
   123             minvalue = Node.GetEntry(index, 2)
   124             maxvalue = str(Node.GetEntry(index, 3))
   124             maxvalue = Node.GetEntry(index, 3)
   125             strDefine += "\n#define valueRange_%d 0x%02X /* Type %s, %s < value < %s */"%(num,index,typeinfos[0],minvalue,maxvalue)
   125             strDefine += "\n#define valueRange_%d 0x%02X /* Type %s, %s < value < %s */"%(num,index,typeinfos[0],str(minvalue),str(maxvalue))
   126             strSwitch += """    case valueRange_%d:
   126             strSwitch += "    case valueRange_%d:\n"%(num)
   127       if (*(%s*)value < (%s)%s) return OD_VALUE_TOO_LOW;
   127             if typeinfos[4] and minvalue <= 0:
   128       if (*(%s*)value > (%s)%s) return OD_VALUE_TOO_HIGH;
   128                 strSwitch += "      /* Negative or null low limit ignored because of unsigned type */;\n"
   129       break;\n"""%(num,typeinfos[0],typeinfos[0],minvalue,typeinfos[0],typeinfos[0],maxvalue)
   129             else:
       
   130                 strSwitch += "      if (*(%s*)value < (%s)%s) return OD_VALUE_TOO_LOW;\n"%(typeinfos[0],typeinfos[0],str(minvalue))
       
   131             strSwitch += "      if (*(%s*)value > (%s)%s) return OD_VALUE_TOO_HIGH;\n"%(typeinfos[0],typeinfos[0],str(maxvalue))
       
   132             strSwitch += "    break;\n"
   130 
   133 
   131     valueRangeContent += strDefine
   134     valueRangeContent += strDefine
   132     valueRangeContent += "\nUNS32 %(NodeName)s_valueRangeTest (UNS8 typeValue, void * value)\n{"%texts
   135     valueRangeContent += "\nUNS32 %(NodeName)s_valueRangeTest (UNS8 typeValue, void * value)\n{"%texts
   133     valueRangeContent += "\n  switch (typeValue) {\n"
   136     valueRangeContent += "\n  switch (typeValue) {\n"
   134     valueRangeContent += strSwitch
   137     valueRangeContent += strSwitch