Status.java 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package at.acdp.urweb.fhpp;
  2. import java.util.StringJoiner;
  3. public class Status {
  4. //SCON
  5. public int opm;
  6. public boolean fct;
  7. public boolean rdyen;
  8. public boolean fault;
  9. public boolean warn;
  10. public boolean open;
  11. public boolean enabled;
  12. //SPOS
  13. public boolean ref; /** antrieb referenzieren */
  14. public boolean still; /** stillstandsüberwachung */
  15. public boolean dev; /** schleppfehler */
  16. public boolean mov; /** achse bewegt sich */
  17. public boolean teach; /** Quittung teachen */
  18. public boolean mc; /** motion complete*/
  19. public boolean ack; /** quittung start*/
  20. public boolean halt; /** halt*/
  21. //SDIR
  22. public boolean func; /** funktion wird ausgeführt */
  23. public int fgrp; /** rückmeldung funktionsgruppe */
  24. public int fnum; /** rückmeldung funktionsmodus */
  25. public int com; /** rückmeldung regelmodus */
  26. public boolean abs;
  27. @Override
  28. public String toString() {
  29. return new StringJoiner("<br>", Status.class.getSimpleName() + "[", "]")
  30. .add("opm=" + opm)
  31. .add("fct=" + fct)
  32. .add("rdyen=" + rdyen)
  33. .add("fault=" + fault)
  34. .add("warn=" + warn)
  35. .add("open=" + open)
  36. .add("enabled=" + enabled)
  37. .add("ref=" + ref)
  38. .add("still=" + still)
  39. .add("dev=" + dev)
  40. .add("mov=" + mov)
  41. .add("teach=" + teach)
  42. .add("mc=" + mc)
  43. .add("ack=" + ack)
  44. .add("halt=" + halt)
  45. .add("func=" + func)
  46. .add("fgrp=" + fgrp)
  47. .add("fnum=" + fnum)
  48. .add("com=" + com)
  49. .add("abs=" + abs)
  50. .toString();
  51. }
  52. public static String byteArrayToHex(byte[] a) {
  53. StringBuilder sb = new StringBuilder(a.length * 2);
  54. for(byte b: a)
  55. sb.append(String.format("%02x", b));
  56. return sb.toString();
  57. }
  58. public void read(byte[] status) {
  59. byte scon=status[0];
  60. opm = (scon & (1 <<7) | scon & (1 <<6));
  61. fct = (scon & (1 << 5))>0;
  62. rdyen = (scon & (1 << 4))>0;
  63. fault = (scon & (1 << 3))>0;
  64. warn = (scon & (1 << 2))>0;
  65. open = (scon & (1 << 1))>0;
  66. enabled = (scon & (1 << 0))>0;
  67. byte spos=status[1];
  68. ref = (spos & (1 << 7)) > 0;
  69. still = (spos & (1 << 6)) > 0;
  70. dev = (spos & (1 << 5)) > 0;
  71. mov = (spos & (1 << 4)) > 0;
  72. teach = (spos & (1 << 3)) > 0;
  73. mc = (spos & (1 << 2)) > 0;
  74. ack = (spos & (1 << 1)) > 0;
  75. halt = (spos & (1 << 0)) > 0;
  76. byte sdir=status[2];
  77. func = (sdir & (1 << 7)) > 0;
  78. fgrp = (sdir >> 5) & 0x3;
  79. fnum = (sdir >> 3) & 0x3;
  80. com = (sdir >> 1) & 0x3;
  81. abs = (sdir & (1 << 0)) > 0;
  82. }
  83. }