def deframe_APDU(self, msg_pmt):
        if pmt.is_blob(msg_pmt):
            blob = msg_pmt
            #print "is blob"
        elif pmt.is_pair(msg_pmt):
            blob = pmt.cdr(msg_pmt)
            #print "is pair"
        else:
            print "Formato desconocido"
            return
        data_np = pmt.to_python(blob)  #numpy.ndarray
        data_py = data_np.tolist()  #python list
        #print "Paquete",data_py,data_py.__class__
        if data_py[2:4] == [0xFF, 0xFF]:
            index = 16
        else:
            index = 24
        del data_py[:
                    index]  # FC(2),Dst_Add(2),Src_Add(2),Radio(1),Sec_N(1),X->Dst_IEEE(8), Src_IEEE(8)
        #print "DEPACKED-->",data_py

        # Crea un PMT vacio:
        send_pmt = pmt.make_u8vector(len(data_py), ord(' '))
        # Copy all characters to the u8vector:
        for i in range(len(data_py)):
            pmt.u8vector_set(send_pmt, i, data_py[i])

        # Send the message:
        self.message_port_pub(pmt.intern('out'),
                              pmt.cons(pmt.PMT_NIL, send_pmt))
    def deframe_APDU(self, msg_pmt):
        if pmt.is_blob(msg_pmt):
            blob = msg_pmt
            # print "is blob"
        elif pmt.is_pair(msg_pmt):
            blob = pmt.cdr(msg_pmt)
            # print "is pair"
        else:
            print "Formato desconocido"
            return
        data_np = pmt.to_python(blob)  # numpy.ndarray
        data_py = data_np.tolist()  # python list
        # print "Paquete",data_py,data_py.__class__
        if data_py[2:4] == [0xFF, 0xFF]:
            index = 16
        else:
            index = 24
        del data_py[:index]  # FC(2),Dst_Add(2),Src_Add(2),Radio(1),Sec_N(1),X->Dst_IEEE(8), Src_IEEE(8)
        # print "DEPACKED-->",data_py

        # Crea un PMT vacio:
        send_pmt = pmt.make_u8vector(len(data_py), ord(" "))
        # Copy all characters to the u8vector:
        for i in range(len(data_py)):
            pmt.u8vector_set(send_pmt, i, data_py[i])

            # Send the message:
        self.message_port_pub(pmt.intern("out"), pmt.cons(pmt.PMT_NIL, send_pmt))
Beispiel #3
0
    def deframe_MSJ(self, msg_pmt):
        if pmt.is_blob(msg_pmt):
            blob = msg_pmt
            # print "is blob"
        elif pmt.is_pair(msg_pmt):
            blob = pmt.cdr(msg_pmt)
            # print "is pair"
        else:
            print "Formato desconocido"
            return
        data_np = pmt.to_python(blob)  # numpy.ndarray
        data_py = data_np.tolist()  # python list
        # print "Paquete",data_py,data_py.__class__
        index = 8
        del data_py[:index]  # FC (1), DesEP(1),Cluster(2),Profile(2),SourEP(1),Counter(1)
        # print "DEPACKED-->",data_py

        # Crea un PMT vacio:
        send_pmt = pmt.make_u8vector(len(data_py), ord(" "))
        # Copy all characters to the u8vector:
        for i in range(len(data_py)):
            pmt.u8vector_set(send_pmt, i, data_py[i])

            # Send the message:
        self.message_port_pub(pmt.intern("out"), pmt.cons(pmt.PMT_NIL, send_pmt))
    def make_MPDU(self, msg_pmt):
        if pmt.is_blob(msg_pmt):
            blob = msg_pmt
            # print "is blob"
        elif pmt.is_pair(msg_pmt):
            blob = pmt.cdr(msg_pmt)
            # print "is pair"
        else:
            print "Formato desconocido"
            return
        # Toma Pmt pair a numpyarray y luego a list
        data_np = pmt.to_python(blob)  # numpy.ndarray
        npdu = data_np.tolist()  # python list

        Src_Add = self.SrcAddM  # Dir 16 bit id de la red
        Dst_Add = [0xFF, 0xFF]  # Coordinador 00 00 / #broadcast FF FF
        Pan_Id = self.PanId  # PanID que estabece el coordinador LSB -MSB
        global Seq_M
        Seq_M[0] = Seq_M[0] + 1
        if Seq_M[0] > 254:
            Seq_M[0] = 0
        FC_M = [0x41, 0x88]  # Frame control Mac LSB-MSB

        to_fcs = FC_M + Seq_M + Pan_Id + Dst_Add + Src_Add + npdu
        s_to_fcs = struct.pack("B" * len(to_fcs), *to_fcs)  # Convierte List a String
        a = self.crc16(s_to_fcs)  # Calcula FCS
        FCS = [a & 0xFF, (a >> 8) & 0xFF]

        MPDU = FC_M + Seq_M + Pan_Id + Dst_Add + Src_Add + npdu + FCS

        send_pmt = pmt.make_u8vector(len(MPDU), ord(" "))  # Crea PMT vacio
        for i in range(len(MPDU)):
            pmt.u8vector_set(send_pmt, i, MPDU[i])  # Copia Caracteres a u8vector:
        # Envia mensaje:
        self.message_port_pub(pmt.intern("out"), pmt.cons(pmt.PMT_NIL, send_pmt))
 def make_NPDU(self,msg_pmt):
     if pmt.is_blob(msg_pmt):
         blob = msg_pmt
         #print "is blob"
     elif pmt.is_pair(msg_pmt):
         blob = pmt.cdr(msg_pmt)
         #print "is pair"
     else:
         print "Formato desconocido" 
         return
     # Toma Pmt pair a numpyarray y luego a list
     data_np	= pmt.to_python(blob) 	#numpy.ndarray	
     apdu = data_np.tolist()			#python list
     
     Src_Ieee = self.SrcIeeeN	# la dir del USRP de 64 bit puede ser cualquiera
     
     global Seq_Num
     Seq_Num[0] =  Seq_Num[0] +1
     if Seq_Num[0] > 254: Seq_Num[0] = 0
     
     Radio = [0x1E] 	 			# Saltos Max del mensaje
     Src_Add = self.SrcAddN		# Puede ser cualquiera
     Dst_Add = [0xFF,0xFF]	 	# Coordinador 00 00 / #broadcast FF FF
     FC_N = [0x08,0x10] 			# Frame Control LSB-MSB 
     
     NPDU = FC_N + Dst_Add + Src_Add + Radio + Seq_Num + Src_Ieee  + apdu 
     
     # Crea PMT vacio
     send_pmt = pmt.make_u8vector(len(NPDU), ord(' '))
     # Copia Caracteres a u8vector:
     for i in range(len(NPDU)):
         pmt.u8vector_set(send_pmt, i, NPDU[i])
     
     # Envia mensaje:
     self.message_port_pub(pmt.intern('out'), pmt.cons(pmt.PMT_NIL, send_pmt))
Beispiel #6
0
    def StdDev(self, msg_pmt):
        # veficcación del formato PMT
        if pmt.is_blob(msg_pmt):
            blob = msg_pmt
            #print "is blob"
        elif pmt.is_pair(msg_pmt):
            blob = pmt.cdr(msg_pmt)

        else:
            print "Formato desconocido"
            return

        vec = pmt.cdr(
            msg_pmt)  #se toma del diccionario en formato pmt la llave
        #print "sin convertir",vec,vec.__class__
        vecp = pmt.to_python(vec)  #se convierte de pmt a vector en python
        self.d_Std = np.array(
            vecp)  # se crea una variable que se pueda mmanipular
        Std1 = np.std(
            self.d_Std
        )  # se calcula la desviación estandar del vector que llego
        #print (self.d_Std)
        #print (Std1)
        Std12 = float(Std1)
        #print (Std12)
        #Stdv = pmt.from_float(Std12) #se convierte a float el valor obtenido
        Stdv1 = pmt.make_f32vector(
            1, Std12
        )  # se crea un vector de tipo PMT para despues ser interpretado por el  bloque PDU to Tagged Stream; debe ser "1" en el primer argumento o no funciona.
        self.message_port_pub(pmt.intern("out"), pmt.cons(pmt.PMT_NIL, Stdv1))
Beispiel #7
0
    def deframe_MSJ(self, msg_pmt):
        if pmt.is_blob(msg_pmt):
            blob = msg_pmt
            #print "is blob"
        elif pmt.is_pair(msg_pmt):
            blob = pmt.cdr(msg_pmt)
            #print "is pair"
        else:
            print "Formato desconocido"
            return
        data_np = pmt.to_python(blob)  #numpy.ndarray
        data_py = data_np.tolist()  #python list
        #print "Paquete",data_py,data_py.__class__
        index = 8
        del data_py[:
                    index]  # FC (1), DesEP(1),Cluster(2),Profile(2),SourEP(1),Counter(1)
        #print "DEPACKED-->",data_py

        # Crea un PMT vacio:
        send_pmt = pmt.make_u8vector(len(data_py), ord(' '))
        # Copy all characters to the u8vector:
        for i in range(len(data_py)):
            pmt.u8vector_set(send_pmt, i, data_py[i])

        # Send the message:
        self.message_port_pub(pmt.intern('out'),
                              pmt.cons(pmt.PMT_NIL, send_pmt))
Beispiel #8
0
    def app_in(self, msg):  # Generate messages
        global d_msg_len, d_mac_id, d_seq_nr, d_msg

        if self.debug:
            print "******************************** \nGenerating messages ...\n******************************** "
            print ""
            print "MAC:app_in: got something:", msg
        data = msg

        if (pmt.is_pair(msg)):
            data = pmt.cdr(msg)
            #if self.debug: print  "mac.py:app_in: pmt_is_pair \n"
        elif (pmt.is_eof_object(msg)):
            if self.debug: print "MAC: exiting"
            return
        elif (pmt.is_blob(msg)):
            data = pmt.cdr(msg)
            if self.debug: print "data is blob"
        else:
            if self.debug: print "MAC: unknown input"
            return
        if pmt.is_u8vector(data):
            "data is u8vector"
            data_elements = pmt.u8vector_elements(data)
            if self.debug:
                print "Data from Application Layer: ", data_elements, "\n"
                print "Data length :", len(data_elements), "\n"

        d_msg = []

        if pmt.is_symbol(data):
            dataString = pmt.symbol_to_string(data)
            if self.debug:
                print "len(pmt.symbol_to_string(data)): ", len(
                    dataString), "pmt.symbol_to_string(data): ", dataString
            generate_mac(data, len(dataString), self.debug, d_mac_id, d_seq_nr,
                         self.no_self_loop)
        else:
            generate_mac(data, pmt.length(data), self.debug, d_mac_id,
                         d_seq_nr, self.no_self_loop)

        generatedMacPayload = pmt.make_u8vector(len(d_msg), 0)
        for i in range(len(d_msg)):
            #if (pmt.is_vector(data)):
            #print "d_msg[",i,"]: ", d_msg[i], " ; type: ", type(d_msg[i])
            #    pmt.vector_set(generatedMacPayload, i, pmt.to_pmt(d_msg[i]))
            pmt.u8vector_set(generatedMacPayload, i, d_msg[i])
            #else: pmt.u8vector_set(generatedMacPayload, i, d_msg[i])

        self.message_port_pub(pmt.intern("pdu out"),
                              pmt.cons(pmt.PMT_NIL, generatedMacPayload))
        print
        print "**********************************"
        print
        if self.debug:
            print "Data Published to physical Layer: ", pmt.u8vector_elements(
                generatedMacPayload), "\n"
    def deframe_NPDU(self, msg_pmt):
        global pack_err
        global pack_tot
        global PER
        # veficcación del formato PMT
        if pmt.is_blob(msg_pmt):
            blob = msg_pmt
            #print "is blob"
        elif pmt.is_pair(msg_pmt):
            blob = pmt.cdr(msg_pmt)
            #print "is pair"
        else:
            print "Formato desconocido"
            return
        data_len = pmt.blob_length(blob)
        if (data_len < 11):
            print "MAC: muy corta!"
            pack_err = pack_err + 1.0
            return
        data_np = pmt.to_python(blob)  #numpy.ndarray
        data_py = data_np.tolist()  #python list
        #print "Paquete",data_py,data_py.__class__
        #print "Dir Gateway",self.SrcAddR," Dir Nodo",data_py[7:9]
        if len(set(self.SrcAddR).intersection(
                data_py)) < 2:  #Validación TX de la misma dirección

            # Valodacion FCS y cuenta PER
            rec_FCS = [data_py[-2], data_py[-1]]  #FCS recibido
            del data_py[-2], data_py[-1]  #quita FCS
            s_to_fcs = struct.pack('B' * len(data_py),
                                   *data_py)  # Convierte List a String
            a = self.crc16(s_to_fcs)  #Calcula FCS
            FCS = [a & 0xFF, (a >> 8) & 0xFF]

            if FCS == rec_FCS:  # paquete correcto
                index = 9
                del data_py[:
                            index]  # FC(2),Sec_N(1),PanID(2),Dst_Add(2),Src_Add(2)
                # Crea un PMT vacio:
                send_pmt = pmt.make_u8vector(len(data_py), ord(' '))
                # Copy all characters to the u8vector:
                for i in range(len(data_py)):
                    pmt.u8vector_set(send_pmt, i, data_py[i])
                # Send the message:
                self.message_port_pub(pmt.intern('out'),
                                      pmt.cons(pmt.PMT_NIL, send_pmt))
            else:
                pack_err = pack_err + 1.0

            pack_tot = pack_tot + 1.0
            PER = pack_err / pack_tot * 100.0
            print ",", pack_tot, ",", pack_err, ",", PER, "%"
Beispiel #10
0
    def test_002_multiple_message_out(self):
        src_data = (1j, 1 + 2j, 1, 0)
        # expected1 is the binary representation of (1j, 1+2j)
        expected1 = np.array(
            [0, 0, 0, 0, 0, 0, 128, 63, 0, 0, 128, 63, 0, 0, 0, 64],
            dtype='uint8')
        # expected2 is the binary representation of (1, 0)
        expected2 = np.array(
            [0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype='uint8')

        src = blocks.vector_source_c(src_data)
        ctm = starcoder.complex_to_msg_c(2)
        snk = blocks.message_debug()
        self.tb.connect(src, ctm)
        self.tb.msg_connect((ctm, 'out'), (snk, 'store'))
        self.tb.run()

        self.assertEqual(snk.num_messages(), 2)
        self.assertTrue(pmt.is_blob(snk.get_message(0)))
        self.assertTrue(pmt.is_blob(snk.get_message(1)))
        np.testing.assert_array_equal(pmt.to_python(snk.get_message(0)),
                                      expected1)
        np.testing.assert_array_equal(pmt.to_python(snk.get_message(1)),
                                      expected2)
	def deframe_NPDU(self,msg_pmt):
		global pack_err
		global pack_tot
		global PER
		# veficcación del formato PMT
		if pmt.is_blob(msg_pmt):
			blob = msg_pmt
			#print "is blob"
		elif pmt.is_pair(msg_pmt):
			blob = pmt.cdr(msg_pmt)
			#print "is pair"
		else:
			print "Formato desconocido" 
			return
		data_len = pmt.blob_length(blob)
		if(data_len < 11):
			print "MAC: muy corta!"
			pack_err = pack_err+1.0
			return;
		data_np	= pmt.to_python(blob) 	#numpy.ndarray	
		data_py = data_np.tolist()		#python list
		#print "Paquete",data_py,data_py.__class__
		#print "Dir Gateway",self.SrcAddR," Dir Nodo",data_py[7:9]
		if len(set(self.SrcAddR).intersection(data_py)) < 2 :		#Validación TX de la misma dirección
			
			# Valodacion FCS y cuenta PER
			rec_FCS = [data_py[-2],data_py[-1]] #FCS recibido
			del data_py[-2],data_py[-1]			#quita FCS
			s_to_fcs = struct.pack('B'*len(data_py), *data_py)  # Convierte List a String
			a = self.crc16(s_to_fcs)		#Calcula FCS
			FCS= [a & 0xFF,(a>>8)&0xFF] 

			if FCS == rec_FCS:		# paquete correcto
				index = 9
				del data_py[:index]				# FC(2),Sec_N(1),PanID(2),Dst_Add(2),Src_Add(2)
				# Crea un PMT vacio:
				send_pmt = pmt.make_u8vector(len(data_py), ord(' '))
				# Copy all characters to the u8vector:
				for i in range(len(data_py)):
					pmt.u8vector_set(send_pmt, i, data_py[i])
				# Send the message:
				self.message_port_pub(pmt.intern('out'), pmt.cons(pmt.PMT_NIL, send_pmt))
			else:
				pack_err = pack_err+1.0
		
			pack_tot = pack_tot +1.0
			PER =pack_err/pack_tot*100.0
			print ",",pack_tot,",",pack_err,",",PER,"%"
    def test_fr(self):
        """
            Simple TCH/F Full Rate test
        """
        framenumbers_input = [
            373420, 373421, 373422, 373423, 373424, 373425, 373426, 373427,
            3734298
        ]
        timeslots_input = [3, 3, 3, 3, 3, 3, 3, 3]
        bursts_input = [
            "0000101011011010011110011011101011100000100010001011010100110111011110001001011101111000111010001001000110000011100010000010111110110101001101011000",
            "0001011011111010000000111010110001110101010011011100000110100111011110001001011101111000110100000010000001100010101101011010000110000101101011000000",
            "0000011010010000100000000100110111111110101101011001001010010111011110001001011101111000010001010001101000010100100111101110110010011110010000011000",
            "0001000000010111010111100100110110000101101111000000011011100111011110001001011101111000101001000001101010010110011100011010010011010001010010001000",
            "0000111001001110100011110000101001110110111011001110110110110111011110001001011101111000011110001000010101011000101010010101000000100000010011101000",
            "0000011001001010010101100000110100101001111001001100101010000111011110001001011101111000100111000000111111000000100001101001101010000110111111100000",
            "0001011011101100100001010001001000110010010010100101000111010111011110001001011101111000100001101110100101000100100100100100000100011101111001011000",
            "0000010111000101101101100001011000110010010011001110101000010111011110001001011101111000001001100011010001111110001101010100110001010001100100001000"
        ]

        src = grgsm.burst_source(framenumbers_input, timeslots_input,
                                 bursts_input)
        decoder = grgsm.tch_f_decoder(grgsm.TCH_FS, False)
        dst = blocks.message_debug()

        self.tb.msg_connect(src, "out", decoder, "bursts")
        self.tb.msg_connect(decoder, "voice", dst, "store")

        self.tb.run()

        self.assertEqual(dst.num_messages(), 1)

        pdu = dst.get_message(0)
        self.assertEqual(True, pmt.is_pair(pdu))

        data = pmt.cdr(pdu)
        self.assertEqual(True, pmt.is_blob(data))

        np.testing.assert_array_equal(
            np.array([
                211, 92, 197, 118, 171, 142, 160, 70, 219, 146, 71, 20, 226,
                128, 73, 35, 142, 75, 35, 94, 32, 73, 28, 114, 73, 44, 132,
                192, 72, 228, 141, 201, 27
            ]), pmt.to_python(data))
Beispiel #13
0
    def tchh_multirate(self, frames, timeslots, bursts, multirate, subchan):
        """
            Common TCH/H MultiRate test code
        """
        src = grgsm.burst_source(frames, timeslots, bursts)
        decoder = grgsm.tch_h_decoder(subchan, multirate, False)
        dst = blocks.message_debug()

        self.tb.msg_connect(src, "out", decoder, "bursts")
        self.tb.msg_connect(decoder, "voice", dst, "store")

        self.tb.run()

        result = []
        for i in range(0, dst.num_messages()):
            pdu = dst.get_message(i)
            self.assertEqual(True, pmt.is_pair(pdu))
            data = pmt.cdr(pdu)
            self.assertEqual(True, pmt.is_blob(data))
            result.append(pmt.to_python(data).tolist())
        return result
    def make_MPDU(self, msg_pmt):
        if pmt.is_blob(msg_pmt):
            blob = msg_pmt
            #print "is blob"
        elif pmt.is_pair(msg_pmt):
            blob = pmt.cdr(msg_pmt)
            #print "is pair"
        else:
            print "Formato desconocido"
            return
        # Toma Pmt pair a numpyarray y luego a list
        data_np = pmt.to_python(blob)  #numpy.ndarray
        npdu = data_np.tolist()  #python list

        Src_Add = self.SrcAddM  # Dir 16 bit id de la red
        Dst_Add = [0xFF, 0xFF]  # Coordinador 00 00 / #broadcast FF FF
        Pan_Id = self.PanId  # PanID que estabece el coordinador LSB -MSB
        global Seq_M
        Seq_M[0] = Seq_M[0] + 1
        if Seq_M[0] > 254: Seq_M[0] = 0
        FC_M = [0x41, 0x88]  #Frame control Mac LSB-MSB

        to_fcs = FC_M + Seq_M + Pan_Id + Dst_Add + Src_Add + npdu
        s_to_fcs = struct.pack('B' * len(to_fcs),
                               *to_fcs)  # Convierte List a String
        a = self.crc16(s_to_fcs)  #Calcula FCS
        FCS = [a & 0xFF, (a >> 8) & 0xFF]

        MPDU = FC_M + Seq_M + Pan_Id + Dst_Add + Src_Add + npdu + FCS

        send_pmt = pmt.make_u8vector(len(MPDU), ord(' '))  # Crea PMT vacio
        for i in range(len(MPDU)):
            pmt.u8vector_set(send_pmt, i,
                             MPDU[i])  # Copia Caracteres a u8vector:
        # Envia mensaje:
        self.message_port_pub(pmt.intern('out'),
                              pmt.cons(pmt.PMT_NIL, send_pmt))