/*****************************************************************
SPINE - Signal Processing In-Node Environment is a framework that
allows dynamic on node configuration for feature extraction and a
OtA protocol for the management for WSN
Copyright (C) 2007 Telecom Italia S.p.A.
GNU Lesser General Public License
This library is free software; you can redistribute
modify it under the terms of the sub-license (below).
*****************************************************************/
/*****************************************************************
BSPAN - BlueTooth Sensor Processing for Android is a framework
that extends the SPINE framework to work on Android and the
Android Bluetooth communication services.
Copyright (C) 2011 The National Center for Telehealth and
Technology
Eclipse Public License 1.0 (EPL-1.0)
This library is free software; you can redistribute it and/or
modify it under the terms of the Eclipse Public License as
published by the Free Software Foundation, version 1.0 of the
License.
The Eclipse Public License is a reciprocal license, under
Section 3. REQUIREMENTS iv) states that source code for the
Program is available from such Contributor, and informs licensees
how to obtain it in a reasonable manner on or through a medium
customarily used for software exchange.
Post your updates and modifications to our GitHub or email to
t2@tee2.org.
This library is distributed WITHOUT ANY WARRANTY; without
the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the Eclipse Public License 1.0 (EPL-1.0)
for more details.
You should have received a copy of the Eclipse Public License
along with this library; if not,
visit http://www.opensource.org/licenses/EPL-1.0
*****************************************************************/
package com.t2.biofeedback.device.Mobi;
import java.util.ArrayList;
import android.os.Messenger;
import android.util.Log;
import com.t2.biofeedback.Constants;
import com.t2.biofeedback.device.BioFeedbackDevice;
import com.t2.biofeedback.device.Mobi.Structures.FrontEndInfo;
/**
* Encapsulates methods necessary to communicate with a Bluetooth Neurosky device
*
* @author scott.coleman
*
*/
public abstract class MobiDevice extends BioFeedbackDevice{
private static final String TAG = Constants.TAG;
boolean mDebug = true;
/**
* @param serverListeners List of server listeners (used to transmit messages to the Spine server)
*/
MobiDevice(ArrayList<Messenger> serverListeners)
{
this.mServerListeners = serverListeners;
}
/* (non-Javadoc)
* @see com.t2.biofeedback.device.BioFeedbackDevice#onDeviceConnected()
*/
protected void onDeviceConnected()
{
Log.i(TAG, "Mobi device Connected");
super.onDeviceConnected();
MobiMessage m = new MobiMessage(
FrontEndInfo.TMSFRONTENDINFOREQ,
new byte[] {
}
);
this.write(m.getBytes());
// mStreamParser = new StreamParser(StreamParser.PARSER_TYPE_PACKETS, this, null);
}
/* (non-Javadoc)
* @see com.t2.biofeedback.device.SerialBTDevice#onBeforeConnectionClosed()
*/
protected void onBeforeConnectionClosed()
{
}
/**
*
* Receives bytes from Bluetooth device and sends them to the parser.
* Note that the received bytes by come in any length. The parser seeds to
* Frame the data and detect complete messages. When this happens the
* parser will call dataValueReceived with the complete message.
* @see com.t2.biofeedback.device.SerialBTDevice#onBytesReceived(byte[])
*/
protected void onBytesReceived(byte[] bytes)
{
// Transfer bytes to parser one by one
// Each time updating the state machine
// then checking for a value header
for (int i=0; i< bytes.length; i++)
{
// mStreamParser.parseByte(bytes[i]);
}
}
/* (non-Javadoc)
* @see com.t2.biofeedback.device.BioFeedbackDevice#write(byte[])
*
* Not used - Neurosky device is write only.
*/
public void write(byte[] bytes) {
super.write(bytes);
}
/**
* Begins a Mindset message, populating common fields
*/
private void startMessage()
{
}
/*
* Called when the parser has a data row to send to the server
*
* (non-Javadoc)
* @see com.t2.biofeedback.device.neurosky.DataListener#dataValueReceived(int, int, int, byte[], java.lang.Object)
*/
public void dataValueReceived( int extendedCodeLevel, int code, int numBytes,
byte[] valueBytes, Object customData )
{
// if (mDebug)
// Util.logHexByteString(TAG, "Found message:", "");
}
}