index.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Vue.js markdown editor example</title>
  6. <link rel="stylesheet" href="css/style.css">
  7. <script src="js/util.js"></script>
  8. <script src="js/moment.js"></script>
  9. <script src="js/vue.js"></script>
  10. <style>
  11. table {
  12. display: inline-table;
  13. width:50%;
  14. }
  15. td {
  16. max-width: 100px;
  17. overflow: hidden;
  18. text-overflow: ellipsis;
  19. white-space: nowrap;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <div id="app">
  25. <textarea v-model="input" cols="80" rows="20"></textarea>
  26. <button v-on:click="send">send</button>
  27. Running: {{ $data.running }}
  28. <table border="1">
  29. <tr v-for="x in cmdq">
  30. <td>{{x.id}}</td>
  31. <td>{{x.cmd}}</td>
  32. <td>{{x.cpeeCallback}}</td>
  33. <td>
  34. </td>
  35. </tr>
  36. </table>
  37. <table border="1">
  38. <tr v-for="x in cData">
  39. <td>{{x.type}}</td>
  40. <td>{{x.ts}}</td>
  41. <td>
  42. <pre>{{JSON.stringify(x.entry, null, 2)}}</pre>
  43. </td>
  44. </tr>
  45. </table>
  46. <ul id="loglist">
  47. <li v-for="(item, index) in log.slice().reverse()">
  48. {{ ts2txt(item.ts) }} - {{ item.entry.message }} -
  49. <pre>{{ JSON.stringify(item.entry) }}</pre>
  50. </li>
  51. </ul>
  52. </div>
  53. <script type="application/javascript">
  54. new Vue({
  55. el: '#app',
  56. data: {
  57. input: '// rde.writeCmd("set_digital_out(2,True)");\n' +
  58. '// rde.writeCmd("movej([-1.95,-1.58,-1.16,-1.15,-1.55,1.25], a=1.0, v=0.1)");\n' +
  59. '//rde.writeCmd("freedrive_mode()");\n' +
  60. 'def asdf():\n' +
  61. ' set_digital_out(3, True) \n' +
  62. ' set_digital_out(4, True) \n' +
  63. 'end',
  64. log: [],
  65. lastID: -1,
  66. doBits: [],
  67. cData: {},
  68. cmdq: []
  69. },
  70. created: function () {
  71. setInterval(this.update, 210);
  72. setInterval(this.updateQ, 220);
  73. setInterval(this.updateCurrent, 230);
  74. },
  75. watch: {
  76. doBits: (newValue, oldValue) => {
  77. let diff1 = newValue.filter(x => !oldValue.includes(x));
  78. let diff2 = oldValue.filter(x => !newValue.includes(x));
  79. for (const x of diff1) {
  80. fetch('/digital/' + x, {method: "POST", body: 'True'})
  81. .then(function (response) {
  82. return response;
  83. });
  84. }
  85. for (const x of diff2) {
  86. fetch('/digital/' + x, {method: "POST", body: 'False'})
  87. .then(function (response) {
  88. return response;
  89. });
  90. }
  91. }
  92. },
  93. methods: {
  94. send: function (event) {
  95. var params = new URLSearchParams();
  96. params.append('script', this.input);
  97. fetch('/cmd', {method: "POST", body: params})
  98. .then(function (response) {
  99. return response;
  100. });
  101. },
  102. ts2txt: function (ts) {
  103. return moment(ts).format('YYYY-MM-DD hh:mm ss.SSS ')
  104. },
  105. handlePackage: function (package) {
  106. Vue.set(this.$data.cData, package.type, package)
  107. switch (package.type) {
  108. case 'Message':
  109. break;
  110. case 'MasterBoardData':
  111. let bits = package.entry.digitalOutputBits;
  112. for (let i = 0; i < 8; i++) {
  113. if (bits & (1 << i)) {
  114. this.$data.doBits.push('' + (i + 1));
  115. }
  116. }
  117. break;
  118. case 'ModeData':
  119. break;
  120. case 'ToolData':
  121. break;
  122. case 'ToolCommInfo':
  123. break;
  124. case 'JointDataList':
  125. break;
  126. case 'CartesianInfo':
  127. break;
  128. case 'ForceModeData':
  129. break;
  130. case 'AdditionalInfo':
  131. break;
  132. case 'KinematicsInfo':
  133. break;
  134. case 'ConfigurationData':
  135. break;
  136. case 'ProgramStateMessage':
  137. break;
  138. case 'ModbusInfoMessage':
  139. break;
  140. case 'RobotMessageError':
  141. break;
  142. default:
  143. console.log('unknown package:' + package.type);
  144. }
  145. },
  146. updateCurrent: function (event) {
  147. fetch('/running', {method: "GET"})
  148. .then(handleErrors)
  149. .then((response) => {
  150. return response.json();
  151. })
  152. .then((myJson) => {
  153. this.$data.running = myJson;
  154. })
  155. .catch(error => {
  156. console.log(error)
  157. })},
  158. updateQ: function (event) {
  159. fetch('/cmdq', {method: "GET"})
  160. .then(handleErrors)
  161. .then((response) => {
  162. return response.json();
  163. })
  164. .then((myJson) => {
  165. this.$data.cmdq = myJson;
  166. })
  167. .catch(error => {
  168. console.log(error)
  169. })},
  170. update: function (event) {
  171. fetch('/log/' + this.lastID, {method: "GET"})
  172. .then(handleErrors)
  173. .then((response) => {
  174. return response.json();
  175. })
  176. .then((myJson) => {
  177. for (const entry of myJson.entries) {
  178. this.handlePackage(entry);
  179. }
  180. this.$data.log = this.$data.log.concat(myJson.entries);
  181. this.$data.lastID = myJson.lastID;
  182. let len = this.$data.log.length;
  183. this.$data.log.splice(0, len - 200);
  184. })
  185. .catch(error => {
  186. this.$data.lastID = 0;
  187. this.$data.log = [];
  188. console.log(error)
  189. });
  190. }
  191. }
  192. })
  193. </script>
  194. </body>
  195. </html>