index.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. <table border="1">
  28. <tr v-for="x in cmdq">
  29. <td>{{x.id}}</td>
  30. <td>{{x.cmd}}</td>
  31. <td>{{x.cpeeCallback}}</td>
  32. <td>
  33. </td>
  34. </tr>
  35. </table>
  36. <table border="1">
  37. <tr v-for="x in cData">
  38. <td>{{x.type}}</td>
  39. <td>{{x.ts}}</td>
  40. <td>
  41. <pre>{{JSON.stringify(x.entry, null, 2)}}</pre>
  42. </td>
  43. </tr>
  44. </table>
  45. <ul id="loglist">
  46. <li v-for="(item, index) in log.slice().reverse()">
  47. {{ ts2txt(item.ts) }} - {{ item.entry.message }} -
  48. <pre>{{ JSON.stringify(item.entry) }}</pre>
  49. </li>
  50. </ul>
  51. </div>
  52. <script type="application/javascript">
  53. new Vue({
  54. el: '#app',
  55. data: {
  56. input: '// rde.writeCmd("set_digital_out(2,True)");\n' +
  57. '// rde.writeCmd("movej([-1.95,-1.58,-1.16,-1.15,-1.55,1.25], a=1.0, v=0.1)");\n' +
  58. '//rde.writeCmd("freedrive_mode()");\n' +
  59. 'def asdf():\n' +
  60. ' set_digital_out(3, True) \n' +
  61. ' set_digital_out(4, True) \n' +
  62. 'end',
  63. log: [],
  64. lastID: -1,
  65. doBits: [],
  66. cData: {},
  67. cmdq: []
  68. },
  69. created: function () {
  70. setInterval(this.update, 200);
  71. setInterval(this.updateQ, 250);
  72. },
  73. watch: {
  74. doBits: (newValue, oldValue) => {
  75. let diff1 = newValue.filter(x => !oldValue.includes(x));
  76. let diff2 = oldValue.filter(x => !newValue.includes(x));
  77. for (const x of diff1) {
  78. fetch('/digital/' + x, {method: "POST", body: 'True'})
  79. .then(function (response) {
  80. return response;
  81. });
  82. }
  83. for (const x of diff2) {
  84. fetch('/digital/' + x, {method: "POST", body: 'False'})
  85. .then(function (response) {
  86. return response;
  87. });
  88. }
  89. }
  90. },
  91. methods: {
  92. send: function (event) {
  93. var params = new URLSearchParams();
  94. params.append('script', this.input);
  95. fetch('/cmd', {method: "POST", body: params})
  96. .then(function (response) {
  97. return response;
  98. });
  99. },
  100. ts2txt: function (ts) {
  101. return moment(ts).format('YYYY-MM-DD hh:mm ss.SSS ')
  102. },
  103. handlePackage: function (package) {
  104. Vue.set(this.$data.cData, package.type, package)
  105. switch (package.type) {
  106. case 'Message':
  107. break;
  108. case 'MasterBoardData':
  109. let bits = package.entry.digitalOutputBits;
  110. for (let i = 0; i < 8; i++) {
  111. if (bits & (1 << i)) {
  112. this.$data.doBits.push('' + (i + 1));
  113. }
  114. }
  115. break;
  116. case 'ModeData':
  117. break;
  118. case 'ToolData':
  119. break;
  120. case 'ToolCommInfo':
  121. break;
  122. case 'JointDataList':
  123. break;
  124. case 'CartesianInfo':
  125. break;
  126. case 'ForceModeData':
  127. break;
  128. case 'AdditionalInfo':
  129. break;
  130. case 'KinematicsInfo':
  131. break;
  132. case 'ConfigurationData':
  133. break;
  134. case 'ProgramStateMessage':
  135. break;
  136. case 'ModbusInfoMessage':
  137. break;
  138. case 'RobotMessageError':
  139. break;
  140. default:
  141. console.log('unknown package:' + package.type);
  142. }
  143. },
  144. updateQ: function (event) {
  145. fetch('/cmdq', {method: "GET"})
  146. .then(handleErrors)
  147. .then((response) => {
  148. return response.json();
  149. })
  150. .then((myJson) => {
  151. this.$data.cmdq = myJson;
  152. })
  153. .catch(error => {
  154. console.log(error)
  155. })},
  156. update: function (event) {
  157. fetch('/log/' + this.lastID, {method: "GET"})
  158. .then(handleErrors)
  159. .then((response) => {
  160. return response.json();
  161. })
  162. .then((myJson) => {
  163. for (const entry of myJson.entries) {
  164. this.handlePackage(entry);
  165. }
  166. this.$data.log = this.$data.log.concat(myJson.entries);
  167. this.$data.lastID = myJson.lastID;
  168. let len = this.$data.log.length;
  169. this.$data.log.splice(0, len - 200);
  170. })
  171. .catch(error => {
  172. this.$data.lastID = 0;
  173. this.$data.log = [];
  174. console.log(error)
  175. });
  176. }
  177. }
  178. })
  179. </script>
  180. </body>
  181. </html>