From 93e806b35932b511c976902af6c163dedacd9063 Mon Sep 17 00:00:00 2001 From: Emanuele Date: Thu, 19 Mar 2020 17:09:49 +0100 Subject: [PATCH] aggiunta compilazione comandi nel driver --- driver/tsc_commands.py | 6 ++++ driver/tsc_printer.py | 64 ++++++++++++++++++++++++++++++++---------- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/driver/tsc_commands.py b/driver/tsc_commands.py index 6a30106..614d5f2 100644 --- a/driver/tsc_commands.py +++ b/driver/tsc_commands.py @@ -3,3 +3,9 @@ Created on 19 mar 2020 @author: Emanuele Trabattoni ''' +TSC_COMMANDS = {'DOWNLOAD': "DOWNLOAD {location}{name}{size}{content}", + 'REMOVE': "KILL {location}{name}", + 'LIST': "~!F", + 'RUN': "RUN {name}"} + +LINE_SEP = '\r\n' \ No newline at end of file diff --git a/driver/tsc_printer.py b/driver/tsc_printer.py index 48253e1..930d3bd 100644 --- a/driver/tsc_printer.py +++ b/driver/tsc_printer.py @@ -5,37 +5,70 @@ Created on 19 mar 2020 ''' import queue, sys, time, socket, logging +from driver.tsc_commands import TSC_COMMANDS, LINE_SEP +from driver.notifier import URL_ERR, URL_EVENT, URL_RESPONSE SOCK_TIMEOUT = 2 + def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: str, port: int, logger: logging.getLogger): prt = None - def lista_file(): - nonlocal prt - pass + def read_until(term): + buf = '' + + c=prt.recv(1) + while c is not term: + buf = buf+c + c = prt.recv(1) + return buf - def invia_file(name=None, content=None): + def list_files(): nonlocal prt - pass - - def elimina_file(name=None): - nonlocal prt + prt.sendall(TSC_COMMANDS['LIST']+LINE_SEP) + retval = read_until(0x1A).split(0x0D) + q_out.put({'url':URL_RESPONSE, + 'msg': retval}) pass - def muovi_file(name=None): + 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) + 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.sendall(to_send) + pass + + def delete_file(name=None): + nonlocal prt + 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}"') + prt.sendall(to_send+LINE_SEP) + pass + + def move_file(name=None): #per default muove i file dalla RAM alla FLASH nonlocal prt + to_send = TSC_COMMANDS['MOVE'].format(name=f'"{name}"') + prt.sendall(to_send+LINE_SEP) pass - def esegui(name=None): + def run_batch(name=None): nonlocal prt + to_send = TSC_COMMANDS['RUN'].format(name=f'"{name}"') + prt.sendall(to_send+LINE_SEP) pass - def stato(): + def get_status(): nonlocal prt - return sts + return True + + while True: # connetti mantieni vivo il socket try: @@ -47,15 +80,16 @@ def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: s cmd = itm['name'] par = itm['parameters'] if cmd == 'DOWNLOAD': - invia_file(par['name'], par['lines']) + send_file(**par) pass elif cmd == 'REMOVE': - elimina_file(par['name']) + delete_file(**par) pass elif cmd == 'MOVE': - muovi_file(par['name']) + move_file(**par) pass elif cmd == 'LIST': + resp = get_status() q_out.put({'url='}) pass elif cmd == 'RUN':