BA / Mbed OS BaBoRo1
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers serial_nc_rx_auto.py Source File

serial_nc_rx_auto.py

00001 """
00002 mbed SDK
00003 Copyright (c) 2011-2013 ARM Limited
00004 
00005 Licensed under the Apache License, Version 2.0 (the "License");
00006 you may not use this file except in compliance with the License.
00007 You may obtain a copy of the License at
00008 
00009     http://www.apache.org/licenses/LICENSE-2.0
00010 
00011 Unless required by applicable law or agreed to in writing, software
00012 distributed under the License is distributed on an "AS IS" BASIS,
00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 See the License for the specific language governing permissions and
00015 limitations under the License.
00016 """
00017 
00018 import sys
00019 import uuid
00020 import time
00021 import string
00022 from sys import stdout
00023 
00024 class SerialNCRXTest():
00025 
00026     def test(self, selftest):
00027         selftest.mbed.flush();
00028         # Wait 0.5 seconds to ensure mbed is listening
00029         time.sleep(0.5)
00030 
00031         #handshake with target to sync test start
00032         selftest.mbed.serial_write("S");
00033 
00034         strip_chars = string.whitespace + "\0"
00035 
00036         out_str = selftest.mbed.serial_readline()
00037 
00038         if not out_str:
00039             selftest.notify("HOST: No output detected")
00040             return selftest.RESULT_IO_SERIAL
00041 
00042         out_str_stripped = out_str.strip(strip_chars)
00043 
00044         if out_str_stripped != "RX OK - Start NC test":
00045             selftest.notify("HOST: Unexpected output. Expected 'RX OK - Expected' but received '%s'" % out_str_stripped)
00046             return selftest.RESULT_FAILURE
00047 
00048         # Wait 0.5 seconds to ensure mbed is listening
00049         time.sleep(0.5)
00050 
00051         selftest.mbed.serial_write("E");
00052 
00053         strip_chars = string.whitespace + "\0"
00054 
00055         out_str = selftest.mbed.serial_readline()
00056 
00057         if not out_str:
00058             selftest.notify("HOST: No output detected")
00059             return selftest.RESULT_IO_SERIAL
00060 
00061         out_str_stripped = out_str.strip(strip_chars)
00062 
00063         if out_str_stripped != "RX OK - Expected":
00064             selftest.notify("HOST: Unexpected output. Expected 'RX OK - Expected' but received '%s'" % out_str_stripped)
00065             return selftest.RESULT_FAILURE
00066 
00067         # Wait 0.5 seconds to ensure mbed is listening
00068         time.sleep(0.5)
00069 
00070         # Send character, mbed shouldn't receive
00071         selftest.mbed.serial_write("U");
00072 
00073         out_str = selftest.mbed.serial_readline()
00074 
00075         # If no characters received, pass the test
00076         if not out_str:
00077             selftest.notify("HOST: No further output detected")
00078             return selftest.RESULT_SUCCESS
00079         else:
00080             out_str_stripped = out_str.strip(strip_chars)
00081 
00082             if out_str_stripped == "RX OK - Unexpected":
00083                 selftest.notify("HOST: Unexpected output returned indicating RX still functioning")
00084             else:
00085                 selftest.notify("HOST: Extraneous output '%s' detected indicating unknown error" % out_str_stripped)
00086 
00087             return selftest.RESULT_FAILURE