use of org.eclipse.kura.usb.UsbModemDevice 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);
}
}
use of org.eclipse.kura.usb.UsbModemDevice in project kura by eclipse.
the class NetworkServiceImpl method getModemPppPort.
/**
* Given a usb port address, look up the associated ppp interface name
*
* @throws KuraException
*/
@Override
public String getModemPppPort(ModemDevice modemDevice) throws KuraException {
String deviceName = null;
String modemId = null;
if (modemDevice instanceof UsbModemDevice) {
UsbModemDevice usbModem = (UsbModemDevice) modemDevice;
SupportedUsbModemInfo modemInfo = SupportedUsbModemsInfo.getModem(usbModem.getVendorId(), usbModem.getProductId(), usbModem.getProductName());
deviceName = modemInfo.getDeviceName();
modemId = usbModem.getUsbPort();
} else if (modemDevice instanceof SerialModemDevice) {
SerialModemDevice serialModem = (SerialModemDevice) modemDevice;
deviceName = serialModem.getProductName();
modemId = serialModem.getProductName();
}
// find a matching config file in the ppp peers directory
File peersDir = new File(PPP_PEERS_DIR);
if (peersDir.isDirectory()) {
File[] peerFiles = peersDir.listFiles();
for (File peerFile : peerFiles) {
String peerFilename = peerFile.getName();
if (peerFilename.startsWith(deviceName) && peerFilename.endsWith(/* usbPort */
modemId)) {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(peerFile));
String line = null;
StringBuilder sbIfaceName = null;
while ((line = br.readLine()) != null) {
if (line.startsWith("unit")) {
sbIfaceName = new StringBuilder("ppp");
sbIfaceName.append(line.substring("unit".length()).trim());
break;
}
}
return sbIfaceName.toString();
} catch (Exception e) {
s_logger.error("failed to parse peers file - {}", e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
s_logger.error("failed to close buffered reader - {}", e);
}
}
}
break;
}
}
}
return null;
}
use of org.eclipse.kura.usb.UsbModemDevice in project kura by eclipse.
the class NetworkServiceImpl method getModemInterface.
private ModemInterface<ModemInterfaceAddress> getModemInterface(String interfaceName, boolean isUp, ModemDevice modemDevice) throws KuraException {
ModemInterfaceImpl<ModemInterfaceAddress> modemInterface = new ModemInterfaceImpl<ModemInterfaceAddress>(interfaceName);
modemInterface.setModemDevice(modemDevice);
if (modemDevice instanceof UsbModemDevice) {
UsbModemDevice usbModemDevice = (UsbModemDevice) modemDevice;
SupportedUsbModemInfo supportedUsbModemInfo = null;
supportedUsbModemInfo = SupportedUsbModemsInfo.getModem(usbModemDevice.getVendorId(), usbModemDevice.getProductId(), usbModemDevice.getProductName());
modemInterface.setTechnologyTypes(supportedUsbModemInfo.getTechnologyTypes());
modemInterface.setUsbDevice((UsbModemDevice) modemDevice);
} else if (modemDevice instanceof SerialModemDevice) {
SupportedSerialModemInfo supportedSerialModemInfo = null;
supportedSerialModemInfo = SupportedSerialModemsInfo.getModem();
modemInterface.setTechnologyTypes(supportedSerialModemInfo.getTechnologyTypes());
}
int pppNum = 0;
if (interfaceName.startsWith("ppp")) {
pppNum = Integer.parseInt(interfaceName.substring(3));
}
modemInterface.setPppNum(pppNum);
modemInterface.setManufacturer(modemDevice.getManufacturerName());
modemInterface.setModel(modemDevice.getProductName());
modemInterface.setModemIdentifier(modemDevice.getProductName());
// these properties required net.admin packages
modemInterface.setDriver(getDriver());
modemInterface.setDriverVersion(getDriverVersion());
modemInterface.setFirmwareVersion(getFirmwareVersion());
modemInterface.setSerialNumber("unknown");
modemInterface.setLoopback(false);
modemInterface.setPointToPoint(true);
modemInterface.setState(getState(interfaceName, isUp));
modemInterface.setHardwareAddress(new byte[] { 0, 0, 0, 0, 0, 0 });
LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
if (ifconfig != null) {
modemInterface.setMTU(ifconfig.getMtu());
modemInterface.setSupportsMulticast(ifconfig.isMulticast());
}
modemInterface.setUp(isUp);
modemInterface.setVirtual(isVirtual());
modemInterface.setNetInterfaceAddresses(getModemInterfaceAddresses(interfaceName, isUp));
return modemInterface;
}
use of org.eclipse.kura.usb.UsbModemDevice in project kura by eclipse.
the class ModemMonitorServiceImpl method trackModem.
private void trackModem(ModemDevice modemDevice) {
Class<? extends CellularModemFactory> modemFactoryClass = null;
if (modemDevice instanceof UsbModemDevice) {
SupportedUsbModemInfo supportedUsbModemInfo = SupportedUsbModemsInfo.getModem((UsbModemDevice) modemDevice);
UsbModemFactoryInfo usbModemFactoryInfo = SupportedUsbModemsFactoryInfo.getModem(supportedUsbModemInfo);
modemFactoryClass = usbModemFactoryInfo.getModemFactoryClass();
} else if (modemDevice instanceof SerialModemDevice) {
SupportedSerialModemInfo supportedSerialModemInfo = SupportedSerialModemsInfo.getModem();
SerialModemFactoryInfo serialModemFactoryInfo = SupportedSerialModemsFactoryInfo.getModem(supportedSerialModemInfo);
modemFactoryClass = serialModemFactoryInfo.getModemFactoryClass();
}
if (modemFactoryClass != null) {
CellularModemFactory modemFactoryService = null;
try {
try {
Method getInstanceMethod = modemFactoryClass.getDeclaredMethod("getInstance", (Class<?>[]) null);
getInstanceMethod.setAccessible(true);
modemFactoryService = (CellularModemFactory) getInstanceMethod.invoke(null, (Object[]) null);
} catch (Exception e) {
s_logger.error("Error calling getInstance() method on " + modemFactoryClass.getName() + e);
}
// if unsuccessful in calling getInstance()
if (modemFactoryService == null) {
modemFactoryService = modemFactoryClass.newInstance();
}
String platform = null;
if (this.m_systemService != null) {
platform = this.m_systemService.getPlatform();
}
CellularModem modem = modemFactoryService.obtainCellularModemService(modemDevice, platform);
try {
HashMap<String, String> modemInfoMap = new HashMap<String, String>();
modemInfoMap.put(ModemReadyEvent.IMEI, modem.getSerialNumber());
modemInfoMap.put(ModemReadyEvent.IMSI, modem.getMobileSubscriberIdentity());
modemInfoMap.put(ModemReadyEvent.ICCID, modem.getIntegratedCirquitCardId());
modemInfoMap.put(ModemReadyEvent.RSSI, Integer.toString(modem.getSignalStrength()));
s_logger.info("posting ModemReadyEvent on topic {}", ModemReadyEvent.MODEM_EVENT_READY_TOPIC);
this.m_eventAdmin.postEvent(new ModemReadyEvent(modemInfoMap));
} catch (Exception e) {
s_logger.error("Failed to post the ModemReadyEvent - {}", e);
}
String ifaceName = this.m_networkService.getModemPppPort(modemDevice);
List<NetConfig> netConfigs = null;
if (ifaceName != null) {
NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig = this.m_networkConfig.getNetInterfaceConfig(ifaceName);
if (netInterfaceConfig == null) {
this.m_networkConfig = this.m_netConfigService.getNetworkConfiguration();
netInterfaceConfig = this.m_networkConfig.getNetInterfaceConfig(ifaceName);
}
if (netInterfaceConfig != null) {
netConfigs = getNetConfigs(netInterfaceConfig);
if (netConfigs != null && netConfigs.size() > 0) {
modem.setConfiguration(netConfigs);
}
}
}
if (modemDevice instanceof UsbModemDevice) {
this.m_modems.put(((UsbModemDevice) modemDevice).getUsbPort(), modem);
} else if (modemDevice instanceof SerialModemDevice) {
this.m_modems.put(modemDevice.getProductName(), modem);
}
if (modem instanceof EvdoCellularModem) {
NetInterfaceStatus netIfaceStatus = getNetInterfaceStatus(netConfigs);
if (netIfaceStatus == NetInterfaceStatus.netIPv4StatusEnabledWAN) {
if (modem.isGpsEnabled()) {
if (!disableModemGps(modem)) {
s_logger.error("trackModem() :: Failed to disable modem GPS, resetting modem ...");
modem.reset();
this.m_resetTimerStart = System.currentTimeMillis();
}
}
if (!((EvdoCellularModem) modem).isProvisioned()) {
s_logger.info("trackModem() :: The {} is not provisioned, will try to provision it ...", modem.getModel());
if (task != null && !task.isCancelled()) {
s_logger.info("trackModem() :: Cancelling monitor task");
stopThread.set(true);
monitorNotity();
task.cancel(true);
task = null;
}
((EvdoCellularModem) modem).provision();
if (task == null) {
s_logger.info("trackModem() :: Restarting monitor task");
stopThread.set(false);
task = this.m_executor.submit(new Runnable() {
@Override
public void run() {
while (!stopThread.get()) {
Thread.currentThread().setName("ModemMonitor");
try {
monitor();
monitorWait();
} catch (InterruptedException interruptedException) {
Thread.interrupted();
s_logger.debug("modem monitor interrupted - {}", interruptedException);
} catch (Throwable t) {
s_logger.error("trackModem() :: Exception while monitoring cellular connection {}", t);
}
}
}
});
} else {
monitorNotity();
}
} else {
s_logger.info("trackModem() :: The {} is provisioned", modem.getModel());
}
}
if (modem.isGpsSupported()) {
if (isGpsEnabledInConfig(netConfigs) && !modem.isGpsEnabled()) {
modem.enableGps();
postModemGpsEvent(modem, true);
}
}
}
} catch (Exception e) {
s_logger.error("trackModem() :: {}", e);
}
}
}
use of org.eclipse.kura.usb.UsbModemDevice in project kura by eclipse.
the class TelitHe910 method getTechnologyTypes.
@Override
public List<ModemTechnologyType> getTechnologyTypes() throws KuraException {
List<ModemTechnologyType> modemTechnologyTypes = null;
ModemDevice device = getModemDevice();
if (device == null) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "No modem device");
}
if (device instanceof UsbModemDevice) {
SupportedUsbModemInfo usbModemInfo = SupportedUsbModemsInfo.getModem((UsbModemDevice) device);
if (usbModemInfo != null) {
modemTechnologyTypes = usbModemInfo.getTechnologyTypes();
} else {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "No usbModemInfo available");
}
} else if (device instanceof SerialModemDevice) {
SupportedSerialModemInfo serialModemInfo = SupportedSerialModemsInfo.getModem();
if (serialModemInfo != null) {
modemTechnologyTypes = serialModemInfo.getTechnologyTypes();
} else {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "No serialModemInfo available");
}
} else {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Unsupported modem device");
}
return modemTechnologyTypes;
}
Aggregations