def has_data(self): """ :returns: True if there is data waiting on *socket*. """ # read a word try: tmpstr = socketread(self.socket, 4, socket.MSG_DONTWAIT | socket.MSG_PEEK) except socket.error: self.eof = True return False return True
def __init__(self, word, socket): self.ptype = 1 self.count = (word >> 16) & 0x0f self.size = (word >> 0) & 0xffff # read in the rest of the header tmpstr = socketread(socket, 16) if len(tmpstr) < 16: raise InvalidDataReceived("data packet too short: %r" % tmpstr) (self.streamId, self.tsi, self.tsf) = struct.unpack(">IIQ", tmpstr) # read in the payload payloadsize = self.size - 5 - 1 tmpstr = socketread(socket, payloadsize * 4) if (len(tmpstr) < (payloadsize * 4)): raise InvalidDataReceived("data packet too short: %r" % tmpstr) # interpret data self.data = IQData(tmpstr) # read in the trailer tmpstr = socketread(socket, 4) if (len(tmpstr) < 4): raise InvalidDataReceived("data packet too short: %r" % tmpstr)
def __init__(self, pkt_type, word, socket): # extract the pieces of word we want self.ptype = pkt_type self.count = (word >> 16) & 0x0f self.size = (word >> 0) & 0xffff self.fields = {} # now read in the rest of the packet packet_size = (self.size - 1) * 4 tmpstr = socketread(socket, packet_size) (self.streamId, self.tsi, self.tsf,indicatorsField,) = struct.unpack(">IIQI", tmpstr[0:20]) # now read all the indicators if self.streamId == VRTRECEIVER: self._parseReceiverContext(indicatorsField, tmpstr[20:]) elif self.streamId == VRTDIGITIZER: self._parseDigitizerContext(indicatorsField, tmpstr[20:]) elif self.streamId == VRTCUSTOM: self._parseCustomContext(indicatorsField, tmpstr[20:])
def read_packet(self): """ Read a complete packet from *socket* and return either a :class:`pyrf.vrt.ContextPacket` or a :class:`pyrf.vrt.DataPacket`. """ # read a word tmpstr = socketread(self.socket, 4, 0) # convert to int word (word, ) = struct.unpack(">I", tmpstr) # decode the packet type packet_type = (word >> 28) & 0x0f if packet_type in (VRTCONTEXT, VRTCUSTOMCONTEXT): return ContextPacket(packet_type, word, self.socket) elif packet_type == VRTDATA: return DataPacket(word, self.socket) else: raise InvalidDataReceived("unknown packet type: %s" % packet_type)
def read_packet(self): """ Read a complete packet from *socket* and return either a :class:`pyrf.vrt.ContextPacket` or a :class:`pyrf.vrt.DataPacket`. """ # read a word tmpstr = socketread(self.socket, 4, 0) # convert to int word (word,) = struct.unpack(">I", tmpstr) # decode the packet type packet_type = (word >> 28) & 0x0f if packet_type in (VRTCONTEXT, VRTCUSTOMCONTEXT): return ContextPacket(packet_type, word, self.socket) elif packet_type == VRTDATA: return DataPacket(word, self.socket) else: raise InvalidDataReceived("unknown packet type: %s" % packet_type)
def __init__(self, pkt_type, word, socket): # extract the pieces of word we want self.ptype = pkt_type self.count = (word >> 16) & 0x0f self.size = (word >> 0) & 0xffff self.fields = {} # now read in the rest of the packet packet_size = (self.size - 1) * 4 tmpstr = socketread(socket, packet_size) ( self.streamId, self.tsi, self.tsf, indicatorsField, ) = struct.unpack(">IIQI", tmpstr[0:20]) # now read all the indicators if self.streamId == VRTRECEIVER: self._parseReceiverContext(indicatorsField, tmpstr[20:]) elif self.streamId == VRTDIGITIZER: self._parseDigitizerContext(indicatorsField, tmpstr[20:]) elif self.streamId == VRTCUSTOM: self._parseCustomContext(indicatorsField, tmpstr[20:])
def raw_read(self, num): return socketread(self._sock_vrt, num)