Пример #1
0
 def connect_box(self, token):
     """
     This route is called when we want that a IoT Box will be connected to a Odoo DB
     token is a base 64 encoded string and have 2 argument separate by |
     1 - url of odoo DB
     2 - token. This token will be compared to the token of Odoo. He have 1 hour lifetime
     """
     server = helpers.get_odoo_server_url()
     image = get_resource_path('hw_drivers', 'static/img', 'False.jpg')
     if server == '':
         credential = b64decode(token).decode('utf-8').split('|')
         url = credential[0]
         token = credential[1]
         if len(credential) > 2:
             # IoT Box send token with db_uuid and enterprise_code only since V13
             db_uuid = credential[2]
             enterprise_code = credential[3]
             helpers.add_credential(db_uuid, enterprise_code)
         try:
             subprocess.check_call([
                 get_resource_path(
                     'point_of_sale',
                     'tools/posbox/configuration/connect_to_server.sh'),
                 url, '', token, 'noreboot'
             ])
             helpers.check_certificate()
             m.send_alldevices()
             m.load_drivers()
             image = get_resource_path('hw_drivers', 'static/img',
                                       'True.jpg')
         except subprocess.CalledProcessError as e:
             _logger.error('A error encountered : %s ' % e.output)
     if os.path.isfile(image):
         with open(image, 'rb') as f:
             return f.read()
Пример #2
0
    def run(self):
        """
        Thread that will load interfaces and drivers and contact the odoo server with the updates
        """

        helpers.check_git_branch()
        helpers.check_certificate()

        # We first add the IoT Box to the connected DB because IoT handlers cannot be downloaded if
        # the identifier of the Box is not found in the DB. So add the Box to the DB.
        self.send_alldevices()
        helpers.download_iot_handlers()
        helpers.load_iot_handlers()

        # Start the interfaces
        for interface in interfaces.values():
            i = interface()
            i.daemon = True
            i.start()

        # Check every 3 secondes if the list of connected devices has changed and send the updated
        # list to the connected DB.
        self.previous_iot_devices = []
        while 1:
            try:
                if iot_devices != self.previous_iot_devices:
                    self.send_alldevices()
                    self.previous_iot_devices = iot_devices.copy()
                time.sleep(3)
            except:
                # No matter what goes wrong, the Manager loop needs to keep running
                _logger.error(format_exc())
Пример #3
0
 def run(self):
     """
     Thread that will check connected/disconnected device, load drivers if needed and contact the odoo server with the updates
     """
     helpers.check_git_branch()
     helpers.check_certificate()
     updated_devices = {}
     self.send_alldevices()
     self.load_drivers()
     # The list of devices doesn't change after the Raspberry has booted
     display_devices = self.get_connected_displays()
     cpt = 0
     while 1:
         try:
             updated_devices = self.usb_loop()
             updated_devices.update(self.video_loop())
             updated_devices.update(mpdm.devices)
             updated_devices.update(display_devices)
             updated_devices.update(bt_devices)
             updated_devices.update(socket_devices)
             updated_devices.update(self.serial_loop())
             if cpt % 40 == 0:
                 printer_devices = self.printer_loop()
                 cpt = 0
             updated_devices.update(printer_devices)
             cpt += 1
             added = updated_devices.keys() - self.devices.keys()
             removed = self.devices.keys() - updated_devices.keys()
             self.devices = updated_devices
             send_devices = False
             for path in [device_rm for device_rm in removed if device_rm in iot_devices]:
                 iot_devices[path].disconnect()
                 _logger.info('Device %s is now disconnected', path)
                 send_devices = True
             for path in [device_add for device_add in added if device_add not in iot_devices]:
                 for driverclass in [d for d in drivers if d.connection_type == self.devices[path].connection_type]:
                     if driverclass.supported(device = updated_devices[path].dev):
                         _logger.info('Device %s is now connected', path)
                         d = driverclass(device = updated_devices[path].dev)
                         d.daemon = True
                         iot_devices[path] = d
                         # Start the thread after creating the iot_devices entry so the
                         # thread can assume the iot_devices entry will exist while it's
                         # running, at least until the `disconnect` above gets triggered
                         # when `removed` is not empty. Threads are currently not
                         # explicitly terminated when that happens, so the results can
                         # be undefined.
                         d.start()
                         send_devices = True
                         break
             if send_devices:
                 self.send_alldevices()
             time.sleep(3)
         except:
             # No matter what goes wrong, the Manager loop needs to keep running
             _logger.error(format_exc())
Пример #4
0
 def run(self):
     """
     Thread that will check connected/disconnected device, load drivers if needed and contact the odoo server with the updates
     """
     helpers.check_git_branch()
     helpers.check_certificate()
     updated_devices = {}
     self.send_alldevices()
     self.load_drivers()
     # The list of devices doesn't change after the Raspberry has booted
     display_devices = self.get_connected_displays()
     cpt = 0
     while 1:
         updated_devices = self.usb_loop()
         updated_devices.update(self.video_loop())
         updated_devices.update(mpdm.devices)
         updated_devices.update(display_devices)
         updated_devices.update(bt_devices)
         updated_devices.update(socket_devices)
         updated_devices.update(self.serial_loop())
         if cpt % 40 == 0:
             printer_devices = self.printer_loop()
             cpt = 0
         updated_devices.update(printer_devices)
         cpt += 1
         added = updated_devices.keys() - self.devices.keys()
         removed = self.devices.keys() - updated_devices.keys()
         self.devices = updated_devices
         send_devices = False
         for path in [
                 device_rm for device_rm in removed
                 if device_rm in iot_devices
         ]:
             iot_devices[path].disconnect()
             _logger.info('Device %s is now disconnected', path)
             send_devices = True
         for path in [
                 device_add for device_add in added
                 if device_add not in iot_devices
         ]:
             for driverclass in [
                     d for d in drivers if d.connection_type ==
                     self.devices[path].connection_type
             ]:
                 if driverclass.supported(device=updated_devices[path].dev):
                     _logger.info('Device %s is now connected', path)
                     d = driverclass(device=updated_devices[path].dev)
                     d.daemon = True
                     d.start()
                     iot_devices[path] = d
                     send_devices = True
                     break
         if send_devices:
             self.send_alldevices()
         time.sleep(3)
Пример #5
0
 def run(self):
     """
     Thread that will check connected/disconnected device, load drivers if needed and contact the odoo server with the updates
     """
     helpers.check_git_branch()
     helpers.check_certificate()
     self.send_alldevices()
     self.load_iot_handlers()
     self.previous_iot_devices = []
     for interface in interfaces.values():
         i = interface()
         i.daemon = True
         i.start()
     while 1:
         if iot_devices != self.previous_iot_devices:
             self.send_alldevices()
             self.previous_iot_devices = iot_devices.copy()
         time.sleep(3)
Пример #6
0
 def check_certificate(self):
     """
     This route is called when we want to check if certificate is up-to-date
     Used in cron.daily
     """
     helpers.check_certificate()