Created
December 7, 2016 10:35
-
-
Save hdo/792eebcb98c14285e65069e325a0e520 to your computer and use it in GitHub Desktop.
Emulate Advantech ADAM-6050 for Synology Surveillance Station
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twisted.internet.protocol import DatagramProtocol | |
from twisted.internet import reactor | |
import time | |
class Echo(DatagramProtocol): | |
def datagramReceived(self, data, (host, port)): | |
print "received %r from %s:%d" % (data, host, port) | |
# Login | |
if data.startswith('$01PW'): | |
self.transport.write(">01\r", (host, port)) | |
return | |
# Request IO status | |
if data.startswith('$01C'): | |
self.transport.write("!01" + "000000000000" + "000000000000" + "000000000000" + "\r", (host, port)) | |
return | |
# Request IO input status | |
if data.startswith('$016'): | |
seconds = int(time.time()) % 60 | |
print seconds | |
if seconds > 20 and seconds < 24: | |
print "trigger!" | |
self.transport.write("!01"+"00"+"FFFF\r", (host, port)) | |
else: | |
self.transport.write("!01"+"01"+"FFFF\r", (host, port)) | |
return | |
# Request set IO output | |
if data.startswith('#011'): | |
print "Channel[0x" + data[4:6]+ "] = " + data[6:7] | |
self.transport.write(">\r", (host, port)) | |
return | |
print "unknow command!" | |
#self.transport.write(data, (host, port)) | |
print "starting ..." | |
reactor.listenUDP(1025, Echo()) | |
reactor.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment