]> defiant.homedns.org Git - arm_ros_conn.git/commitdiff
json_client now in pyshared
authorErik Andresen <erik@vontaene.de>
Sat, 3 Jan 2015 11:31:56 +0000 (12:31 +0100)
committerErik Andresen <erik@vontaene.de>
Sat, 3 Jan 2015 11:31:56 +0000 (12:31 +0100)
.gitmodules [new file with mode: 0644]
scripts/arm_ros_conn.py
scripts/json_client.py [deleted file]
scripts/pyshared [new submodule]

diff --git a/.gitmodules b/.gitmodules
new file mode 100644 (file)
index 0000000..cd8f6f2
--- /dev/null
@@ -0,0 +1,3 @@
+[submodule "scripts/pyshared"]
+       path = scripts/pyshared
+       url = ssh://erik@vontaene/home/erik_alt/git/pyshared.git
index 29462c89c5a86010e5b6bb2e9d1849c85167db42..67561b3b8dfb13111e329c91ea22400dc583e231 100755 (executable)
@@ -6,7 +6,7 @@ import tf
 import prctl
 #import cProfile
 import threading
-from json_client import JsonClient
+from pyshared.json_client import JsonClient
 from geometry_msgs.msg import Twist
 from nav_msgs.msg import Odometry
 
diff --git a/scripts/json_client.py b/scripts/json_client.py
deleted file mode 100755 (executable)
index 4e2208e..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: iso-8859-15 -*-
-
-import sys
-import socket
-import json
-
-def set_keepalive(sock, after_idle_sec=1, interval_sec=3, max_fails=5):
-       """Set TCP keepalive on an open socket.
-
-       It activates after 1 second (after_idle_sec) of idleness,
-       then sends a keepalive ping once every 3 seconds (interval_sec),
-       and closes the connection after 5 failed ping (max_fails), or 15 seconds
-       """
-       sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
-       sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, after_idle_sec)
-       sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, interval_sec)
-       sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, max_fails)
-if not hasattr(socket, "set_keepalive"):
-       socket.set_keepalive = set_keepalive
-
-class JsonClient:
-       def __init__(self, addr = ("arm", 10002)):
-               self.pSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-               self.pSocket.settimeout(1)
-               socket.set_keepalive(self.pSocket)
-               self.pSocket.connect(addr)
-               self.lMsgs = []
-
-       def write(self, cmd):
-               data = {'command': cmd}
-               num = self.pSocket.sendall(json.dumps(data))
-               while True:
-                       msg = json.loads(self.pSocket.recv(4096))
-                       if msg.has_key("return"): return msg["return"]
-                       elif msg.has_key("error"): return msg["error"]
-                       self.lMsgs.insert(0, msg)
-
-       def read(self):
-               if len(self.lMsgs) > 0:
-                       return self.lMsgs.pop()
-               self.pSocket.setblocking(False)
-               try:
-                       return json.loads(self.pSocket.recv(4096))
-               except socket.error:
-                       pass
-               finally:
-                       self.pSocket.setblocking(True)
-
-if __name__ == "__main__":
-       print JsonClient().write(sys.argv[1])
-
-       #from datetime import datetime
-       #from time import sleep
-       #pClient = JsonClient()
-       #while True:
-       #       msg = pClient.read()
-       #       if msg:
-       #               print "Got async", msg
-       #       print datetime.now(), float(pClient.write("get distance forward lower"))
-       #       sleep(0.1)
diff --git a/scripts/pyshared b/scripts/pyshared
new file mode 160000 (submodule)
index 0000000..d73e753
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit d73e753a4c2c8a9bb79ada177d1cb122a08cabeb