Permalink
Browse files

send a simpleMeshMS using DNA or Rhizome

  • Loading branch information...
1 parent 6740c89 commit bc228381194243150e2cd18bda38035b3354a3cc techxplorer committed with lakeman Jan 27, 2012
Showing with 78 additions and 5 deletions.
  1. +0 −1 .classpath
  2. +10 −0 reinstall-debug
  3. +68 −4 src/org/servalproject/meshms/IncomingMeshMS.java
View
@@ -3,6 +3,5 @@
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="src" path="gen"/>
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
View
@@ -0,0 +1,10 @@
+#!/bin/csh -f
+
+set devices=`adb devices| tail +2 | awk '{ print $1;}'`
+
+foreach dev ( $devices )
+ echo $dev
+ adb -s $dev uninstall org.servalproject
+ adb -s $dev install -r bin/batphone-debug.apk
+# adb -s $dev shell am start -a android.intent.action.MAIN -n org.servalproject/.Main
+end
@@ -27,6 +27,11 @@
import java.util.ArrayList;
import org.servalproject.R;
+import org.servalproject.ServalBatPhoneApplication;
+import org.servalproject.dna.DataFile;
+import org.servalproject.dna.Dna;
+import org.servalproject.rhizome.Rhizome;
+import org.servalproject.rhizome.RhizomeMessage;
import android.app.IntentService;
import android.content.Intent;
@@ -126,9 +131,68 @@ private void processComplexMessage(ComplexMeshMS message) {
// private method to process a simple message
private void processSimpleMessage(SimpleMeshMS message) {
- //TODO actually do something with the message
- Log.v(TAG, "sender: " + message.getSender());
- Log.v(TAG, "recipient: " + message.getRecipient());
- Log.v(TAG, "content: " + message.getContent());
+ // validate the message contents
+ if (message.getRecipient() == null) {
+ Log.e(TAG, "new simpleMeshMS is missing the recipient field");
+ return;
+ }
+
+ if (message.getContent() == null) {
+ Log.e(TAG, "new simpleMeshMS is missing the content field");
+ return;
+ }
+
+ if (message.getSender() == null) {
+ // replace with the sender configured in batphone
+ Log.w(TAG,
+ "new simpleMeshMS is missing sender field, using primary batphone number");
+ message.setSender(DataFile.getDid(0));
+ }
+
+ // declare helper variables
+ ServalBatPhoneApplication mBatphoneApplication = (ServalBatPhoneApplication) getApplicationContext();
+
+ Dna mDnaClient = new Dna();
+ mDnaClient.timeout = 3000;
+ try {
+ mDnaClient.setDynamicPeers(mBatphoneApplication.wifiRadio
+ .getPeers());
+ } catch (IOException e) {
+ Log.e(TAG,
+ "Unable to configure DNA instance with peer list, sending simpleMeshMS aborted",
+ e);
+ return;
+ }
+
+ boolean mSent = false;
+
+ // try to send the message via DNA directly
+ try {
+ mSent = mDnaClient.sendSms(message.getSender(),
+ message.getRecipient(), message.getContent());
+ } catch (IOException e) {
+ Log.w(TAG, "unable to send new simpleMeshMS directly", e);
+ }
+
+ if (mSent == true) {
+ Log.i(TAG, "new simpleMeshMS to: " + message.getRecipient()
+ + " has been sent directly");
+ } else {
+ // send message via rhizome
+ RhizomeMessage mRhizomeMessage = new RhizomeMessage(
+ message.getSender(), message.getRecipient(),
+ message.getContent());
+
+ mSent = Rhizome.appendMessage(mBatphoneApplication.getPrimarySID(),
+ mRhizomeMessage.toBytes());
+
+ if (mSent == false) {
+ Log.w(TAG, "unable to send new SimpleMeshMS via Rhizome");
+ } else {
+ Log.i(TAG, "new simeMeshMS to: " + message.getRecipient()
+ + " has been sent via Rhizome");
+ }
+
+ }
}
}

0 comments on commit bc22838

Please sign in to comment.