Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466

Dependencies:   ssd1331

Committer:
kadonotakashi
Date:
Thu Oct 11 02:27:46 2018 +0000
Revision:
3:f3764f852aa8
Parent:
0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kadonotakashi 0:8fdf9a60065b 1 """
kadonotakashi 0:8fdf9a60065b 2 mbed SDK
kadonotakashi 0:8fdf9a60065b 3 Copyright (c) 2011-2014 ARM Limited
kadonotakashi 0:8fdf9a60065b 4
kadonotakashi 0:8fdf9a60065b 5 Licensed under the Apache License, Version 2.0 (the "License");
kadonotakashi 0:8fdf9a60065b 6 you may not use this file except in compliance with the License.
kadonotakashi 0:8fdf9a60065b 7 You may obtain a copy of the License at
kadonotakashi 0:8fdf9a60065b 8
kadonotakashi 0:8fdf9a60065b 9 http://www.apache.org/licenses/LICENSE-2.0
kadonotakashi 0:8fdf9a60065b 10
kadonotakashi 0:8fdf9a60065b 11 Unless required by applicable law or agreed to in writing, software
kadonotakashi 0:8fdf9a60065b 12 distributed under the License is distributed on an "AS IS" BASIS,
kadonotakashi 0:8fdf9a60065b 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kadonotakashi 0:8fdf9a60065b 14 See the License for the specific language governing permissions and
kadonotakashi 0:8fdf9a60065b 15 limitations under the License.
kadonotakashi 0:8fdf9a60065b 16
kadonotakashi 0:8fdf9a60065b 17 Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
kadonotakashi 0:8fdf9a60065b 18 """
kadonotakashi 0:8fdf9a60065b 19
kadonotakashi 0:8fdf9a60065b 20 import re
kadonotakashi 0:8fdf9a60065b 21 import json
kadonotakashi 0:8fdf9a60065b 22
kadonotakashi 0:8fdf9a60065b 23
kadonotakashi 0:8fdf9a60065b 24 class BaseDBAccess():
kadonotakashi 0:8fdf9a60065b 25 """ Class used to connect with test database and store test results
kadonotakashi 0:8fdf9a60065b 26 """
kadonotakashi 0:8fdf9a60065b 27 def __init__(self):
kadonotakashi 0:8fdf9a60065b 28 self.db_object = None
kadonotakashi 0:8fdf9a60065b 29 self.db_type = None
kadonotakashi 0:8fdf9a60065b 30 # Connection credentials
kadonotakashi 0:8fdf9a60065b 31 self.host = None
kadonotakashi 0:8fdf9a60065b 32 self.user = None
kadonotakashi 0:8fdf9a60065b 33 self.passwd = None
kadonotakashi 0:8fdf9a60065b 34 self.db = None
kadonotakashi 0:8fdf9a60065b 35
kadonotakashi 0:8fdf9a60065b 36 # Test Suite DB scheme (table names)
kadonotakashi 0:8fdf9a60065b 37 self.TABLE_BUILD_ID = 'mtest_build_id'
kadonotakashi 0:8fdf9a60065b 38 self.TABLE_BUILD_ID_STATUS = 'mtest_build_id_status'
kadonotakashi 0:8fdf9a60065b 39 self.TABLE_BUILD_ID_TYPE = 'mtest_build_id_type'
kadonotakashi 0:8fdf9a60065b 40 self.TABLE_TARGET = 'mtest_target'
kadonotakashi 0:8fdf9a60065b 41 self.TABLE_TEST_ENTRY = 'mtest_test_entry'
kadonotakashi 0:8fdf9a60065b 42 self.TABLE_TEST_ID = 'mtest_test_id'
kadonotakashi 0:8fdf9a60065b 43 self.TABLE_TEST_RESULT = 'mtest_test_result'
kadonotakashi 0:8fdf9a60065b 44 self.TABLE_TEST_TYPE = 'mtest_test_type'
kadonotakashi 0:8fdf9a60065b 45 self.TABLE_TOOLCHAIN = 'mtest_toolchain'
kadonotakashi 0:8fdf9a60065b 46 # Build ID status PKs
kadonotakashi 0:8fdf9a60065b 47 self.BUILD_ID_STATUS_STARTED = 1 # Started
kadonotakashi 0:8fdf9a60065b 48 self.BUILD_ID_STATUS_IN_PROGRESS = 2 # In Progress
kadonotakashi 0:8fdf9a60065b 49 self.BUILD_ID_STATUS_COMPLETED = 3 #Completed
kadonotakashi 0:8fdf9a60065b 50 self.BUILD_ID_STATUS_FAILED = 4 # Failed
kadonotakashi 0:8fdf9a60065b 51 # Build ID type PKs
kadonotakashi 0:8fdf9a60065b 52 self.BUILD_ID_TYPE_TEST = 1 # Test
kadonotakashi 0:8fdf9a60065b 53 self.BUILD_ID_TYPE_BUILD_ONLY = 2 # Build Only
kadonotakashi 0:8fdf9a60065b 54
kadonotakashi 0:8fdf9a60065b 55 def get_hostname(self):
kadonotakashi 0:8fdf9a60065b 56 """ Useful when creating build_id in database
kadonotakashi 0:8fdf9a60065b 57 Function returns (hostname, uname) which can be used as (build_id_name, build_id_desc)
kadonotakashi 0:8fdf9a60065b 58 """
kadonotakashi 0:8fdf9a60065b 59 # Get hostname from socket
kadonotakashi 0:8fdf9a60065b 60 import socket
kadonotakashi 0:8fdf9a60065b 61 hostname = socket.gethostbyaddr(socket.gethostname())[0]
kadonotakashi 0:8fdf9a60065b 62 # Get uname from platform resources
kadonotakashi 0:8fdf9a60065b 63 import platform
kadonotakashi 0:8fdf9a60065b 64 uname = json.dumps(platform.uname())
kadonotakashi 0:8fdf9a60065b 65 return (hostname, uname)
kadonotakashi 0:8fdf9a60065b 66
kadonotakashi 0:8fdf9a60065b 67 def get_db_type(self):
kadonotakashi 0:8fdf9a60065b 68 """ Returns database type. E.g. 'mysql', 'sqlLite' etc.
kadonotakashi 0:8fdf9a60065b 69 """
kadonotakashi 0:8fdf9a60065b 70 return self.db_type
kadonotakashi 0:8fdf9a60065b 71
kadonotakashi 0:8fdf9a60065b 72 def detect_database(self, verbose=False):
kadonotakashi 0:8fdf9a60065b 73 """ detect database and return VERION data structure or string (verbose=True)
kadonotakashi 0:8fdf9a60065b 74 """
kadonotakashi 0:8fdf9a60065b 75 return None
kadonotakashi 0:8fdf9a60065b 76
kadonotakashi 0:8fdf9a60065b 77 def parse_db_connection_string(self, str):
kadonotakashi 0:8fdf9a60065b 78 """ Parsing SQL DB connection string. String should contain:
kadonotakashi 0:8fdf9a60065b 79 - DB Name, user name, password, URL (DB host), name
kadonotakashi 0:8fdf9a60065b 80 Function should return tuple with parsed (db_type, username, password, host, db_name) or None if error
kadonotakashi 0:8fdf9a60065b 81
kadonotakashi 0:8fdf9a60065b 82 (db_type, username, password, host, db_name) = self.parse_db_connection_string(db_url)
kadonotakashi 0:8fdf9a60065b 83
kadonotakashi 0:8fdf9a60065b 84 E.g. connection string: 'mysql://username:password@127.0.0.1/db_name'
kadonotakashi 0:8fdf9a60065b 85 """
kadonotakashi 0:8fdf9a60065b 86 result = None
kadonotakashi 0:8fdf9a60065b 87 if type(str) == type(''):
kadonotakashi 0:8fdf9a60065b 88 PATTERN = '^([\w]+)://([\w]+):([\w]*)@(.*)/([\w]+)'
kadonotakashi 0:8fdf9a60065b 89 result = re.match(PATTERN, str)
kadonotakashi 0:8fdf9a60065b 90 if result is not None:
kadonotakashi 0:8fdf9a60065b 91 result = result.groups() # Tuple (db_name, host, user, passwd, db)
kadonotakashi 0:8fdf9a60065b 92 return result # (db_type, username, password, host, db_name)
kadonotakashi 0:8fdf9a60065b 93
kadonotakashi 0:8fdf9a60065b 94 def is_connected(self):
kadonotakashi 0:8fdf9a60065b 95 """ Returns True if we are connected to database
kadonotakashi 0:8fdf9a60065b 96 """
kadonotakashi 0:8fdf9a60065b 97 pass
kadonotakashi 0:8fdf9a60065b 98
kadonotakashi 0:8fdf9a60065b 99 def connect(self, host, user, passwd, db):
kadonotakashi 0:8fdf9a60065b 100 """ Connects to DB and returns DB object
kadonotakashi 0:8fdf9a60065b 101 """
kadonotakashi 0:8fdf9a60065b 102 pass
kadonotakashi 0:8fdf9a60065b 103
kadonotakashi 0:8fdf9a60065b 104 def connect_url(self, db_url):
kadonotakashi 0:8fdf9a60065b 105 """ Connects to database using db_url (database url parsing),
kadonotakashi 0:8fdf9a60065b 106 store host, username, password, db_name
kadonotakashi 0:8fdf9a60065b 107 """
kadonotakashi 0:8fdf9a60065b 108 pass
kadonotakashi 0:8fdf9a60065b 109
kadonotakashi 0:8fdf9a60065b 110 def reconnect(self):
kadonotakashi 0:8fdf9a60065b 111 """ Reconnects to DB and returns DB object using stored host name,
kadonotakashi 0:8fdf9a60065b 112 database name and credentials (user name and password)
kadonotakashi 0:8fdf9a60065b 113 """
kadonotakashi 0:8fdf9a60065b 114 pass
kadonotakashi 0:8fdf9a60065b 115
kadonotakashi 0:8fdf9a60065b 116 def disconnect(self):
kadonotakashi 0:8fdf9a60065b 117 """ Close DB connection
kadonotakashi 0:8fdf9a60065b 118 """
kadonotakashi 0:8fdf9a60065b 119 pass
kadonotakashi 0:8fdf9a60065b 120
kadonotakashi 0:8fdf9a60065b 121 def escape_string(self, str):
kadonotakashi 0:8fdf9a60065b 122 """ Escapes string so it can be put in SQL query between quotes
kadonotakashi 0:8fdf9a60065b 123 """
kadonotakashi 0:8fdf9a60065b 124 pass
kadonotakashi 0:8fdf9a60065b 125
kadonotakashi 0:8fdf9a60065b 126 def select_all(self, query):
kadonotakashi 0:8fdf9a60065b 127 """ Execute SELECT query and get all results
kadonotakashi 0:8fdf9a60065b 128 """
kadonotakashi 0:8fdf9a60065b 129 pass
kadonotakashi 0:8fdf9a60065b 130
kadonotakashi 0:8fdf9a60065b 131 def insert(self, query, commit=True):
kadonotakashi 0:8fdf9a60065b 132 """ Execute INSERT query, define if you want to commit
kadonotakashi 0:8fdf9a60065b 133 """
kadonotakashi 0:8fdf9a60065b 134 pass
kadonotakashi 0:8fdf9a60065b 135
kadonotakashi 0:8fdf9a60065b 136 def get_next_build_id(self, name, desc='', location='', type=None, status=None):
kadonotakashi 0:8fdf9a60065b 137 """ Insert new build_id (DB unique build like ID number to send all test results)
kadonotakashi 0:8fdf9a60065b 138 """
kadonotakashi 0:8fdf9a60065b 139 pass
kadonotakashi 0:8fdf9a60065b 140
kadonotakashi 0:8fdf9a60065b 141 def get_table_entry_pk(self, table, column, value, update_db=True):
kadonotakashi 0:8fdf9a60065b 142 """ Checks for entries in tables with two columns (<TABLE_NAME>_pk, <column>)
kadonotakashi 0:8fdf9a60065b 143 If update_db is True updates table entry if value in specified column doesn't exist
kadonotakashi 0:8fdf9a60065b 144 """
kadonotakashi 0:8fdf9a60065b 145 pass
kadonotakashi 0:8fdf9a60065b 146
kadonotakashi 0:8fdf9a60065b 147 def update_table_entry(self, table, column, value):
kadonotakashi 0:8fdf9a60065b 148 """ Updates table entry if value in specified column doesn't exist
kadonotakashi 0:8fdf9a60065b 149 Locks table to perform atomic read + update
kadonotakashi 0:8fdf9a60065b 150 """
kadonotakashi 0:8fdf9a60065b 151 pass
kadonotakashi 0:8fdf9a60065b 152
kadonotakashi 0:8fdf9a60065b 153 def update_build_id_info(self, build_id, **kw):
kadonotakashi 0:8fdf9a60065b 154 """ Update additional data inside build_id table
kadonotakashi 0:8fdf9a60065b 155 Examples:
kadonotakashi 0:8fdf9a60065b 156 db.update_build_is(build_id, _status_fk=self.BUILD_ID_STATUS_COMPLETED, _shuffle_seed=0.0123456789):
kadonotakashi 0:8fdf9a60065b 157 """
kadonotakashi 0:8fdf9a60065b 158 pass
kadonotakashi 0:8fdf9a60065b 159
kadonotakashi 0:8fdf9a60065b 160 def insert_test_entry(self, build_id, target, toolchain, test_type, test_id, test_result, test_time, test_timeout, test_loop, test_extra=''):
kadonotakashi 0:8fdf9a60065b 161 """ Inserts test result entry to database. All checks regarding existing
kadonotakashi 0:8fdf9a60065b 162 toolchain names in DB are performed.
kadonotakashi 0:8fdf9a60065b 163 If some data is missing DB will be updated
kadonotakashi 0:8fdf9a60065b 164 """
kadonotakashi 0:8fdf9a60065b 165 pass