diff --git a/app/build.gradle b/app/build.gradle index 556e18cded..c9df240616 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,6 +43,7 @@ android { applicationId "info.nightscout.androidaps" minSdkVersion 21 targetSdkVersion 23 + multiDexEnabled true versionCode 1500 version "1.54-dev" buildConfigField "String", "VERSION", '"' + version + '"' diff --git a/app/libs/rhino-1.7.7.2.jar b/app/libs/rhino-1.7.7.2.jar new file mode 100644 index 0000000000..4a18d33609 Binary files /dev/null and b/app/libs/rhino-1.7.7.2.jar differ diff --git a/app/src/main/assets/OpenAPSMA/determine-basal.js b/app/src/main/assets/OpenAPSMA/determine-basal.js index 4c5a00fade..266547c04d 100644 --- a/app/src/main/assets/OpenAPSMA/determine-basal.js +++ b/app/src/main/assets/OpenAPSMA/determine-basal.js @@ -16,6 +16,9 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_ var rT = { //short for requestedTemp }; + rT.error ='Error: could not get current basal rate'; + return rT; + if (typeof profile === 'undefined' || typeof profile.current_basal === 'undefined') { rT.error ='Error: could not get current basal rate'; return rT; @@ -313,4 +316,4 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_ }; -module.exports = determine_basal; \ No newline at end of file +//module.exports = determine_basal; \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java index a8f797f8c1..b79a3065ec 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java @@ -4,9 +4,14 @@ import com.eclipsesource.v8.JavaVoidCallback; import com.eclipsesource.v8.V8; import com.eclipsesource.v8.V8Array; import com.eclipsesource.v8.V8Object; +import com.j256.ormlite.logger.Log; import org.json.JSONException; import org.json.JSONObject; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.Function; +import org.mozilla.javascript.NativeObject; +import org.mozilla.javascript.Scriptable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,9 +65,56 @@ public class DetermineBasalAdapterMAJS { initProcessExitCallback(); initModuleParent(); loadScript(); + rhinotest(); + } + + public void rhinotest(){ + Context rhino = Context.enter(); + Scriptable scope = rhino.initStandardObjects(); + // Turn off optimization to make Rhino Android compatible + rhino.setOptimizationLevel(-1); + + try { + // Note the forth argument is 1, which means the JavaScript source has + // been compressed to only one line using something like YUI + //rhino.evaluateString(scope, javaScriptCode, "JavaScript", 1, null); + rhino.evaluateString(scope, readFile("OpenAPSMA/determine-basal.js"), "JavaScript", 0, null); + + // Get the functionName defined in JavaScriptCode + //Object obj = scope.get(functionNameInJavaScriptCode, scope); + Object obj = scope.get("determine_basal", scope); + + if (obj instanceof Function) { + Function jsFunction = (Function) obj; + + // Call the function with params + + String[] params = { + "undefined", + "undefined", + "undefined", + "undefined", + "undefined", + "undefined", + "setTempBasal"}; + + NativeObject jsResult = (NativeObject) jsFunction.call(rhino, scope, scope, params); + + // Parse the jsResult object to a String + String result = rhino.toString(jsResult); + log.debug("rhino result: + " + result); + } else { + log.debug("hod ned kloppt"); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + Context.exit(); + } } public void init() { + // Profile mProfile = new V8Object(mV8rt); mProfile.add("max_iob", 0);