iqrfpy.confirmation

Confirmation module.

This module contains DPA Confirmation message class.

  1"""Confirmation module.
  2
  3This module contains DPA Confirmation message class.
  4"""
  5
  6from typing import List, Optional, Union
  7from iqrfpy.enums.commands import Command
  8from iqrfpy.enums.peripherals import Peripheral
  9from iqrfpy.utils.common import Common
 10from iqrfpy.utils.dpa import ResponsePacketMembers
 11from iqrfpy.iresponse import IResponseGetterMixin
 12from iqrfpy.utils.validators import DpaValidator
 13
 14__all__ = ['Confirmation']
 15
 16
 17class Confirmation(IResponseGetterMixin):
 18    """Confirmation message class.
 19
 20    DPA confirmation is used to confirm reception of DPA request by node device at coordinator.
 21    The message carries DPA value, request hops (number of hops used to deliver DPA request to node device),
 22    response hops (number of hops used to deliver DPA response from node device to coordinator),
 23    and timeslot (see DPA documentation for timeslot length calculation).
 24    """
 25
 26    __slots__ = '_request_hops', '_response_hops', '_timeslot'
 27
 28    def __init__(self, nadr: int, pnum: Union[Peripheral, int], pcmd: Union[Command, int], hwpid: int, dpa_value: int,
 29                 rcode: int, pdata: Optional[List[int]] = None, result: Optional[dict] = None):
 30        """Confirmation constructor.
 31
 32        Args:
 33            nadr (int): Device address.
 34            pnum (Union[Peripheral, int]): Peripheral.
 35            pcmd (Union[Command, int]): Peripheral command.
 36            hwpid (int, optional): Hardware profile ID. Defaults to 65535, this value ignores HWPID check.
 37            rcode (int, optional): Response code. Defaults to 128.
 38            dpa_value (int, optional): DPA value. Defaults to 0.
 39            pdata (List[int], optional): DPA response data. Defaults to None.
 40            result (dict, optional): JSON response data. Defaults to None.
 41        """
 42        super().__init__(
 43            nadr=nadr,
 44            pcmd=pcmd,
 45            pnum=pnum,
 46            hwpid=hwpid,
 47            rcode=rcode,
 48            dpa_value=dpa_value,
 49            pdata=pdata,
 50            result=result
 51        )
 52        self._request_hops: int = result['requestHops']
 53        self._response_hops: int = result['responseHops']
 54        self._timeslot: int = result['timeslot']
 55
 56    @property
 57    def request_hops(self) -> int:
 58        """:obj:`int`: Request hops.
 59
 60        Getter only.
 61        """
 62        return self._request_hops
 63
 64    @property
 65    def response_hops(self) -> int:
 66        """:obj:`int`: Response hops.
 67
 68        Getter only.
 69        """
 70        return self._response_hops
 71
 72    @property
 73    def timeslot(self) -> int:
 74        """:obj:`int`: Timeslot.
 75
 76        Getter only.
 77        """
 78        return self._timeslot
 79
 80    @classmethod
 81    def from_dpa(cls, dpa: bytes) -> 'Confirmation':
 82        """Confirmation DPA factory method.
 83
 84        Parses DPA confirmation message and constructs :obj:`Confirmation` object.
 85
 86        Args:
 87            dpa (bytes): DPA confirmation bytes.
 88
 89        Returns:
 90            :obj:`Confirmation`: Confirmation message object.
 91        """
 92        DpaValidator.confirmation_length(dpa=dpa)
 93        DpaValidator.confirmation_code(dpa=dpa)
 94        nadr = dpa[ResponsePacketMembers.NADR]
 95        pnum = Common.pnum_from_dpa(dpa[ResponsePacketMembers.PNUM])
 96        pcmd = Common.request_pcmd_from_dpa(pnum, dpa[ResponsePacketMembers.PCMD])
 97        hwpid = Common.hwpid_from_dpa(dpa[ResponsePacketMembers.HWPID_HI], dpa[ResponsePacketMembers.HWPID_LO])
 98        rcode = dpa[ResponsePacketMembers.RCODE]
 99        dpa_value = dpa[ResponsePacketMembers.DPA_VALUE]
100        pdata = list(dpa[8:])
101        result = {'requestHops': dpa[8], 'responseHops': dpa[10], 'timeslot': dpa[9]}
102        return cls(nadr=nadr, pnum=pnum, pcmd=pcmd, hwpid=hwpid, rcode=rcode, dpa_value=dpa_value,
103                   pdata=pdata, result=result)
104
105    @classmethod
106    def from_json(cls, json: dict) -> 'Confirmation':
107        """Confirmation JSON factory method.
108
109        This method is not implemented as JSON API does not support standalone Confirmation messages.
110
111        Raises:
112            NotImplementedError: This method is not implemented.
113        """
114        raise NotImplementedError('from_json() method not implemented.')
class Confirmation(iqrfpy.iresponse.IResponseGetterMixin):
 18class Confirmation(IResponseGetterMixin):
 19    """Confirmation message class.
 20
 21    DPA confirmation is used to confirm reception of DPA request by node device at coordinator.
 22    The message carries DPA value, request hops (number of hops used to deliver DPA request to node device),
 23    response hops (number of hops used to deliver DPA response from node device to coordinator),
 24    and timeslot (see DPA documentation for timeslot length calculation).
 25    """
 26
 27    __slots__ = '_request_hops', '_response_hops', '_timeslot'
 28
 29    def __init__(self, nadr: int, pnum: Union[Peripheral, int], pcmd: Union[Command, int], hwpid: int, dpa_value: int,
 30                 rcode: int, pdata: Optional[List[int]] = None, result: Optional[dict] = None):
 31        """Confirmation constructor.
 32
 33        Args:
 34            nadr (int): Device address.
 35            pnum (Union[Peripheral, int]): Peripheral.
 36            pcmd (Union[Command, int]): Peripheral command.
 37            hwpid (int, optional): Hardware profile ID. Defaults to 65535, this value ignores HWPID check.
 38            rcode (int, optional): Response code. Defaults to 128.
 39            dpa_value (int, optional): DPA value. Defaults to 0.
 40            pdata (List[int], optional): DPA response data. Defaults to None.
 41            result (dict, optional): JSON response data. Defaults to None.
 42        """
 43        super().__init__(
 44            nadr=nadr,
 45            pcmd=pcmd,
 46            pnum=pnum,
 47            hwpid=hwpid,
 48            rcode=rcode,
 49            dpa_value=dpa_value,
 50            pdata=pdata,
 51            result=result
 52        )
 53        self._request_hops: int = result['requestHops']
 54        self._response_hops: int = result['responseHops']
 55        self._timeslot: int = result['timeslot']
 56
 57    @property
 58    def request_hops(self) -> int:
 59        """:obj:`int`: Request hops.
 60
 61        Getter only.
 62        """
 63        return self._request_hops
 64
 65    @property
 66    def response_hops(self) -> int:
 67        """:obj:`int`: Response hops.
 68
 69        Getter only.
 70        """
 71        return self._response_hops
 72
 73    @property
 74    def timeslot(self) -> int:
 75        """:obj:`int`: Timeslot.
 76
 77        Getter only.
 78        """
 79        return self._timeslot
 80
 81    @classmethod
 82    def from_dpa(cls, dpa: bytes) -> 'Confirmation':
 83        """Confirmation DPA factory method.
 84
 85        Parses DPA confirmation message and constructs :obj:`Confirmation` object.
 86
 87        Args:
 88            dpa (bytes): DPA confirmation bytes.
 89
 90        Returns:
 91            :obj:`Confirmation`: Confirmation message object.
 92        """
 93        DpaValidator.confirmation_length(dpa=dpa)
 94        DpaValidator.confirmation_code(dpa=dpa)
 95        nadr = dpa[ResponsePacketMembers.NADR]
 96        pnum = Common.pnum_from_dpa(dpa[ResponsePacketMembers.PNUM])
 97        pcmd = Common.request_pcmd_from_dpa(pnum, dpa[ResponsePacketMembers.PCMD])
 98        hwpid = Common.hwpid_from_dpa(dpa[ResponsePacketMembers.HWPID_HI], dpa[ResponsePacketMembers.HWPID_LO])
 99        rcode = dpa[ResponsePacketMembers.RCODE]
100        dpa_value = dpa[ResponsePacketMembers.DPA_VALUE]
101        pdata = list(dpa[8:])
102        result = {'requestHops': dpa[8], 'responseHops': dpa[10], 'timeslot': dpa[9]}
103        return cls(nadr=nadr, pnum=pnum, pcmd=pcmd, hwpid=hwpid, rcode=rcode, dpa_value=dpa_value,
104                   pdata=pdata, result=result)
105
106    @classmethod
107    def from_json(cls, json: dict) -> 'Confirmation':
108        """Confirmation JSON factory method.
109
110        This method is not implemented as JSON API does not support standalone Confirmation messages.
111
112        Raises:
113            NotImplementedError: This method is not implemented.
114        """
115        raise NotImplementedError('from_json() method not implemented.')

Confirmation message class.

DPA confirmation is used to confirm reception of DPA request by node device at coordinator. The message carries DPA value, request hops (number of hops used to deliver DPA request to node device), response hops (number of hops used to deliver DPA response from node device to coordinator), and timeslot (see DPA documentation for timeslot length calculation).

Confirmation( nadr: int, pnum: Union[iqrfpy.enums.peripherals.Peripheral, int], pcmd: Union[iqrfpy.enums.commands.Command, int], hwpid: int, dpa_value: int, rcode: int, pdata: Optional[List[int]] = None, result: Optional[dict] = None)
29    def __init__(self, nadr: int, pnum: Union[Peripheral, int], pcmd: Union[Command, int], hwpid: int, dpa_value: int,
30                 rcode: int, pdata: Optional[List[int]] = None, result: Optional[dict] = None):
31        """Confirmation constructor.
32
33        Args:
34            nadr (int): Device address.
35            pnum (Union[Peripheral, int]): Peripheral.
36            pcmd (Union[Command, int]): Peripheral command.
37            hwpid (int, optional): Hardware profile ID. Defaults to 65535, this value ignores HWPID check.
38            rcode (int, optional): Response code. Defaults to 128.
39            dpa_value (int, optional): DPA value. Defaults to 0.
40            pdata (List[int], optional): DPA response data. Defaults to None.
41            result (dict, optional): JSON response data. Defaults to None.
42        """
43        super().__init__(
44            nadr=nadr,
45            pcmd=pcmd,
46            pnum=pnum,
47            hwpid=hwpid,
48            rcode=rcode,
49            dpa_value=dpa_value,
50            pdata=pdata,
51            result=result
52        )
53        self._request_hops: int = result['requestHops']
54        self._response_hops: int = result['responseHops']
55        self._timeslot: int = result['timeslot']

Confirmation constructor.

Arguments:
  • nadr (int): Device address.
  • pnum (Union[Peripheral, int]): Peripheral.
  • pcmd (Union[Command, int]): Peripheral command.
  • hwpid (int, optional): Hardware profile ID. Defaults to 65535, this value ignores HWPID check.
  • rcode (int, optional): Response code. Defaults to 128.
  • dpa_value (int, optional): DPA value. Defaults to 0.
  • pdata (List[int], optional): DPA response data. Defaults to None.
  • result (dict, optional): JSON response data. Defaults to None.
request_hops: int

int: Request hops.

Getter only.

response_hops: int

int: Response hops.

Getter only.

timeslot: int

int: Timeslot.

Getter only.

@classmethod
def from_dpa(cls, dpa: bytes) -> Confirmation:
 81    @classmethod
 82    def from_dpa(cls, dpa: bytes) -> 'Confirmation':
 83        """Confirmation DPA factory method.
 84
 85        Parses DPA confirmation message and constructs :obj:`Confirmation` object.
 86
 87        Args:
 88            dpa (bytes): DPA confirmation bytes.
 89
 90        Returns:
 91            :obj:`Confirmation`: Confirmation message object.
 92        """
 93        DpaValidator.confirmation_length(dpa=dpa)
 94        DpaValidator.confirmation_code(dpa=dpa)
 95        nadr = dpa[ResponsePacketMembers.NADR]
 96        pnum = Common.pnum_from_dpa(dpa[ResponsePacketMembers.PNUM])
 97        pcmd = Common.request_pcmd_from_dpa(pnum, dpa[ResponsePacketMembers.PCMD])
 98        hwpid = Common.hwpid_from_dpa(dpa[ResponsePacketMembers.HWPID_HI], dpa[ResponsePacketMembers.HWPID_LO])
 99        rcode = dpa[ResponsePacketMembers.RCODE]
100        dpa_value = dpa[ResponsePacketMembers.DPA_VALUE]
101        pdata = list(dpa[8:])
102        result = {'requestHops': dpa[8], 'responseHops': dpa[10], 'timeslot': dpa[9]}
103        return cls(nadr=nadr, pnum=pnum, pcmd=pcmd, hwpid=hwpid, rcode=rcode, dpa_value=dpa_value,
104                   pdata=pdata, result=result)

Confirmation DPA factory method.

Parses DPA confirmation message and constructs Confirmation object.

Arguments:
  • dpa (bytes): DPA confirmation bytes.
Returns:

Confirmation: Confirmation message object.

@classmethod
def from_json(cls, json: dict) -> Confirmation:
106    @classmethod
107    def from_json(cls, json: dict) -> 'Confirmation':
108        """Confirmation JSON factory method.
109
110        This method is not implemented as JSON API does not support standalone Confirmation messages.
111
112        Raises:
113            NotImplementedError: This method is not implemented.
114        """
115        raise NotImplementedError('from_json() method not implemented.')

Confirmation JSON factory method.

This method is not implemented as JSON API does not support standalone Confirmation messages.

Raises:
  • NotImplementedError: This method is not implemented.