-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from koolsb/addip
Add IP support
- Loading branch information
Showing
5 changed files
with
136 additions
and
55 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
import os | ||
import sys | ||
|
||
VERSION = '0.4' | ||
VERSION = '0.5' | ||
|
||
try: | ||
from setuptools import setup | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,66 @@ | ||
import threading | ||
import os | ||
import pty | ||
import socket | ||
|
||
|
||
def create_dummy_port(responses): | ||
def listener(port): | ||
# continuously listen to commands on the master device | ||
while 1: | ||
res = b'' | ||
while not res.endswith(b"\r"): | ||
# keep reading one byte at a time until we have a full line | ||
res += os.read(port, 1) | ||
print("command: %s" % res) | ||
|
||
# write back the response | ||
if res in responses: | ||
resp = responses[res] | ||
del responses[res] | ||
os.write(port, resp) | ||
|
||
master, slave = pty.openpty() | ||
thread = threading.Thread(target=listener, args=[master], daemon=True) | ||
thread.start() | ||
return os.ttyname(slave) | ||
def listener(port): | ||
# continuously listen to commands on the master device | ||
while 1: | ||
res = b'' | ||
while not res.endswith(b"\r"): | ||
# keep reading one byte at a time until we have a full line | ||
res += os.read(port, 1) | ||
print("command: %s" % res) | ||
|
||
# write back the response | ||
if res in responses: | ||
resp = responses[res] | ||
del responses[res] | ||
os.write(port, resp) | ||
|
||
master, slave = pty.openpty() | ||
thread = threading.Thread(target=listener, args=[master], daemon=True) | ||
thread.start() | ||
return os.ttyname(slave) | ||
|
||
def create_dummy_socket(responses): | ||
HOST = '127.0.0.1' | ||
PORT = 4001 | ||
|
||
|
||
|
||
def listener(): | ||
|
||
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
conn.bind((HOST, PORT)) | ||
conn.listen(10) | ||
|
||
while 1: | ||
conn, addr = s.accept() | ||
|
||
conn.send('Please Input Your Command :\r') | ||
|
||
while True: | ||
# Receive data | ||
res = conn.recv(1024) | ||
print("command: %s" % res) | ||
|
||
# write back the response | ||
if res in responses: | ||
resp = responses[res] | ||
del responses[res] | ||
conn.sendall(resp) | ||
|
||
if not res: | ||
break | ||
|
||
#while 1: | ||
|
||
# start_new_thread(listener ,(conn,)) | ||
|
||
thread = threading.Thread(target=listener, daemon=True) | ||
thread.start() | ||
|
||
return HOST |
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