Added daemon info get command

master
Ringo Wantanabe 6 years ago
parent 551303b05e
commit ad899111a6
No known key found for this signature in database
GPG Key ID: C1C1CD34CF2907B2

@ -1,2 +1,3 @@
pylzma pylzma
argparse argparse
probably some other stuff

@ -349,10 +349,11 @@ def _fork():
return os.fork() return os.fork()
class Daemon(threading.Thread): class Daemon(threading.Thread):
def __init__(self, socket, buf): def __init__(self, socket, buf, info=None):
self.sock = socket self.sock = socket
self.buf = buf self.buf = buf
self.running=True self.running=True
self.info = info
threading.Thread.__init__(self) threading.Thread.__init__(self)
def _get(self,con, fr, ca=False): def _get(self,con, fr, ca=False):
if ca: if ca:
@ -383,6 +384,9 @@ class Daemon(threading.Thread):
elif cmd.uCommand == Command.CMD_CLEAR: #clear buffer elif cmd.uCommand == Command.CMD_CLEAR: #clear buffer
log("[daemon]: Recieved clear") log("[daemon]: Recieved clear")
self.buf.clear() self.buf.clear()
elif cmd.uCommand == Command.CMD_INFO: #information
log("[daemon]: Recieved info")
con.send(json.dumps(self.info).encode("ascii"))
else: #unknwon command else: #unknwon command
log("[daemon]: Recieved unknown command") log("[daemon]: Recieved unknown command")
pass pass
@ -441,7 +445,7 @@ if args.daemon!=None:
daemon_sock.settimeout(5) daemon_sock.settimeout(5)
daemon_sock.listen(5) daemon_sock.listen(5)
daemon = Daemon(daemon_sock, buf) daemon = Daemon(daemon_sock, buf, { "timeout": args.timeout, "board": args.board })
daemon.start() daemon.start()
try: try:

@ -27,6 +27,7 @@ def parsecmd(s):
elif s=="stop": return Command.CMD_SHUTDOWN elif s=="stop": return Command.CMD_SHUTDOWN
elif s=="clear": return Command.CMD_CLEAR elif s=="clear": return Command.CMD_CLEAR
elif s=="get-clear": return Command.CMD_GET_CLEAR elif s=="get-clear": return Command.CMD_GET_CLEAR
elif s=="info": return Command.CMD_INFO
else: return None else: return None
parser = argparse.ArgumentParser(description="rtbwpy daemon control.") parser = argparse.ArgumentParser(description="rtbwpy daemon control.")
@ -63,5 +64,8 @@ if cmd.uCommand == Command.CMD_GET or cmd.uCommand == Command.CMD_GET_CLEAR:
json = con.recv().decode("utf-8") json = con.recv().decode("utf-8")
print(json) print(json)
elif cmd.uCommand == Command.CMD_INFO:
print(con.recv().decode("ascii"))
sock.close() sock.close()

@ -28,6 +28,7 @@ class Command(object):
CMD_CLEAR = 2 CMD_CLEAR = 2
CMD_SHUTDOWN = 3 CMD_SHUTDOWN = 3
CMD_GET_CLEAR = 4 CMD_GET_CLEAR = 4
CMD_INFO = 5
def __init__(self): def __init__(self):
self.uCommand = 0 self.uCommand = 0

Loading…
Cancel
Save