summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/msg_client.py
diff options
context:
space:
mode:
Diffstat (limited to 'abs/core/LinHES-system/msg_client.py')
-rwxr-xr-xabs/core/LinHES-system/msg_client.py69
1 files changed, 56 insertions, 13 deletions
diff --git a/abs/core/LinHES-system/msg_client.py b/abs/core/LinHES-system/msg_client.py
index 175933f..54c2e54 100755
--- a/abs/core/LinHES-system/msg_client.py
+++ b/abs/core/LinHES-system/msg_client.py
@@ -5,7 +5,7 @@ import socket
import sys
import argparse
import pickle
-
+import time
# Create a UDS socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
@@ -18,22 +18,59 @@ def send_message(message):
except socket.error, msg:
print >>sys.stderr, msg
sys.exit(1)
- try:
- sock.sendall(message)
- #amount_received = 0
- #amount_expected = len(message)
+#try:
+ sock.sendall(message)
+ #amount_received = 0
+ #amount_expected = len(message)
+ print "Waiting for response..."
+ data = sock.recv(1024)
+ print data
+
+#finally:
+ #print >>sys.stderr, 'error occured closing socket'
+
+ sock.close()
+def usage():
+ line = '''
+ Help screen:
+ msg_client.py is used to add,remove, or list items in the queue of messages that
+ will be displayed on screen. Optionaly messages can be given an identifier or "tag".
+ This identifier does not have to be unique.
+
+ Items are processed in the order they arrive, based off their slot number.
+ The lowest slot number will be displayed first.
+ After the message is displayed it is removed from the queue.
+
+
+ ADD:
+ To add items to the queue:
+ msg_client.py --msg "My first message" --tag "tag1"
+
+ REMOVE:
+ Removing items are based off the tag.
+ To remove all items from the queue that match the tag "tag1":
+ msg_client.py --clear --tag tag1
+
+ To remove all items from the queue:
+ msg_client.py --clear
+
- #while amount_received < amount_expected:
- # data = sock.recv(16)
- # amount_received += len(data)
- # print >>sys.stderr, 'received "%s"' % data
+ Listing items in the queue or to get the total count:
+ msg_client.py --print_list
+ > -------------
+ > msg : slot 1
+ > slot : 1
+ > cmd : msg
+ > tag : None
+ > timeout : None
- finally:
- #print >>sys.stderr, 'closing socket'
- print "message sent"
- sock.close()
+ To immediately stop displaying the current message, use the kill command.
+ msg_client.py --kill
+ '''
+ print line
+ sys.exit(0)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
@@ -43,6 +80,8 @@ if __name__ == "__main__":
action.add_argument('--msg', action='store', dest='msg', help='Add message to the queue')
action.add_argument('--clear', action='store_true', help='Remove message from queue that match tag')
action.add_argument('--kill', action='store_true', help='Kill current msg thats displayed')
+ action.add_argument('--print_list', action='store_true', help='Print current queue')
+ action.add_argument('--usage', action='store_true', help='Print help screen')
results = parser.parse_args()
resultsdict = vars(results)
@@ -53,6 +92,10 @@ if __name__ == "__main__":
cmd = "clear"
elif results.kill:
cmd = "kill"
+ elif results.print_list:
+ cmd = "list"
+ elif results.usage:
+ usage()
arg_dict = {'cmd':cmd , 'msg':resultsdict['msg'] , 'tag':resultsdict['tag'] , 'timeout':resultsdict['timeout']}
send_message(pickle.dumps(arg_dict))