本文整理汇总了Python中ustruct.pack方法的典型用法代码示例。如果您正苦于以下问题:Python ustruct.pack方法的具体用法?Python ustruct.pack怎么用?Python ustruct.pack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ustruct
的用法示例。
在下文中一共展示了ustruct.pack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _write_header
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import pack [as 别名]
def _write_header(self, initlength):
assert not self._headerwritten
self._file.write(b'RIFF')
if not self._nframes:
self._nframes = initlength // (self._nchannels * self._sampwidth)
self._datalength = self._nframes * self._nchannels * self._sampwidth
try:
self._form_length_pos = self._file.tell()
except (AttributeError, OSError):
self._form_length_pos = None
self._file.write(struct.pack('<L4s4sLHHLLHH4s',
36 + self._datalength, b'WAVE', b'fmt ', 16,
WAVE_FORMAT_PCM, self._nchannels, self._framerate,
self._nchannels * self._framerate * self._sampwidth,
self._nchannels * self._sampwidth,
self._sampwidth * 8, b'data'))
if self._form_length_pos is not None:
self._data_length_pos = self._file.tell()
self._file.write(struct.pack('<L', self._datalength))
self._headerwritten = True
示例2: fill_rectangle
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import pack [as 别名]
def fill_rectangle(self, x, y, w, h, color=None):
x = min(self.width - 1, max(0, x))
y = min(self.height - 1, max(0, y))
w = min(self.width - x, max(1, w))
h = min(self.height - y, max(1, h))
if color:
color = ustruct.pack(">H", color)
else:
color = self._colormap[0:2] #background
for i in range(_CHUNK):
self._buf[2*i]=color[0]; self._buf[2*i+1]=color[1]
chunks, rest = divmod(w * h, _CHUNK)
self._writeblock(x, y, x + w - 1, y + h - 1, None)
if chunks:
for count in range(chunks):
self._data(self._buf)
if rest != 0:
mv = memoryview(self._buf)
self._data(mv[:rest*2])
示例3: acc_update
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import pack [as 别名]
def acc_update(self):
#accel = pyb.Accel()
#axis_x, axis_y, axis_z = accel.x(), accel.y(), accel.z()
axis_x, axis_y, axis_z = (
urandom.randint(0, 32767) % X_OFFSET,
urandom.randint(0, 32767) % Y_OFFSET,
urandom.randint(0, 32767) % Z_OFFSET)
buffer = ustruct.pack(
"<HHH",
axis_x, axis_y, axis_z)
result = self.aci_gatt_update_char_value(
serv_handle=self.acc_serv_handle,
char_handle=self.acc_char_handle,
char_val_offset=0,
char_value_len=len(buffer),
char_value=buffer).response_struct
if result.status != BLE_STATUS_SUCCESS:
raise ValueError("aci_gatt_update_char_value status: {:02x}".format(
result.status))
log.debug("aci_gatt_update_char_value %02x", result.status)
示例4: temp_update
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import pack [as 别名]
def temp_update(self):
tick = utime.time()
buffer = ustruct.pack(
"<HB",
tick,
(270 + urandom.randint(0, 32767)))
result = self.aci_gatt_update_char_value(
serv_handle=self.hw_serv_handle,
char_handle=self.temperature_bluest_char_handle,
char_val_offset=0,
char_value_len=len(buffer),
char_value=buffer).response_struct
if result.status != status.BLE_STATUS_SUCCESS:
raise ValueError("aci_gatt_update_char_value status: {:02x}".format(
result.status))
log.debug("aci_gatt_update_char_value %02x", result.status)
示例5: pwr_update
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import pack [as 别名]
def pwr_update(self):
tick = utime.time()
chg = urandom.randint(0, 100)
voltage = urandom.randint(0, 100)
current = urandom.randint(0, 100)
npwrstat = urandom.randint(0, 100)
buffer = ustruct.pack(
"<HHHHB",
tick,
chg, voltage, current, npwrstat)
result = self.aci_gatt_update_char_value(
serv_handle=self.hw_serv_handle,
char_handle=self.pwr_bluest_char_handle,
char_val_offset=0,
char_value_len=len(buffer),
char_value=buffer).response_struct
if result.status != status.BLE_STATUS_SUCCESS:
raise ValueError("aci_gatt_update_char_value status: {:02x}".format(
result.status))
log.debug("aci_gatt_update_char_value %02x", result.status)
示例6: press_update
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import pack [as 别名]
def press_update(self):
tick = utime.time()
buffer = ustruct.pack(
"<HI",
tick,
100000 + urandom.randint(0, 32767))
result = self.aci_gatt_update_char_value(
serv_handle=self.hw_serv_handle,
char_handle=self.pressure_bluest_char_handle,
char_val_offset=0,
char_value_len=len(buffer),
char_value=buffer).response_struct
if result.status != status.BLE_STATUS_SUCCESS:
raise ValueError("aci_gatt_update_char_value status: {:02x}".format(
result.status))
log.debug("aci_gatt_update_char_value %02x", result.status)
示例7: aci_gap_set_limited_discoverable
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import pack [as 别名]
def aci_gap_set_limited_discoverable(
self, adv_type=0, adv_interv_min=0, adv_interv_max=0,
own_addr_type=0, adv_filter_policy=0, local_name_len=0,
local_name=b'', service_uuid_len=0, service_uuid_list=b'',
slave_conn_interv_min=0, slave_conn_interv_max=0):
"""aci_gap_set_limited_discoverable"""
data = ustruct.pack(
"<BHHBBB{:d}sB{:d}sHH".format(local_name_len, service_uuid_len),
adv_type, adv_interv_min, adv_interv_max,
own_addr_type,
adv_filter_policy,
local_name_len,
local_name,
service_uuid_len,
service_uuid_list,
slave_conn_interv_min, slave_conn_interv_max)
hci_cmd = HCI_COMMAND(
ogf=OGF_VENDOR_CMD,
ocf=OCF_GAP_SET_LIMITED_DISCOVERABLE,
data=data)
self.hci_send_cmd(hci_cmd)
return hci_cmd
示例8: aci_gap_set_discoverable
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import pack [as 别名]
def aci_gap_set_discoverable(
self, adv_type=0, adv_interv_min=0, adv_interv_max=0,
own_addr_type=0, adv_filter_policy=0, local_name_len=0,
local_name=b'', service_uuid_len=0, service_uuid_list=b'',
slave_conn_interv_min=0, slave_conn_interv_max=0):
"""aci_gap_set_discoverable"""
data = ustruct.pack(
"<BHHBBB{:d}sB{:d}sHH".format(local_name_len, service_uuid_len),
adv_type, adv_interv_min, adv_interv_max,
own_addr_type, adv_filter_policy,
local_name_len,
local_name,
service_uuid_len,
service_uuid_list,
slave_conn_interv_min, slave_conn_interv_max)
hci_cmd = HCI_COMMAND(
ogf=OGF_VENDOR_CMD,
ocf=OCF_GAP_SET_DISCOVERABLE,
data=data)
self.hci_send_cmd(hci_cmd)
return hci_cmd
示例9: aci_gap_set_auth_requirement
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import pack [as 别名]
def aci_gap_set_auth_requirement(
self, mitm_mode=0, oob_enable=False, oob_data=b'',
min_encryption_key_size=0, max_encryption_key_size=0,
use_fixed_pin=False, fixed_pin=0, bonding_mode=0):
"""aci_gap_set_auth_requirement"""
data = ustruct.pack(
"<BB16sBBBIB",
mitm_mode, int(oob_enable), oob_data,
min_encryption_key_size, max_encryption_key_size,
int(use_fixed_pin), fixed_pin, bonding_mode)
hci_cmd = HCI_COMMAND(
ogf=OGF_VENDOR_CMD,
ocf=OCF_GAP_SET_AUTH_REQUIREMENT,
data=data)
self.hci_send_cmd(hci_cmd)
return hci_cmd
示例10: aci_gap_start_name_discovery_proc
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import pack [as 别名]
def aci_gap_start_name_discovery_proc(
self, scan_interval=0, scan_window=0, peer_bdaddr_type=0,
peer_bdaddr=b'', own_bdaddr_type=0, conn_min_interval=0,
conn_max_interval=0, conn_latency=0, supervision_timeout=0,
min_conn_length=0, max_conn_length=0):
"""aci_gap_start_name_discovery_proc"""
data = ustruct.pack(
"<HHB6sBHHHHHH",
scan_interval, scan_window,
peer_bdaddr_type, peer_bdaddr, own_bdaddr_type,
conn_min_interval, conn_max_interval, conn_latency,
supervision_timeout, min_conn_length, max_conn_length)
hci_cmd = HCI_COMMAND(
ogf=OGF_VENDOR_CMD,
ocf=OCF_GAP_START_NAME_DISCOVERY_PROC,
data=data,
evtcode=EVT_CMD_STATUS)
self.hci_send_cmd(hci_cmd)
return hci_cmd
示例11: aci_gap_start_auto_conn_establish_proc_IDB05A1
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import pack [as 别名]
def aci_gap_start_auto_conn_establish_proc_IDB05A1(
self, scan_interval=0, scan_window=0, own_bdaddr_type=0,
conn_min_interval=0, conn_max_interval=0, conn_latency=0,
supervision_timeout=0, min_conn_length=0, max_conn_length=0,
num_whitelist_entries=0, addr_array=b''):
"""aci_gap_start_auto_conn_establish_proc_IDB05A1"""
data = ustruct.pack(
"<HHBHHHHHHB{:d}s".format(num_whitelist_entries * 7),
scan_interval, scan_window,
own_bdaddr_type,
conn_min_interval, conn_max_interval, conn_latency,
supervision_timeout,
min_conn_length, max_conn_length,
num_whitelist_entries,
addr_array)
hci_cmd = HCI_COMMAND(
ogf=OGF_VENDOR_CMD,
ocf=OCF_GAP_START_AUTO_CONN_ESTABLISH_PROC,
data=data,
evtcode=EVT_CMD_STATUS)
self.hci_send_cmd(hci_cmd)
return hci_cmd
示例12: aci_gap_start_auto_conn_establish_proc_IDB04A1
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import pack [as 别名]
def aci_gap_start_auto_conn_establish_proc_IDB04A1(
self, scan_interval=0, scan_window=0, own_bdaddr_type=0,
conn_min_interval=0, conn_max_interval=0, conn_latency=0,
supervision_timeout=0, min_conn_length=0, max_conn_length=0,
use_reconn_addr=False, reconn_addr=b'', num_whitelist_entries=0,
addr_array=b''):
"""aci_gap_start_auto_conn_establish_proc_IDB04A1"""
data = ustruct.pack(
"<HHBHHHHHHB6sB{:d}s".format(num_whitelist_entries * 7),
scan_interval, scan_window,
own_bdaddr_type,
conn_min_interval, conn_max_interval, conn_latency,
supervision_timeout,
min_conn_length, max_conn_length,
int(use_reconn_addr), reconn_addr,
num_whitelist_entries,
addr_array)
hci_cmd = HCI_COMMAND(
ogf=OGF_VENDOR_CMD,
ocf=OCF_GAP_START_AUTO_CONN_ESTABLISH_PROC,
data=data,
evtcode=EVT_CMD_STATUS)
self.hci_send_cmd(hci_cmd)
return hci_cmd
示例13: aci_gap_start_general_conn_establish_proc_IDB04A1
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import pack [as 别名]
def aci_gap_start_general_conn_establish_proc_IDB04A1(
self, scan_type=0, scan_interval=0, scan_window=0,
own_address_type=0, filter_duplicates=False, reconn_addr=b''):
"""aci_gap_start_general_conn_establish_proc_IDB04A1"""
data = ustruct.pack(
"<BHHBB6s",
scan_type, scan_interval, scan_window,
own_address_type, int(filter_duplicates),
reconn_addr)
hci_cmd = HCI_COMMAND(
ogf=OGF_VENDOR_CMD,
ocf=OCF_GAP_START_GENERAL_CONN_ESTABLISH_PROC,
data=data,
evtcode=EVT_CMD_STATUS)
self.hci_send_cmd(hci_cmd)
return hci_cmd
示例14: aci_gap_start_selective_conn_establish_proc
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import pack [as 别名]
def aci_gap_start_selective_conn_establish_proc(
self, scan_type=0, scan_interval=0, scan_window=0,
own_address_type=0, filter_duplicates=False,
num_whitelist_entries=0, addr_array=b''):
"""aci_gap_start_selective_conn_establish_proc"""
data = ustruct.pack(
"<BHHBBB{:d}s".format(num_whitelist_entries * 7),
scan_type, scan_interval, scan_window, own_address_type,
int(filter_duplicates), num_whitelist_entries, addr_array)
hci_cmd = HCI_COMMAND(
ogf=OGF_VENDOR_CMD,
ocf=OCF_GAP_START_SELECTIVE_CONN_ESTABLISH_PROC,
data=data,
evtcode=EVT_CMD_STATUS)
self.hci_send_cmd(hci_cmd)
return hci_cmd
示例15: aci_gap_create_connection
# 需要导入模块: import ustruct [as 别名]
# 或者: from ustruct import pack [as 别名]
def aci_gap_create_connection(
self, scan_interval=0, scan_window=0, peer_bdaddr_type=0,
peer_bdaddr=b'', own_bdaddr_type=0, conn_min_interval=0,
conn_max_interval=0, conn_latency=0, supervision_timeout=0,
min_conn_length=0, max_conn_length=0):
"""aci_gap_create_connection"""
data = ustruct.pack(
"<HHB6sBHHHHHH",
scan_interval, scan_window,
peer_bdaddr_type, peer_bdaddr,
own_bdaddr_type,
conn_min_interval, conn_max_interval, conn_latency,
supervision_timeout,
min_conn_length, max_conn_length)
hci_cmd = HCI_COMMAND(
ogf=OGF_VENDOR_CMD,
ocf=OCF_GAP_CREATE_CONNECTION,
data=data,
evtcode=EVT_CMD_STATUS)
self.hci_send_cmd(hci_cmd)
return hci_cmd