IeAbstractQuality.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package wei.yigulu.iec104.asdudataframe.qualitydescription;
  2. import io.netty.buffer.ByteBuf;
  3. import lombok.AllArgsConstructor;
  4. import lombok.Data;
  5. import lombok.NoArgsConstructor;
  6. import wei.yigulu.iec104.exception.Iec104Exception;
  7. /**
  8. * 品质描述 的抽象类
  9. *
  10. * @author 修唯xiuwei
  11. * @version 3.0
  12. */
  13. @Data
  14. @AllArgsConstructor
  15. @NoArgsConstructor
  16. public class IeAbstractQuality {
  17. public static final int OCCUPYBYTES=1;
  18. /**
  19. * 品质的值
  20. */
  21. protected int value;
  22. /**
  23. * 封锁标志 0-未被封锁;1被封锁·
  24. */
  25. protected boolean blocked;
  26. /**
  27. * 取代标识 0-未被取代;1被取代
  28. */
  29. protected boolean substituted;
  30. /**
  31. * 当前值标志 0当前值;1非当前值
  32. */
  33. protected boolean notTopical;
  34. /**
  35. * 有效标志 0有效;1无效
  36. */
  37. protected boolean invalid;
  38. /**
  39. * Ie abstract quality
  40. *
  41. * @param is is
  42. */
  43. public IeAbstractQuality(ByteBuf is) throws Iec104Exception {
  44. if(is.readableBytes()<OCCUPYBYTES){
  45. throw new Iec104Exception(3301,"可用字节不足,不能进行读取");
  46. }
  47. this.value = (is.readByte() & 0xff);
  48. this.blocked = (value & 0x10) == 0x10;
  49. this.substituted = (value & 0x20) == 0x20;
  50. this.notTopical = (value & 0x40) == 0x40;
  51. this.invalid = (value & 0x80) == 0x80;
  52. }
  53. /**
  54. * 描述品质位 为1位
  55. *
  56. * @return int
  57. */
  58. public int encode() {
  59. int v = 0x00;
  60. if (blocked) {
  61. v |= 0x10;
  62. }
  63. if (substituted) {
  64. v |= 0x20;
  65. }
  66. if (notTopical) {
  67. v |= 0x40;
  68. }
  69. if (invalid) {
  70. v |= 0x80;
  71. }
  72. return v;
  73. }
  74. /**
  75. * 是否是良好值
  76. *
  77. * @return boolean
  78. */
  79. public boolean isGoodValue(){
  80. return !this.isBlocked()&&!isInvalid()&&!isSubstituted()&&!isNotTopical();
  81. }
  82. @Override
  83. public String toString() {
  84. return "被封锁: " + isBlocked() + ", 被取代: " + isSubstituted() + ", 非当前值: " + isNotTopical()
  85. + ", 无效: " + isInvalid();
  86. }
  87. }