# Path: pyipmi/msgs/registry.py
# def create_request_by_name(self, name, *args, **kwargs):
#     return self.registry[name + "Req"](*args, **kwargs)
# 
# Path: pyipmi/utils.py
# def check_completion_code(cc):
#     if cc != constants.CC_OK:
#         raise CompletionCodeError(cc)
# 
# Path: pyipmi/state.py
# class State(DefaultProperties, ResponseDecoder):
#     """This is a container that represents a state.
# 
#     The state can have default
#     properties that are created by init.
#     """
# 
#     def __init__(self, rsp=None):
#         DefaultProperties.__init__(self)
#         ResponseDecoder.__init__(self, rsp)
# 
# Path: pyipmi/fields.py
# class VersionField(object):
#     """This class represent the Version fields defines by IPMI.
# 
#     Introduced with HPM the version field can hold additional auxiliary bytes.
#     """
# 
#     VERSION_FIELD_LEN = 2
#     VERSION_WITH_AUX_FIELD_LEN = 6
# 
#     def __init__(self, data=None):
#         self.major = None
#         self.minor = None
#         if data:
#             self._from_data(data)
# 
#     def _from_data(self, data):
#         if isinstance(data, str):
#             data = [ord(c) for c in data]
# 
#         data = array.array('B', data)
#         self.version = self._decode_data(data[0:2])
#         if len(data) == self.VERSION_WITH_AUX_FIELD_LEN:
#             self.auxiliary = data[2:6]
# 
#     def __str__(self):
#         return self.version_to_string()
# 
#     def _decode_data(self, data):
#         """`data` is array.array."""
#         self.major = data[0]
# 
#         if data[1] == 0xff:
#             self.minor = data[1]
#         elif data[1] <= 0x99:
#             self.minor = int(py3_array_tobytes(data[1:2]).decode('bcd+'))
#         else:
#             raise DecodingError()
# 
#     def version_to_string(self):
#         return ''.join("%s.%s" % (self.major, self.minor))


from .msgs import create_request_by_name
from .utils import check_completion_code
from .state import State
from .fields import VersionField
        req.bus_id.id = bus_id
        req.bus_id.channel = channel
        req.bus_id.slave_address = address
        req.read_count = count
        if data:
            req.data = data
        rsp = self.send_message(req)
        check_completion_code(rsp.completion_code)
        return rsp.data

    def i2c_write(self, bus_type, bus_id, channel, address, data):
        self.i2c_write_read(bus_type, bus_id, channel, address, 0, data)

    def i2c_read(self, bus_type, bus_id, channel, address, count):
        return self.i2c_write_read(bus_type, bus_id, channel,
                                   address, count, None)

    def set_watchdog_timer(self, config):
        req = create_request_by_name('SetWatchdogTimer')
        req.timer_use.timer_use = config.timer_use
        req.timer_use.dont_stop = config.dont_stop and 1 or 0
        req.timer_use.dont_log = config.dont_log and 1 or 0

        req.timer_actions.pre_timeout_interrupt = config.pre_timeout_interrupt
        req.timer_actions.timeout_action = config.timeout_action

        req.pre_timeout_interval = config.pre_timeout_interval
        req.timer_use_expiration_flags = config.timer_use_expiration_flags
        req.initial_countdown = config.initial_countdown
        rsp = self.send_message(req)

# Path: pyipmi/msgs/registry.py
# def create_request_by_name(self, name, *args, **kwargs):
#     return self.registry[name + "Req"](*args, **kwargs)
# 
# Path: pyipmi/utils.py
# def check_completion_code(cc):
#     if cc != constants.CC_OK:
#         raise CompletionCodeError(cc)
# 
# Path: pyipmi/state.py
# class State(DefaultProperties, ResponseDecoder):
#     """This is a container that represents a state.
# 
#     The state can have default
#     properties that are created by init.
#     """
# 
#     def __init__(self, rsp=None):
#         DefaultProperties.__init__(self)
#         ResponseDecoder.__init__(self, rsp)
# 
# Path: pyipmi/fields.py
# class VersionField(object):
#     """This class represent the Version fields defines by IPMI.
# 
#     Introduced with HPM the version field can hold additional auxiliary bytes.
#     """
# 
#     VERSION_FIELD_LEN = 2
#     VERSION_WITH_AUX_FIELD_LEN = 6
# 
#     def __init__(self, data=None):
#         self.major = None
#         self.minor = None
#         if data:
#             self._from_data(data)
# 
#     def _from_data(self, data):
#         if isinstance(data, str):
#             data = [ord(c) for c in data]
# 
#         data = array.array('B', data)
#         self.version = self._decode_data(data[0:2])
#         if len(data) == self.VERSION_WITH_AUX_FIELD_LEN:
#             self.auxiliary = data[2:6]
# 
#     def __str__(self):
#         return self.version_to_string()
# 
#     def _decode_data(self, data):
#         """`data` is array.array."""
#         self.major = data[0]
# 
#         if data[1] == 0xff:
#             self.minor = data[1]
#         elif data[1] <= 0x99:
#             self.minor = int(py3_array_tobytes(data[1:2]).decode('bcd+'))
#         else:
#             raise DecodingError()
# 
#     def version_to_string(self):
#         return ''.join("%s.%s" % (self.major, self.minor))


# Path: pyipmi/bmc.py
from .msgs import create_request_by_name
from .utils import check_completion_code
from .state import State
from .fields import VersionField

        req.bus_id.id = bus_id
        req.bus_id.channel = channel
        req.bus_id.slave_address = address
        req.read_count = count
        if data:
            req.data = data
        rsp = self.send_message(req)
        check_completion_code(rsp.completion_code)
        return rsp.data

    def i2c_write(self, bus_type, bus_id, channel, address, data):
        self.i2c_write_read(bus_type, bus_id, channel, address, 0, data)

    def i2c_read(self, bus_type, bus_id, channel, address, count):
        return self.i2c_write_read(bus_type, bus_id, channel,
                                   address, count, None)

    def set_watchdog_timer(self, config):
        req = create_request_by_name('SetWatchdogTimer')
        req.timer_use.timer_use = config.timer_use
        req.timer_use.dont_stop = config.dont_stop and 1 or 0
        req.timer_use.dont_log = config.dont_log and 1 or 0

        req.timer_actions.pre_timeout_interrupt = config.pre_timeout_interrupt
        req.timer_actions.timeout_action = config.timeout_action

        req.pre_timeout_interval = config.pre_timeout_interval
        req.timer_use_expiration_flags = config.timer_use_expiration_flags
        req.initial_countdown = config.initial_countdown
        rsp = self.send_message(req)

        check_completion_code(rsp.completion_code)