Ejemplo n.º 1
0
class EmbeddedEngine(Thread):
    def __init__(self, publisher=None, stop_on_fail=False):
        super(EmbeddedEngine, self).__init__()

        if publisher:
            self.transport = publisher
        else:
            ctx = zmq.Context()
            self.transport = ZmqServerTransport.create(ctx, 'tcp://*:22700')

        self.dispatcher = EEDispatcher(self.transport)
        self.dispatcher.register_public_methods()

        #give the publisher sometime
        time.sleep(1)

        self.rpc_server = RPCServer(
            self.transport,
            JSONRPCProtocol(),
            self.dispatcher,
        )

    def add_methods(self):
        self.dispatcher.register_public_methods()

    def run(self):
        logger.boot('embedded engine starting')
        while True:
            try:
                self.rpc_server.serve_forever()
            except Exception:
                logger.warning("rpc server exception: %s" %
                               (traceback.format_exc()))

        logger.info("embedded engine stopping")
Ejemplo n.º 2
0
    def __init__(self, publisher=None, stop_on_fail=False):
        super(EmbeddedEngine, self).__init__()

        if publisher:
            self.transport = publisher
        else:
            ctx = zmq.Context()
            self.transport = ZmqServerTransport.create(ctx, 'tcp://*:22700')

        self.dispatcher = EEDispatcher(self.transport)
        self.dispatcher.register_public_methods()

        #give the publisher sometime
        time.sleep(1)

        self.rpc_server = RPCServer(
            self.transport,
            JSONRPCProtocol(),
            self.dispatcher,
        )
Ejemplo n.º 3
0
        return bus.rdwr(dev_addr, write_data, read_length)
    except Exception as e:
        logger.error("execute module i2c rdwr False:" + repr(e))
        return False


def i2c_config(bus_id, rate):
    logger.debug("bus:%s, rate:%s" % (bus_id, rate))
    """ 
        Args:
            bus_id: str type, i2c bus id.
            rate: int type.

        Returns:
            return None

    """
    try:
        profile = Profile.get_bus_by_name(bus_id)
        bus = I2cBus(profile["path"])
        return bus.config(rate)
    except Exception as e:
        logger.error("execute module i2c config False:" + repr(e))
        return False


EEDispatcher.register_method(i2c_write)
EEDispatcher.register_method(i2c_read)
EEDispatcher.register_method(i2c_rdwr)
EEDispatcher.register_method(i2c_config)
Ejemplo n.º 4
0
        result = Eeprom.write(profile, addr, data)
    except Exception as e:
        logger.error("execute module  eeprom_write  False:" + repr(e))
        return False
    return result


def eeprom_read(module_name, addr, length):
    """ read   data  by  the defined profile
        
        Args:
            module_name: the key of Dictionary which can get the hardware profile.for example: "dmm-module-1"
            addr:  read data from this addr.
            length: read data length.
            
        Returns:
            list: success  return data which beed  saved in a list. False otherwise.
            
    """
    try:
        profile = Profile.get_eeprom_by_name(module_name)
        result = Eeprom.read(profile, addr, length)
    except Exception as e:
        logger.error("execute module  eeprom_read  False:" + repr(e))
        return False
    return result


EEDispatcher.register_method(eeprom_write)
EEDispatcher.register_method(eeprom_read)
Ejemplo n.º 5
0
        bus = SpiSlaveFactory.create_object(SpiSlaveFactory, profile["path"])
        return bus.config(spi_clk_cpha_cpol, spi_byte_cfg)
    except Exception as e:
        logger.error("execute module spi_slave_config False:" + repr(e))
        return False

def spi_slave_disable(bus_name):
    logger.debug("spi slave disable -->bus name:%s "%(bus_name))
    try:
        profile = Profile.get_bus_by_name(bus_name)
        bus = SpiSlaveFactory.create_object(SpiSlaveFactory, profile["path"])
        return bus.disable()
    except Exception as e:
        logger.error("execute module spi_slave_disable False:" + repr(e))
        return False

def spi_slave_enable(bus_name):
    logger.debug("spi slave enable -->bus name:%s "%(bus_name))
    try:
        profile = Profile.get_bus_by_name(bus_name)
        bus = SpiSlaveFactory.create_object(SpiSlaveFactory, profile["path"])
        return bus.enable()
    except Exception as e:
        logger.error("execute module spi_slave_enable False:" + repr(e))
        return False

EEDispatcher.register_method(spi_slave_read)
EEDispatcher.register_method(spi_slave_write)
EEDispatcher.register_method(spi_slave_config)
EEDispatcher.register_method(spi_slave_disable)
EEDispatcher.register_method(spi_slave_enable)
Ejemplo n.º 6
0

def calibration_work_mode_close(name):
    """The board work in normal mode,out of the calibration mode
        
        You need to out of the calibration mode,
        when you want to the result use the calibration parameters.
        The measure results of the return after calibration.

        Args:
            name: the dmm board's name
        Returns:
            bool: True | False, True for success, False for adc read failed
    """
    try:
        dmm = XObject.get_board_object(name)
        dmm.calibration_work_mode_close()
        return True
    except Exception as e:
        logger.error(
            "the %s board calibration_work_mode_close() execute error: %s" %
            (name, repr(e)))
        return False


EEDispatcher.register_method(voltage_measure)
EEDispatcher.register_method(current_measure)
EEDispatcher.register_method(measure_path_set)
EEDispatcher.register_method(measure_path_get)
EEDispatcher.register_method(measure_path_record)
Ejemplo n.º 7
0
               
        Returns:
            dict type: {"cpX": Y}, "cpX": Y, "cpX": False...}
            X:[1- ]
            Y: 16bit: [0x0000 - 0xffff]
                 24bit:[0x000000 - 0xffffff]
            
            eg: cp5 read false returns: {"cp5": False,} 
    """
    chip_state_dict = OrderedDict()

    ioprofile = Profile.get_extendio_by_name(board_name)
    for name in chipname:
        try:
            chip_state_dict[name] = Extendio.chip_dir_get(ioprofile, name)
        except Exception as e:
            logger.error("execute module io io_chip_dir_get  False:" + repr(e))
            chip_state_dict[name] = False

    return chip_state_dict


EEDispatcher.register_method(io_set)
EEDispatcher.register_method(io_get)
EEDispatcher.register_method(io_dir_set)
EEDispatcher.register_method(io_dir_get)
EEDispatcher.register_method(io_chip_set)
EEDispatcher.register_method(io_chip_get)
EEDispatcher.register_method(io_chip_dir_set)
EEDispatcher.register_method(io_chip_dir_get)
Ejemplo n.º 8
0

def spi_disable(bus_name):
    logger.warning("spi disable -->bus name:%s " % (bus_name))
    try:
        profile = Profile.get_bus_by_name(bus_name)
        bus = SpiFactory.create_object(SpiFactory, profile["path"])
        return bus.disable()
    except Exception as e:
        logger.error("execute module spi_disable False:" + repr(e))
        return False


def spi_enable(bus_name):
    logger.warning("spi enable -->bus name:%s " % (bus_name))
    try:
        profile = Profile.get_bus_by_name(bus_name)
        bus = SpiFactory.create_object(SpiFactory, profile["path"])
        return bus.enable()
    except Exception as e:
        logger.error("execute module spi_enable False:" + repr(e))
        return False


EEDispatcher.register_method(spi_read)
EEDispatcher.register_method(spi_write)
EEDispatcher.register_method(spi_write_and_read)
EEDispatcher.register_method(spi_write_to_read)
EEDispatcher.register_method(spi_config)
EEDispatcher.register_method(spi_disable)
EEDispatcher.register_method(spi_enable)
Ejemplo n.º 9
0

def swd_disable(bus_name):
    logger.warning("swd disable -->bus name:%s " % (bus_name))
    try:
        profile = Profile.get_bus_by_name(bus_name)
        bus = SwdFactory.create_object(SwdFactory, profile["path"])
        return bus.disable()
    except Exception as e:
        logger.error("execute module swd_disable False:" + repr(e))
        return False


def swd_enable(bus_name):
    logger.warning("swd enable -->bus name:%s " % (bus_name))
    try:
        profile = Profile.get_bus_by_name(bus_name)
        bus = SwdFactory.create_object(SwdFactory, profile["path"])
        return bus.enable()
    except Exception as e:
        logger.error("execute module swd_enable False:" + repr(e))
        return False


EEDispatcher.register_method(swd_write)
EEDispatcher.register_method(swd_read)
EEDispatcher.register_method(swd_freq_set)
EEDispatcher.register_method(swd_rst_set)
EEDispatcher.register_method(swd_timing_generate)
EEDispatcher.register_method(swd_disable)
EEDispatcher.register_method(swd_enable)
Ejemplo n.º 10
0
            Returns:
                a dict of the initconfig
        '''
        return cls._initconfig
    
    @classmethod
    def get_ioes(cls):
        '''get all the ioes profile

            Returns:
                a dict of all ioes profile
        '''
        return cls._ioes

EEDispatcher.register_method(Profile.get_extendio)
EEDispatcher.register_method(Profile.get_extendio_by_name)
EEDispatcher.register_method(Profile.get_extendio_chip_name)
EEDispatcher.register_method(Profile.get_busswitch)
EEDispatcher.register_method(Profile.get_busswitch_by_name)
EEDispatcher.register_method(Profile.get_eeprom)
EEDispatcher.register_method(Profile.get_eeprom_by_name)
EEDispatcher.register_method(Profile.get_boards)
EEDispatcher.register_method(Profile.get_board_by_name)
EEDispatcher.register_method(Profile.get_buses)
EEDispatcher.register_method(Profile.get_bus_by_name)
EEDispatcher.register_method(Profile.get_bus_path)
EEDispatcher.register_method(Profile.get_chips)
EEDispatcher.register_method(Profile.get_chip_by_name)
EEDispatcher.register_method(Profile.get_initconfig)
EEDispatcher.register_method(Profile.get_ioes)
Ejemplo n.º 11
0
        isok = True
        if utility.mount_on_fpga(uart.name):
            uart.disable()
            uart.enable()
            uart.config(baud_rate, data_bits, parity, stop_bits, timestamp)
        else:
            isok = uart.config(baud_rate, data_bits, parity, stop_bits)

        return isok
    except Exception as e:
        logger.error("the %s uart param config execute error:%s" %
                     (name, repr(e)))
        return False


def uart_close(uart_id):
    try:
        uart = XObject.get_object(uart_id)
        if utility.mount_on_fpga(uart.name):
            uart.disable()
        else:
            uart.close()

        return True
    except Exception as e:
        logger.error("close  the %s uart error:%s" % (uart_id, repr(e)))
        return False


EEDispatcher.register_method(uart_param_config)
EEDispatcher.register_method(uart_close)