Cracker
The Cracker module includes all operations on the device, such as device configuration, data transmission, and acquisition.
CrackerBasic
- class cracknuts.cracker.cracker_basic.ConfigBasic[source]
Bases:
object- __init__()[source]
- dump_to_json()[source]
Dump the configuration to a JSON string.
- Return type:
str
- load_from_json(json_str)[source]
Load configuration from a JSON string. If a value in the JSON string is null, it will be skipped, and the default configuration will be used.
- Return type:
ConfigBasic
- class cracknuts.cracker.cracker_basic.CrackerBasic(address=None, bin_server_path=None, bin_bitstream_path=None, operator_port=None)[source]
Bases:
ABC,Generic[T]- DISCONNECTED = -2
- NON_PROTOCOL_ERROR = -1
- __init__(address=None, bin_server_path=None, bin_bitstream_path=None, operator_port=None)[source]
- Parameters:
address (str | tuple | None) – Cracker device address (ip, port) or “[cnp://]<ip>[:port]”, If no configuration is provided here, it needs to be configured later by calling set_address, set_ip_port, or set_uri.
bin_server_path (str | None) – The bin_server (firmware) file for updates; normally, the user should not specify this.
bin_bitstream_path (str | None) – The bin_bitstream (firmware) file for updates; normally, the user should not specify this.
operator_port (
int) – The operator port to connect to.
- change_ip(new_ip, new_mask, new_gateway)[source]
Change the IP address of the device.
- Parameters:
new_ip (str) – The new IP address of the device.
new_mask (str) – The new IP address of the device.
new_gateway (str) – The new IP address of the device.
- Return type:
bool- Returns:
True if the IP address is changed, False otherwise.
- connect(update_bin=True, force_update_bin=False, bin_server_path=None, bin_bitstream_path=None, force_write_default_config=False)[source]
Connect to cracker device.
- Parameters:
update_bin (bool) – Whether to update the firmware.
force_update_bin (bool) – Whether to force update the firmware while the device is running normally (by default, firmware updates are not performed when the device is running normally).
bin_server_path (str | None) – The bin_server (firmware) file for updates.
bin_bitstream_path (str | None) – The bin_bitstream (firmware) file for updates.
force_write_default_config (bool) – Whether to force update the configuration while the device is running normally (by default, configuration updates are only performed when updating the firmware).
- Return type:
None- Returns:
None
- disconnect()[source]
Disconnect from cracker device.
- Return type:
None- Returns:
None
- dump_config(path=None)[source]
Dump the current config to a JSON file if a path is specified, or to a JSON string if no path is specified.
- Parameters:
path (str | None) – the path to the JSON file
- Returns:
the content of JSON string or None if no path is specified.
- Return type:
str | None
- get_address()[source]
Get the device address in tuple format.
- Returns:
address in tuple format: (ip, port).
- Return type:
tuple[str, int]
- get_bitstream_version()[source]
- get_connection_status()[source]
Get connection status.
- Returns:
True for connected and False for disconnected.
- Return type:
bool
- get_current_config()[source]
Get current configuration of Cracker. Note: Currently, the configuration returned is recorded on the host computer, not the ACTUAL configuration of the device. In the future, it should be synchronized from the device to the host computer.
- Returns:
Current configuration of Cracker.
- Return type:
ConfigBasic
- abstractmethod get_default_config()[source]
Get the default configuration. This method needs to be implemented by the specific device class, as different devices have different default configurations.
- Returns:
The default config object(The specific subclass of CommonConfig).
- Return type:
ConfigBasic
- get_firmware_info()[source]
- get_firmware_version()[source]
Get the version of the equipment.
- Returns:
The equipment response status code and the version of the equipment.
- Return type:
tuple[int, str | None]
- get_hardware_model()[source]
Get the name of the equipment.
- Returns:
The equipment response status code and the name of the equipment.
- Return type:
tuple[int, str | None]
- get_id()[source]
Get the ID of the equipment.
- Returns:
The equipment response status code and the ID of the equipment.
- Return type:
tuple[int, str | None]
- get_operator()[source]
Get the operator object for this Cracker instance.
- Returns:
Operator object.
- Return type:
Operator
- get_uri()[source]
Get the device address in URI format.
- Returns:
URI. if cracker address is not specified, None is returned.
- Return type:
str | None
- load_config_from_file(path)[source]
Load config from a JSON file.
- Parameters:
path (str) – the path to the JSON file
- Return type:
None- Returns:
None
- load_config_from_str(json_str)[source]
Load config from a JSON string.
- Parameters:
json_str (str) – the JSON string
- Return type:
None- Returns:
None
- osc_force()[source]
Force produce a wave data.
- Returns:
The device response status
- Return type:
tuple[int, None]
- osc_get_analog_wave(channel, offset, sample_count)[source]
Get the analog wave.
- Parameters:
channel (int|str) – The channel of the analog wave. It can be either 0, 1, or ‘A’, ‘B’.
offset (int) – the offset of the analog wave.
sample_count (int) – the sample count of the analog wave.
- Returns:
the analog wave.
- Return type:
tuple[int, np.ndarray]
- osc_get_digital_wave(channel, offset, sample_count)[source]
- Return type:
tuple[int,ndarray]
- osc_get_wave(channel, offset, sample_count)[source]
- Return type:
tuple[int,ndarray|None]
- osc_is_triggered()[source]
- Return type:
tuple[int,bool]
- osc_single()[source]
- Return type:
tuple[int,None]
- reconnect()[source]
Reconnect to cracker device.
- Returns:
None
- send_and_receive(message)[source]
Send message to cracker device.
- Parameters:
message (bytes) – The byte message to send.
- Returns:
Received message in format: (status, message).
- Return type:
tuple[int, bytes | None]
- send_with_command(command, rfu=0, payload=None)[source]
- Return type:
tuple[int,bytes|None]
- set_address(address)[source]
Set the device address in tuple format.
- Parameters:
address (tuple[str, int]) – address in tuple format: (ip, port).
- Return type:
None- Returns:
None
- set_ip_port(ip, port)[source]
Set the device IP address.
- Parameters:
ip (str) – IP address.
port (int) – Port.
- Return type:
None- Returns:
None
- set_logger_debug_payload_max_length(length)[source]
- set_logger_info_payload_max_length(length)[source]
- set_logging_level(level)[source]
Set the Cracker OS logging level.
- Parameters:
level (
str) – The logging level, debug, info, warning, error,- Return type:
None
- set_uri(uri)[source]
Set the device address in URI format.
- Parameters:
uri (str) – URI.
- Return type:
None- Returns:
None
- write_config_to_cracker(config)[source]
Sync config to cracker.
To prevent configuration inconsistencies between the host and the device, so all configuration information needs to be written to the device. User should call this function before get data from device.
NOTE: This function is currently ignored and will be resumed after all Cracker functions are completed.
CrackerS1
- class cracknuts.cracker.cracker_s1.CrackerS1(address=None, bin_server_path=None, bin_bitstream_path=None, operator_port=None)[source]
Bases:
CrackerBasic[ConfigS1]- digital_pin_mode(pin_num, mode)[source]
设置数字IO引脚工作模式
- Parameters:
pin_num (int) – 引脚编号,从0开始编号,支持 5,6 两个引脚
mode (int | str) – 引脚工作模式,1:输入模式,0:输出模式,或者 “INPUT”、”OUTPUT”
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- digital_read(pin_num)[source]
读取数字IO引脚电平状态
- Parameters:
pin_num (int) – 引脚编号,从0开始编号,支持 5,6 两个引脚
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None | int]
- digital_write(pin_num, value)[source]
设置数字IO引脚电平状态
- Parameters:
pin_num (int) – 引脚编号,从0开始编号,支持 5,6 两个引脚
value (int) – 引脚电平状态,1:高电平,0:
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- get_current_config()[source]
Get current configuration of Cracker. Note: Currently, the configuration returned is recorded on the host computer, not the ACTUAL configuration of the device. In the future, it should be synchronized from the device to the host computer.
- Returns:
Current configuration of Cracker.
- Return type:
ConfigBasic
- get_default_config()[source]
Get the default configuration. This method needs to be implemented by the specific device class, as different devices have different default configurations.
- Returns:
The default config object(The specific subclass of CommonConfig).
- Return type:
ConfigBasic
- i2c_config(dev_addr=None, speed=None, enable_stretch=False)[source]
配置 I2C。
- Parameters:
dev_addr (int) – 设备地址.
speed (serial.I2cSpeed) – 速度.
- Enable_stretch:
是否启用 stretch
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, None]
- i2c_disable()[source]
Disable the I2C
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, None]
- i2c_enable()[source]
Enable the I2C
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, None]
- i2c_receive(rx_count, is_trigger=False)[source]
通过i2c协议接收数据
is_trigger=True 时,rx_data传输开始时 Trigger 信号拉低,完毕后 Trigger 信号拉高
is_trigger=True:
TRIG: ───┐ ┌─── HIGH | | └────────────┘ LOW ┌────────────┐ │ rx_data │ └────────────┘is_trigger=False 时,Trigger 信号不变
is_trigger=False:
TRIG: ──────────────────── HIGH LOW ┌────────────┐ │ rx_data │ └────────────┘- Parameters:
rx_count (int) – 要接收数据的长度
is_trigger (
bool) – 在数据接收时是否产生触发信息(即:接收开始时拉低,结束时拉高)
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- i2c_reset()[source]
重置 I2C 配置。
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, None]
- i2c_transceive(tx_data, rx_count, is_trigger=False)[source]
通过I2C协议,无延迟的发送并接收数据.
is_trigger=True 时,tx_data传输开始时 Trigger 信号拉低,完毕后 Trigger 信号拉高 is_trigger=False是,trigger 信号不变
is_trigger=True:
TRIG: ───┐ ┌─── HIGH | | └─────────────────────────┘ LOW ┌────────────┬────────────┐ │ tx_data │ rx_data │ └────────────┴────────────┘is_trigger=False:
TRIG: ──────────────────────────────── HIGH LOW ┌────────────┬────────────┐ │ tx_data │ rx_data │ └────────────┴────────────┘- Parameters:
tx_data (str | bytes) – 待发送的数据
rx_count (int) – 接收数据的长度
is_trigger (bool) – 在数据接收时是否产生触发信息(即:接收开始时拉低,结束时拉高)
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- i2c_transmit(tx_data, is_trigger=False)[source]
通过i2c协议发送数据
is_trigger=True 时,tx_data传输开始时 Trigger 信号拉低,完毕后 Trigger 信号拉高
is_trigger=True:
TRIG: ───┐ ┌─── HIGH | | └────────────┘ LOW ┌────────────┐ │ tx_data │ └────────────┘is_trigger=False 时,Trigger 信号不变
is_trigger=False:
TRIG: ──────────────────── HIGH LOW ┌────────────┐ │ tx_data │ └────────────┘- Parameters:
tx_data (str | bytes) – 待发送的数据
is_trigger (
bool) – 在数据发送时是否产生触发信息(即:发送开始时拉低,结束时拉高)
- Return type:
tuple[int,None]
- i2c_transmit_delay_receive(tx_data, delay, rx_count, is_trigger=False)[source]
通过i2c协议发送并接收数据
is_trigger=True 时,tx_data传输开始时 Trigger 信号拉低,完毕后 Trigger 信号拉高 is_trigger=False是,trigger 信号不变
is_trigger=True:
TRIG: ───┐ ┌────────────┐ ┌─── HIGH | | | | └────────────┘ └────────────┘ LOW ┌────────────┬────────────┬────────────┐ │ tx_data │ delay │ rx_data │ └────────────┴────────────┴────────────┘is_trigger=False:
TRIG: ────────────────────────────────────────────── HIGH LOW ┌────────────┬────────────┬────────────┐ │ tx_data │ delay │ rx_data │ └────────────┴────────────┴────────────┘- Parameters:
tx_data (str | bytes) – 待发送的数据.
delay (int) – 发送和接收之间的间隔,单位是10纳秒。
rx_count (int) – 要接收的数据长度
is_trigger (bool) – 在数据接收时是否产生触发信息(即:接收开始时拉低,结束时拉高)
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- nut_clock_disable()[source]
Disable the nut clock.
- Returns:
The device response status
- Return type:
tuple[int, None]
- nut_clock_enable()[source]
Enable the nut clock.
- Returns:
The device response status
- Return type:
tuple[int, None]
- nut_clock_freq(clock)[source]
Set nut clock.
- Parameters:
clock (float | int | str) – The clock of the nut in kHz
- Returns:
The device response status
- Return type:
tuple[int, None]
- nut_reset(polar=0, time=10)[source]
复位nut芯片的RESET管脚,可配置复位电平极性,复位电平时间。默认RESET管脚为三态输入, 用户在测试板设计时需确保默认不复位(如默认上拉), 下发nut_reset()命令后,RESET管脚根据极性持续相应的复位时间。
polar=LOW TRIG: ~~~ ┐ ┌ ~~~ └────────────┘ LOW |<- time ->| polar=HIGH TRIG: ┌────────────┐ HIGH ~~~ ┘ └ ~~~ |<- time ->|- Parameters:
polar (int) – 极性 0 低电平,1 高电平
time (int) – 高低电平持续时间
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- nut_reset_io_enable(enable)[source]
- nut_timeout_ms(timeout)[source]
Set nut timeout.
- Parameters:
timeout (int) – Nut timeout.
- Returns:
The device response status
- Return type:
tuple[int, None]
- nut_voltage(voltage)[source]
Set nut voltage.
- Parameters:
voltage (float | str | int) – Nut voltage can be a number or a string. If the input is a float, the voltage will be treated as a V value. If the input is a string, you can specify the unit, ending with the value, using either mV or V.
- Returns:
The device response status
- Return type:
tuple[int, None]
- nut_voltage_disable()[source]
Disable the nut voltage.
- Returns:
The device response status
- Return type:
tuple[int, None]
- nut_voltage_enable()[source]
Enable the nut voltage.
- Returns:
The device response status
- Return type:
tuple[int, None]
- osc_analog_disable(channel)[source]
Disable osc analog.
- Parameters:
channel (int | str) – Channel to enable, it can be ‘A’ or ‘B’, or 0, 1
- Returns:
The device response status
- Return type:
tuple[int, None]
- osc_analog_enable(channel)[source]
Enable osc analog.
- Parameters:
channel (int | str) – Channel to enable, it can be ‘A’ or ‘B’, or 0, 1
- Returns:
The device response status
- Return type:
tuple[int, None]
- osc_analog_gain(channel, gain)[source]
Set analog gain.
- Parameters:
channel (int | str) – Analog channel, it can be ‘A’ or ‘B’, or 0, 1
gain (int) – Analog gain.
- Returns:
The device response status
- Return type:
tuple[int, None]
- osc_sample_clock(clock)[source]
Set osc sample rate
- Parameters:
clock (int | str) – The sample rate in kHz can be one of (65000, 48000, 24000, 12000, 8000) or a string in (65M, 48M, 24M, 12M, 8M).
- Returns:
The device response status
- Return type:
tuple[int, None]
- osc_sample_clock_phase(phase)[source]
Set sample phase.
- Parameters:
phase (int) – Sample phase.
- Returns:
The device response status
- Return type:
tuple[int, None]
- osc_sample_delay(delay)[source]
Set sample delay.
- Parameters:
delay (int) – Sample delay. It can be a number or a string, if the input is a string, you can specify the unit, ending with the value, using either ‘k’ (representing 1024) or ‘m’ (representing 1024^2). For example, “1k” means 1024 and “2m” means 2097152.
- Returns:
The device response status
- Return type:
tuple[int, None]
- osc_sample_length(length)[source]
Set sample length.
- Parameters:
length (int | str) – Sample length. It can be a number or a string, if the input is a string, you can specify the unit, ending with the value, using either ‘k’ (representing 1024) or ‘m’ (representing 1024^2). For example, “1k” means 1024 and “2m” means 2097152.
- Returns:
The device response status
- Return type:
tuple[int, None]
- osc_trigger_edge(edge)[source]
Set trigger edge.
- Parameters:
edge (int | str) – Trigger edge. (‘up’, ‘down’, ‘either’) or (‘u’, ‘d’, ‘e’) or 0, 1, 2 represent up, down, either, respectively.
- Returns:
The device response status
- Return type:
tuple[int, None]
- osc_trigger_level(edge_level)[source]
Set trigger edge level.
- Parameters:
edge_level (int) – Edge level.
- Returns:
The device response status
- Return type:
tuple[int, None]
- osc_trigger_mode(mode)[source]
Set trigger mode.
- Parameters:
mode (int | str) – Trigger mode. Trigger mode can be one of (“EDGE”, “PATTERN”) or (“E”, “P”), or the index of the string value.
- Returns:
The device response status
- Return type:
tuple[int, None]
- osc_trigger_source(source)[source]
Set trigger source.
- Parameters:
source (int | str) – Trigger source: It can be one of (‘N’, ‘A’, ‘B’, ‘P’, ‘R’, ‘V’) or (‘Nut’, ‘ChA’, ‘ChB’, ‘Protocol’, ‘Reset’, ‘Voltage’) or a number in 0 1 2 3 4 5 represent Nut, Channel A, Channel B, Protocol, Reset and Voltage respectively.
- Returns:
The device response status
- Return type:
tuple[int, None]
- register_read(base_address, offset)[source]
Read register.
- Parameters:
base_address (int) – Base address of the register.
offset (int) – Offset of the register.
- Returns:
The device response status and the value read from the register or None if an exception is raised.
- Return type:
tuple[int, bytes | None]
- register_write(base_address, offset, data)[source]
Write register.
- Parameters:
base_address (int) – Base address of the register.
offset (int) – Offset of the register.
data (
bytes|int|str) – Data to write.
- Returns:
The device response status
- Return type:
tuple[int, None]
- spi_config(speed=None, cpol=None, cpha=None, csn_auto=None, csn_delay=None)[source]
配置SPI接口参数。CPOL(时钟极性)和CPHA(时钟相位)
- Parameters:
speed (int) – 通信速率,默认10kHz,同CFG_PROTOCOL寄存器中PSC关系为:speed=(100×10^6)/(2*PSC)
cpol (serial.SpiCpol) – 时钟极性.
cpha (serial.SpiCpha) – 时钟相位.
csn_auto (bool,) – True,片选(Chip Select)信号只在数据通信时拉低。False,片选信号一直拉低。
csn_delay (
bool|None) – True,片选(Chip Select)信号在Delay过程中保持低电平。False,片选信号在Delay期间为高电平。
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, None]
- spi_disable()[source]
禁用 SPI
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, None]
- spi_enable()[source]
启用SPI
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, None]
- spi_receive(rx_count, dummy=b'\\x00', is_trigger=False)[source]
通过SPI接口读取rx_count个bytes型数据,根据 is_trigger 决定在数据接收后是否产生触发信号。
is_trigger=True 时,tx_data传输完毕后,Trigger 信号拉高
TRIG: ───┐ ┌─── HIGH | | └────────────┘ LOW ┌────────────┐ │ rx_data │ └────────────┘is_trigger=False 时,Trigger 信号不变
TRIG: ──────────────────── HIGH LOW ┌────────────┐ │ rx_data │ └────────────┘- Parameters:
rx_count (int) – 要读取数据字节长度。
dummy (bytes|str) – 需要在spi读取阶段发送的填充数据
is_trigger (bool) – 在数据发送时是否产生触发信息(即:发送开始时拉低,结束时拉高)
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。 Return None if an exception is caught.
- Return type:
tuple[int, bytes | None]
- spi_reset()[source]
复位SPI硬件。
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, None]
- spi_transceive(tx_data, rx_count=None, dummy=b'\\x00', is_trigger=False)[source]
通过SPI接口发送bytes型数据tx_data,默认返回与tx_data等长的数据
is_trigger=True 时,tx_data传输开始时 Trigger 信号拉低,完毕后 Trigger 信号拉高
TRIG: ───┐ ┌─── HIGH | | └────────────┘ LOW ┌────────────┐ │ tx_data │ └────────────┘ ┌────────────┐ │ rx_data │ └────────────┘is_trigger=False 时,Trigger 信号不变
TRIG: ──────────────────── HIGH LOW ┌────────────┐ │ tx_data │ └────────────┘ ┌────────────┐ │ rx_data │ └────────────┘- Parameters:
tx_data (str | bytes) – 要发送数据,bytes或十六进制字符串。
rx_count (int) – 接收数据的长度,默认与 tx_data长度一致,如果指定了该长度: 1. 发送数据长度小于接收数据长度时,自动在 tx_data后补充dummy数据 2. 如果接收数据长度小于发送数据长度,则函数自动把接收到的数据从头截取到 rx_count 长度
dummy (bytes | str) – 发送的填充数据
is_trigger (bool) – 在数据发送时是否产生触发信息(即:发送开始时拉低,结束时拉高)
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- spi_transceive_delay_transceive(tx_data1, tx_data2, is_delay, delay, is_trigger)[source]
通过SPI发送tx_data1,等待delay后(单位10ns),读取再发送tx_data2数据。
is_trigger=True 时,tx_data传输完毕后,Trigger 信号拉高
TRIG: ───┐ ┌────────────┐ ┌─── HIGH | | | | └────────────┘ └────────────┘ LOW ┌────────────┬────────────┬────────────┐ │ tx_data1 │ delay │ tx_data2 │ └────────────┴────────────┴────────────┘is_trigger=False 时,Trigger 信号不变
TRIG: ────────────────────────────────────────────── HIGH LOW ┌────────────┬────────────┬────────────┐ │ tx_data1 │ timeout │ rx_data2 │ └────────────┴────────────┴────────────┘- Parameters:
tx_data1 (str | bytes) – 第一阶段待发送数据。
tx_data2 (str | bytes) – 第二阶段待发送数据。
is_delay (bool) – 是否开启delay
delay (int) – 发送和接收之间的延时,单位10纳秒。
is_trigger (bool) – 在数据发送时是否产生触发信息(即:发送开始时拉低,结束时拉高)
- Returns:
Cracker设备响应状态和接收到的数据:(status, (response1, response2))。
- Return type:
tuple[int, bytes | None]
- spi_transmit(tx_data, is_trigger=False)[source]
通过SPI接口发送数据,并根据is_trigger决定在数据发送后是否产生触发信号。
is_trigger=True 时,tx_data传输完毕后,Trigger 信号拉高
TRIG: ───┐ ┌─── HIGH | | └────────────┘ LOW ┌────────────┐ │ tx_data │ └────────────┘is_trigger=False 时,Trigger 信号不变
TRIG: ──────────────────── HIGH LOW ┌────────────┐ │ tx_data │ └────────────┘- Parameters:
tx_data (str | bytes) – 待发送的数据
is_trigger (bool) – 在数据发送时是否产生触发信息(即:发送开始时拉低,结束时拉高)
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, None]
- spi_transmit_delay_receive(tx_data, delay, rx_count, dummy=b'\\x00', is_trigger=False)[source]
通过SPI发送bytes型数据tx_data,等待delay后(单位10ns),读取rx_count长度数据。其实现方式是在发送完数据后, 等待 delay 时间,master 再发送等于 rx_count 长度的dummy数据,master 解析此时 slave 发送来的数据作为 rx_data。
is_trigger=True 时,tx_data传输开始时 Trigger 信号拉低,完毕后 Trigger 信号拉高
TRIG: ───┐ ┌────────────┐ ┌─── HIGH | | | | └────────────┘ └────────────┘ LOW ┌────────────┬────────────┬────────────┐ MASTER │ tx_data │ delay │ dummy │ └────────────┴────────────┴────────────┘ ┌────────────┬────────────┬────────────┐ SLAVE │ dummy │ delay │ rx_data │ └────────────┴────────────┴────────────┘is_trigger=False 时,Trigger 信号不变
TRIG: ────────────────────────────────────────────── HIGH LOW ┌────────────┬────────────┬────────────┐ MASTER │ tx_data │ delay │ dummy │ └────────────┴────────────┴────────────┘ ┌────────────┬────────────┬────────────┐ SLAVE │ dummy │ delay │ rx_data │ └────────────┴────────────┴────────────┘- Parameters:
tx_data (str | bytes) – 待发送的数据。
delay (int) – 发送和接收之间的延时,单位10纳秒。
rx_count (int) – 要读取数据字节长度。
dummy (bytes|str) – 需要在spi读取阶段发送的填充数据
is_trigger (bool) – 在数据发送时是否产生触发信息(即:发送开始时拉低,结束时拉高)
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- uart_config(baudrate=None, bytesize=None, parity=None, stopbits=None)[source]
配置UART接口参数。
- Parameters:
baudrate (serial.Baudrate) – 波特率。
bytesize (serial.Bytesize) – 数据位长度。
parity (serial.Parity) – 校验方式。
stopbits (serial.Stopbits) – 停止位。
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, None]
- uart_disable()[source]
Deprecated since version 0.19.0: 此函数将在未来版本中移除,请使用`uart_io_disable`代替。
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- uart_enable()[source]
Deprecated since version 0.19.0: 此函数将在未来版本中移除,请使用`uart_io_enable`代替。
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- uart_io_disable()[source]
关闭UART通信接口,关闭后TX引脚、RX引脚置为三态输入状态。
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- uart_io_enable()[source]
” 使能UART通信接口,使能后TX引脚变为高电平,RX引脚置为三态输入状态。
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- uart_receive(rx_count, timeout=10000, is_trigger=False)[source]
通过UART接口接收数据,根据用户配置决定是否产生Trigger信号。
is_trigger=True 时,tx_data传输完毕后,Trigger 信号拉高
TRIG: ───┐ ┌─── HIGH | | └────────────┘ LOW ┌────────────┐ │ rx_data │ └────────────┘is_trigger=False 时,Trigger 信号不变
TRIG: ──────────────────── HIGH LOW ┌────────────┐ │ rx_data │ └────────────┘- Parameters:
rx_count (int) – 要接收数据长度。
timeout (int) – 超时时间,单位毫秒。
is_trigger (bool) – 接收完成时是否产生触发信号。 True:接收完成时,Trigger信号拉高, False:接收完成时,Trigger信号不变
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- uart_receive_fifo_clear()[source]
清除UART接收FIFO中剩余的所有数据。
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- uart_receive_fifo_dump()[source]
读取UART接收FIFO中剩余的所有数据。
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- uart_receive_fifo_remained()[source]
读取UART接收FIFO剩余未读字节数。
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, int]
- uart_reset()[source]
复位UART硬件逻辑。
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- uart_transmit(tx_data, is_trigger=False)[source]
通过UART接口发送数据,根据用户配置决定是否产生Trigger信号。
is_trigger=True 时,tx_data传输完毕后,Trigger 信号拉高
TRIG: ───┐ ┌─── HIGH | | └────────────┘ LOW ┌────────────┐ │ tx_data │ └────────────┘is_trigger=False 时,Trigger 信号不变
TRIG: ──────────────────── HIGH LOW ┌────────────┐ │ tx_data │ └────────────┘- Parameters:
tx_data (str | bytes) – 要发送数据,bytes或十六进制字符串。
is_trigger (bool) – 接收完成时是否产生触发信号。 True:接收完成时,Trigger信号拉高, False:接收完成时,Trigger信号不变
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- uart_transmit_receive(tx_data=None, rx_count=0, timeout=10000, is_trigger=False)[source]
通过UART接口发送数据,等待一段时间后,接收数据,根据用户配置决定是否产生Trigger信号。
is_trigger=True 时,tx_data传输完毕后,Trigger 信号拉高
TRIG: ───┐ ┌────────────┐ ┌─── HIGH | | | | └────────────┘ └────────────┘ LOW ┌────────────┬────────────┬────────────┐ │ tx_data │ process │ rx_data │ └────────────┴────────────┴────────────┘ | <------ timeout ------> |is_trigger=False 时,Trigger 信号不变
TRIG: ────────────────────────────────────────────── HIGH LOW ┌────────────┬────────────┬────────────┐ │ tx_data │ process │ rx_data │ └────────────┴────────────┴────────────┘ | <------ timeout ------> |- Parameters:
tx_data (str | bytes) – 要发送数据,bytes或十六进制字符串。
rx_count (int) – 要接收数据长度。
timeout (int) – 超时时间,单位毫秒。
is_trigger (bool) – 接收完成时是否产生触发信号。 True:接收完成时,Trigger信号拉高, False:接收完成时,Trigger信号不变
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- write_config_to_cracker(config)[source]
Sync config to cracker.
To prevent configuration inconsistencies between the host and the device, so all configuration information needs to be written to the device. User should call this function before get data from device.
NOTE: This function is currently ignored and will be resumed after all Cracker functions are completed.
CrackerG1
- class cracknuts.cracker.cracker_g1.CrackerG1(address=None, bin_server_path=None, bin_bitstream_path=None, operator_port=None)[source]
Bases:
CrackerS1- __init__(address=None, bin_server_path=None, bin_bitstream_path=None, operator_port=None)[source]
- Parameters:
address (str | tuple | None) – Cracker device address (ip, port) or “[cnp://]<ip>[:port]”, If no configuration is provided here, it needs to be configured later by calling set_address, set_ip_port, or set_uri.
bin_server_path (str | None) – The bin_server (firmware) file for updates; normally, the user should not specify this.
bin_bitstream_path (str | None) – The bin_bitstream (firmware) file for updates; normally, the user should not specify this.
operator_port (
int) – The operator port to connect to.
- get_current_config()[source]
Get current configuration of Cracker. Note: Currently, the configuration returned is recorded on the host computer, not the ACTUAL configuration of the device. In the future, it should be synchronized from the device to the host computer.
- Returns:
Current configuration of Cracker.
- Return type:
ConfigBasic
- get_default_config()[source]
Get the default configuration. This method needs to be implemented by the specific device class, as different devices have different default configurations.
- Returns:
The default config object(The specific subclass of CommonConfig).
- Return type:
ConfigBasic
- glitch_clock_arm()[source]
- glitch_clock_config(wave, wait, delay, repeat)[source]
- Return type:
tuple[int,None|bytes]
- glitch_clock_force()[source]
- glitch_clock_normal(wave)[source]
- Return type:
tuple[int,None|bytes]
- glitch_clock_normal_disable()[source]
- glitch_clock_normal_enable()[source]
- glitch_clock_reset()[source]
- glitch_gnd_arm()[source]
- glitch_gnd_config(wait, level, length, delay, repeat)[source]
- glitch_gnd_force()[source]
- glitch_gnd_normal(voltage)[source]
- Return type:
tuple[int,None]
- glitch_gnd_reset()[source]
- glitch_vcc_arm()[source]
设置glitch VCC 为armed状态。
- glitch_vcc_config(wait, level, length, delay, repeat)[source]
配置glitch
v_normal────┬───────────────────┐ ┌────────────┐ ┌─────── | wait | count | delay | count | | | | | | | └───────┘ └───────┘ <--------- level voltage | └────────────────────┘ Trigger repeat- Parameters:
wait (int) – glitch产生前等待时间(时钟个数)
level (int) – Glitch DAC电压值
length (
int) – Glitch持续时间, 单位 10nsrepeat (int) – Glitch重复次数
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- glitch_vcc_force()[source]
强制触发glitch VCC。
- glitch_vcc_normal(voltage)[source]
设置glitch VCC正常电压值。
- Return type:
tuple[int,None]
- glitch_vcc_reset()[source]
重置glitch VCC配置。
- nut_clock_freq(clock)[source]
Set nut clock.
- Parameters:
clock (int | str) – Clock frequency in kHz or string with unit ‘M’, e.g., ‘8M’ for 8000 kHz
- Returns:
The device response status
- Return type:
tuple[int, None]
- nut_voltage(voltage)[source]
Set nut voltage.
- Parameters:
voltage (float | str | int) – Nut voltage can be a number or a string. If the input is a float, the voltage will be treated as a V value. If the input is a string, you can specify the unit, ending with the value, using either mV or V.
- Returns:
The device response status
- Return type:
tuple[int, None]
- write_config_to_cracker(config)[source]
Sync config to cracker.
To prevent configuration inconsistencies between the host and the device, so all configuration information needs to be written to the device. User should call this function before get data from device.
NOTE: This function is currently ignored and will be resumed after all Cracker functions are completed.
CrackerO1
- class cracknuts.cracker.cracker_o1.CrackerO1(address=None, bin_server_path=None, bin_bitstream_path=None, operator_port=None)[source]
Bases:
CrackerG1- __init__(address=None, bin_server_path=None, bin_bitstream_path=None, operator_port=None)[source]
Cracker O1 设备接口类。
- digital_pin_mode(pin_id, mode)[source]
设置数字IO引脚工作模式
- Parameters:
pin_id (str) – 引脚ID, 支持 GP0-GP7, GP21-GP27, A, A2-A5, IO2-IO9
mode (int | str) – 引脚工作模式,1:输入模式,0:输出模式,或者 “INPUT”、”OUTPUT”
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- digital_read(pin_id)[source]
读取数字IO引脚电平状态,高电平需要大于 1.4v
- Parameters:
pin_id (str) – 引脚ID, 支持 GP0-GP7, GP21-GP27, A, A2-A5, IO2-IO9
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None | int]
- digital_write(pin_id, value)[source]
设置数字IO引脚电平状态
- Parameters:
pin_id (str) – 引脚ID, 支持 GP0-GP7, GP21-GP27, A, A2-A5, IO2-IO9
value (int) – 引脚电平状态,1:高电平,0:
- Returns:
Cracker设备响应状态和接收到的数据:(status, response)。
- Return type:
tuple[int, bytes | None]
- get_switch_status(switch_id)[source]
获取开关状态
- Parameters:
switch_id (str) – 开关ID,’pl’或’ps’
- Return type:
tuple[int,None|tuple[int,int]]- Returns:
(status, (sw1, sw2)),其中status为协议状态码, sw1和sw2分别为开关的两个状态位, 0表示开关关闭,1表示开关打开
- get_switch_status_pl()[source]
获取PL开关状态 :rtype:
tuple[int,None|tuple[int,int]] :return: (status, (sw1, sw2)),其中status为协议状态码,sw1和sw2分别为PL开关的两个状态位, 0表示开关关闭,1表示开关打开
- get_switch_status_ps()[source]
获取PS开关状态 :rtype:
tuple[int,None|tuple[int,int]] :return: (status, (sw1, sw2)),其中status为协议状态码,sw1和sw2分别为PS开关的两个状态位, 0表示开关关闭,1表示开关打开
- get_voltage_a0()[source]
获取测量点a0电压
- get_voltage_a1()[source]
获取测量点a1电压
- set_led_content(t, x, y, c, w=None)[source]
设置LED显示内容
- Parameters:
t (
int) – 显示内容类型,0表示文本,1表示图片x (
int) – 显示内容的x坐标,单位为像素y (
int) – 显示内容的y坐标,单位为像素c (
bytes) – 显示内容,文本类型为UTF-8编码的字符串,图片类型为RGB888格式的字节数组w (
int) – 显示内容的宽度,单位为像素,文本类型为内容的像素宽度,图片类型为图片的宽度
- Return type:
None
- set_led_image(image_path, x=0, y=0, fit=True)[source]
设置LED显示图片
- Parameters:
image_path (
str) – 图片文件路径,支持常见格式如PNG、JPEG等x (
int) – 显示图片的x坐标,单位为像素y (
int) – 显示图片的y坐标,单位为像素fit (
bool) – 是否强制缩放图片至64x64像素 - True: 无论原图大小,统一缩放至64x64。 - False: 保持原图尺寸,不进行缩放。
- Return type:
None
- set_led_text(text, x=0, y=0, auto_wrap=True)[source]
设置LED显示文本,仅支持英文字符显示。字符宽度为5像素,高度为6像素,字符间距为1像素。 屏幕分辨率为64x64像素,坐标原点在屏幕左上角,x坐标向右增加,y坐标向下增加。
- Parameters:
text (
str) – 显示文本内容x (
int) – 显示文本的x坐标,单位为像素y (
int) – 显示文本的y坐标,单位为像素。 注意,坐标表示文本基线的位置,即文本的底部位置。所以如果要显示完整的一行文字,则要设置y为6(字符高度为6)
- Return type:
None
- set_pwm(freq, duty_cycle)[source]
设置PWM输出, GP29引脚 :type freq: :param freq: PWM频率,单位Hz :type duty_cycle: :param duty_cycle: PWM占空比,0-1之间的小数
- set_waveform_arbitrary(wave)[source]
设置波形发生器输出波形。
- Parameters:
wave (list[float]) – 单组波形的电压采样点序列(单位:伏特 V)。列表中每个元素表示一个离散采样点的输出电压值。 - 单个采样点时间间隔: 100 ns(对应 10 MHz 的采样率) - 波形按照数组顺序依次输出 - 一个数组表示一个完整周期的波形
- Returns:
执行状态码与设备返回数据。
- Return type:
tuple[int, None | bytes]
- set_waveform_dc(voltage)[source]
设置直流电压输出。
- Parameters:
voltage (float) – 输出直流电压(Volt)。电压值必须在设备允许的输出范围内,且不得为负值。
- Returns:
设备返回状态与响应数据。
- Return type:
tuple[int, None | bytes]
- set_waveform_from_file(file_path)[source]
从文件加载波形数据并设置输出波形。
文件内容应为电压采样点序列(单位:伏特 V), 支持逗号分隔或逐行排列的数值格式。 采样点数量最大不得超过 160 个。
- Parameters:
file_path (str) – 包含波形数据的文本文件路径。 文件中每个数值表示一个电压采样点(单位 V)。
- Returns:
设备返回状态与响应数据。
- Return type:
tuple[int, None | bytes]
- set_waveform_sawtooth(frequency, *, vpp=1.0, slope=1.0, phase=0.0, offset=None)[source]
设置锯齿波输出。
- Parameters:
frequency (float) – 输出频率(Hz)。
vpp (float, optional) – 峰峰值电压(Volt)。
slope (float, optional) – 上升段占整个周期的比例(0~1)。 - 1.0 → 标准锯齿波(慢上升,快下降) - 0.5 → 对称三角波 - 接近 0 → 快速上升,慢下降
phase (float, optional) – 初始相位(弧度 rad)。
offset (float or None, optional) – 直流偏置电压(Volt)。
- Default vpp:
1.0
- Default slope:
1.0
- Default phase:
0.0
- Returns:
设备返回状态与响应数据。
- Return type:
tuple[int, None | bytes]
- set_waveform_sine(frequency, *, vpp=1.0, phase=0.0, offset=None)[source]
设置正弦波输出。
- Parameters:
frequency (float or str) – 输出频率(Hz)。支持数值或带单位的字符串形式,例如 1e6、1m、”1MHz”、”10kHz”。
vpp (float, optional) – 峰峰值电压(Volt)。
phase (float, optional) – 初始相位(弧度 rad)。
offset (float or None, optional) – 直流偏置电压(Volt)。若为 None,默认自动设置为 vpp / 2 以避免负电压。
- Default vpp:
1.0
- Default phase:
0.0
- Returns:
设备返回状态与响应数据。
- Return type:
tuple[int, None | bytes]
- set_waveform_square(frequency, *, duty=0.5, vpp=1.0, phase=0.0, offset=None)[source]
设置方波输出。
- Parameters:
frequency (float) – 输出频率(Hz)。
duty (float, optional) – 占空比(0~1)。 - 0.5 表示标准 50% 方波 - 0.2 表示高电平占 20% 周期
vpp (float, optional) – 峰峰值电压(Volt)。
phase (float, optional) – 初始相位(弧度 rad)。
offset (float or None, optional) – 直流偏置电压(Volt)。
- Default duty:
0.5
- Default vpp:
1.0
- Default phase:
0.0
- Returns:
设备返回状态与响应数据。
- Return type:
tuple[int, None | bytes]
- set_waveform_standard(waveform, vpp, *, frequency=None, offset=None, duty=0.5, phase=0.0)[source]
设置标准波形输出。
本函数根据指定参数在软件中生成 单周期波形数据,并写入设备任意波形缓冲区,由 DAC 循环播放该波形。
支持波形类型:
"dc":直流电压"sine":正弦波"square":方波"triangle":三角波"sawtooth":锯齿波(可调坡度)
- Parameters:
waveform (str) – 波形类型名称(大小写不敏感)。
vpp (float) – 峰峰值电压(Volt)。对于非 DC 波形,振幅 amplitude = vpp / 2。
frequency (float, str, or None, optional) – 输出频率(Hz)。对
"dc"可省略,其他波形必须指定。 支持数值或带单位字符串(例如 1e6、”1MHz”、”100kHz”)。offset (float or None, optional) – 直流偏置电压(Volt)。若为 None,默认 offset = vpp / 2,保证波形非负。
duty (float, optional) –
波形占空比 / 坡度参数(0~1)。 -
square:高电平占周期比例 -sawtooth:上升段占周期比例接近 1 → 慢上升 + 快下降(标准锯齿波)
0.5 → 对称三角波
接近 0 → 快速上升 + 慢下降
对
sine与triangle无作用
phase (float, optional) – 初始相位(弧度 rad)。数学定义:2π rad = 1 个周期
- Default duty:
0.5
- Default phase:
0.0
- Returns:
执行状态码与设备返回数据。
- Return type:
tuple[int, None | bytes]
- set_waveform_triangle(frequency, *, vpp=1.0, phase=0.0, offset=None)[source]
设置三角波输出。
- Parameters:
frequency (float) – 输出频率(Hz)。
vpp (float, optional) – 峰峰值电压(Volt)。
phase (float, optional) – 初始相位(弧度 rad)。
offset (float or None, optional) – 直流偏置电压(Volt)。
- Default vpp:
1.0
- Default phase:
0.0
- Returns:
设备返回状态与响应数据。
- Return type:
tuple[int, None | bytes]