def ProcessConfigCommand(self, message): """Process system configuration command Returns: True if command was processed, False otherwise.""" error = None try: value = 1 - int( message['payload'] ) #Invert the value since the config script uses 0 for enable and 1 for disable command_id = { cayennemqtt.SYS_I2C: 11, cayennemqtt.SYS_SPI: 12, cayennemqtt.SYS_UART: 13, cayennemqtt.SYS_ONEWIRE: 19 } result, output = SystemConfig.ExecuteConfigCommand( command_id[message['channel']], value) debug('ProcessConfigCommand: {}, result: {}, output: {}'.format( message, result, output)) if result != 0: error = 'Error executing config command' except Exception as ex: error = '{}: {}'.format(type(ex).__name__, ex) self.EnqueueCommandResponse(message, error) return error == None
def SendSystemInfo(self): """Enqueue a packet containing system info to send to the server""" try: currentSystemInfo = [] cayennemqtt.DataChannel.add(currentSystemInfo, cayennemqtt.SYS_OS_NAME, value=self.oSInfo.ID) cayennemqtt.DataChannel.add(currentSystemInfo, cayennemqtt.SYS_OS_VERSION, value=self.oSInfo.VERSION_ID) cayennemqtt.DataChannel.add(currentSystemInfo, cayennemqtt.AGENT_VERSION, value=self.config.get( 'Agent', 'Version', __version__)) cayennemqtt.DataChannel.add(currentSystemInfo, cayennemqtt.SYS_POWER_RESET, value=0) cayennemqtt.DataChannel.add(currentSystemInfo, cayennemqtt.SYS_POWER_HALT, value=0) config = SystemConfig.getConfig() if config: channel_map = { 'I2C': cayennemqtt.SYS_I2C, 'SPI': cayennemqtt.SYS_SPI, 'Serial': cayennemqtt.SYS_UART, 'OneWire': cayennemqtt.SYS_ONEWIRE, 'DeviceTree': cayennemqtt.SYS_DEVICETREE } for key, channel in channel_map.items(): try: cayennemqtt.DataChannel.add(currentSystemInfo, channel, value=config[key]) except: pass if currentSystemInfo != self.systemInfo: data = currentSystemInfo if self.systemInfo: data = [x for x in data if x not in self.systemInfo] if data: self.systemInfo = currentSystemInfo info('Send system info: {}'.format([{ item['channel']: item['value'] } for item in data])) self.EnqueuePacket(data) except Exception: exception('SendSystemInfo unexpected error')
def wildcard(self, compact=False): if gpio_library and os.geteuid() != 0: #If not root on an ASUS device get the pin states as root value, err = executeCommand('sudo python3 -m myDevices.devices.readvalue --pins') value = value.splitlines()[0] import json return json.loads(value) if compact: f = "f" v = "v" else: f = "function" v = "value" values = {} self.system_config = SystemConfig.getConfig() for i in self.pins + self.overlay_pins: if compact: func = self.getFunction(i) else: func = self.getFunctionString(i) values[i] = {f: func, v: int(self.__digitalRead__(i))} return values
def testSystemConfig(self): config = SystemConfig.getConfig() info(config) if config: for item in ('DeviceTree', 'Serial', 'I2C', 'SPI', 'OneWire'): self.assertIn(item, config)
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