PowCon_MLVDS_register_map_to_schedule.py
Go to the documentation of this file.
00001 # BMS_MLVDS_register_map_to_token.py
00002 # First row of the csv file must be header!
00003 import sys, getopt
00004 import csv
00005 
00006 def main(argv):
00007     csvFile = 'ICD_PowCon_MLVDS_Oct_28_2013.csv'
00008     xmlFile = 'PowConSchedule.xml'
00009 
00010     try:
00011         opts, args = getopt.getopt(argv, "hi:o:",["input=", "output="])
00012     except getopt.GetoptError:
00013         print("PowCon_MLVDS_register_map_to_token.py -i <inputfile> -o <outputfile>")
00014         sys.exit(2)
00015     for opt, arg in opts:
00016         if opt == '-h':
00017             print 'PowCon_MLVDS_register_map_to_token.py -i <inputfile> -o <outputfile>'
00018             sys.exit()
00019         elif opt in ("-i", "--input"):
00020             csvFile = arg
00021         elif opt in ("-o", "--output"):
00022             xmlFile = arg
00023 
00024     print("Opening " + csvFile)
00025     data = csv.reader(open(csvFile))
00026 
00027     print("Writing output to " + xmlFile)
00028     xmlData = open(xmlFile, 'w')
00029 
00030     xmlData.write('<?xml version="1.0" encoding="ISO-8859-1"?>' + "\n")
00031     xmlData.write('<ScheduleData>' + "\n")
00032     xmlData.write('    <Properties>' + "\n")
00033     xmlData.write('        The schedule for the PowCon Board in the Batpack' + "\n")
00034     xmlData.write('    </Properties>' + "\n")
00035     xmlData.write('    <Elements>' + "\n")
00036     rowNum = 0
00037     for row in data:
00038         if rowNum == 0:
00039             tags = row
00040             # replace spaces w/ underscores in tag names
00041             for i in range(len(tags)):
00042                 tags[i] = tags[i].strip().replace(' ', '_')
00043             if("name" in tags):
00044                 iName = tags.index("name")
00045                 print("found name tag at index: " + str(iName))
00046             else:
00047                 print("can not find name tag")
00048                 break    
00049             if("data_type" in tags):
00050                 iDataType = tags.index("data_type")
00051                 print("found datatype tag at index: " + str(iDataType))
00052             else:
00053                 print("can not find datatype tag")
00054                 break
00055             if("ROBONET_type" in tags):
00056                 iDirection = tags.index("ROBONET_type")
00057                 print("found ROBONET_type tag at index: " + str(iDirection))
00058             else:
00059                 print("can not find ROBONET_type tag")
00060                 break    
00061             if("style" in tags):
00062                 iStyle = tags.index("style")
00063                 print("found style tag at index: " + str(iStyle))
00064             else:
00065                 print("can not find style tag")
00066                 break    
00067         else:
00068             if(row[iName].strip().replace(' ', '_')):
00069                 if("status" in row[iDirection].lower()):
00070                     dirRW = "Read"
00071                 elif("control" in row[iDirection].lower()):
00072                     dirRW = "Write"
00073                 else:
00074                     rowNum +=1
00075                     continue
00076                 xmlData.write('        <Element {0:30} {1:15} {2:35} {3:20} {4:13} {5:40} /> \n'.format('id="' + str(row[iName].strip().replace(' ', '_')) + '"', 
00077                                                                                                         'type="' + str(row[iDataType]) + '"', 
00078                                                                                                         'offset1="' + str(row[iName]) + '"', 
00079                                                                                                         'direction="' + dirRW + '"', 
00080                                                                                                         'group="Power"', 
00081                                                                                                         'style="' + str(row[iStyle]) + '"'))
00082         rowNum +=1
00083     xmlData.write('    </Elements>' + "\n")
00084     xmlData.write('</ScheduleData>')
00085 
00086     xmlData.close()
00087 
00088 if __name__ == "__main__":
00089    main(sys.argv[1:])


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