aggiunta compilazione comandi nel driver

master
Emanuele Trabattoni 2020-03-19 17:09:49 +01:00
parent 89c8d8715c
commit 93e806b359
2 changed files with 55 additions and 15 deletions

View File

@ -3,3 +3,9 @@ Created on 19 mar 2020
@author: Emanuele Trabattoni @author: Emanuele Trabattoni
''' '''
TSC_COMMANDS = {'DOWNLOAD': "DOWNLOAD {location}{name}{size}{content}",
'REMOVE': "KILL {location}{name}",
'LIST': "~!F",
'RUN': "RUN {name}"}
LINE_SEP = '\r\n'

View File

@ -5,37 +5,70 @@ Created on 19 mar 2020
''' '''
import queue, sys, time, socket, logging 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 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): def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: str, port: int, logger: logging.getLogger):
prt = None prt = None
def lista_file(): def read_until(term):
nonlocal prt buf = ''
pass
def invia_file(name=None, content=None): c=prt.recv(1)
nonlocal prt while c is not term:
pass buf = buf+c
c = prt.recv(1)
return buf
def elimina_file(name=None): def list_files():
nonlocal prt nonlocal prt
prt.sendall(TSC_COMMANDS['LIST']+LINE_SEP)
retval = read_until(0x1A).split(0x0D)
q_out.put({'url':URL_RESPONSE,
'msg': retval})
pass 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 #per default muove i file dalla RAM alla FLASH
nonlocal prt nonlocal prt
to_send = TSC_COMMANDS['MOVE'].format(name=f'"{name}"')
prt.sendall(to_send+LINE_SEP)
pass pass
def esegui(name=None): def run_batch(name=None):
nonlocal prt nonlocal prt
to_send = TSC_COMMANDS['RUN'].format(name=f'"{name}"')
prt.sendall(to_send+LINE_SEP)
pass pass
def stato(): def get_status():
nonlocal prt nonlocal prt
return sts return True
while True: # connetti mantieni vivo il socket while True: # connetti mantieni vivo il socket
try: 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'] cmd = itm['name']
par = itm['parameters'] par = itm['parameters']
if cmd == 'DOWNLOAD': if cmd == 'DOWNLOAD':
invia_file(par['name'], par['lines']) send_file(**par)
pass pass
elif cmd == 'REMOVE': elif cmd == 'REMOVE':
elimina_file(par['name']) delete_file(**par)
pass pass
elif cmd == 'MOVE': elif cmd == 'MOVE':
muovi_file(par['name']) move_file(**par)
pass pass
elif cmd == 'LIST': elif cmd == 'LIST':
resp = get_status()
q_out.put({'url='}) q_out.put({'url='})
pass pass
elif cmd == 'RUN': elif cmd == 'RUN':