rhino some more cleanups

This commit is contained in:
AdrianLxM 2017-10-15 16:19:29 +02:00
parent d32a874baa
commit 564c882754
3 changed files with 8 additions and 18 deletions

View file

@ -1,7 +1,5 @@
package info.nightscout.androidaps.plugins.OpenAPSMA; package info.nightscout.androidaps.plugins.OpenAPSMA;
import com.j256.ormlite.logger.Log;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.mozilla.javascript.Callable; import org.mozilla.javascript.Callable;
@ -70,7 +68,7 @@ public class DetermineBasalAdapterMAJS {
//generate functions "determine_basal" and "setTempBasal" //generate functions "determine_basal" and "setTempBasal"
rhino.evaluateString(scope, readFile("OpenAPSMA/determine-basal.js"), "JavaScript", 0, null); rhino.evaluateString(scope, readFile("OpenAPSMA/determine-basal.js"), "JavaScript", 0, null);
String setTempBasalCode= "var setTempBasal = function (rate, duration, profile, rT, offline) {" + String setTempBasalCode = "var setTempBasal = function (rate, duration, profile, rT, offline) {" +
"rT.duration = duration;\n" + "rT.duration = duration;\n" +
" rT.rate = rate;" + " rT.rate = rate;" +
"return rT;" + "return rT;" +
@ -79,6 +77,7 @@ public class DetermineBasalAdapterMAJS {
Object determineBasalObj = scope.get("determine_basal", scope); Object determineBasalObj = scope.get("determine_basal", scope);
Object setTempBasalObj = scope.get("setTempBasal", scope); Object setTempBasalObj = scope.get("setTempBasal", scope);
//call determine-basal
if (determineBasalObj instanceof Function && setTempBasalObj instanceof Function) { if (determineBasalObj instanceof Function && setTempBasalObj instanceof Function) {
Function determineBasalJS = (Function) determineBasalObj; Function determineBasalJS = (Function) determineBasalObj;
Function setTempBasalJS = (Function) setTempBasalObj; Function setTempBasalJS = (Function) setTempBasalObj;
@ -95,7 +94,7 @@ public class DetermineBasalAdapterMAJS {
NativeObject jsResult = (NativeObject) determineBasalJS.call(rhino, scope, scope, params); NativeObject jsResult = (NativeObject) determineBasalJS.call(rhino, scope, scope, params);
// Parse the jsResult object to a String // Parse the jsResult object to a JSON-String
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString(); String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
if (Config.logAPSResult) if (Config.logAPSResult)
log.debug("Result: " + result); log.debug("Result: " + result);
@ -109,14 +108,14 @@ public class DetermineBasalAdapterMAJS {
} }
} catch (IOException e) { } catch (IOException e) {
log.debug("IOException"); log.debug("IOException");
} catch (RhinoException e){ } catch (RhinoException e) {
log.error("RhinoException: (" + e.lineNumber() + ","+ e.columnNumber() + ") " + e.toString()); log.error("RhinoException: (" + e.lineNumber() + "," + e.columnNumber() + ") " + e.toString());
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
e.printStackTrace(); log.error(e.toString());
} catch (InstantiationException e) { } catch (InstantiationException e) {
e.printStackTrace(); log.error(e.toString());
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
e.printStackTrace(); log.error(e.toString());
} finally { } finally {
Context.exit(); Context.exit();
} }

View file

@ -1,10 +1,5 @@
package info.nightscout.androidaps.plugins.OpenAPSMA; package info.nightscout.androidaps.plugins.OpenAPSMA;
import android.os.Parcel;
import android.os.Parcelable;
import com.eclipsesource.v8.V8Object;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.mozilla.javascript.NativeObject; import org.mozilla.javascript.NativeObject;

View file

@ -233,8 +233,6 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
determineBasalResultMA.iob = iobTotal; determineBasalResultMA.iob = iobTotal;
//determineBasalAdapterMAJS.release(); TODO: Rhinoport
try { try {
determineBasalResultMA.json.put("timestamp", DateUtil.toISOString(now)); determineBasalResultMA.json.put("timestamp", DateUtil.toISOString(now));
} catch (JSONException e) { } catch (JSONException e) {
@ -245,8 +243,6 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
lastAPSResult = determineBasalResultMA; lastAPSResult = determineBasalResultMA;
lastAPSRun = now; lastAPSRun = now;
MainApp.bus().post(new EventOpenAPSUpdateGui()); MainApp.bus().post(new EventOpenAPSUpdateGui());
//deviceStatus.suggested = determineBasalResultMA.json;
} }