diff options
| author | lejeune quentin <qle@odoo.com> | 2019-03-14 16:48:16 +0100 |
|---|---|---|
| committer | lejeune quentin <qle@odoo.com> | 2019-05-29 15:49:03 +0200 |
| commit | ccb2835ccc7c7129b4d29b66fbc4ee08397e37f6 (patch) | |
| tree | c522d2111781150f159f7fd86585e7af6aa926b1 /addons | |
| parent | 0bc8e680442445d3062937e8cf3f1e5f0d18cd0e (diff) | |
[IMP] hw_drivers: Adds the ability to listen to a port
With this commit it is now possible for the IoT Box
to listen on a specific port of the box to interact
with a device via TCP / IP.
We use the library 'socket' to listen on port 9000
and if a request comes on this port we create an IoT Device
Diffstat (limited to 'addons')
| -rwxr-xr-x | addons/hw_drivers/controllers/driver.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/addons/hw_drivers/controllers/driver.py b/addons/hw_drivers/controllers/driver.py index 64d45a1fcfc..9d238227a38 100755 --- a/addons/hw_drivers/controllers/driver.py +++ b/addons/hw_drivers/controllers/driver.py @@ -18,6 +18,7 @@ from cups import Connection as cups_connection from glob import glob from base64 import b64decode from pathlib import Path +import socket from odoo import http, _ from odoo.modules.module import get_resource_path @@ -117,6 +118,7 @@ class StatusController(http.Controller): drivers = [] bt_devices = {} +socket_devices = {} iot_devices = {} class DriverMetaClass(type): @@ -348,6 +350,7 @@ class Manager(Thread): updated_devices = self.usb_loop() updated_devices.update(self.video_loop()) updated_devices.update(bt_devices) + updated_devices.update(socket_devices) if cpt % 40 == 0: printer_devices = self.printer_loop() cpt = 0 @@ -388,6 +391,19 @@ class BtManager(Thread): dm.start_discovery() dm.run() +class SocketManager(Thread): + + def run(self): + while True: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + sock.bind(('', 9000)) + sock.listen(1) + dev, addr = sock.accept() + if addr and addr[0] not in socket_devices: + iot_device = IoTDevice(type('', (), {'dev': dev}), 'socket') + socket_devices[addr[0]] = iot_device + conn = cups_connection() PPDs = conn.getPPDs() printers = conn.getPrinters() @@ -399,3 +415,7 @@ m.start() bm = BtManager() bm.daemon = True bm.start() + +sm = SocketManager() +sm.daemon = True +sm.start() |
