Subversion Repositories HomeAutomation

Rev

Rev 1259 | Rev 1727 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1259 Rev 1572
Line 29... Line 29...
29
 
29
 
30
def parseModuleIdFromFile(moduleName, fileName):
30
def parseModuleIdFromFile(moduleName, fileName):
31
	config_inc = open(fileName, 'r') 
31
	config_inc = open(fileName, 'r') 
32
	config_inc_lines = config_inc.readlines()
32
	config_inc_lines = config_inc.readlines()
33
	config_inc.close()
33
	config_inc.close()
34
	
34
	takenIds = []
35
	for line in config_inc_lines:
35
	for line in config_inc_lines:
36
		line = line.strip("\n").strip(" ")
36
		line = line.strip("\n").strip(" ")
37
		
37
		
38
		if line.find(moduleName + "_ID") != -1:
38
		if line.find(moduleName + "_ID") != -1:
39
			parts = line.split("=")
39
			parts = line.split("=")
-
 
40
			if parts[1].strip(" ") != -1 and parts[1].strip(" ") != "<ID>":
40
			return parts[1].strip(" ")
41
				takenIds.append(int(parts[1].strip(" "), 16))
-
 
42
				print "hittade: "+parts[1].strip(" ")+" in file: "+fileName
-
 
43
	return takenIds
-
 
44
 
41
	
45
 
42
	return -1;
-
 
43
 
-
 
44
 
-
 
45
def getFreeModuleId(moduleName):
46
def getModuleIdsFromFile(moduleName):
46
	takenIds = []
47
	takenIds = []
47
 
-
 
48
	for applicationName in os.listdir("../"):
48
	for applicationName in os.listdir("../"):	
49
		
-
 
50
		if applicationName[0] != '.' and os.path.exists("../" + applicationName + "/config.inc"):
49
		if applicationName[0] != '.' and os.path.exists("../" + applicationName + "/config.inc"):
51
			takenId = parseModuleIdFromFile(moduleName, "../" + applicationName + "/config.inc")
50
			takenIds = parseModuleIdFromFile(moduleName, "../" + applicationName + "/config.inc")
52
			if takenId != -1 and takenId != "<ID>":
-
 
53
				takenIds.append(int(takenId, 16))
51
	return takenIds
54
 
52
	
-
 
53
 
-
 
54
def getFreeModuleId(takenIds):
55
	if len(takenIds) == 0:
55
	if len(takenIds) == 0:
56
		return "0x01"
56
		return 1
57
 
-
 
58
	takenIds.sort()
57
	takenIds.sort()
59
 
58
 
60
	lastId = 0
59
	lastId = 0
61
 
60
 
62
	for takenId in takenIds:
61
	for takenId in takenIds:
63
		if takenId != lastId+1:
62
		if takenId != lastId+1:
64
			return hex(lastId+1)
63
			return lastId+1
65
		lastId = takenId
64
		lastId = takenId
66
 
65
 
67
	return hex(lastId+1)
66
	return lastId+1
-
 
67
 
68
	
68
 
69
 
69
 
70
def compileMainFile():
70
def compileMainFile():
71
	print "Compiling new main.c..."
71
	print "Compiling new main.c..."
72
	main_c_template = open('src/main.c.template', 'r') 
72
	main_c_template = open('src/main.c.template', 'r') 
Line 110... Line 110...
110
 
110
 
111
def readConfigSection(fileName, sectionName):
111
def readConfigSection(fileName, sectionName):
112
	fileInstance = open(fileName, 'r')
112
	fileInstance = open(fileName, 'r')
113
	lines = fileInstance.readlines()
113
	lines = fileInstance.readlines()
114
	fileInstance.close()
114
	fileInstance.close()
115
	
115
	
116
	sectionLines = []
116
	sectionLines = []
117
	
117
	
118
	inSection = False
118
	inSection = False
119
	
119
	
120
	for line in lines:
120
	for line in lines:
Line 131... Line 131...
131
	return sectionLines
131
	return sectionLines
132
	
132
	
133
 
133
 
134
def updateConfigFile():
134
def updateConfigFile():
135
	print "Updating config.inc..."
135
	print "Updating config.inc..."
136
	
-
 
137
	modules = getLocalModules()
136
	modules = getLocalModules()
138
	moduleSections = {}
137
	moduleSections = {}
139
	applicationSection = []
138
	applicationSection = []
140
	
139
	
141
	if not os.path.exists("config.inc"):
140
	if not os.path.exists("config.inc"):
142
		applicationSection = readConfigSection("src/config.inc.template", "application")
141
		applicationSection = readConfigSection("src/config.inc.template", "application")
143
		
142
		
144
		for moduleName in modules:
143
		for moduleName in modules:
145
			moduleSections[moduleName] = readConfigSection(localmoddir + "/" + moduleName + "/config.inc.template", moduleName)
144
			moduleSections[moduleName] = readConfigSection(localmoddir + "/" + moduleName + "/config.inc.template", moduleName)
146
	else:
145
	else:
147
		applicationSection = readConfigSection("config.inc", "application")
146
		applicationSection = readConfigSection("config.inc", "application")
148
		
147
		
149
		for moduleName in modules:
148
		for moduleName in modules:
150
			moduleSections[moduleName] = readConfigSection("config.inc", moduleName)
149
			moduleSections[moduleName] = readConfigSection("config.inc", moduleName)
151
			
150
			
152
			if len(moduleSections[moduleName]) <= 1:
151
			if len(moduleSections[moduleName]) <= 1:
153
				moduleSections[moduleName] = readConfigSection(localmoddir + "/" + moduleName + "/config.inc.template", moduleName)
152
				moduleSections[moduleName] = readConfigSection(localmoddir + "/" + moduleName + "/config.inc.template", moduleName)
154
	
153
	
155
	timers = 0
154
	timers = 0
156
	pcints = 0
155
	pcints = 0
-
 
156
	
-
 
157
	moduleIds = getModuleIdsFromFile(moduleName)
-
 
158
	
157
		
159
	
158
	for moduleName, moduleSection in moduleSections.iteritems():
160
	for moduleName, moduleSection in moduleSections.iteritems():
159
		c = 0
161
		c = 0
160
		for line in moduleSection:
162
		for line in moduleSection:
161
			if len(line) > 0:
163
			if len(line) > 0:
162
				if line[0] != '#':
164
				if line[0] != '#':
163
					if line.find("<ID>") != -1:
165
					if line.find("<ID>") != -1:
-
 
166
						new_ID = getFreeModuleId(moduleIds)
-
 
167
						print "id = "+hex(new_ID)
-
 
168
						moduleIds.append(new_ID)
164
						line = line.replace("<ID>", getFreeModuleId(moduleName))
169
						line = line.replace("<ID>", hex(new_ID))
165
					elif line.find("<TIMER>") != -1:
170
					elif line.find("<TIMER>") != -1:
166
						line = line[:line.find("=")+1] + hex(timers) + " /* <TIMER> -- DO NOT REMOVE THIS COMMENT -- */"
171
						line = line[:line.find("=")+1] + hex(timers) + " /* <TIMER> -- DO NOT REMOVE THIS COMMENT -- */"
167
						timers += 1
172
						timers += 1
168
					elif line.find("<PCINT>") != -1:
173
					elif line.find("<PCINT>") != -1:
169
						line = line[:line.find("=")+1] + hex(pcints) + " /* <PCINT> -- DO NOT REMOVE THIS COMMENT -- */"
174
						line = line[:line.find("=")+1] + hex(pcints) + " /* <PCINT> -- DO NOT REMOVE THIS COMMENT -- */"