示例#1
0
 def createSpecificEnumHistorizer(xmlDataFieldNode, xmlTypeNode):
     enumValues = xmlHelper.getEnumValues(
         xmlDataFieldNode.find("enum"), "item", "description",
         "value")
     for enumValue in enumValues:
         enumValue[1] = re.split(":|<", enumValue[1])[0]
     cppHistorizerClassName = "C" + cppHelper.toCppName(
         xmlTypeNode.find(
             "title").text) + "_" + cppHelper.toCppName(
                 xmlDataFieldNode.find("data").text) + "Historizer"
     historizerEnumName = "E" + cppHelper.toCppName(
         xmlTypeNode.find(
             "title").text) + "_" + cppHelper.toCppName(
                 xmlDataFieldNode.find(
                     "data").text) + "_" + cppHelper.toCppName(
                         xmlDataFieldNode.find("data").text)
     cppHistorizerClass = cppClass.CppClass(cppHistorizerClassName,
                                            createDefaultCtor=False)
     cppHistorizerClass.inheritFrom(
         "yApi::historization::CSingleHistorizableData<" +
         historizerEnumName + ">", cppClass.PUBLIC)
     cppHistorizerClass.addConstructor(cppClass.CppClassConstructor("const std::string& keywordName", \
        "CSingleHistorizableData<" + historizerEnumName + ">(keywordName, yApi::CStandardCapacity(\"" + historizerEnumName + "\", yApi::CStandardUnits::NoUnit(), yApi::EKeywordDataType::kNoData), yApi::EKeywordAccessMode::kGet)"))
     cppHistorizerClass.addDependency(
         cppClass.CppExtendedEnumType(historizerEnumName,
                                      enumValues))
     return cppHistorizerClass
示例#2
0
        def createTypeCode(xmlRorgNode, xmlFuncNode):
            itemNumber = 0
            for xmlTypeNode in xmlFuncNode.findall("type"):
                if profileHelper.profileName(xmlRorgNode, xmlFuncNode,
                                             xmlTypeNode) in supportedProfiles:
                    itemNumber += 1
            if itemNumber == 0:
                return "   throw std::out_of_range(\"Invalid EFuncIds\");"

            code = "   switch(static_cast<ETypeIds>(typeId))\n"
            code += "   {\n"
            for xmlTypeNode in xmlFuncNode.findall("type"):
                if profileHelper.profileName(
                        xmlRorgNode, xmlFuncNode,
                        xmlTypeNode) not in supportedProfiles:
                    continue
                enumValue = cppHelper.toEnumValueName(
                    xmlTypeNode.find("number").text)
                className = cppHelper.toCppName(
                    "CProfile_" + profileHelper.profileName(
                        xmlRorgNode, xmlFuncNode, xmlTypeNode))
                code += "   case " + enumValue + ": return boost::make_shared<" + className + ">(deviceId, api);\n"
            code += "   default : throw std::out_of_range(\"Invalid EFuncIds\");\n"
            code += "   }"
            return code
示例#3
0
 def statesCodeForBoolValue(xmlDataFieldNode):
     offset = xmlDataFieldNode.find("bitoffs").text
     keywordName = xmlDataFieldNode.find(
         "shortcut").text + " - " + xmlDataFieldNode.find(
             "data").text
     historizerCppName = "m_" + cppHelper.toCppName(keywordName)
     return "   " + historizerCppName + "->set(data[" + offset + "]);\n"
示例#4
0
 def statesCodeForLinearValue(xmlDataFieldNode,
                              applyCoef=None,
                              finalCast=None):
     offset = xmlDataFieldNode.find("bitoffs").text
     size = xmlDataFieldNode.find("bitsize").text
     code = "   {\n"
     code += "      auto rawValue = bitset_extract(data, " + offset + ", " + size + ");\n"
     rangeMin = int(xmlDataFieldNode.find("range/min").text)
     rangeMax = int(xmlDataFieldNode.find("range/max").text)
     scaleMin = float(xmlDataFieldNode.find("scale/min").text)
     scaleMax = float(xmlDataFieldNode.find("scale/max").text)
     if applyCoef is not None:
         scaleMin = scaleMin * float(applyCoef)
         scaleMax = scaleMax * float(applyCoef)
     multiplier = (scaleMax - scaleMin) / (rangeMax - rangeMin)
     code += "      auto value = " + str(
         multiplier) + " * (static_cast<signed>(rawValue) - " + str(
             rangeMin) + ") + " + str(scaleMin) + ";\n"
     keywordName = xmlDataFieldNode.find(
         "shortcut").text + " - " + xmlDataFieldNode.find(
             "data").text
     historizerCppName = "m_" + cppHelper.toCppName(keywordName)
     if finalCast is not None:
         code += "      " + historizerCppName + "->set(static_cast<" + finalCast + ">(value));\n"
     else:
         code += "      " + historizerCppName + "->set(value);\n"
     code += "   }\n"
     return code
示例#5
0
 def createFuncCode(xmlRorgNode):
    code = "   switch(static_cast<EFuncIds>(funcId))\n"
    code += "   {\n"
    for xmlFuncNode in xmlRorgNode.findall("func"):
       enumValue = cppHelper.toEnumValueName(xmlFuncNode.find("title").text)
       className = "C" + xmlRorgNode.find("telegram").text + "_" + cppHelper.toCppName(xmlFuncNode.find("number").text)
       code += "   case " + enumValue + ": return boost::make_shared<" + className + ">();\n"
    code += "   default : throw std::out_of_range(\"Invalid EFuncIds\");\n"
    code += "   }\n"
    return code
示例#6
0
        def createTypeCode(xmlRorgNode, xmlFuncNode):
            itemNumber = 0
            # Add types found in XML file
            for xmlTypeNode in xmlFuncNode.findall("type"):
                if profileHelper.profileName(xmlRorgNode, xmlFuncNode,
                                             xmlTypeNode) in supportedProfiles:
                    itemNumber += 1
            # Add hard-coded types not present in XML file
            profilePattern = profileHelper.profileFuncPattern(
                xmlRorgNode, xmlFuncNode)
            hardCodedProfilesNotInXml = list(
                filter(lambda p: re.match(profilePattern, p),
                       hardCodedProfiles.getProfilesNotInXml()))
            itemNumber += len(hardCodedProfilesNotInXml)
            if itemNumber == 0:
                return "   throw std::out_of_range(\"Invalid EFuncIds\");"

            code = "   switch(static_cast<ETypeIds>(typeId))\n"
            code += "   {\n"
            # Add types found in XML file
            for xmlTypeNode in xmlFuncNode.findall("type"):
                if profileHelper.profileName(
                        xmlRorgNode, xmlFuncNode,
                        xmlTypeNode) not in supportedProfiles:
                    continue
                enumValue = cppHelper.toEnumValueName(
                    xmlTypeNode.find("number").text)
                className = cppHelper.toCppName(
                    "CProfile_" + profileHelper.profileName(
                        xmlRorgNode, xmlFuncNode, xmlTypeNode))
                code += "   case " + enumValue + ": return boost::make_shared<" + className + ">(deviceId, api);\n"
            # Add hard-coded types not present in XML file
            for profile in hardCodedProfilesNotInXml:
                enumValue = cppHelper.toEnumValueName(
                    "0x" + profileHelper.getType(profile))
                className = cppHelper.toCppName("CProfile_" + profile)
                code += "   case " + enumValue + ": return boost::make_shared<" + className + ">(deviceId, api);\n"
            code += "   default : throw std::out_of_range(\"Invalid EFuncIds\");\n"
            code += "   }"
            return code
示例#7
0
       "      throw std::out_of_range(\"Unknown func \" + CProfileHelper::byteToHexString(id));\n" \
       "   return static_cast<EFuncIds>(id);\n"))
    rorgClass.addMethod(cppClass.CppMethod("toFuncName", "const std::string&", "unsigned int id", cppClass.PUBLIC, cppClass.STATIC, \
       "   try {\n" \
       "      return FuncMap.at(id);\n" \
       "   } catch(std::out_of_range&) {\n" \
       "      static const std::string UnknownFunc(\"Unknown func\");\n" \
       "      return UnknownFunc;\n" \
       "   }"))

    #------------------------------------------------------------------------
    # Func cppTypes
    for xmlFuncNode in xmlRorgNode.findall("func"):
        funcClass = cppClass.CppClass(
            "C" + xmlRorgNode.find("telegram").text + "_" +
            cppHelper.toCppName(xmlFuncNode.find("number").text))
        funcClass.addComment(
            cppHelper.toCppName(xmlFuncNode.find("title").text))
        funcClass.inheritFrom("IFunc", cppClass.PUBLIC)
        rorgClass.addDependency(funcClass)
        funcClass.addSubType(
            cppClass.CppEnumType(
                "ETypeIds",
                xmlHelper.getEnumValues(inNode=xmlFuncNode,
                                        foreachSubNode="type",
                                        enumValueNameTag="number",
                                        enumValueTag="number"),
                cppClass.PUBLIC))
        funcClass.addMethod(
            cppClass.CppMethod(
                "id", "unsigned int", "", cppClass.PUBLIC,
示例#8
0
      "   if (FuncMap.find(id) == FuncMap.end())\n" \
      "      throw std::out_of_range(\"Unknown func \" + CProfileHelper::byteToHexString(id));\n" \
      "   return static_cast<EFuncIds>(id);\n"))
   rorgClass.addMethod(cppClass.CppMethod("toFuncName", "const std::string&", "unsigned int id", cppClass.PUBLIC, cppClass.STATIC, \
      "   try {\n" \
      "      return FuncMap.at(id);\n" \
      "   } catch(std::out_of_range&) {\n" \
      "      static const std::string UnknownFunc(\"Unknown func\");\n" \
      "      return UnknownFunc;\n" \
      "   }"))


   #------------------------------------------------------------------------
   # Func cppTypes
   for xmlFuncNode in xmlRorgNode.findall("func"):
      funcClass = cppClass.CppClass("C" + xmlRorgNode.find("telegram").text + "_" + cppHelper.toCppName(xmlFuncNode.find("number").text))
      funcClass.addComment(cppHelper.toCppName(xmlFuncNode.find("title").text))
      funcClass.inheritFrom("IFunc", cppClass.PUBLIC)
      rorgClass.addDependency(funcClass)
      funcClass.addSubType(cppClass.CppEnumType("ETypeIds", xmlHelper.getEnumValues(inNode=xmlFuncNode, foreachSubNode="type", enumValueNameTag="number", enumValueTag="number"), cppClass.PUBLIC))
      funcClass.addMethod(cppClass.CppMethod("id", "unsigned int", "", cppClass.PUBLIC, cppClass.CONST | cppClass.OVERRIDE, "   return " + xmlFuncNode.find("number").text + ";"))
      funcClass.addMethod(cppClass.CppMethod("title", "const std::string&", "", cppClass.PUBLIC, cppClass.CONST | cppClass.OVERRIDE, \
         "   static const std::string title(\"" + xmlFuncNode.find("title").text + "\");\n" \
         "   return title;"))

      #------------------------------------------------------------------------
      # Type cppTypes
      for xmlTypeNode in xmlFuncNode.findall("type"):
         profileName = profileHelper.profileName(xmlRorgNode, xmlFuncNode, xmlTypeNode)
         typeClassName = cppHelper.toCppName("CProfile_" + profileName)
         if hardCodedProfiles.isProfileHardCoded(profileName):