예제 #1
0
 def test_doubleFunctionality(self):
     message = 'helloworld'
     chars = IL.loadCharacterSet('lowerCaseLiterals')
     srcEncoder = IL.SrcEncoder(chars, 'basic')
     srcDecoder = RL.sourceDecoder(chars, 'basic')
     binMessage = srcEncoder.EncodeData(message)
     symbols = IL.SymbolMapping(binMessage, 4)
     recBin = RL.Demapper(symbols, 4, 'HARD')
     recvMessage = srcDecoder.Decode(recBin)
     self.assertEqual(message, recvMessage)
예제 #2
0
    def run_receiver(self):

        fig = plt.figure(figsize=(3, 3))
        ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
        canvas = FigureCanvasTkAgg(fig, master=self.main_class)
        canvas.get_tk_widget().grid(row=8, column=0)
        canvas.show()
        time.sleep(1)

        x_axis = numpy.linspace(0, 64,
                                (128 * self.TimePerSymbolSeconds) / 2 + 1)
        numBatches = int(self.recordTime / self.TimePerSymbolSeconds)
        Data = numpy.zeros([self.recordTime * 128, len(self.Electrodes)])

        self.main_class.update()
        if self.syncMethod == 'HeaderV2':
            if self.EEGChannel.gaze_detect():
                self.set_gaze_detected()
                self.main_class.update()
            if self.EEGChannel.threshold_detect():
                self.set_threshold_detect()
                self.main_class.update()
        else:
            self.EEGChannel.waitForStart(self.syncMethod)
            self.main_class.update()

        self.EEGChannel.flushBuffer()
        for i in range(numBatches):
            newData = self.EEGChannel.getDataBlock(self.TimePerSymbolSeconds,
                                                   False)
            Data = dataUpdate(Data, newData)
            dataToPlot = getFFTs(newData)
            ax.clear()
            ax.plot(x_axis, dataToPlot[:, 0])
            canvas.draw()
            time.sleep(0.001)
            self.main_class.update()
            print(time.time())

        print 'DATA: ', Data
        Symbols = self.Detector.getSymbols(Data)
        print(Symbols)
        self.recv_symbols.insert(0.0, Symbols)
        Encoded = RL.Demapper(Symbols, len(self.TransmissionFrequenciesActual),
                              self.DecisionType)
        DeIntBits = self.CD.de_interleave(Encoded)
        print(DeIntBits)
        Decoded = self.CD.Decode(DeIntBits)
        self.dec_msg.insert(0.0, Decoded)
        String = self.SD.Decode(Decoded)
        self.dec_str.insert(0.0, String)
        print(String)

        self.restart_button.grid(row=8, column=0)  #pack(pady=10, padx=20)
        self.main_class.update()
예제 #3
0
	def run_receiver(self):
		
		#while 1:
		sendString = self.InputValidationObject.getInput()
		SendBits = self.SrcEncoder.EncodeData(sendString)
		#print 'Sendbits: ', SendBits
		EncBits = self.FEC.EncodeData(SendBits)
		#print 'EncBits:', (EncBits)
		IntBits = self.FEC.interleave(EncBits)
		#print 'IntBITS: ', (IntBits)
	
		NoisyBits = ''
		for i in range(0, len(IntBits)):
			if i == 2:
				NoisyBits += '1'
			else:
				NoisyBits += IntBits[i]
	
		print 'NoisyBits: ', NoisyBits
		
		#wait for bool to change colour
		#if waitforStart:
		self.set_gaze_detected()
		self.set_threshold_detect()
		
		Symbols  = IL.SymbolMapping(NoisyBits, 4)
		print 'Symbols: ', (Symbols)
	
		
	
		Encoded = RL.Demapper(Symbols,4, 'HARD')
		print 'Encoded: ', (Encoded)
		self.encoded = Encoded
		self.recv_symbols.insert(0.0,Encoded)
		DeintBits = self.CD.de_interleave(Encoded)
		print 'DEint Bits: ',(DeintBits)
		Decoded = self.CD.Decode(DeintBits)
		print 'Decoded: ', Decoded
		String = self.SD.Decode(Decoded)
		print 'String: ', String
			
			
		self.restart_button.grid(row=8,column=0) #pack(pady=10, padx=20)
예제 #4
0
def RunReciever( data_file, results_file , config_parameters, test_option ):
	# function which will execute a run of the emotiv reciever

	channel = Channel.Channel(config_parameters["CHANNEL_SOURCE"], config_parameters["ELECTRODES"], config_parameters["FILE_WRITE"],\
					  holdFreq= HOLD_FREQUENCY, headerFreq = HEADER_FREQUENCY ,startThreshold= START_THRESHOLD ,\
					  startThresholdRelative= START_THRESHOLD_RELATIVE,\
					  crossoverThresholdRelative= CROSSOVER_THRESHOLD_RELATIVE )
	detectorCCA = Reciever.DetectionObject("CCA", config_parameters["TRANSMISSION_FREQUENCIES"], None, config_parameters["ELECTRODES"], config_parameters["TIME_PER_SYMBOL"],config_parameters["DECISION_TYPE"])
	detectorPSDA = Reciever.DetectionObject("PSDA", config_parameters["TRANSMISSION_FREQUENCIES"], None, config_parameters["ELECTRODES"][0], config_parameters["TIME_PER_SYMBOL"],config_parameters["DECISION_TYPE"])


	channelDecoder = Reciever.ChannelDecoder(config_parameters["ERROR_CORRECTION"],"HARD",\
					config_parameters["FEC_BLOCK_SIZE"], config_parameters["FEC_MESSAGE_SIZE"])

	characterSet =  Reciever.loadCharacterSet(config_parameters["CHARACTER_SET"])
	sourceDecoder = Reciever.sourceDecoder(characterSet,config_parameters["SOURCE_ENCODER"])


	#calculate the record time
	recordTime = Reciever.calculateRecvTime(config_parameters["TIME_PER_SYMBOL"],\
										    len( config_parameters["TRANSMISSION_FREQUENCIES"] ),\
										    config_parameters["FEC_BLOCK_SIZE"],\
										    config_parameters["FEC_MESSAGE_SIZE"],\
										    config_parameters["CHARACTERS_PER_MESSAGE"],\
										    len(characterSet))
	print('calculated record time is: '+ str(recordTime))

	# need to now do the actual recording here
	# channel.setFileName(data_file)
	raw_input("ready ... press Enter to Start")
	if config_parameters["SYNC_METHOD"] == 'HeaderV2':
		print('--- DETECTING GAZE ----')
		channel.gaze_detect()
		print('--- GAZE DETECTED ----')
		channel.threshold_detect()
		print('--- THRESHOLD DETECTED ----')
	else:
		channel.waitForStart(config_parameters["SYNC_METHOD"])


	recordStartTime = time.time()
	symbolsToCapture = int(float(recordTime)/float(config_parameters["TIME_PER_SYMBOL"]))
	print("--- DATA RECORDING STARTED --- " + str(recordStartTime))
	channel.flushBuffer()

	symbolsCCA = []
	symbolsPSDA = []
	Data = numpy.zeros((0, len(config_parameters["ELECTRODES"])))
	for symbol in range(symbolsToCapture):
		print("Getting Symbol "+str(symbol)+'. . . .')
		DataBlock = channel.getDataBlock(int(config_parameters["TIME_PER_SYMBOL"]),False)
		Data = numpy.concatenate([Data, DataBlock])
		print( 'Number of samples collected: ' + str(len(DataBlock)))

		symbolsPSDA.append(detectorPSDA.getSymbols(DataBlock)[0])
		symbolsCCA.append(detectorCCA.getSymbols(DataBlock)[0])
		print('psda symbol vector :' + str(symbolsPSDA))
		print('cca symbol vector :' +  str(symbolsCCA))

	if int(recordTime) != 0:
		intCCA =     Reciever.Demapper(symbolsCCA,  len(config_parameters["TRANSMISSION_FREQUENCIES"] ),'HARD')
		intPSDA =    Reciever.Demapper(symbolsPSDA,len(config_parameters["TRANSMISSION_FREQUENCIES"] ),'HARD')
		encodedCCA = channelDecoder.de_interleave(intCCA)
		encodedPSDA =channelDecoder.de_interleave(intPSDA)
		binaryCCA =  channelDecoder.Decode(encodedCCA)
		binaryPSDA = channelDecoder.Decode(encodedPSDA)
		StringCCA =  sourceDecoder.Decode(binaryCCA)
		StringPSDA = sourceDecoder.Decode(binaryPSDA)
		print('Message Recieved from the CCA reciever '+StringCCA)
		print('Message Recieved from the PSDA reciever '+StringPSDA)

	successful = raw_input("Was this a successful run (Y/n): ")
	comments = raw_input("Provide any comments on the trial here: \n")

	results = {}
	results["SUCCESSFUL"] = successful
	results["COMMENTS"] = comments
	results["CONFIGURATION"] = config_parameters
	results["RECORD_START_TIME"] = recordStartTime

	if test_option != 'protocol_only':
		results["INTERLEAVED_CCA"]= intCCA
		results["INTERLEAVED_PSDA"]= intPSDA 
		results["ENCODED_CCA"]= encodedCCA
		results["ENCODED_PSDA"]= encodedPSDA
		results["BINARY_CCA"]= binaryCCA
		results["BINARY_PSDA"]= binaryPSDA
		results["STRING_PSDA"]= StringPSDA
		results["STRING_CCA"]= StringCCA

	print(results)
	with open(results_file, 'w') as outfile:
		 json.dump(results, outfile)

	with open(data_file,'w') as outfile:
		outfile.write(Data)

	data_file = open(data_file,'w')
	writer = csv.writer(data_file)
	for i in range(len(Data)):
		writer.writerow(Data[i])
	data_file.close()