Elias Bakken avatar Elias Bakken committed 600481d

Added support for getting g-codes via ethernet

Comments (0)

Files changed (2)

 
 tests:
 	scp -r software/tests $(REMOTE):$(RPATH)/software/
+
+install_image: 
+	cp images/uImage-3.2.34-20130303 /boot/
+	rm /boot/uImage
+	ln -s /boot/uImage-3.2.34-20130303 /boot/uImage
+
+install_modules: 
+	unzip images/3.2.34.zip
+	cp -r images/3.2.34/ /lib/modules/ 

software/Ethernet.py

+#!/usr/bin/env python
+'''
+Ethernet communication file for Replicape. 
+
+Author: Elias Bakken
+email: elias.bakken@gmail.com
+Website: http://www.hipstercircuits.com
+License: BSD
+
+You can use and change this, but keep this heading :)
+'''
+
+#from Gcode import Gcode
+from threading import Thread
+import socket
+import logging
+
+size = 1024 
+
+class Ethernet:
+    def __init__(self, queue):
+        self.queue = queue
+        self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        host = ''
+        port = 50000
+        backlog = 5       
+        for i in range(10):
+            try: 
+                self.s.bind((host,port))
+                break
+            except socket.error as e:
+                port += 1    
+
+        print "Ethernet bound to port "+str(port)
+        self.s.listen(backlog)
+        self.running = True
+        self.debug = 0
+        self.t = Thread(target=self.get_message)
+        self.t.start()		
+
+    # Loop that gets messages and pushes them on the queue
+    def get_message(self):
+        while self.running:
+            self.client, self.address = self.s.accept()
+            try: 
+                while True:
+                    data = ''
+                    while not "\n" in data:
+                        data += self.client.recv(1)
+                    message = data.strip("\n")
+                    self.queue.put({"message": message, "prot": "Eth"})
+            except IOError as e:
+                print "Connection closed"
+            finally:
+                self.client.close()             
+
+
+    # Send a message		
+    def send_message(self, message):
+        logging.debug("'"+message+"'")
+        if message[-1] != "\n":
+            message += "\n"
+        self.client.send(message)
+
+    # Stop receiving mesassages
+    def close(self):
+        self.running = False
+        self.t.join()
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.