Example #1
0
def loadWave(wavePath, numSamples, seqStart, srcChan, selChan):
	type = 1
	print "Loading  EEG "
	waveList, seq = [], seqStart
	waveFile = EEGReader(wavePath, selChan)
	
	for i in range(numSamples):
		sample = waveFile.getRecord(100)
		if sample == "%ENDFILE": break
		wavePacket = dataPacketHandler.encodePacket(seq, sample.toBinary(srcChan, type))
		waveList.append(wavePacket)
		seq += 1
	return waveList
Example #2
0
def loadSpikes(ttPath, seqStart, numSpikes, srcChan):
	type = 0
	print "Loading real spikes"
	sList, seq = [], seqStart
	ttFile = TTReader(ttPath)
	ttFile.readHeader()
	print "LOADING SPIKES, depending spikeNum this may take some time...."
	for i in range(numSpikes):
		spike = ttFile.getSpike()
		if spike == "%ENDFILE": break
		s = dataPacketHandler.encodePacket(seq, spike.toBinary(srcChan, type))
		sList.append(s)
		seq += 1
	print "tSpikes loaded!"
	return sList
	def sendPackets(self):
		data = self.packetList.pop(0)
		seq = dataPacketHandler.getPacketSeq(data)
#		print "Writing:" #, data
		self.transport.write(data,(self.bcast,self.port))
		self.cachePacket(data)  # save if packet is needed in a ReTx
		
#		print "Getting old seq"
		seqNew = self.getSequence()+1  # as the packet list goes 1 -> 2 -> ... -> n ->1  but we can't do this we seq numbers so we need to update them to a new number everytime we paste the packet back into the list
		seqOld, pData = dataPacketHandler.decodePacket(data)
		newData = dataPacketHandler.encodePacket(seqNew, pData)

		self.packetList.append(newData) #adds spike to end of list
#		print "sleeping"
		self.reactor.callLater(self.sleep, self.sendPackets)
Example #4
0
def genFakeSpikes(numSpikes, seqStart, srcChn):
	print "Generating fake spikes"
	seq = seqStart
	sList = []
	type = 0
	for i in range(numSpikes):
		spike = TSpike(time.clock())
		chan1 = [30000 * (((i+0)%4)+4) -100000] * 32;
		chan2 = [30000 * (((i+2)%4)+4) -100000] * 32;
		chan3 = [30000 * (((i+3)%4)+4) -100000] * 32;
		chan4 = [30000 * (((i+4)%4)+4) -100000] * 32;
		spike.addChannel(0, 1, 0, 250, chan1)
		spike.addChannel(1, 1, 0, 250, chan2)
		spike.addChannel(2, 1, 0, 250, chan3)
		spike.addChannel(3, 1, 0, 250, chan4)
		s = dataPacketHandler.encodePacket(seq, spike.toBinary(srcChn, type))
		sList.append(s)
		seq += 1
	print "Fake Spike data GENERATED!"
	return sList
Example #5
0
def genFakeWave(numSamples, seqStart, srcChn):
	print "Generating fake EEG wave data"
	import time, math
	seq = seqStart
	waveList = []
	type = 1
	gain = 10000
	selChan, rateNumer, rateDenom, filid = 0, 4000, 1, 1

	for packet in range(numSamples):
		wave = EEGSample(selChan, rateNumer, rateDenom, filid, time.clock())
		samples = []

		for sample in range(100):
			samples.append(int(math.sin(2*math.pi*sample/100)*gain))
		wave.addChannel(samples)
		wave = dataPacketHandler.encodePacket(seq, wave.toBinary(srcChn,type))
		waveList.append(wave)
		seq += 1
	return waveList