changeset 484 | f59d1cdde42b |
parent 479 | 92891f53630b |
child 493 | a204a86a71f1 |
483:763ae2ca410a | 484:f59d1cdde42b |
---|---|
93 def WriteFile(filepath, content): |
93 def WriteFile(filepath, content): |
94 cfile = open(filepath,"w") |
94 cfile = open(filepath,"w") |
95 cfile.write(content) |
95 cfile.write(content) |
96 cfile.close() |
96 cfile.close() |
97 |
97 |
98 def GenerateFileContent(Node, headerfilepath): |
98 def GenerateFileContent(Node, headerfilepath, pointers_dict = {}): |
99 """ |
|
100 pointers_dict = {(Idx,Sidx):"VariableName",...} |
|
101 """ |
|
99 global type |
102 global type |
100 global internal_types |
103 global internal_types |
101 global default_string_size |
104 global default_string_size |
102 |
105 |
103 texts = {} |
106 texts = {} |
160 #------------------------------------------------------------------------------- |
163 #------------------------------------------------------------------------------- |
161 # Creation of the mapped variables and object dictionary |
164 # Creation of the mapped variables and object dictionary |
162 #------------------------------------------------------------------------------- |
165 #------------------------------------------------------------------------------- |
163 |
166 |
164 mappedVariableContent = "" |
167 mappedVariableContent = "" |
168 pointedVariableContent = "" |
|
165 strDeclareHeader = "" |
169 strDeclareHeader = "" |
166 strDeclareCallback = "" |
170 strDeclareCallback = "" |
167 indexContents = {} |
171 indexContents = {} |
168 indexCallbacks = {} |
172 indexCallbacks = {} |
169 for index in listIndex: |
173 for index in listIndex: |
317 if params["save"]: |
321 if params["save"]: |
318 save = "|TO_BE_SAVE" |
322 save = "|TO_BE_SAVE" |
319 else: |
323 else: |
320 save = "" |
324 save = "" |
321 strIndex += " { %s%s, %s, %s, (void*)&%s }%s\n"%(subentry_infos["access"].upper(),save,typeinfos[2],sizeof,name,sep) |
325 strIndex += " { %s%s, %s, %s, (void*)&%s }%s\n"%(subentry_infos["access"].upper(),save,typeinfos[2],sizeof,name,sep) |
326 pointer_name = pointers_dict.get((index, subIndex), None) |
|
327 if pointer_name is not None: |
|
328 pointedVariableContent += "%s* %s = &%s;\n"%(typeinfos[0], pointer_name, name) |
|
322 strIndex += " };\n" |
329 strIndex += " };\n" |
323 indexContents[index] = strIndex |
330 indexContents[index] = strIndex |
324 |
331 |
325 #------------------------------------------------------------------------------- |
332 #------------------------------------------------------------------------------- |
326 # Declaration of Particular Parameters |
333 # Declaration of Particular Parameters |
327 #------------------------------------------------------------------------------- |
334 #------------------------------------------------------------------------------- |
328 |
335 |
329 if 0x1003 not in communicationlist: |
336 if 0x1003 not in communicationlist: |
428 #include "%s" |
435 #include "%s" |
429 """%(headerfilepath) |
436 """%(headerfilepath) |
430 |
437 |
431 fileContent += """ |
438 fileContent += """ |
432 /**************************************************************************/ |
439 /**************************************************************************/ |
433 /* Declaration of the mapped variables */ |
440 /* Declaration of mapped variables */ |
434 /**************************************************************************/ |
441 /**************************************************************************/ |
435 """ + mappedVariableContent |
442 """ + mappedVariableContent |
436 |
443 |
437 fileContent += """ |
444 fileContent += """ |
438 /**************************************************************************/ |
445 /**************************************************************************/ |
439 /* Declaration of the value range types */ |
446 /* Declaration of value range types */ |
440 /**************************************************************************/ |
447 /**************************************************************************/ |
441 """ + valueRangeContent |
448 """ + valueRangeContent |
442 |
449 |
443 fileContent += """ |
450 fileContent += """ |
444 /**************************************************************************/ |
451 /**************************************************************************/ |
471 """%texts |
478 """%texts |
472 contentlist = indexContents.keys() |
479 contentlist = indexContents.keys() |
473 contentlist.sort() |
480 contentlist.sort() |
474 for index in contentlist: |
481 for index in contentlist: |
475 fileContent += indexContents[index] |
482 fileContent += indexContents[index] |
483 |
|
484 fileContent += """ |
|
485 /**************************************************************************/ |
|
486 /* Declaration of pointed variables */ |
|
487 /**************************************************************************/ |
|
488 """ + pointedVariableContent |
|
476 |
489 |
477 fileContent += """ |
490 fileContent += """ |
478 const indextable %(NodeName)s_objdict[] = |
491 const indextable %(NodeName)s_objdict[] = |
479 { |
492 { |
480 """%texts |
493 """%texts |
540 |
553 |
541 #------------------------------------------------------------------------------- |
554 #------------------------------------------------------------------------------- |
542 # Main Function |
555 # Main Function |
543 #------------------------------------------------------------------------------- |
556 #------------------------------------------------------------------------------- |
544 |
557 |
545 def GenerateFile(filepath, node): |
558 def GenerateFile(filepath, node, pointers_dict = {}): |
546 try: |
559 try: |
547 headerfilepath = os.path.splitext(filepath)[0]+".h" |
560 headerfilepath = os.path.splitext(filepath)[0]+".h" |
548 content, header = GenerateFileContent(node, os.path.split(headerfilepath)[1]) |
561 content, header = GenerateFileContent(node, os.path.split(headerfilepath)[1], pointers_dict) |
549 WriteFile(filepath, content) |
562 WriteFile(filepath, content) |
550 WriteFile(headerfilepath, header) |
563 WriteFile(headerfilepath, header) |
551 return None |
564 return None |
552 except ValueError, message: |
565 except ValueError, message: |
553 return "Unable to Generate C File\n%s"%message |
566 return "Unable to Generate C File\n%s"%message |