API

bleak_sigspec.formatter

Utils to work with binary data or bytes

exception bleak_sigspec.formatter.FormatIncompleteError(*args)[source]

Bases: Exception

class bleak_sigspec.formatter.SuperStruct[source]

Bases: object

Struct class Bluetooth SIG compliant

calcsize(fmt)[source]

Return the size in bytes of a string format, same as struct.calcsize

pack(fmt, *args)[source]

Pack values (args) into bytes following the specified format (fmt)

unpack(fmt, bb)[source]

Unpack values from bytes(bb) following the specified format (fmt)

bleak_sigspec.formatter.decode_2_uint12(bb)[source]

Decode 3 bytes as two unsigned 12 bit integers

Specs:

2_uint12 len: 3 bytes

Format string: ‘o’

bleak_sigspec.formatter.decode_FLOAT_ieee11073(value)[source]

Defined in ISO/IEEE Std. 11073-20601TM-2008:

FLOAT-Type is defined as a 32-bit value with a 24-bit mantissa and an 8-bit exponent.

Special Values:
  • +INFINITY : [exponent 0, mantissa +(2^23 –2) → 0x007FFFFE]
  • NaN (Not a Number): [exponent 0, mantissa +(2^23 –1) → 0x007FFFFF]
  • NRes (Not at this Resolution): [exponent 0, mantissa –(2^23) → 0x00800000]
  • Reserved for future use : [exponent 0, mantissa –(2^23–1) → 0x00800001]
  • – INFINITY : [exponent 0, mantissa –(2^23 –2) → 0x00800002]
bleak_sigspec.formatter.decode_SFLOAT_ieee11073(value)[source]

Defined in ISO/IEEE Std. 11073-20601TM-2008:

SFLOAT-Type is defined as a 16-bit value with 12-bit mantissa and 4-bit exponent. The 16–bit value contains a 4-bit exponent to base 10, followed by a 12-bit mantissa. Each is in twos- complement form.

Special Values:
  • +INFINITY : [exponent 0, mantissa +(2^11 –2) → 0x07FE]
  • NaN (Not a Number): [exponent 0, mantissa +(2^11 –1) → 0x07FF]
  • NRes (Not at this Resolution): [exponent 0, mantissa –(2^11) → 0x0800]
  • Reserved for future use: [exponent 0, mantissa –(2^11 –1) → 0x0801]
  • – INFINITY : [exponent 0, mantissa –(2^11 –2) → 0x0802]
bleak_sigspec.formatter.decode_nibbles(bb)[source]

Decode 1 byte as two nibbles (ints)

Specs:

bb_len : 1

returns: (int, int)

bleak_sigspec.formatter.decode_sint24(bb)[source]

Decode 3 bytes as a signed 24 bit integer

Specs:
  • sint24 len: 3 bytes
  • Format string: ‘K’
bleak_sigspec.formatter.decode_uint128(bb)[source]

Decode 16 bytes as a unsigned 128 bit integer

Specs:
  • uint128 len: 16 bytes
  • Format string: ‘z’
bleak_sigspec.formatter.decode_uint24(bb)[source]

Decode 3 bytes as a unsigned 24 bit integer

Specs:
  • uint24 len: 3 bytes
  • Format string: ‘k’
bleak_sigspec.formatter.decode_uint40(bb)[source]

Decode 5 bytes as an unsigned 40 bit integer

Specs:
  • uint40 len: 5 bytes
  • Format string: ‘j’
bleak_sigspec.formatter.decode_uint48(bb)[source]

Decode 6 bytes as an unsigned 48 bit integer

Specs:
  • uint48 len: 6 bytes
  • Format string: ‘J’
bleak_sigspec.formatter.encode_2_uint12(val, val2)[source]

Format two values as two unsigned 12 bit integers

Specs:

2_uint12 len: 3 bytes

Format string: ‘o’

bleak_sigspec.formatter.encode_FLOAT_ieee11073(value, precision=1, debug=False)[source]

Binary representation of float value as IEEE-11073:20601 32-bit FLOAT

FLOAT-Type is defined as a 32-bit value with a 24-bit mantissa and an 8-bit exponent.

bleak_sigspec.formatter.encode_SFLOAT_ieee11073(value, precision=1, debug=False)[source]

Binary representation of float value as ISO/IEEE Std. 11073-20601TM-2008: 16-Bit FLOAT

The SFLOAT-Type is defined as a 16-bit value with 12-bit mantissa and 4-bit exponent

bleak_sigspec.formatter.encode_nibbles(val, val2)[source]

Encode two values as two nibbles in a byte

Specs:
  • Nibble: MSN LSN
  • Byte: 0b0000 0000
  • Indexes: 7654 3210
  • Values: val2 val
Requirement:
  • Only values (0-15) allowed
bleak_sigspec.formatter.encode_sint24(val)[source]

Format a value as a signed 24 bit integer

Specs:
  • sint24 len: 3 bytes
  • Format string: ‘K’
bleak_sigspec.formatter.encode_uint128(val)[source]

Format a value as a unsigned 128 bit integer

Specs:
  • uint128 len: 16 bytes
  • Format string: ‘z’
bleak_sigspec.formatter.encode_uint24(val)[source]

Format a value as a unsigned 24 bit integer

Specs:
  • uint24 len: 3 bytes
  • Format string: ‘k’
bleak_sigspec.formatter.encode_uint40(val)[source]

Format a value as an unsigned 40 bit integer

Specs:
  • uint40 len: 5 bytes
  • Format string: ‘j’
bleak_sigspec.formatter.encode_uint48(val)[source]

Format a value as an unsigned 48 bit integer

Specs:
  • uint48 len: 6 bytes
  • Format string: ‘J’
bleak_sigspec.formatter.twos_comp(val, bits)[source]

returns the 2’s complement of int value val with n bits

bleak_sigspec.formatter.twos_comp_dec(val, bits)[source]

returns the signed int value from the 2’s complement val with n bits

bleak_sigspec.utils

Utils to decode binary data from SIG Characteristics

class bleak_sigspec.utils.CHAR_XML(xml_file, path='/home/docs/checkouts/readthedocs.org/user_builds/bleak-sigspec/envs/stable/lib/python3.7/site-packages/bleak_sigspec-0.0.4-py3.7.egg/bleak_sigspec/characteristics_xml')[source]

Bases: object

Parse characteristic xml file

bleak_sigspec.utils.dict_char_value(data, raw=False)[source]

Simplify the characteristic value in dict format

bleak_sigspec.utils.get_char_value(value: bytes, characteristic: Union[bleak.backends.characteristic.BleakGATTCharacteristic, str, bleak_sigspec.utils.CHAR_XML], rtn_flags: bool = False, debug: bool = False) → dict[source]

Given a characteristic and its raw value in bytes, obtain the formatted value as a dict instance:

Args:
  • value (bytes):

    The result of read_gatt_char()

  • characteristic (BleakGATTCharacteristic, str, CHAR_XML):

    The characteristic from which get metadata.

  • rnt_flags:

    return the bitflags too if present

  • debug:

    print debug information about bytes unpacking

Returns:
  • dict:

    dict instance with the formatted value and its metadata.

bleak_sigspec.utils.get_plain_format(field)[source]

Iterates until the last level where Value is

bleak_sigspec.utils.get_ref_char_field(_field, name_field)[source]

Get characteristics field references recursively

bleak_sigspec.utils.get_xml_char(characteristic: Union[str, bleak.backends.characteristic.BleakGATTCharacteristic]) → bleak_sigspec.utils.CHAR_XML[source]

Get characteristic metadata from its xml file

Args:
  • characteristic (str, BleakGATTCharacteristic):

    The name of the characteristic or bleak characteristic class

Returns:
  • characteristic metatada class (CHAR_XML):

    The characteristic metadata parsed from its xml file

bleak_sigspec.utils.map_char_value(data, keys=[], string_fmt=False, one_line=True, sep=', ')[source]

Map characteristic value with the given keys, return dict or string format

bleak_sigspec.utils.pformat_char_flags(data, sep='\n', prnt=False, rtn=True)[source]

Print or return the characteristic flag in string format

bleak_sigspec.utils.pformat_char_value(data, char='', only_val=False, one_line=False, sep=', ', custom=None, symbols=True, prnt=True, rtn=False)[source]

Print or return the characteristic value in string format

bleak_sigspec.utils.pformat_field_value(field_data, field='', sep=', ', prnt=True, rtn=False)[source]

Print or return the field value in string format

bleak_sigspec.utils.pformat_ref_char_value(char_value)[source]

Print or return the characteristic value in string format