|
| 1 | +import _bluetooth |
| 2 | +# 需要额外注意类型转换 |
| 3 | + |
| 4 | +class BLE(_bluetooth.BLE): |
| 5 | + # last_adv_data = "" #广播内容 |
| 6 | + # last_resp_data = "" #回应扫描内容 |
| 7 | + # addr_mode = "" #地址类型 |
| 8 | + # def __init__(self): |
| 9 | + # super().__init__() |
| 10 | + # pass |
| 11 | + |
| 12 | + def test(self): |
| 13 | + pass |
| 14 | + |
| 15 | + def active(self): |
| 16 | + # _bluetooth.BLE.active(self) |
| 17 | + # a = _bluetooth.BLE() |
| 18 | + # a.active() |
| 19 | + _ = super().active() |
| 20 | + # self.active() |
| 21 | + return print("bluetooth active") |
| 22 | + |
| 23 | + # def config(self,param_name, /): |
| 24 | + # if(param_name=="mac"): |
| 25 | + # pass |
| 26 | + # elif(param_name=="addr_mode"): |
| 27 | + # pass |
| 28 | + # elif(param_name=="gap_name"): |
| 29 | + # pass |
| 30 | + # elif(param_name=="rxbuf"): |
| 31 | + # pass |
| 32 | + # elif(param_name=="mtu"): |
| 33 | + # pass |
| 34 | + # elif(param_name=="bond"): |
| 35 | + # pass |
| 36 | + # elif(param_name=="mitm"): |
| 37 | + # pass |
| 38 | + # elif(param_name=="io"): |
| 39 | + # pass |
| 40 | + # elif(param_name=="le_secire"): |
| 41 | + # pass |
| 42 | + # else: |
| 43 | + # print("there is not params") |
| 44 | + |
| 45 | + # def config(self,*, mac,addr_mode,gap_name,rxbuf,mtu,bond,mitm,io,le_secire=False): |
| 46 | + # if gap_name != None: |
| 47 | + # super.config_name_update(gap_name) |
| 48 | + |
| 49 | + # # TODO:如何进行事件处理函数 |
| 50 | + # def irq(): |
| 51 | + # pass |
| 52 | + |
| 53 | + # """ |
| 54 | + # interval_us:广告间隔时间, 为none则停止广播 |
| 55 | + # adv_data: 包含在所有广播中, 是任何实现缓冲协议的类型(例如bytes, bytearray, str) |
| 56 | + # resp_data: 被发送以响应主动扫描, 是任何实现缓冲协议的类型(例如bytes, bytearray, str) |
| 57 | + |
| 58 | + # """ |
| 59 | + # def gap_advertise(self, interval_us, adv_data=None, *, resp_data=None, connectable=True): |
| 60 | + # # 停止广播 |
| 61 | + # if interval_us is None: |
| 62 | + # return super.stop_advertise() |
| 63 | + |
| 64 | + # if adv_data is None: |
| 65 | + # adv_data = self.last_adv_data |
| 66 | + # else : |
| 67 | + # self.last_adv_data = adv_data |
| 68 | + |
| 69 | + # if resp_data is None: |
| 70 | + # resp_data = self.last_resp_data |
| 71 | + # else : |
| 72 | + # self.last_resp_data = resp_data |
| 73 | + |
| 74 | + |
| 75 | + # #TODO:active的作用是什么意思 |
| 76 | + # """ |
| 77 | + # 使用interval_us和window_us可选择配置占空比。扫描器将每interval_us微秒运行window_us 微秒, |
| 78 | + # 总共持续duration_ms毫秒。默认间隔和窗口分别为 1.28 秒和 11.25 毫秒(后台扫描)。 |
| 79 | + # TODO:无法完全实现和micropython相同API |
| 80 | + # """ |
| 81 | + # # def gap_scan(self, duration_ms, interval_us=1280000, window_us=11250, active=False, /): |
| 82 | + # # if duration_ms is None : |
| 83 | + # # super.gap_stop_scan() |
| 84 | + # # elif (duration_ms == 0): |
| 85 | + # # super.gap_scan_forever() |
| 86 | + # # else: |
| 87 | + # # super.gap_scan_forever() |
| 88 | + |
| 89 | + # """ |
| 90 | + # micropython:直接输入时间 |
| 91 | + |
| 92 | + # nimble: 按照单位算时间 |
| 93 | + # duration: |
| 94 | + |
| 95 | + # """ |
| 96 | + # def gap_scan(self, duration_ms, interval_us=1280000, window_us=11250, active=False, /): |
| 97 | + # if duration_ms is None : |
| 98 | + # super.gap_stop_scan() |
| 99 | + # else: |
| 100 | + # duration = duration_ms / 10 |
| 101 | + # super.gap_scan(duration_ms, interval_us, window_us, active) |
| 102 | + |
| 103 | + # def gap_connect(self, addr_type, addr, scan_duration_ms=2000, /): |
| 104 | + # super.gap_connect(addr_type, addr,scan_duration_ms) |
| 105 | + # pass |
| 106 | + |
| 107 | + # def gap_disconnect(self, conn_handle, /): |
| 108 | + # super.gap_disconnect() |
| 109 | + # pass |
| 110 | + |
| 111 | + # def gatts_register_services(self, services_definition, /): |
| 112 | + # for service in services_definition: |
| 113 | + # service_uuid, characteristics = service |
| 114 | + |
| 115 | + # print(f"Service UUID: {service_uuid}") |
| 116 | + |
| 117 | + # # 遍历特征 |
| 118 | + # for characteristic in characteristics: |
| 119 | + # char_uuid, flags = characteristic |
| 120 | + # print(f"Characteristic UUID: {char_uuid}") |
| 121 | + # print(f"Flags: {flags}") |
| 122 | + # super.register_a_service() |
| 123 | + |
| 124 | + |
| 125 | + # def gatts_read(value_handle, /): |
| 126 | + # pass |
| 127 | + |
| 128 | + # def gatts_write(value_handle, data, send_update=False, /): |
| 129 | + # pass |
| 130 | + |
| 131 | + # def gatts_notify(conn_handle, value_handle, data=None, /): |
| 132 | + # pass |
| 133 | + |
| 134 | + # def gatts_indicate(conn_handle, value_handle, /): |
| 135 | + # pass |
| 136 | + |
| 137 | + # def gatts_set_buffer(value_handle, len, append=False, /): |
| 138 | + # pass |
| 139 | + |
| 140 | + # def gattc_discover_services(conn_handle, uuid=None, /): |
| 141 | + # pass |
| 142 | + |
| 143 | + # def gattc_discover_characteristics(conn_handle, start_handle, end_handle, uuid=None, /): |
| 144 | + # pass |
| 145 | + |
| 146 | + # def gattc_discover_descriptors(conn_handle, start_handle, end_handle, /): |
| 147 | + # pass |
| 148 | + |
| 149 | + # def gattc_read(conn_handle, value_handle, /): |
| 150 | + # pass |
| 151 | + |
| 152 | + # def gattc_write(conn_handle, value_handle, data, mode=0, /): |
| 153 | + # pass |
| 154 | + |
| 155 | + # def gattc_exchange_mtu(conn_handle, /): |
| 156 | + # pass |
| 157 | + |
0 commit comments