MQTTpublishPacket.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /**
  19. * True if boolean
  20. */
  21. private boolean isBoolean = false;
  22. /**
  23. * MQTT Publish Packet
  24. * @param timestamp time it is send
  25. * @param source source port
  26. * @param destination destination port
  27. * @param topic topic of the message
  28. * @param value value of the message
  29. */
  30. public MQTTpublishPacket(long timestamp, Port source, Port destination, String topic, float value) {
  31. super(MQTT_packet.PUBLISH, timestamp, source, destination);
  32. this.setTopic(topic);
  33. this.setValue(value);
  34. setBoolean(false);
  35. this.message = topic + ":"+ value;
  36. }
  37. /**
  38. * MQTT Publish Packet
  39. * @param timestamp time it is send
  40. * @param source source port
  41. * @param destination destination port
  42. * @param topic topic of the message
  43. * @param value value of the message
  44. */
  45. public MQTTpublishPacket(long timestamp, Port source, Port destination, String topic, boolean value) {
  46. super(MQTT_packet.PUBLISH, timestamp, source, destination);
  47. this.setTopic(topic);
  48. this.setValue(value ? 1 : 0);
  49. setBoolean(true);
  50. this.message = "Topic:"+topic + ":"+ value;
  51. }
  52. public boolean isBoolean() {
  53. return isBoolean;
  54. }
  55. public void setBoolean(boolean isBoolean) {
  56. this.isBoolean = isBoolean;
  57. }
  58. public float getValue() {
  59. return value;
  60. }
  61. public void setValue(float value) {
  62. this.value = value;
  63. }
  64. public String getTopic() {
  65. return topic;
  66. }
  67. public void setTopic(String topic) {
  68. this.topic = topic;
  69. }
  70. }