예제 #1
0
for a in data[1:-1]:
	if a == 0x7E:
		print "To many 0x7E in the message"

## Validating CRC

print crc_test(data)

# Removing Start and Stop Bit

data = data[1:-1]


## Destuffing

data = destuffed(data)

length = data[5]

print 'Length is', length

## Filtering content by removing the tinyOS Header

xmesh_msg = data[6:-2]

## Printing out the payload -> Convert to dictionary

print 'Multihop Header'
print 'sourceAddr', hex(xmesh_msg[0]), hex(xmesh_msg[1])
print 'originAddr', hex(xmesh_msg[2]), hex(xmesh_msg[3])
print 'seqno', hex(xmesh_msg[4]), hex(xmesh_msg[5])
예제 #2
0
        def __init__(self,msg):

                f = open("msg_log",'w')
                f.writelines(map(str,msg))
                f.close
                # Removing 7E: Start and Stop bit
                msg = msg[1:-1]

                # Destuffing message -> Replacing encrypted 7E
                msg = destuffed(msg)


                if msg[3] == 0xb:
	
                        self.tipe = "normal"
        
                        # Removing xmesh Header 
                        msg = msg[6:-2]
                        
                        # Converting data
                        
                        self.node = conector(msg[2:4])
                        # print "Confirm node mapping", self.node
                        
                        # Humity      
                        humid_medida = conector(msg[13:15])
                        humtemp_medida = conector(msg[15:17])
                        humtemp_calc = -38.4 + (0.0098*humtemp_medida)
                        self.humidade =(0.0098 * humtemp_medida - 63.4)*(0.01+0.00008*humid_medida)-4 + \
                        (0.0405*humid_medida) - (0.0000028*humid_medida*humid_medida)

                        # Temperature
                        self.temperatura = -38.4 + (0.0098*humtemp_medida)

                        # Luminosity
                        taosch0_bin = conector(msg[29:31])
                        taosch1_bin = conector(msg[31:33])
                        taosch0_bin_0=taosch0_bin & 0xFF
                        taosch1_bin_1=taosch1_bin & 0xFF
                        v0 = (taosch0_bin_0 & 0b10000000) >>7
                        c0 = (taosch0_bin_0 & 0b01110000) >>4
                        s0 = (taosch0_bin_0 & 0b00001111)
                        v1 = (taosch1_bin_1 & 0b10000000) >>7
                        c1 = (taosch1_bin_1 & 0b01110000) >>4
                        s1 = (taosch1_bin_1 & 0b00001111)
                        adccount0 = 16.5*((pow(2,c0)-1))+(s0*(pow(2,c0)))
                        adccount1 = 16.5*((pow(2,c1)-1))+(s1*(pow(2,c1)))
                        exponencial=exp(-3.13*(adccount1/adccount0))
                        self.light = (adccount0*0.46*exponencial)
                                
                        # Pressure
                        C1= (conector(msg[17:19]) >> 1)
                        C2= (((conector(msg[21:23]) & 0x3F )<< 6)) + (conector(msg[23:25]) & 0x3F)
                        C3= (conector(msg[23:25]) >> 6)
                        C4= (conector(msg[21:23]) >> 6)
                        C5= ((conector(msg[17:19]) & 1) << 10) + (conector(msg[19:21]) >> 6)
                        C6= (conector(msg[19:21]) & 0x3F)
                        prtemp_medido=conector(msg[25:27])
                        pressao_medido=conector(msg[27:29])
                        UTI= (8 * C5) + 20224
                        dT= prtemp_medido - UTI
                        prtemp_calc= (200 + (dT * (C6+50)/float(1024)))/float(10)
                        OFF= ((C2*4) +(((C4-512)*dT))/float(4096))
                        SENS= (C1 + (C3*dT)/float(1024))+ 24576
                        X=SENS*((pressao_medido-7168)/float(16384)) - OFF
                        pressao_calc= (X*(100/float(32))+ (250*100))/100
                        self.pressure = pressao_calc
                        
                        try:
                                nodeNumber = nodeList.index(self.node)

                        except ValueError:
                                nodeList.append(self.node)
                                nodeNumber = nodeList.index(self.node)

                        node = "Node" + str(nodeNumber)
                        humidade = "Humidade" + str(nodeNumber)
                        temperatura = "Temperatura" + str(nodeNumber)
                        luminosidade = "Luminosidade" + str(nodeNumber)
                        pressao = "Pressao" + str(nodeNumber)
                                                
                        self.data = {node: self.node, humidade: self.humidade, temperatura: self.temperatura, \
                                        luminosidade: self.light, pressao: self.pressure}
                else:
                        self.tipe = "abnormal"
                        return
                return