12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package at.acdp.urweb.fhpp;
- import java.util.StringJoiner;
- public class Status {
- //SCON
- public int opm;
- public boolean fct;
- public boolean rdyen;
- public boolean fault;
- public boolean warn;
- public boolean open;
- public boolean enabled;
- //SPOS
- public boolean ref; /** antrieb referenzieren */
- public boolean still; /** stillstandsüberwachung */
- public boolean dev; /** schleppfehler */
- public boolean mov; /** achse bewegt sich */
- public boolean teach; /** Quittung teachen */
- public boolean mc; /** motion complete*/
- public boolean ack; /** quittung start*/
- public boolean halt; /** halt*/
- //SDIR
- public boolean func; /** funktion wird ausgeführt */
- public int fgrp; /** rückmeldung funktionsgruppe */
- public int fnum; /** rückmeldung funktionsmodus */
- public int com; /** rückmeldung regelmodus */
- public boolean abs;
- @Override
- public String toString() {
- return new StringJoiner("<br>", Status.class.getSimpleName() + "[", "]")
- .add("opm=" + opm)
- .add("fct=" + fct)
- .add("rdyen=" + rdyen)
- .add("fault=" + fault)
- .add("warn=" + warn)
- .add("open=" + open)
- .add("enabled=" + enabled)
- .add("ref=" + ref)
- .add("still=" + still)
- .add("dev=" + dev)
- .add("mov=" + mov)
- .add("teach=" + teach)
- .add("mc=" + mc)
- .add("ack=" + ack)
- .add("halt=" + halt)
- .add("func=" + func)
- .add("fgrp=" + fgrp)
- .add("fnum=" + fnum)
- .add("com=" + com)
- .add("abs=" + abs)
- .toString();
- }
- public static String byteArrayToHex(byte[] a) {
- StringBuilder sb = new StringBuilder(a.length * 2);
- for(byte b: a)
- sb.append(String.format("%02x", b));
- return sb.toString();
- }
- public void read(byte[] status) {
- byte scon=status[0];
- opm = (scon & (1 <<7) | scon & (1 <<6));
- fct = (scon & (1 << 5))>0;
- rdyen = (scon & (1 << 4))>0;
- fault = (scon & (1 << 3))>0;
- warn = (scon & (1 << 2))>0;
- open = (scon & (1 << 1))>0;
- enabled = (scon & (1 << 0))>0;
- byte spos=status[1];
- ref = (spos & (1 << 7)) > 0;
- still = (spos & (1 << 6)) > 0;
- dev = (spos & (1 << 5)) > 0;
- mov = (spos & (1 << 4)) > 0;
- teach = (spos & (1 << 3)) > 0;
- mc = (spos & (1 << 2)) > 0;
- ack = (spos & (1 << 1)) > 0;
- halt = (spos & (1 << 0)) > 0;
- byte sdir=status[2];
- func = (sdir & (1 << 7)) > 0;
- fgrp = (sdir >> 5) & 0x3;
- fnum = (sdir >> 3) & 0x3;
- com = (sdir >> 1) & 0x3;
- abs = (sdir & (1 << 0)) > 0;
- }
- }
|