1. Running Sample OBEX applications. Allan has found some sample
application that he think might work. It may be a matter of time
before he can get it to work on the PC.
2. Decompose a working RFCOMM example and tailor it to work on the PC:
I had found an RFCOMM example implemented by Skarzhevskyy. I am
confident that given the time and effort I can remove the mobile
device-specific code and implement it so that it will work on the base
station.
3. COM Programming: The Windows bluetooth stack and standard controls
allow one to make the BT adapter act as a COM port. In this case it is
a matter of simply datastreaming information onto the COM port and
allow the operating system handle the communication protocols.
This is my main focus so far, but I would like to get Chris started on
designing the digital signal processing information for reading the
sensor information from the remote devices.
-CN
http://developers.sun.com/mobility/apis/articles/bluetoothintro/
Link leads to url format for stream connection.
Latest RIFL Mobile Application Project:
http://engineering-design-ii-group-6-spring-2010.googlegroups.com/web/RIFLMobileApp_20100327A.zip?hl=en&gda=ar6AsU4AAAAwTyAxwHLHtIuBlBn-zYvOdKcNTbXyOelrLKctlz3BMwmjc21bTLet4nUqigOwfc3M0fqyNZ9G9mkkMSqWY8tl47Cl1bPl-23V2XOW7kn5sQ&gsc=25YwXAsAAACJE8INRGehRZZt8ECs-VES
Latest RIFL Base Station Application Project:
http://engineering-design-ii-group-6-spring-2010.googlegroups.com/web/Bluetooth_RFCOMM_Example_v1_4_en-1.zip?hl=en&gda=cB7WkVkAAAAwTyAxwHLHtIuBlBn-zYvOzizw3wgPbOSrzB1MvbZV2zNKR5demoBi23TLLYe9gKeVjjUIt5MQcXdRfzi6GfyiUE08L0elliYmXmGPZRXkPYQIqBBuatoZ3GVm6VpieyE&gsc=25YwXAsAAACJE8INRGehRZZt8ECs-VES
Parsing Function:
This code takes advantage of the import java.util.Scanner class. If
you have an IDE that makes use of the log statement they will help.
Otherwise, you may want to replace with println.
/**
* Takes message and extracts information from it and stores values
in respective data types.
* @param message
* String that is passed from message handler that contains the
contents of the bluetooth transmission.
*/
private void parseBTMessage(String message)
{
sensorName = "";
sensorType = "";
sensorVendor = "";
sensorVersion = "";
maxRange = "";
powerDissipation = "";
resolution = "";
accuracy = "";
timeStamp = "";
values[0] = "";
values[1] = "";
values[2] = "";
Scanner scanner = new Scanner(message);
scanner.useDelimiter("\n");
if ( scanner.hasNext() )
{
sensorName = scanner.next();
sensorType = scanner.next();
sensorVendor = scanner.next();
sensorVersion = scanner.next();
maxRange = scanner.next();
powerDissipation = scanner.next();
resolution = scanner.next();
accuracy = scanner.next();
timeStamp = scanner.next();
values[0] = scanner.next();
values[1] = scanner.next();
values[2] = scanner.next();
Log.d(TAG,"Name: "+ sensorName.trim()
+ " Type: " + sensorType
+ " Vendor: " + sensorVendor
+ " Version: " + sensorVersion
+ " Max Range: " + maxRange
+ " Power: " + powerDissipation
+ " Resolution: " + resolution
+ " accuracy: " + accuracy
+ " Timestamp: " + timeStamp
+ " Values[0]: " + values[0]
+ " Values[1]: " + values[1]
+ " Values[2]: " + values[2]);
}
else
{
Log.d(TAG,"Sensor parser: Empty or invalid line. Unable to
process.");
}
scanner.close();
}
On Mar 27, 11:52 am, allan pinero <onik...@gmail.com> wrote:
> http://www.codemiles.com/java/connecting-to-pc-from-mobile-using-blue...
> bluetooth server
On Mar 27, 5:58 pm, Charles Norona <cnoro...@gmail.com> wrote:
> Good work, guys! We have made great progress in both establishing a
> bluetooth datastreaming medium between the PC and the mobile devices
> as well as implementing some sensor interpretation logic. Allan,
> please, refer to the end of this message for an improved way of
> parsing the bluetooth messages. We are using the same algorithm to
> interpret the sensor readings and find out the magnitude of the
> distance the user travels. In the time being, we are testing these
> algorithms on a mobile-to-mobile basis but will plug them into the
> base station application once a stable bluetooth medium has been
> established for good! The updated files can be found in the files
> section. Again, great work to the both of you!
>
> Latest RIFL Mobile Application Project:http://engineering-design-ii-group-6-spring-2010.googlegroups.com/web...
>
> Latest RIFL Base Station Application Project:http://engineering-design-ii-group-6-spring-2010.googlegroups.com/web...
> > bluetooth server- Hide quoted text -
>
> - Show quoted text -
Message handling algorithm:
byte[] readBuf = (byte[]) msg.obj;
// construct a string from the valid bytes in the buffer
String readMessage = new String(readBuf, 0, msg.arg1);
input.setText(readMessage);
//TODO: Implement functions
try
{
parseBTMessage(readMessage);//Parse message information
magnitude = determineMagnitude(values[0],values[1],values[2]);//
Determine magnitude
timeChange = determineTimeChange(timeStamp);//Determine change in
time
distanceChange = determineDistanceChange(magnitude, timeChange);//
Determine change in distance
}
catch(NullPointerException e)
{
Log.e(TAG,"e");
Log.e(TAG,"handleMessage:MESSAGE_READ does not work!");
}
Functions:
/**
* Takes message and extracts information from it and stores values
in respective data types. Also, outputs the values to a local file on
the SD card.
* NOTE: Meant to be used by base station application.
* @param message
* String that is passed from message handler that contains the
contents of the bluetooth transmission.
*/
private void parseBTMessage(String message)
{
pWriter.println(message);
if(message != null)
{
if(message.length() > 105)
{
Scanner scanner = new Scanner(message);
scanner.useDelimiter("\n");
if ( scanner.hasNext() )
{
try
{
sensorName = scanner.next();
sensorType = scanner.next();
sensorVendor = scanner.next();
sensorVersion = scanner.next();
maxRange = scanner.next();
powerDissipation = scanner.next();
resolution = scanner.next();
accuracy = scanner.next();
timeStamp = scanner.next();
values[0] = scanner.next();
values[1] = scanner.next();
values[2] = scanner.next();
}
catch (NoSuchElementException e)
{
e.printStackTrace();
}
Log.d(TAG,"Name: "+ sensorName.trim()
+ ", Type: " + sensorType
+ ", Vendor: " + sensorVendor
+ ", Version: " + sensorVersion
+ ", Max Range: " + maxRange
+ ", Power: " + powerDissipation
+ ", Resolution: " + resolution
+ ", accuracy: " + accuracy
+ ", Timestamp: " + timeStamp
+ ", Values[0]: " + values[0]
+ ", Values[1]: " + values[1]
+ ",
Values[2]: " + values[2]);
}
else
{
Log.d(TAG,"Sensor parser: Empty or invalid line. Unable to
process.");
}
scanner.close();
}
}
}
/**
* Takes the sensor values of the accelerometer and determines the
magnitude using those values.
* NOTE: Meant to be used by base station application.
* @param x,y,z
*/
private double determineMagnitude(String x, String y, String z)
{
float newX = 0, newY = 0, newZ = 0;
double sum;
//Convert strings to float
newX = Float.valueOf(x);
newY = Float.valueOf(y);
newZ = Float.valueOf(z);
//Squaring each value
newX = newX * newX;
newY = newY * newY;
newZ = newZ * newZ;
//Add them together
sum = newX + newY + newZ;
//Square root
return(Math.sqrt(sum));
}
/**
* Calculates the difference of the respective remote device's
previous timestamp with the current timestamp.
* NOTE: Meant to be used by base station application.
* @param newTime
*/
private double determineTimeChange(String newTime)
{
double timeChange = 0;
double mNewTime = 0;
//Convert to int...err, double
mNewTime = Double.valueOf(newTime);
mNewTime = (mNewTime/1000000000);
//newTimeStamp = Integer.parseInt(newTime.substring(0, 1));//Works
newTimeStamp = mNewTime;
//oldTimeStamp = newTimeStamp;
timeChange = newTimeStamp - oldTimeStamp;
//Store old time stamp.
oldTimeStamp = newTimeStamp;
Log.d(TAG,"Old Timestamp: "+ oldTimeStamp
+ " New Timestamp: " + newTimeStamp
+ " Time Change: " + timeChange);
return timeChange;
}
/**
* With given time and magnitude the distance is calculated.
* NOTE: Meant to be used by base station application.
* @param magnitude, timeChange
*/
private double determineDistanceChange(Double mMagnitude, double
mTimeChange)
{
distanceChange = 0;
distanceChange = (int) (mMagnitude * (mTimeChange * mTimeChange));
Log.d(TAG,"Magnitude: "+ mMagnitude
+ " Time Change: " + mTimeChange
+ " Distance Change: " + distanceChange);
return distanceChange;
}
/**
* Sets up the file stream for writing
* NOTE: Meant to be used by base station application.
*/
private void fileSetup()
{
try
{
if (!filepath.exists())
{
filepath.mkdirs();
}
fWriter = new FileWriter(filepath.getPath() + "/testresult" +
numberOfRuns + ".txt");
pWriter = new PrintWriter(fWriter);
}
catch (Exception e)
{
e.printStackTrace();
}
pWriter.println("Time \t X: \t Y: \t Z:");
}
> > - Show quoted text -- Hide quoted text -