예제 #1
0
    def test_send_binary_timeout(self):

        send_binary(START_MESSAGE)  # go to arduino listening state
        print('sleeping...')
        time.sleep(15)

        response = send_binary(
            START_MESSAGE)  # send dummy message to read response
        # time.sleep(0.1)

        status = interpret_response(response)
        self.assertEqual(status, (False, TIMEOUT_ERR_PACKET), 'No timeout!')
예제 #2
0
    def test_send_binary_long_message_is_truncated(self):

        bad_message1 = ACK_MESSAGE + ' E0'
        bad_message2 = 'E4 02 01 E0'

        response1 = send_binary(bad_message1)
        # time.sleep(0.1)
        response2 = send_binary(bad_message2)

        status1 = interpret_response(response1)
        status2 = interpret_response(response2)
        self.assertEqual(status1, (False, BAD_MESSAGE_PACKET),
                         'Bad message sent -- second message')
        self.assertEqual(status2, (False, BAD_MESSAGE_PACKET),
                         'Bad message sent -- second message')
예제 #3
0
    def test_send_binary_bad_message(self):

        bad_messages = [
            'E1 E4 08 00 E1',
            'E0 E4 08 00 E0',
            'E0 FF 08 00 E1',
            'E0 01 08 00 E1',
            'E3 E3 E3 E3 E3',
            'E0 E4 08 00 E1 E1',
            'E0 E4 08 00 E1 E0 E4 08 00',
            'E0 E4 08 00 E1 E0 E4 08 00 E4'  # 100 byte message
            'E0 E4 08 00 E1 E0 E4 08 00 E4'  # 100 byte message
            'E0 E4 08 00 E1 E0 E4 08 00 E4'  # 100 byte message
            'E0 E4 08 00 E1 E0 E4 08 00 E4'  # 100 byte message
            'E0 E4 08 00 E1 E0 E4 08 00 E4'  # 100 byte message
            'E0 E4 08 00 E1 E0 E4 08 00 E4'  # 100 byte message
            'E0 E4 08 00 E1 E0 E4 08 00 E4'  # 100 byte message
            'E0 E4 08 00 E1 E0 E4 08 00 E4'  # 100 byte message
            'E0 E4 08 00 E1 E0 E4 08 00 E4'  # 100 byte message
            'E0 E4 08 00 E1 E0 E4 08 00 E4',  # 100 byte message
            'E0 E4 08 E1',
            'E0 E4 08 02 E1',
            '00 00 00 00 00',
            'E9 E9 E9 E9 E9'
        ]
        for message in bad_messages:  # first message, i.e. waiting state

            arduino_reset()
            print('test case: ' + str(message))
            response = send_binary(message)
            status = interpret_response(response)
            self.assertEqual(status, (False, BAD_MESSAGE_PACKET),
                             'Bad message sent -- first message')

        for message in bad_messages:  # second message, i.e. listening state

            arduino_reset()
            send_binary(START_MESSAGE)
            # time.sleep(0.1)

            response = send_binary(message)
            status = interpret_response(response)
            self.assertEqual(status, (False, BAD_MESSAGE_PACKET),
                             'Bad message sent -- second message')
예제 #4
0
    def test_send_binary_bad_pin(self):

        bad_pins = [
            'E0 E4 00 00 E1', 'E0 E4 01 00 E1', 'E0 E4 13 00 E1',
            'E0 E4 14 00 E1', 'E0 E4 15 00 E1', 'E0 E4 E0 00 E1',
            'E0 E4 E1 00 E1', 'E0 E4 E2 00 E1', 'E0 E4 E3 00 E1',
            'E0 E4 E4 00 E1', 'E0 E4 E5 00 E1', 'E0 E4 E6 00 E1',
            'E0 E4 E7 00 E1', 'E0 E4 E8 00 E1', 'E0 E4 E9 00 E1',
            'E0 E4 0D 00 E1', 'E0 E4 0E 00 E1', 'E0 E4 0F 00 E1',
            'E0 E4 10 00 E1'
        ]

        for pin in bad_pins:  # second message, i.e. listening state

            arduino_reset()
            send_binary(START_MESSAGE)  # go to arduino listening state
            # time.sleep(0.1)

            response = send_binary(pin)
            status = interpret_response(response)
            self.assertEqual(status, (False, BAD_PIN_PACKET),
                             'Bad pin sent -- second message')
예제 #5
0
def arduino_reset():
    # time.sleep(0.1)
    send_binary(START_MESSAGE)
    # time.sleep(0.1)
    send_binary('E0 E4 02 00 E1')
    # time.sleep(0.1)

    send_binary(START_MESSAGE)
    # time.sleep(0.1)
    send_binary('E0 E4 02 01 E1')
    # time.sleep(0.1)

    send_binary(START_MESSAGE)
    # time.sleep(0.1)
    send_binary('E0 E4 02 00 E1')