Permalink
Browse files

power keepon for cpu, some other misc updates

  • Loading branch information...
1 parent 5bbd11a commit 576c874b8ba9fc22a5e53183ec8eb65e73508e4c @tz1 committed May 28, 2012
View
@@ -6,7 +6,8 @@
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.INTERNET"/>
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-sdk android:targetSdkVersion="7" android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".BlueLogger"
View
@@ -8,4 +8,4 @@
# project structure.
# Project target.
-target=android-8
+target=android-9
@@ -9,13 +9,15 @@
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
+import java.util.Arrays;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
+import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.view.GestureDetector;
import android.view.KeyEvent;
@@ -626,15 +628,15 @@ public SendAGPSThread() {
}
private byte setagps[] = { (byte) 0xa0, (byte) 0xa1, 0x00, 0x01, 0x35, 0x35, 0x0d, 0x0a };
- private byte agpsresp[] = { (byte) 0xa0, (byte) 0xa1, 0x00, 0x02, (byte) 0x83, 0x35, (byte) 0xb6, 0x0d, 0x0a };
+ //private byte agpsresp[] = { (byte) 0xa0, (byte) 0xa1, 0x00, 0x02, (byte) 0x83, 0x35, (byte) 0xb6, 0x0d, 0x0a };
private byte agpsenable[] = { (byte) 0xa0, (byte) 0xa1, 0x00, 0x02, 0x33, 0x01, 0x32, 0x0d, 0x0a };
public void run() {
mEmulatorView.write("SendAGPS\r\n".getBytes(),9);
int len = 0;
int bufmax = 256*1024;
- byte[] buf = new byte[bufmax];
+ byte [] buf = new byte[bufmax];
String retr = "Accessing downloaded file\r\n";
try {
System.err.println(retr);
@@ -657,16 +659,16 @@ public void run() {
csuma += buf[i];
csuma &= 0xff;
csumb &= 0xff;
- //mmOutStream.write(setagps, 0, setagps.length);
+ send(setagps);
sleep(1000);
String astline = "BINSIZE = " + len + " Checksum = " + csuma + " Checksumb = " + csumb + " ";
retr = astline + "\r\n";
System.err.println(retr);
mEmulatorView.write(retr.getBytes(),retr.length());
- //mmOutStream.write(astline.getBytes(), 0, astline.length());
+ send(astline.getBytes());
- retr = "Sending SkyTraq AGPS data\r\n";
+ retr = "\r\nSending SkyTraq AGPS data\r\n";
System.err.println(retr);
mEmulatorView.write(retr.getBytes(),retr.length());
@@ -677,16 +679,15 @@ public void run() {
retr = ((tot - len) * 100 / tot) + "\r\n";
System.err.println(retr);
mEmulatorView.write(retr.getBytes(),retr.length());
-
- //mmOutStream.write(buf, ofst, len > 8192 ? 8192 : len);
+ send(Arrays.copyOfRange(buf, ofst, ofst + (len > 8192 ? 8192 : len)));
// should respond with OK
sleep(1000);
len -= 8192;
ofst += 8192;
}
// should respond with END
sleep(1000);
- //mmOutStream.write(agpsenable, 0, agpsenable.length);
+ send(agpsenable);
retr = "(Not Implemented)\r\n";
System.err.println(retr);
mEmulatorView.write(retr.getBytes(),retr.length());
@@ -700,6 +701,8 @@ public void run() {
}
}
private SendAGPSThread mSendAGPSThread;
+ private PowerManager mPm;
+ private PowerManager.WakeLock mWl;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
@@ -710,13 +713,17 @@ public boolean onOptionsItemSelected(MenuItem item) {
// Launch the DeviceListActivity to see devices and do scan
Intent serverIntent = new Intent(this, DeviceListActivity.class);
startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
+ mPm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
+ mWl = mPm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BlueLog");
+ mWl.acquire();
}
else
if (getConnectionState() == BluetoothSerialService.STATE_CONNECTED) {
+ mWl.release();
mSerialService.stop();
mSerialService.start();
}
- return true;
+ return true;
case R.id.preferences:
doPreferences();
return true;
@@ -1243,6 +1250,7 @@ public void resize(int columns, int rows, int foreColor, int backColor) {
}
}
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Renders text into a screen. Contains all the terminal-specific knowlege and
* state. Emulates a subset of the X Window System xterm terminal, which in turn
@@ -25,8 +25,10 @@
import java.io.OutputStream;
import java.util.UUID;
import java.util.Date;
+import java.util.zip.Deflater;
import java.util.zip.GZIPOutputStream;
import java.text.SimpleDateFormat;
+//import java.util.zip.Deflater;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
@@ -345,24 +347,34 @@ public void run() {
try {
FileOutputStream logfy = new FileOutputStream(logfy0);
BufferedOutputStream logfw = new BufferedOutputStream(logfy);
- GZIPOutputStream zos = new GZIPOutputStream(new BufferedOutputStream(logfw));
-
+ GZIPOutputStream zos = new GZIPOutputStream(logfw)
+ {
+ {
+ def.setLevel(Deflater.BEST_COMPRESSION);
+ }
+ };
+ //zos.setLevel(BEST_COMPRESSION);
// Keep listening to the InputStream while connected
int rxblocks = 0;
+
while (true) {
try {
// Read from the InputStream
- bytes = mmInStream.read(buffer);
- zos.write(buffer, 0, bytes);
- mEmulatorView.write(buffer, bytes);
- if( rxblocks++ > 5000 ) {
- // push the data through every 5000 blocks
- zos.flush();
- logfw.flush();
- logfy.flush();
- logfy.getFD().sync();
- rxblocks = 0;
- }
+ bytes = mmInStream.read(buffer);
+ if( bytes > 0 ) {
+ zos.write(buffer, 0, bytes);
+ mEmulatorView.write(buffer, bytes);
+ if( rxblocks++ > 5000 ) {
+ // push the data through every 5000 blocks
+ zos.flush();
+ logfw.flush();
+ logfy.flush();
+ logfy.getFD().sync();
+ rxblocks = 0;
+ }
+ }
+ else
+ sleep(1);
} catch (Exception e) {
Log.e(TAG, "disconnected", e);
connectionLost();
@@ -375,11 +387,12 @@ public void run() {
} catch (Exception e) {
}
if( brokenconn ) {
- Log.e(TAG, "Broken Connection");
+ Log.e(TAG, "Broken Connection - will try reconnect");
mConnectThread = new ConnectThread(mmDevice);
mConnectThread.start();
setState(STATE_CONNECTING);
}
+
}
/**

0 comments on commit 576c874

Please sign in to comment.