Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.jar
*.class
5 changes: 4 additions & 1 deletion bin/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/devices/
/admin.properties
/application.properties
/com/
/maps/
4 changes: 2 additions & 2 deletions bin/admin.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group.name = simulator
nr.of.cars = 5
nr.of.ambulances = 3
nr.of.cars = 8
nr.of.ambulances = 4
6 changes: 3 additions & 3 deletions bin/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Credentials to access the IOT-Hub - INSERT the credentials of your IOT-instance here!
api-key = <change>a-876fe7-6qjcxyvocx
api-token = <change>mF3R7B)a!GC0My-Pad
orga-id = <change>876fe7
api-key = a-jcq86q-hner51xsr4
api-token = FJE3tMjGe2KpV&j!3F
orga-id = jcq86q

#file where devices need to be configured to allow car-simulation - do not change this
devices = devices/test-devices.json
Binary file modified bin/com/capgemini/hackathon/device/simulation/bo/Car.class
Binary file not shown.
Binary file not shown.
Binary file modified bin/com/capgemini/hackathon/device/simulation/bo/Hospital.class
Binary file not shown.
Binary file not shown.
Binary file modified bin/com/capgemini/hackathon/device/simulation/bo/Vehicle.class
Binary file not shown.
Binary file not shown.
88 changes: 60 additions & 28 deletions bin/devices/test-devices.json
Original file line number Diff line number Diff line change
@@ -1,73 +1,105 @@
[{
"simulatorClazz": "com.capgemini.hackathon.device.simulation.bo.Car",
"id": "car0",
"orgId": "876fe7",
"clientId": "d:876fe7:car-simulator:car0",
"orgId": "jcq86q",
"clientId": "d:jcq86q:car-simulator:car0",
"typeId": "car-simulator",
"deviceId": "car0",
"apiToken": "CAE8674A-8B27-4539-83F4-257466A2C5F8"
"apiToken": "03543868-E3EA-4B11-8DA1-5E7D7904849C"
},{
"simulatorClazz": "com.capgemini.hackathon.device.simulation.bo.Car",
"id": "car1",
"orgId": "876fe7",
"clientId": "d:876fe7:car-simulator:car1",
"orgId": "jcq86q",
"clientId": "d:jcq86q:car-simulator:car1",
"typeId": "car-simulator",
"deviceId": "car1",
"apiToken": "D4C4A59F-FCA6-4EAA-B07E-C77E3702BF7C"
"apiToken": "30702F18-B151-4F74-8C3A-F1FD7525CC6E"
},{
"simulatorClazz": "com.capgemini.hackathon.device.simulation.bo.Car",
"id": "car2",
"orgId": "876fe7",
"clientId": "d:876fe7:car-simulator:car2",
"orgId": "jcq86q",
"clientId": "d:jcq86q:car-simulator:car2",
"typeId": "car-simulator",
"deviceId": "car2",
"apiToken": "048CFDD6-02F3-4B9B-B3EB-7BC4BDB929E5"
"apiToken": "B9F3B6BF-D646-4113-8E91-6748BC25F6A8"
},{
"simulatorClazz": "com.capgemini.hackathon.device.simulation.bo.Car",
"id": "car3",
"orgId": "876fe7",
"clientId": "d:876fe7:car-simulator:car3",
"orgId": "jcq86q",
"clientId": "d:jcq86q:car-simulator:car3",
"typeId": "car-simulator",
"deviceId": "car3",
"apiToken": "1ED30408-5B03-4869-96F1-191050703335"
"apiToken": "3E7C67A7-D342-43C9-9C8B-43F0C27FE26C"
},{
"simulatorClazz": "com.capgemini.hackathon.device.simulation.bo.Car",
"id": "car4",
"orgId": "876fe7",
"clientId": "d:876fe7:car-simulator:car4",
"orgId": "jcq86q",
"clientId": "d:jcq86q:car-simulator:car4",
"typeId": "car-simulator",
"deviceId": "car4",
"apiToken": "8025B588-B5C3-47C7-AA82-5A95BD7577C8"
"apiToken": "3678BB64-1B46-4F4D-B901-F10B110F9D78"
},{
"simulatorClazz": "com.capgemini.hackathon.device.simulation.bo.Car",
"id": "car5",
"orgId": "jcq86q",
"clientId": "d:jcq86q:car-simulator:car5",
"typeId": "car-simulator",
"deviceId": "car5",
"apiToken": "39B507A5-7A39-499B-AE40-01A72CCD773E"
},{
"simulatorClazz": "com.capgemini.hackathon.device.simulation.bo.Car",
"id": "car6",
"orgId": "jcq86q",
"clientId": "d:jcq86q:car-simulator:car6",
"typeId": "car-simulator",
"deviceId": "car6",
"apiToken": "CEDC7CAE-F84C-40DB-A314-9CDB7245A6FE"
},{
"simulatorClazz": "com.capgemini.hackathon.device.simulation.bo.Car",
"id": "car7",
"orgId": "jcq86q",
"clientId": "d:jcq86q:car-simulator:car7",
"typeId": "car-simulator",
"deviceId": "car7",
"apiToken": "EDB1CD9F-494F-460D-BE8C-FF0609147B01"
},{
"simulatorClazz": "com.capgemini.hackathon.device.simulation.bo.Ambulance",
"id": "ambulance0",
"orgId": "876fe7",
"clientId": "d:876fe7:ambulance-simulator:ambulance0",
"orgId": "jcq86q",
"clientId": "d:jcq86q:ambulance-simulator:ambulance0",
"typeId": "ambulance-simulator",
"deviceId": "ambulance0",
"apiToken": "DFF2309A-3514-4736-9201-1EAC6C8FA60D"
"apiToken": "E3B40C78-9482-435B-8D34-EE897C705FEA"
},{
"simulatorClazz": "com.capgemini.hackathon.device.simulation.bo.Ambulance",
"id": "ambulance1",
"orgId": "876fe7",
"clientId": "d:876fe7:ambulance-simulator:ambulance1",
"orgId": "jcq86q",
"clientId": "d:jcq86q:ambulance-simulator:ambulance1",
"typeId": "ambulance-simulator",
"deviceId": "ambulance1",
"apiToken": "5D3C8512-1BA4-4986-AF29-24A7CE01D9AA"
"apiToken": "49FEC597-0343-4869-88CA-330BC4103040"
},{
"simulatorClazz": "com.capgemini.hackathon.device.simulation.bo.Ambulance",
"id": "ambulance2",
"orgId": "876fe7",
"clientId": "d:876fe7:ambulance-simulator:ambulance2",
"orgId": "jcq86q",
"clientId": "d:jcq86q:ambulance-simulator:ambulance2",
"typeId": "ambulance-simulator",
"deviceId": "ambulance2",
"apiToken": "5EC59625-C4CC-42D7-963F-4A93329752A4"
"apiToken": "AE6B40E4-D885-4F94-AB27-3FC412565452"
},{
"simulatorClazz": "com.capgemini.hackathon.device.simulation.bo.Ambulance",
"id": "ambulance3",
"orgId": "jcq86q",
"clientId": "d:jcq86q:ambulance-simulator:ambulance3",
"typeId": "ambulance-simulator",
"deviceId": "ambulance3",
"apiToken": "E2709B2D-88CA-476B-B6BE-B4C1B3D95933"
},{
"simulatorClazz": "com.capgemini.hackathon.device.simulation.bo.Hospital",
"id": "hospital",
"orgId": "876fe7",
"clientId": "d:876fe7:hospital:hospital1",
"orgId": "jcq86q",
"clientId": "d:jcq86q:hospital:hospital1",
"typeId": "hospital",
"deviceId": "hospital1",
"apiToken": "3992129C-FE5F-4B37-A6B9-1BCFAD2C1984"
}]
"apiToken": "FF3E0C2B-38B9-4809-A5A1-C5BE812B5190"
}]
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.capgemini.hackathon.device.simulation.bo;

import com.capgemini.hackathon.device.simulation.DeviceClientConfig;
import com.capgemini.hackathon.device.simulation.model.EmergencyRequest;
import com.capgemini.hackathon.device.simulation.model.Location;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.ibm.iotf.client.device.Command;
import com.ibm.iotf.client.device.CommandCallback;
import com.ibm.iotf.client.device.DeviceClient;

public class Car extends Vehicle {

private boolean gotSome = false;

public Car(DeviceClientConfig deviceClientConfig, Object id) {
super(deviceClientConfig, id);
Expand All @@ -15,7 +21,6 @@ public Car(DeviceClientConfig deviceClientConfig, Object id) {
public void process() {
while (true) {
driveToDestination(Location.createRandomLocation());

}

}
Expand All @@ -27,6 +32,5 @@ protected void addMetainformationWhenPublishLocation(JsonObject event) {

@Override
protected void configureDeviceClient(DeviceClient deviceClient) {
// nothing to do
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.capgemini.hackathon.device.simulation.DeviceClientConfig;
import com.capgemini.hackathon.device.simulation.model.Emergency;
import com.capgemini.hackathon.device.simulation.model.EmergencyRequest;
import com.capgemini.hackathon.device.simulation.model.Emergency.Status;
import com.capgemini.hackathon.device.simulation.model.Location;
import com.capgemini.hackathon.device.simulation.routing.RouteCalculator;
Expand Down Expand Up @@ -147,7 +148,6 @@ public void processCommand(Command command) {
}

private void handleNewEmergency(String latitude, String longtitude) {

// new emergency
Emergency emergency = new Emergency();
emergency.setEmergencyId(UUID.randomUUID().toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,47 @@
package com.capgemini.hackathon.device.simulation.bo;

import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Random;
import java.util.UUID;

import org.joda.time.DateTime;

import com.capgemini.hackathon.device.simulation.DeviceClientConfig;
import com.capgemini.hackathon.device.simulation.model.Emergency;
import com.capgemini.hackathon.device.simulation.model.EmergencyRequest;
import com.capgemini.hackathon.device.simulation.model.Location;
import com.capgemini.hackathon.device.simulation.model.Route;
import com.capgemini.hackathon.device.simulation.model.VehicleLocation;
import com.capgemini.hackathon.device.simulation.routing.MapCoordinatePoint;
import com.capgemini.hackathon.device.simulation.routing.RouteCalculator;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.graphhopper.GHResponse;
import com.ibm.iotf.client.device.Command;
import com.ibm.iotf.client.device.CommandCallback;
import com.ibm.iotf.client.device.DeviceClient;

public abstract class Vehicle extends Simulation {

private static final Interruption FALSE_INTERRUPTION = new Vehicle.FalseInterruption();

// How close the vehicles reach their destination
private static final double DIST_LAT_LONG = 0.00005;
private static final double DEFAULT_SPEED = 0.0001;
private static final double DEFAULT_SPEED = 0.0003;
// The steps driving the vehicles per iteration
private final static double SPEED = Vehicle.getSPEED();

// current Location
private Location currentLocation;
// destination Location
private Location destination;

//route Information
private Route route;

private static final double CrashProb = 0.00208; // About 1 every minute (considering 8 cars are driving)

public Vehicle(DeviceClientConfig deviceClientConfig, Location location, Object id) {
super(deviceClientConfig, id);
this.currentLocation = location;
Expand All @@ -34,11 +51,40 @@ public Vehicle(DeviceClientConfig deviceClientConfig, Object id) {
this(deviceClientConfig, Location.createRandomLocation(), id);
}

protected void publishEmergencyRequest(double lat,double lon){
try{
JsonObject JsonEmergencyReq = new EmergencyRequest(lat,lon).asJson();
getDeviceClient().publishEvent(EmergencyRequest.EVENT, JsonEmergencyReq);
}catch(Exception e){
e.printStackTrace();
}
}

protected void publishRoute(){
try{
JsonObject JsonRoute=route.asJson();
getDeviceClient().publishEvent(Route.EVENT,JsonRoute);


}catch (Exception e){
e.printStackTrace();
}
}

protected void tickCrash(){
Random rn = new Random();
if(rn.nextDouble() < CrashProb)
{
publishEmergencyRequest(currentLocation.getLatitude(),currentLocation.getLongitude());
}
}

protected void publishLocation() {
try {

VehicleLocation vl = new VehicleLocation(currentLocation.getLatitude(), currentLocation.getLongitude(),
getId().toString());

JsonObject event = vl.asJson();
addMetainformationWhenPublishLocation(event);
// Publish event to IoT
Expand Down Expand Up @@ -71,7 +117,9 @@ protected void driveToDestination(Location destination, Interruption interruptio

GHResponse response = RouteCalculator.getInstance().calculateRoute(currentLocation.getLatitude(),
currentLocation.getLongitude(), destination.getLatitude(), destination.getLongitude());



// in case of error, the vehicle seems to be stuck somewhere
if (response.hasErrors()) {

Expand All @@ -90,6 +138,15 @@ protected void driveToDestination(Location destination, Interruption interruptio

return;
}

route = Route.fromGHRes(this.getId().toString(),response);
try {
this.publishRoute();

} catch (Exception e) {
e.printStackTrace();
}


int i = 0;
long millis = DateTime.now().getMillis();
Expand Down Expand Up @@ -142,7 +199,7 @@ protected void driveToDestination(Location destination, Interruption interruptio

distLat = nextPointLatitude - currentLocation.getLatitude();
distLong = nextpointLongitude - currentLocation.getLongitude();

tickCrash();
try {
// whatever time has passed so far, wait until 1s has passed
millis = DateTime.now().getMillis();
Expand Down Expand Up @@ -184,5 +241,6 @@ public static double getSPEED() {
return DEFAULT_SPEED;
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.capgemini.hackathon.device.simulation.model;

import com.google.gson.JsonObject;

public class EmergencyRequest {
private static final String CMD="cmd";
public static final String EVENT="icrashed";
private static final String LAT="latitude";
private static final String LON="longitude";

private double lat;
private double lon;

public EmergencyRequest(double lat,double lon) {
// TODO Auto-generated constructor stub
this.lat = lat;
this.lon = lon;
}

public JsonObject asJson()
{
JsonObject json = new JsonObject();
json.addProperty(CMD, "emergency");
json.addProperty(LAT, lat);
json.addProperty(LON, lon);

return json;
}
}
Loading