mbed os with nrf51 internal bandgap enabled to read battery level

Dependents:   BLE_file_test BLE_Blink ExternalEncoder

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 """
elessair 0:f269e3021894 2 mbed SDK
elessair 0:f269e3021894 3 Copyright (c) 2011-2015 ARM Limited
elessair 0:f269e3021894 4
elessair 0:f269e3021894 5 Licensed under the Apache License, Version 2.0 (the "License");
elessair 0:f269e3021894 6 you may not use this file except in compliance with the License.
elessair 0:f269e3021894 7 You may obtain a copy of the License at
elessair 0:f269e3021894 8
elessair 0:f269e3021894 9 http://www.apache.org/licenses/LICENSE-2.0
elessair 0:f269e3021894 10
elessair 0:f269e3021894 11 Unless required by applicable law or agreed to in writing, software
elessair 0:f269e3021894 12 distributed under the License is distributed on an "AS IS" BASIS,
elessair 0:f269e3021894 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
elessair 0:f269e3021894 14 See the License for the specific language governing permissions and
elessair 0:f269e3021894 15 limitations under the License.
elessair 0:f269e3021894 16
elessair 0:f269e3021894 17 Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
elessair 0:f269e3021894 18
elessair 0:f269e3021894 19 """
elessair 0:f269e3021894 20
elessair 0:f269e3021894 21 from ioper_base import IOperTestCaseBase
elessair 0:f269e3021894 22
elessair 0:f269e3021894 23
elessair 0:f269e3021894 24 class IOperTest_TargetID(IOperTestCaseBase):
elessair 0:f269e3021894 25 """ tests related to target_id value
elessair 0:f269e3021894 26 """
elessair 0:f269e3021894 27
elessair 0:f269e3021894 28 def __init__(self, scope=None):
elessair 0:f269e3021894 29 IOperTestCaseBase.__init__(self, scope)
elessair 0:f269e3021894 30 self.TARGET_ID_LEN = 24
elessair 0:f269e3021894 31
elessair 0:f269e3021894 32 def test_target_id_format(self, target_id, target_id_name):
elessair 0:f269e3021894 33 # Expected length == 24, eg. "02400203D94B0E7724B7F3CF"
elessair 0:f269e3021894 34 result = []
elessair 0:f269e3021894 35 target_id_len = len(target_id) if target_id else 0
elessair 0:f269e3021894 36 if target_id_len == self.TARGET_ID_LEN:
elessair 0:f269e3021894 37 result.append((self.PASS, "TARGET_ID_LEN", self.scope, "%s '%s' is %d chars long " % (target_id_name, target_id, target_id_len)))
elessair 0:f269e3021894 38 result.append((self.INFO, "FW_VER_STR", self.scope, "%s Version String is %s.%s.%s " % (target_id_name,
elessair 0:f269e3021894 39 target_id[0:4],
elessair 0:f269e3021894 40 target_id[4:8],
elessair 0:f269e3021894 41 target_id[8:24],
elessair 0:f269e3021894 42 )))
elessair 0:f269e3021894 43 else:
elessair 0:f269e3021894 44 result.append((self.ERROR, "TARGET_ID_LEN", self.scope, "%s '%s' is %d chars long. Expected %d chars" % (target_id_name, target_id, target_id_len, self.TARGET_ID_LEN)))
elessair 0:f269e3021894 45 return result
elessair 0:f269e3021894 46
elessair 0:f269e3021894 47 def test_decode_target_id(self, target_id, target_id_name):
elessair 0:f269e3021894 48 result = []
elessair 0:f269e3021894 49 target_id_len = len(target_id) if target_id else 0
elessair 0:f269e3021894 50 if target_id_len >= 4:
elessair 0:f269e3021894 51 result.append((self.INFO, "FW_VEN_CODE", self.scope, "%s Vendor Code is '%s'" % (target_id_name, target_id[0:2])))
elessair 0:f269e3021894 52 result.append((self.INFO, "FW_PLAT_CODE", self.scope, "%s Platform Code is '%s'" % (target_id_name, target_id[2:4])))
elessair 0:f269e3021894 53 result.append((self.INFO, "FW_VER", self.scope, "%s Firmware Version is '%s'" % (target_id_name, target_id[4:8])))
elessair 0:f269e3021894 54 result.append((self.INFO, "FW_HASH_SEC", self.scope, "%s Hash of secret is '%s'" % (target_id_name, target_id[8:24])))
elessair 0:f269e3021894 55 return result
elessair 0:f269e3021894 56
elessair 0:f269e3021894 57 def test(self, param=None):
elessair 0:f269e3021894 58 result = []
elessair 0:f269e3021894 59 if param:
elessair 0:f269e3021894 60 pass
elessair 0:f269e3021894 61 return result
elessair 0:f269e3021894 62
elessair 0:f269e3021894 63
elessair 0:f269e3021894 64 class IOperTest_TargetID_Basic(IOperTest_TargetID):
elessair 0:f269e3021894 65 """ Basic interoperability tests checking TargetID compliance
elessair 0:f269e3021894 66 """
elessair 0:f269e3021894 67
elessair 0:f269e3021894 68 def __init__(self, scope=None):
elessair 0:f269e3021894 69 IOperTest_TargetID.__init__(self, scope)
elessair 0:f269e3021894 70
elessair 0:f269e3021894 71 def test(self, param=None):
elessair 0:f269e3021894 72 result = []
elessair 0:f269e3021894 73
elessair 0:f269e3021894 74 if param:
elessair 0:f269e3021894 75 result.append((self.PASS, "TARGET_ID", self.scope, "TargetID '%s' found" % param['target_id']))
elessair 0:f269e3021894 76
elessair 0:f269e3021894 77 # Check if target name can be decoded with mbed-ls
elessair 0:f269e3021894 78 if param['platform_name']:
elessair 0:f269e3021894 79 result.append((self.PASS, "TARGET_ID_DECODE", self.scope, "TargetID '%s' decoded as '%s'" % (param['target_id'][0:4], param['platform_name'])))
elessair 0:f269e3021894 80 else:
elessair 0:f269e3021894 81 result.append((self.ERROR, "TARGET_ID_DECODE", self.scope, "TargetID '%s'... not decoded" % (param['target_id'] if param['target_id'] else '')))
elessair 0:f269e3021894 82
elessair 0:f269e3021894 83 # Test for USBID and mbed.htm consistency
elessair 0:f269e3021894 84 if param['target_id_mbed_htm'] == param['target_id_usb_id']:
elessair 0:f269e3021894 85 result.append((self.PASS, "TARGET_ID_MATCH", self.scope, "TargetID (USBID) and TargetID (mbed.htm) match"))
elessair 0:f269e3021894 86 else:
elessair 0:f269e3021894 87 text = "TargetID (USBID) and TargetID (mbed.htm) don't match: '%s' != '%s'" % (param['target_id_usb_id'], param['target_id_mbed_htm'])
elessair 0:f269e3021894 88 result.append((self.WARN, "TARGET_ID_MATCH", self.scope, text))
elessair 0:f269e3021894 89 else:
elessair 0:f269e3021894 90 result.append((self.ERROR, "TARGET_ID", self.scope, "TargetID not found"))
elessair 0:f269e3021894 91 return result
elessair 0:f269e3021894 92
elessair 0:f269e3021894 93 class IOperTest_TargetID_MbedEnabled(IOperTest_TargetID):
elessair 0:f269e3021894 94 """ Basic interoperability tests checking TargetID compliance
elessair 0:f269e3021894 95 """
elessair 0:f269e3021894 96
elessair 0:f269e3021894 97 def __init__(self, scope=None):
elessair 0:f269e3021894 98 IOperTest_TargetID.__init__(self, scope)
elessair 0:f269e3021894 99
elessair 0:f269e3021894 100 def test(self, param=None):
elessair 0:f269e3021894 101 result = []
elessair 0:f269e3021894 102
elessair 0:f269e3021894 103 if param:
elessair 0:f269e3021894 104 # Target ID tests:
elessair 0:f269e3021894 105 result += self.test_target_id_format(param['target_id_usb_id'], "TargetId (USBID)")
elessair 0:f269e3021894 106 result += self.test_target_id_format(param['target_id_mbed_htm'], "TargetId (mbed.htm)")
elessair 0:f269e3021894 107
elessair 0:f269e3021894 108 # Some extra info about TargetID itself
elessair 0:f269e3021894 109 result += self.test_decode_target_id(param['target_id_usb_id'], "TargetId (USBID)")
elessair 0:f269e3021894 110 result += self.test_decode_target_id(param['target_id_mbed_htm'], "TargetId (mbed.htm)")
elessair 0:f269e3021894 111 return result