Beispiel #1
0
def flashbinary(btmac, binfile):
    try:
        socket = BT_Socket(btmac, 0x1001)
    except:
        print "bad mac address"
        sys.exit()

    proto.determine_packet_format(socket)
    socket.send(proto.cmd_set_bt_sniff_off())

    f = open(binfile, 'rb')
    fileLen = len(f.read())

    numSectorsToErase = fileLen / 4096 + (fileLen % 4096 > 0)

    for i in range(numSectorsToErase):
        socket.send(proto.cmd_erase_spiflash_sector(8 + i))
        byte = socket.receive(4)

    f.seek(0)
    bytesToSend = fileLen
    addr_offset = 0
    data = f.read(220)

    while (len(data) != 0):
        print bytesToSend
        socket.send(proto.write_spiflash(32768 + addr_offset, data))
        socket.receive(4)
        addr_offset += 220
        f.seek(addr_offset)
        data = f.read(220)
        bytesToSend -= 220

    socket.send(proto.cmd_send_time())
    socket.send(proto.cmd_reboot_watch())
    socket.close()
Beispiel #2
0
def flashbinary( btmac, binfile):
	try:
		socket = BT_Socket(btmac, 0x1001)
	except:
		print "bad mac address"
		sys.exit()

	proto.determine_packet_format(socket)
	socket.send(proto.cmd_set_bt_sniff_off())

	f = open(binfile, 'rb')
	fileLen = len(f.read())

	numSectorsToErase = fileLen / 4096 + (fileLen % 4096 > 0)

	for i in range(numSectorsToErase):
		socket.send(proto.cmd_erase_spiflash_sector(8 + i))
		byte = socket.receive(4)

	f.seek(0)
	bytesToSend = fileLen
	addr_offset = 0
	data = f.read(220)

	while (len(data) != 0):
		print bytesToSend
		socket.send(proto.write_spiflash(32768 + addr_offset, data))
		socket.receive(4)
		addr_offset += 220
		f.seek(addr_offset)
		data = f.read(220)
		bytesToSend -= 220

	socket.send(proto.cmd_send_time())
	socket.send(proto.cmd_reboot_watch())
	socket.close()
Beispiel #3
0
def flashbinary( btmac, binfile, addr, is_url, reboot):
	tries = 1
	while True:
		try:			
			socket = BT_Socket(btmac, 0x1001)
			break
		except:
			tries += 1
		if tries > 3:
			print "invalid, missing, or unavailable bd addr"
			sys.exit()

	proto.determine_packet_format(socket)
	socket.send(proto.cmd_set_bt_sniff_off())

	if (is_url):
		urllib.urlretrieve(binfile, "temp.bin")
		f = open("temp.bin", 'rb')
	else:
		f = open(binfile, 'rb')
	fileLen = len(f.read())

	numSectorsToErase = fileLen / 4096 + (fileLen % 4096 > 0)
	print "Preparing ",
        if proto.get_in_vlf() and addr == 0x40000:
            # TODO: I don't like having the hard-coded addr check here
            proto.cmd_erase_resources(fileLen)
        else:
            for i in range(numSectorsToErase):
                    socket.send(proto.cmd_erase_spiflash_sector((addr / 4096) + i))
                    resp_len = len(socket.receive(1024))
                    # TODO FIX code duplication here
                    if resp_len >= 4:
                        error_count = 0
                        print ".",
                        #time.sleep(0.5)
                    else:
                        print "Retrying packet ..."
                        print resp_len
                        error_count = error_count + 1
                        if error_count == 5:
                            socket = handle_error(btmac, socket)
                            error_count = 0
                    sys.stdout.flush()
            print ""

	f.seek(0)
	bytesToSend = fileLen
	addr_offset = 0
	if proto.get_in_vlf():
		data_packet_chunk = 128
	else:
		data_packet_chunk = 220

	data = f.read(data_packet_chunk)
        error_count = 0
	while (len(data) != 0):
		print bytesToSend
		socket.send(proto.write_spiflash(addr + addr_offset, data))
                resp_len = len(socket.receive(1024))
                # TODO FIX code duplication here
		if resp_len >= 4:
                    error_count = 0
                    addr_offset += data_packet_chunk
                    f.seek(addr_offset)
                    data = f.read(data_packet_chunk)
                    bytesToSend -= data_packet_chunk
                    #time.sleep(0.5)
                else:
                    print "Retrying packet ..."
                    print resp_len
                    error_count = error_count + 1
                    if error_count == 5:
                        socket = handle_error(btmac, socket)
                        error_count = 0

	socket.send(proto.cmd_send_time())

	if is_url:
		f.close()
		os.remove("temp.bin")

	if reboot:
		socket.send(proto.cmd_reboot_watch())
	socket.close()
btmac = sys.argv[1]
try:
    socket = BT_Socket(btmac, 0x1001)
except:
    print "Bad mac address, or if on Windows, the L2CAPServer might not be wokring"
    sys.exit()
proto.determine_packet_format(socket)
socket.send(proto.cmd_set_bt_sniff_off())
socket.receive(4)

#Establishing connection with iTunes
iTunes = win32com.client.gencache.EnsureDispatch("iTunes.Application")
iTunes.Pause()

while (1):
    #Receive the commain from the watch
    text = socket.receive(256)
    #If it's a valid command (Note: non-valid commands will have a length of 2)
    if (len(text) is 4):
        #transform it into an int
        key = proto.int_from_buffer(text)
        if (key is 1):
            iTunes.PlayPause()
        elif (key is 0):
            iTunes.NextTrack()
        #Sends back the artist name and track number
        socket.send(iTunes.CurrentTrack.Artist)
        socket.send(iTunes.CurrentTrack.Name)
#Closes conncetions
socket.close()
Beispiel #5
0
proto.determine_packet_format(socket)
socket.send(proto.cmd_set_bt_sniff_off())
socket.receive(4)

while(1):
	#Receive the commain from the watch
	text=socket.receive(256)
	#If it's a valid command (Note: non-valid commands will have a length of 2)
	if(len(text) is 4):
		#transform it into an int
		key=proto.int_from_buffer(text)
		# Always send back the message if in valid ascii range
                if(key >= 128 and key <= 255):
                      print "Message received. Sending response ", key
                      socket.send(chr(key)) # send the response back
                if(key is 69):
                     print "Next slide request received ", key 
                     os.system("./sendkey.osascript 'N'")
                elif(key is 70):
                     print "Previous slide request received ", key 
                     os.system("./sendkey.osascript 'P'")
                elif(key <= 128):
                     print "Unknown key=", key
	#	elif (key is 0):
	#		SendKeys.SendKeys("""{LEFT}""")
        print "looping..."
        # wend

#Closes conncetions		
socket.close()
Beispiel #6
0
def flashbinary(btmac, binfile, addr, is_url, reboot):
    tries = 1
    while True:
        try:
            socket = BT_Socket(btmac, 0x1001)
            break
        except:
            tries += 1
        if tries > 3:
            print "invalid, missing, or unavailable bd addr"
            sys.exit()

    proto.determine_packet_format(socket)
    socket.send(proto.cmd_set_bt_sniff_off())

    if (is_url):
        urllib.urlretrieve(binfile, "temp.bin")
        f = open("temp.bin", 'rb')
    else:
        f = open(binfile, 'rb')
    fileLen = len(f.read())

    numSectorsToErase = fileLen / 4096 + (fileLen % 4096 > 0)
    print "Preparing ",
    if proto.get_in_vlf() and addr == 0x40000:
        # TODO: I don't like having the hard-coded addr check here
        proto.cmd_erase_resources(fileLen)
    else:
        for i in range(numSectorsToErase):
            socket.send(proto.cmd_erase_spiflash_sector((addr / 4096) + i))
            resp_len = len(socket.receive(1024))
            # TODO FIX code duplication here
            if resp_len >= 4:
                error_count = 0
                print ".",
                #time.sleep(0.5)
            else:
                print "Retrying packet ..."
                print resp_len
                error_count = error_count + 1
                if error_count == 5:
                    socket = handle_error(btmac, socket)
                    error_count = 0
            sys.stdout.flush()
        print ""

    f.seek(0)
    bytesToSend = fileLen
    addr_offset = 0
    if proto.get_in_vlf():
        data_packet_chunk = 128
    else:
        data_packet_chunk = 220

    data = f.read(data_packet_chunk)
    error_count = 0
    while (len(data) != 0):
        print bytesToSend
        socket.send(proto.write_spiflash(addr + addr_offset, data))
        resp_len = len(socket.receive(1024))
        # TODO FIX code duplication here
        if resp_len >= 4:
            error_count = 0
            addr_offset += data_packet_chunk
            f.seek(addr_offset)
            data = f.read(data_packet_chunk)
            bytesToSend -= data_packet_chunk
            #time.sleep(0.5)
        else:
            print "Retrying packet ..."
            print resp_len
            error_count = error_count + 1
            if error_count == 5:
                socket = handle_error(btmac, socket)
                error_count = 0

    socket.send(proto.cmd_send_time())

    if is_url:
        f.close()
        os.remove("temp.bin")

    if reboot:
        socket.send(proto.cmd_reboot_watch())
    socket.close()