Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
Ce dépôt est archivé. Vous pouvez voir les fichiers et le cloner, mais vous ne pouvez pas pousser ni ouvrir de ticket/demande d'ajout.

rtc_auto.py 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """
  2. mbed SDK
  3. Copyright (c) 2011-2013 ARM Limited
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. """
  14. import re
  15. from time import time, strftime, gmtime
  16. class RTCTest():
  17. PATTERN_RTC_VALUE = "\[(\d+)\] \[(\d+-\d+-\d+ \d+:\d+:\d+ [AaPpMm]{2})\]"
  18. re_detect_rtc_value = re.compile(PATTERN_RTC_VALUE)
  19. def test(self, selftest):
  20. test_result = True
  21. start = time()
  22. sec_prev = 0
  23. for i in range(0, 5):
  24. # Timeout changed from default: we need to wait longer for some boards to start-up
  25. c = selftest.mbed.serial_readline(timeout=10)
  26. if c is None:
  27. return selftest.RESULT_IO_SERIAL
  28. selftest.notify(c.strip())
  29. delta = time() - start
  30. m = self.re_detect_rtc_value.search(c)
  31. if m and len(m.groups()):
  32. sec = int(m.groups()[0])
  33. time_str = m.groups()[1]
  34. correct_time_str = strftime("%Y-%m-%d %H:%M:%S %p", gmtime(float(sec)))
  35. single_result = time_str == correct_time_str and sec > 0 and sec > sec_prev
  36. test_result = test_result and single_result
  37. result_msg = "OK" if single_result else "FAIL"
  38. selftest.notify("HOST: [%s] [%s] received time %+d sec after %.2f sec... %s"% (sec, time_str, sec - sec_prev, delta, result_msg))
  39. sec_prev = sec
  40. else:
  41. test_result = False
  42. break
  43. start = time()
  44. return selftest.RESULT_SUCCESS if test_result else selftest.RESULT_FAILURE