MQTTpublishPacket.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.packets;
  2. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
  3. /**
  4. * MQTT Publish Packet
  5. *
  6. *
  7. * @author Andreas T. Meyer-Berg
  8. */
  9. public class MQTTpublishPacket extends MQTT_packet {
  10. /**
  11. * Topic of the Publish Packet
  12. */
  13. private String topic = "";
  14. /**
  15. * Value of the packet
  16. */
  17. private float value = 0;
  18. private float sensorValue = 0;
  19. private boolean valueBool = false;
  20. private boolean sensorBool = false;
  21. /**
  22. * True if boolean
  23. */
  24. private boolean isBoolean = false;
  25. /**
  26. * MQTT Publish Packet
  27. * @param timestamp time it is send
  28. * @param source source port
  29. * @param destination destination port
  30. * @param topic topic of the message
  31. * @param value value of the message
  32. */
  33. public MQTTpublishPacket(long timestamp, Port source, Port destination, String topic, float value, float sensorValue) {
  34. super(MQTT_packet.PUBLISH, timestamp, source, destination);
  35. this.setTopic(topic);
  36. this.setValue(value);
  37. this.sensorValue = sensorValue;
  38. setBoolean(false);
  39. this.message = topic + ":"+ value;
  40. }
  41. /**
  42. * MQTT Publish Packet
  43. * @param timestamp time it is send
  44. * @param source source port
  45. * @param destination destination port
  46. * @param topic topic of the message
  47. * @param value value of the message
  48. */
  49. public MQTTpublishPacket(long timestamp, Port source, Port destination, String topic, boolean value, boolean sensorValue) {
  50. super(MQTT_packet.PUBLISH, timestamp, source, destination);
  51. this.setTopic(topic);
  52. this.setValue(value ? 1 : 0);
  53. setBoolean(true);
  54. this.setValueBool(value);
  55. this.setSensorBool(value);
  56. this.sensorValue = sensorValue ? 1 : 0;
  57. this.message = "Topic:"+topic + ":"+ value;
  58. }
  59. public boolean isBoolean() {
  60. return isBoolean;
  61. }
  62. public void setBoolean(boolean isBoolean) {
  63. this.isBoolean = isBoolean;
  64. }
  65. public float getValue() {
  66. return value;
  67. }
  68. public void setValue(float value) {
  69. this.value = value;
  70. }
  71. public String getTopic() {
  72. return topic;
  73. }
  74. public void setTopic(String topic) {
  75. this.topic = topic;
  76. }
  77. public float getSensorValue() {
  78. return sensorValue;
  79. }
  80. public void setSensorValue(float sensorValue) {
  81. this.sensorValue = sensorValue;
  82. }
  83. /**
  84. * @return the valueBool
  85. */
  86. public boolean isValueBool() {
  87. return valueBool;
  88. }
  89. /**
  90. * @param valueBool the valueBool to set
  91. */
  92. public void setValueBool(boolean valueBool) {
  93. this.valueBool = valueBool;
  94. }
  95. /**
  96. * @return the sensorBool
  97. */
  98. public boolean isSensorBool() {
  99. return sensorBool;
  100. }
  101. /**
  102. * @param sensorBool the sensorBool to set
  103. */
  104. public void setSensorBool(boolean sensorBool) {
  105. this.sensorBool = sensorBool;
  106. }
  107. }