Skip to content

Commit

Permalink
JNI - GPS API added - not finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Kit committed Jan 30, 2014
1 parent 8065b31 commit f69694d
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 7 deletions.
Binary file modified jdeeco-simulation-demo/libintegration.dll
Binary file not shown.
Binary file modified jdeeco-simulation-demo/libmodel.dll
Binary file not shown.
13 changes: 10 additions & 3 deletions jdeeco-simulation-integration/jDEECoModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,23 @@ class DLLEXPORT_OR_IMPORT jDEECoModule {
virtual const char * jDEECoGetModuleId() {return NULL;};
//Needs to be implemented by the module
virtual void jDEECoSendPacket(JDEECoPacket *packet, const char *recipient) {};
//Needs to be implemented by the module
virtual void jDEECoScheduleAt(double absoluteTime, cMessage *msg) {};
//Needs to be implemented by the module
virtual bool jDEECoIsGPSAvailable() {return false;};
//Needs to be implemented by the module
virtual double jDEECoGetPositionX() {return 0;};
//Needs to be implemented by the module
virtual double jDEECoGetPositionY() {return 0;};
//Needs to be implemented by the module
virtual double jDEECoGetPositionZ() {return 0;};

protected:
//Needs to be called at the module initialisation
void jDEECoInitialize();
//Needs to be called from the handleMessage method
void jDEECoOnHandleMessage(cMessage *msg);

//Needs to be implemented by the module
virtual void jDEECoScheduleAt(double absoluteTime, cMessage *msg) {};

};

#endif /* JDEECOMODULE_H_ */
60 changes: 60 additions & 0 deletions jdeeco-simulation-integration/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,66 @@ JNIEXPORT void JNICALL _Java_cz_cuni_mff_d3s_deeco_simulation_Simulation_nativeC
env->ReleaseStringUTFChars(id, cstring);
}

JNIEXPORT jboolean JNICALL _Java_cz_cuni_mff_d3s_deeco_simulation_Simulation_nativeIsGPSAvailable
(JNIEnv *env, jobject jsimulation, jstring id) {
const char * cstring = env->GetStringUTFChars(id, 0);
jboolean result = 0;
for (std::vector<jDEECoModule *>::iterator it = jDEECoModules.begin();
it != jDEECoModules.end(); ++it) {
if (opp_strcmp((*it)->jDEECoGetModuleId(), cstring) == 0) {
result = (*it)->jDEECoIsGPSAvailable();
break;
}
}
env->ReleaseStringUTFChars(id, cstring);
return result;
}

JNIEXPORT jdouble JNICALL _Java_cz_cuni_mff_d3s_deeco_simulation_Simulation_nativeGetPositionX
(JNIEnv *env, jobject jsimulation, jstring id) {
const char * cstring = env->GetStringUTFChars(id, 0);
jdouble result = 0;
for (std::vector<jDEECoModule *>::iterator it = jDEECoModules.begin();
it != jDEECoModules.end(); ++it) {
if (opp_strcmp((*it)->jDEECoGetModuleId(), cstring) == 0) {
result = (*it)->jDEECoGetPositionX();
break;
}
}
env->ReleaseStringUTFChars(id, cstring);
return result;
}

JNIEXPORT jdouble JNICALL _Java_cz_cuni_mff_d3s_deeco_simulation_Simulation_nativeGetPositionY
(JNIEnv *env, jobject jsimulation, jstring id) {
const char * cstring = env->GetStringUTFChars(id, 0);
jdouble result = 0;
for (std::vector<jDEECoModule *>::iterator it = jDEECoModules.begin();
it != jDEECoModules.end(); ++it) {
if (opp_strcmp((*it)->jDEECoGetModuleId(), cstring) == 0) {
result = (*it)->jDEECoGetPositionY();
break;
}
}
env->ReleaseStringUTFChars(id, cstring);
return result;
}

JNIEXPORT jdouble JNICALL _Java_cz_cuni_mff_d3s_deeco_simulation_Simulation_nativeGetPositionZ
(JNIEnv *env, jobject jsimulation, jstring id) {
const char * cstring = env->GetStringUTFChars(id, 0);
jdouble result = 0;
for (std::vector<jDEECoModule *>::iterator it = jDEECoModules.begin();
it != jDEECoModules.end(); ++it) {
if (opp_strcmp((*it)->jDEECoGetModuleId(), cstring) == 0) {
result = (*it)->jDEECoGetPositionZ();
break;
}
}
env->ReleaseStringUTFChars(id, cstring);
return result;
}

DLLEXPORT_OR_IMPORT void jDEECoModule::jDEECoCallAt(double absoluteTime) {
//::printf("Adding callback at: %f for %f\n", simTime().dbl(), absoluteTime);
if (currentCallAtTime != absoluteTime && simTime().dbl() < absoluteTime) {
Expand Down
32 changes: 32 additions & 0 deletions jdeeco-simulation-integration/simulation.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ protected void sendPacket(byte[] packet, String recipient) {
}

public double getPositionX() {
// TODO Auto-generated method stub
return 0;
return simulation.getPositionX(id);
}

public double getPositionY() {
// TODO Auto-generated method stub
return 0;
return simulation.getPositionY(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public class Simulation {
* @param nodeId
*/
private native void nativeCallAt(double absoluteTime, String nodeId);

private native boolean nativeIsGPSAvailable(String nodeId);
private native double nativeGetPositionX(String nodeId);
private native double nativeGetPositionY(String nodeId);
private native double nativeGetPositionZ(String nodeId);

public void initialize() {
System.loadLibrary("libintegration");
Expand Down Expand Up @@ -83,6 +88,22 @@ public void run(String environment) {
public void callAt(long absoluteTime, String nodeId) {
nativeCallAt(timeLongToDouble(absoluteTime), nodeId);
}

public boolean isGPSAvailable(String id) {
return nativeIsGPSAvailable(id);
}

public double getPositionX(String id) {
return nativeGetPositionX(id);
}

public double getPositionY(String id) {
return nativeGetPositionY(id);
}

public double getPositionZ(String id) {
return nativeGetPositionZ(id);
}

public long getSimulationTime() {
double nativeTime = nativeGetCurrentTime();
Expand Down

0 comments on commit f69694d

Please sign in to comment.