Ejemplo n.º 1
0
    def create_objects(self):
        ## DEFINE PARAMETERS ###########
        self.CharSet = 'lowerCaseLiterals'
        self.CharactersPerMessage = 5
        self.SourceEncodeMethod = 'basic'
        self.errorCorrection = 'HardHamming'

        # NOTE: Only use frequencies From the following Set:
        # [23.26, 23.81, 24.39, 25, 25.64, 26.36, 27.03, 27.78, 28.57, 29.41, 30.30, 31.25, 32.26, 33.33,
        #  34.48, 35.71, 37.04, 38.46 ]
        self.TransmissionFrequenciesIdeal = [
            23.26, 25, 26.36, 27.78, 28.57, 30.30, 31.25, 33.33
        ]

        self.TimePerSymbolSeconds = 4

        self.ValidDictionary = IL.loadCharacterSet(self.CharSet)
        self.InputValidationObject = IL.InputValidation(
            self.ValidDictionary, self.CharactersPerMessage)
        self.SrcEncoder = IL.SrcEncoder(self.ValidDictionary,
                                        self.SourceEncodeMethod)
        self.FEC = IL.ChannelEncoder(self.errorCorrection, 7, 4)
        self.Chan = IL.Channel('FixedFrequencyAndDuty',
                               self.TransmissionFrequenciesIdeal,
                               self.TimePerSymbolSeconds, True, 28.57, 30.30)
Ejemplo n.º 2
0
def RunSender(file_name, config_parameters, test_option):
    # function which will execute on the sender

    sendHeader = True
    if config_parameters["SYNC_METHOD"] == "KeyPress":
        sendHeader = False

    characterSet = Sender.loadCharacterSet(config_parameters["CHARACTER_SET"])
    sourceEncoder = Sender.SrcEncoder(characterSet,
                                      config_parameters["SOURCE_ENCODER"])

    channelEncoder = Sender.ChannelEncoder(config_parameters["ERROR_CORRECTION"],\
                config_parameters["FEC_BLOCK_SIZE"],\
                config_parameters["FEC_MESSAGE_SIZE"])

    channel = Sender.Channel('FixedFrequencyAndDuty',\
           config_parameters["TRANSMISSION_FREQUENCIES"],\
           config_parameters["TIME_PER_SYMBOL"],\
           sendHeader,\
           HOLD_FREQUENCY,\
           HEADER_FREQUENCY)

    # need to do the actual sending here
    symbols = []
    if config_parameters["CHARACTERS_PER_MESSAGE"] != 0:

        message = raw_input("Enter a Message (" +
                            str(config_parameters["CHARACTERS_PER_MESSAGE"]) +
                            ") characters \n")
        sendBits = sourceEncoder.EncodeData(message)
        encodedBits = channelEncoder.EncodeData(sendBits)
        intBits = channelEncoder.interleave(encodedBits)
        symbols = Sender.SymbolMapping(
            intBits, len(config_parameters["TRANSMISSION_FREQUENCIES"]))
        print("Symbols to Transmit " + str(symbols))

    raw_input("ready ... press Enter to Start")
    if sendHeader:
        channel.sendHeaderV2()
    sendStartTime = time.time()
    print("Starting to Send message at time " + str(sendStartTime))
    for symbol in symbols:
        channel.send(symbol)
    channel.re_header()

    results = {}
    results["CONFIGURATION"] = config_parameters
    results["SEND_START_TIME"] = sendStartTime

    if test_option != 'protocol_only':
        results["SENT_SYMBOLS"] = symbols
        results["INTERLEAVED_BITS"] = intBits
        results["ENCODED_BITS"] = encodedBits
        results["BINARY_MESSAGE"] = sendBits
        results["STRING_MESSAGE"] = message

    print(results)
    with open(file_name, 'w') as outfile:
        json.dump(results, outfile)
Ejemplo n.º 3
0
 def test_EncodeSingleCharacterBasic(self):
     CharSet = IL.loadCharacterSet('lowerCaseLiterals')
     SrcEnc = IL.SrcEncoder(CharSet, 'basic')
     SendMessage1 = 'a'
     SendMessage2 = 'k'
     SendMessage3 = 'z'
     self.assertEqual('00001', SrcEnc.EncodeData(SendMessage1))
     self.assertEqual('01011', SrcEnc.EncodeData(SendMessage2))
     self.assertEqual('11010', SrcEnc.EncodeData(SendMessage3))
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
 def test_mapToNsymbolsNoPadding(self):
     message = '1000111010101110'
     TwoSymbols = IL.SymbolMapping(message, 2)
     self.assertEqual(TwoSymbols,
                      [1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0])
     FourSymbols = IL.SymbolMapping(message, 4)
     self.assertEqual(FourSymbols, [2, 0, 3, 2, 2, 2, 3, 2])
     message = '100011100'
     EightSymbols = IL.SymbolMapping(message, 8)
     self.assertEqual(EightSymbols, [4, 3, 4])
Ejemplo n.º 6
0
 def test_mapToSymbolsWithPadding(self):
     message = '1000111'
     EightSybols = IL.SymbolMapping(message, 8)
     self.assertEqual(EightSybols, [4, 3, 4])
     # the following will be padded to '110'-> 6
     message = '11'
     EightSybols = IL.SymbolMapping(message, 8)
     self.assertEqual(EightSybols, [6])
     message = '0'
     FourSymbols = IL.SymbolMapping(message, 4)
     self.assertEqual(FourSymbols, [0])
Ejemplo n.º 7
0
	def create_objects(self):
		self.CharSet = 'lowerCaseLiterals'
		self.CharactersPerMessage = 7
		self.SourceEncodeMethod = 'basic'
		self.errorCorrection = 'HardHamming'
		self.FEC_blockSize = 15
		self.FEC_msgSize = 11
###########################
		self.ValidDictionary = IL.loadCharacterSet(self.CharSet)
		self.InputValidationObject = IL.InputValidation(self.ValidDictionary,self.CharactersPerMessage)
		self.SrcEncoder  = IL.SrcEncoder(self.ValidDictionary , self.SourceEncodeMethod)
		self.FEC = IL.ChannelEncoder(self.errorCorrection, self.FEC_blockSize , self.FEC_msgSize)
################################
		self.CharSet = RL.loadCharacterSet(self.CharSet)
		self.CD = RL.ChannelDecoder(self.errorCorrection,'HARD', self.FEC_blockSize, self.FEC_msgSize)
		self.SD = RL.sourceDecoder(self.CharSet, self.SourceEncodeMethod)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
# this file will be used merely to determine properties of the
# header it should be deleted.

# create a detector
# roll values into the detector
import Source.InputLib as IL
import time

Channel = IL.Channel('FixedFrequencyAndDuty', [23.26, 25], 1)
time.sleep(2)
Channel.setSingleFreq(28.57)
time.sleep(20)
Channel.setSingleFreq(30.30)
time.sleep(4)
Channel.setSingleFreq(28.57)
time.sleep(20)
Channel.setSingleFreq(23.26)
time.sleep(20)
Ejemplo n.º 10
0
    'TimeSet variation Not yet Implemented - default will be for 3 and 4 seconds'
)
FrequencySet = [
    23.26, 23.81, 24.39, 25, 25.64, 26.36, 27.03, 27.78, 28.57, 29.41, 30.30,
    31.25, 32.26, 33.33, 34.48, 35.71, 37.04, 38.46
]
SymbolVector = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]
ElectrodesForCCA = ['O1', 'O2', 'P7', 'P8']
NumRuns = 4  # how many detection loops should be performed
# =================

#########
#===Collect Data ======

TransmissionFrequencies4s = FD.mapToClosestFrequencies(FrequencySet, 512)
Sender = SendLib.Channel('FixedFrequencyAndDuty', None, None)
Receiver = Channel.Channel('Emokit', ElectrodesForCCA, False, False)
CCADetector4s = RecvLib.DetectionObject('CCA', TransmissionFrequencies4s, None,
                                        ElectrodesForCCA, 4, 'HARD')
PSDADetector4s = RecvLib.DetectionObject('PSDA', TransmissionFrequencies4s,
                                         None, ['O1'], 4, 'HARD')
CombinedDetector4s = RecvLib.DetectionObject('Combined',
                                             TransmissionFrequencies4s, None,
                                             ElectrodesForCCA, 4, 'HARD')
ResultsCCA4s = numpy.zeros([len(SymbolVector), NumRuns])
ResultsPSDA4s = numpy.zeros([len(SymbolVector), NumRuns])
ResultsCombined4s = numpy.zeros([len(SymbolVector), NumRuns])
time.sleep(2)
Receiver.flushBuffer()

for i in range(NumRuns):
Ejemplo n.º 11
0
import os
import Source.TESTLIB  as TL

# change this for each participant
user = raw_input('Enter Subject ID :')

option = raw_input("1 - wholeSystem; 2 - transmissionOnly;  3 - timingOnly \n")
if option == "1":
	testType = 'WithSync'
	CharSet = 'lowerCaseLiterals'
	CharactersPerMessage = 5
	SourceEncodeMethod = 'basic'
	errorCorrection = 'HardHamming'
	transFrequencies = [23.26, 25, 26.36, 27.78 ,28.57, 30.30, 31.25, 33.33]
	period = 4
	ValidDictionary = IL.loadCharacterSet(CharSet)
	SrcEncoder  = IL.SrcEncoder(ValidDictionary , SourceEncodeMethod)
	FEC = IL.ChannelEncoder(errorCorrection,7,4)
	Chan = IL.Channel('FixedFrequencyAndDuty',transFrequencies,period, True, 28.57,30.30)
	while True:
		run = raw_input('Enter Run Number: ')
		path = TL.makePath(user, testType, run)
		TL.quickRunSender(path,Chan, FEC, SrcEncoder,transFrequencies,option)

		



elif option == "2":
	testType = 'SelfSync'
	CharSet = 'lowerCaseLiterals'
Ejemplo n.º 12
0
    def run_send(self):

        sendString = (self.send_msg.get()
                      )  #self.InputValidationObject.getInput()
        #print 'JJJJ:: ', (sendString)
        time.sleep(2)
        SendBits = self.SrcEncoder.EncodeData(sendString)
        print(SendBits)
        self.send_bits.insert(0.0, SendBits)
        EncBits = self.FEC.EncodeData(SendBits)
        print(EncBits)
        self.enc_bits.insert(0.0, EncBits)
        IntBits = self.FEC.interleave(EncBits)

        Symbols = IL.SymbolMapping(IntBits,
                                   len(self.TransmissionFrequenciesIdeal))
        print(Symbols)
        self.symbols.insert(0.0, Symbols)

        num_syms = str(0) + '/' + str(len(Symbols))
        self.progress_label = ttk.Label(self,
                                        text=num_syms,
                                        font=('Times New Roman', 22))
        self.progress_label.grid(row=2, column=2, padx=0, pady=5)

        self.sent_header = tk.Label(self,
                                    text="Sending Header...",
                                    fg="light green",
                                    bg="dark green",
                                    font="Helvetica 16 bold italic")
        self.sent_header.grid(row=2, column=0, padx=30, pady=5)
        self.main_class.update()
        self.Chan.sendHeaderV2()

        self.sent_header.grid_remove()
        self.sent_header = tk.Label(self,
                                    text="Header Sent",
                                    fg="light green",
                                    bg="dark green",
                                    font="Helvetica 16 bold italic")
        self.sent_header.grid(row=2, column=0, padx=30, pady=5)
        self.main_class.update()

        print time.time()
        self.sending_msg.grid_remove()
        self.sending_msg = tk.Label(self,
                                    text="Sending Symbols...",
                                    fg="light green",
                                    bg="dark green",
                                    font="Helvetica 16 bold italic")
        self.sending_msg.grid(row=2, column=1, padx=30, pady=5)
        self.main_class.update()
        i = 1
        for symbol in Symbols:
            fre = self.Chan.send(symbol)
            self.sent_freq.insert(0.0, str(fre) + '\n')

            num_syms = str(i) + '/' + str(len(Symbols))
            self.progress_label = ttk.Label(self,
                                            text=num_syms,
                                            font=('Times New Roman', 22))
            self.progress_label.grid(row=2, column=2, padx=0, pady=5)
            self.main_class.update()
            i = i + 1

        num_syms = str(len(Symbols)) + '/' + str(len(Symbols))
        self.progress_label = ttk.Label(self,
                                        text=num_syms,
                                        font=('Times New Roman', 22))
        self.progress_label.grid(row=2, column=2, padx=0, pady=5)

        self.sending_msg.grid_remove()
        self.progress_label.grid_remove()

        self.sending_msg = tk.Label(self,
                                    text="Message Sent",
                                    fg="light green",
                                    bg="dark green",
                                    font="Helvetica 16 bold italic")
        self.sending_msg.grid(row=8, column=0, padx=30, pady=5)
        self.main_class.update()

        self.Chan.re_header()

        self.send_button.grid_remove()
        self.restart_button.grid(row=8, column=1)  #pack(pady=10, padx=20)
Ejemplo n.º 13
0
 def test_DisregardAdditionalBits(self):
     # any bits added by the FEC will be disregarded
     # unless they can create a full character
     chars = IL.loadCharacterSet('lowerCaseLiterals')
     SrcDec = RL.sourceDecoder(chars, 'basic')
     self.assertEqual('yj', SrcDec.Decode('11001010100000'))
Ejemplo n.º 14
0
 def test_DecodeShortMessage(self):
     chars = IL.loadCharacterSet('lowerCaseLiterals')
     SrcDec = RL.sourceDecoder(chars, 'basic')
     self.assertEqual('yj', SrcDec.Decode('1100101010'))
Ejemplo n.º 15
0
 def test_EncodeLongData(self):
     CharSet = IL.loadCharacterSet('lowerCaseLiterals')
     SrcEnc = IL.SrcEncoder(CharSet, 'basic')
     sendMessage = 'ajyajyajyajy'
     EncDat = '000010101011001000010101011001000010101011001000010101011001'
     self.assertEqual(EncDat, SrcEnc.EncodeData(sendMessage))