Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
vladamatena committed Mar 13, 2015
1 parent aebdc23 commit d540dfb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 5 additions & 3 deletions jdeeco-simulation-omnet-native/src/JDEECoApplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ void JDEECoApplication::registerCallbackAt(double absoluteTime, cMessage *msg) {
scheduleAt(absoluteTime, msg);
}

void JDEECoApplication::sendPacket(JDEECoPacket *packet,
const char *recipient) {
void JDEECoApplication::sendPacket(JDEECoPacket *packet, const char *recipient) {
if (opp_strcmp("", recipient) == 0) {
if (gate(lower802154LayerOut)->isConnected()) {
NetwToMacControlInfo::setControlInfo(packet, LAddress::L2BROADCAST);
Expand All @@ -74,7 +73,10 @@ void JDEECoApplication::sendPacket(JDEECoPacket *packet,
}
} else {
packet->setByteLength(packet80211ByteLength);
socket.sendTo(packet, IPvXAddressResolver().resolve(recipient).get4(), port);
// std::cout << "X" << std::endl;
IPvXAddress ip = IPvXAddressResolver().resolve(recipient).get4();
// std::cout << "Y" << std::endl;
socket.sendTo(packet, ip, port);
}
}

Expand Down
9 changes: 6 additions & 3 deletions jdeeco-simulation-omnet-native/src/OMNeTJDEECoAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ JNIEXPORT void JNICALL Java_cz_cuni_mff_d3s_deeco_simulation_omnet_OMNeTNative_n
int length = env->GetArrayLength(packet);
jbyte *buffer = env->GetByteArrayElements(packet, 0);
JDEECoPacket *jPacket = new JDEECoPacket(JDEECO_DATA_MESSAGE);
//Setting data

// Setting data
jPacket->setDataArraySize(length);
for (int i = 0; i < length; i++)
jPacket->setData(i, buffer[i]);
for (int i = 0; i < length; i++) {
jPacket->setData(i, buffer[i]);
}
const char *cRecipient = env->GetStringUTFChars(recipient, 0);
EV << "OMNET++ ("<< simTime() <<") : " << module->getModuleId() << " sending packet with ID = " << jPacket->getId() << endl;
module->sendPacket(jPacket, cRecipient);

env->ReleaseByteArrayElements(packet, buffer, JNI_ABORT);
env->ReleaseStringUTFChars(recipient, cRecipient);
env->DeleteLocalRef(packet);
Expand Down

0 comments on commit d540dfb

Please sign in to comment.