|
@@ -17,6 +17,7 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.BoolSensor;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatCollector;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatSensor;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.packets.MQTT_packet;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.packets.MQTTpublishPacket;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.scheduler.AbstractEvent;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.util.Pair;
|
|
|
|
|
@@ -259,6 +260,7 @@ public class MQTT_protocol implements Protocol {
|
|
|
* Value which should be published
|
|
|
*/
|
|
|
String newValue = null;
|
|
|
+ boolean isBoolean = false;
|
|
|
|
|
|
/**
|
|
|
* Check if FloatSensor
|
|
@@ -278,18 +280,24 @@ public class MQTT_protocol implements Protocol {
|
|
|
if (newTopic == null || new Random().nextBoolean()) {
|
|
|
newTopic = bSensor.getBSinfoName();
|
|
|
newValue = "" + bSensor.getBSval();
|
|
|
+ isBoolean = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (newTopic != null) {
|
|
|
/**
|
|
|
- * Message to be published
|
|
|
+ * Packet for publishing the new value
|
|
|
*/
|
|
|
- String msg = "Topic:" + newTopic + ":" + newValue;
|
|
|
+ Packet pubPacket = null;
|
|
|
+ if(isBoolean) {
|
|
|
+ pubPacket = new MQTTpublishPacket(timestep, port, broker, newTopic, Boolean.parseBoolean(newValue));
|
|
|
+ }else {
|
|
|
+ pubPacket = new MQTTpublishPacket(timestep, port, broker, newTopic, Float.parseFloat(newValue));
|
|
|
+ }
|
|
|
/**
|
|
|
* Send Packet
|
|
|
*/
|
|
|
- returnPackets.add(new MQTT_packet(MQTT_packet.PUBLISH, timestep, port, broker, msg));
|
|
|
+ returnPackets.add(pubPacket);
|
|
|
|
|
|
/**
|
|
|
* Delay to the broker
|
|
@@ -315,8 +323,15 @@ public class MQTT_protocol implements Protocol {
|
|
|
*/
|
|
|
long delayBrokerToSub = broker.getTransmissionDelayTo(p);
|
|
|
timestep += broker.getResponseTime();
|
|
|
-
|
|
|
- returnPackets.add(new MQTT_packet(MQTT_packet.PUBLISH, timestep, broker, p, msg));
|
|
|
+ /**
|
|
|
+ * Packet Broker -> Subscriber
|
|
|
+ */
|
|
|
+ if(isBoolean) {
|
|
|
+ pubPacket = new MQTTpublishPacket(timestep, broker, p, newTopic, Boolean.parseBoolean(newValue));
|
|
|
+ }else {
|
|
|
+ pubPacket = new MQTTpublishPacket(timestep, broker, p, newTopic, Float.parseFloat(newValue));
|
|
|
+ }
|
|
|
+ returnPackets.add(pubPacket);
|
|
|
if (p.getStatus() != Port.CLOSED && delayBrokerToSub != Long.MAX_VALUE) {
|
|
|
returnPackets.add(
|
|
|
new MQTT_packet(MQTT_packet.PUBACK, timestep + p.getResponseTime(), p, broker));
|
|
@@ -368,8 +383,13 @@ public class MQTT_protocol implements Protocol {
|
|
|
*/
|
|
|
long delayBrokerToSub = broker.getTransmissionDelayTo(p);
|
|
|
timestep += broker.getResponseTime();
|
|
|
-
|
|
|
- returnPackets.add(new MQTT_packet(MQTT_packet.PUBLISH, timestep, broker, p, msg));
|
|
|
+
|
|
|
+ if(isBoolean) {
|
|
|
+ pubPacket = new MQTTpublishPacket(timestep, broker, p, newTopic, Boolean.parseBoolean(newValue));
|
|
|
+ }else {
|
|
|
+ pubPacket = new MQTTpublishPacket(timestep, broker, p, newTopic, Float.parseFloat(newValue));
|
|
|
+ }
|
|
|
+ returnPackets.add(pubPacket);
|
|
|
if (p.getStatus() != Port.CLOSED && delayBrokerToSub != Long.MAX_VALUE) {
|
|
|
returnPackets.add(
|
|
|
new MQTT_packet(MQTT_packet.PUBACK, timestep + p.getResponseTime(), p, broker));
|