Example #1
0
File: tap_sf.py Project: nesl/uant
 def write_packet(self, dest, src, type, payload):
     msg = SerialPacket(None)
     #using set_header info to set header contents
     msg.set_header_dest(dest)
     msg.set_header_src(src)
     msg.set_header_group(type)
     msg.set_header_type(type) 
     msg.set_header_length(len(payload)) #might need to be payload + header length
     data = chr(Serial.TOS_SERIAL_ACTIVE_MESSAGE_ID) #it is a serial message
     data += msg.dataGet()[0:msg.offset_data(0)] #header info
     data += payload
     self.tos_source.writePacket(data) #write that all
Example #2
0
File: tap_sf.py Project: nesl/uant
    def write_packet(self, dest, src, type, payload):
    msg = SerialPacket(None)
    #using set_header info to set header contents
    msg.set_header_dest(dest)
    msg.set_header_src(src)
    msg.set_header_group(type)
    msg.set_header_type(type) 
    msg.set_header_length(len(payload)) #might need to be payload + header length
    data = chr(Serial.TOS_SERIAL_ACTIVE_MESSAGE_ID) #it is a serial message
    data += msg.dataGet()[0:msg.offset_data(0)] #header info
    data += payload
    self.tos_source.writePacket(data) #write that all

    def main_loop(self):
    counter = 0
        while 1:
        #now we need to get the payload from OS
        #need to send to TOS 10*1024 is max length of the read 
        #although one should explicity set MTU to less than 248
        payload = os.read(self.tun_fd, 10*1024)
        #from_linux.write(str( map(lambda (x): hex(ord(x)), payload)))
            if not payload:
                break
        self.send_to_tos(payload)