OSDN Git Service

First GIt master
authortomohiro <tomohiro@yz.yamagata-u.ac.jp>
Tue, 16 Aug 2016 17:06:12 +0000 (02:06 +0900)
committertomohiro <tomohiro@yz.yamagata-u.ac.jp>
Tue, 16 Aug 2016 17:06:12 +0000 (02:06 +0900)
ITOManager4.1/.modules [new file with mode: 0644]
ITOManager4.1/.project [new file with mode: 0644]
ITOManager4.1/application.xml [new file with mode: 0644]
ITOManager4.1/device/AD.js [new file with mode: 0644]
ITOManager4.1/device/AD1.js [new file with mode: 0644]
ITOManager4.1/device/AD2.js [new file with mode: 0644]
ITOManager4.1/device/DIO.js [new file with mode: 0644]
ITOManager4.1/device/LM61BIZ.js [new file with mode: 0644]
ITOManager4.1/src/main.js [new file with mode: 0644]
ITOManager4.1/src/tools.js [new file with mode: 0644]

diff --git a/ITOManager4.1/.modules b/ITOManager4.1/.modules
new file mode 100644 (file)
index 0000000..0df71d8
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<modulepath>
+   <modulepathentry path="src" type="src"></modulepathentry>
+</modulepath>
diff --git a/ITOManager4.1/.project b/ITOManager4.1/.project
new file mode 100644 (file)
index 0000000..073d469
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<projectDescription>\r
+       <name>ITOManager4.1</name>\r
+       <comment></comment>\r
+       <projects>\r
+       </projects>\r
+       <buildSpec>\r
+               <buildCommand>\r
+                       <name>com.marvell.kinoma.kpr.kprBuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+       </buildSpec>\r
+       <natures>\r
+               <nature>com.marvell.kinoma.kpr.application</nature>\r
+       </natures>\r
+</projectDescription>\r
diff --git a/ITOManager4.1/application.xml b/ITOManager4.1/application.xml
new file mode 100644 (file)
index 0000000..631b4bb
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<application xmlns="http://www.kinoma.com/kpr/application/1" id="itomanager4.1" program="src/main" title="ITOManager4.1">
+
+</application>
diff --git a/ITOManager4.1/device/AD.js b/ITOManager4.1/device/AD.js
new file mode 100644 (file)
index 0000000..0480716
--- /dev/null
@@ -0,0 +1,57 @@
+//@module\r
+/*\r
+  Copyright 2011-2014 Marvell Semiconductor, Inc.\r
+\r
+  Licensed under the Apache License, Version 2.0 (the "License");\r
+  you may not use this file except in compliance with the License.\r
+  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+  Unless required by applicable law or agreed to in writing, software\r
+  distributed under the License is distributed on an "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  See the License for the specific language governing permissions and\r
+  limitations under the License.\r
+*/\r
+\r
+exports.pins = {\r
+       dummy: {type: "Analog" },\r
+       AD1: { type: "Analog" },\r
+       AD2: { type: "Analog" }\r
+};\r
+\r
+exports.configure = function() {\r
+       this.dummy.init();\r
+   this.AD1.init();\r
+  this.AD2.init();\r
+   this.supplyVoltage = 3.268;\r
+};\r
+\r
+exports.read = function() {\r
+    return {\r
+    AD1: (this.AD1.read()-1/1024)*this.supplyVoltage,\r
+       AD2: (this.AD2.read()-1/1024)*this.supplyVoltage\r
+      };\r
+};\r
+\r
+exports.close = function() {\r
+       this.dummy.close();\r
+       this.AD1.close();\r
+       this.AD2.close();\r
+};\r
+\r
+exports.metadata = {\r
+       sources: [\r
+               {\r
+                       name: "read",\r
+                       result: \r
+                               { type: "Object", name: "result", properties:\r
+                                       [\r
+                                               { type: "Number", name: "AD1" },\r
+                                               { type: "Number", name: "AD2" },\r
+                                       ]\r
+                               },\r
+               },\r
+       ]\r
+};
\ No newline at end of file
diff --git a/ITOManager4.1/device/AD1.js b/ITOManager4.1/device/AD1.js
new file mode 100644 (file)
index 0000000..f0e01f0
--- /dev/null
@@ -0,0 +1,50 @@
+//@module\r
+/*\r
+  Copyright 2011-2014 Marvell Semiconductor, Inc.\r
+\r
+  Licensed under the Apache License, Version 2.0 (the "License");\r
+  you may not use this file except in compliance with the License.\r
+  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+  Unless required by applicable law or agreed to in writing, software\r
+  distributed under the License is distributed on an "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  See the License for the specific language governing permissions and\r
+  limitations under the License.\r
+*/\r
+\r
+exports.pins = {\r
+       AD1: { type: "Analog" }\r
+};\r
+\r
+exports.configure = function() {\r
+   this.AD1.init();\r
+   this.supplyVoltage = 3.258;\r
+};\r
+\r
+exports.read = function() {\r
+       let value = this.AD1.read()*this.supplyVoltage;\r
+    return {\r
+       AD1: value\r
+      };\r
+};\r
+\r
+exports.close = function() {\r
+       this.AD1.close();\r
+};\r
+\r
+exports.metadata = {\r
+       sources: [\r
+               {\r
+                       name: "read",\r
+                       result: \r
+                               { type: "Object", name: "result", properties:\r
+                                       [\r
+                                               { type: "Number", name: "AD1" },\r
+                                       ]\r
+                               },\r
+               },\r
+       ]\r
+};
\ No newline at end of file
diff --git a/ITOManager4.1/device/AD2.js b/ITOManager4.1/device/AD2.js
new file mode 100644 (file)
index 0000000..3f3994c
--- /dev/null
@@ -0,0 +1,50 @@
+//@module\r
+/*\r
+  Copyright 2011-2014 Marvell Semiconductor, Inc.\r
+\r
+  Licensed under the Apache License, Version 2.0 (the "License");\r
+  you may not use this file except in compliance with the License.\r
+  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+  Unless required by applicable law or agreed to in writing, software\r
+  distributed under the License is distributed on an "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  See the License for the specific language governing permissions and\r
+  limitations under the License.\r
+*/\r
+\r
+exports.pins = {\r
+       AD2: { type: "Analog" }\r
+};\r
+\r
+exports.configure = function() {\r
+  this.AD2.init();\r
+   this.supplyVoltage = 3.258;\r
+};\r
+\r
+exports.read = function() {\r
+       let value = this.AD2.read()*this.supplyVoltage;\r
+    return {\r
+       AD2: value\r
+      };\r
+};\r
+\r
+exports.close = function() {\r
+       this.AD2.close();\r
+};\r
+\r
+exports.metadata = {\r
+       sources: [\r
+               {\r
+                       name: "read",\r
+                       result: \r
+                               { type: "Object", name: "result", properties:\r
+                                       [\r
+                                               { type: "Number", name: "AD2" },\r
+                                       ]\r
+                               },\r
+               },\r
+       ]\r
+};
\ No newline at end of file
diff --git a/ITOManager4.1/device/DIO.js b/ITOManager4.1/device/DIO.js
new file mode 100644 (file)
index 0000000..8c4ed4f
--- /dev/null
@@ -0,0 +1,47 @@
+//@module\r
+/*\r
+  Copyright 2011-2014 Marvell Semiconductor, Inc.\r
+\r
+  Licensed under the Apache License, Version 2.0 (the "License");\r
+  you may not use this file except in compliance with the License.\r
+  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+  Unless required by applicable law or agreed to in writing, software\r
+  distributed under the License is distributed on an "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  See the License for the specific language governing permissions and\r
+  limitations under the License.\r
+*/\r
+\r
+exports.pins = {\r
+    DIO1: {type: "Digital", direction: "output"},\r
+    DIO2: {type: "Digital", direction: "output"}\r
+};\r
+\r
+exports.configure = function() {\r
+    this.DIO1.init();\r
+    this.DIO2.init();\r
+}\r
+\r
+exports.turnOn1 = function() {\r
+    this.DIO1.write(1 );\r
+}\r
+\r
+exports.turnOn2 = function() {\r
+    this.DIO2.write( 1 );\r
+}\r
+               \r
+exports.turnOff1 = function() {\r
+    this.DIO1.write( 0 );\r
+}\r
+\r
+exports.turnOff2 = function() {\r
+    this.DIO2.write( 0 );\r
+}\r
+\r
+exports.close = function() {\r
+       this.DIO1.close();\r
+       this.DIO2.close();\r
+}
\ No newline at end of file
diff --git a/ITOManager4.1/device/LM61BIZ.js b/ITOManager4.1/device/LM61BIZ.js
new file mode 100644 (file)
index 0000000..452b903
--- /dev/null
@@ -0,0 +1,52 @@
+//@module\r
+/*\r
+  Copyright 2011-2014 Marvell Semiconductor, Inc.\r
+\r
+  Licensed under the Apache License, Version 2.0 (the "License");\r
+  you may not use this file except in compliance with the License.\r
+  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+  Unless required by applicable law or agreed to in writing, software\r
+  distributed under the License is distributed on an "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  See the License for the specific language governing permissions and\r
+  limitations under the License.\r
+*/\r
+// This javascript source code is converted to the temperature from the AD input for the LM61BIZ.\r
+\r
+exports.pins = {\r
+       temperature1: { type: "Analog" }\r
+};\r
+\r
+exports.configure = function() {\r
+   this.temperature1.init();\r
+   this.supplyVoltage=3.258;\r
+};\r
+\r
+exports.read = function() { \r
+    let AD =  this.temperature1.read()*this.supplyVoltage;\r
+    let temp = (AD*1000-600)/10;\r
+    return {\r
+               temperature1: temp,\r
+      };\r
+};\r
+\r
+exports.close = function() {\r
+       this.temperature1.close();\r
+};\r
+\r
+exports.metadata = {\r
+       sources: [\r
+               {\r
+                       name: "read",\r
+                       result: \r
+                               { type: "Object", name: "result", properties:\r
+                                       [\r
+                                               { type: "Number", name: "temperature1" },\r
+                                       ]\r
+                               },\r
+               },\r
+       ]\r
+};
\ No newline at end of file
diff --git a/ITOManager4.1/src/main.js b/ITOManager4.1/src/main.js
new file mode 100644 (file)
index 0000000..01bf868
--- /dev/null
@@ -0,0 +1,388 @@
+let Pins = require("pins");\r
+const bdebug = false;\r
+\r
+var temp=0;\r
+var counter=0;\r
+var AD1=0;\r
+var AD2=0;\r
+var tAD1=0;\r
+var tAD2=0;\r
+var ttemp = 0;\r
+var cADC1=0;\r
+var cADC2=0;\r
+var ctemp=0;\r
+var bCompletedAD1 = 0;\r
+var bCompletedAD2 = 0;\r
+var bCompletedTemp = 0;\r
+var nEventID =0;\r
+var DIO1=0;\r
+var DIO2=0;\r
+var szCommand = "";\r
+var nADChannel = 1;\r
+const deviceID = K4.deviceID;\r
+\r
+const nAnalogMeasureInterval = 30; //ms\r
+const nDataUploadInterval=30000; //ms\r
+const nGetCommandInterval=1000; //ms\r
+const nDisplayInterval=1000; //ms\r
+const nAccumAD1=4;\r
+const nAccumAD2=4;\r
+const nAccumTemp=4;\r
+//const protomode = "MieSAN";\r
+//const xAD1Gain = 1.99162; //-\r
+//const protomode = "Basis";\r
+//const xAD1Gain = 1.000;\r
+const protomode = "RiceDryer";\r
+const xAD1Gain = 1.000;\r
+const szVer = "4.1b3";\r
+const xErrorVoltageMax = 3.2; //V\r
+const xErrorVoltageMin = 0.0; //V\r
+const xErrorTempMax = 100;//C\r
+const xErrorTempMin = -35;//C\r
+\r
+log("DeiveID: " +deviceID +"\n");\r
+\r
+let whiteSkin = new Skin({ fill:"white" });\r
+let normalText = new Style( { font: "30px", color:"black" } );\r
+let smallText = new Style( { font: "20px", color:"black" } ); \r
+let label0 = new Label({ left:0, right:0, top:-90, bottom:0, string:"ITO Manager Ver. " + szVer, style: normalText });\r
+let labelpin = new Label({ left:0, right:0, top:-50, bottom:0, string:"AD1:52, AD2:51, Vout(LM61BIZ):54 GND:58", style: smallText });\r
+let label1 = new Label({ left:0, right:0, top:-26, bottom:0, string:"---", style: smallText });\r
+let label2 = new Label({ left:0, right:0, top:0, bottom:0, string:"---", style: smallText });\r
+let label3 = new Label({ left:0, right:0, top:24, bottom:0, string:"---", style: smallText });\r
+let labelDevID = new Label({ left:0, right:0, top:90, bottom:0, string:"DeviceID: " + deviceID , style: smallText });\r
+let labelControlMode = new Label({ left:0, right:0, top:120, bottom:0, string:"ControlMode: " + protomode , style: smallText });\r
+let mainCon = new Container({ \r
+    left:0, right:0, top:0, bottom:0, skin: whiteSkin\r
+});\r
+mainCon.add(label0);\r
+mainCon.add(labelpin);\r
+mainCon.add(label1);\r
+mainCon.add(label2);\r
+mainCon.add(label3);\r
+mainCon.add(labelDevID);\r
+mainCon.add(labelControlMode);\r
+application.add(mainCon);\r
+\r
+// analogpins 37 -> 52, 38->51, 39->54\r
+Pins.invoke("setPinMux", {\r
+    leftVoltage: 3.3, rightVoltage: 3.3,\r
+    leftPins: [3, 3, 0, 3, 0, 0, 0, 2],\r
+    rightPins: [0, 0, 0, 0, 0, 0, 0, 0]\r
+});\r
+\r
+\r
+                               Pins.configure({\r
+                                               analogSensor1: {\r
+                                               require: "AD1",\r
+                                               pins: {\r
+                                                       AD1: { pin: 52 }\r
+                                       }\r
+                                       },\r
+                                       analogSensor2: {\r
+                                               require: "AD2",\r
+                                               pins: {\r
+                                                       AD2: { pin: 51 }\r
+                                       }\r
+                                       },\r
+                                       analogTemp: {\r
+                                               require: "LM61BIZ",\r
+                                               pins: {\r
+                                                       temperature1: { pin: 54 }\r
+                                       }\r
+                               },\r
+                       DIO: {\r
+                                       require: "DIO",\r
+                                       pins: {\r
+                                               DIO1: { pin: 4 },\r
+                                               DIO2: { pin: 6 }\r
+                                       }\r
+                       },\r
+                               ground: {\r
+                                       pin: 58, type: "Ground"\r
+                                       }\r
+                                       }\r
+                                       , function(success) {\r
+                                                if (success){\r
+                                                log("Successed to Pin configure\n");\r
+                                               //Pins.repeat("/analogTemp/read", 50, value => TemperatureValueChanged(value));\r
+                                               //Pins.repeat("/analogSensor1/read", 3, value => Analog1ValueChanged(value));\r
+                                               //Pins.repeat("/analogSensor2/read", 3, value => Analog2ValueChanged(value));\r
+                                               //Pins.share("ws", {zeroconf: true, name: "analog-temperature"});\r
+                                               application.invoke(new Message("/AnalogMeasureTimer"));\r
+                                                }else{\r
+                                                \r
+                                                 log("Failed to configure\n");\r
+                                                 }\r
+                                       }\r
+                               );\r
+\r
+        application.invoke(new Message("/UploadTimer"));\r
+        application.invoke(new Message("/GetCommandTimer"));\r
+        application.invoke(new Message("/DisplayTimer"));\r
+\r
+\r
+//--sub routine --                             \r
+function log(messsage) {\r
+if (bdebug==true){\r
+   trace(messsage);\r
+       }\r
+};\r
+\r
+function sleep(time) {\r
+                let d1 = new Date().getTime();\r
+                let d2 = new Date().getTime();\r
+                        while (d2 < d1 + time) {\r
+                                 d2 = new Date().getTime();\r
+                                }\r
+                                 return;\r
+};\r
+       \r
+function TemperatureValueChanged(value){\r
+               let xtemp1 = value.temperature1;\r
+               if (xtemp1 < xErrorTempMax && xtemp1 > xErrorTempMin) {\r
+                       ttemp = (ttemp * ctemp + xtemp1)/(ctemp+1);\r
+                       ctemp=ctemp+1;\r
+               }\r
+               if (ctemp==nAccumTemp){\r
+                       temp= ttemp;\r
+                       ctemp =0;\r
+                       log("temperature:"+temp.toFixed(3) + ' C AD1:'+AD1.toFixed(3)+'V AD2:'+AD2.toFixed(3)+'V\n');\r
+                       if ( bCompletedTemp==0){\r
+                               bCompletedTemp = 1;\r
+                               application.invoke(new Message("/KinomaDataUpload"));\r
+                        }\r
+               }                                       \r
+}\r
+\r
+function Analog1ValueChanged(value){\r
+       let voltage = value.AD1;\r
+       if (voltage <= xErrorVoltageMax && voltage >= xErrorVoltageMin) {\r
+               tAD1 = (tAD1 * cADC1 +voltage/xAD1Gain)/(cADC1+1);\r
+               cADC1 = cADC1+1;\r
+       }\r
+       if (cADC1==nAccumAD1){\r
+               AD1= tAD1;\r
+               cADC1 = 0;\r
+               if ( bCompletedAD1==0){\r
+                       bCompletedAD1 = 1;\r
+                       application.invoke(new Message("/KinomaDataUpload"));\r
+        }\r
+       }\r
+//     log("AD1:"+AD1.toFixed(3) + 'V AD2:'+AD2.toFixed(3) +'\n');\r
+}\r
+function Analog2ValueChanged(value){\r
+       let voltage = value.AD2;\r
+       if (voltage <= xErrorVoltageMax && voltage >= xErrorVoltageMin) {\r
+               tAD2 = (tAD2 * cADC2 +voltage)/(cADC2+1);\r
+               cADC2 = cADC2+1;\r
+       }\r
+       if (cADC2==nAccumAD2){\r
+               AD2= tAD2;\r
+               cADC2 = 0;\r
+               if ( bCompletedAD2==0){\r
+                       bCompletedAD2 = 1;\r
+                       application.invoke(new Message("/KinomaDataUpload"));\r
+               }\r
+       }\r
+//     log('AD2:'+AD2.toFixed(3) +'\n');\r
+}\r
+\r
+//--handler--\r
+Handler.bind("/AnalogMeasureTimer", {\r
+    onInvoke: function(handler, message){\r
+    log("TimeAnalog \n");\r
+    if (nADChannel==1){\r
+               Pins.invoke("/analogTemp/read", value => TemperatureValueChanged(value));\r
+               \r
+               Pins.invoke("setPinMux", {\r
+                leftVoltage: 3.3, rightVoltage: 3.3,\r
+                 leftPins: [3, 0, 0, 0, 0, 0, 0, 2],\r
+                 rightPins: [0, 0, 0, 0, 0, 0, 0, 0]\r
+               });\r
+       }\r
+       if (nADChannel==2){\r
+               Pins.invoke("/analogSensor1/read", value => Analog1ValueChanged(value));\r
+               \r
+               Pins.invoke("setPinMux", {\r
+                leftVoltage: 3.3, rightVoltage: 3.3,\r
+                 leftPins: [0, 0, 0, 3, 0, 0, 0, 2],\r
+                 rightPins: [0, 0, 0, 0, 0, 0, 0, 0]\r
+               });\r
+       }\r
+       if (nADChannel==3){\r
+                Pins.invoke("/analogSensor2/read", value => Analog2ValueChanged(value));\r
+                \r
+                Pins.invoke("setPinMux", {\r
+                leftVoltage: 3.3, rightVoltage: 3.3,\r
+                 leftPins: [0, 3, 0, 0, 0, 0, 0, 2],\r
+                 rightPins: [0, 0, 0, 0, 0, 0, 0, 0]\r
+               });\r
+       }\r
+        nADChannel = nADChannel +1;\r
+     if (nADChannel > 3){\r
+       nADChannel = 1;\r
+     } \r
+     counter=counter+1;\r
+   handler.invoke( new Message("/delayAnalog?duration=" +nAnalogMeasureInterval ));\r
+    },\r
+    onComplete: function(handler, message){\r
+     log("Time2 \n");\r
+     //    handler.invoke( new Message("/delay?duration=" +nDataUploadInterval ));\r
+    }\r
+});\r
+\r
+Handler.bind("/delayAnalog", {\r
+    onInvoke: function(handler, message){\r
+       let query = parseQuery( message.query );\r
+               let duration = query.duration;\r
+        handler.wait(duration); \r
+    },\r
+    onComplete: function(handler, message){\r
+        handler.invoke(new Message("/AnalogMeasureTimer"));\r
+    }\r
+});\r
+\r
+\r
+\r
+Handler.bind("/UploadTimer", {\r
+    onInvoke: function(handler, message){\r
+    handler.invoke(new Message("/KinomaDataUpload"));\r
+     log("Time \n");\r
+   handler.invoke( new Message("/delay?duration=" +nDataUploadInterval ));\r
+    },\r
+    onComplete: function(handler, message){\r
+     log("Time2 \n");   \r
+     //    handler.invoke( new Message("/delay?duration=" +nDataUploadInterval ));\r
+    }\r
+});\r
+\r
+Handler.bind("/delay", {\r
+    onInvoke: function(handler, message){\r
+       let query = parseQuery( message.query );\r
+               let duration = query.duration;\r
+        handler.wait(duration); //will call onComplete after 10 seconds\r
+    },\r
+    onComplete: function(handler, message){\r
+        handler.invoke(new Message("/UploadTimer"));\r
+    }\r
+});\r
+\r
+Handler.bind("/GetCommandTimer", {\r
+    onInvoke: function(handler, message){\r
+    handler.invoke(new Message("/KinomaGetCommand"));\r
+     log("GetCommandTimer\n");\r
+   handler.invoke( new Message("/delayCommand?duration=" +nGetCommandInterval ));\r
+    },\r
+    onComplete: function(handler, message){\r
+     log("GetCommandTimer2 \n");   \r
+     //    handler.invoke( new Message("/delay?duration=" +nDataUploadInterval ));\r
+    }\r
+});\r
+\r
+Handler.bind("/delayCommand", {\r
+    onInvoke: function(handler, message){\r
+       let query = parseQuery( message.query );\r
+               let duration = query.duration;\r
+        handler.wait(duration); \r
+    },\r
+    onComplete: function(handler, message){\r
+        handler.invoke(new Message("/GetCommandTimer"));\r
+    }\r
+});\r
+\r
+Handler.bind("/DisplayTimer", {\r
+    onInvoke: function(handler, message){\r
+    label1.string = "Temperature:"+temp.toFixed(1) + ' C AD1:'+AD1.toFixed(3)+' V AD2:'+AD2.toFixed(3)+' V';\r
+     label2.string = "Counter:"+counter;\r
+     label3.string = "DIO1: " + DIO1 + "  DIO2: " + DIO2;\r
+    handler.invoke( new Message("/delayDisplay?duration=" +nDisplayInterval ));\r
+    log("TImeD\n");\r
+    },\r
+    onComplete: function(handler, message){\r
+     log("TimeD2 \n");   \r
+     //     handler.invoke( new Message("/delayCommand?duration=" +nDisplayInterval ));\r
+    }\r
+});\r
+\r
+Handler.bind("/delayDisplay", {\r
+    onInvoke: function(handler, message){\r
+       let query = parseQuery( message.query );\r
+               let duration = query.duration;\r
+        handler.wait(duration); //will call onComplete after 10 seconds\r
+    },\r
+    onComplete: function(handler, message){\r
+        handler.invoke(new Message("/DisplayTimer"));\r
+    }\r
+});\r
+\r
+\r
+Handler.bind("/KinomaDataUpload", {\r
+                       onInvoke: function(handler, message){\r
+                       if (bCompletedAD1 == 1 && bCompletedAD2 == 1 && bCompletedTemp == 1){\r
+                               var uri = "http://a.yamagata-u.ac.jp/amenity/network/M2M/KinomaDataReciever.aspx?DeviceID="+deviceID;\r
+                               uri = uri + "&AI1=" + AD1;\r
+                               uri = uri + "&AI2=" + AD2;\r
+                               uri = uri + "&AI3=" + temp;\r
+                               uri = uri + "&pm=" + protomode;\r
+                               uri = uri + "&EventID=" + nEventID;\r
+                               handler.invoke( new Message( uri ), Message.TEXT );\r
+                               log("uri:" + uri +"\n");\r
+                               }\r
+                       },      \r
+                       onComplete: function(handler, message){\r
+                       //szCommand = data\r
+                               //application.distribute( "onLabelDisplayCom", "Command: " + message.status + "," + szCommand);\r
+                       log("Http:" +  message.status +"\n");\r
+                       },      \r
+                       onError: function(handler, message){\r
+                               let result = { success: false, items: [] };\r
+                               log("Http error:" +  result +"\n");\r
+                               //application.distribute( "onLabelDisplayCom", "Command: " + result);\r
+                       }       \r
+       }\r
+);\r
+       \r
+Handler.bind("/KinomaGetCommand", {\r
+                       onInvoke: function(handler, message){\r
+                               var uri = "http://a.yamagata-u.ac.jp/amenity/network/M2M/KinomaControlRequest.aspx?DeviceID="+deviceID;\r
+                               handler.invoke( new Message( uri ), Message.TEXT );\r
+                       },      \r
+                       onComplete: function(handler, message,data){\r
+                       szCommand = data\r
+\r
+                               //command analysis\r
+                               if (szCommand.match(/on1/)){\r
+                                       application.invoke(new Message("/KinomaDataUpload"));\r
+                                       DIO1=1;\r
+                                       application.invoke(new MessageWithObject("pins:/DIO/turnOn1"));\r
+                                       sleep( 50 );\r
+                                       application.invoke(new Message("/KinomaDataUpload"));\r
+                                  }\r
+                                  if(szCommand.match(/off1/)) {\r
+                                       application.invoke(new Message("/KinomaDataUpload"));\r
+                                       DIO1=0;\r
+                                       application.invoke(new MessageWithObject("pins:/DIO/turnOff1"));\r
+                                       sleep( 50 );\r
+                                       application.invoke(new Message("/KinomaDataUpload"));\r
+                                       }\r
+                                  if(szCommand.match(/on2/)){\r
+                                       DIO2=1;\r
+                                       application.invoke(new MessageWithObject("pins:/DIO/turnOn2"));\r
+                                  }\r
+                                  if(szCommand.match(/off2/)) {\r
+                                       DIO2=0;\r
+                                       application.invoke(new MessageWithObject("pins:/DIO/turnOff2"));\r
+                                       }        \r
+                                log("DO1(4): "+DIO1+"\n");\r
+                log("DO2(6): "+DIO2+"\n");\r
+                       log("Http-GetCommand: " + message.status + "," + szCommand +"\n");\r
+                       },      \r
+                       onError: function(handler, message){\r
+                               let result = { success: false, items: [] };\r
+                               log("Http error:" +  result +"\n");\r
+                               //application.distribute( "onLabelDisplayCom", "Command: " + result);\r
+                       }       \r
+       }\r
+);\r
+       \r
diff --git a/ITOManager4.1/src/tools.js b/ITOManager4.1/src/tools.js
new file mode 100644 (file)
index 0000000..e69de29