# Copyright (c) 2010 - 2017, Nordic Semiconductor ASA
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
#    list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of Nordic Semiconductor ASA nor the names of its
#    contributors may be used to endorse or promote products derived from this
#    software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

# This file was autogenerated by serial_doc_gen_pyaci.py at 2017-07-06 08:12:08.
from aci.aci_utils import CommandPacket, ResponsePacket, value_to_barray, iterable_to_barray, barray_pop
from aci.aci_evt import CmdRsp


class Echo(CommandPacket):
    """A simple loopback test command, to verify that the serial
transport layer is working as intended."""
    def __init__(self, data):
        __data = bytearray()
        __data += iterable_to_barray(data)
        super(Echo, self).__init__(0x02, __data)


class InternalEventsReport(CommandPacket):
    """Start reporting internal events, if supported."""
    def __init__(self):
        __data = bytearray()
        super(InternalEventsReport, self).__init__(0x03, __data)


class SerialVersionGet(CommandPacket):
    """Request the implemented version of the serial interface."""
    def __init__(self):
        __data = bytearray()
        super(SerialVersionGet, self).__init__(0x09, __data)


class FwInfoGet(CommandPacket):
    """Request the firmware version info structure for the firmware."""
    def __init__(self):
        __data = bytearray()
        super(FwInfoGet, self).__init__(0x0A, __data)


class RadioReset(CommandPacket):
    """Restart the device."""
    def __init__(self):
        __data = bytearray()
        super(RadioReset, self).__init__(0x0E, __data)


class BeaconStart(CommandPacket):
    """Start an application controlled beacon with the given payload."""
    def __init__(self, beacon_slot, data):
        __data = bytearray()
        __data += value_to_barray(beacon_slot, 1)
        __data += iterable_to_barray(data)
        super(BeaconStart, self).__init__(0x10, __data)


class BeaconStop(CommandPacket):
    """Stop transmitting the current beacon."""
    def __init__(self, beacon_slot):
        __data = bytearray()
        __data += value_to_barray(beacon_slot, 1)
        super(BeaconStop, self).__init__(0x11, __data)


class BeaconParamsGet(CommandPacket):
    """Set parameters for application controlled beacon."""
    def __init__(self, beacon_slot):
        __data = bytearray()
        __data += value_to_barray(beacon_slot, 1)
        super(BeaconParamsGet, self).__init__(0x13, __data)


class BeaconParamsSet(CommandPacket):
    """Set parameters for application controlled beacon."""
    def __init__(self, beacon_slot, tx_power, channel_map, interval_ms):
        __data = bytearray()
        __data += value_to_barray(beacon_slot, 1)
        __data += value_to_barray(tx_power, 1)
        __data += value_to_barray(channel_map, 1)
        __data += value_to_barray(interval_ms, 4)
        super(BeaconParamsSet, self).__init__(0x12, __data)


class Application(CommandPacket):
    """Application specific command, has no functionality in the
framework, but is forwarded to the application."""
    def __init__(self, data):
        __data = bytearray()
        __data += iterable_to_barray(data)
        super(Application, self).__init__(0x20, __data)


class Start(CommandPacket):
    """Opening message of a Segmentation and Reassembly message."""
    def __init__(self):
        __data = bytearray()
        super(Start, self).__init__(0x21, __data)


class Continue(CommandPacket):
    """Continuation of a Segmentation and Reassembly message."""
    def __init__(self):
        __data = bytearray()
        super(Continue, self).__init__(0x22, __data)


class AdvAddrSet(CommandPacket):
    """Set the device's BLE advertisement address used for all BLE
advertisment messages sent by the device."""
    def __init__(self, addr_type, adv_addr):
        __data = bytearray()
        __data += value_to_barray(addr_type, 1)
        __data += iterable_to_barray(adv_addr)
        super(AdvAddrSet, self).__init__(0x40, __data)


class AdvAddrGet(CommandPacket):
    """Get the device's BLE advertisement address."""
    def __init__(self):
        __data = bytearray()
        super(AdvAddrGet, self).__init__(0x41, __data)


class ChannelMapSet(CommandPacket):
    """Set the channel map for advertisement packets."""
    def __init__(self, channel_map):
        __data = bytearray()
        __data += value_to_barray(channel_map, 1)
        super(ChannelMapSet, self).__init__(0x42, __data)


class ChannelMapGet(CommandPacket):
    """Get the channel map used for advertisement packets."""
    def __init__(self):
        __data = bytearray()
        super(ChannelMapGet, self).__init__(0x43, __data)


class TxPowerSet(CommandPacket):
    """Set the transmission power of the radio."""
    def __init__(self, tx_power):
        __data = bytearray()
        __data += value_to_barray(tx_power, 1)
        super(TxPowerSet, self).__init__(0x44, __data)


class TxPowerGet(CommandPacket):
    """Get the transmission power of the radio."""
    def __init__(self):
        __data = bytearray()
        super(TxPowerGet, self).__init__(0x45, __data)


class UuidSet(CommandPacket):
    """Set the device UUID used for identifying the device during
provisioning. If the UUID isn't set, the device will use a
preprogrammed UUID."""
    def __init__(self, uuid):
        __data = bytearray()
        __data += iterable_to_barray(uuid)
        super(UuidSet, self).__init__(0x53, __data)


class UuidGet(CommandPacket):
    """Get the device UUID used for identifying the device during
provisioning."""
    def __init__(self):
        __data = bytearray()
        super(UuidGet, self).__init__(0x54, __data)


class InitContext(CommandPacket):
    """Reset a provisioning context so it can be used for provisioning a
device."""
    def __init__(self, context_id):
        __data = bytearray()
        __data += value_to_barray(context_id, 1)
        super(InitContext, self).__init__(0x60, __data)


class ScanStart(CommandPacket):
    """Start reporting of incoming unprovisioned beacons."""
    def __init__(self):
        __data = bytearray()
        super(ScanStart, self).__init__(0x61, __data)


class ScanStop(CommandPacket):
    """Stop reporting of incoming unprovisioned beacons."""
    def __init__(self):
        __data = bytearray()
        super(ScanStop, self).__init__(0x62, __data)


class Provision(CommandPacket):
    """Start provisioning of a device."""
    def __init__(self, context_id, target_uuid, network_key, network_key_index, iv_index, address, iv_update_flag, key_refresh_flag):
        __data = bytearray()
        __data += value_to_barray(context_id, 1)
        __data += iterable_to_barray(target_uuid)
        __data += iterable_to_barray(network_key)
        __data += value_to_barray(network_key_index, 2)
        __data += value_to_barray(iv_index, 4)
        __data += value_to_barray(address, 2)
        __data += value_to_barray(iv_update_flag, 1)
        __data += value_to_barray(key_refresh_flag, 1)
        super(Provision, self).__init__(0x63, __data)


class Listen(CommandPacket):
    """As an uprovisioned device, listen for incoming provisioning
requests."""
    def __init__(self):
        __data = bytearray()
        super(Listen, self).__init__(0x64, __data)


class OobUse(CommandPacket):
    """Used to respond to the _Provisioning Capabilities Received_
event. It is used to select which kind of OOB authentication
method to use. The values can be found in nrf_mesh_prov.h.  If
authentication is enabled, the application will receive a
_Provisioning Auth Request_ event requesting authentication data.
A _Provisioning ECDH Request_ will be received when the
provisioner needs to calculate the ECDH shared secret for the
nodes.  The _Provisioning Complete_ event is received when the
provisioning procedure has completed successfully. At this point,
a provisioner must wait for the _Provisioning Link Closed_ event
before re-using the provisioning context."""
    def __init__(self, context_id, oob_method, size):
        __data = bytearray()
        __data += value_to_barray(context_id, 1)
        __data += value_to_barray(oob_method, 1)
        __data += value_to_barray(size, 1)
        super(OobUse, self).__init__(0x66, __data)


class AuthData(CommandPacket):
    """Used to respond to a _Provisioning Auth Request_ event."""
    def __init__(self, context_id, data):
        __data = bytearray()
        __data += value_to_barray(context_id, 1)
        __data += iterable_to_barray(data)
        super(AuthData, self).__init__(0x67, __data)


class EcdhSecret(CommandPacket):
    """Used to respond to a _Provisioning ECDH Request_ event."""
    def __init__(self, context_id, shared_secret):
        __data = bytearray()
        __data += value_to_barray(context_id, 1)
        __data += iterable_to_barray(shared_secret)
        super(EcdhSecret, self).__init__(0x68, __data)


class KeypairSet(CommandPacket):
    """Send a public/private keypair to the device."""
    def __init__(self, private_key, public_key):
        __data = bytearray()
        __data += iterable_to_barray(private_key)
        __data += iterable_to_barray(public_key)
        super(KeypairSet, self).__init__(0x69, __data)


class CapabilitiesSet(CommandPacket):
    """Used to set the out-of-band authentication capabilities of a
device. The values for the parameters can be found in the various
defines in the nrf_mesh_prov.h header file."""
    def __init__(self, num_components, public_key_type, static_oob_types, output_oob_size, output_oob_actions, input_oob_size, input_oob_actions):
        __data = bytearray()
        __data += value_to_barray(num_components, 1)
        __data += value_to_barray(public_key_type, 1)
        __data += value_to_barray(static_oob_types, 1)
        __data += value_to_barray(output_oob_size, 1)
        __data += value_to_barray(output_oob_actions, 2)
        __data += value_to_barray(input_oob_size, 1)
        __data += value_to_barray(input_oob_actions, 2)
        super(CapabilitiesSet, self).__init__(0x6A, __data)


class Init(CommandPacket):
    """Not implemented."""
    def __init__(self):
        __data = bytearray()
        super(Init, self).__init__(0x70, __data)


class ValueSet(CommandPacket):
    """Not implemented."""
    def __init__(self):
        __data = bytearray()
        super(ValueSet, self).__init__(0x71, __data)


class ValueEnable(CommandPacket):
    """Not implemented."""
    def __init__(self):
        __data = bytearray()
        super(ValueEnable, self).__init__(0x72, __data)


class ValueDisable(CommandPacket):
    """Not implemented."""
    def __init__(self):
        __data = bytearray()
        super(ValueDisable, self).__init__(0x73, __data)


class Start(CommandPacket):
    """Not implemented."""
    def __init__(self):
        __data = bytearray()
        super(Start, self).__init__(0x74, __data)


class Stop(CommandPacket):
    """Not implemented."""
    def __init__(self):
        __data = bytearray()
        super(Stop, self).__init__(0x75, __data)


class FlagSet(CommandPacket):
    """Not implemented."""
    def __init__(self):
        __data = bytearray()
        super(FlagSet, self).__init__(0x76, __data)


class FlagGet(CommandPacket):
    """Not implemented."""
    def __init__(self):
        __data = bytearray()
        super(FlagGet, self).__init__(0x77, __data)


class DfuData(CommandPacket):
    """Send DFU data to the device."""
    def __init__(self, dfu_packet):
        __data = bytearray()
        __data += value_to_barray(dfu_packet, 24)
        super(DfuData, self).__init__(0x78, __data)


class ValueGet(CommandPacket):
    """Not implemented."""
    def __init__(self):
        __data = bytearray()
        super(ValueGet, self).__init__(0x7A, __data)


class BuildVersionGet(CommandPacket):
    """Not implemented."""
    def __init__(self):
        __data = bytearray()
        super(BuildVersionGet, self).__init__(0x7B, __data)


class AccessAddrGet(CommandPacket):
    """Not implemented."""
    def __init__(self):
        __data = bytearray()
        super(AccessAddrGet, self).__init__(0x7C, __data)


class ChannelGet(CommandPacket):
    """Not implemented."""
    def __init__(self):
        __data = bytearray()
        super(ChannelGet, self).__init__(0x7D, __data)


class IntervalMinMsGet(CommandPacket):
    """Not implemented."""
    def __init__(self):
        __data = bytearray()
        super(IntervalMinMsGet, self).__init__(0x7F, __data)


class Enable(CommandPacket):
    """Enable mesh operation."""
    def __init__(self):
        __data = bytearray()
        super(Enable, self).__init__(0x90, __data)


class Disable(CommandPacket):
    """Disable mesh operation."""
    def __init__(self):
        __data = bytearray()
        super(Disable, self).__init__(0x91, __data)


class SubnetAdd(CommandPacket):
    """Add a mesh subnetwork to the device."""
    def __init__(self, net_key_index, key):
        __data = bytearray()
        __data += value_to_barray(net_key_index, 2)
        __data += iterable_to_barray(key)
        super(SubnetAdd, self).__init__(0x92, __data)


class SubnetUpdate(CommandPacket):
    """Update a mesh subnetwork's root key."""
    def __init__(self, subnet_handle, key):
        __data = bytearray()
        __data += value_to_barray(subnet_handle, 2)
        __data += iterable_to_barray(key)
        super(SubnetUpdate, self).__init__(0x93, __data)


class SubnetDelete(CommandPacket):
    """Delete a subnetwork from the device."""
    def __init__(self, subnet_handle):
        __data = bytearray()
        __data += value_to_barray(subnet_handle, 2)
        super(SubnetDelete, self).__init__(0x94, __data)


class SubnetGetAll(CommandPacket):
    """Get all known subnetwork key indexes."""
    def __init__(self):
        __data = bytearray()
        super(SubnetGetAll, self).__init__(0x95, __data)


class SubnetCountMaxGet(CommandPacket):
    """Get the maximum number of subnetworks the device can fit."""
    def __init__(self):
        __data = bytearray()
        super(SubnetCountMaxGet, self).__init__(0x96, __data)


class AppkeyAdd(CommandPacket):
    """Add a mesh application key to the device."""
    def __init__(self, app_key_index, subnet_handle, key):
        __data = bytearray()
        __data += value_to_barray(app_key_index, 2)
        __data += value_to_barray(subnet_handle, 2)
        __data += iterable_to_barray(key)
        super(AppkeyAdd, self).__init__(0x97, __data)


class AppkeyUpdate(CommandPacket):
    """Update a mesh application key."""
    def __init__(self, appkey_handle, key):
        __data = bytearray()
        __data += value_to_barray(appkey_handle, 2)
        __data += iterable_to_barray(key)
        super(AppkeyUpdate, self).__init__(0x98, __data)


class AppkeyDelete(CommandPacket):
    """Delete a application key from the device."""
    def __init__(self, appkey_handle):
        __data = bytearray()
        __data += value_to_barray(appkey_handle, 2)
        super(AppkeyDelete, self).__init__(0x99, __data)


class AppkeyGetAll(CommandPacket):
    """Get all the application key indices of the stored application
keys associated with a specific subnetwork."""
    def __init__(self, subnet_handle):
        __data = bytearray()
        __data += value_to_barray(subnet_handle, 2)
        super(AppkeyGetAll, self).__init__(0x9A, __data)


class AppkeyCountMaxGet(CommandPacket):
    """Get the maximum number of application keys the device can fit."""
    def __init__(self):
        __data = bytearray()
        super(AppkeyCountMaxGet, self).__init__(0x9B, __data)


class DevkeyAdd(CommandPacket):
    """Add a mesh device key to the device."""
    def __init__(self, owner_addr, subnet_handle, key):
        __data = bytearray()
        __data += value_to_barray(owner_addr, 2)
        __data += value_to_barray(subnet_handle, 2)
        __data += iterable_to_barray(key)
        super(DevkeyAdd, self).__init__(0x9C, __data)


class DevkeyDelete(CommandPacket):
    """Delete a device key from the device."""
    def __init__(self, devkey_handle):
        __data = bytearray()
        __data += value_to_barray(devkey_handle, 2)
        super(DevkeyDelete, self).__init__(0x9D, __data)


class DevkeyCountMaxGet(CommandPacket):
    """Get the maximum number of device keys the device can fit."""
    def __init__(self):
        __data = bytearray()
        super(DevkeyCountMaxGet, self).__init__(0x9E, __data)


class AddrLocalUnicastSet(CommandPacket):
    """Set the start and count of the device's local unicast address."""
    def __init__(self, start_address, count):
        __data = bytearray()
        __data += value_to_barray(start_address, 2)
        __data += value_to_barray(count, 2)
        super(AddrLocalUnicastSet, self).__init__(0x9F, __data)


class AddrLocalUnicastGet(CommandPacket):
    """Get the start and count of the device's local unicast addresses."""
    def __init__(self):
        __data = bytearray()
        super(AddrLocalUnicastGet, self).__init__(0xA0, __data)


class AddrGet(CommandPacket):
    """Get the raw representation of the address with the given handle."""
    def __init__(self, address_handle):
        __data = bytearray()
        __data += value_to_barray(address_handle, 2)
        super(AddrGet, self).__init__(0xA7, __data)


class AddrGetAll(CommandPacket):
    """Get a list of all address handles in the address pool, not
including local unicast addresses."""
    def __init__(self):
        __data = bytearray()
        super(AddrGetAll, self).__init__(0xA8, __data)


class AddrNonvirtualCountMaxGet(CommandPacket):
    """Get the maximum number of nonvirtual addresses the device can
fit."""
    def __init__(self):
        __data = bytearray()
        super(AddrNonvirtualCountMaxGet, self).__init__(0xA9, __data)


class AddrVirtualCountMaxGet(CommandPacket):
    """Get the maximum number of virtual addresses the device can fit."""
    def __init__(self):
        __data = bytearray()
        super(AddrVirtualCountMaxGet, self).__init__(0xAA, __data)


class AddrSubscriptionAdd(CommandPacket):
    """Add the specified address to the set of active address
subscriptions."""
    def __init__(self, address):
        __data = bytearray()
        __data += value_to_barray(address, 2)
        super(AddrSubscriptionAdd, self).__init__(0xA1, __data)


class AddrSubscriptionAddVirtual(CommandPacket):
    """Add the virtual address with the specified UUID to the set of
active address subscriptions."""
    def __init__(self, uuid):
        __data = bytearray()
        __data += iterable_to_barray(uuid)
        super(AddrSubscriptionAddVirtual, self).__init__(0xA2, __data)


class AddrSubscriptionRemove(CommandPacket):
    """Remove the address with the given handle from the set of active
address subscriptions."""
    def __init__(self, address_handle):
        __data = bytearray()
        __data += value_to_barray(address_handle, 2)
        super(AddrSubscriptionRemove, self).__init__(0xA3, __data)


class AddrPublicationAdd(CommandPacket):
    """Add the specified address to the set of active publish addresses."""
    def __init__(self, address):
        __data = bytearray()
        __data += value_to_barray(address, 2)
        super(AddrPublicationAdd, self).__init__(0xA4, __data)


class AddrPublicationAddVirtual(CommandPacket):
    """Add the virtual address with the specified UUID to the set of
active publish addresses."""
    def __init__(self, uuid):
        __data = bytearray()
        __data += iterable_to_barray(uuid)
        super(AddrPublicationAddVirtual, self).__init__(0xA5, __data)


class AddrPublicationRemove(CommandPacket):
    """Remove the address with the specified handle from the set of
active publish addresses."""
    def __init__(self, address_handle):
        __data = bytearray()
        __data += value_to_barray(address_handle, 2)
        super(AddrPublicationRemove, self).__init__(0xA6, __data)


class PacketSend(CommandPacket):
    """Send a mesh packet."""
    def __init__(self, appkey_handle, src_addr, dst_addr_handle, ttl, reliable, data):
        __data = bytearray()
        __data += value_to_barray(appkey_handle, 2)
        __data += value_to_barray(src_addr, 2)
        __data += value_to_barray(dst_addr_handle, 2)
        __data += value_to_barray(ttl, 1)
        __data += value_to_barray(reliable, 1)
        __data += iterable_to_barray(data)
        super(PacketSend, self).__init__(0xAB, __data)


class StateClear(CommandPacket):
    """Reset the device and network state and erase the flash copies."""
    def __init__(self):
        __data = bytearray()
        super(StateClear, self).__init__(0xAC, __data)


class JumpToBootloader(CommandPacket):
    """Immediately jump to bootloader mode."""
    def __init__(self):
        __data = bytearray()
        super(JumpToBootloader, self).__init__(0xD0, __data)


class Request(CommandPacket):
    """Request a DFU transfer."""
    def __init__(self, dfu_type, fwid, bank_addr):
        __data = bytearray()
        __data += value_to_barray(dfu_type, 1)
        __data += value_to_barray(fwid, 10)
        __data += value_to_barray(bank_addr, 4)
        super(Request, self).__init__(0xD1, __data)


class Relay(CommandPacket):
    """Relay a DFU transfer."""
    def __init__(self, dfu_type, fwid):
        __data = bytearray()
        __data += value_to_barray(dfu_type, 1)
        __data += value_to_barray(fwid, 10)
        super(Relay, self).__init__(0xD2, __data)


class Abort(CommandPacket):
    """Abort the ongoing DFU transfer."""
    def __init__(self):
        __data = bytearray()
        super(Abort, self).__init__(0xD3, __data)


class BankInfoGet(CommandPacket):
    """Get information about the firmware bank of the given type, if it
exists."""
    def __init__(self, dfu_type):
        __data = bytearray()
        __data += value_to_barray(dfu_type, 1)
        super(BankInfoGet, self).__init__(0xD4, __data)


class BankFlash(CommandPacket):
    """Flash the bank with the given firmware type."""
    def __init__(self, dfu_type):
        __data = bytearray()
        __data += value_to_barray(dfu_type, 1)
        super(BankFlash, self).__init__(0xD5, __data)


class StateGet(CommandPacket):
    """Get the current state of the DFU module."""
    def __init__(self):
        __data = bytearray()
        super(StateGet, self).__init__(0xD6, __data)


class ModelPubAddrSet(CommandPacket):
    """Set the publish address for a model instance."""
    def __init__(self, model_handle, dsm_handle):
        __data = bytearray()
        __data += value_to_barray(model_handle, 2)
        __data += value_to_barray(dsm_handle, 2)
        super(ModelPubAddrSet, self).__init__(0xE0, __data)


class ModelPubAddrGet(CommandPacket):
    """Get the publish address for a model instance."""
    def __init__(self, handle):
        __data = bytearray()
        __data += value_to_barray(handle, 2)
        super(ModelPubAddrGet, self).__init__(0xE1, __data)


class ModelPubPeriodSet(CommandPacket):
    """Set the publish address for a model instance."""
    def __init__(self, model_handle, resolution, step_number):
        __data = bytearray()
        __data += value_to_barray(model_handle, 2)
        __data += value_to_barray(resolution, 1)
        __data += value_to_barray(step_number, 1)
        super(ModelPubPeriodSet, self).__init__(0xE2, __data)


class ModelPubPeriodGet(CommandPacket):
    """Get the publish period for a model instance."""
    def __init__(self, handle):
        __data = bytearray()
        __data += value_to_barray(handle, 2)
        super(ModelPubPeriodGet, self).__init__(0xE3, __data)


class ModelSubsAdd(CommandPacket):
    """Add a subscription address to a model instance."""
    def __init__(self, model_handle, dsm_handle):
        __data = bytearray()
        __data += value_to_barray(model_handle, 2)
        __data += value_to_barray(dsm_handle, 2)
        super(ModelSubsAdd, self).__init__(0xE4, __data)


class ModelSubsRemove(CommandPacket):
    """Remove a subscription address from a model instance."""
    def __init__(self, model_handle, dsm_handle):
        __data = bytearray()
        __data += value_to_barray(model_handle, 2)
        __data += value_to_barray(dsm_handle, 2)
        super(ModelSubsRemove, self).__init__(0xE5, __data)


class ModelSubsGet(CommandPacket):
    """Get the list of subscription addresses from a model instance."""
    def __init__(self, handle):
        __data = bytearray()
        __data += value_to_barray(handle, 2)
        super(ModelSubsGet, self).__init__(0xE6, __data)


class ModelAppBind(CommandPacket):
    """Bind an application key to a model instance."""
    def __init__(self, model_handle, dsm_handle):
        __data = bytearray()
        __data += value_to_barray(model_handle, 2)
        __data += value_to_barray(dsm_handle, 2)
        super(ModelAppBind, self).__init__(0xE7, __data)


class ModelAppUnbind(CommandPacket):
    """Unbind an application key from a model instance."""
    def __init__(self, model_handle, dsm_handle):
        __data = bytearray()
        __data += value_to_barray(model_handle, 2)
        __data += value_to_barray(dsm_handle, 2)
        super(ModelAppUnbind, self).__init__(0xE8, __data)


class ModelAppGet(CommandPacket):
    """Get all the application keys bound to a model instance."""
    def __init__(self, handle):
        __data = bytearray()
        __data += value_to_barray(handle, 2)
        super(ModelAppGet, self).__init__(0xE9, __data)


class ModelPubAppSet(CommandPacket):
    """Set the application key to be used when publishing for a model
instance."""
    def __init__(self, model_handle, dsm_handle):
        __data = bytearray()
        __data += value_to_barray(model_handle, 2)
        __data += value_to_barray(dsm_handle, 2)
        super(ModelPubAppSet, self).__init__(0xEA, __data)


class ModelPubAppGet(CommandPacket):
    """Get the application key used when publishing for a model
instance."""
    def __init__(self, handle):
        __data = bytearray()
        __data += value_to_barray(handle, 2)
        super(ModelPubAppGet, self).__init__(0xEB, __data)


class ModelPubTtlSet(CommandPacket):
    """Set the default ttl value used when publishing for a model
instance."""
    def __init__(self, model_handle, ttl):
        __data = bytearray()
        __data += value_to_barray(model_handle, 2)
        __data += value_to_barray(ttl, 1)
        super(ModelPubTtlSet, self).__init__(0xEC, __data)


class ModelPubTtlGet(CommandPacket):
    """Get the default ttl value used when publishing for a model
instance."""
    def __init__(self, handle):
        __data = bytearray()
        __data += value_to_barray(handle, 2)
        super(ModelPubTtlGet, self).__init__(0xED, __data)


class ElemLocSet(CommandPacket):
    """Set the location descriptor for an element."""
    def __init__(self, element_index, location):
        __data = bytearray()
        __data += value_to_barray(element_index, 2)
        __data += value_to_barray(location, 2)
        super(ElemLocSet, self).__init__(0xEE, __data)


class ElemLocGet(CommandPacket):
    """Get the location descriptor for an element."""
    def __init__(self, element_index):
        __data = bytearray()
        __data += value_to_barray(element_index, 2)
        super(ElemLocGet, self).__init__(0xEF, __data)


class ElemSigModelCountGet(CommandPacket):
    """Get the number of Bluetooth SIG models for an element."""
    def __init__(self, element_index):
        __data = bytearray()
        __data += value_to_barray(element_index, 2)
        super(ElemSigModelCountGet, self).__init__(0xF0, __data)


class ElemVendorModelCountGet(CommandPacket):
    """Get the number of vendor specific models for an element."""
    def __init__(self, element_index):
        __data = bytearray()
        __data += value_to_barray(element_index, 2)
        super(ElemVendorModelCountGet, self).__init__(0xF1, __data)


class ModelIdGet(CommandPacket):
    """Get the model ID of a model instance."""
    def __init__(self, handle):
        __data = bytearray()
        __data += value_to_barray(handle, 2)
        super(ModelIdGet, self).__init__(0xF2, __data)


class HandleGet(CommandPacket):
    """Get the handle assigned to the model instance of a model based on
the element index and model ID."""
    def __init__(self, element_index, model_id):
        __data = bytearray()
        __data += value_to_barray(element_index, 2)
        __data += value_to_barray(model_id, 4)
        super(HandleGet, self).__init__(0xF3, __data)


class ElemModelsGet(CommandPacket):
    """Get the array of handles corresponding to an element."""
    def __init__(self, element_index):
        __data = bytearray()
        __data += value_to_barray(element_index, 2)
        super(ElemModelsGet, self).__init__(0xF4, __data)


class AccessFlashStore(CommandPacket):
    """Store the access layer information to flash."""
    def __init__(self):
        __data = bytearray()
        super(AccessFlashStore, self).__init__(0xF5, __data)


class ModelsGet(CommandPacket):
    """Get a list of all the models available on the device."""
    def __init__(self):
        __data = bytearray()
        super(ModelsGet, self).__init__(0xFC, __data)


class Init(CommandPacket):
    """Calls the initializer of the addressed model in order to create a
new instance."""
    def __init__(self, model_init_info, data):
        __data = bytearray()
        __data += value_to_barray(model_init_info, 6)
        __data += iterable_to_barray(data)
        super(Init, self).__init__(0xFD, __data)


class Command(CommandPacket):
    """Forwards a model specific command to a model instance."""
    def __init__(self, model_cmd_info, data):
        __data = bytearray()
        __data += value_to_barray(model_cmd_info, 2)
        __data += iterable_to_barray(data)
        super(Command, self).__init__(0xFE, __data)


class EchoRsp(ResponsePacket):
    """Response to a(n) Echo command."""
    def __init__(self, raw_data):
        __data = {}
        __data["data"] = raw_data[:len(raw_data)]
        raw_data = raw_data[len(raw_data):]
        assert(len(raw_data) == 0)
        super(EchoRsp, self).__init__("Echo", 0x02, __data)


class SerialVersionGetRsp(ResponsePacket):
    """Response to a(n) SerialVersionGet command."""
    def __init__(self, raw_data):
        __data = {}
        __data["serial_ver"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(SerialVersionGetRsp, self).__init__("SerialVersionGet", 0x09, __data)


class FwInfoGetRsp(ResponsePacket):
    """Response to a(n) FwInfoGet command."""
    def __init__(self, raw_data):
        __data = {}
        __data["fwid"] = raw_data[:10]
        raw_data = raw_data[10:]
        assert(len(raw_data) == 0)
        super(FwInfoGetRsp, self).__init__("FwInfoGet", 0x0A, __data)


class BeaconParamsGetRsp(ResponsePacket):
    """Response to a(n) BeaconParamsGet command."""
    def __init__(self, raw_data):
        __data = {}
        __data["beacon_slot"] = barray_pop(raw_data, 1)
        __data["tx_power"] = barray_pop(raw_data, 1)
        __data["channel_map"] = barray_pop(raw_data, 1)
        __data["interval_ms"] = barray_pop(raw_data, 4)
        assert(len(raw_data) == 0)
        super(BeaconParamsGetRsp, self).__init__("BeaconParamsGet", 0x13, __data)


class AdvAddrGetRsp(ResponsePacket):
    """Response to a(n) AdvAddrGet command."""
    def __init__(self, raw_data):
        __data = {}
        __data["addr_type"] = barray_pop(raw_data, 1)
        __data["addr"] = raw_data[:6]
        raw_data = raw_data[6:]
        assert(len(raw_data) == 0)
        super(AdvAddrGetRsp, self).__init__("AdvAddrGet", 0x41, __data)


class UuidGetRsp(ResponsePacket):
    """Response to a(n) UuidGet command."""
    def __init__(self, raw_data):
        __data = {}
        __data["device_uuid"] = raw_data[:16]
        raw_data = raw_data[16:]
        assert(len(raw_data) == 0)
        super(UuidGetRsp, self).__init__("UuidGet", 0x54, __data)


class ProvisionRsp(ResponsePacket):
    """Response to a(n) Provision command."""
    def __init__(self, raw_data):
        __data = {}
        __data["context"] = barray_pop(raw_data, 1)
        assert(len(raw_data) == 0)
        super(ProvisionRsp, self).__init__("Provision", 0x63, __data)


class OobUseRsp(ResponsePacket):
    """Response to a(n) OobUse command."""
    def __init__(self, raw_data):
        __data = {}
        __data["context"] = barray_pop(raw_data, 1)
        assert(len(raw_data) == 0)
        super(OobUseRsp, self).__init__("OobUse", 0x66, __data)


class AuthDataRsp(ResponsePacket):
    """Response to a(n) AuthData command."""
    def __init__(self, raw_data):
        __data = {}
        __data["context"] = barray_pop(raw_data, 1)
        assert(len(raw_data) == 0)
        super(AuthDataRsp, self).__init__("AuthData", 0x67, __data)


class EcdhSecretRsp(ResponsePacket):
    """Response to a(n) EcdhSecret command."""
    def __init__(self, raw_data):
        __data = {}
        __data["context"] = barray_pop(raw_data, 1)
        assert(len(raw_data) == 0)
        super(EcdhSecretRsp, self).__init__("EcdhSecret", 0x68, __data)


class SubnetAddRsp(ResponsePacket):
    """Response to a(n) SubnetAdd command."""
    def __init__(self, raw_data):
        __data = {}
        __data["subnet_handle"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(SubnetAddRsp, self).__init__("SubnetAdd", 0x92, __data)


class SubnetUpdateRsp(ResponsePacket):
    """Response to a(n) SubnetUpdate command."""
    def __init__(self, raw_data):
        __data = {}
        __data["subnet_handle"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(SubnetUpdateRsp, self).__init__("SubnetUpdate", 0x93, __data)


class SubnetDeleteRsp(ResponsePacket):
    """Response to a(n) SubnetDelete command."""
    def __init__(self, raw_data):
        __data = {}
        __data["subnet_handle"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(SubnetDeleteRsp, self).__init__("SubnetDelete", 0x94, __data)


class SubnetGetAllRsp(ResponsePacket):
    """Response to a(n) SubnetGetAll command."""
    def __init__(self, raw_data):
        __data = {}
        __data["subnet_key_index"] = raw_data[:94]
        raw_data = raw_data[94:]
        assert(len(raw_data) == 0)
        super(SubnetGetAllRsp, self).__init__("SubnetGetAll", 0x95, __data)


class SubnetCountMaxGetRsp(ResponsePacket):
    """Response to a(n) SubnetCountMaxGet command."""
    def __init__(self, raw_data):
        __data = {}
        __data["list_size"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(SubnetCountMaxGetRsp, self).__init__("SubnetCountMaxGet", 0x96, __data)


class AppkeyAddRsp(ResponsePacket):
    """Response to a(n) AppkeyAdd command."""
    def __init__(self, raw_data):
        __data = {}
        __data["appkey_handle"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(AppkeyAddRsp, self).__init__("AppkeyAdd", 0x97, __data)


class AppkeyUpdateRsp(ResponsePacket):
    """Response to a(n) AppkeyUpdate command."""
    def __init__(self, raw_data):
        __data = {}
        __data["appkey_handle"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(AppkeyUpdateRsp, self).__init__("AppkeyUpdate", 0x98, __data)


class AppkeyDeleteRsp(ResponsePacket):
    """Response to a(n) AppkeyDelete command."""
    def __init__(self, raw_data):
        __data = {}
        __data["appkey_handle"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(AppkeyDeleteRsp, self).__init__("AppkeyDelete", 0x99, __data)


class AppkeyGetAllRsp(ResponsePacket):
    """Response to a(n) AppkeyGetAll command."""
    def __init__(self, raw_data):
        __data = {}
        __data["subnet_handle"] = barray_pop(raw_data, 2)
        __data["appkey_key_index"] = raw_data[:92]
        raw_data = raw_data[92:]
        assert(len(raw_data) == 0)
        super(AppkeyGetAllRsp, self).__init__("AppkeyGetAll", 0x9A, __data)


class AppkeyCountMaxGetRsp(ResponsePacket):
    """Response to a(n) AppkeyCountMaxGet command."""
    def __init__(self, raw_data):
        __data = {}
        __data["list_size"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(AppkeyCountMaxGetRsp, self).__init__("AppkeyCountMaxGet", 0x9B, __data)


class DevkeyAddRsp(ResponsePacket):
    """Response to a(n) DevkeyAdd command."""
    def __init__(self, raw_data):
        __data = {}
        __data["devkey_handle"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(DevkeyAddRsp, self).__init__("DevkeyAdd", 0x9C, __data)


class DevkeyDeleteRsp(ResponsePacket):
    """Response to a(n) DevkeyDelete command."""
    def __init__(self, raw_data):
        __data = {}
        __data["devkey_handle"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(DevkeyDeleteRsp, self).__init__("DevkeyDelete", 0x9D, __data)


class DevkeyCountMaxGetRsp(ResponsePacket):
    """Response to a(n) DevkeyCountMaxGet command."""
    def __init__(self, raw_data):
        __data = {}
        __data["list_size"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(DevkeyCountMaxGetRsp, self).__init__("DevkeyCountMaxGet", 0x9E, __data)


class AddrLocalUnicastGetRsp(ResponsePacket):
    """Response to a(n) AddrLocalUnicastGet command."""
    def __init__(self, raw_data):
        __data = {}
        __data["address_start"] = barray_pop(raw_data, 2)
        __data["count"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(AddrLocalUnicastGetRsp, self).__init__("AddrLocalUnicastGet", 0xA0, __data)


class AddrGetRsp(ResponsePacket):
    """Response to a(n) AddrGet command."""
    def __init__(self, raw_data):
        __data = {}
        __data["address_handle"] = barray_pop(raw_data, 2)
        __data["addr_type"] = barray_pop(raw_data, 1)
        __data["subscribed"] = barray_pop(raw_data, 1)
        __data["raw_short_addr"] = barray_pop(raw_data, 2)
        __data["virtual_uuid"] = raw_data[:16]
        raw_data = raw_data[16:]
        assert(len(raw_data) == 0)
        super(AddrGetRsp, self).__init__("AddrGet", 0xA7, __data)


class AddrGetAllRsp(ResponsePacket):
    """Response to a(n) AddrGetAll command."""
    def __init__(self, raw_data):
        __data = {}
        __data["address_handles"] = raw_data[:94]
        raw_data = raw_data[94:]
        assert(len(raw_data) == 0)
        super(AddrGetAllRsp, self).__init__("AddrGetAll", 0xA8, __data)


class AddrNonvirtualCountMaxGetRsp(ResponsePacket):
    """Response to a(n) AddrNonvirtualCountMaxGet command."""
    def __init__(self, raw_data):
        __data = {}
        __data["list_size"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(AddrNonvirtualCountMaxGetRsp, self).__init__("AddrNonvirtualCountMaxGet", 0xA9, __data)


class AddrVirtualCountMaxGetRsp(ResponsePacket):
    """Response to a(n) AddrVirtualCountMaxGet command."""
    def __init__(self, raw_data):
        __data = {}
        __data["list_size"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(AddrVirtualCountMaxGetRsp, self).__init__("AddrVirtualCountMaxGet", 0xAA, __data)


class AddrSubscriptionAddRsp(ResponsePacket):
    """Response to a(n) AddrSubscriptionAdd command."""
    def __init__(self, raw_data):
        __data = {}
        __data["address_handle"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(AddrSubscriptionAddRsp, self).__init__("AddrSubscriptionAdd", 0xA1, __data)


class AddrSubscriptionAddVirtualRsp(ResponsePacket):
    """Response to a(n) AddrSubscriptionAddVirtual command."""
    def __init__(self, raw_data):
        __data = {}
        __data["address_handle"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(AddrSubscriptionAddVirtualRsp, self).__init__("AddrSubscriptionAddVirtual", 0xA2, __data)


class AddrSubscriptionRemoveRsp(ResponsePacket):
    """Response to a(n) AddrSubscriptionRemove command."""
    def __init__(self, raw_data):
        __data = {}
        __data["address_handle"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(AddrSubscriptionRemoveRsp, self).__init__("AddrSubscriptionRemove", 0xA3, __data)


class AddrPublicationAddRsp(ResponsePacket):
    """Response to a(n) AddrPublicationAdd command."""
    def __init__(self, raw_data):
        __data = {}
        __data["address_handle"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(AddrPublicationAddRsp, self).__init__("AddrPublicationAdd", 0xA4, __data)


class AddrPublicationAddVirtualRsp(ResponsePacket):
    """Response to a(n) AddrPublicationAddVirtual command."""
    def __init__(self, raw_data):
        __data = {}
        __data["address_handle"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(AddrPublicationAddVirtualRsp, self).__init__("AddrPublicationAddVirtual", 0xA5, __data)


class AddrPublicationRemoveRsp(ResponsePacket):
    """Response to a(n) AddrPublicationRemove command."""
    def __init__(self, raw_data):
        __data = {}
        __data["address_handle"] = barray_pop(raw_data, 2)
        assert(len(raw_data) == 0)
        super(AddrPublicationRemoveRsp, self).__init__("AddrPublicationRemove", 0xA6, __data)


class BankInfoGetRsp(ResponsePacket):
    """Response to a(n) BankInfoGet command."""
    def __init__(self, raw_data):
        __data = {}
        __data["dfu_type"] = barray_pop(raw_data, 1)
        __data["fwid"] = raw_data[:10]
        raw_data = raw_data[10:]
        __data["is_signed"] = barray_pop(raw_data, 1)
        __data["start_addr"] = barray_pop(raw_data, 4)
        __data["length"] = barray_pop(raw_data, 4)
        assert(len(raw_data) == 0)
        super(BankInfoGetRsp, self).__init__("BankInfoGet", 0xD4, __data)


class StateGetRsp(ResponsePacket):
    """Response to a(n) StateGet command."""
    def __init__(self, raw_data):
        __data = {}
        __data["role"] = barray_pop(raw_data, 1)
        __data["type"] = barray_pop(raw_data, 1)
        __data["fwid"] = raw_data[:10]
        raw_data = raw_data[10:]
        __data["state"] = barray_pop(raw_data, 1)
        __data["data_progress"] = barray_pop(raw_data, 1)
        assert(len(raw_data) == 0)
        super(StateGetRsp, self).__init__("StateGet", 0xD6, __data)


RESPONSE_LUT = {
    0x02: {"object": EchoRsp, "name": "Echo"},
    0x09: {"object": SerialVersionGetRsp, "name": "SerialVersionGet"},
    0x0A: {"object": FwInfoGetRsp, "name": "FwInfoGet"},
    0x13: {"object": BeaconParamsGetRsp, "name": "BeaconParamsGet"},
    0x41: {"object": AdvAddrGetRsp, "name": "AdvAddrGet"},
    0x54: {"object": UuidGetRsp, "name": "UuidGet"},
    0x63: {"object": ProvisionRsp, "name": "Provision"},
    0x66: {"object": OobUseRsp, "name": "OobUse"},
    0x67: {"object": AuthDataRsp, "name": "AuthData"},
    0x68: {"object": EcdhSecretRsp, "name": "EcdhSecret"},
    0x92: {"object": SubnetAddRsp, "name": "SubnetAdd"},
    0x93: {"object": SubnetUpdateRsp, "name": "SubnetUpdate"},
    0x94: {"object": SubnetDeleteRsp, "name": "SubnetDelete"},
    0x95: {"object": SubnetGetAllRsp, "name": "SubnetGetAll"},
    0x96: {"object": SubnetCountMaxGetRsp, "name": "SubnetCountMaxGet"},
    0x97: {"object": AppkeyAddRsp, "name": "AppkeyAdd"},
    0x98: {"object": AppkeyUpdateRsp, "name": "AppkeyUpdate"},
    0x99: {"object": AppkeyDeleteRsp, "name": "AppkeyDelete"},
    0x9A: {"object": AppkeyGetAllRsp, "name": "AppkeyGetAll"},
    0x9B: {"object": AppkeyCountMaxGetRsp, "name": "AppkeyCountMaxGet"},
    0x9C: {"object": DevkeyAddRsp, "name": "DevkeyAdd"},
    0x9D: {"object": DevkeyDeleteRsp, "name": "DevkeyDelete"},
    0x9E: {"object": DevkeyCountMaxGetRsp, "name": "DevkeyCountMaxGet"},
    0xA0: {"object": AddrLocalUnicastGetRsp, "name": "AddrLocalUnicastGet"},
    0xA7: {"object": AddrGetRsp, "name": "AddrGet"},
    0xA8: {"object": AddrGetAllRsp, "name": "AddrGetAll"},
    0xA9: {"object": AddrNonvirtualCountMaxGetRsp, "name": "AddrNonvirtualCountMaxGet"},
    0xAA: {"object": AddrVirtualCountMaxGetRsp, "name": "AddrVirtualCountMaxGet"},
    0xA1: {"object": AddrSubscriptionAddRsp, "name": "AddrSubscriptionAdd"},
    0xA2: {"object": AddrSubscriptionAddVirtualRsp, "name": "AddrSubscriptionAddVirtual"},
    0xA3: {"object": AddrSubscriptionRemoveRsp, "name": "AddrSubscriptionRemove"},
    0xA4: {"object": AddrPublicationAddRsp, "name": "AddrPublicationAdd"},
    0xA5: {"object": AddrPublicationAddVirtualRsp, "name": "AddrPublicationAddVirtual"},
    0xA6: {"object": AddrPublicationRemoveRsp, "name": "AddrPublicationRemove"},
    0xD4: {"object": BankInfoGetRsp, "name": "BankInfoGet"},
    0xD6: {"object": StateGetRsp, "name": "StateGet"}
}


def response_deserialize(rsp):
    if not isinstance(rsp, CmdRsp):
        raise TypeError("Expected a CmdRsp object.")
    elif not rsp._data["opcode"] in RESPONSE_LUT:
        return None

    response = RESPONSE_LUT[rsp._data["opcode"]]
    # Response is always {opcode, status, [...]}
    if len(rsp._data["data"]) > 0:
        return response["object"](rsp._data["data"])
    else:
        return response["name"]
