Python API¶
API for controlling blueSPY from Python.¶
Provides functions for connecting to a moreph and loading existing captures.
Also provides a packets object, which behaves like a list and can be used to
access the packets in the current file.
len(packets) shows the number of available packets; packets[0] accesses the first packet.
The queries documented in the GUI can be accessed with attribute syntax, e.g. packets[0].summary.
Examples¶
To connect to a moreph with serial 00010100 and capture CL and LE:
python
import bluespy
from time import sleep
bluespy.connect(0x00010100)
bluespy.capture("example.pcapng", CL=True, LE=True)
sleep(20)
bluespy.stop_capture()
bluespy.disconnect()
print(f"Captured {len(bluespy.packets)} packets")
bluespy.close_file()
To load an existing capture and print the summary strings of all packets:
import bluespy
bluespy.load_file("example.pcapng")
for p in bluespy.packets:
print(p.summary)
bluespy.close_file()
BluespyError ¶
Bases: RuntimeError
! Exception showing why an operation failed.
Source code in application/bluespy.py
Packets ¶
Bases: object
List-like object representing the currently loaded baseband packets.
Source code in application/bluespy.py
__getitem__ ¶
! Get an event_id for a packet
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
i
|
Index of packet, 0 <= i < len() |
required |
Returns:
| Type | Description |
|---|---|
|
An event_id |
Source code in application/bluespy.py
audiopod_options ¶
Bases: object
! Audiopod capture options
Source code in application/bluespy.py
__init__ ¶
__init__(channels=audio_channel.STEREO, output=audio_connect.NOAUDIO, input=audio_connect.NOAUDIO, bias=audio_bias.OFF, sample_rate=0, current_probe=False, LA_low_voltage=0.0, LA_high_voltage=0.0, power_supply_V=0.0, VIO_dV=0.0, second_I2S_input=False, AGC=False, DRC=False, vol_in_left=0.0, vol_in_right=0.0, vol_out_left=0.0, vol_out_right=0.0)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channels
|
Audiopod Channels |
STEREO
|
|
output
|
Which audiopod port is used for output |
NOAUDIO
|
|
input
|
Which audiopod port is used for intput |
NOAUDIO
|
|
bias
|
Audiopod bias |
OFF
|
|
sample_rate
|
Audiopod sample rate Allowed values are: 8'000, 11'025, 16'000, 22'050, 32'000, 44'100, 48'000, 88'200, 96'000, 176'400, 192'000 |
0
|
|
current_probe
|
Enable current probe |
False
|
|
LA_low_voltage
|
Logic Low Voltage. Must be within the [0.0, 3.3] range. |
0.0
|
|
LA_high_voltage
|
Logic High Voltage. Must be within the [0.0, 3.3] range. Allowed values for Audiopod_Logic(Low/High)Voltage are from 0.0 to 3.3 |
0.0
|
|
power_supply_V
|
Power supply in volts Allowed values are from 0.6 to 5.0 |
0.0
|
|
VIO_dV
|
VIO in deciVolts |
0.0
|
|
second_I2S_input
|
Enable a second I2S input, output must be set to BLUESPY_NO_AUDIO |
False
|
|
AGC
|
AGC |
False
|
|
DRC
|
DRC |
False
|
|
vol_in_left
|
Input volume (Left) |
0.0
|
|
vol_in_right
|
Input volume (Right) |
0.0
|
|
vol_out_left
|
Output volume (Left) |
0.0
|
|
vol_out_right
|
Output volume (Right) |
0.0
|
Source code in application/bluespy.py
audiostream_id ¶
Bases: id
! An object referencing a audio stream.
Do not make your own, only get these from the audio stream id functions. Audio Stream IDs are ordered arbitrarily After running close_file(), do not call any methods on any existing audiostream_id objects.
Source code in application/bluespy.py
connection_id ¶
Bases: id
! An object referencing a connection.
Do not make your own, only get these from the connection id functions. Connection IDs are ordered arbitrarily After running close_file(), do not call any methods on any existing connection_id objects.
Source code in application/bluespy.py
get_audio_streams ¶
! Get the audio streams
Returns:
| Type | Description |
|---|---|
|
Array of audio streams IDs |
device_id ¶
Bases: id
! An object referencing a device.
Do not make your own, only get these from the device id functions. Device IDs are ordered arbitrarily After running close_file(), do not call any methods on any existing device_id objects.
Source code in application/bluespy.py
error ¶
Bases: c_int
! Return type showing why an operation failed.
Evaluates to True if the operation succeeded, else False. str() and repr() give an error string, .value gives an error code.
Source code in application/bluespy.py
event_id ¶
Bases: id
! An object referencing a loaded packet.
Do not make your own, only get these from the 'packets' object. After running close_file(), do not call any methods on any existing event_id objects.
Any query (see the documentation or Help->Query List in the GUI) can be accessed as an attribute on this object
Source code in application/bluespy.py
children ¶
! Get all constituent packets of this packet. e.g. if this is an L2CAP packet
Returns:
| Type | Description |
|---|---|
|
List of event_ids |
Source code in application/bluespy.py
parent ¶
! Get the a higher layer packet that contains this one. e.g. if this is a baseband data packet get the L2CAP packet it is part of.
Returns:
| Type | Description |
|---|---|
|
event_id |
file_id ¶
Bases: c_uint64
! An object referencing a loaded file.
Do not make your own, only get these from the 'files' object.
Source code in application/bluespy.py
__bool__ ¶
i2s_options ¶
Bases: object
! I2S capture options
Source code in application/bluespy.py
__init__ ¶
__init__(SCLK_line=0, WS_line=0, SD_line=0, n_channels=0, bits_per_ch=0, sample_on_rising_edge=False, first_chan_follows_WS_high=False, one_sample_delay=False, MSB_first=False, DSP_Mode=False, master=False)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
SCLK_line
|
SCLK line for each interface. Valid values are [0,15] |
0
|
|
WS_line
|
WS line for each interface. Valid values are [0,15] |
0
|
|
SD_line
|
SD line for each interface. Valid values are [0,15] |
0
|
|
n_channels
|
Number of channels. Valid values are [1,16] |
0
|
|
bits_per_ch
|
Number of bits per channel. Valid values are [1,32] |
0
|
|
sample_on_rising_edge
|
Whether to sample on rising edges |
False
|
|
first_chan_follows_WS_high
|
Whether the first channel follows WS High |
False
|
|
one_sample_delay
|
Whether to delay by one sample |
False
|
|
MSB_first
|
MSB first |
False
|
|
DSP_Mode
|
DSP Mode |
False
|
|
master
|
Master |
False
|
Source code in application/bluespy.py
id ¶
Bases: c_uint64
! An object referencing a loaded event, device, connection, or audio stream.
Do not make your own, only get these from the bluespy functions. After running close_file(), do not call any methods on any existing event_id objects.
Any query (see the documentation or Help->Query List in the GUI) can be accessed as an attribute on this object
Source code in application/bluespy.py
__bool__ ¶
__getattr__ ¶
query ¶
! Get a query from this object, and return it in its preferred form
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
A query string, e.g. "summary" |
required |
Returns:
| Type | Description |
|---|---|
|
A string, int or bool depending on the query |
Source code in application/bluespy.py
query_bool ¶
! Get a query from this object, and return it as a bool if possible
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
A query string, e.g. "acked" |
required |
Returns:
| Type | Description |
|---|---|
|
bool |
query_int ¶
! Get a query from this object, and return it as an integer if possible
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
A query string, e.g. "summary" |
required |
Returns:
| Type | Description |
|---|---|
|
int |
query_str ¶
! Get a query from this object, and return it as a string
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
A query string, e.g. "summary" |
required |
Returns:
| Type | Description |
|---|---|
|
string |
Source code in application/bluespy.py
latency_status ¶
Bases: c_int
! Return log level
Source code in application/bluespy.py
log_level ¶
logic_rate ¶
time_point ¶
Bases: c_int64
! Represents the time in nanoseconds since epoch 1970/01/01 00:00 UTC
Source code in application/bluespy.py
__bool__ ¶
add_link_key ¶
! Add a link key for decryption
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Link key as a 16-byte bytes object |
required | |
addr0
|
(Optional) MAC address of central as a 64-bit integer |
0
|
|
addr1
|
(Optional) MAC address of peripheral as a 64-bit integer |
0
|
Source code in application/bluespy.py
add_log_message ¶
! Adds a log message into the running capture
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
The Log Level. |
required | |
message
|
The log message content. |
required | |
ts
|
The time of the log message. ts=invalid means the time will be set to the present. |
9223372036854775807
|
Raises:
| Type | Description |
|---|---|
BluespyError
|
Exception in the bluespy library |
Source code in application/bluespy.py
add_to_filter_file ¶
! Add an event to a filter file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_
|
File ID |
required | |
event_
|
Event ID |
required |
Raises:
| Type | Description |
|---|---|
BluespyError
|
Exception in the bluespy library |
Source code in application/bluespy.py
capture ¶
capture(filename, CL=False, LE=False, QHS=False, _15_4=False, wifi=False, MHDT_CL=False, MHDT_LE=False, Dukosi=False, Varjo=False, CS=False, Audiopod=None, I2S=[None, None], spectrum=0, logic_mask=0, logic_use_external_vref=True, logic_rate=0, HDT=False, Proprietary_1=False, Proprietary_2=False)
! Start a new capture in filename
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
Path to store capture in |
required | |
CL
|
Enable Bluetooth Classic capture |
False
|
|
LE
|
Enable Bluetooth LE capture |
False
|
|
QHS
|
Enable Qualcomm High Speed capture |
False
|
|
_15_4
|
Enable 802.15.4 capture |
False
|
|
wifi
|
Enable WiFi capture |
False
|
|
MHDT_CL
|
Enable MediaTek mHDT Classic capture |
False
|
|
MHDT_LE
|
Enable MediaTek mHDT LE capture |
False
|
|
Dukosi
|
Enable Dukosi capture |
False
|
|
Varjo
|
Enable Varjo capture |
False
|
|
CS
|
Enable Channel-Sounding capture |
False
|
|
Audiopod
|
Audiopod options. Providing an audiopod_options struct will enable audiopod |
None
|
|
I2S
|
I2S options. Providing i2s_options structs will enable I2S |
[None, None]
|
|
spectrum
|
Spectrum capture interval in microseconds. 0 means disabled. Allowed values are: 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000. |
0
|
|
logic_mask
|
32-bit mask enabling logic lines |
0
|
|
logic_use_external_vref
|
Use External or Internal vref |
True
|
|
logic_rate
|
Low, Medium, or High logic rate |
0
|
|
Proprietary_1
|
Enable Proprietary_1 capture |
False
|
|
Proprietary_2
|
Enable Proprietary_2 capture |
False
|
Raises:
| Type | Description |
|---|---|
BluespyError
|
Exception in the bluespy library |
Source code in application/bluespy.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
capture_multiple ¶
capture_multiple(filename, CL=[], LE=[], wifi=[], QHS=False, _15_4=False, MHDT_CL=False, MHDT_LE=False, Dukosi=False, Varjo=False, CS=False, Audiopod=None, I2S=[None, None], spectrum=0, logic_mask=0, logic_use_external_vref=True, logic_rate=0, HDT=[], Proprietary_1=False, Proprietary_2=False)
! Start a new capture in filename
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
Path to store capture in |
required | |
CL
|
Enable Bluetooth Classic capture, list of bools, one for each Moreph |
[]
|
|
LE
|
Enable Bluetooth LE capture, list of bools, one for each Moreph |
[]
|
|
wifi
|
Enable WiFi capture, list of bools, one for each Moreph |
[]
|
|
QHS
|
Enable Qualcomm High Speed capture |
False
|
|
_15_4
|
Enable 802.15.4 capture |
False
|
|
MHDT_CL
|
Enable MediaTek mHDT Classic capture |
False
|
|
MHDT_LE
|
Enable MediaTek mHDT LE capture |
False
|
|
Dukosi
|
Enable Dukosi capture |
False
|
|
Varjo
|
Enable Varjo capture |
False
|
|
CS
|
Enable Channel-Sounding capture |
False
|
|
Audiopod
|
Audiopod options. Providing an audiopod_options struct will enable audiopod |
None
|
|
I2S
|
I2S options. Providing i2s_options structs will enable I2S |
[None, None]
|
|
spectrum
|
Spectrum capture interval in microseconds. 0 means disabled. Allowed values are: 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000. |
0
|
|
Proprietary_1
|
Enable Proprietary_1 capture |
False
|
|
Proprietary_2
|
Enable Proprietary_2 capture |
False
|
Raises:
| Type | Description |
|---|---|
BluespyError
|
Exception in the bluespy library |
Source code in application/bluespy.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | |
close_file ¶
! Close an existing capture
Raises:
| Type | Description |
|---|---|
BluespyError
|
Exception in the bluespy library |
close_filter_file ¶
! Close a filter file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_
|
File ID |
required |
Raises:
| Type | Description |
|---|---|
BluespyError
|
Exception in the bluespy library |
connect ¶
! Connect to Moreph hardware via USB or Ethernet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
serial
|
A serial number as an integer, or -1 to connect to the first device. The serial number shown in the software and on the MiniMoreph is hexadecimal, so should be entered as 0xNNNNNN. There is a serial number on the bottom of some Moreph30s is of the form AYYYY-XXXXX, the XXXXX is the required serial number in decimal. |
-1
|
Raises:
| Type | Description |
|---|---|
BluespyError
|
Exception in the bluespy library You should run disconnect() later if this is successful. |
Source code in application/bluespy.py
connect_multiple ¶
! Connect to multiple Moreph hardware devices via USB or Ethernet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
serials
|
An array of serial numbers as integers. The first serial number in the array is considered that of the primary device. The serial numbers shown in the software and on the MiniMoreph are hexadecimal, so should be entered as 0xNNNNNN. There is a serial number on the bottom of some Moreph30s is of the form AYYYY-XXXXX, the XXXXX is the required serial number in decimal. |
required |
Raises:
| Type | Description |
|---|---|
BluespyError
|
Exception in the bluespy library You should run disconnect() later if this is successful. |
Source code in application/bluespy.py
connected_morephs ¶
! Get the serial numbers of connected moreph devices.
Returns:
| Type | Description |
|---|---|
|
Array of serial numbers |
Source code in application/bluespy.py
create_filter_file ¶
create_filter_file(filename, range_start=-1, keep_spec=True, keep_logic=True, keep_uart=True, keep_i2s_and_audiopod=True)
! Creates a filter file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
File name |
required | |
range_start
|
File name |
-1
|
|
keep_spec
|
Enable copying spectrum |
True
|
|
keep_logic
|
Enable copying logic |
True
|
|
keep_uart
|
Enable copying UART |
True
|
|
keep_i2s_and_audiopod
|
Enable copying I2S and Audiopod |
True
|
Returns:
| Type | Description |
|---|---|
|
file_id of filter file. -1 = invalid |
Source code in application/bluespy.py
disconnect ¶
! Disconnect from the connected Morephs
Raises:
| Type | Description |
|---|---|
BluespyError
|
Exception in the bluespy library |
get_audiostreams ¶
! Get the ids of the audio streams from 'id'
If id is device_id: Streams which a device is creating. If id is connection_id: Streams which are part of a connection. If id is BLUESPY_ID_INVALID: Streams not associated with any device, e.g. audiopod streams.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_
|
Device ID or Connection ID, or -1 for audiopod streams. |
id(18446744073709551615)
|
Returns:
| Type | Description |
|---|---|
|
Array of audio stream IDs |
Source code in application/bluespy.py
get_device_id ¶
! Get the Device ID from an address
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
addr
|
Six bytes representing an address |
required |
Returns:
| Type | Description |
|---|---|
|
Device ID. -1 = no device |
get_logic_at_time ¶
! Get the logic state at ts
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ts
|
Timestamp |
required |
Returns:
| Type | Description |
|---|---|
|
32 bit integer. The i'th bit represents the state of the i'th logic line |
get_next_logic_change ¶
! Get the next logic state after ts
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ts
|
Timestamp |
required | |
mask
|
32 integer mask. logic lines corresponding to zero bits are ignored |
required |
Returns:
| Type | Description |
|---|---|
|
A struct containing a 32 integer mask representing the next logic state, and the time of transition |
Source code in application/bluespy.py
invalid_time ¶
list_keys ¶
! List the keys from the security tab
Returns:
| Type | Description |
|---|---|
|
Keys |
Source code in application/bluespy.py
load_file ¶
! Load an existing capture
Raises:
| Type | Description |
|---|---|
BluespyError
|
Exception in the bluespy library |
mark_key_used ¶
! Marks an encryption key as used
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
bytes
|
Encryption key as bytes object |
required |
measure_latency ¶
! Measures the latency between two audio streams
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel0
|
Audio channel 0 |
required | |
channel1
|
Audio channel 1 |
required | |
include_pres_delay
|
Include presentation delay |
required | |
ts
|
Timestamp |
required |
Returns:
| Type | Description |
|---|---|
|
Array of latency results |
Source code in application/bluespy.py
play_to_audiopod_output ¶
! Playback audio file to audiopod
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
Audio file |
required | |
loop
|
Loop audio |
False
|
Source code in application/bluespy.py
reboot_moreph ¶
! Reboot Moreph hardware via USB or Ethernet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
serial
|
A serial number as an integer, or -1 to connect to the first device. The serial number shown in the software and on the MiniMoreph is hexadecimal, so should be entered as 0xNNNNNN. There is a serial number on the bottom of some Moreph30s is of the form AYYYY-XXXXX, the XXXXX is the required serial number in decimal. |
-1
|
Raises:
| Type | Description |
|---|---|
BluespyError
|
Exception in the bluespy library This function will cause the specified Moreph to disconnect - bluespy.connect(serial) needs to be called afterwards to talk to the Moreph again |
Source code in application/bluespy.py
set_cis_lc3_config ¶
set_cis_lc3_config(audio_id, codec_frames_per_SDU=1, presentation_delay_us=40000, octets_per_codec_frame=120, frame_duration_us=10000, sampling_frequency_Hz=48000, audio_channel_allocation=256)
! Set the config of a CIS stream
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio_id
|
CIS stream ID |
required | |
codec_frames_per_SDU
|
Codec Frames per SDU |
1
|
|
presentation_delay_us
|
Presentation Delay in μs |
40000
|
|
octets_per_codec_frame
|
Octets per Codec Frame |
120
|
|
frame_duration_us
|
Frame Duration in μs |
10000
|
|
sampling_frequency_Hz
|
Sample Rate in Hz |
48000
|
|
audio_channel_allocation
|
Audio Channel Allocation mask |
256
|
Returns:
| Type | Description |
|---|---|
|
Array of serial numbers |
Source code in application/bluespy.py
start_gui ¶
stop_audio ¶
stop_capture ¶
! Stop the current capture
Raises:
| Type | Description |
|---|---|
BluespyError
|
Exception in the bluespy library |
wait_until_next_logic_change ¶
! Waits until a logic line in the specified mask changes or until the given timeout period passes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
32 integer mask. logic lines corresponding to zero bits are ignored |
required | |
timeout
|
Timeout |
required | |
ts
|
Time to wait from |
required |
Returns:
| Type | Description |
|---|---|
|
A struct containing the new state, the line which switched, the time of the switch, and whether the logic state changed or the function timed out. True = Logic changed. False = Timeout |