Example #1
0
class Switch(BaseSwitch):
    """
    This class wrapped opiom command to emulate a switch
    the configuration may look like this:
    opiom: $opiom_name
    register: IMA
    mask: 0x3
    shift: 1
    states:
       - label: OPEN
         value: 1
       - label: CLOSED
         value: 0
       - label: MUSST
         value: 2
       - label: COUNTER_CARD
         value: 3
    """
    def __init__(self, name, config):
        BaseSwitch.__init__(self, name, config)
        self.__opiom = None
        self.__register = None
        self.__mask = None
        self.__shift = None
        self.__states = OrderedDict() if OrderedDict else dict()

    def _init(self):
        config = self.config
        self.__opiom = config['opiom']
        self.__register = config['register']
        self.__mask = config['mask']
        self.__shift = config['shift']
        for state in config['states']:
            label = state['label']
            value = state['value']
            self.__states[label] = value

    def _set(self, state):
        value = self.__states.get(state)
        if value is None:
            raise RuntimeError("State %s don't exist" % state)
        mask = self.__mask << self.__shift
        value <<= self.__shift
        cmd = '%s 0x%x 0x%x' % (self.__register, value, mask)
        self.__opiom.comm_ack(cmd)

    def _get(self):
        cmd = '?%s' % self.__register
        value = int(self.__opiom.comm_ack(cmd), base=16)
        value >>= self.__shift
        value &= self.__mask
        for label, state_value in self.__states.iteritems():
            if state_value == value:
                return label
        return 'UNKNOWN'

    def _states_list(self):
        return self.__states.keys()
Example #2
0
class Switch(BaseSwitch):
    """
    This class wrapped opiom command to emulate a switch
    the configuration may look like this:
    opiom: $opiom_name
    register: IMA
    mask: 0x3
    shift: 1
    states:
       - label: OPEN
         value: 1
       - label: CLOSED
         value: 0
       - label: MUSST
         value: 2
       - label: COUNTER_CARD
         value: 3
    """
    def __init__(self,name,config):
        BaseSwitch.__init__(self,name,config)
        self.__opiom = None
        self.__register = None
        self.__mask = None
        self.__shift = None
        self.__states = OrderedDict() if OrderedDict else dict()

    def _init(self):
        config = self.config
        self.__opiom = config['opiom']
        self.__register = config['register']
        self.__mask = config['mask']
        self.__shift = config['shift']
        for state in config['states']:
            label = state['label']
            value = state['value']
            self.__states[label] = value

    def _set(self,state):
        value = self.__states.get(state)
        if value is None:
            raise RuntimeError("State %s don't exist" % state)
        mask = self.__mask << self.__shift
        value <<= self.__shift
        cmd = '%s 0x%x 0x%x' % (self.__register,value,mask)
        self.__opiom.comm_ack(cmd)

    def _get(self):
        cmd = '?%s' % self.__register
        value = int(self.__opiom.comm_ack(cmd),base=16)
        value >>= self.__shift
        value &= self.__mask
        for label,state_value in self.__states.iteritems():
            if state_value == value:
                return label
        return 'UNKNOWN'

    def _states_list(self):
        return self.__states.keys()
Example #3
0
class Switch(BaseSwitch):
    """
    This class wrapped musst command to emulate a switch.
    the configuration may look like this:
    musst: $musst_name
    states:
       - label: OPEN
         set_cmd: "#BTRIG 1"
         test_cmd: "?BTRIG"
         test_cmd_reply: "1"
       - label: CLOSED
         set_cmd: "#BTRIG 0"
         test_cmd: "?BTRIG"
         test_cmd_reply: "0"
    """
    def __init__(self, name, config):
        BaseSwitch.__init__(self, name, config)
        self.__musst = None
        self.__states = OrderedDict()
        self.__state_test = OrderedDict()

    def _init(self):
        config = self.config
        self.__musst = config['musst']
        for state in config['states']:
            label = state['label']
            cmd = state['set_cmd']
            self.__states[label] = cmd

            t1 = {config['test_cmd_reply']: label}
            t = self.__state_test.setdefault(config['test_cmd'], result)
            if t1 != t:
                t.update(t1)

    def _set(self, state):
        cmd = self.__states.get(state)
        if cmd is None:
            raise RuntimeError("State %s don't exist" % state)
        self.__musst.putget(cmd)

    def _get(self):
        for test_cmd, test_reply in self.__state_test.iteritems():
            reply = self.__musst.putget(test_cmd)
            state = test_reply.get(reply)
            if state is not None:
                return state
        return 'UNKNOWN'

    def _states_list(self):
        return self.__states.keys()
Example #4
0
class Switch(BaseSwitch):
    """
    This class wrapped musst command to emulate a switch.
    the configuration may look like this:
    musst: $musst_name
    states:
       - label: OPEN
         set_cmd: "#BTRIG 1"
         test_cmd: "?BTRIG"
         test_cmd_reply: "1"
       - label: CLOSED
         set_cmd: "#BTRIG 0"
         test_cmd: "?BTRIG"
         test_cmd_reply: "0"
    """
    def __init__(self,name,config):
        BaseSwitch.__init__(self,name,config)
        self.__musst = None
        self.__states = OrderedDict()
        self.__state_test = OrderedDict()

    def _init(self):
        config = self.config
        self.__musst = config['musst']
        for state in config['states']:
            label = state['label']
            cmd = state['set_cmd']
            self.__states[label] = cmd

            t1 = {config['test_cmd_reply'] : label}
            t = self.__state_test.setdefault(config['test_cmd'],result)
            if t1 != t:
                t.update(t1)

    def _set(self,state):
        cmd = self.__states.get(state)
        if cmd is None:
            raise RuntimeError("State %s don't exist" % state)
        self.__musst.putget(cmd)

    def _get(self):
        for test_cmd,test_reply in self.__state_test.iteritems():
            reply = self.__musst.putget(test_cmd)
            state = test_reply.get(reply)
            if state is not None:
                return state
        return 'UNKNOWN'

    def _states_list(self):
        return self.__states.keys()
Example #5
0
    def get_values(self, from_index, *counters):
        roi_counter_size = len(RoiStat)
        raw_data = self.controller._proxy.readCounters(from_index)
        if not raw_data.size:
            return len(counters)*(numpy.array(()),)
        raw_data.shape = (raw_data.size) / roi_counter_size, roi_counter_size
        result = OrderedDict([int(counter), []] for counter in counters)

        for roi_counter in raw_data:
            roi_id = int(roi_counter[0])
            for stat in range(roi_counter_size):
                full_id = RoiStatCounter.roi_stat_id(roi_id, stat)
                counter_data = result.get(full_id)
                if counter_data is not None:
                    counter_data.append(roi_counter[stat])
        return map(numpy.array, result.values())
Example #6
0
    def get_values(self, from_index, *counters):
        roi_counter_size = len(RoiStat)
        raw_data = self.controller._proxy.readCounters(from_index)
        if not raw_data.size:
            return len(counters) * (numpy.array(()), )
        raw_data.shape = (raw_data.size) / roi_counter_size, roi_counter_size
        result = OrderedDict([int(counter), []] for counter in counters)

        for roi_counter in raw_data:
            roi_id = int(roi_counter[0])
            for stat in range(roi_counter_size):
                full_id = RoiStatCounter.roi_stat_id(roi_id, stat)
                counter_data = result.get(full_id)
                if counter_data is not None:
                    counter_data.append(roi_counter[stat])
        return map(numpy.array, result.values())