Guest User

Untitled

a guest
Sep 13th, 2018
300
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! python
  2.  
  3. import sys
  4. import telnetlib
  5. import argparse
  6. import logging
  7.  
  8. parser = argparse.ArgumentParser(description="Python IALDOWN for HP Logic Analysers")
  9. parser.add_argument('-H', '--host', required=True, help='LA hostname')
  10. parser.add_argument('-p', '--port', type=int, default=5025, help='defaults to 5025')
  11. args = parser.parse_args(sys.argv[1:])
  12.  
  13. hostname=args.host
  14. port=args.port
  15.  
  16. # open up the telnet connection first
  17. # otherwise the user doesnt find out if its going to
  18. # work until after he types all the info in.
  19. tn = telnetlib.Telnet(hostname, port)
  20.  
  21. params = {}
  22.  
  23. params['filename'] = raw_input("Logic Analyzer Filename = ").rstrip()
  24. params['description'] = raw_input("Logic Analyzer File Description\n(must be 32 characters or less) = ").rstrip()
  25. params['rfile'] = raw_input("Relocatable File on the PC = ").rstrip()
  26. # ignored but here for compatibility with scripts
  27. params['comport'] = raw_input("COM Port (Ignored) = ").rstrip()
  28. params['option'] = raw_input(""""Invasm" Field Options:
  29. A = No "Invasm" Field
  30. B = "Invasm" Field with no pop-up
  31. C = "Invasm" Field with pop-up. 2 choices in pop-up.
  32. D = "Invasm" Field with pop-up. 8 choices in pop-up.
  33. Select the appropriate letter (A, B, C or D)""").rstrip()
  34.  
  35. if len(params['description']) > 32:
  36.     print "Description too long will be trimmed"
  37.  
  38. # read the data file
  39. with open(params['rfile'], 'rb') as f:
  40.     buffer = f.read()
  41.  
  42. # get the params.
  43. if params['option'].upper() == 'A':
  44.     type_byte = '\xFF'
  45. elif params['option'].upper() == 'B':
  46.     type_byte = '\x00'
  47. elif params['option'].upper() == 'C':
  48.     type_byte = '\x01'
  49. elif params['option'].upper() == 'D':
  50.     type_byte = '\x02'
  51. else:
  52.     raise Exception("Unknown type optiom specified (A,B,C or D)")
  53.  
  54. # now actually do the transfer.
  55. tn.write(""":MMEMory:DOWNload '{filename}',INTERNAL0,'{description}',-15614,""".format(**params))
  56. data_size = len(buffer)+1
  57.  
  58. tn.write("#8%08i" % data_size)
  59. tn.write(type_byte)
  60. tn.write(buffer)
  61. tn.write('\n')
  62. tn.close()
RAW Paste Data