Skip to content

Commit

Permalink
Merge branch 'espressif:master' into main_work
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason2866 authored Nov 13, 2024
2 parents ea61b03 + 39a12a4 commit 72a5ed1
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions esp_rfc2217_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def main():
level = (logging.WARNING, logging.INFO, logging.DEBUG, logging.NOTSET)[
args.verbosity
]
logging.basicConfig(level=logging.INFO)
# logging.getLogger('root').setLevel(logging.INFO)
logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.INFO)
logging.getLogger("rfc2217").setLevel(level)

# connect to serial port
Expand All @@ -75,26 +74,42 @@ def main():
ser.dtr = False
ser.rts = False

logging.info(" RFC 2217 TCP/IP to Serial redirector - type Ctrl-C / BREAK to quit")
logging.info("RFC 2217 TCP/IP to Serial redirector - type Ctrl-C / BREAK to quit")

try:
ser.open()
except serial.SerialException as e:
logging.error(" Could not open serial port {}: {}".format(ser.name, e))
logging.error(f"Could not open serial port {ser.name}: {e}")
sys.exit(1)

logging.info(" Serving serial port: {}".format(ser.name))
logging.info(f"Serving serial port: {ser.name}")
settings = ser.get_settings()

srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
srv.bind(("", args.localport))
srv.listen(1)
logging.info(" TCP/IP port: {}".format(args.localport))
logging.info(f"TCP/IP port: {args.localport}")

host_ip = socket.gethostbyname(socket.gethostname())
wait_msg = f"Waiting for connection ... use the 'rfc2217://{host_ip}:{args.localport}?ign_set_control' as a PORT"
logging.info(wait_msg)

while True:
srv.settimeout(5)
client_socket = None
try:
while client_socket is None:
try:
client_socket, addr = srv.accept()
except TimeoutError:
print(".", end="", flush=True)
except KeyboardInterrupt:
print("") # resetting inline print
logging.info("Exited with keyboard interrupt")
break
try:
client_socket, addr = srv.accept()
logging.info("Connected by {}:{}".format(addr[0], addr[1]))
logging.info(f"Connected by {addr[0]}:{addr[1]}")
client_socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
ser.rts = True
ser.dtr = True
Expand Down

0 comments on commit 72a5ed1

Please sign in to comment.