Esempio n. 1
0
class HarwareTest(unittest.TestCase):
    def setUp(self):
        setInfo()
        self.hardware = Hardware()

    def testGetManufacturer(self):
        manufacturer = self.hardware.getManufacturer()
        info(manufacturer)
        self.assertNotEqual(manufacturer, '')

    def testGetModel(self):
        model = self.hardware.getModel()
        info(model)
        self.assertNotEqual(model, 'Unknown')

    def testGetMac(self):
        mac = self.hardware.getMac()
        info(mac)
        self.assertRegex(mac, '^([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})$')

    def testBoardRevision(self):
        info(BOARD_REVISION)
        self.assertGreaterEqual(BOARD_REVISION, 0)
        self.assertLessEqual(BOARD_REVISION, 3)

    def testCpuRevision(self):
        info(CPU_REVISION)
        self.assertNotEqual(CPU_REVISION, '0')

    def testCpuHardware(self):
        info(CPU_HARDWARE)
        self.assertNotEqual(CPU_HARDWARE, '')

    def testDeviceVerification(self):
        device_checks = (self.hardware.isRaspberryPi(),
                         self.hardware.isTinkerBoard(),
                         self.hardware.isBeagleBone())
        self.assertEqual(device_checks.count(True), 1)
Esempio n. 2
0
    def __init__(self, chip=0, mode=0, bits=8, speed=0, init=True):
        bus = 0
        hardware = Hardware()
        if hardware.isTinkerBoard():
            bus = 2
        elif hardware.isBeagleBone():
            bus = 1
        Bus.__init__(self, "SPI", "/dev/spidev%d.%d" % (bus, chip))
        self.chip = chip

        val8 = array.array('B', [0])
        val8[0] = mode
        if fcntl.ioctl(self.fd, SPI_IOC_WR_MODE, val8):
            raise Exception("Cannot write SPI Mode")
        if fcntl.ioctl(self.fd, SPI_IOC_RD_MODE, val8):
            raise Exception("Cannot read SPI Mode")
        self.mode = struct.unpack('B', val8)[0]
        assert (self.mode == mode)

        val8[0] = bits
        if fcntl.ioctl(self.fd, SPI_IOC_WR_BITS_PER_WORD, val8):
            raise Exception("Cannot write SPI Bits per word")
        if fcntl.ioctl(self.fd, SPI_IOC_RD_BITS_PER_WORD, val8):
            raise Exception("Cannot read SPI Bits per word")
        self.bits = struct.unpack('B', val8)[0]
        assert (self.bits == bits)

        val32 = array.array('I', [0])
        if speed > 0:
            val32[0] = speed
            if fcntl.ioctl(self.fd, SPI_IOC_WR_MAX_SPEED_HZ, val32):
                raise Exception("Cannot write SPI Max speed")
        if fcntl.ioctl(self.fd, SPI_IOC_RD_MAX_SPEED_HZ, val32):
            raise Exception("Cannot read SPI Max speed")
        self.speed = struct.unpack('I', val32)[0]
        assert ((self.speed == speed) or (speed == 0))
Esempio n. 3
0
    def __init__(self, slave, allow_duplicates=False):
        global SLAVES

        if SLAVES[slave] != None and not allow_duplicates:
            raise Exception("SLAVE_ADDRESS_USED")

        self.channel = 0
        hardware = Hardware()
        if BOARD_REVISION > 1 or hardware.isTinkerBoard():
            self.channel = 1
        elif hardware.isBeagleBone():
            self.channel = 2

        Bus.__init__(self, "I2C", "/dev/i2c-%d" % self.channel)
        self.slave = slave
        if fcntl.ioctl(self.fd, I2C_SLAVE, self.slave):
            raise Exception("Error binding I2C slave 0x%02X" % self.slave)

        # Since we now allow duplicates, e.g. BMP180_TEMPERATURE & BMP180_PRESSURE, we might need to
        # change the SLAVES list to store a reference count or base class name as a way of making sure
        # only the same base sensor type is duplicated. That doesn't seem to be an issue currently though
        # so for now we just ignore the SLAVES check.
        if not allow_duplicates:
            SLAVES[self.slave] = self
Esempio n. 4
0
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

import os
import time
import subprocess

from myDevices.utils.logger import debug, info
from myDevices.system.version import OS_VERSION, OS_JESSIE, OS_WHEEZY
from myDevices.system.hardware import Hardware

hardware = Hardware()
if hardware.isTinkerBoard():
    # Tinker Board only supports I2C and SPI for now. These are enabled by default and 
    # don't need to load any modules.
    BUSLIST = {
        "I2C": {
            "enabled": True,
        },

        "SPI": {
            "enabled": True,
        }
    }
elif hardware.isBeagleBone():
    BUSLIST = {
        "I2C": {
            "enabled": True,
Esempio n. 5
0
 def setPinMapping(self):
     hardware = Hardware()
     if hardware.isTinkerBoard():
         self.MAPPING = [{
             'name':
             'GPIO',
             'map': [{
                 'power': 'V33'
             }, {
                 'power': 'V50'
             }, {
                 'gpio': 252
             }, {
                 'power': 'V50'
             }, {
                 'gpio': 253
             }, {
                 'power': 'GND'
             }, {
                 'gpio': 17
             }, {
                 'gpio': 161
             }, {
                 'power': 'GND'
             }, {
                 'gpio': 160
             }, {
                 'gpio': 164
             }, {
                 'gpio': 184
             }, {
                 'gpio': 166
             }, {
                 'power': 'GND'
             }, {
                 'gpio': 167
             }, {
                 'gpio': 162
             }, {
                 'power': 'V33'
             }, {
                 'gpio': 163
             }, {
                 'gpio': 257
             }, {
                 'power': 'GND'
             }, {
                 'gpio': 256
             }, {
                 'gpio': 171
             }, {
                 'gpio': 254
             }, {
                 'gpio': 255
             }, {
                 'power': 'GND'
             }, {
                 'gpio': 251
             }, {
                 'dnc': True
             }, {
                 'dnc': True
             }, {
                 'gpio': 165
             }, {
                 'power': 'GND'
             }, {
                 'gpio': 168
             }, {
                 'gpio': 239
             }, {
                 'gpio': 238
             }, {
                 'power': 'GND'
             }, {
                 'gpio': 185
             }, {
                 'gpio': 223
             }, {
                 'gpio': 224
             }, {
                 'gpio': 187
             }, {
                 'power': 'GND'
             }, {
                 'gpio': 188
             }]
         }]
     elif hardware.isBeagleBone():
         self.MAPPING = [{
             'name':
             'P9',
             'map': [{
                 'power': 'GND'
             }, {
                 'power': 'GND'
             }, {
                 'power': 'V33'
             }, {
                 'power': 'V33'
             }, {
                 'power': 'V50'
             }, {
                 'power': 'V50'
             }, {
                 'power': 'V50'
             }, {
                 'power': 'V50'
             }, {
                 'power': 'PWR'
             }, {
                 'power': 'RST'
             }, {
                 'gpio': 30
             }, {
                 'gpio': 60
             }, {
                 'gpio': 31
             }, {
                 'gpio': 50
             }, {
                 'gpio': 48
             }, {
                 'gpio': 51
             }, {
                 'gpio': 5
             }, {
                 'gpio': 4
             }, {
                 'alt0': {
                     'channel': 'sys:i2c:2',
                     'name': 'SCL'
                 }
             }, {
                 'alt0': {
                     'channel': 'sys:i2c:2',
                     'name': 'SDA'
                 }
             }, {
                 'gpio': 3
             }, {
                 'gpio': 2
             }, {
                 'gpio': 49
             }, {
                 'gpio': 15
             }, {
                 'gpio': 117
             }, {
                 'gpio': 14
             }, {
                 'gpio': 115
             }, {
                 'gpio': 113,
                 'alt0': {
                     'channel': 'sys:spi:1',
                     'name': 'CS0'
                 }
             }, {
                 'gpio': 111,
                 'alt0': {
                     'channel': 'sys:spi:1',
                     'name': 'D0'
                 }
             }, {
                 'gpio': 112,
                 'alt0': {
                     'channel': 'sys:spi:1',
                     'name': 'D1'
                 }
             }, {
                 'gpio': 110,
                 'alt0': {
                     'channel': 'sys:spi:1',
                     'name': 'SCLK'
                 }
             }, {
                 'power': 'VDD_ADC'
             }, {
                 'analog': 4
             }, {
                 'power': 'GNDA_ADC'
             }, {
                 'analog': 6
             }, {
                 'analog': 5
             }, {
                 'analog': 2
             }, {
                 'analog': 3
             }, {
                 'analog': 0
             }, {
                 'analog': 1
             }, {
                 'gpio': 20
             }, {
                 'gpio': 7
             }, {
                 'power': 'GND'
             }, {
                 'power': 'GND'
             }, {
                 'power': 'GND'
             }, {
                 'power': 'GND'
             }]
         }, {
             'name':
             'P8',
             'map': [{
                 'power': 'GND'
             }, {
                 'power': 'GND'
             }, {
                 'gpio': 38
             }, {
                 'gpio': 39
             }, {
                 'gpio': 34
             }, {
                 'gpio': 35
             }, {
                 'gpio': 66
             }, {
                 'gpio': 67
             }, {
                 'gpio': 69
             }, {
                 'gpio': 68
             }, {
                 'gpio': 45
             }, {
                 'gpio': 44
             }, {
                 'gpio': 23
             }, {
                 'gpio': 26
             }, {
                 'gpio': 47
             }, {
                 'gpio': 46
             }, {
                 'gpio': 27
             }, {
                 'gpio': 65
             }, {
                 'gpio': 22
             }, {
                 'gpio': 63
             }, {
                 'gpio': 62
             }, {
                 'gpio': 37
             }, {
                 'gpio': 36
             }, {
                 'gpio': 33
             }, {
                 'gpio': 32
             }, {
                 'gpio': 61
             }, {
                 'gpio': 86
             }, {
                 'gpio': 88
             }, {
                 'gpio': 87
             }, {
                 'gpio': 89
             }, {
                 'gpio': 10
             }, {
                 'gpio': 11
             }, {
                 'gpio': 9
             }, {
                 'gpio': 81
             }, {
                 'gpio': 8
             }, {
                 'gpio': 80
             }, {
                 'gpio': 78
             }, {
                 'gpio': 79
             }, {
                 'gpio': 76
             }, {
                 'gpio': 77
             }, {
                 'gpio': 74
             }, {
                 'gpio': 75
             }, {
                 'gpio': 72
             }, {
                 'gpio': 73
             }, {
                 'gpio': 70
             }, {
                 'gpio': 71
             }]
         }]
     else:
         if BOARD_REVISION == 1:
             self.MAPPING = [{
                 'name':
                 'P1',
                 'map': [{
                     'power': 'V33'
                 }, {
                     'power': 'V50'
                 }, {
                     'gpio': 0,
                     'alt0': {
                         'channel': 'sys:i2c',
                         'name': 'SDA'
                     }
                 }, {
                     'power': 'V50'
                 }, {
                     'gpio': 1,
                     'alt0': {
                         'channel': 'sys:i2c',
                         'name': 'SCL'
                     }
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 4,
                     'overlay': {
                         'channel': 'sys:1wire',
                         'name': 'DATA'
                     }
                 }, {
                     'gpio': 14,
                     'alt0': {
                         'channel': 'sys:uart',
                         'name': 'TX'
                     }
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 15,
                     'alt0': {
                         'channel': 'sys:uart',
                         'name': 'RX'
                     }
                 }, {
                     'gpio': 17
                 }, {
                     'gpio': 18
                 }, {
                     'gpio': 21
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 22
                 }, {
                     'gpio': 23
                 }, {
                     'power': 'V33'
                 }, {
                     'gpio': 24
                 }, {
                     'gpio': 10,
                     'alt0': {
                         'channel': 'sys:spi',
                         'name': 'MOSI'
                     }
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 9,
                     'alt0': {
                         'channel': 'sys:spi',
                         'name': 'MISO'
                     }
                 }, {
                     'gpio': 25
                 }, {
                     'gpio': 11,
                     'alt0': {
                         'channel': 'sys:spi',
                         'name': 'SCLK'
                     }
                 }, {
                     'gpio': 8,
                     'alt0': {
                         'channel': 'sys:spi',
                         'name': 'CE0'
                     }
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 7,
                     'alt0': {
                         'channel': 'sys:spi',
                         'name': 'CE1'
                     }
                 }]
             }]
         elif BOARD_REVISION == 2:
             self.MAPPING = [{
                 'name':
                 'P1',
                 'map': [{
                     'power': 'V33'
                 }, {
                     'power': 'V50'
                 }, {
                     'gpio': 2,
                     'alt0': {
                         'channel': 'sys:i2c',
                         'name': 'SDA'
                     }
                 }, {
                     'power': 'V50'
                 }, {
                     'gpio': 3,
                     'alt0': {
                         'channel': 'sys:i2c',
                         'name': 'SCL'
                     }
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 4,
                     'overlay': {
                         'channel': 'sys:1wire',
                         'name': 'DATA'
                     }
                 }, {
                     'gpio': 14,
                     'alt0': {
                         'channel': 'sys:uart',
                         'name': 'TX'
                     }
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 15,
                     'alt0': {
                         'channel': 'sys:uart',
                         'name': 'RX'
                     }
                 }, {
                     'gpio': 17
                 }, {
                     'gpio': 18
                 }, {
                     'gpio': 27
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 22
                 }, {
                     'gpio': 23
                 }, {
                     'power': 'V33'
                 }, {
                     'gpio': 24
                 }, {
                     'gpio': 10,
                     'alt0': {
                         'channel': 'sys:spi',
                         'name': 'MOSI'
                     }
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 9,
                     'alt0': {
                         'channel': 'sys:spi',
                         'name': 'MISO'
                     }
                 }, {
                     'gpio': 25
                 }, {
                     'gpio': 11,
                     'alt0': {
                         'channel': 'sys:spi',
                         'name': 'SCLK'
                     }
                 }, {
                     'gpio': 8,
                     'alt0': {
                         'channel': 'sys:spi',
                         'name': 'CE0'
                     }
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 7,
                     'alt0': {
                         'channel': 'sys:spi',
                         'name': 'CE1'
                     }
                 }]
             }]
         elif BOARD_REVISION == 3:
             self.MAPPING = [{
                 'name':
                 'P1',
                 'map': [{
                     'power': 'V33'
                 }, {
                     'power': 'V50'
                 }, {
                     'gpio': 2,
                     'alt0': {
                         'channel': 'sys:i2c',
                         'name': 'SDA'
                     }
                 }, {
                     'power': 'V50'
                 }, {
                     'gpio': 3,
                     'alt0': {
                         'channel': 'sys:i2c',
                         'name': 'SCL'
                     }
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 4,
                     'overlay': {
                         'channel': 'sys:1wire',
                         'name': 'DATA'
                     }
                 }, {
                     'gpio': 14,
                     'alt0': {
                         'channel': 'sys:uart',
                         'name': 'TX'
                     }
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 15,
                     'alt0': {
                         'channel': 'sys:uart',
                         'name': 'RX'
                     }
                 }, {
                     'gpio': 17
                 }, {
                     'gpio': 18
                 }, {
                     'gpio': 27
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 22
                 }, {
                     'gpio': 23
                 }, {
                     'power': 'V33'
                 }, {
                     'gpio': 24
                 }, {
                     'gpio': 10,
                     'alt0': {
                         'channel': 'sys:spi',
                         'name': 'MOSI'
                     }
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 9,
                     'alt0': {
                         'channel': 'sys:spi',
                         'name': 'MISO'
                     }
                 }, {
                     'gpio': 25
                 }, {
                     'gpio': 11,
                     'alt0': {
                         'channel': 'sys:spi',
                         'name': 'SCLK'
                     }
                 }, {
                     'gpio': 8,
                     'alt0': {
                         'channel': 'sys:spi',
                         'name': 'CE0'
                     }
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 7,
                     'alt0': {
                         'channel': 'sys:spi',
                         'name': 'CE1'
                     }
                 }, {
                     'dnc': True
                 }, {
                     'dnc': True
                 }, {
                     'gpio': 5
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 6
                 }, {
                     'gpio': 12
                 }, {
                     'gpio': 13
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 19
                 }, {
                     'gpio': 16
                 }, {
                     'gpio': 26
                 }, {
                     'gpio': 20
                 }, {
                     'power': 'GND'
                 }, {
                     'gpio': 21
                 }]
             }]
     if isinstance(self.MAPPING, list):
         self.pins = []
         self.overlay_pins = []
         self.spi_pins = []
         self.i2c_pins = []
         self.system_config = SystemConfig.getConfig()
         for header in self.MAPPING:
             self.pins.extend(
                 [pin['gpio'] for pin in header['map'] if 'gpio' in pin])
         try:
             if Hardware().isRaspberryPi():
                 if self.system_config['OneWire'] == 1:
                     self.overlay_pins.extend([
                         pin['gpio'] for pin in header['map']
                         if 'overlay' in pin
                         and pin['overlay']['channel'] == 'sys:1wire'
                     ])
                     self.pins = [
                         pin for pin in self.pins
                         if pin not in self.overlay_pins
                     ]
                 self.spi_pins.extend([
                     pin['gpio'] for pin in header['map'] if 'alt0' in pin
                     and pin['alt0']['channel'] == 'sys:spi'
                 ])
                 self.i2c_pins.extend([
                     pin['gpio'] for pin in header['map'] if 'alt0' in pin
                     and pin['alt0']['channel'] == 'sys:i2c'
                 ])
         except:
             pass