
#
# Use library for VME I/O via network calls; also normal libraries
#
from Vision import *
import string

def main():
  #
  # Connect to boards, send backplane init signal
  #
  crate = "yellow.uchicago.edu"
  sc = Slave(crate, 3)			# connect to Spy Control board
  sc.writeword(0x108, 0)		# send SVT_INIT pulse
  gb = Slave(crate, 7)			# connect to GhostBuster board

  #
  # Prepare dummy input data and expected output data
  #
  din = map(lambda x: 0x600000|(x&0xff), range(16))
  din = map(lambda x: string.atoi(x, 16), open("gbinput.dat").readlines())
  expect = map(lambda x: string.atoi(x, 16), open("gboutput.dat").readlines())
  f = open("gboutput_board.dat","w")
  #
  # Send data out from channel 2; read channel 1's input FIFO
  #
  for i in range(1):
    gb.writewords(0x1e<<17 | 2<<22, din)
    dout = gb.readwords(0x1e<<17 | 2<<22, 512)
    dout = filter(lambda x: (x>>31&1)==0, dout)
    print map(lambda x: "%6.6x"%(x), din)
    print map(lambda x: "%6.6x"%(x), dout)
    print map(lambda x: "%6.6x"%(x), expect)
    if dout==expect:
      print "good"
    else:
      print "bad"
    if dout!=expect:
      print "bad"       
      f.writelines(map(lambda x: "%6.6x\n"%(x), dout))
      f.flush()
    #for j in range(1):
    #  if j>=100: print "1Bunch of track is finished!!" 
  f.close()
  print "%x"%(gb.readword(0<<22 | 0x80<<2))
  print "%x"%(gb.readword(0<<22 | 0x81<<2))
  print "%x"%(gb.readword(0<<22 | 0x82<<2))
  print "%x"%(gb.readword(0<<22 | 0x83<<2))
  print "%x"%(gb.readword(0<<22 | 0x84<<2))
  print "%x"%(gb.readword(0<<22 | 0x85<<2))

if __name__=="__main__":
  main()
