Skip to content

Instantly share code, notes, and snippets.

Created November 7, 2015 21:27
Show Gist options
  • Save anonymous/07cd28fe578ec49839db to your computer and use it in GitHub Desktop.
Save anonymous/07cd28fe578ec49839db to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
TCP_IP = '10.0.0.7'
TCP_PORT = 50001
BUFFER_SIZE = 1024
import socket
import sys, time
def send(MESSAGE):
MESSAGE = MESSAGE.decode('hex')
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.send(MESSAGE)
s.close()
def turnOff():
send("0001020900")
def turnOn():
send("0001020901")
def setVol(n):
send("00010204"+(hex(int(n))[2:]).zfill(2))
def getSetVol(delta): #Fuck yeah magic numbers
MESSAGE = "000102020b000102020400010202060001020207000102020800010202050001020209000102020a000102020c0001020203000102020d00010207000001020800000102020b000102020400010202060001020207000102020800010202050001020209000102020a000102020c0001020203000102020d00010207000001020800"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.send(MESSAGE.decode('hex'))
counter = 0
while True:
x = s.recv(1024)
for a in x:
if counter==11:
z = ord(a)
s.send(("00010204"+(hex(int(z+delta))[2:]).zfill(2)).decode('hex'))
s.close()
return z
counter += 1
if len(sys.argv)==2:
if sys.argv[1]=="up":
getSetVol(6)
elif sys.argv[1]=="down":
getSetVol(-6)
else:
print "Please give up or down as argument"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment