import dds
import ddsutil
import std_msgs/msg/Header_.std_msgs.msg.dds_
import struct

class BatteryState___TypeSupport(dds.TypeSupport):

    _typename = 'sensor_msgs::msg::dds_::BatteryState_'
    _keylist = ''
    _metadescriptor = '<MetaData version="1.0.0"><Module name="builtin_interfaces"><Module name="msg"><Module name="dds_"><Struct name="Time_"><Member name="sec_"><Long/></Member><Member name="nanosec_"><ULong/></Member></Struct></Module></Module></Module><Module name="std_msgs"><Module name="msg"><Module name="dds_"><Struct name="Header_"><Member name="stamp_"><Type name="::builtin_interfaces::msg::dds_::Time_"/></Member><Member name="frame_id_"><String/></Member></Struct></Module></Module></Module><Module name="sensor_msgs"><Module name="msg"><Module name="dds_"><Struct name="BatteryState_"><Member name="header_"><Type name="::std_msgs::msg::dds_::Header_"/></Member><Member name="voltage_"><Float/></Member><Member name="temperature_"><Float/></Member><Member name="current_"><Float/></Member><Member name="charge_"><Float/></Member><Member name="capacity_"><Float/></Member><Member name="design_capacity_"><Float/></Member><Member name="percentage_"><Float/></Member><Member name="power_supply_status_"><Octet/></Member><Member name="power_supply_health_"><Octet/></Member><Member name="power_supply_technology_"><Octet/></Member><Member name="present_"><Boolean/></Member><Member name="cell_voltage_"><Sequence><Float/></Sequence></Member><Member name="cell_temperature_"><Sequence><Float/></Sequence></Member><Member name="location_"><String/></Member><Member name="serial_number_"><String/></Member></Struct></Module></Module></Module></MetaData>'

    def __init__(self):
        super(BatteryState___TypeSupport, self).__init__(self._typename,
              self._keylist,
              self._metadescriptor,
              struct.calcsize(BatteryState_()._get_packing_fmt()))

    def _serialize(self, o):
        if not isinstance(o, BatteryState_):
            raise TypeError('Incorrect data type')
        result = o._serialize()
        return result

    def _deserialize(self, buf):
        result = BatteryState_()
        data = struct.unpack(result._get_packing_fmt(), buf)
        result._deserialize(list(data))
        return result

class BatteryState_(ddsutil.TopicDataClass):

    @staticmethod
    def get_type_support():
        ''' Return type support information required for dds.Topic constructor '''
        return BatteryState___TypeSupport()

    @property
    def header_(self):
        '''
        a DDS std_msgs::msg::dds_::Header_ value
        @rtype: std_msgs/msg/Header_.std_msgs.msg.dds_.Header_
        '''
        return self._header__

    _header__checker = ddsutil._class_checker(std_msgs/msg/Header_.std_msgs.msg.dds_.Header_)
    @header_.setter
    def header_(self, value):
        self._header__checker(value)
        self._header__ = value

    @property
    def voltage_(self):
        '''
        a DDS float value
        @rtype: float
        '''
        return self._voltage__

    _voltage__checker = ddsutil._float_checker
    @voltage_.setter
    def voltage_(self, value):
        self._voltage__checker(value)
        self._voltage__ = value

    @property
    def temperature_(self):
        '''
        a DDS float value
        @rtype: float
        '''
        return self._temperature__

    _temperature__checker = ddsutil._float_checker
    @temperature_.setter
    def temperature_(self, value):
        self._temperature__checker(value)
        self._temperature__ = value

    @property
    def current_(self):
        '''
        a DDS float value
        @rtype: float
        '''
        return self._current__

    _current__checker = ddsutil._float_checker
    @current_.setter
    def current_(self, value):
        self._current__checker(value)
        self._current__ = value

    @property
    def charge_(self):
        '''
        a DDS float value
        @rtype: float
        '''
        return self._charge__

    _charge__checker = ddsutil._float_checker
    @charge_.setter
    def charge_(self, value):
        self._charge__checker(value)
        self._charge__ = value

    @property
    def capacity_(self):
        '''
        a DDS float value
        @rtype: float
        '''
        return self._capacity__

    _capacity__checker = ddsutil._float_checker
    @capacity_.setter
    def capacity_(self, value):
        self._capacity__checker(value)
        self._capacity__ = value

    @property
    def design_capacity_(self):
        '''
        a DDS float value
        @rtype: float
        '''
        return self._design_capacity__

    _design_capacity__checker = ddsutil._float_checker
    @design_capacity_.setter
    def design_capacity_(self, value):
        self._design_capacity__checker(value)
        self._design_capacity__ = value

    @property
    def percentage_(self):
        '''
        a DDS float value
        @rtype: float
        '''
        return self._percentage__

    _percentage__checker = ddsutil._float_checker
    @percentage_.setter
    def percentage_(self, value):
        self._percentage__checker(value)
        self._percentage__ = value

    @property
    def power_supply_status_(self):
        '''
        a DDS octet value
        @rtype: int
        '''
        return self._power_supply_status__

    _power_supply_status__checker = ddsutil._octet_checker
    @power_supply_status_.setter
    def power_supply_status_(self, value):
        self._power_supply_status__checker(value)
        self._power_supply_status__ = value

    @property
    def power_supply_health_(self):
        '''
        a DDS octet value
        @rtype: int
        '''
        return self._power_supply_health__

    _power_supply_health__checker = ddsutil._octet_checker
    @power_supply_health_.setter
    def power_supply_health_(self, value):
        self._power_supply_health__checker(value)
        self._power_supply_health__ = value

    @property
    def power_supply_technology_(self):
        '''
        a DDS octet value
        @rtype: int
        '''
        return self._power_supply_technology__

    _power_supply_technology__checker = ddsutil._octet_checker
    @power_supply_technology_.setter
    def power_supply_technology_(self, value):
        self._power_supply_technology__checker(value)
        self._power_supply_technology__ = value

    @property
    def present_(self):
        '''
        a DDS boolean value
        @rtype: bool
        '''
        return self._present__

    _present__checker = ddsutil._bool_checker
    @present_.setter
    def present_(self, value):
        self._present__checker(value)
        self._present__ = value

    @property
    def cell_voltage_(self):
        '''
        a DDS sequence<float> value
        @rtype: list
        '''
        return self._cell_voltage__

    _cell_voltage__checker = ddsutil._seq_checker(0,ddsutil._float_checker)
    @cell_voltage_.setter
    def cell_voltage_(self, value):
        self._cell_voltage__checker(value)
        self._cell_voltage__ = value

    @property
    def cell_temperature_(self):
        '''
        a DDS sequence<float> value
        @rtype: list
        '''
        return self._cell_temperature__

    _cell_temperature__checker = ddsutil._seq_checker(0,ddsutil._float_checker)
    @cell_temperature_.setter
    def cell_temperature_(self, value):
        self._cell_temperature__checker(value)
        self._cell_temperature__ = value

    @property
    def location_(self):
        '''
        a DDS string value
        @rtype: str
        '''
        return self._location__

    _location__checker = ddsutil._str_checker
    @location_.setter
    def location_(self, value):
        self._location__checker(value)
        self._location__ = value

    @property
    def serial_number_(self):
        '''
        a DDS string value
        @rtype: str
        '''
        return self._serial_number__

    _serial_number__checker = ddsutil._str_checker
    @serial_number_.setter
    def serial_number_(self, value):
        self._serial_number__checker(value)
        self._serial_number__ = value

    _member_attributes = ('header_', 'voltage_', 'temperature_', 'current_', 'charge_', 'capacity_', 'design_capacity_', 'percentage_', 'power_supply_status_', 'power_supply_health_', 'power_supply_technology_', 'present_', 'cell_voltage_', 'cell_temperature_', 'location_', 'serial_number_')

    def __init__(self, **kwargs):
        ''' Create a BatteryState_ instance, optionally initializing fields by name '''
        # init attributes to default value
        self.header_ = std_msgs/msg/Header_.std_msgs.msg.dds_.Header_()
        self.voltage_ = 0.0
        self.temperature_ = 0.0
        self.current_ = 0.0
        self.charge_ = 0.0
        self.capacity_ = 0.0
        self.design_capacity_ = 0.0
        self.percentage_ = 0.0
        self.power_supply_status_ = 0
        self.power_supply_health_ = 0
        self.power_supply_technology_ = 0
        self.present_ = False
        self.cell_voltage_ = []
        self.cell_temperature_ = []
        self.location_ = ''
        self.serial_number_ = ''
        # set values for attributes passed in
        for key, value in kwargs.items():
            if key not in self._member_attributes:
                raise TypeError('Invalid argument name : %s' %(key))
            setattr(self, key, value)

    _packing_fmt = None

    @staticmethod
    def _get_packing_fmt():
        ''' Returns packing format of this class data '''
        if BatteryState_._packing_fmt is not None:
            return BatteryState_._packing_fmt
        fmt = ''
        fmt += ddsutil._align(fmt, std_msgs/msg/Header_.std_msgs.msg.dds_.Header_._get_packing_fmt())
        fmt += 'f'
        fmt += 'f'
        fmt += 'f'
        fmt += 'f'
        fmt += 'f'
        fmt += 'f'
        fmt += 'f'
        fmt += 'B'
        fmt += 'B'
        fmt += 'B'
        fmt += '?'
        fmt += ddsutil._align(fmt, ddsutil._pad_fmt('iiP?'))
        fmt += ddsutil._align(fmt, ddsutil._pad_fmt('iiP?'))
        fmt += 'P'
        fmt += 'P'

        BatteryState_._packing_fmt = ddsutil._pad_fmt(fmt)
        return BatteryState_._packing_fmt

    def _serialize(self):
        ''' Serialize data for writing '''
        fmt = self._get_packing_fmt()
        args = self._get_packing_args()
        result = struct.pack(fmt, *args)
        return result

    def _deserialize(self, data):
        ''' Initialize values from data returned by struct.unpack()'''
        self.header_ = std_msgs/msg/Header_.std_msgs.msg.dds_.Header_()._deserialize(data)
        self.voltage_ = data.pop(0)
        self.temperature_ = data.pop(0)
        self.current_ = data.pop(0)
        self.charge_ = data.pop(0)
        self.capacity_ = data.pop(0)
        self.design_capacity_ = data.pop(0)
        self.percentage_ = data.pop(0)
        self.power_supply_status_ = data.pop(0)
        self.power_supply_health_ = data.pop(0)
        self.power_supply_technology_ = data.pop(0)
        self.present_ = data.pop(0)
        self.cell_voltage_ = ddsutil._deserialize_seq(data, 'f', lambda seq_data: seq_data.pop(0))
        self.cell_temperature_ = ddsutil._deserialize_seq(data, 'f', lambda seq_data: seq_data.pop(0))
        self.location_ = ddsutil._ptr_to_bytes(data.pop(0)).decode('ISO-8859-1')
        self.serial_number_ = ddsutil._ptr_to_bytes(data.pop(0)).decode('ISO-8859-1')
        return self;

    def _get_packing_args(self):
        ''' Return an list of data suitable for struct.pack '''
        args = []
        args.extend(self.header_._get_packing_args())
        args.append(self.voltage_)
        args.append(self.temperature_)
        args.append(self.current_)
        args.append(self.charge_)
        args.append(self.capacity_)
        args.append(self.design_capacity_)
        args.append(self.percentage_)
        args.append(self.power_supply_status_)
        args.append(self.power_supply_health_)
        args.append(self.power_supply_technology_)
        args.append(self.present_)
        args.extend(ddsutil._serialize_seq(self.cell_voltage_, 'f', lambda seq_args, v: seq_args.append(v)))
        args.extend(ddsutil._serialize_seq(self.cell_temperature_, 'f', lambda seq_args, v: seq_args.append(v)))
        args.append(ddsutil._bytes_to_ptr(self.location_.encode('ISO-8859-1')))
        args.append(ddsutil._bytes_to_ptr(self.serial_number_.encode('ISO-8859-1')))
        return args

