/**
 * Copyright (c) 2011, 2014 Eurotech and/or its affiliates
 *
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Eurotech
 */
package org.eclipse.kura.linux.net.modem;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.kura.linux.net.util.KuraConstants;

public class SupportedSerialModems {

	private static final Logger s_logger = LoggerFactory.getLogger(SupportedSerialModems.class);
	private static final String OS_VERSION = System.getProperty("kura.os.version");
	
	private static boolean modemReachable = false;
	static {
		breakout:
		for (SupportedSerialModemInfo modem : SupportedSerialModemInfo.values()) {
			if (modem == SupportedSerialModemInfo.MiniGateway_Telit_HE910_NAD) {
				if (OS_VERSION.equals(KuraConstants.Mini_Gateway.getImageName() + "_" + KuraConstants.Mini_Gateway.getImageVersion())) {
					s_logger.info("Installing modem driver for {} ...", modem.getModemName());
					try {
						if (modem.getDriver().install() == 0) {
							for (String modemModel : modem.getModemModels()) {
								if (modemModel.equals(modem.getDriver().getModemModel())) {
									s_logger.info("Driver for the {} modem has been installed" , modemModel);
									modemReachable = true;
									break breakout;
								}
							}
						}
						s_logger.warn("Failed to installing modem driver for {}", modem.getModemName());
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
	}
	
	public static SupportedSerialModemInfo getModem(String imageName, String imageVersion) {
		
		SupportedSerialModemInfo supportedSerialModemInfo = null;
		
		for (SupportedSerialModemInfo modem : SupportedSerialModemInfo.values()) {
			if (modem.getOsImageName().equals(imageName) && modem.getOsImageVersion().equals(imageVersion)) {
				if (modemReachable) {
					s_logger.debug("The {} modem is attached", modem.getModemName());
					supportedSerialModemInfo = modem;
				} else {
					// do not return this modem if it isn't reachable
					s_logger.debug("The {} modem is not attached", modem.getModemName());
				}
				break;
			}
		}
		
		return supportedSerialModemInfo;
	}
}

@@ -1152,16 +1152,181 @@
 %09%09try %7B%0A
+%09%09%09%09%09%09if (!SupportedUsbModems.isAttached(%0A%09%09%09%09%09%09%09%09SupportedUsbModemInfo.Telit_HE910_D.getVendorId(),%0A%09%09%09%09%09%09%09%09SupportedUsbModemInfo.Telit_HE910_D.getProductId())) %7B%0A%09
 %09%09%09%09%09%09if
@@ -1359,24 +1359,25 @@
 l() == 0) %7B%0A
+%09
 %09%09%09%09%09%09%09for (
@@ -1426,24 +1426,25 @@
 ) %7B%0A%09%09%09%09%09%09%09%09
+%09
 if (modemMod
@@ -1487,24 +1487,25 @@
 Model())) %7B%0A
+%09
 %09%09%09%09%09%09%09%09%09s_l
@@ -1575,16 +1575,17 @@
 Model);%0A
+%09
 %09%09%09%09%09%09%09%09
@@ -1613,24 +1613,25 @@
 e;%0A%09%09%09%09%09%09%09%09%09
+%09
 break breako
@@ -1634,16 +1634,17 @@
 eakout;%0A
+%09
 %09%09%09%09%09%09%09%09
@@ -1656,18 +1656,20 @@
 %09%09%09%09
+%09
 %7D%0A
+%09
 %09%09%09%09%09%09%7D%0A
 %09%09%09%09
@@ -1660,24 +1660,25 @@
 %09%7D%0A%09%09%09%09%09%09%09%7D%0A
+%09
 %09%09%09%09%09%09s_logg
@@ -1748,24 +1748,32 @@
 demName());%0A
+%09%09%09%09%09%09%7D%0A
 %09%09%09%09%09%7D catch

Work to treat HE910 on MGW as USB device (if both USB and serial)