cc2650_compitable
This commit is contained in:
+53
-14
@@ -7,12 +7,13 @@ def survive_cmd(ser):
|
||||
send = [0x0A, 0x01, 0xF1]
|
||||
ser.write(send)
|
||||
read = ser.read(4)
|
||||
print("recv: "+" ".join("%02X" % b for b in read))
|
||||
print("recv: " + " ".join("%02X" % b for b in read))
|
||||
|
||||
def scan_cmd(ser, is_raw_data = True):
|
||||
|
||||
def scan_cmd(ser, is_raw_data=True):
|
||||
send = [0x03, 0x01, 0xF1]
|
||||
ser.write(send)
|
||||
peer_addr = []
|
||||
peer_addr = []
|
||||
for i in range(10):
|
||||
hci_packet_event = ser.read(2)
|
||||
if int.from_bytes(hci_packet_event, "little") != 0x0004:
|
||||
@@ -36,38 +37,76 @@ def scan_cmd(ser, is_raw_data = True):
|
||||
print(" hw version: " + " ".join("%02X" % b for b in payload[10:14]))
|
||||
print(" build time: " + " ".join("%02X" % b for b in payload[14:16]))
|
||||
print(" Parameter1: " + str(payload[16:19], "utf-8"))
|
||||
print(" battery volt: " + str(int.from_bytes(payload[19:21], "big")/1000.0) + "V")
|
||||
print(" device name: " + str(payload[21:], "utf-8"))
|
||||
print(
|
||||
" battery volt: "
|
||||
+ str(int.from_bytes(payload[19:21], "big") / 1000.0)
|
||||
+ "V"
|
||||
)
|
||||
print(" device name: " + str(payload[21:], "utf-8"))
|
||||
return peer_addr
|
||||
|
||||
def connect(ser, peer_addr = []):
|
||||
|
||||
def connect(ser, peer_addr=[]):
|
||||
send = [0x05, 0x08, 0x00]
|
||||
send += peer_addr
|
||||
send += [0xF1]
|
||||
ser.write(send)
|
||||
read = ser.read(7)
|
||||
print("recv: "+" ".join("%02X" % b for b in read))
|
||||
read = ser.read(4)
|
||||
print("recv: " + " ".join("%02X" % b for b in read))
|
||||
|
||||
|
||||
def disconnect(ser):
|
||||
send = [0x08, 0x01, 0xF1]
|
||||
ser.write(send)
|
||||
read = ser.read(4)
|
||||
print("recv: "+" ".join("%02X" % b for b in read))
|
||||
print("recv: " + " ".join("%02X" % b for b in read))
|
||||
|
||||
|
||||
def write_char(ser: serial.Serial, handle: int, write_data: tuple):
|
||||
send = [0x06, len(write_data)+2, handle]
|
||||
send += write_data
|
||||
send += [0xF1]
|
||||
ser.write(send)
|
||||
|
||||
def read_char(ser: serial.Serial, handle: int):
|
||||
send = [0x07, 0x02, handle, 0xF1]
|
||||
ser.write(send)
|
||||
read = ser.read(0xFFFF)
|
||||
print("recv: " + " ".join("%02X" % b for b in read))
|
||||
|
||||
|
||||
def main():
|
||||
# set comport
|
||||
ser = serial.Serial("COM12", 57600, 8)
|
||||
ser = serial.Serial("COM15", 57600, 8, inter_byte_timeout=0.01)
|
||||
|
||||
# send survive cmd
|
||||
survive_cmd(ser)
|
||||
survive_cmd(ser)
|
||||
|
||||
# send scan cmd
|
||||
peer_addr = scan_cmd(ser, False)
|
||||
|
||||
peer_addr = scan_cmd(ser, False)
|
||||
time.sleep(10)
|
||||
return
|
||||
# send connect cmd with peer addr
|
||||
connect(ser, peer_addr)
|
||||
time.sleep(10)
|
||||
time.sleep(3)
|
||||
|
||||
# send write char to enable notify
|
||||
write_char(ser, 0x0024, [0xc4,0xf0,0xf1,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00])
|
||||
time.sleep(0.1)
|
||||
write_char(ser, 0x0024, [0x74,0x10,0xf1,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00])
|
||||
time.sleep(0.1)
|
||||
read_char(ser, 0x0021)
|
||||
# 130500040000000000000000000000000000001c
|
||||
time.sleep(0.2)
|
||||
# send write char to enable notify
|
||||
#write_char(ser, 0x0028, 1)
|
||||
#time.sleep(5)
|
||||
|
||||
# send write char to disable notify
|
||||
#write_char(ser, 0x0028, 0)
|
||||
|
||||
# send read char to disable notify
|
||||
#read_char(ser, 0x0027)
|
||||
|
||||
# send disconnect cmd
|
||||
disconnect(ser)
|
||||
|
||||
Reference in New Issue
Block a user