Rev 1259 | Rev 1574 | Go to most recent revision | Show entire file | Ignore 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 |
|
41 | takenIds.append(int(parts[1].strip(" "), 16)) |
| 41 | - | ||
| - | 42 | print "hittade: "+parts[1].strip(" ")+" in file: "+fileName |
|
| 42 | return |
43 | return takenIds |
| 43 | 44 | ||
| 44 | 45 | ||
| 45 | def |
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 |
|
50 | takenIds = parseModuleIdFromFile(moduleName, "../" + applicationName + "/config.inc") |
| 52 | if takenId != -1 and takenId != "<ID>": |
- | |
| 53 |
|
51 | return takenIds |
| - | 52 | ||
| 54 | 53 | ||
| - | 54 | def getFreeModuleId(takenIds): |
|
| 55 | if len(takenIds) == 0: |
55 | if len(takenIds) == 0: |
| 56 | return |
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 |
63 | return lastId+1 |
| 65 | lastId = takenId |
64 | lastId = takenId |
| 66 | 65 | ||
| 67 | return |
66 | return lastId+1 |
| 68 | 67 | ||
| - | 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') |
| 73 | main_c_template_lines = main_c_template.readlines() |
73 | main_c_template_lines = main_c_template.readlines() |
| Line 83... | Line 83... | ||
| 83 | pos_process = main_c_template_line.find('%PROCESS') |
83 | pos_process = main_c_template_line.find('%PROCESS') |
| 84 | pos_list = main_c_template_line.find('%LIST') |
84 | pos_list = main_c_template_line.find('%LIST') |
| 85 | pos_handlemsg = main_c_template_line.find('%HANDLEMSG') |
85 | pos_handlemsg = main_c_template_line.find('%HANDLEMSG') |
| 86 | 86 | ||
| 87 | if pos_include != -1: |
87 | if pos_include != -1: |
| 88 | for moduleName in modules: |
88 | for moduleName in modules: |
| 89 | main_c.write(main_c_template_line[:pos_include] + "#include \"../modules/" + moduleName + "/" + moduleName + ".h\"\n") |
89 | main_c.write(main_c_template_line[:pos_include] + "#include \"../modules/" + moduleName + "/" + moduleName + ".h\"\n") |
| 90 | elif pos_init != -1: |
90 | elif pos_init != -1: |
| 91 | for moduleName in modules: |
91 | for moduleName in modules: |
| 92 | main_c.write(main_c_template_line[:pos_init] + moduleName + "_Init();\n") |
92 | main_c.write(main_c_template_line[:pos_init] + moduleName + "_Init();\n") |
| 93 | elif pos_process != -1: |
93 | elif pos_process != -1: |
| Line 125... | Line 125... | ||
| 125 | else: |
125 | else: |
| 126 | if line.find("## End section " + sectionName) != -1: |
126 | if line.find("## End section " + sectionName) != -1: |
| 127 | inSection = False |
127 | inSection = False |
| 128 | 128 | ||
| 129 | sectionLines.append(line.strip("\n")) |
129 | sectionLines.append(line.strip("\n")) |
| 130 | 130 | ||
| 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"): |
| Line 152... | Line 151... | ||
| 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>", |
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 -- */" |