parent
14d019ce67
commit
e09fbc26a2
|
|
@ -48,7 +48,7 @@ def gest_in(command):
|
||||||
|
|
||||||
def build_logger():
|
def build_logger():
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.DEBUG)
|
||||||
logger.propagate = False
|
logger.propagate = False
|
||||||
formatter = logging.Formatter(("%(asctime)s|%(levelname)-7s|%(funcName)-10s|%(lineno)-3d: %(message)-50s"),
|
formatter = logging.Formatter(("%(asctime)s|%(levelname)-7s|%(funcName)-10s|%(lineno)-3d: %(message)-50s"),
|
||||||
("%m-%d %H:%M:%S"))
|
("%m-%d %H:%M:%S"))
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ Created on 19 mar 2020
|
||||||
'''
|
'''
|
||||||
TSC_COMMANDS = {'DOWNLOAD': "DOWNLOAD {location}{name}{size}{content}",
|
TSC_COMMANDS = {'DOWNLOAD': "DOWNLOAD {location}{name}{size}{content}",
|
||||||
'REMOVE': "KILL {location}{name}",
|
'REMOVE': "KILL {location}{name}",
|
||||||
'MOVE': "MOVE",
|
'MOVE': "MOVE {name}",
|
||||||
'LIST': "~!F",
|
'LIST': "~!F",
|
||||||
'INFO': "~!T",
|
'INFO': "~!T",
|
||||||
'USE': "~!@",
|
'USE': "~!@",
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import queue, time, socket, logging
|
||||||
from driver.tsc_commands import TSC_COMMANDS, TSC_STATUS, LINE_SEP
|
from driver.tsc_commands import TSC_COMMANDS, TSC_STATUS, LINE_SEP
|
||||||
from driver.notifier import URL_ERR, URL_EVENT, URL_RESPONSE, send_response
|
from driver.notifier import URL_ERR, URL_EVENT, URL_RESPONSE, send_response
|
||||||
import traceback
|
import traceback
|
||||||
|
import struct
|
||||||
|
|
||||||
SOCK_TIMEOUT = 2
|
SOCK_TIMEOUT = 2
|
||||||
ENC = 'ascii'
|
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):
|
def send_file(name=None, content=None, ftype=None):
|
||||||
nonlocal prt
|
nonlocal prt
|
||||||
if ftype == 'batch':
|
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':
|
elif ftype == 'data':
|
||||||
data = content.join(LINE_SEP)+LINE_SEP
|
data = LINE_SEP.join(content)+LINE_SEP
|
||||||
to_send = TSC_COMMANDS['DOWNLOAD'].format(name=f'"{name}"',size=','+len(data),content=data)
|
to_send = TSC_COMMANDS['DOWNLOAD'].format(location='',name=f'"{name}"',size=','+str(len(bytearray(data,encoding=ENC)))+',',content=data)
|
||||||
prt.send_all(bytearray(to_send, encoding=ENC))
|
prt.sendall(bytearray(to_send, encoding=ENC))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def delete_file(name=None):
|
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:
|
if ".BAS" in name:
|
||||||
to_send = TSC_COMMANDS['REMOVE'].format(location='F,', name=f'"{name}"')
|
to_send = TSC_COMMANDS['REMOVE'].format(location='F,', name=f'"{name}"')
|
||||||
else:
|
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))
|
prt.sendall(bytearray(to_send+LINE_SEP, encoding=ENC))
|
||||||
pass
|
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():
|
def printer_pause():
|
||||||
nonlocal prt
|
nonlocal prt
|
||||||
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['PAUSE'], encoding=ENC))
|
prt.sendall(b'\x1B'+bytearray(TSC_COMMANDS['PAUSE'], encoding=ENC))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def printer_resume():
|
def printer_resume():
|
||||||
nonlocal prt
|
nonlocal prt
|
||||||
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['RESUME'], encoding=ENC))
|
prt.sendall(b'\x1B'+bytearray(TSC_COMMANDS['RESUME'], encoding=ENC))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def clear_memory():
|
def clear_memory():
|
||||||
nonlocal prt
|
nonlocal prt
|
||||||
prt.sendall(bytearray(b'\x1B'+TSC_COMMANDS['CLEAR'], encoding=ENC))
|
prt.sendall(b'\x1B'+bytearray(TSC_COMMANDS['CLEAR'], encoding=ENC))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run_batch(name=None):
|
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():
|
def get_status():
|
||||||
nonlocal prt
|
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)
|
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
|
while True: # connetti mantieni vivo il socket
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue