Guest User

Untitled

a guest
Jul 21st, 2019
72
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from ironman.constructs.ipbus import IPBusConstruct
  2. from ironman.hardware import HardwareManager, HardwareMap
  3. from ironman.communicator import Jarvis
  4. from ironman.packet import IPBusPacket
  5. from twisted.internet.defer import Deferred
  6. import mmap
  7.  
  8. hardware_map = '''
  9. nodes:
  10. -
  11. id: devmemtest
  12. address: 0x00000000
  13. nodes:
  14. - {id: read, address: 0x0, permissions: 1}
  15. '''
  16.  
  17. j = Jarvis()
  18. manager = HardwareManager()
  19.  
  20. manager.add(HardwareMap(hardware_map, 'main'))
  21. j.set_hardware_manager(manager)
  22.  
  23. @j.register('main')
  24. class DevMemIO(object):
  25. __f__ = open('/dev/mem', 'r+')
  26.  
  27. def read(self, offset, size):
  28. with mmap.mmap(__f__.fileno(), size, offset=offset) as m:
  29. return m.readline()
  30.  
  31. def buildResponsePacket(packet):
  32. packet.response.transactions[0].header.info_code = 'SUCCESS'
  33. return IPBusConstruct.build(packet.response)
  34.  
  35. def printPacket(raw):
  36. print "raw: {0:s}".format(repr(raw.encode('hex')))
  37. print IPBusConstruct.parse(raw)
  38.  
  39. d = Deferred().addCallback(IPBusPacket).addCallback(j).addCallback(buildResponsePacket).addCallback(printPacket)
  40. initialPacket = '200000f02000010f00000002'.decode('hex')
  41. d.callback(initialPacket)
RAW Paste Data