示例#1
0
    def test_writing_slip_file(self):
        """Test writing SLIP-encoded messages"""

        with self.filepath.open(mode='wb', buffering=0) as f:
            slipstream = SlipStream(f)
            for msg in data:
                slipstream.send_msg(msg)
        assert self.filepath.read_bytes() == b''.join(encode(msg) for msg in data)
示例#2
0
    def test_reading_slip_file(self):
        """Test reading SLIP-encoded message"""

        self.filepath.write_bytes(b''.join(encode(msg) for msg in data))
        with self.filepath.open(mode='rb', buffering=0) as f:
            slipstream = SlipStream(f)
            for exp, act in zip(data, slipstream):
                assert exp == act
    def trigger_solenoid(self, sol_id, velocity, delay=0):
        time.sleep(delay)
        msg = osc_message_builder.OscMessageBuilder(address='/sole' +
                                                    str(sol_id) + '/on')
        msg.add_arg(int(2 * velocity))
        msg = msg.build()
        # print(msg.dgram)
        slip_msg = sliplib.encode(msg.dgram)

        self.arduino.write(slip_msg)
示例#4
0
    def handle(self):
        while True:
            data = self.request.recv(1024)
            if not data:
                break

            print('raw data received:', data)
            message = decode(data)
            print('decoded data:', message)

            data_to_send = encode(bytes(reversed(message)))
            print('raw data to send:', data_to_send)
            self.request.sendall(data_to_send)
示例#5
0
def test_serialParamaterizedSynchSend(test_input):
    # Create class object necessary for test
    serialInstance = faraday.SerialTestClass()
    faradayRadio = faraday.Faraday(serialInstance.serialPort)

    # Create slip message to test against
    slipMsg = sliplib.encode(test_input)

    # Send data over Faraday
    res = faradayRadio.send(test_input)

    # Use serial to receive raw transmission with slip protocol
    ret = serialInstance.serialPort.read(res)

    # Check that the returned data from the serial port == slipMsg
    assert ret == slipMsg
示例#6
0
 def test_special_character_encoding(self, msg, packet):
     """Messages with special bytes should encode these according to the specification."""
     assert encode(msg) == END + packet + END
示例#7
0
 def test_message_with_zero_byte_decoding(self):
     """A message that contains a NULL byte must be encoded correctly."""
     msg = b'a\0b'
     packet = END + msg + END
     assert encode(msg) == packet
示例#8
0
 def test_single_byte_encoding(self):
     """Verify that single bytes are encoded correctly"""
     msg = b'x'
     packet = END + msg + END
     assert encode(msg) == packet
示例#9
0
 def test_simple_message_encoding(self):
     """A simple message without special bytes should be surrounded with END bytes."""
     msg = b'hallo'
     packet = END + msg + END
     assert encode(msg) == packet
示例#10
0
 def test_empty_message_encoding(self):
     """Empty message should result in an empty packet."""
     msg = b''
     packet = END + END
     assert encode(msg) == packet
示例#11
0
 def test_single_message_decoding(self):
     """Test decoding of a byte string with a single packet."""
     msg = b'hallo'
     packet = encode(msg)
     msg_list = self.driver.receive(packet)
     assert msg_list == [msg]
def write_status(status):
    data = status.SerializeToString()
    length = 2 + len(data)
    encoded = encode(pack('<H', length) + data)
    port.write(encoded)
    port.flush()