mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

UserRevisionLine numberNew contents of line
be_bryan 0:b74591d5ab33 1 """
be_bryan 0:b74591d5ab33 2 mbed SDK
be_bryan 0:b74591d5ab33 3 Copyright (c) 2011-2013 ARM Limited
be_bryan 0:b74591d5ab33 4
be_bryan 0:b74591d5ab33 5 Licensed under the Apache License, Version 2.0 (the "License");
be_bryan 0:b74591d5ab33 6 you may not use this file except in compliance with the License.
be_bryan 0:b74591d5ab33 7 You may obtain a copy of the License at
be_bryan 0:b74591d5ab33 8
be_bryan 0:b74591d5ab33 9 http://www.apache.org/licenses/LICENSE-2.0
be_bryan 0:b74591d5ab33 10
be_bryan 0:b74591d5ab33 11 Unless required by applicable law or agreed to in writing, software
be_bryan 0:b74591d5ab33 12 distributed under the License is distributed on an "AS IS" BASIS,
be_bryan 0:b74591d5ab33 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
be_bryan 0:b74591d5ab33 14 See the License for the specific language governing permissions and
be_bryan 0:b74591d5ab33 15 limitations under the License.
be_bryan 0:b74591d5ab33 16 """
be_bryan 0:b74591d5ab33 17
be_bryan 0:b74591d5ab33 18 import sys
be_bryan 0:b74591d5ab33 19 import uuid
be_bryan 0:b74591d5ab33 20 from sys import stdout
be_bryan 0:b74591d5ab33 21
be_bryan 0:b74591d5ab33 22 class EchoTest():
be_bryan 0:b74591d5ab33 23
be_bryan 0:b74591d5ab33 24 # Test parameters
be_bryan 0:b74591d5ab33 25 TEST_SERIAL_BAUDRATE = 115200
be_bryan 0:b74591d5ab33 26 TEST_LOOP_COUNT = 50
be_bryan 0:b74591d5ab33 27
be_bryan 0:b74591d5ab33 28 def test(self, selftest):
be_bryan 0:b74591d5ab33 29 """ This host test will use mbed serial port with
be_bryan 0:b74591d5ab33 30 baudrate 115200 to perform echo test on that port.
be_bryan 0:b74591d5ab33 31 """
be_bryan 0:b74591d5ab33 32 # Custom initialization for echo test
be_bryan 0:b74591d5ab33 33 selftest.mbed.init_serial_params(serial_baud=self.TEST_SERIAL_BAUDRATE)
be_bryan 0:b74591d5ab33 34 selftest.mbed.init_serial()
be_bryan 0:b74591d5ab33 35
be_bryan 0:b74591d5ab33 36 # Test function, return True or False to get standard test notification on stdout
be_bryan 0:b74591d5ab33 37 selftest.mbed.flush()
be_bryan 0:b74591d5ab33 38 selftest.notify("HOST: Starting the ECHO test")
be_bryan 0:b74591d5ab33 39 result = True
be_bryan 0:b74591d5ab33 40
be_bryan 0:b74591d5ab33 41 """ This ensures that there are no parasites left in the serial buffer.
be_bryan 0:b74591d5ab33 42 """
be_bryan 0:b74591d5ab33 43 for i in range(0, 2):
be_bryan 0:b74591d5ab33 44 selftest.mbed.serial_write("\n")
be_bryan 0:b74591d5ab33 45 c = selftest.mbed.serial_readline()
be_bryan 0:b74591d5ab33 46
be_bryan 0:b74591d5ab33 47 for i in range(0, self.TEST_LOOP_COUNT):
be_bryan 0:b74591d5ab33 48 TEST_STRING = str(uuid.uuid4()) + "\n"
be_bryan 0:b74591d5ab33 49 selftest.mbed.serial_write(TEST_STRING)
be_bryan 0:b74591d5ab33 50 c = selftest.mbed.serial_readline()
be_bryan 0:b74591d5ab33 51 if c is None:
be_bryan 0:b74591d5ab33 52 return selftest.RESULT_IO_SERIAL
be_bryan 0:b74591d5ab33 53 if c.strip() != TEST_STRING.strip():
be_bryan 0:b74591d5ab33 54 selftest.notify('HOST: "%s" != "%s"'% (c, TEST_STRING))
be_bryan 0:b74591d5ab33 55 result = False
be_bryan 0:b74591d5ab33 56 else:
be_bryan 0:b74591d5ab33 57 sys.stdout.write('.')
be_bryan 0:b74591d5ab33 58 stdout.flush()
be_bryan 0:b74591d5ab33 59 return selftest.RESULT_SUCCESS if result else selftest.RESULT_FAILURE