Beispiel #1
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])
Beispiel #2
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])
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)
Beispiel #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)
Beispiel #5
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)
Beispiel #6
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)