diff --git a/addons/hw_drivers/controllers/driver.py b/addons/hw_drivers/controllers/driver.py index 9e0b478dadc..65b57c43815 100755 --- a/addons/hw_drivers/controllers/driver.py +++ b/addons/hw_drivers/controllers/driver.py @@ -19,6 +19,7 @@ from glob import glob from base64 import b64decode from pathlib import Path import socket +import ctypes from odoo import http, _ from odoo.modules.module import get_resource_path @@ -379,6 +380,7 @@ class Manager(Thread): while 1: updated_devices = self.usb_loop() updated_devices.update(self.video_loop()) + updated_devices.update(mpdm.devices) updated_devices.update(bt_devices) updated_devices.update(socket_devices) updated_devices.update(self.serial_loop()) @@ -441,11 +443,46 @@ class SocketManager(Thread): iot_device = IoTDevice(type('', (), {'dev': dev}), 'socket') socket_devices[addr[0]] = iot_device +class MPDManager(Thread): + def __init__(self): + super(MPDManager, self).__init__() + self.devices = {} + self.mpd_session = ctypes.c_void_p() + + def run(self): + eftapi.EFT_CreateSession(ctypes.byref(self.mpd_session)) + eftapi.EFT_PutDeviceId(self.mpd_session, terminal_id.encode()) + while True: + if self.terminal_connected(terminal_id): + self.devices[terminal_id] = IoTDevice(terminal_id, 'mpd') + elif terminal_id in self.devices: + self.devices = {} + time.sleep(20) + + def terminal_connected(self, terminal_id): + eftapi.EFT_QueryStatus(self.mpd_session) + eftapi.EFT_Complete(self.mpd_session, 1) # Needed to read messages from driver + device_status = ctypes.c_long() + eftapi.EFT_GetDeviceStatusCode(self.mpd_session, ctypes.byref(device_status)) + return device_status.value in [0, 1] + + conn = cups_connection() PPDs = conn.getPPDs() printers = conn.getPrinters() cups_lock = Lock() # We can only make one call to Cups at a time +mpdm = MPDManager() +terminal_id = read_file_first_line('odoo-six-payment-terminal.conf') +if terminal_id: + try: + subprocess.check_output(["pidof", "eftdvs"]) # Check if MPD server is running + except subprocess.CalledProcessError: + subprocess.Popen(["eftdvs", "/ConfigDir", "/usr/share/eftdvs/"]) # Start MPD server + eftapi = ctypes.CDLL("eftapi.so") # Library given by Six + mpdm.daemon = True + mpdm.start() + m = Manager() m.daemon = True m.start() diff --git a/addons/hw_posbox_homepage/controllers/main.py b/addons/hw_posbox_homepage/controllers/main.py index 36a22356327..6494d11bc4f 100644 --- a/addons/hw_posbox_homepage/controllers/main.py +++ b/addons/hw_posbox_homepage/controllers/main.py @@ -53,6 +53,7 @@ wifi_config_template = jinja_env.get_template('wifi_config.html') driver_list_template = jinja_env.get_template('driver_list.html') remote_connect_template = jinja_env.get_template('remote_connect.html') configure_wizard_template = jinja_env.get_template('configure_wizard.html') +six_payment_terminal_template = jinja_env.get_template('six_payment_terminal.html') class IoTboxHomepage(web.Home): @@ -72,6 +73,12 @@ class IoTboxHomepage(web.Home): statuses[driver] = hw_proxy.drivers[driver].get_status() return statuses + def get_six_terminal(self): + path = Path.home() / 'odoo-six-payment-terminal.conf' + if path.exists(): + return path.read_text() + return 'Not Configured' + def get_homepage_data(self): hostname = str(socket.gethostname()) mac = get_mac() @@ -113,6 +120,7 @@ class IoTboxHomepage(web.Home): 'mac': ":".join(i + next(h) for i in h), 'iot_device_status': iot_device, 'server_status': get_odoo_server_url() or 'Not Configured', + 'six_terminal': self.get_six_terminal(), 'network_status': network, } @@ -296,3 +304,30 @@ class IoTboxHomepage(web.Home): return 'starting with ' + auth_token else: return 'already running' + + @http.route('/six_payment_terminal', type='http', auth='none', cors='*', csrf=False) + def six_payment_terminal(self): + return six_payment_terminal_template.render({ + 'title': 'Six Payment Terminal', + 'breadcrumb': 'Six Payment Terminal', + 'terminalId': self.get_six_terminal(), + }) + + @http.route('/six_payment_terminal_add', type='http', auth='none', cors='*', csrf=False) + def add_six_payment_terminal(self, terminal_id): + subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/"]) + path = Path.home() / 'odoo-six-payment-terminal.conf' + path.write_text(terminal_id) + subprocess.check_call(["sudo", "service", "odoo", "restart"]) + subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"]) + return 'http://' + get_ip() + ':8069' + + @http.route('/six_payment_terminal_clear', type='http', auth='none', cors='*', csrf=False) + def clear_six_payment_terminal(self): + subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/"]) + path = Path.home() / 'odoo-six-payment-terminal.conf' + if path.exists(): + path.unlink() + subprocess.check_call(["sudo", "service", "odoo", "restart"]) + subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"]) + return "" diff --git a/addons/hw_posbox_homepage/views/homepage.html b/addons/hw_posbox_homepage/views/homepage.html index 74a502f7ca7..d70238fc54f 100644 --- a/addons/hw_posbox_homepage/views/homepage.html +++ b/addons/hw_posbox_homepage/views/homepage.html @@ -22,6 +22,7 @@ font-weight: bold; vertical-align: top; width: 30%; + text-align: left; } .device-status { margin: 6px 0; @@ -109,6 +110,12 @@
+ Set the Terminal ID (TID) of the terminal you want to use. +
+ + {% if terminalId %} ++ Current Terminal Id: {{ terminalId }} +
+