Skip to content

Commit

Permalink
Added some SVIP commands and added DPN filtering to AutoSessionAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
gtosoft committed Aug 16, 2011
1 parent 2c8b612 commit 5f5912c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
18 changes: 16 additions & 2 deletions doc/SVIP-protocol.txt
Expand Up @@ -17,17 +17,33 @@ Sample Transation.

CLIENT SERVER
==================================================================

* Sends a ping, expects a pong response.
PING|> <_
> ACK|PING|PONG|>

* rejected secret. possibly close connection upon bad secret.
AUTH|BADSECRET|> <_
> NACK|AUTH|>

* specify authentication secret.
AUTH|SECRET|> <_
> ACK|AUTH|>

* future use: activate or deactivate unsolicited OOB messages. When activated, out of band messages will be broadcast to all connected clients.
OOB|on|> <_
> ACK|OOB|>

* Get a list of all DPNs that we can subscribe to.
GETACTIVEDPNS|> <_
> ACK|GETACTIVEDPNS|SPEED,RPM,GPS|>

* Subscribe to zero or more DPNs. Once subscribed, expect to receive upates for each DPN.
SETDPNFILTER|SPEED|> <_
> ACK|SETDPNFILTER|>


* Sample messages (unsolicited types):
OOB|IOCONNECT|1|>
OOB|SESSIONDETECT|detected network as CAN 500 moni=yes|>
OOB|MSG|Diagnostic message: asdfad asdfa sd fsdf|>
Expand All @@ -37,8 +53,6 @@ OOB|on|> <_
DPDATA|RPM|1505|>
DPDATA|SPEED|27|>



* libVoyager will support more than one simultaneous connections.
* Any connection can elect to receive OOB events and/or decoded-data (DPDATA) events.

Expand Down
33 changes: 29 additions & 4 deletions src/com/gtosoft/libvoyager/autosession/AutoSessionAdapter.java
@@ -1,5 +1,8 @@
package com.gtosoft.libvoyager.autosession;

import java.util.Set;
import java.util.TreeSet;

import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.util.Log;
Expand Down Expand Up @@ -35,6 +38,11 @@ public class AutoSessionAdapter {
GeneralStats mgStats = new GeneralStats();
ServiceHelper msHelper;

// This will hold zero or more DPNs. If a DPN is in this set then we route/forward DPArrived events up the chain as we see them.
// elements not in the list get dropped by this class.
// Use a treeSets because it is sorted for faster access.
Set<String> mDPSubscribedSet = new TreeSet<String>();

// SVIP server component. listens for incoming connections. its lifecycle should track that of the hybridsession.
SVIPTCPServer mSVIPServer;

Expand Down Expand Up @@ -253,10 +261,15 @@ public void onNewMessageArrived(String message) {
@Override
public void onDPArrived(String DPN, String sDecodedData, int iDecodedData) {

// Route it upwards!
// - to our parent class, in case they want it
// - also probably to SVIP or whatever.
sendDPArrivedMessage(DPN, sDecodedData);
if (mDPSubscribedSet.contains(DPN)) {
// Route it upwards!
// - to our parent class, in case they want it
// - also probably to SVIP or whatever.
sendDPArrivedMessage(DPN, sDecodedData);
} else {
msg ("AugoSessionAdapter: Not routing DPN " + DPN + " because no subscription exists for it.");
// skip routing of this DPN - not subscribed.
}
}
};

Expand Down Expand Up @@ -329,6 +342,18 @@ private void sendDPArrivedMessage (String DPN, String sDecodedData) {
}

}

public void addDPSubscription (String DPN) {
mDPSubscribedSet.add(DPN);
}

public void removeDPSubscription (String DPN) {
mDPSubscribedSet.remove(DPN);
}

public Set<String> getDPSubscriptionSet () {
return new TreeSet<String>(mDPSubscribedSet);
}


private void msg (String m) {
Expand Down
4 changes: 1 addition & 3 deletions src/com/gtosoft/libvoyager/svip/SVIPTCPServer.java
Expand Up @@ -47,9 +47,7 @@ public class SVIPTCPServer {
*/
public SVIPTCPServer() {
if (DEBUG) msg ("----------------------------------------------------------------------SVIP TCP SERVER STARTUP.");
// if (DEBUG) EasyTime.safeSleep(1000);

// hs = h;

// Start a thread that waits for new connections.
startAcceptThread();
}
Expand Down

0 comments on commit 5f5912c

Please sign in to comment.