test_code.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import bluetooth
  2. a = bluetooth.BLE()
  3. c = bluetooth.UUID(0x291a)
  4. c = bluetooth.UUID(0x291a123)
  5. c = bluetooth.UUID('6E400001-B5A3-F393-E0A9-E50E24DCCA9E')
  6. c = bluetooth.UUID(bytearray('6E400001B5A3F393E0A9E50E24DCCA9E'))
  7. c = bluetooth.UUID('6E400001-B5A3-F393-E0A9-E50E24DCCA9')
  8. c = bluetooth.UUID('6E400001-B5A3-F393-E0A9--E50E24DCCA9')
  9. c = bluetooth.UUID(0x29199999)
  10. value = '6E400001-B5A3-F393-E0A9-E50E24DCCA9E'
  11. value = '6E400001-B5A3-F393-E0A9-E50E24DCCA9'
  12. value = '6E400001-B5A3-F393-E0A9--50E24DCCA9'
  13. len(value) == 36 and (value[8] == '-') and (value[13] == '-') and (value[18] == '-') and (value[23] == '-')
  14. c.value
  15. # 广播
  16. # 输入格式判断
  17. c = a.gap_advertise(6250,"adv_test","rsp_test")
  18. c = a.gap_advertise(6250,"adv","rsp")
  19. c = a.gap_advertise(6250,"adv","rsp")
  20. c = a.gap_advertise(6250,bytes("adv"),bytes("rsp"))
  21. c = a.gap_advertise(6250,bytearray("adv"),bytearray("rsp"))
  22. c = a.gap_advertise(6250,bytearray("adv"),bytes([0x12,0x34,0x56]))
  23. # 暂停广播
  24. a.gap_advertise(None)
  25. # 测间隔
  26. a.gap_advertise(625 * 400 ,"adv_test","rsp_test")
  27. a.gap_advertise(625 * 10 ,"adv_test","rsp_test")
  28. a.gap_advertise(625 * 32,"adv_test","rsp_test")
  29. a.gap_advertise(625 * 40 ,"adv_test","rsp_test")
  30. a.gap_advertise(0 ,"adv_test","rsp_test",False)
  31. a.gap_advertise(0)
  32. # 测连接
  33. a.gap_advertise(0 ,"adv_test","rsp_test",False)
  34. # 多次连接广播
  35. a.gap_advertise(0)
  36. a.gap_advertise(625 * 400 ,"adv_test","rsp_test")
  37. #测扫描
  38. a.gap_scan(10000,320000,active=True)
  39. a.gap_scan(10000,320000,active=False)
  40. # 无限扫描
  41. a.gap_scan(0,320000,active=True)
  42. a.gap_scan(0,320000,active=False)
  43. # 停止扫描
  44. a.gap_scan(None)
  45. # 多次扫描
  46. a.gap_scan(10000,320000,active=True)
  47. a.gap_scan(10000,320000,active=False)
  48. # 测connect
  49. a.gap_scan(1000,320000,active=False)
  50. addr = bytes([0xec,0xda,0x3b,0x67,0x7a,0x82]) # new eps32 s3
  51. a.gap_connect(addr,0)
  52. addr = bytes([0xec,0xda,0x3b,0x67,0x7a,0x82]) # new eps32 s3
  53. addr = [0xec,0xda,0x3b,0x67,0x7a] # new eps32 s3
  54. #测disconnect
  55. a.gap_disconnect(1)
  56. # 测发现服务
  57. a.gattc_discover_services(1)
  58. a.gattc_discover_services(1,bluetooth.UUID(0x1800))
  59. a.gattc_discover_services(1,bluetooth.UUID(b'\x6e\x40\x00\x01\xb5\xa3\xf3\x93\xe0\xa9\xe5\x0e\x24\xdc\xca\x9e'))
  60. a.gattc_discover_services(0)
  61. a.gattc_discover_services(1,bluetooth.UUID(0x1803))
  62. #发现属性
  63. a.gattc_discover_characteristics(1,0x01,0xff,bluetooth.UUID(0x2A37))
  64. a.gattc_discover_characteristics(1,29,0xff,bluetooth.UUID(0x2A37))
  65. a.gap_connect(addr,0)
  66. #订阅 notify
  67. a.gattc_write(1,32,bytes([0x01,0x00]))
  68. a.gattc_write(1,32,b'\x00\x01')
  69. a.gattc_write(1,32,b'\x01\x00')
  70. # b'\x01\x00'
  71. a.gattc_write(1,32,bytes([0x00,0x01]))
  72. a.gattc_write(1,32,bytes([0x00,0x00]))
  73. a.gattc_read(1,32)
  74. a.gattc_read(3,32)
  75. #订阅 indicate
  76. a.gattc_write(1,38,bytes([0x02,0x00]))
  77. a.gattc_write(1,38,bytes([0x00,0x09]))
  78. a.gattc_write(0,38,b'\x00\x01')
  79. a.gattc_write(0,38,b'\x00\x00')
  80. a.gattc_write(1,38,bytes([0x00,0x00]))
  81. a.gattc_read(1,38)
  82. a.gattc_read(0,38)
  83. #发现描述符
  84. a.gattc_discover_descriptors(1,0x01,0xff)
  85. a.gattc_discover_descriptors(1,29,0xff)
  86. # a._c2py_dict
  87. # a._py2c_dict
  88. # a._c2value_dict
  89. # notify
  90. a.gatts_read(21)
  91. a.gatts_write(21,bytes([0x43,0x43]))
  92. a.gatts_notify(1,21)
  93. a.gatts_notify(1,21,"test")
  94. len(a.gatts_read(22))
  95. # gattc write
  96. a.gatts_read(22)
  97. a.test2()
  98. a.test3(1,1)
  99. a.gap_connect(addr,0)
  100. a.gattc_subscribe(1,26,1)
  101. a.gattc_subscribe(1,26,0)
  102. a.gattc_subscribe(1,26,2)
  103. a.gattc_subscribe(1,26)
  104. a.gattc_read(1,27)
  105. a.gattc_subscribe_indicate(1,38)
  106. a.gattc_subscribe_indicate(1,38,False)
  107. a.gattc_subscribe_notify(1,33,False)
  108. a.test3(1,1)
  109. a.active(1)