コード例 #1
0
    def write(self, packet: Packet, *, timeout: float = 10, raise_api_error: bool = True) -> Packet:
        logger.debug(f"Send {packet}")
        self.ch_api_v2.write(packet.build(), withResponse=True)

        response = self.packet_collector.get_response(packet, timeout=timeout)
        if raise_api_error and response.api_error is not Api2Error.success:
            raise PySpheroApiError(response.api_error)
        return response
コード例 #2
0
 def write(self,
           packet: Packet,
           *,
           timeout: float = 10,
           raise_api_error: bool = True) -> Optional[Packet]:
     logger.debug(f"Send {packet}")
     self.ch_api_v2.write(packet.build(), withResponse=True)
     return self.packet_collector.get_response(packet,
                                               raise_api_error,
                                               timeout=timeout)
コード例 #3
0
    def write(self, packet: Packet, *, timeout: float = 10, raise_api_error: bool = True) -> Optional[Packet]:
        """
         Method allow send request packet and get response packet

         :param packet: request packet
         :param timeout: timeout waiting for a response from sphero
         :param raise_api_error: raise exception when receive api error
         :return Packet: response packet
        """
        logger.debug(f"Send {packet}")
        self._device.char_write(self.ch_api_v2, packet.build(), wait_for_response=True)
        return self.packet_collector.get_response(packet, raise_api_error, timeout)
コード例 #4
0
ファイル: gatt_adapter.py プロジェクト: MatP-MatP/pysphero
    def write(self,
              packet: Packet,
              *,
              timeout: float = 10,
              raise_api_error: bool = True) -> Packet:
        """
         Method allow send request packet and get response packet

         :param packet: request packet
         :param timeout: timeout waiting for a response from sphero
         :param raise_api_error: raise exception when receive api error
         :return Packet: response packet
        """
        self.ch_api_v2.write_value(packet.build())
        return self.packet_collector.get_response(packet, timeout)
コード例 #5
0
    def request(self,
                packet: Packet,
                with_api_error: bool = True,
                timeout: float = 10) -> Packet:
        """
        Method allow send request packet and get response packet

        :param packet: request packet
        :param with_api_error: error code check
        :param timeout: timeout for waiting response from device
        :return Packet: response packet
        """
        logger.debug(f"Send {packet}")
        packet.sequence = self.sequence
        self.ch_api_v2.write(packet.build(), withResponse=True)

        response = self._get_response(packet, timeout=timeout)
        if with_api_error and response.api_error is not Api2Error.success:
            raise PySpheroApiError(response.api_error)
        return response
コード例 #6
0
ファイル: test_packet.py プロジェクト: typedivision/pysphero
def test_packet_build_with_escape():
    packet = Packet(0x23, 0x42, sequence=0x01, data=[0xab, 0x8d])
    raw_packet = [
        0x8d, 0x0a, 0x23, 0x42, 0x01, 0xab, 0x23, 0xab, 0x05, 0x57, 0xd8
    ]
    assert packet.build() == b"".join(b.to_bytes(1, "big") for b in raw_packet)
コード例 #7
0
ファイル: test_packet.py プロジェクト: typedivision/pysphero
def test_packet_build():
    packet = Packet(0x23, 0x42, sequence=0x01, data=[0x15, 0x16])
    raw_packet = [0x8d, 0x0a, 0x23, 0x42, 0x01, 0x15, 0x16, 0x64, 0xd8]
    assert packet.build() == b"".join(b.to_bytes(1, "big") for b in raw_packet)
コード例 #8
0
def my_write(self, packet: Packet, *, timeout: float = 10, raise_api_error: bool = True) -> Optional[Packet]:
        logger.debug(f"Send {packet}")
        self.ch_api_v2.write(packet.build(), withResponse=False) #changed to false