diff --git a/driver/main.py b/driver/main.py index 4bcbebd..7b915f8 100644 --- a/driver/main.py +++ b/driver/main.py @@ -48,7 +48,7 @@ def gest_in(command): def build_logger(): logger = logging.getLogger(__name__) - logger.setLevel(logging.INFO) + logger.setLevel(logging.DEBUG) logger.propagate = False formatter = logging.Formatter(("%(asctime)s|%(levelname)-7s|%(funcName)-10s|%(lineno)-3d: %(message)-50s"), ("%m-%d %H:%M:%S")) diff --git a/driver/tsc_commands.py b/driver/tsc_commands.py index cfb0546..1b7a01a 100644 --- a/driver/tsc_commands.py +++ b/driver/tsc_commands.py @@ -5,7 +5,7 @@ Created on 19 mar 2020 ''' TSC_COMMANDS = {'DOWNLOAD': "DOWNLOAD {location}{name}{size}{content}", 'REMOVE': "KILL {location}{name}", - 'MOVE': "MOVE", + 'MOVE': "MOVE {name}", 'LIST': "~!F", 'INFO': "~!T", 'USE': "~!@", diff --git a/driver/tsc_printer.py b/driver/tsc_printer.py index b9745d3..9c03cd8 100644 --- a/driver/tsc_printer.py +++ b/driver/tsc_printer.py @@ -8,6 +8,7 @@ import queue, time, socket, logging from driver.tsc_commands import TSC_COMMANDS, TSC_STATUS, LINE_SEP from driver.notifier import URL_ERR, URL_EVENT, URL_RESPONSE, send_response import traceback +import struct SOCK_TIMEOUT = 2 ENC = 'ascii' @@ -26,11 +27,12 @@ def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: s def send_file(name=None, content=None, ftype=None): nonlocal prt if ftype == 'batch': - to_send = TSC_COMMANDS['DOWNLOAD'].format(location='F,', name=f'"{name}"', content=LINE_SEP+content.join(LINE_SEP)+LINE_SEP) + content.append('EOP') + to_send = TSC_COMMANDS['DOWNLOAD'].format(location='F,', name=f'"{name}"', size='',content=LINE_SEP+LINE_SEP.join(content)+LINE_SEP) elif ftype == 'data': - data = content.join(LINE_SEP)+LINE_SEP - to_send = TSC_COMMANDS['DOWNLOAD'].format(name=f'"{name}"',size=','+len(data),content=data) - prt.send_all(bytearray(to_send, encoding=ENC)) + data = LINE_SEP.join(content)+LINE_SEP + to_send = TSC_COMMANDS['DOWNLOAD'].format(location='',name=f'"{name}"',size=','+str(len(bytearray(data,encoding=ENC)))+',',content=data) + prt.sendall(bytearray(to_send, encoding=ENC)) pass def delete_file(name=None): @@ -38,7 +40,7 @@ def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: s if ".BAS" in name: to_send = TSC_COMMANDS['REMOVE'].format(location='F,', name=f'"{name}"') else: - to_send = TSC_COMMANDS['REMOVE'].format(name=f'"{name}"') + to_send = TSC_COMMANDS['REMOVE'].format(location='', name=f'"{name}"') prt.sendall(bytearray(to_send+LINE_SEP, encoding=ENC)) pass @@ -70,17 +72,17 @@ def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: s def printer_pause(): nonlocal prt - prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['PAUSE'], encoding=ENC)) + prt.sendall(b'\x1B'+bytearray(TSC_COMMANDS['PAUSE'], encoding=ENC)) pass def printer_resume(): nonlocal prt - prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['RESUME'], encoding=ENC)) + prt.sendall(b'\x1B'+bytearray(TSC_COMMANDS['RESUME'], encoding=ENC)) pass def clear_memory(): nonlocal prt - prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['CLEAR'], encoding=ENC)) + prt.sendall(b'\x1B'+bytearray(TSC_COMMANDS['CLEAR'], encoding=ENC)) pass def run_batch(name=None): @@ -91,9 +93,9 @@ def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: s def get_status(): nonlocal prt - prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['STATUS'], encoding=ENC)) + prt.sendall(b'\x1B'+bytearray(TSC_COMMANDS['STATUS'], encoding=ENC)) time.sleep(0.1) - return TSC_STATUS[int(prt.recv(1))] + send_response(q_out, ip, "STATUS",{"stato": TSC_STATUS[struct.unpack('>b',prt.recv(1))[0]]}) while True: # connetti mantieni vivo il socket