def pingset(dspboardaddrs): eio = NetEventIO("10.0.0.2") eio.addRXMask(0xF1, xrange(256)) eio.start() # Create event and set mask N = 40 x = n.zeros(N) for i in range(N): e = Event() e.src = eaddr.NETWORK e.cmd = 0xF0 e.data[0] = 0x1234 ea = eaddr.TXDest() for d in dspboardaddrs: ea[d] = 1 eio.sendEvent(ea, e) erx = eio.getEvents() x[i] = len(erx) eio.stop() pylab.figure() pylab.hist(x)
def digital_out(ip): addr = ADDR_DIGITAL_OUT eio = NetEventIO(ip) eio.addRXMask(xrange(256), [addr]) eio.start() vals = True while True: e = Event() e.src = eaddr.NETWORK e.cmd = DIGITALOUT_WRITE e.data[0] = 0xFFFF e.data[1] = 0xFFFF if vals: e.data[2] = 0xFFFF e.data[3] = 0xFFFF else: e.data[2] = 0x0 e.data[3] = 0x0 ea = eaddr.TXDest() ea[addr] = 1 eio.sendEvent(ea, e) # now read e = Event() e.src = eaddr.NETWORK e.cmd = DIGITALOUT_READ ea = eaddr.TXDest() ea[addr] = 1 eio.sendEvent(ea, e) erx = eio.getEvents(blocking=True) for e in erx: print e vals = not vals time.sleep(0.2) eio.stop()
class FPGAPing(object): def __init__(self, somaIP, tgts): self.eio = NetEventIO(somaIP) self.pingtgts = set(tgts) for i in self.pingtgts: #self.eio.addRXMask(0x09, i) self.eio.addRXMask(PING_RESPONSE_CMD, i) self.eio.start() def ping(self): # Create event and set mask e = Event() e.src = eaddr.NETWORK e.cmd = 0x08 e.data[0] = 0x1234 e.data[1] = 0x5678 ea = eaddr.TXDest() for i in self.pingtgts: ea[i] = 1 self.eio.sendEvent(ea, e) starttime = time.time() PINGWAIT = 1.0 eventsrxed = [] while len(eventsrxed) < len(self.pingtgts): erx = self.eio.getEvents(blocking=False) if erx != None: for eias in erx: print eias eventsrxed += erx if time.time() > starttime + PINGWAIT: break rxset = set() for e in eventsrxed: rxset.add(e.src) missing = self.pingtgts.difference(rxset) return (rxset, missing) def stop(self): self.eio.stop()
class FPGAPing(object): def __init__(self, somaIP, tgts): self.eio = NetEventIO(somaIP) self.pingtgts = set(tgts) for i in self.pingtgts: # self.eio.addRXMask(0x09, i) self.eio.addRXMask(PING_RESPONSE_CMD, i) self.eio.start() def ping(self): # Create event and set mask e = Event() e.src = eaddr.NETWORK e.cmd = 0x08 e.data[0] = 0x1234 e.data[1] = 0x5678 ea = eaddr.TXDest() for i in self.pingtgts: ea[i] = 1 self.eio.sendEvent(ea, e) starttime = time.time() PINGWAIT = 1.0 eventsrxed = [] while len(eventsrxed) < len(self.pingtgts): erx = self.eio.getEvents(blocking=False) if erx != None: for eias in erx: print eias eventsrxed += erx if time.time() > starttime + PINGWAIT: break rxset = set() for e in eventsrxed: rxset.add(e.src) missing = self.pingtgts.difference(rxset) return (rxset, missing) def stop(self): self.eio.stop()
def debug(dspboardaddrs): eio = NetEventIO("10.0.0.2") eio.addRXMask(0x38, dspboardaddrs) eio.start() print "Sending to ", dspboardaddrs # Create event and set mask e = Event() e.src = eaddr.NETWORK e.cmd = 0x38 for d in dspboardaddrs: ea = eaddr.TXDest() ea[d] = 1 eio.sendEvent(ea, e) print "sending", e erx = eio.getEvents() print erx[0] eio.stop()
def ping_digital_out(ip): addr = DIGITAL_OUT eio = NetEventIO(ip) eio.addRXMask(PING_RESPONSE_CMD, [addr]) eio.start() e = Event() e.src = eaddr.NETWORK e.cmd = 0x08 e.data[0] = 0x1234 e.data[1] = 0x5678 ea = eaddr.TXDest() ea[addr] = 1 eio.sendEvent(ea, e) erx = eio.getEvents(blocking=True) for e in erx: print e eio.stop()
class AcqBoardInterface(object): CMDFIBERCMD = 0x50 CMDFIBERDATAA = 128 CMDFIBERDATAB = 129 CMDFIBERRESP = 0x82 DESTSRCID = 76 def __init__(self, IP="10.0.0.2", set = 'A'): self.eio = NetEventIO(IP) self.set = set def sendCommandAndBlock(self, acqboardcmd): """ acqboardcmd is an AcqBoardCommand object whose state represents the most recent state change to the board; we retreive the encoded string with acqboardcmd.latestString and the most recent commandID with . """ # setup rx self.eio.addRXMask(self.CMDFIBERRESP, xrange(256) ) SRC = 3 acmdstr = acqboardcmd.latestString # this is a total hack, we extract out the command byte bytes = struct.unpack("BBBBBB", acmdstr) cmdid = bytes[0] >> 4 cmd = bytes[0] & 0xF assert cmdid == acqboardcmd.cmdid self.eio.start() ea = eaddr.TXDest() ea[:] = 1 e = Event() e.cmd = self.CMDFIBERCMD e.src = SRC e.data[0] = (cmdid << 8) | cmd e.data[1] = bytes[4] << 8 | bytes[3] e.data[2] = bytes[2] << 8 | bytes[1] ## Substantial debugging #cmdtuple = (0x50, 4, (cmdid << 8) | (cmd & 0xF), 1, 0, 0, 0) #self.pne.sendEvent(addrtuple, cmdtuple) print "sending event", e self.eio.sendEvent(ea, e) success = False while success == False: erx = self.eio.getEvents() # extract out events for e in erx: #print e if e.cmd == self.CMDFIBERRESP: # and e.src == self.DESTSRCID: # response; extract out bits cmdid = e.data[0] if cmdid == acqboardcmd.cmdid: success = True self.eio.stop() def getSamples(self, N): """ Very simple interface to getting samples -- at the moment we just return N samples from either the A channels or the B channels""" data = n.zeros((5, N), dtype=n.int16) if self.set == "A": self.eio.addRXMask(self.CMDFIBERDATAA, xrange(256) ) elif self.set == "B" : self.eio.addRXMask(self.CMDFIBERDATAB, xrange(256) ) else: # both self.eio.addRXMask(self.CMDFIBERDATAA, xrange(256) ) self.eio.addRXMask(self.CMDFIBERDATAB, xrange(256) ) self.eio.start() receivedN = 0 while (receivedN < N): erx = self.eio.getEvents() for e in erx: if receivedN < N: for i in xrange(5): data[i][receivedN] = e.data[i] receivedN += 1 self.eio.stop() return data def getNormSamplesA(self, N): """ Return 5xN "normal", that is not-raw-mode, samples, from the A tetrode set of channels """ self.set = "A" return self.getSamples(N) def getNormSamplesB(self, N): """ Return 5xN "normal", that is not-raw-mode, samples, from the B tetrode set of channels """ self.set = "B" return self.getSamples(N) def getRawSamples(self, N): """ return N sampes as if from "Raw" """ raise "Not implemented"
eio.start() CMD = 0xF2 # Create event and set mask while (1): e = Event() e.src = eaddr.NETWORK e.cmd = CMD e.data[0] = 0xFFFF ea = eaddr.TXDest() for i in dspaddrs: ea[i] = 1 eio.sendEvent(ea, e) #rint "on" time.sleep(delay) e = Event() e.src = eaddr.NETWORK e.cmd = CMD e.data[0] = 0x0 ea = eaddr.TXDest() for i in dspaddrs: ea[i] = 1 eio.sendEvent(ea, e) # print "off" time.sleep(delay)
src = eaddr.JTAG else: eio = NetEventIO("10.0.0.2") src = eaddr.NETWORK eio.addRXMask(xrange(256), eaddr.SYSCONTROL) eio.start() e = Event() e.src = src e.cmd = 0x20 ea = eaddr.TXDest() ea[eaddr.SYSCONTROL] = 1 eio.sendEvent(ea, e) erx = eio.getEvents() linkstatus_event = erx[0] print "link status event:", linkstatus_event # now get all of the counter events DEVN = 4 rx_set = {} for i in range(DEVN): e = Event() e.src = src e.cmd = 0x21 e.data[0] = i ea = eaddr.TXDest()
eio.addRXMask(ECMD_ECHOPROC_MEMCHECK_RESP, dspboardaddrs) eio.addRXMask(ECMD_ECHOPROC_BENCHMARK_RESP, dspboardaddrs) eio.start() for d in dspboardaddrs: print "Device %02x ----------------------------------------" % (d,) # Create event and set mask e = Event() e.src = eaddr.NETWORK e.cmd = ECMD_ECHOPROC_MEMCHECK ea = eaddr.TXDest() ea[d] = 1 eio.sendEvent(ea, e) erx = eio.getEvents() memsize = erx[0].data[1] print "heap use: %2.2fk" % (memsize/ 1000.0 ) # get the benchmarks: for i in range(3): eb = Event() eb.src = eaddr.NETWORK eb.cmd = ECMD_ECHOPROC_BENCHMARK eb.data[0] = i eab = eaddr.TXDest() eab[d] = 1 eio.sendEvent(eab, eb)
class DeviceLinkStatus(object): def __init__(self, SOMAIP): self.eio = NetEventIO(SOMAIP) self.src = eaddr.NETWORK self.eio.addRXMask(xrange(256), eaddr.SYSCONTROL) self.eio.start() def getLinkStatus(self, DEVN): # get the link status event e = Event() e.src = self.src e.cmd = 0x20 ea = eaddr.TXDest() ea[eaddr.SYSCONTROL] = 1 self.eio.sendEvent(ea, e) erx = self.eio.getEvents() linkstatus_event = erx[0] # now parse the link status event status = [] for i in range(DEVN): if (linkstatus_event.data[1] >> i) & 0x1 > 0: status.append(True) else: status.append(False) return status def getLinkCycleCount(self, DEVN): # now get all of the counter events rx_set = {} for i in range(DEVN): e = Event() e.src = self.src e.cmd = 0x21 e.data[0] = i ea = eaddr.TXDest() ea[eaddr.SYSCONTROL] = 1 self.eio.sendEvent(ea, e) erx = self.eio.getEvents() rx_set[i] = erx cyclecnt = [] for i in range(DEVN): cyclecnt.append(rx_set[i][0].data[2]) return cyclecnt ## print debug_event ## for i in range(DEVN): ## dly = (-1, -1) ## if i in delays: ## dly = (delays[i] >> 8, delays[1] & 0xFF) ## if (linkstatus_event.data[1] >> i) & 0x1 > 0: ## print "Device %2d : UP" % i, ## else: ## print "Device %2d : " % i, ## print "%d link cycles" % (rx_set[i][0].data[2] ) def getDLTiming(self): # now get the debug counters e = Event() e.src = self.src e.cmd = 0x22 ea = eaddr.TXDest() ea[eaddr.SYSCONTROL] = 1 self.eio.sendEvent(ea, e) erx = self.eio.getEvents() for e in erx: debug_event = erx[0] timings = [] for ei in range(4): tpos = (debug_event.data[ei] >> 8 ) & 0xFF tlen = debug_event.data[ei] & 0xFF timings.append((tpos, tlen)) return timings def stop(self): self.eio.stop()
def manual_boot_device(filename, devicenums, youares): """ Devicenums are the device link nums. Note that they do not map directly onto the configuration bit lines """ eio = NetEventIO("10.0.0.2") eio.addRXMask(xrange(256), eaddr.SYSCONTROL) eio.start() MANBOOTSER_SETMASK = 0xA0 MANBOOTSER_TOGPROG = 0xA1 MANBOOTSER_WRITEBYTES = 0xA2 MANBOOTSER_SENDBYTES = 0xA3 EVENTCMD_YOUARE = 0x01 EVENTCMD_LINKSTATUS = 0x20 e = Event() e.src = eaddr.NETWORK e.cmd = MANBOOTSER_SETMASK wrd = 0 #int_devicenums = [int(x) for x in devicenums] for d in devicenums: # [device_to_config_mapping[x] for x in int_devicenums]: cfg_line = device_to_config_bits[d] wrd |= (1 << cfg_line) #print "word = %8.8X" % wrd # FIXME: e.data[0] = wrd >> 16 e.data[1] = wrd & 0xFFFF ea = eaddr.TXDest() ea[eaddr.SYSCONTROL] = 1 eio.sendEvent(ea, e) # toggle FPROG e.cmd = MANBOOTSER_TOGPROG eio.sendEvent(ea, e) # send the actual data fid = file(filename) fid.seek(72) data = fid.read(8) pos = 0 ecnt = 0 while data: e.cmd = MANBOOTSER_WRITEBYTES e.src = eaddr.NETWORK ea = eaddr.TXDest() ea[eaddr.SYSCONTROL] = 1 if len(data) < 8: #print "The end" data = data + " " for i in xrange(4): e.data[i] = struct.unpack(">H", data[(i*2):(i*2+2)])[0] reallysend(eio, ea, e) # now push the bytes to the client device e.cmd = MANBOOTSER_SENDBYTES e.src = eaddr.NETWORK ea = eaddr.TXDest() ea[eaddr.SYSCONTROL] = 1 reallysend(eio, ea, e) erx = eio.getEvents() data =fid.read(8) pos += 8 ecnt += 1 # loop and query the linkstatus register to see if our links # are up yet, and once they are, go. up_delay = False allup = False for i in range(20): e = Event() e.cmd = EVENTCMD_LINKSTATUS e.src = eaddr.NETWORK ea = eaddr.TXDest() ea[eaddr.SYSCONTROL] = 1 reallysend(eio, ea, e) erx = eio.getEvents(False) device_status_event = None if erx != None: for e in erx: if e.cmd == EVENTCMD_LINKSTATUS: device_status_event = e if device_status_event: stat = parse_linkstatus(device_status_event) allup = True for i in devicenums: if not stat[i]: allup = False if allup: break up_delay += 1 time.sleep(1) if not allup: print "Was unable to bring up the requested links" sys.exit(1) else: print "links up after", up_delay, "secs" #now send the YOUARE so the device knows who it is for deviceid in youares: e = Event() e.cmd = EVENTCMD_YOUARE e.src = eaddr.NETWORK e.data[0] = deviceid ea = eaddr.TXDest() ea[deviceid] = 1 print "Sending youare for ", deviceid, e reallysend(eio, ea, e) eio.stop()
eio.addRXMask(ECMD_ECHOPROC_MEMCHECK_RESP, dspboardaddrs) eio.addRXMask(ECMD_ECHOPROC_BENCHMARK_RESP, dspboardaddrs) eio.start() for d in dspboardaddrs: print "Device %02x ----------------------------------------" % (d, ) # Create event and set mask e = Event() e.src = eaddr.NETWORK e.cmd = ECMD_ECHOPROC_MEMCHECK ea = eaddr.TXDest() ea[d] = 1 eio.sendEvent(ea, e) erx = eio.getEvents() memsize = erx[0].data[1] print "heap use: %2.2fk" % (memsize / 1000.0) # get the benchmarks: for i in range(3): eb = Event() eb.src = eaddr.NETWORK eb.cmd = ECMD_ECHOPROC_BENCHMARK eb.data[0] = i eab = eaddr.TXDest() eab[d] = 1 eio.sendEvent(eab, eb)
class AudioMonitorCore(dbus.service.Object): def __init__(self, *args): dbus.service.Object.__init__(self, *args) # State Variables self.playing = False self.audioChan = 0x20; self.selectedAudioChan = self.audioChan self.subChan = 0; #most likely will refere to a tetrode sub-channel self.selectedSubChan = self.subChan self.eio = NetEventIO("10.0.0.2") # AudioControl Event Constants setup on 10/13/08 self.AUDIO_EVENT_CMD = 0x12 self.ENABLE_AUDIO_EVENTS = 1 self.DISABLE_AUDIO_EVENTS = 0 self.AUDIO_REQUEST = 0 self.AUDIO_UPDATE = 1 #Create GST elements - pipeline will not be created gobject.type_register(SomaAudioEventFilter) self.eventSource = gst.element_factory_make('somaeventsource', "SomaEventSource") self.audioEventFilter = SomaAudioEventFilter() self.AUDIO_SINK = "pulsesink" self.audioSink = gst.element_factory_make(self.AUDIO_SINK) self.audioConverter = gst.element_factory_make("audioconvert") self.audioResampler= gst.element_factory_make("audioresample") self.queue = gst.element_factory_make("queue") self.pipeline = None def setChannel(self, src): print "setting Channel to:", src self.selectedAudioChan = src def getChannel(self): return self.audioChan def setSubChannel(self, chan): print "stting SubChannel to:", chan self.selectedSubChan = chan def getSubChannel(self): return self.subChan def startPlaying(self): if self.pipeline == None: self.__createNewPipeline() print "Create Pipeline" print "Play Pipeline" self.pipeline.set_state(gst.STATE_PLAYING) def stopPlaying(self): print "Destroy Pipeline" if self.pipeline != None: self.pipeline.set_state(gst.STATE_NULL) self.pipeline = None # ----- Private Methods, Pipeline control, Event Transmission, and looping def __createNewPipeline(self): self.pipeline = gst.Pipeline() self.audioEventFilter.set_audio_src(self.audioChan) self.pipeline.add(self.eventSource, self.audioEventFilter) self.pipeline.add(self.queue, self.audioConverter, self.audioResampler) self.pipeline.add(self.audioSink) gst.element_link_many(self.eventSource, self.audioEventFilter,self.queue, self.audioConverter, self.audioResampler, self.audioSink) def __loop(self): if self.audioChan != self.selectedAudioChan: changeSource() if self.subChan != self.selectedSubChan: changeSource() self.processEvents(self.eio.getEvents(), False) def changeSource(self): self.stopPlaying() self.disableCurrentSource() self.enableDesiredSource() if self.playing==True: self.startPlaying() def disableCurrentSource(self): e = self.disableEvent() self.eio.addRxMask(self.AUDIO_EVENT_CMD, self.audioChan) ea = eaddr.TXDest() ea[self.audioChan] = 1 self.eio.sendEvent(e, ea) # Send the disable Event self.processEvents(self.eio.getEvents(), True) # Act when the disable Event is echoed back ea[self.audioChan] = 0 self.playing = False def enableDesiredSource(self): self.eio.addRxMask(self.AUDIO_EVENT_CMD, self.selectedAudioChan, True) e = self.enableEvent() ea[self.selectedAudioChan] = 0 self.eio.sendEvent(e, ea) # Send the enable event self.processEvents(self.eio.getEvents(), True) # Act when the enable Event is echoed back def processEvents(self, events, active): for e in events: src = e.src if unpack('>H', e.data[0])[0] == 1: #Reporting a Change if unpack('>H', e.data[1])[0] == 0: #Device has been disabled if src==self.audioChan: self.stopPlaying() if active==False: # if the source wasn't actively changed re-enable it self.enableDesiredSource() if unpack('>H', e.data[1])[0] == 1: #Device has been enabled if src==self.selectedAudioChan: self.audioChan = self.selectedAudioChan #selected chan is playing make def disableEvent(self): e = Event() e.cmd = self.AUDIO_EVENT_CMD e.src = eaddr.NETWORK e.data[0] = pack('>H', 0) #Requesting Change e.data[1] = pack('>H', 0) #Set Channel to Off return e def enableEvent(self): e = Event() e.cmd = self.AUDIO_EVENT_CMD e.src = eaddr.NETWORK e.data[0] = pack('>H', 0) #Requesting Change e.data[1] = pack('>H', 1) #Set Channel to On e.data[2] = pack('>H', self.selectedSubChan) e.data[3] = pack('>H', 32000) return e # ---------- DBus Methods @dbus.service.method("soma.audio.AudioMonitor") def start_playing(self): print "DBus call to start audio monitor" self.startPlaying() @dbus.service.method("soma.audio.AudioMonitor") def stop_playing(self): print "DBus call to pause audio monitor" self.stopPlaying() @dbus.service.method("soma.audio.AudioMonitor", in_signature='i') def set_audio_channel(self, src): print src self.setChannel(src) @dbus.service.method("soma.audio.AudioMonitor", out_signature='i') def get_audio_channel(self): return self.getChannel() @dbus.service.method("soma.audio.AudioMonitor", in_signature='i') def set_sub_channel(self, src): self.setSubChannel(src) @dbus.service.method("soma.audio.AudioMonitor", out_signature='i') def get_sub_channel(self): return self.getSubChannel() @dbus.service.method("soma.audio.AudioMonitor", out_signature='b') def get_playing_state(self): return self.playing