Search in sources :

Example 1 with UsbModemDriver

use of org.eclipse.kura.linux.net.modem.UsbModemDriver in project kura by eclipse.

the class NetworkServiceImpl method handleEvent.

@Override
public void handleEvent(Event event) {
    s_logger.debug("handleEvent() :: topic: {}", event.getTopic());
    String topic = event.getTopic();
    if (topic.equals(UsbDeviceAddedEvent.USB_EVENT_DEVICE_ADDED_TOPIC)) {
        // validate mandatory properties
        if (event.getProperty(UsbDeviceEvent.USB_EVENT_VENDOR_ID_PROPERTY) == null) {
            return;
        }
        if (event.getProperty(UsbDeviceEvent.USB_EVENT_PRODUCT_ID_PROPERTY) == null) {
            return;
        }
        if (event.getProperty(UsbDeviceEvent.USB_EVENT_USB_PORT_PROPERTY) == null) {
            return;
        }
        if (event.getProperty(UsbDeviceEvent.USB_EVENT_RESOURCE_PROPERTY) == null) {
            return;
        }
        // do we care?
        final SupportedUsbModemInfo modemInfo = SupportedUsbModemsInfo.getModem((String) event.getProperty(UsbDeviceEvent.USB_EVENT_VENDOR_ID_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_PRODUCT_ID_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_PRODUCT_NAME_PROPERTY));
        if (modemInfo != null) {
            // Found one - see if we have some info for it.
            // Also check if we are getting more devices than expected.
            // This can happen if all the modem resources cannot be removed from the OS or from Kura.
            // In this case we did not receive an UsbDeviceRemovedEvent and we did not post
            // an ModemRemovedEvent. Should we do it here?
            List<? extends UsbModemDriver> drivers = modemInfo.getDeviceDrivers();
            for (UsbModemDriver driver : drivers) {
                try {
                    driver.install();
                } catch (Exception e) {
                    s_logger.error("handleEvent() :: Failed to install modem device driver {} - {}", driver.getName(), e);
                }
            }
            UsbModemDevice usbModem = this.m_usbModems.get(event.getProperty(UsbDeviceEvent.USB_EVENT_USB_PORT_PROPERTY));
            boolean createNewUsbModemDevice = false;
            if (usbModem == null) {
                createNewUsbModemDevice = true;
            } else if (modemInfo.getNumTtyDevs() > 0 && modemInfo.getNumBlockDevs() > 0) {
                if (usbModem.getTtyDevs().size() >= modemInfo.getNumTtyDevs() && usbModem.getBlockDevs().size() >= modemInfo.getNumBlockDevs()) {
                    createNewUsbModemDevice = true;
                }
            } else if (modemInfo.getNumTtyDevs() > 0 && usbModem.getTtyDevs().size() >= modemInfo.getNumTtyDevs() || modemInfo.getNumBlockDevs() > 0 && usbModem.getBlockDevs().size() >= modemInfo.getNumBlockDevs()) {
                createNewUsbModemDevice = true;
            }
            if (createNewUsbModemDevice) {
                if (usbModem == null) {
                    s_logger.debug("handleEvent() :: Modem not found. Create one");
                } else {
                    s_logger.debug("handleEvent() :: Found modem with too many resources: {}. Create a new one", usbModem);
                }
                usbModem = new UsbModemDevice((String) event.getProperty(UsbDeviceEvent.USB_EVENT_VENDOR_ID_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_PRODUCT_ID_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_MANUFACTURER_NAME_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_PRODUCT_NAME_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_BUS_NUMBER_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_DEVICE_PATH_PROPERTY));
            }
            String resource = (String) event.getProperty(UsbDeviceEvent.USB_EVENT_RESOURCE_PROPERTY);
            s_logger.debug("handleEvent() :: Adding resource: {} for: {}", resource, usbModem.getUsbPort());
            if (resource.contains("tty")) {
                usbModem.addTtyDev(resource);
            } else {
                usbModem.addBlockDev(resource);
            }
            this.m_usbModems.put(usbModem.getUsbPort(), usbModem);
            // At this point, we should have some modems - display them
            s_logger.info("handleEvent() :: Modified modem (Added resource): {}", usbModem);
            s_logger.debug("handleEvent() :: usbModem.getTtyDevs().size()={}, modemInfo.getNumTtyDevs()={}", usbModem.getTtyDevs().size(), modemInfo.getNumTtyDevs());
            s_logger.debug("handleEvent() :: usbModem.getBlockDevs().size()={}, modemInfo.getNumBlockDevs()={}", usbModem.getBlockDevs().size(), modemInfo.getNumBlockDevs());
            // Check for correct number of resources
            if (usbModem.getTtyDevs().size() == modemInfo.getNumTtyDevs() && usbModem.getBlockDevs().size() == modemInfo.getNumBlockDevs()) {
                s_logger.info("handleEvent() :: posting ModemAddedEvent -- USB_EVENT_DEVICE_ADDED_TOPIC: {}", usbModem);
                this.m_eventAdmin.postEvent(new ModemAddedEvent(usbModem));
                this.m_addedModems.add(usbModem.getUsbPort());
                if (OS_VERSION != null && TARGET_NAME != null && OS_VERSION.equals(KuraConstants.Mini_Gateway.getImageName() + "_" + KuraConstants.Mini_Gateway.getImageVersion()) && TARGET_NAME.equals(KuraConstants.Mini_Gateway.getTargetName()) || OS_VERSION.equals(KuraConstants.Reliagate_10_11.getImageName() + "_" + KuraConstants.Reliagate_10_11.getImageVersion()) && TARGET_NAME.equals(KuraConstants.Reliagate_10_11.getTargetName())) {
                    if (this.m_serialModem != null) {
                        if (SupportedUsbModemInfo.Telit_HE910_D.getVendorId().equals(usbModem.getVendorId()) && SupportedUsbModemInfo.Telit_HE910_D.getProductId().equals(usbModem.getProductId())) {
                            s_logger.info("handleEvent() :: Removing {} from addedModems", this.m_serialModem.getProductName());
                            this.m_addedModems.remove(this.m_serialModem.getProductName());
                        }
                    }
                }
            }
        }
    /*
             * System.out.println("ADDED Device: " + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_VENDOR_ID_PROPERTY)
             * + ":" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_PRODUCT_ID_PROPERTY));
             * System.out.println("\t" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_RESOURCE_PROPERTY));
             * System.out.println("\t" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_MANUFACTURER_NAME_PROPERTY));
             * System.out.println("\t" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_PRODUCT_NAME_PROPERTY));
             * System.out.println("\t" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_USB_PORT_PROPERTY));
             */
    } else if (topic.equals(UsbDeviceRemovedEvent.USB_EVENT_DEVICE_REMOVED_TOPIC)) {
        // validate mandatory properties
        if (event.getProperty(UsbDeviceEvent.USB_EVENT_VENDOR_ID_PROPERTY) == null) {
            return;
        }
        if (event.getProperty(UsbDeviceEvent.USB_EVENT_PRODUCT_ID_PROPERTY) == null) {
            return;
        }
        if (event.getProperty(UsbDeviceEvent.USB_EVENT_USB_PORT_PROPERTY) == null) {
            return;
        }
        // do we care?
        SupportedUsbModemInfo modemInfo = SupportedUsbModemsInfo.getModem((String) event.getProperty(UsbDeviceEvent.USB_EVENT_VENDOR_ID_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_PRODUCT_ID_PROPERTY), (String) event.getProperty(UsbDeviceEvent.USB_EVENT_PRODUCT_NAME_PROPERTY));
        if (modemInfo != null) {
            // found one - remove if it exists
            UsbModemDevice usbModem = this.m_usbModems.remove(event.getProperty(UsbDeviceEvent.USB_EVENT_USB_PORT_PROPERTY));
            if (usbModem != null) {
                s_logger.info("handleEvent() :: Removing modem: {}", usbModem);
                this.m_addedModems.remove(usbModem.getUsbPort());
                Map<String, String> properties = new HashMap<String, String>();
                properties.put(UsbDeviceEvent.USB_EVENT_BUS_NUMBER_PROPERTY, usbModem.getUsbBusNumber());
                properties.put(UsbDeviceEvent.USB_EVENT_DEVICE_PATH_PROPERTY, usbModem.getUsbDevicePath());
                properties.put(UsbDeviceEvent.USB_EVENT_USB_PORT_PROPERTY, usbModem.getUsbPort());
                properties.put(UsbDeviceEvent.USB_EVENT_VENDOR_ID_PROPERTY, usbModem.getVendorId());
                properties.put(UsbDeviceEvent.USB_EVENT_PRODUCT_ID_PROPERTY, usbModem.getProductId());
                properties.put(UsbDeviceEvent.USB_EVENT_MANUFACTURER_NAME_PROPERTY, usbModem.getManufacturerName());
                properties.put(UsbDeviceEvent.USB_EVENT_PRODUCT_NAME_PROPERTY, usbModem.getProductName());
                this.m_eventAdmin.postEvent(new ModemRemovedEvent(properties));
            }
        }
    /*
             * System.out.println("REMOVED Device: " +
             * event.getProperty(UsbDeviceAddedEvent.USB_EVENT_VENDOR_ID_PROPERTY) + ":" +
             * event.getProperty(UsbDeviceAddedEvent.USB_EVENT_PRODUCT_ID_PROPERTY));
             * System.out.println("\t" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_RESOURCE_PROPERTY));
             * System.out.println("\t" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_MANUFACTURER_NAME_PROPERTY));
             * System.out.println("\t" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_PRODUCT_NAME_PROPERTY));
             * System.out.println("\t" + event.getProperty(UsbDeviceAddedEvent.USB_EVENT_USB_PORT_PROPERTY));
             */
    } else if (topic.equals(SerialModemAddedEvent.SERIAL_MODEM_EVENT_ADDED_TOPIC)) {
        SerialModemAddedEvent serialModemAddedEvent = (SerialModemAddedEvent) event;
        SupportedSerialModemInfo serialModemInfo = serialModemAddedEvent.getSupportedSerialModemInfo();
        if (serialModemInfo != null) {
            if (OS_VERSION != null && TARGET_NAME != null && OS_VERSION.equals(KuraConstants.Mini_Gateway.getImageName() + "_" + KuraConstants.Mini_Gateway.getImageVersion()) && TARGET_NAME.equals(KuraConstants.Mini_Gateway.getTargetName()) || OS_VERSION.equals(KuraConstants.Reliagate_10_11.getImageName() + "_" + KuraConstants.Reliagate_10_11.getImageVersion()) && TARGET_NAME.equals(KuraConstants.Reliagate_10_11.getTargetName())) {
                if (this.m_usbModems.isEmpty()) {
                    this.m_serialModem = new SerialModemDevice(serialModemInfo.getModemName(), serialModemInfo.getManufacturerName(), serialModemInfo.getDriver().getComm().getSerialPorts());
                    if (this.m_serialModem != null) {
                        s_logger.debug("handleEvent() :: posting ModemAddedEvent for serial modem: {}", this.m_serialModem.getProductName());
                        this.m_eventAdmin.postEvent(new ModemAddedEvent(this.m_serialModem));
                        this.m_addedModems.add(this.m_serialModem.getProductName());
                    }
                } else {
                    s_logger.info("handleEvent() :: Ignoring {} modem since it has already been detected as a USB device", serialModemInfo.getModemName());
                }
            } else {
                this.m_serialModem = new SerialModemDevice(serialModemInfo.getModemName(), serialModemInfo.getManufacturerName(), serialModemInfo.getDriver().getComm().getSerialPorts());
                if (this.m_serialModem != null) {
                    s_logger.debug("handleEvent() :: posting ModemAddedEvent for serial modem: {}", this.m_serialModem.getProductName());
                    this.m_eventAdmin.postEvent(new ModemAddedEvent(this.m_serialModem));
                    this.m_addedModems.add(this.m_serialModem.getProductName());
                }
            }
        }
    } else {
        s_logger.error("handleEvent() :: Unexpected event topic: {}", topic);
    }
}
Also used : SerialModemDevice(org.eclipse.kura.net.modem.SerialModemDevice) SerialModemAddedEvent(org.eclipse.kura.linux.net.modem.SerialModemAddedEvent) ModemAddedEvent(org.eclipse.kura.net.modem.ModemAddedEvent) SupportedSerialModemInfo(org.eclipse.kura.linux.net.modem.SupportedSerialModemInfo) KuraException(org.eclipse.kura.KuraException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) UsbModemDevice(org.eclipse.kura.usb.UsbModemDevice) UsbModemDriver(org.eclipse.kura.linux.net.modem.UsbModemDriver) ModemRemovedEvent(org.eclipse.kura.net.modem.ModemRemovedEvent) Map(java.util.Map) HashMap(java.util.HashMap) SupportedUsbModemInfo(org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo) SerialModemAddedEvent(org.eclipse.kura.linux.net.modem.SerialModemAddedEvent)

Example 2 with UsbModemDriver

use of org.eclipse.kura.linux.net.modem.UsbModemDriver in project kura by eclipse.

the class NetworkServiceImpl method toggleModem.

private void toggleModem(SupportedUsbModemInfo modemInfo) throws Exception {
    while (!s_stopThread.get()) {
        ModemDriver modemDriver = null;
        List<? extends UsbModemDriver> usbDeviceDrivers = modemInfo.getDeviceDrivers();
        if (usbDeviceDrivers != null && !usbDeviceDrivers.isEmpty()) {
            modemDriver = usbDeviceDrivers.get(0);
        }
        if (modemDriver != null) {
            boolean status = false;
            try {
                s_logger.info("toggleModem() :: turning modem off ...");
                if (modemDriver.turnModemOff()) {
                    modemDriver.sleep(3000);
                    s_logger.info("toggleModem() :: turning modem on ...");
                    status = modemDriver.turnModemOn();
                    if (status) {
                        s_logger.info("toggleModem() :: modem has been toggled successfully ...");
                        s_stopThread.set(status);
                        toggleModemNotity();
                    }
                }
            } catch (Exception e) {
                s_logger.error("toggleModem() :: failed to toggle modem - {}", e);
            }
        }
        if (!s_stopThread.get()) {
            toggleModemWait();
        }
    }
}
Also used : UsbModemDriver(org.eclipse.kura.linux.net.modem.UsbModemDriver) ModemDriver(org.eclipse.kura.linux.net.modem.ModemDriver) KuraException(org.eclipse.kura.KuraException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 3 with UsbModemDriver

use of org.eclipse.kura.linux.net.modem.UsbModemDriver in project kura by eclipse.

the class NetworkConfigurationServiceImpl method addPropertiesInModemInterface.

private void addPropertiesInModemInterface(ModemInterfaceImpl<? extends NetInterfaceAddress> modemInterface) throws KuraException {
    String interfaceName = modemInterface.getName();
    if (this.m_modemManagerService != null) {
        String modemPort = this.m_networkService.getModemUsbPort(interfaceName);
        if (modemPort == null) {
            modemPort = interfaceName;
        }
        CellularModem modem = this.m_modemManagerService.getModemService(modemPort);
        if (modem != null) {
            // set modem properties
            modemInterface.setSerialNumber(modem.getSerialNumber());
            modemInterface.setModel(modem.getModel());
            modemInterface.setFirmwareVersion(modem.getRevisionID());
            modemInterface.setGpsSupported(modem.isGpsSupported());
            // set modem driver
            UsbModemDevice usbModemDevice = (UsbModemDevice) modemInterface.getUsbDevice();
            if (usbModemDevice != null) {
                List<? extends UsbModemDriver> drivers = null;
                drivers = SupportedUsbModemsFactoryInfo.getDeviceDrivers(usbModemDevice.getVendorId(), usbModemDevice.getProductId());
                if (drivers != null && drivers.size() > 0) {
                    UsbModemDriver driver = drivers.get(0);
                    modemInterface.setDriver(driver.getName());
                }
            }
        }
    }
}
Also used : UsbModemDevice(org.eclipse.kura.usb.UsbModemDevice) CellularModem(org.eclipse.kura.net.modem.CellularModem) UsbModemDriver(org.eclipse.kura.linux.net.modem.UsbModemDriver)

Aggregations

UsbModemDriver (org.eclipse.kura.linux.net.modem.UsbModemDriver)3 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 KuraException (org.eclipse.kura.KuraException)2 UsbModemDevice (org.eclipse.kura.usb.UsbModemDevice)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ModemDriver (org.eclipse.kura.linux.net.modem.ModemDriver)1 SerialModemAddedEvent (org.eclipse.kura.linux.net.modem.SerialModemAddedEvent)1 SupportedSerialModemInfo (org.eclipse.kura.linux.net.modem.SupportedSerialModemInfo)1 SupportedUsbModemInfo (org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo)1 CellularModem (org.eclipse.kura.net.modem.CellularModem)1 ModemAddedEvent (org.eclipse.kura.net.modem.ModemAddedEvent)1 ModemRemovedEvent (org.eclipse.kura.net.modem.ModemRemovedEvent)1 SerialModemDevice (org.eclipse.kura.net.modem.SerialModemDevice)1