[FIX] hw_proxy,hw_blackbox_be: make RS-232 drivers protect their device
RS-232 drivers now need to register any device they are handling in the hw_proxy.rs232_devices map. This will prevent other drivers from probing them, possibly messing up with the device. Any update to rs232_devices must be done while holding the hw_proxy.rs232_lock. The hw_scale driver will be updated to use this mechanism in the next commit, that will also handle a new RS-232 scale protocol.
This commit is contained in:
parent
2fd4dfca7f
commit
eeadeb0d6e
|
@ -14,6 +14,8 @@ import openerp.addons.hw_proxy.controllers.main as hw_proxy
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DRIVER_NAME = 'fiscal_data_module'
|
||||||
|
|
||||||
class Blackbox(Thread):
|
class Blackbox(Thread):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
|
@ -39,6 +41,7 @@ class Blackbox(Thread):
|
||||||
# request. The first device to give an answer that makes sense
|
# request. The first device to give an answer that makes sense
|
||||||
# wins.
|
# wins.
|
||||||
def _find_device_path_by_probing(self):
|
def _find_device_path_by_probing(self):
|
||||||
|
with hw_proxy.rs232_lock:
|
||||||
path = "/dev/serial/by-path/"
|
path = "/dev/serial/by-path/"
|
||||||
probe_message = self._wrap_low_level_message_around("S000")
|
probe_message = self._wrap_low_level_message_around("S000")
|
||||||
|
|
||||||
|
@ -46,18 +49,22 @@ class Blackbox(Thread):
|
||||||
devices = listdir(path)
|
devices = listdir(path)
|
||||||
except OSError:
|
except OSError:
|
||||||
_logger.warning(path + " doesn't exist")
|
_logger.warning(path + " doesn't exist")
|
||||||
|
self.set_status("disconnected", ["No RS-232 device (or emulated ones) found"])
|
||||||
else:
|
else:
|
||||||
for device in listdir(path):
|
for device in devices:
|
||||||
|
if device in hw_proxy.rs232_devices:
|
||||||
|
continue
|
||||||
path_to_device = path + device
|
path_to_device = path + device
|
||||||
_logger.debug("Probing " + device)
|
_logger.debug("Probing " + device)
|
||||||
|
|
||||||
if self._send_to_blackbox(probe_message, 21, path_to_device, just_wait_for_ack=True):
|
if self._send_to_blackbox(probe_message, 21, path_to_device, just_wait_for_ack=True):
|
||||||
_logger.info(device + " will be used as the blackbox")
|
_logger.info(device + " will be used as the blackbox")
|
||||||
self.set_status("connected", [device])
|
self.set_status("connected", [device])
|
||||||
|
hw_proxy.rs232_devices[device] = DRIVER_NAME
|
||||||
return path_to_device
|
return path_to_device
|
||||||
|
|
||||||
_logger.warning("Blackbox could not be found")
|
_logger.warning("Blackbox could not be found")
|
||||||
self.set_status("error", ["Couldn't find the Fiscal Data Module"])
|
self.set_status("disconnected", ["Couldn't find the Fiscal Data Module"])
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def _lrc(self, msg):
|
def _lrc(self, msg):
|
||||||
|
@ -152,7 +159,7 @@ class Blackbox(Thread):
|
||||||
|
|
||||||
if isfile("/home/pi/registered_blackbox_be"):
|
if isfile("/home/pi/registered_blackbox_be"):
|
||||||
blackbox_thread = Blackbox()
|
blackbox_thread = Blackbox()
|
||||||
hw_proxy.drivers['fiscal_data_module'] = blackbox_thread
|
hw_proxy.drivers[DRIVER_NAME] = blackbox_thread
|
||||||
|
|
||||||
class BlackboxDriver(hw_proxy.Proxy):
|
class BlackboxDriver(hw_proxy.Proxy):
|
||||||
@http.route('/hw_proxy/request_blackbox/', type='json', auth='none', cors='*')
|
@http.route('/hw_proxy/request_blackbox/', type='json', auth='none', cors='*')
|
||||||
|
|
|
@ -11,6 +11,8 @@ import subprocess
|
||||||
import simplejson
|
import simplejson
|
||||||
import werkzeug
|
import werkzeug
|
||||||
import werkzeug.wrappers
|
import werkzeug.wrappers
|
||||||
|
from threading import Lock
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,6 +32,11 @@ BANNED_DEVICES = set([
|
||||||
# so that 'status' can return the status of all active drivers
|
# so that 'status' can return the status of all active drivers
|
||||||
drivers = {}
|
drivers = {}
|
||||||
|
|
||||||
|
# keep a list of RS-232 devices that have been recognized by a driver,
|
||||||
|
# so other drivers can skip them during probes
|
||||||
|
rs232_devices = {} # {'/path/to/device': 'driver'}
|
||||||
|
rs232_lock = Lock() # must be held to update `rs232_devices`
|
||||||
|
|
||||||
class Proxy(http.Controller):
|
class Proxy(http.Controller):
|
||||||
|
|
||||||
def get_status(self):
|
def get_status(self):
|
||||||
|
|
Loading…
Reference in New Issue