Merge PR #33: Add option to generate libnymea-sunspec with a minimal model set to minimize the library size
commit
c6a8ebad28
|
|
@ -22,6 +22,7 @@ import sys
|
||||||
import json
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
import datetime
|
import datetime
|
||||||
|
import argparse
|
||||||
|
|
||||||
def convertToAlphaNumeric(text):
|
def convertToAlphaNumeric(text):
|
||||||
finalText = ''
|
finalText = ''
|
||||||
|
|
@ -91,6 +92,10 @@ def loadModel(modelFilePath):
|
||||||
print('--> Loading model', modelFilePath)
|
print('--> Loading model', modelFilePath)
|
||||||
modelFile = open(modelFilePath, 'r')
|
modelFile = open(modelFilePath, 'r')
|
||||||
modelData = json.load(modelFile)
|
modelData = json.load(modelFile)
|
||||||
|
if useWhiteList:
|
||||||
|
if modelData['id'] in modelWhiteList:
|
||||||
|
models[modelData['id']] = modelData
|
||||||
|
else:
|
||||||
models[modelData['id']] = modelData
|
models[modelData['id']] = modelData
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1195,6 +1200,9 @@ def getClassName(groupName):
|
||||||
|
|
||||||
|
|
||||||
def createClass(className, modelId):
|
def createClass(className, modelId):
|
||||||
|
if useWhiteList and modelId not in modelWhiteList:
|
||||||
|
return
|
||||||
|
|
||||||
print('Creating class -->', className, 'using model id', modelId)
|
print('Creating class -->', className, 'using model id', modelId)
|
||||||
headerFileName = os.path.join(outputDirectory, className.lower() + '.h')
|
headerFileName = os.path.join(outputDirectory, className.lower() + '.h')
|
||||||
sourceFileName = os.path.join(outputDirectory, className.lower() + '.cpp')
|
sourceFileName = os.path.join(outputDirectory, className.lower() + '.cpp')
|
||||||
|
|
@ -1307,14 +1315,21 @@ def writeModelFactorySource(fileDescriptor):
|
||||||
# Main
|
# Main
|
||||||
############################################################################################
|
############################################################################################
|
||||||
|
|
||||||
#testCamelCase()
|
parser = argparse.ArgumentParser(description='Generate sunspec model classes from specification json definitions.')
|
||||||
#exit(0)
|
parser.add_argument('-m', '--minimal', action='store_true', help='Generate a minimal set of model classes used in the sunspec plugin. Option to minimize the library size.')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Paths
|
# Paths
|
||||||
scriptPath = os.path.dirname(os.path.realpath(sys.argv[0]))
|
scriptPath = os.path.dirname(os.path.realpath(sys.argv[0]))
|
||||||
modelJsonFolder = os.path.join(scriptPath, 'models/json')
|
modelJsonFolder = os.path.join(scriptPath, 'models/json')
|
||||||
outputDirectory = os.path.join(scriptPath, '../models')
|
outputDirectory = os.path.join(scriptPath, '../models')
|
||||||
|
|
||||||
|
# Whitelist for minimal library size
|
||||||
|
modelWhiteList = [1, 101, 102, 103, 111, 112, 113, 124, 201, 202, 203, 204, 211, 212, 213, 214, 802]
|
||||||
|
useWhiteList = args.minimal
|
||||||
|
if useWhiteList:
|
||||||
|
print('Using the white list for minimizing the library size: %s' % modelWhiteList)
|
||||||
|
|
||||||
# id, {name, lable}
|
# id, {name, lable}
|
||||||
models = {}
|
models = {}
|
||||||
modelHeaderSize = 2
|
modelHeaderSize = 2
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue