Skip to content

Commit

Permalink
- Improve performance
Browse files Browse the repository at this point in the history
- Stability issues
  • Loading branch information
unknown authored and unknown committed Jul 14, 2015
1 parent 8c41fa8 commit 2910b21
Show file tree
Hide file tree
Showing 13 changed files with 1,457 additions and 869 deletions.
2 changes: 2 additions & 0 deletions assets/logback.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/sdcard/MedtronicUploader.log</file>
<append>true</append>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>/sdcard/MedtronicUploader.%i.log.zip</fileNamePattern>
<minIndex>1</minIndex>
Expand Down
Binary file added libs/mongo-java-driver-3.0.2.jar
Binary file not shown.
Binary file modified libs/physicaloidlibrary.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<string name="eula_title">Disclaimer</string>
<string name="eula_accept">Accept</string>
<string name="eula_refuse">Refuse</string>
<string name="version">Version: 10.02.15</string>
<string name="version">Version: 03.07.15</string>
<style name="ButtonText">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
Expand Down
136 changes: 118 additions & 18 deletions src/com/nightscout/android/dexcom/DexcomG4Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class DexcomG4Activity extends Activity implements OnSharedPreferenceChan
boolean mIsBound;
boolean keepServiceAlive = true;
Boolean mHandlerActive = false;
Object mHandlerActiveLock = new Object();
Boolean usbAllowedPermission = false;
final Messenger mMessenger = new Messenger(new IncomingHandler());
ActivityManager manager = null;
Expand Down Expand Up @@ -123,6 +124,9 @@ public void handleMessage(Message msg) {
mHandler.removeCallbacks(updateDataView);
mHandler.post(updateDataView);
break;
case MedtronicConstants.MSG_MEDTRONIC_GLUCMEASURE_DETECTED:
showUseCalibConfirmation(msg.getData().getFloat("data"), msg.getData().getBoolean("calibrating"), msg.getData().getBoolean("isCalFactorFromPump"));
break;
case MedtronicConstants.MSG_MEDTRONIC_CGM_USB_GRANTED:
usbAllowedPermission = true;
mHandler.removeCallbacks(updateDataView);
Expand All @@ -148,11 +152,93 @@ public void handleMessage(Message msg) {
mHandler.removeCallbacks(updateDataView);
mHandler.post(updateDataView);
break;
case MedtronicConstants.MSG_REFRESH_DB_CONNECTION:
if (mService != null){
try {
Message message = Message.obtain(null, MedtronicConstants.MSG_REFRESH_DB_CONNECTION);
msg.replyTo = mMessenger;
mService.send(message);
} catch (RemoteException e) {
StringBuffer sb1 = new StringBuffer("");
sb1.append("EXCEPTION!!!!!! "+ e.getMessage()+" "+e.getCause());
for (StackTraceElement st : e.getStackTrace()){
sb1.append(st.toString()).append("\n");
}
Log.e("ApprovingGlucValReceived", "Error approving gluc. value \n "+sb1.toString());
if (ISDEBUG){
display.setText(display.getText()+"Error approving gluc. value\n", BufferType.EDITABLE);
}
}
}
break;
default:
super.handleMessage(msg);
}
}
}
private void showUseCalibConfirmation(final float num, final boolean calibrate, final boolean isCalFactorFromPump){
AlertDialog.Builder alert = new AlertDialog.Builder(ctx);
alert.setTitle("Calibration Detected!!!");
alert.setMessage("Do you want to use the received glucometer value for calibration?");

alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (mService != null){
try {
Message msg = Message.obtain(null, MedtronicConstants.MSG_MEDTRONIC_GLUCMEASURE_APPROVED);
Bundle b = new Bundle();
b.putBoolean("approved", true);
b.putFloat("data", num);
b.putBoolean("calibrating", calibrate);
b.putBoolean("isCalFactorFromPump", isCalFactorFromPump);
msg.setData(b);
msg.replyTo = mMessenger;
mService.send(msg);
} catch (RemoteException e) {
StringBuffer sb1 = new StringBuffer("");
sb1.append("EXCEPTION!!!!!! "+ e.getMessage()+" "+e.getCause());
for (StackTraceElement st : e.getStackTrace()){
sb1.append(st.toString()).append("\n");
}
Log.e("ApprovingGlucValReceived", "Error approving gluc. value \n "+sb1.toString());
if (ISDEBUG){
display.setText(display.getText()+"Error approving gluc. value\n", BufferType.EDITABLE);
}
}
}
}
});

alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (mService != null){
try {
Message msg = Message.obtain(null, MedtronicConstants.MSG_MEDTRONIC_GLUCMEASURE_APPROVED);
Bundle b = new Bundle();

b.putBoolean("approved", false);

msg.setData(b);
msg.replyTo = mMessenger;
mService.send(msg);
} catch (RemoteException e) {
StringBuffer sb1 = new StringBuffer("");
sb1.append("EXCEPTION!!!!!! "+ e.getMessage()+" "+e.getCause());
for (StackTraceElement st : e.getStackTrace()){
sb1.append(st.toString()).append("\n");
}
Log.e("ApprovingGlucValReceived", "Error approving gluc. value \n "+sb1.toString());
if (ISDEBUG){
display.setText(display.getText()+"Error approving gluc. value\n", BufferType.EDITABLE);
}
}
}
}
});

alert.show();
}

private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
bService = service;
Expand All @@ -179,6 +265,7 @@ public void onServiceConnected(ComponentName className, IBinder service) {
public void onServiceDisconnected(ComponentName className) {
// This is called when the connection with the service has been unexpectedly disconnected - process crashed.
mService = null;
bService = null;
Log.i("DXCG4_MEDTRONICSERVICE_ONSERVICEDISCONNECTED","Service Disconnected\n");
if (ISDEBUG){
display.setText(display.getText()+"Service Disconnected\n", BufferType.EDITABLE);
Expand All @@ -191,7 +278,7 @@ public void onServiceDisconnected(ComponentName className) {
//All I'm really doing here is creating a simple activity to launch and maintain the service
private Runnable updateDataView = new Runnable() {
public void run() {
synchronized (mHandlerActive) {
synchronized (mHandlerActiveLock) {
if (!mHandlerActive)
return;
if (!isMyServiceRunning()) {
Expand Down Expand Up @@ -442,7 +529,7 @@ public void onClick(View v) {
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
synchronized (mHandlerActive) {
synchronized (mHandlerActiveLock) {
if (b1.getText() == "Stop Uploading CGM Data") {
mHandlerActive = false;
mHandler.removeCallbacks(updateDataView);
Expand Down Expand Up @@ -785,6 +872,16 @@ public void onClick(DialogInterface dialog, int whichButton) {
// Set an EditText view to get user input
input = new EditText(ctx);
input.setInputType(InputType.TYPE_CLASS_NUMBER|InputType.TYPE_NUMBER_FLAG_DECIMAL);

float num = settings.getFloat("lastGlucometerValue", (float) -1f);
if (num <= 0)
num = 0;

if (prefs.getBoolean("mmolxl", false)){
DecimalFormat df = new DecimalFormat("#.#");
input.setText(df.format((num/18.0)));
}else
input.setText(""+(int)num);
alert2.setView(input);

alert2.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
Expand Down Expand Up @@ -873,7 +970,7 @@ protected void onDestroy() {
log.info("onDestroy called");
PreferenceManager.getDefaultSharedPreferences(getBaseContext()).unregisterOnSharedPreferenceChangeListener(this);
unregisterReceiver(mArrow);
synchronized (mHandlerActive) {
synchronized (mHandlerActiveLock) {
mHandler.removeCallbacks(updateDataView);
doUnbindService();
if (keepServiceAlive){
Expand Down Expand Up @@ -992,21 +1089,24 @@ else if ("2".equalsIgnoreCase(type)){
stopService(new Intent(DexcomG4Activity.this, DexcomG4Service.class));
SharedPreferences settings = getSharedPreferences(MedtronicConstants.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.remove("lastGlucometerMessage");
editor.remove("previousValue");
editor.remove("expectedSensorSortNumber");
editor.remove("knownDevices");
editor.remove("isCalibrating");
editor.remove("lastGlucometerMessage");
editor.remove("previousValue");
editor.remove("lastGlucometerValue");
editor.remove("lastGlucometerDate");
editor.remove("expectedSensorSortNumberForCalibration0");
editor.remove("expectedSensorSortNumberForCalibration1");
editor.remove("lastPumpAwake");
editor.commit();
String type = prefs.getString("monitor_type", "1");
if ("1".equalsIgnoreCase(type)){
editor.remove("lastGlucometerMessage");
editor.remove("previousValue");
editor.remove("expectedSensorSortNumber");
editor.remove("knownDevices");
editor.remove("isCalibrating");
editor.remove("lastGlucometerMessage");
editor.remove("previousValue");
editor.remove("lastGlucometerValue");
editor.remove("lastGlucometerDate");
editor.remove("expectedSensorSortNumberForCalibration0");
editor.remove("expectedSensorSortNumberForCalibration1");
editor.remove("lastPumpAwake");
editor.commit();
}
if (!sharedPreferences.getBoolean("IUNDERSTAND", false)){
synchronized (mHandlerActive) {
synchronized (mHandlerActiveLock) {
mHandler.removeCallbacks(updateDataView);
mHandlerActive = false;
}
Expand All @@ -1023,7 +1123,7 @@ else if ("2".equalsIgnoreCase(type)){
//If i do not
if (key.equals("IUNDERSTAND")){
if (!sharedPreferences.getBoolean("IUNDERSTAND", false)){
synchronized (mHandlerActive) {
synchronized (mHandlerActiveLock) {
mHandler.removeCallbacks(updateDataView);
mHandlerActive = false;
}
Expand Down
30 changes: 15 additions & 15 deletions src/com/nightscout/android/medtronic/CommandSenderThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,44 +78,44 @@ public void run() {
}
if (wThread.retries >= MedtronicConstants.NUMBER_OF_RETRIES){
mHandler3.removeCallbacks(wThread);
synchronized (reader.sendingCommand) {
synchronized (reader.sendingCommandLock) {
reader.sendingCommand = false;
}
synchronized (reader.waitingCommand) {
synchronized (reader.waitingCommandLock) {
reader.waitingCommand = false;
reader.lastCommandSend = null;
}
synchronized (reader.processingCommand) {
synchronized (reader.processingCommandLock) {
reader.processingCommand = false;
}
sendMessageToUI("Timeout expired executing command list", false);
synchronized (reader.processingCommand) {
synchronized (reader.processingCommandLock) {
reader.processingCommand = false;
}
synchronized (reader.waitingCommand) {
synchronized (reader.waitingCommandLock) {
reader.waitingCommand = false;
reader.lastCommandSend = null;
}
return;
}

if (index >= commandList.length){
synchronized (reader.processingCommand) {
synchronized (reader.processingCommandLock) {
reader.processingCommand = false;
}
synchronized (reader.waitingCommand) {
synchronized (reader.waitingCommandLock) {
reader.waitingCommand = false;
reader.lastCommandSend = null;
}
return;
}
if (withoutConfirmation <= 0){
synchronized (reader.waitingCommand) {
synchronized (reader.waitingCommandLock) {
reader.waitingCommand = true;
reader.lastCommandSend = null;
}
}else{
synchronized (reader.waitingCommand) {
synchronized (reader.waitingCommandLock) {
reader.waitingCommand = false;
reader.lastCommandSend = null;
}
Expand Down Expand Up @@ -235,7 +235,7 @@ public void setCommand(byte command){

public void run(){
try{
synchronized (reader.processingCommand) {
synchronized (reader.processingCommandLock) {
if (!reader.processingCommand)
return;
}
Expand All @@ -247,7 +247,7 @@ public void run(){
}
log.debug("sendcommand");

synchronized (reader.sendingCommand) {
synchronized (reader.sendingCommandLock) {
if (reader.sendingCommand){
if (timeoutSending < 11){
log.debug("timeoutSending++ "+timeoutSending);
Expand All @@ -268,7 +268,7 @@ public void run(){
log.debug("sent ");
//if I have sent it, I will wait once to give the "enlite" time to answer, next time I will retry.
sent = false;
synchronized (reader.waitingCommand) {
synchronized (reader.waitingCommandLock) {
if (!reader.waitingCommand){
retries = 0;
mHandler4.removeCallbacks(instance);
Expand All @@ -282,7 +282,7 @@ public void run(){
mHandler3.postDelayed(wThread, delay);
return;
}
synchronized (reader.waitingCommand) {
synchronized (reader.waitingCommandLock) {
if (!reader.waitingCommand){
if (withoutConfirmation > 0){
log.debug("sending command without expecting confirmation still send -->"+ (withoutConfirmation--));
Expand All @@ -304,11 +304,11 @@ public void run(){
else
sendMedtronicPumpCommand(command, repeat, postCommandBytes);

synchronized (reader.waitingCommand) {
synchronized (reader.waitingCommandLock) {
reader.lastCommandSend = command;// register the command
}

synchronized (reader.sendingCommand) {
synchronized (reader.sendingCommandLock) {
log.debug("send command "+retries);
reader.sendingCommand = true;
if (!sent){
Expand Down
Loading

0 comments on commit 2910b21

Please sign in to comment.