def note_acceptor_worker(queue_request, queue_response, params): verbose = params.verbose lh = logging.FileHandler( params.logfile) if params.daemon else logging.StreamHandler(sys.stdout) essp = EsspApi(params.device, logger_handler=lh, verbose=(verbose and verbose > 1)) logger = essp.get_logger() essp_state = 'disabled' logger.info('[WORKER] Start') cmds = { 'sync': lambda: essp.sync, 'enable': lambda: essp.enable, 'disable': lambda: essp.disable, 'hold': lambda: essp.hold, 'display_on': lambda: essp.display_on, 'display_off': lambda: essp.display_off } credit = 0 while True: try: cmd = queue_request.get(block=False)['cmd'] except: pass else: res = {'cmd': cmd, 'result': False} logger.info('[WORKER] command: %s' % cmd) if cmd in ('start', 'disable'): credit = 0 essp_state = 'disabled' elif cmd == 'enable': essp.sync() essp.enable_higher_protocol() #essp.disable() essp.set_inhibits(essp.easy_inhibit([1, 1, 1, 1, 1, 1, 1]), '0') credit = 0 essp_state = 'enabled' if cmd in cmds: res['result'] = cmds[cmd]()() elif cmd == 'start': credit = 0 res['result'] = bool( essp.sync() and essp.enable_higher_protocol() and essp.disable() and essp.set_inhibits( essp.easy_inhibit([1, 1, 1, 1, 1, 1, 1]), '0')) queue_response.put(res) continue if essp_state == 'enabled': for event in essp.poll(): status = event['status'] param = event['param'] if status == EsspApi.DISABLED: continue if status == EsspApi.CREDIT_NOTE: logger.info('[WORKER] credit %s' % Euros[param]) credit += Euros[param] elif status == EsspApi.READ_NOTE: logger.info('[WORKER] read note %s' % param) queue_response.put({ 'cmd': 'poll', 'status': status, 'param': param, 'credit': credit }) sleep(0.8) if os.getppid() == 1: logger.info('[WORKER] Parent process has terminated') break
def note_acceptor_worker(queue_request, queue_response, params): verbose = params.verbose if params.test: serial.Serial = SerialMock lh = logging.FileHandler(params.logfile) if params.daemon else logging.StreamHandler(sys.stdout) verbose = verbose and verbose > 1 essp = EsspApi('/dev/ttyACM0', logger_handler=lh, verbose=verbose) logger = essp.get_logger() logger.info('[WORKER] Start') cmds = { 'sync': lambda: essp.sync, 'reset': lambda: essp.reset, 'enable': lambda: essp.enable, 'disable': lambda: essp.disable, 'hold': lambda: essp.hold, 'display_on': lambda: essp.display_on, 'display_off': lambda: essp.display_off, } essp_state = 'disabled' while True: try: data = queue_request.get(block=False) except: pass else: logger.info('[WORKER] command: %s' % data['cmd']) cmd = data['cmd'] res = {'cmd': cmd, 'result': False} if cmd == 'test': res['result'] = True queue_response.put(res) continue if cmd in ('start', 'reset', 'disable'): if essp_state == 'hold': essp.reject_note() essp_state = 'disabled' elif cmd in ('enable',): if essp_state == 'disabled': essp_state = 'enabled' if HOLD_AND_WAIT_ACCEPT_CMD else 'accept' if cmd in cmds: res['result'] = cmds[cmd]()() elif cmd == 'start': res['result'] = bool(essp.sync() and essp.enable_higher_protocol() and essp.disable() and essp.set_inhibits(essp.easy_inhibit([1, 1, 1, 1, 1, 1, 1]), '0')) elif cmd == 'accept': if essp_state == 'hold': essp_state = 'accept' res['result'] = True queue_response.put(res) continue if essp_state in ('enabled', 'accept'): for event in essp.poll(): status = event['status'] param = event['param'] if status == EsspApi.DISABLED: continue if status == EsspApi.READ_NOTE: logger.info('[WORKER] read note %s' % (param if param else 'unknown yet')) if event['param'] and essp_state == 'enabled': essp_state = 'hold' essp.hold() queue_response.put({'cmd': 'poll', 'status': status, 'param': param}) if essp_state == 'hold': essp.hold() sleep(1) if os.getppid() == 1: logger.info('[WORKER] Parent process has terminated') break
def note_acceptor_worker(queue_request, queue_response, params): verbose = params.verbose if params.test: serial.Serial = SerialMock lh = logging.FileHandler( params.logfile) if params.daemon else logging.StreamHandler(sys.stdout) verbose = verbose and verbose > 1 essp = EsspApi('/dev/ttyACM0', logger_handler=lh, verbose=verbose) logger = essp.get_logger() logger.info('[WORKER] Start') cmds = { 'sync': lambda: essp.sync, 'reset': lambda: essp.reset, 'enable': lambda: essp.enable, 'disable': lambda: essp.disable, 'hold': lambda: essp.hold, 'display_on': lambda: essp.display_on, 'display_off': lambda: essp.display_off, } essp_state = 'disabled' while True: try: data = queue_request.get(block=False) except: pass else: logger.info('[WORKER] command: %s' % data['cmd']) cmd = data['cmd'] res = {'cmd': cmd, 'result': False} if cmd == 'test': res['result'] = True queue_response.put(res) continue if cmd in ('start', 'reset', 'disable'): if essp_state == 'hold': essp.reject_note() essp_state = 'disabled' elif cmd in ('enable', ): if essp_state == 'disabled': essp_state = 'enabled' if HOLD_AND_WAIT_ACCEPT_CMD else 'accept' if cmd in cmds: res['result'] = cmds[cmd]()() elif cmd == 'start': res['result'] = bool( essp.sync() and essp.enable_higher_protocol() and essp.disable() and essp.set_inhibits( essp.easy_inhibit([1, 1, 1, 1, 1, 1, 1]), '0')) elif cmd == 'accept': if essp_state == 'hold': essp_state = 'accept' res['result'] = True queue_response.put(res) continue if essp_state in ('enabled', 'accept'): for event in essp.poll(): status = event['status'] param = event['param'] if status == EsspApi.DISABLED: continue if status == EsspApi.READ_NOTE: logger.info('[WORKER] read note %s' % (param if param else 'unknown yet')) if event['param'] and essp_state == 'enabled': essp_state = 'hold' essp.hold() queue_response.put({ 'cmd': 'poll', 'status': status, 'param': param }) if essp_state == 'hold': essp.hold() sleep(1) if os.getppid() == 1: logger.info('[WORKER] Parent process has terminated') break