Status.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. public int istMoment;
  28. public int istPosition;
  29. @Override
  30. public String toString() {
  31. return new StringJoiner("<br>", Status.class.getSimpleName() + "[", "]")
  32. .add("opm=" + opm)
  33. .add("fct=" + fct)
  34. .add("rdyen=" + rdyen)
  35. .add("fault=" + fault)
  36. .add("warn=" + warn)
  37. .add("open=" + open)
  38. .add("enabled=" + enabled)
  39. .add("ref=" + ref)
  40. .add("still=" + still)
  41. .add("dev=" + dev)
  42. .add("mov=" + mov)
  43. .add("teach=" + teach)
  44. .add("mc=" + mc)
  45. .add("ack=" + ack)
  46. .add("halt=" + halt)
  47. .add("func=" + func)
  48. .add("fgrp=" + fgrp)
  49. .add("fnum=" + fnum)
  50. .add("com=" + com)
  51. .add("abs=" + abs)
  52. .add(("istMoment=" + istMoment))
  53. .add(("istPosition" + istPosition))
  54. .toString();
  55. }
  56. public static String byteArrayToHex(byte[] a) {
  57. StringBuilder sb = new StringBuilder(a.length * 2);
  58. for(byte b: a)
  59. sb.append(String.format("%02x", b));
  60. return sb.toString();
  61. }
  62. public void read(byte[] status) {
  63. byte scon=status[0];
  64. opm = (scon & (1 <<7) | scon & (1 <<6));
  65. fct = (scon & (1 << 5))>0;
  66. rdyen = (scon & (1 << 4))>0;
  67. fault = (scon & (1 << 3))>0;
  68. warn = (scon & (1 << 2))>0;
  69. open = (scon & (1 << 1))>0;
  70. enabled = (scon & (1 << 0))>0;
  71. byte spos=status[1];
  72. ref = (spos & (1 << 7)) > 0;
  73. still = (spos & (1 << 6)) > 0;
  74. dev = (spos & (1 << 5)) > 0;
  75. mov = (spos & (1 << 4)) > 0;
  76. teach = (spos & (1 << 3)) > 0;
  77. mc = (spos & (1 << 2)) > 0;
  78. ack = (spos & (1 << 1)) > 0;
  79. halt = (spos & (1 << 0)) > 0;
  80. byte sdir=status[2];
  81. func = (sdir & (1 << 7)) > 0;
  82. fgrp = (sdir >> 5) & 0x3;
  83. fnum = (sdir >> 3) & 0x3;
  84. com = (sdir >> 1) & 0x3;
  85. abs = (sdir & (1 << 0)) > 0;
  86. istMoment = status[3];
  87. istPosition= ((status[4] &0xFF) << 24) | ((status[5] &0xFF) << 16) | ((status[6] &0xFF) << 8) | ((status[7] &0xFF));
  88. }
  89. }