Skip to content

Commit

Permalink
now sending teamColor and teamName on public Beacon signal. Upgraded …
Browse files Browse the repository at this point in the history
…version to 0.6.
  • Loading branch information
pkohout committed Oct 15, 2024
1 parent 0f51a06 commit 570fe86
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ ENV BROKER tcp://localhost:1883
ENV REFBOX localhost
ENV TEAM GRIPS
ENV KEY randomkey
ENTRYPOINT ["sh", "-c", "java -jar /home/gradle/src/app/build/libs/mqtt-bridge-0.5-all.jar -b $BROKER -r $REFBOX -t $TEAM -k $KEY"]
ENTRYPOINT ["sh", "-c", "java -jar /home/gradle/src/app/build/libs/mqtt-bridge-0.6-all.jar -b $BROKER -r $REFBOX -t $TEAM -k $KEY"]
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plugins {

group = 'io.github.robocup-logistics'
archivesBaseName = "mqtt-bridge"
version = '0.5'
version = '0.6'

repositories {
// Use Maven Central for resolving dependencies.
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/java/com/rcll/java/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void main(String[] args) throws MqttException, InterruptedExceptio
IMqttClient publisher = new MqttClient(brokerUrl, publisherId);
try {
publisher.connect();
} catch(MqttException me) {
} catch (MqttException me) {
log.error("Error on connecting to mqtt broker[" + brokerUrl + "] - is it Running? Msg: " + me.getMessage(), me.getCause());
System.exit(1);
}
Expand All @@ -52,12 +52,21 @@ public static void main(String[] args) throws MqttException, InterruptedExceptio
TeamConfig teamConfig = new TeamConfig(parsed.getOptionValue("k"), parsed.getOptionValue("t"));
RefboxHandler privateHandler = new RefboxHandler();
RefboxHandler publicHandler = new RefboxHandler();
RefboxMqttHandler privateMqttHandler = new RefboxMqttHandler(privateHandler, "private", publisher);
RefboxMqttHandler publicMqttHandler = new RefboxMqttHandler(publicHandler, "public", publisher);
RefboxClient refboxClient = new RefboxClient(connectionConfig, teamConfig, privateHandler, publicHandler, 2000);
refboxClient.startServer();
RefboxTeamHandler refboxTeamHandler = new RefboxTeamHandler(publisher, refboxClient, teamConfig.getName());
refboxTeamHandler.start();

while (refboxClient.getTeamColor().isEmpty()) {
log.info("Waiting for team color...");
Thread.sleep(1000);
}

RefboxMqttHandler privateMqttHandler = new RefboxMqttHandler(privateHandler, "private", publisher,
refboxClient.getTeamColor().get(), teamConfig.getName());
RefboxMqttHandler publicMqttHandler = new RefboxMqttHandler(publicHandler, "public", publisher,
refboxClient.getTeamColor().get(), teamConfig.getName());

while (publisher.isConnected()) {
Thread.sleep(1000);
}
Expand Down
16 changes: 15 additions & 1 deletion app/src/main/java/com/rcll/java/RefboxMqttHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@

import com.google.protobuf.MessageOrBuilder;
import com.google.protobuf.util.JsonFormat;
import com.rcll.domain.TeamColor;
import com.rcll.refbox.RefboxHandler;
import lombok.SneakyThrows;
import org.eclipse.paho.client.mqttv3.IMqttClient;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.robocup_logistics.llsf_msgs.*;

import java.io.IOException;
import java.util.Optional;


public class RefboxMqttHandler {
private final RefboxHandler handler;
private final String prefix;
private final IMqttClient mqttClient;
private final TeamColor teamColor;
private final String teamName;

public RefboxMqttHandler(RefboxHandler handler, String prefix, IMqttClient mqttClient) {
public RefboxMqttHandler(RefboxHandler handler, String prefix, IMqttClient mqttClient, TeamColor teamColor,
String teamName) {
this.handler = handler;
this.prefix = prefix;
this.mqttClient = mqttClient;
this.teamColor = teamColor;
this.teamName = teamName;
this.handler.setGameStateCallback(this::handleGameState);
this.handler.setMachineInfoCallback(this::handleMchineInfo);
this.handler.setOrderInfoCallback(this::handleOrderInfo);
Expand Down Expand Up @@ -65,6 +72,13 @@ private void handleExplorationInfo(ExplorationInfoProtos.ExplorationInfo explora
@SneakyThrows

private void handleBeaconSignal(BeaconSignalProtos.BeaconSignal beaconSignal) {
if (!beaconSignal.hasTeamColor() && !beaconSignal.hasTeamName()) {
if (teamColor.equals(TeamColor.CYAN)) {
beaconSignal = beaconSignal.toBuilder().setTeamColor(TeamProtos.Team.CYAN).setTeamName(teamName).build();
} else {
beaconSignal = beaconSignal.toBuilder().setTeamColor(TeamProtos.Team.MAGENTA).setTeamName(teamName).build();
}
}
this.mqttClient.publish(this.prefix + "/beacon_signal", new MqttMessage(toJson(beaconSignal).getBytes()));
}

Expand Down

0 comments on commit 570fe86

Please sign in to comment.