use of org.eclipse.kura.net.admin.modem.EvdoCellularModem in project kura by eclipse.
the class ModemMonitorServiceImpl method processNetworkConfigurationChangeEvent.
private void processNetworkConfigurationChangeEvent(NetworkConfiguration newNetworkConfig) {
synchronized (s_lock) {
if (this.m_modems == null || this.m_modems.isEmpty()) {
return;
}
for (Map.Entry<String, CellularModem> modemEntry : this.m_modems.entrySet()) {
String usbPort = modemEntry.getKey();
CellularModem modem = modemEntry.getValue();
try {
String ifaceName = null;
if (this.m_networkService != null) {
ifaceName = this.m_networkService.getModemPppPort(modem.getModemDevice());
}
if (ifaceName != null) {
List<NetConfig> oldNetConfigs = modem.getConfiguration();
NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig = newNetworkConfig.getNetInterfaceConfig(ifaceName);
if (netInterfaceConfig == null) {
netInterfaceConfig = newNetworkConfig.getNetInterfaceConfig(usbPort);
}
List<NetConfig> newNetConfigs = null;
IModemLinkService pppService = null;
int ifaceNo = getInterfaceNumber(oldNetConfigs);
if (ifaceNo >= 0) {
pppService = PppFactory.obtainPppService(ifaceNo, modem.getDataPort());
}
if (netInterfaceConfig != null) {
newNetConfigs = getNetConfigs(netInterfaceConfig);
} else {
if (oldNetConfigs != null && pppService != null) {
if (!ifaceName.equals(pppService.getIfaceName())) {
StringBuilder key = new StringBuilder().append("net.interface.").append(ifaceName).append(".config.ip4.status");
String statusString = KuranetConfig.getProperty(key.toString());
NetInterfaceStatus netInterfaceStatus = NetInterfaceStatus.netIPv4StatusDisabled;
if (statusString != null && !statusString.isEmpty()) {
netInterfaceStatus = NetInterfaceStatus.valueOf(statusString);
}
newNetConfigs = oldNetConfigs;
oldNetConfigs = null;
try {
setInterfaceNumber(ifaceName, newNetConfigs);
setNetInterfaceStatus(netInterfaceStatus, newNetConfigs);
} catch (NumberFormatException e) {
s_logger.error("failed to set new interface number - {}", e);
}
}
}
}
if (oldNetConfigs == null || !isConfigsEqual(oldNetConfigs, newNetConfigs)) {
s_logger.info("new configuration for cellular modem on usb port {} netinterface {}", usbPort, ifaceName);
this.m_networkConfig = newNetworkConfig;
if (pppService != null) {
PppState pppState = pppService.getPppState();
if (pppState == PppState.CONNECTED || pppState == PppState.IN_PROGRESS) {
s_logger.info("disconnecting " + pppService.getIfaceName());
pppService.disconnect();
}
PppFactory.releasePppService(pppService.getIfaceName());
}
if (modem.isGpsEnabled()) {
if (!disableModemGps(modem)) {
s_logger.error("processNetworkConfigurationChangeEvent() :: Failed to disable modem GPS");
modem.reset();
this.m_resetTimerStart = System.currentTimeMillis();
}
}
modem.setConfiguration(newNetConfigs);
if (modem instanceof EvdoCellularModem) {
NetInterfaceStatus netIfaceStatus = getNetInterfaceStatus(newNetConfigs);
if (netIfaceStatus == NetInterfaceStatus.netIPv4StatusEnabledWAN) {
if (!((EvdoCellularModem) modem).isProvisioned()) {
s_logger.info("NetworkConfigurationChangeEvent :: The {} is not provisioned, will try to provision it ...", modem.getModel());
if (task != null && !task.isCancelled()) {
s_logger.info("NetworkConfigurationChangeEvent :: Cancelling monitor task");
stopThread.set(true);
monitorNotity();
task.cancel(true);
task = null;
}
((EvdoCellularModem) modem).provision();
if (task == null) {
s_logger.info("NetworkConfigurationChangeEvent :: 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("handleEvent() :: Exception while monitoring cellular connection {}", t);
}
}
}
});
} else {
monitorNotity();
}
} else {
s_logger.info("NetworkConfigurationChangeEvent :: The " + modem.getModel() + " is provisioned");
}
}
if (modem.isGpsSupported()) {
if (isGpsEnabledInConfig(newNetConfigs) && !modem.isGpsEnabled()) {
modem.enableGps();
postModemGpsEvent(modem, true);
}
}
}
}
}
} catch (KuraException e) {
s_logger.error("NetworkConfigurationChangeEvent :: Failed to process - {}", e);
}
}
}
}
use of org.eclipse.kura.net.admin.modem.EvdoCellularModem 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);
}
}
}
Aggregations