Example #1
0
File: sensor.py Project: xiar/idic
    def execute(self):
        while not self.quit:
            self.condition.acquire()
            try:
                if self.mode == "user":  # user mode
                    self.condition.wait()
                    if self.quit == True:
                        return
                else:
                    #(lnc, unc) = self.get_lnc_unc()
                    if self.mode == "auto":  # auto mode
                        s_value = self.get_random_value()
                    else:  # fault mode
                        s_value = self.get_fault_value()
                        self.mode = "user"

                    if s_value == None:
                        continue

                    self.value = s_value

                    command = "sensor_set_value " + hex(self.mc) + " " \
                        + hex(self.lun) + " " + hex(self.ID) + " " + hex(s_value) + " 0x01\n"
                    common.send_ipmi_sim_command(command)

                    if self.mode == "auto":  # auto mode
                        self.condition.wait(5)
                        if self.quit == True:
                            return
            # we release the lock so that master thread could join us
            # and release the thread resource
            finally:
                self.condition.release()
Example #2
0
    def execute(self):
        while not self.quit:
            self.condition.acquire()
            try:
                if self.mode == "user": # user mode
                    self.condition.wait()
                    if self.quit == True:
                        return
                else:
                    #(lnc, unc) = self.get_lnc_unc()
                    if self.mode == "auto": # auto mode
                        s_value = self.get_random_value()
                    else: # fault mode
                        s_value = self.get_fault_value()
                        self.mode = "user"

                    if s_value == None:
                        continue

                    self.value = s_value

                    command = "sensor_set_value " + hex(self.mc) + " " \
                        + hex(self.lun) + " " + hex(self.ID) + " " + hex(s_value) + " 0x01\n"
                    common.send_ipmi_sim_command(command)

                    if self.mode == "auto": # auto mode
                        self.condition.wait(5)
                        if self.quit == True:
                            return
            # we release the lock so that master thread could join us
            # and release the thread resource
            finally:
                self.condition.release()
Example #3
0
File: sensor.py Project: xiar/idic
    def set_state(self, state_id, state_bit):
        """
        Set disrete sensor's state in id to a certain bit
        :param state_id: 0-14, according to IPMI spec 2.0
        :param state_bit: 1 or 0
        """
        if state_id not in range(0, 15):
            raise ValueError('State id must be in 0-14 according to '
                             'IPMI 2.0 specification')
        if state_bit not in range(0, 2):
            raise ValueError('Bit to set must be 0 or 1')

        value_in_int = int(self.value[4:6] + self.value[2:4], 16)

        if state_bit:
            mask = 1 << state_id
            value_in_int = value_in_int | mask
        else:
            mask = ~(1 << state_id)
            value_in_int = value_in_int & mask

        value_in_hex = hex(value_in_int)[2:].zfill(4)

        self.lock_sensor_write.acquire()
        self.value = "0x" + value_in_hex[2:4] + value_in_hex[0:2]
        command = "sensor_set_bit " + hex(self.mc) + " " + hex(self.lun) \
                  + " " + hex(self.ID) + " " + str(state_id) + " " \
                  + str(state_bit) + " 0x01\n"
        common.send_ipmi_sim_command(command)
        self.lock_sensor_write.release()
Example #4
0
    def set_state(self, state_id, state_bit):
        """
        Set disrete sensor's state in id to a certain bit
        :param state_id: 0-14, according to IPMI spec 2.0
        :param state_bit: 1 or 0
        """
        if state_id not in range(0, 15):
            raise ValueError('State id must be in 0-14 according to '
                             'IPMI 2.0 specification')
        if state_bit not in range(0, 2):
            raise ValueError('Bit to set must be 0 or 1')

        value_in_int = int(self.value[4:6]+self.value[2:4], 16)

        if state_bit:
            mask = 1 << state_id
            value_in_int = value_in_int | mask
        else:
            mask = ~(1 << state_id)
            value_in_int = value_in_int & mask

        value_in_hex = hex(value_in_int)[2:].zfill(4)

        self.lock_sensor_write.acquire()
        self.value = "0x"+value_in_hex[2:4]+value_in_hex[0:2]
        command = "sensor_set_bit " + hex(self.mc) + " " + hex(self.lun) \
                  + " " + hex(self.ID) + " " + str(state_id) + " " \
                  + str(state_bit) + " 0x01\n"
        common.send_ipmi_sim_command(command)
        self.lock_sensor_write.release()
Example #5
0
File: sel.py Project: InfraSIM/idic
    def send_event(self, sel):
        command = 'sel_add ' + hex(self.mc) + ' ' + hex(self.record_type) + ' ' \
                + hex(self.ts_1) + ' ' + hex(self.ts_2) + ' ' + hex(self.ts_3) + ' ' + hex(self.ts_4) + ' ' \
                + hex(self.mfg_id_1) + ' ' + hex(self.mfg_id_2) + ' ' + hex(self.mfg_id_3) + ' ' \
                + ' '.join([hex(x) for x in self.oem_defined]) + '\n'

        common.logger.info(command)
        common.send_ipmi_sim_command(command)
Example #6
0
File: sel.py Project: InfraSIM/idic
 def send_event(self):
     command = 'sel_add ' + hex(self.mc) + ' ' + hex(self.record_type) + ' ' \
           + hex(self.ts_1) + ' ' + hex(self.ts_2) + ' ' + hex(self.ts_3) + ' ' + hex(self.ts_4) + ' ' \
           + hex(self.gid_1) + ' ' + hex(self.gid_2) + ' ' + hex(self.evm_rev) + ' ' \
           + hex(self.sensor_type) + ' ' + hex(self.sensor_num) + ' ' + hex((self.event_dir << 7)| self.event_type) + ' ' \
           + hex(self.event_data_1) + ' ' + hex(self.event_data_2) + ' ' + hex(self.event_data_3) + '\n'
     common.logger.info(command)
     common.send_ipmi_sim_command(command)
Example #7
0
File: sel.py Project: xiar/idic
    def send_event(self, sel):
        command = 'sel_add ' + hex(self.mc) + ' ' + hex(self.record_type) + ' ' \
                + hex(self.ts_1) + ' ' + hex(self.ts_2) + ' ' + hex(self.ts_3) + ' ' + hex(self.ts_4) + ' ' \
                + hex(self.mfg_id_1) + ' ' + hex(self.mfg_id_2) + ' ' + hex(self.mfg_id_3) + ' ' \
                + ' '.join([hex(x) for x in self.oem_defined]) + '\n'

        common.logger.info(command)
        common.send_ipmi_sim_command(command)
Example #8
0
File: sel.py Project: xiar/idic
 def send_event(self):
     command = 'sel_add ' + hex(self.mc) + ' ' + hex(self.record_type) + ' ' \
           + hex(self.ts_1) + ' ' + hex(self.ts_2) + ' ' + hex(self.ts_3) + ' ' + hex(self.ts_4) + ' ' \
           + hex(self.gid_1) + ' ' + hex(self.gid_2) + ' ' + hex(self.evm_rev) + ' ' \
           + hex(self.sensor_type) + ' ' + hex(self.sensor_num) + ' ' + hex((self.event_dir << 7)| self.event_type) + ' ' \
           + hex(self.event_data_1) + ' ' + hex(self.event_data_2) + ' ' + hex(self.event_data_3) + '\n'
     common.logger.info(command)
     common.send_ipmi_sim_command(command)
Example #9
0
File: sensor.py Project: xiar/idic
    def set_discrete_value(self, value):
        """
        Set discrete sensor value
        :param value: in format of 2 byte little endian, e.g. 0xca10
        """
        if len(value) != 6 or not value.startswith('0x'):
            raise ValueError('Discrete sensor value should be in format '
                             'of 2 bytes in little endian, e.g. 0x1ac0')

        # Sensor reading in big endian binary
        # e.g.
        # Original reading is 0xca10 in little endian
        # This value in bin is
        # 0001 0000 1100 1010
        #  1    0    c    a
        # bit 0 > 15
        # bit 0 is reserved, bit 1 is state 14 ... bit 15 is state 0
        value_in_bin = "{0:b}".format(
            int(self.value[4:6] + self.value[2:4], 16)).zfill(16)
        value_to_set = "{0:b}".format(int(value[4:6] + value[2:4],
                                          16)).zfill(16)
        list_diff = []

        for i in range(0, 15):
            state_id = i
            bit_orig = value_in_bin[15 - state_id]
            bit_targ = value_to_set[15 - state_id]
            if bit_orig != bit_targ:
                list_diff.append((state_id, int(bit_targ)))

        self.lock_sensor_write.acquire()
        self.value = value
        for diff in list_diff:
            command = "sensor_set_bit " + hex(self.mc) + " " + hex(self.lun) \
                      + " " + hex(self.ID) + " " + str(diff[0]) + " " \
                      + str(diff[1]) + " 0x01\n"
            common.send_ipmi_sim_command(command)
        self.lock_sensor_write.release()
Example #10
0
    def set_discrete_value(self, value):
        """
        Set discrete sensor value
        :param value: in format of 2 byte little endian, e.g. 0xca10
        """
        if len(value) != 6 or not value.startswith('0x'):
            raise ValueError('Discrete sensor value should be in format '
                             'of 2 bytes in little endian, e.g. 0x1ac0')

        # Sensor reading in big endian binary
        # e.g.
        # Original reading is 0xca10 in little endian
        # This value in bin is
        # 0001 0000 1100 1010
        #  1    0    c    a
        # bit 0 > 15
        # bit 0 is reserved, bit 1 is state 14 ... bit 15 is state 0
        value_in_bin = "{0:b}".format(int(self.value[4:6]+self.value[2:4], 16)).zfill(16)
        value_to_set = "{0:b}".format(int(value[4:6]+value[2:4], 16)).zfill(16)
        list_diff = []

        for i in range(0, 15):
            state_id = i
            bit_orig = value_in_bin[15-state_id]
            bit_targ = value_to_set[15-state_id]
            if bit_orig != bit_targ:
                list_diff.append((state_id, int(bit_targ)))

        self.lock_sensor_write.acquire()
        self.value = value
        for diff in list_diff:
            command = "sensor_set_bit " + hex(self.mc) + " " + hex(self.lun) \
                      + " " + hex(self.ID) + " " + str(diff[0]) + " " \
                      + str(diff[1]) + " 0x01\n"
            common.send_ipmi_sim_command(command)
        self.lock_sensor_write.release()
Example #11
0
File: sensor.py Project: xiar/idic
 def set_threshold_value(self, value):
     self.value = value
     command = "sensor_set_value " + hex(self.mc) + " " \
           + hex(self.lun) + " " + hex(self.ID) + " " + hex(value) + " 0x01\n"
     common.send_ipmi_sim_command(command)
Example #12
0
 def set_threshold_value(self, value):
     self.value = value
     command = "sensor_set_value " + hex(self.mc) + " " \
           + hex(self.lun) + " " + hex(self.ID) + " " + hex(value) + " 0x01\n"
     common.send_ipmi_sim_command(command)