Beispiel #1
0
    def from_response(self, data):
        if len(data) != 16:
            raise DecodingError('Invalid SEL record length (%d)' % len(data))

        self.data = data

        # pop will change data, therefore copy it
        buffer = ByteBuffer(data)

        self.record_id = buffer.pop_unsigned_int(2)
        self.type = buffer.pop_unsigned_int(1)
        if (self.type != self.TYPE_SYSTEM_EVENT
                and self.type not in self.TYPE_OEM_TIMESTAMPED_RANGE
                and self.type not in self.TYPE_OEM_NON_TIMESTAMPED_RANGE):
            raise DecodingError('Unknown SEL type (0x%02x)' % self.type)
        self.timestamp = buffer.pop_unsigned_int(4)
        self.generator_id = buffer.pop_unsigned_int(2)
        self.evm_rev = buffer.pop_unsigned_int(1)
        self.sensor_type = buffer.pop_unsigned_int(1)
        self.sensor_number = buffer.pop_unsigned_int(1)
        event_desc = buffer.pop_unsigned_int(1)
        if event_desc & 0x80:
            self.event_direction = EVENT_DEASSERTION
        else:
            self.event_direction = EVENT_ASSERTION
        self.event_type = event_desc & 0x3f
        self.event_data = buffer.pop_string(3)
Beispiel #2
0
 def from_data(self, data):
     self.format_version = ord(data[0]) & 0x0f
     if self.format_version != 1:
         raise DecodingError('unsupported format version (%d)' %
                             self.format_version)
     self.length = ord(data[1]) * 8
     if sum([ord(c) for c in data[:self.length]]) % 256 != 0:
         raise DecodingError('checksum failed')
Beispiel #3
0
 def from_data(self, data):
     if len(data) != 8:
         raise DecodingError('InventoryCommonHeader length != 8')
     self.format_version = ord(data[0]) & 0x0f
     self.internal_use_area_offset = ord(data[1]) * 8 or None
     self.chassis_info_area_offset = ord(data[2]) * 8 or None
     self.board_info_area_offset = ord(data[3]) * 8 or None
     self.product_info_area_offset = ord(data[4]) * 8 or None
     self.multirecord_area_offset = ord(data[5]) * 8 or None
     if sum([ord(c) for c in data]) % 256 != 0:
         raise DecodingError('InventoryCommonHeader checksum failed')
Beispiel #4
0
 def from_data(self, data):
     if len(data) < 5:
         raise DecodingError('data too short')
     self.record_type_id = ord(data[0])
     self.format_version = ord(data[1]) & 0x0f
     self.end_of_list = bool(ord(data[1]) & 0x80)
     self.length = ord(data[2])
     if sum([ord(c) for c in data[:5]]) % 256 != 0:
         raise DecodingError('FruDataMultiRecord header checksum failed')
     self.raw = data[5:5 + self.length]
     if (sum([ord(c) for c in self.raw]) + ord(data[3])) % 256 != 0:
         raise DecodingError('FruDataMultiRecord record checksum failed')
Beispiel #5
0
 def from_data(self, data):
     if len(data) < 10:
         raise DecodingError('data too short')
     FruDataMultiRecord.from_data(self, data)
     self.manufacturer_id = ord(
         data[5]) | ord(data[6]) << 8 | ord(data[7]) << 16
     self.picmg_record_type_id = ord(data[8])
     self.format_version = ord(data[9])
Beispiel #6
0
 def decode(self, obj, data):
     value = 0
     for i in xrange(self.length):
         try:
             value |= data.pop_unsigned_int(1) << (8 * i)
         except IndexError:
             raise DecodingError('Data too short for message')
     wrapper = getattr(obj, self.name)
     wrapper._value = value
Beispiel #7
0
    def from_response(self, data):
        if len(data) < 5:
            raise DecodingError('Invalid SDR length (%d)' % len(data))

        self.data = data
        buffer = ByteBuffer(data[:])
        self.id = buffer.pop_unsigned_int(2)
        self.version = buffer.pop_unsigned_int(1)
        self.type = buffer.pop_unsigned_int(1)
        self.lenght = buffer.pop_unsigned_int(1)
Beispiel #8
0
def create_sdr(data, next_id=None):
    sdr_type = data[3]

    if sdr_type == SDR_TYPE_FULL_SENSOR_RECORD:
        return SdrFullSensorRecord(data, next_id)
    elif sdr_type == SDR_TYPE_COMPACT_SENSOR_RECORD:
        return SdrCompactSensorRecord(data, next_id)
    elif sdr_type == SDR_TYPE_EVENT_ONLY_SENSOR_RECORD:
        return SdrEventOnlySensorRecord(data, next_id)
    elif sdr_type == SDR_TYPE_FRU_DEVICE_LOCATOR_RECORD:
        return SdrFruDeviceLocator(data, next_id)
    elif sdr_type == SDR_TYPE_MANAGEMENT_CONTROLLER_DEVICE_LOCATOR_RECORD:
        return SdrManagementContollerDeviceLocator(data, next_id)
    elif sdr_type == SDR_TYPE_MANAGEMENT_CONTROLLER_CONFIRMATION_RECORD:
        raise DecodingError('Unsupported SDR type(0x%02x)' % sdr_type)
    elif sdr_type == SDR_TYPE_BMC_MESSAGE_CHANNEL_INFO_RECORD:
        raise DecodingError('Unsupported SDR type(0x%02x)' % sdr_type)
    else:
        raise DecodingError('Unsupported SDR type(0x%02x)' % sdr_type)
Beispiel #9
0
    def from_response(self, res):
        self.local_state_available = bool(res.led_states.local_avail)
        self.override_enabled = bool(res.led_states.override_en)
        self.lamp_test_enabled = bool(res.led_states.lamp_test_en)

        if res.local_function == picmg.LED_FUNCTION_OFF:
            self.local_function = self.FUNCTION_OFF
        elif res.local_function == picmg.LED_FUNCTION_ON:
            self.local_function = self.FUNCTION_ON
        elif res.local_function in picmg.LED_FUNCTION_BLINKING_RANGE:
            self.local_function = self.FUNCTION_BLINKING
            self.local_off_duration = res.local_function * 10
            if res.local_on_duration not in picmg.LED_FUNCTION_BLINKING_RANGE:
                raise DecodingError()
            self.local_on_duration = res.local_on_duration * 10
        else:
            raise DecodingError()

        self.local_color = res.local_color

        if self.override_enabled:
            if res.override_function == picmg.LED_FUNCTION_OFF:
                self.override_function = self.FUNCTION_OFF
            elif res.override_function == picmg.LED_FUNCTION_ON:
                self.override_function = self.FUNCTION_ON
            elif res.override_function in picmg.LED_FUNCTION_BLINKING_RANGE:
                self.override_function = self.FUNCTION_BLINKING
                self.override_off_duration = res.local_function * 10
            else:
                raise DecodingError()

            self.override_off_duration = res.override_on_duration * 10
            self.override_color = res.override_color

        if self.lamp_test_enabled:
            self.lamp_test_duration = res.lamp_test_duration * 100
Beispiel #10
0
class Message:
    RESERVED_FIELD_NAMES = ['cmdid', 'netfn', 'lun']

    def __init__(self, *args, **kwargs):
        """Message constructor with ([buf], [field=val,...]) prototype.

        Arguments:

        buf -- option message buffer to decode

        Optional keyword arguments corresponts to members to set (matching
        fields in self.__fields__, or 'data').
        """

        # create message fields
        if hasattr(self, '__fields__'):
            self._create_fields()

        # set default lun
        self.lun = self.__default_lun__

        self.data = ''
        if args:
            self._decode(args[0])
        else:
            for (name, value) in kwargs.iteritems():
                self._set_field(name, value)

    def _set_field(self, name, value):
        raise NotImplementedError()
        # TODO walk along the properties..
        setattr(self, name, value)

    def _create_fields(self):
        for field in self.__fields__:
            if field.name in self.RESERVED_FIELD_NAMES:
                raise DescriptionError('Field name "%s" is reserved' %
                                       field.name)
            if hasattr(self, field.name):
                raise DescriptionError('Field "%s" already added', field.name)
            setattr(self, field.name, field.create())

    def _encode(self):
        if not hasattr(self, '__fields__'):
            raise NotImplementedError('You have to overwrite this method')

        data = ByteBuffer()
        for field in self.__fields__:
            field.encode(self, data)
        return data.to_string()

    def _decode(self, data):
        if not hasattr(self, '__fields__'):
            raise NotImplementedError('You have to overwrite this method')

        data = ByteBuffer(data)
        cc = None
        for field in self.__fields__:
            try:
                field.decode(self, data)
            except CompletionCodeError, e:
                # stop decoding on completion code != 0
                cc = e.cc
                break

        if (cc == None or cc == 0) and len(data) > 0:
            raise DecodingError('Data has extra bytes')
Beispiel #11
0
 def from_data(self, data):
     if len(data) < 12:
         raise DecodingError('data too short')
     FruPicmgRecord.from_data(self, data)
     maximum_current_output = ord(data[10]) | ord(data[11]) << 8
     self.maximum_current_output = float(maximum_current_output / 10)
Beispiel #12
0
def test_DecodingError():
    raise DecodingError()