def connect(address, address_type, initiating_phy): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.LE_GAP.value MSG_ID = 0x1a payload = address_to_bytes(address) + pack('<BB', address_type, initiating_phy) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def set_parameters(connection, min_interval, max_interval, latency, timeout): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.LE_CONNECTION.value MSG_ID = 0x00 payload = pack('<BHHHH', connection, min_interval, max_interval, latency, timeout) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def send_characteristic_notification(connection, characteristic, value): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.GATT_SERVER.value MSG_ID = 0x05 payload = pack('<BHB', connection, characteristic, len(value)) + bytes(value) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def read_multiple_characteristic_values(connection, characteristic_list): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.GATT.value MSG_ID = 0x11 payload = pack( '<B', connection) + characteristic_list_to_bytes(characteristic_list) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def send(port, confirmed, data_value): MSG_TYPE = MessageType.LORA_COMMAND_RESPONSE.value MSG_CLASS = MessageClass.DATA.value MSG_ID = MessageId.SEND.value payload = pack('<BBB', port, confirmed, len(data_value)) + bytes(data_value) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def write_characteristic_value(connection, characteristic, value): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.GATT.value MSG_ID = 0x09 payload = pack('<BHB', connection, characteristic, len(value)) + bytes(value) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def read_characteristic_value_from_offset(connection, characteristic, offset, maxlen): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.GATT.value MSG_ID = 0x12 payload = pack('<BHHH', connection, characteristic, offset, maxlen) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def send_user_read_response(connection, characteristic, att_errorcode, value): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.GATT_SERVER.value MSG_ID = 0x03 payload = pack('<BHBB', connection, characteristic, att_errorcode, len(value)) + bytes(value) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def prepare_characteristic_value_reliable_write(connection, characteristic, offset, value): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.GATT.value MSG_ID = 0x13 payload = pack('<BHHB', connection, characteristic, offset, len(value)) + bytes(value) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def set_advertise_timing(handle, interval_min, interval_max, duration, maxevents): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.LE_GAP.value MSG_ID = 0x0e payload = pack('<BIIHB', handle, interval_min, interval_max, duration, maxevents) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def join_mode(mode): MSG_TYPE = MessageType.LORA_COMMAND_RESPONSE.value MSG_CLASS = MessageClass.DATA.value MSG_ID = MessageId.JOIN_MODE.value payload = pack('<B', mode) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def confirm_status(): MSG_TYPE = MessageType.LORA_COMMAND_RESPONSE.value MSG_CLASS = MessageClass.DATA.value MSG_ID = MessageId.CONFIRM_STATUS.value payload = b'' return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def read(): MSG_TYPE = MessageType.LORA_COMMAND_RESPONSE.value MSG_CLASS = MessageClass.DATA.value MSG_ID = MessageId.READ.value payload = b'' return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def message_to_target(data): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.USER.value MSG_ID = 0x00 payload = pack('<B', len(data)) + bytes(data) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def find_included_services(connection, service): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.GATT.value MSG_ID = 0x10 payload = pack('<BI', connection, service) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def read_characteristic_value(connection, characteristic): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.GATT.value MSG_ID = 0x07 payload = pack('<BH', connection, characteristic) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def set_tx_power(power): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.SYSTEM.value MSG_ID = 0x0a payload = pack('<H', power) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def set_bt_address(address): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.SYSTEM.value MSG_ID = 0x04 payload = address_to_bytes(address) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def set_device_name(type, name): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.SYSTEM.value MSG_ID = 0x0d payload = pack('<BB', type, len(name)) + bytes(name) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def discover_characteristics(connection, service): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.GATT.value MSG_ID = 0x03 payload = pack('<BI', connection, service) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def reset(dfu): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.SYSTEM.value MSG_ID = 0x01 payload = pack('<B', dfu) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def set_phy(connection, phy): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.LE_CONNECTION.value MSG_ID = 0x03 payload = pack('<BB', connection, phy) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def get_random_data(length): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.SYSTEM.value MSG_ID = 0x0b payload = pack('<B', length) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def get_counters(reset): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.SYSTEM.value MSG_ID = 0x0f payload = pack('<B', reset) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def disable_slave_latency(connection, disable): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.LE_CONNECTION.value MSG_ID = 0x02 payload = pack('<BB', connection, disable) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def get_bt_address(): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.SYSTEM.value MSG_ID = 0x03 payload = b'' return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def halt(halt): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.SYSTEM.value MSG_ID = 0x0c payload = pack('<B', halt) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def read_characteristic_value_by_uuid(connection, service, uuid): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.GATT.value MSG_ID = 0x08 payload = pack('<BI', connection, service) + uuid_to_bytes(uuid) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def close(connection): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.LE_CONNECTION.value MSG_ID = 0x04 payload = pack('<B', connection) return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)
def hello(): MSG_TYPE = MessageType.COMMAND_RESPONSE.value MSG_CLASS = MessageClass.SYSTEM.value MSG_ID = 0x00 payload = b'' return command(MSG_TYPE, MSG_CLASS, MSG_ID, payload)