index.html 7.1 KB

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