Package com.gmv.its.deepsy.hal.ecu

Classes

interface  Ecu
 Ecu. More...
 
class  EcuAlarm
 Indicates ecu alarm. More...
 
interface  EcuAlarmEvent
 Ecu alarm event. More...
 
interface  EcuEvent
 Ecu event. More...
 
class  EcuLowLevelException
 Ecu low level exception. More...
 
interface  EcuManager
 Ecu Manager. More...
 
class  EcuNotAvailableException
 Ecu not available exception. More...
 
class  EcuObserver
 Ecu observer. More...
 
interface  EcuParameter
 Ecu parameter. More...
 
interface  EcuProtocol
 Ecu protocol. More...
 

Detailed Description

To work with Deepsy ecu service it is necessary to use DeepsyEcuManager located in com.gmv.its.deepsy.ecu for getting the initial EcuManager object.

EcuManager ecuManager = DeepsyEcuManager.getInstance();


DeepsyEcuManager.getInstance has an optional parameter indicating the ip address of remote service. For instance:

EcuManager ecuManager = DeepsyEcuManager.getInstance("192.168.1.10");


EcuManager is an AutoCloseable interface. An object that may hold resources (such as file or socket handles) until it is closed. The close() method of an AutoCloseable object is called automatically when exiting a try-with-resources block for which the object has been declared in the resource specification header. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur. To obtain an Ecu object:

try (EcuManager ecuManager = DeepsyEcuManager.getInstance()){
Ecu ecu = ecuManager.getEcu();
} catch (EcuNotAvailableException e) {
e.printStackTrace();
} catch (EcuLowLevelException e) {
e.printStackTrace();
}


If this object is not inside a try with resources block, it is recommended to call to ecuManager.close() in order to finalize properly;

ecuManager.close();

Service availability

To detect service availability the DeepsyEcuManager implements Manager interface which provides methods for getting availability and subscribing to availability events.

class MyManagerObserver implements ManagerObserver{
public void notify(ManagerConnectionEvent event) {
System.out.println(event.getManager().getName() + " in "+ event.getManager().getIp() + " "+ event.getAction().toString());
}
}
public class App {
public static void main(String[] args) {
ManagerObserver observer = new MyManagerObserver();
try (EcuManager ecuManager = DeepsyEcuManager.getInstance()){
ecuManager.subscribe(observer);
} catch (CannotSubscribeException e1) {
e1.printStackTrace();
}
}
}


Examples

Get Ecu protocol

package com.gmv.its.dpyjavaexamples.ecu;
import java.util.List;
import java.util.Arrays;
import com.gmv.its.deepsy.ecu.DeepsyEcuManager;
import com.gmv.its.deepsy.hal.ecu.*;
public class GetProtocolApp {
public static void main(String[] args) {
try (EcuManager ecuManager = DeepsyEcuManager.getInstance()){
Ecu ecu = ecuManager.getEcu();
EcuProtocol protocol = ecu.getCurrentProtocol();
System.out.println(protocol.getName());
} catch (EcuNotAvailableException e) {
e.printStackTrace();
} catch (EcuLowLevelException e) {
e.printStackTrace();
}
}
}


Get EPIDs parameters

package com.gmv.its.dpyjavaexamples.ecu;
import com.gmv.its.deepsy.ecu.DeepsyEcuManager;
import com.gmv.its.deepsy.hal.ecu.*;
import java.util.List;
import java.util.Arrays;
public class GetEPIDsApp {
public static void main(String[] args) {
try (EcuManager ecuManager = DeepsyEcuManager.getInstance()){
Ecu ecu = ecuManager.getEcu();
List<String> EPIDs = Arrays.asList("Engine_Temp");
List<EcuParameter> params = ecu.getParameter(EPIDs);
for (EcuParameter param : params) {
System.out.println("Timestamp: " + param.getTimestamp());
System.out.println("Id: " + param.getId());
System.out.println("Value: " + param.getValue());
System.out.println("Units: " + param.getUnits());
}
} catch (EcuNotAvailableException e) {
e.printStackTrace();
} catch (EcuLowLevelException e) {
e.printStackTrace();
}
}
}


Get Ecu available EPIDs

package com.gmv.its.dpyjavaexamples.ecu;
import com.gmv.its.deepsy.ecu.DeepsyEcuManager;
import com.gmv.its.deepsy.hal.ecu.*;
import java.util.List;
public class GetAvailableEPIDsApp {
public static void main(String[] args) {
try (EcuManager ecuManager = DeepsyEcuManager.getInstance()){
Ecu ecu = ecuManager.getEcu();
List<String> pids = ecu.getAvailableEPIDs();
for (String pid : pids) {
System.out.println(pid);
}
} catch (EcuNotAvailableException e) {
e.printStackTrace();
} catch (EcuLowLevelException e) {
e.printStackTrace();
}
}
}


Get Ecu Information

import com.gmv.its.deepsy.ecu.DeepsyEcuManager;
import com.gmv.its.deepsy.hal.ecu.*;
public class App {
public static void main(String[] args) {
EcuManager ecuManager = DeepsyEcuManager.getInstance();
try {
Ecu ecu = ecuManager.getEcu();
EcuAlarm alarm = new EcuAlarm(EcuAlarm.AlarmType.STATE_CHANGE,"Vehicle_Speed",50);
int id = ecu.setAlarm(alarm);
} catch (EcuNotAvailableException e) {
e.printStackTrace();
} catch (EcuLowLevelException e) {
e.printStackTrace();
}
ecuManager.close();
}
}


Subscribe to Ecu alarms

import com.gmv.its.deepsy.ecu.DeepsyEcuManager;
import com.gmv.its.deepsy.hal.ecu.*;
class MyEcuObserver extends EcuObserver {
@Override
public void notifyEcuAlarm(EcuAlarmEvent event) {
EcuAlarm alarm = ((EcuAlarmEvent) event).getAlarm();
System.out.println("EVENT EcuAlarmEvent: ->" + alarm.getType() + ", " + alarm.getParameterId() + ", " + alarm.getThreshold());
}
}
public class App {
public static void main(String[] args) {
EcuManager ecuManager = DeepsyEcuManager.getInstance();
try {
Ecu ecu = ecuManager.getEcu();
ecu.subscribe(new MyEcuObserver());
} catch (EcuNotAvailableException e) {
e.printStackTrace();
} catch (EcuLowLevelException e) {
e.printStackTrace();
} catch (CannotSubscribeException e) {
e.printStackTrace();
}
//Wait for events for 10 seconds
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ecuManager.close();
}
}