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 re
be_bryan 0:b74591d5ab33 19 from time import time, strftime, gmtime
be_bryan 0:b74591d5ab33 20
be_bryan 0:b74591d5ab33 21 class RTCTest():
be_bryan 0:b74591d5ab33 22 PATTERN_RTC_VALUE = "\[(\d+)\] \[(\d+-\d+-\d+ \d+:\d+:\d+ [AaPpMm]{2})\]"
be_bryan 0:b74591d5ab33 23 re_detect_rtc_value = re.compile(PATTERN_RTC_VALUE)
be_bryan 0:b74591d5ab33 24
be_bryan 0:b74591d5ab33 25 def test(self, selftest):
be_bryan 0:b74591d5ab33 26 test_result = True
be_bryan 0:b74591d5ab33 27 start = time()
be_bryan 0:b74591d5ab33 28 sec_prev = 0
be_bryan 0:b74591d5ab33 29 for i in range(0, 5):
be_bryan 0:b74591d5ab33 30 # Timeout changed from default: we need to wait longer for some boards to start-up
be_bryan 0:b74591d5ab33 31 c = selftest.mbed.serial_readline(timeout=10)
be_bryan 0:b74591d5ab33 32 if c is None:
be_bryan 0:b74591d5ab33 33 return selftest.RESULT_IO_SERIAL
be_bryan 0:b74591d5ab33 34 selftest.notify(c.strip())
be_bryan 0:b74591d5ab33 35 delta = time() - start
be_bryan 0:b74591d5ab33 36 m = self.re_detect_rtc_value.search(c)
be_bryan 0:b74591d5ab33 37 if m and len(m.groups()):
be_bryan 0:b74591d5ab33 38 sec = int(m.groups()[0])
be_bryan 0:b74591d5ab33 39 time_str = m.groups()[1]
be_bryan 0:b74591d5ab33 40 correct_time_str = strftime("%Y-%m-%d %H:%M:%S %p", gmtime(float(sec)))
be_bryan 0:b74591d5ab33 41 single_result = time_str == correct_time_str and sec > 0 and sec > sec_prev
be_bryan 0:b74591d5ab33 42 test_result = test_result and single_result
be_bryan 0:b74591d5ab33 43 result_msg = "OK" if single_result else "FAIL"
be_bryan 0:b74591d5ab33 44 selftest.notify("HOST: [%s] [%s] received time %+d sec after %.2f sec... %s"% (sec, time_str, sec - sec_prev, delta, result_msg))
be_bryan 0:b74591d5ab33 45 sec_prev = sec
be_bryan 0:b74591d5ab33 46 else:
be_bryan 0:b74591d5ab33 47 test_result = False
be_bryan 0:b74591d5ab33 48 break
be_bryan 0:b74591d5ab33 49 start = time()
be_bryan 0:b74591d5ab33 50 return selftest.RESULT_SUCCESS if test_result else selftest.RESULT_FAILURE