PowCon_MLVDS_register_map_to_token.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # BMS_MLVDS_register_map_to_token.py
00003 # First row of the csv file must be header!
00004 import sys, getopt
00005 import csv
00006 
00007 def main(argv):
00008     csvFile = 'ICD_PowCon_MLVDS_Oct_28_2013.csv'
00009     xmlFile = 'PowConTokens.xml'
00010 
00011     try:
00012         opts, args = getopt.getopt(argv, "hi:o:",["input=", "output="])
00013     except getopt.GetoptError:
00014         print("PowCon_MLVDS_register_map_to_token.py -i <inputfile> -o <outputfile>")
00015         sys.exit(2)
00016     for opt, arg in opts:
00017         if opt == '-h':
00018             print 'PowCon_MLVDS_register_map_to_token.py -i <inputfile> -o <outputfile>'
00019             sys.exit()
00020         elif opt in ("-i", "--input"):
00021             csvFile = arg
00022         elif opt in ("-o", "--output"):
00023             xmlFile = arg
00024 
00025     print("Opening " + csvFile)
00026     data = csv.reader(open(csvFile))
00027 
00028     print("Writing output to " + xmlFile)
00029     xmlData = open(xmlFile, 'w')
00030 
00031     xmlData.write('<?xml version="1.0" encoding="ISO-8859-1"?>' + "\n")
00032     xmlData.write('<TokenData>' + "\n")
00033     xmlData.write('    <Properties>' + "\n")
00034     xmlData.write('        <Node>PowCon</Node>' + "\n")
00035     xmlData.write('        <Version>BatPack</Version>' + "\n")
00036     xmlData.write('    </Properties>' + "\n")
00037     xmlData.write('    <Tokens>' + "\n")
00038     rowNum = 0
00039     for row in data:
00040         if rowNum == 0:
00041             tags = row
00042             # replace spaces w/ underscores in tag names
00043             for i in range(len(tags)):
00044                 tags[i] = tags[i].strip().replace(' ', '_')
00045             if("addr_(hex)" in tags):
00046                 iHex = tags.index("addr_(hex)")
00047                 print("index of hex value: " + str(iHex))
00048             else:
00049                 break
00050             if("name" in tags):
00051                 iName = tags.index("name")
00052                 print("index of name: " + str(iName))
00053             else:
00054                 break            
00055         else:
00056             if(row[iName].strip().replace(' ', '_')):
00057                 xmlData.write('        <Token {0:50} {1:15} /> \n'.format('id="' + str(row[iName].strip().replace(' ', '_')) + '"', 'value="0x' + str(row[iHex]) + '"'))
00058         rowNum +=1
00059     xmlData.write('    </Tokens>' + "\n")
00060     xmlData.write('</TokenData>')
00061 
00062     xmlData.close()
00063 
00064 if __name__ == "__main__":
00065    main(sys.argv[1:])


robot_instance
Author(s):
autogenerated on Sat Jun 8 2019 20:43:12