def rfcomm_read_msg (self):
        intsize = struct.calcsize ("=i")
        msg_type_data = self.readsock.recv (intsize)
        msg_type = struct.unpack ("=i", msg_type_data)[0]

        if msg_type == _widcomm.RFCOMM_DATA_RECEIVED:
            datalen_fmt = "=i"
            datalen_data = self.readsock.recv (struct.calcsize (datalen_fmt))
            datalen = struct.unpack (datalen_fmt, datalen_data)[0]

            self.received_data.append (self.readsock.recv (datalen))

        elif msg_type == _widcomm.RFCOMM_EVENT_RECEIVED:
            fmt = "=I"
            data = self.readsock.recv (struct.calcsize (fmt))
            code = struct.unpack (fmt, data)[0]
            dbg ("event %X received" % code)
            
            if code & _widcomm.PORT_EV_CONNECTED:
                self.connecting = False
                self.listening = False
                self.connected = True
            if code & _widcomm.PORT_EV_CONNECT_ERR:
                self.connecting = False
                self.listening = False
                self.connected = False
                raise BluetoothError ("Connection failed")
            if code & _widcomm.PORT_EV_RXFLAG:
                dbg ("Rx flag")
            if code & _widcomm.PORT_EV_TXEMPTY:
                dbg ("Tx queue empty")
            if code & _widcomm.PORT_EV_CTS:
                dbg ("CTS changed state")
            if code & _widcomm.PORT_EV_DSR:
                dbg ("DSR changed state")
            if code & _widcomm.PORT_EV_RLSD:
                dbg ("RLSD changed state")
            if code & _widcomm.PORT_EV_BREAK:
                dbg ("BREAK received")
            if code & _widcomm.PORT_EV_ERR:
                dbg ("Line status error")
            if code & _widcomm.PORT_EV_RING:
                dbg ("Ring")
            if code & _widcomm.PORT_EV_CTSS:
                dbg ("CTS state")
            if code & _widcomm.PORT_EV_DSRS:
                dbg ("DSR state")
            if code & _widcomm.PORT_EV_RLSDS:
                dbg ("RLSD state")
            if code & _widcomm.PORT_EV_OVERRUN:
                dbg ("Receive buffer overrun")
            if code & _widcomm.PORT_EV_TXCHAR:
                dbg ("Data transmitted")
            if code & _widcomm.PORT_EV_FC:
                dbg ("Flow control changed by remote")
            if code & _widcomm.PORT_EV_FCS:
                dbg ("Flow control status true = enabled")

            self.last_event_code = code
dataset/ETHPy150Open kuri65536/python-for-android/python-modules/pybluez/bluetooth/widcomm.py/BluetoothSocket.rfcomm_read_msg/original