MQTTpublishPacket.java 2.1 KB

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