Status.java 3.2 KB

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