diff --git a/mslrb2015/AutoReferee.pde b/mslrb2015/AutoReferee.pde new file mode 100644 index 0000000..33dfc53 --- /dev/null +++ b/mslrb2015/AutoReferee.pde @@ -0,0 +1,201 @@ +/** Provides interface with automatic referee + * Uses the same JSON communication protocol as communication with base stations */ +static class AutoReferee +{ + Client refereeClient; + MyServer refereeServer = new MyServer(mainApplet, Config.autoRefereeServerPort); + + /* Last message */ + String commandString = ""; + String teamString = ""; + int robotID = 0; + + MessageTarget targetTeam = MessageTarget.UNKNOWN; + + public void checkIncomingMessages() { + refereeClient = refereeServer.available(); + if (refereeClient == null) return; + + String input = new String(refereeClient.readBytes()); + String msg = ""; + + // There may be multiple messages, split and parse those + if (input == null) return; + while (input.length() !=0) { + int idx = input.indexOf('\0'); + if(idx < 0) return; + + if (idx != 0) { + msg += input.substring(0, idx); + if (idx < msg.length()) { + input = input.substring(idx+1); + } else { + input = ""; + } + } else { + if (input.length() == 1) { + input = ""; + } else { + input = input.substring(1); + } + } + + org.json.JSONObject command; + + try // Check for malformed JSON + { + command = new org.json.JSONObject(msg); + } catch(JSONException e) { + String errorMsg = "ERROR malformed JSON from Automatic Referee\n"; + println(errorMsg); + return; + } + + // JSON is valid + try { + commandString = command.getString("command"); + // Invalid commands are ignored by validateCommand() + } catch(JSONException e) { + println("Missing command in message from Automatic Referee"); + return; + } + try { + teamString = command.getString("targetTeam"); + } catch(JSONException e) { + println("Missing target team in message from Automatic Referee"); + return; + } + try { + robotID = command.getInt("robotID"); + } catch(JSONException e) { + /* It is to be expected that not all messages have a robotID */ + robotID = -1; + } + + println("Received " + commandString + " for " + (teamString.isEmpty() ? "both teams" : teamString) + " from automatic referee (" + robotID + ")"); + + updateTeams(); + CommandHandling ch = validateCommand(); + if (ch == CommandHandling.IGNORE) { + println("Will not handle command " + commandString); + return; + } + + updateRefboxState(); + if (ch == CommandHandling.UPDATE_STATE) return; + + // Implies ch == UPDATE_SEND + forwardToTeams(); + } + } + + public void closeServer() { + refereeServer.stop(); + } + + private void updateTeams() { + if (teamString.equals("teamA")) { + targetTeam = MessageTarget.TEAM_A; + } else if (teamString.equals("teamB")) { + targetTeam = MessageTarget.TEAM_B; + } else if (teamString.isEmpty()) { + targetTeam = MessageTarget.BOTH_TEAMS; + } else { + targetTeam = MessageTarget.UNKNOWN; + println("Error unknown team identifier from AutoReferee: " + teamString); + } + } + + private CommandHandling validateCommand() { + switch(commandString) { + case COMM_FIRST_HALF: + case COMM_SECOND_HALF: + case COMM_FIRST_HALF_OVERTIME: + case COMM_SECOND_HALF_OVERTIME: + case COMM_HALF_TIME: + case COMM_END_GAME: + case COMM_END_PART: + case COMM_GAMEOVER: + case COMM_RESET: + case COMM_YELLOW_CARD: + case COMM_RED_CARD: + return CommandHandling.UPDATE_STATE; + case COMM_STOP: + case COMM_START: + case COMM_GOAL: + case COMM_KICKOFF: + case COMM_FREEKICK: + case COMM_GOALKICK: + case COMM_THROWIN: + case COMM_CORNER: + case COMM_PENALTY: + case COMM_DROP_BALL: + case COMM_PARK: + case COMM_SUBGOAL: + return CommandHandling.UPDATE_SEND; + default: // Ignore any other (or illegal ones) command + return CommandHandling.IGNORE; + } + } + + private void updateRefboxState() { + if (targetTeam == MessageTarget.BOTH_TEAMS) { + if (commandString.equals(COMM_START)) StateMachine.Update(ButtonsEnum.BTN_START, true); + else if (commandString.equals(COMM_STOP)) StateMachine.Update(ButtonsEnum.BTN_STOP, true); + else if (commandString.equals(COMM_DROP_BALL)) StateMachine.Update(ButtonsEnum.BTN_DROPBALL, true); + else if (commandString.equals(COMM_PARK)) StateMachine.Update(ButtonsEnum.BTN_PARK, true); + else if (commandString.equals(COMM_END_PART)) StateMachine.Update(ButtonsEnum.BTN_ENDPART, true); + else if (commandString.equals(COMM_RESET)) StateMachine.Update(ButtonsEnum.BTN_RESET, true); + else println("No handling specified for the " + commandString + " command"); + } else if (targetTeam == MessageTarget.TEAM_A) { + if (commandString.equals(COMM_STOP)) StateMachine.Update(ButtonsEnum.BTN_L_KICKOFF, true); + else if (commandString.equals(COMM_FREEKICK)) StateMachine.Update(ButtonsEnum.BTN_L_FREEKICK, true); + else if (commandString.equals(COMM_GOALKICK)) StateMachine.Update(ButtonsEnum.BTN_L_GOALKICK, true); + else if (commandString.equals(COMM_THROWIN)) StateMachine.Update(ButtonsEnum.BTN_L_THROWIN, true); + else if (commandString.equals(COMM_CORNER)) StateMachine.Update(ButtonsEnum.BTN_L_CORNER, true); + else if (commandString.equals(COMM_GOAL)) StateMachine.Update(ButtonsEnum.BTN_L_GOAL, true); + else if (commandString.equals(COMM_SUBGOAL)) StateMachine.Update(ButtonsEnum.BTN_L_GOAL, false); + else if (commandString.equals(COMM_RED_CARD)) StateMachine.Update(ButtonsEnum.BTN_L_RED, true); + else if (commandString.equals(COMM_YELLOW_CARD)) StateMachine.Update(ButtonsEnum.BTN_L_YELLOW, true); + else println("No handling specified for the " + commandString + " command"); + } else if (targetTeam == MessageTarget.TEAM_B) { + if (commandString.equals(COMM_STOP)) StateMachine.Update(ButtonsEnum.BTN_R_KICKOFF, true); + else if (commandString.equals(COMM_FREEKICK)) StateMachine.Update(ButtonsEnum.BTN_R_FREEKICK, true); + else if (commandString.equals(COMM_GOALKICK)) StateMachine.Update(ButtonsEnum.BTN_R_GOALKICK, true); + else if (commandString.equals(COMM_THROWIN)) StateMachine.Update(ButtonsEnum.BTN_R_THROWIN, true); + else if (commandString.equals(COMM_CORNER)) StateMachine.Update(ButtonsEnum.BTN_R_CORNER, true); + else if (commandString.equals(COMM_GOAL)) StateMachine.Update(ButtonsEnum.BTN_R_GOAL, true); + else if (commandString.equals(COMM_SUBGOAL)) StateMachine.Update(ButtonsEnum.BTN_R_GOAL, false); + else if (commandString.equals(COMM_RED_CARD)) StateMachine.Update(ButtonsEnum.BTN_R_RED, true); + else if (commandString.equals(COMM_YELLOW_CARD)) StateMachine.Update(ButtonsEnum.BTN_R_YELLOW, true); + else println("No handling specified for the " + commandString + " command"); + } + } + + private void forwardToTeams() { + if (targetTeam == MessageTarget.UNKNOWN) return; + + String descr = Description.get(commandString) == null ? "" : Description.get(commandString); + + if (targetTeam == MessageTarget.TEAM_A) { + send_event_v2(commandString, descr, teamA, robotID); + } else if (targetTeam == MessageTarget.TEAM_B) { + send_event_v2(commandString, descr, teamB, robotID); + } else { + // StateMachine handles sending these events + } + } //<>// //<>// +} + +private enum MessageTarget { + BOTH_TEAMS, + TEAM_A, + TEAM_B, + UNKNOWN +} + +private enum CommandHandling { + IGNORE, /* No state change + automatic referee cannot request this */ + UPDATE_STATE, /* Update state, communication will be done in StateMachine */ + UPDATE_SEND, /* Update state and send command to teams */ +} diff --git a/mslrb2015/Comms.pde b/mslrb2015/Comms.pde index 46fc5db..c27bb60 100644 --- a/mslrb2015/Comms.pde +++ b/mslrb2015/Comms.pde @@ -374,31 +374,27 @@ public static final String COMM_REPAIR = "REPAIR"; public static final String COMM_SUBSTITUTION = "SUBSTITUTION"; public static final String COMM_ISALIVE = "IS_ALIVE"; -//free: 056789 iIfFHlmMnqQwxX -//------------------------------------------------------ - public static StringDict Description; void comms_initDescriptionDictionary() { Description = new StringDict(); - Description.set(COMM_STOP, "STOP"); - Description.set(COMM_START, "START"); - Description.set(COMM_DROP_BALL, "Drop Ball"); - Description.set(COMM_HALF_TIME, "Halftime"); - Description.set(COMM_END_GAME, "End Game"); - Description.set(COMM_END_PART, "End Part"); - Description.set(COMM_GAMEOVER, "Game Over"); - Description.set(COMM_RESET, "Reset Game"); - Description.set(COMM_WELCOME, "Welcome"); - Description.set(COMM_TESTMODE_ON, "Test Mode on"); - Description.set(COMM_TESTMODE_OFF, "Test Mode off"); - Description.set(COMM_FIRST_HALF, "1st half"); - Description.set(COMM_SECOND_HALF, "2nd half"); + Description.set(COMM_STOP, "STOP"); + Description.set(COMM_START, "START"); + Description.set(COMM_DROP_BALL, "Drop Ball"); + Description.set(COMM_HALF_TIME, "Halftime"); + Description.set(COMM_END_GAME, "End Game"); + Description.set(COMM_END_PART, "End Part"); + Description.set(COMM_GAMEOVER, "Game Over"); + Description.set(COMM_RESET, "Reset Game"); + Description.set(COMM_WELCOME, "Welcome"); + Description.set(COMM_TESTMODE_ON, "Test Mode on"); + Description.set(COMM_TESTMODE_OFF, "Test Mode off"); + Description.set(COMM_FIRST_HALF, "1st half"); + Description.set(COMM_SECOND_HALF, "2nd half"); Description.set(COMM_FIRST_HALF_OVERTIME, "Overtime 1st half"); Description.set(COMM_SECOND_HALF_OVERTIME, "Overtime 2nd half"); - Description.set(COMM_PARK, "Park"); - Description.set(COMM_SUBSTITUTION, "Substitution"); - Description.set(COMM_ISALIVE, "Is Alive"); - + Description.set(COMM_PARK, "Park"); + Description.set(COMM_SUBSTITUTION, "Substitution"); + Description.set(COMM_ISALIVE, "Is Alive"); Description.set(COMM_KICKOFF, "Kickoff"); Description.set(COMM_FREEKICK, "Freekick"); Description.set(COMM_GOALKICK, "Goalkick"); @@ -407,8 +403,9 @@ void comms_initDescriptionDictionary() { Description.set(COMM_PENALTY, "Penalty"); Description.set(COMM_GOAL, "Goal+"); Description.set(COMM_SUBGOAL, "Goal-"); - Description.set(COMM_REPAIR, "Repair"); + Description.set(COMM_REPAIR, "Repair"); Description.set(COMM_RED_CARD, "Red Card"); Description.set(COMM_YELLOW_CARD, "Yellow Card"); Description.set(COMM_DOUBLE_YELLOW, "Double Yellow"); + } diff --git a/mslrb2015/Config.pde b/mslrb2015/Config.pde index dca3846..c8d25af 100644 --- a/mslrb2015/Config.pde +++ b/mslrb2015/Config.pde @@ -8,6 +8,7 @@ static class Config public static IntList scoreClientPorts = new IntList(); public static int remoteServerPort = 12345; public static int basestationServerPort = 28097; + public static int autoRefereeServerPort = 28098; public static boolean remoteControlEnable = false; // Rules @@ -119,6 +120,10 @@ static class Config if(networking.has("basestationServerPort")) basestationServerPort = networking.getInt("basestationServerPort"); + + if (networking.has("autoRefereeServerPort")) { + autoRefereeServerPort = networking.getInt("autoRefereeServerPort"); + } if(networking.has("remoteControlEnable")) remoteControlEnable = networking.getBoolean("remoteControlEnable"); diff --git a/mslrb2015/MSLRemote.pde b/mslrb2015/MSLRemote.pde deleted file mode 100644 index e7366c9..0000000 --- a/mslrb2015/MSLRemote.pde +++ /dev/null @@ -1,253 +0,0 @@ -/* -This class definitions is kept in the project just for future purposes -Someone implementing a remote crontol, such as an automatic referee can use this class -In the mslrb2015.pde file all lines referencing mslRemot should be uncommented -*/ -class MSLRemote -{ -/* - - public MyServer server; - private String lastCommand = " "; - - private static final String GAMESTATUS_PRE_GAME = "Va"; - private static final String GAMESTATUS_PRE_GAME_KICK_OFF_CYAN = "Vb"; - private static final String GAMESTATUS_PRE_GAME_KICK_OFF_MAGENTA = "Vc"; - private static final String GAMESTATUS_GAME_STOP_HALF1 = "Vd"; - private static final String GAMESTATUS_GAME_STOP_HALF2 = "Ve"; - private static final String GAMESTATUS_GAME_ON_HALF1 = "Vf"; - private static final String GAMESTATUS_GAME_ON_HALF2 = "Vg"; - private static final String GAMESTATUS_HALF_TIME = "Vh"; - private static final String GAMESTATUS_HALF_KICK_OFF_CYAN = "Vi"; - private static final String GAMESTATUS_HALF_KICK_OFF_MAGENTA = "Vj"; - private static final String GAMESTATUS_END_GAME = "Vk"; - private static final String GAMESTATUS_SET_PLAY = "Vl"; - - // Set plays: - private static final String COMMAND_KICK_OFF_CYAN = "CK"; - private static final String COMMAND_FREEKICK_CYAN = "CF"; - private static final String COMMAND_THROW_IN_CYAN = "CT"; - private static final String COMMAND_GOALKICK_CYAN = "CG"; - private static final String COMMAND_CORNER_CYAN = "CE"; - private static final String COMMAND_PENALTY_CYAN = "CP"; - private static final String COMMAND_SCORE_CYAN = "CL"; // append score 2 digits (e.g. "CL01" for left score = 1) - private static final String COMMAND_YELLOW_CYAN = "CY1"; // robot 1 - private static final String COMMAND_OUT_CYAN = "Co1"; // robot 1 - - private static final String COMMAND_KICK_OFF_MAGENTA= "MK"; - private static final String COMMAND_FREEKICK_MAGENTA = "MF"; - private static final String COMMAND_THROW_IN_MAGENTA = "MT"; - private static final String COMMAND_GOALKICK_MAGENTA = "MG"; - private static final String COMMAND_CORNER_MAGENTA = "ME"; - private static final String COMMAND_PENALTY_MAGENTA = "MP"; - private static final String COMMAND_SCORE_MAGENTA = "ML"; // append score 2 digits (e.g. "CL01" for left score = 1) - private static final String COMMAND_YELLOW_MAGENTA = "MY1"; // robot 1 - private static final String COMMAND_OUT_MAGENTA = "Mo1"; // robot 1 - - private static final String COMMAND_DROPBALL = "SD"; - private static final String COMMAND_START = "ST"; - private static final String COMMAND_STOP = "SP"; - private static final String COMMAND_ENDPART = "SG"; - private static final String COMMAND_RESET = "SR"; - - - - public MSLRemote(PApplet parent, int port) - { - server = new MyServer(parent, port); - } - - public void setLastCommand(String cmd) - { - lastCommand = cmd; - } - - public String getEventCommand() - { - if(lastCommand.equals(COMM_START)) - return COMMAND_START; - else if(lastCommand.equals(COMM_STOP)) - return COMMAND_STOP; - else if(lastCommand.equals(COMM_DROP_BALL)) - return COMMAND_DROPBALL; - else if(lastCommand.equals(COMM_HALF_TIME)) - return COMMAND_ENDPART; - else if(lastCommand.equals(COMM_RESET)) - return COMMAND_RESET; - - else if(lastCommand.equals(COMM_KICKOFF)) - return COMMAND_KICK_OFF_CYAN; - else if(lastCommand.equals(COMM_FREEKICK)) - return COMMAND_FREEKICK_CYAN; - else if(lastCommand.equals(COMM_GOALKICK)) - return COMMAND_GOALKICK_CYAN; - else if(lastCommand.equals(COMM_THROWIN)) - return COMMAND_THROW_IN_CYAN; - else if(lastCommand.equals(COMM_CORNER)) - return COMMAND_CORNER_CYAN; - else if(lastCommand.equals(COMM_PENALTY)) - return COMMAND_PENALTY_CYAN; - - return ""; - } - - public String getGameStatusCommand() - { - // 0 "Pre-Game", - // 1 "Game - 1st Half", - // 2 "Game - Halftime", - // 3 "Game - 2nd Half", - // 4 "Game - End", - // 5 "Overtime - 1st", - // 6 "Overtime - Switch", - // 7 "Overtime - 2nd", - // 8 "Penalty", - // 9 "GameOver" - - GameStateEnum gs = StateMachine.GetCurrentGameState(); - - boolean kickoff = false; - boolean teamLeft = false; - - if(lastCommand == COMM_KICKOFF) - { - if(gs == GameStateEnum.GS_PREGAME || gs == GameStateEnum.GS_HALFTIME || gs == GameStateEnum.GS_HALFTIME_OVERTIME) // pre or halftime - { - kickoff = true; - if(lastCommand == COMM_KICKOFF) - teamLeft = true; - } - }else if(lastCommand == COMM_FREEKICK - || lastCommand == COMM_GOALKICK - || lastCommand == COMM_THROWIN - || lastCommand == COMM_CORNER - || lastCommand == COMM_PENALTY - || lastCommand == COMM_DROP_BALL) - return GAMESTATUS_SET_PLAY; - - switch(gs) - { - case GS_PREGAME: - if(kickoff) - { - if(teamLeft) - return GAMESTATUS_PRE_GAME_KICK_OFF_CYAN; - else - return GAMESTATUS_PRE_GAME_KICK_OFF_MAGENTA; - } - return GAMESTATUS_PRE_GAME; - - - case GS_GAMESTOP_H1: - case GS_GAMESTOP_H3: - return GAMESTATUS_GAME_STOP_HALF1; - - case GS_GAMEON_H1: - case GS_GAMEON_H3: - return GAMESTATUS_GAME_ON_HALF1; - - case GS_HALFTIME: - case GS_OVERTIME: - case GS_HALFTIME_OVERTIME: - if(kickoff) - { - if(teamLeft) - return GAMESTATUS_HALF_KICK_OFF_CYAN; - else - return GAMESTATUS_HALF_KICK_OFF_MAGENTA; - } - return GAMESTATUS_HALF_TIME; - - case GS_GAMESTOP_H2: - case GS_GAMESTOP_H4: - return GAMESTATUS_GAME_STOP_HALF2; - - case GS_GAMEON_H2: - case GS_GAMEON_H4: - return GAMESTATUS_GAME_ON_HALF2; - - case GS_PENALTIES: - return GAMESTATUS_GAME_STOP_HALF2; - - case GS_ENDGAME: - return GAMESTATUS_END_GAME; - } - - return ""; - } - - // Sends an "event" type update message to the clients - public void update_tEvent(String eventCode, String eventDesc, Team team) - { - int teamId = -1; - if(team == teamA) teamId = 0; - else if(team == teamB) teamId = 1; - - int scoreA = (teamA != null) ? teamA.Score : 0; - int scoreB = (teamB != null) ? teamB.Score : 0; - - String msg = "{"; - msg += "\"type\": \"event\","; - msg += "\"eventCode\": \"" + eventCode + "\","; - msg += "\"eventDesc\": \"" + eventDesc + "\","; - msg += "\"teamId\": " + teamId + ","; - msg += "\"teamName\": \"" + ((teamId == -1) ? "" : team.shortName) + "\","; - msg += "\"gamestatus\": \"" + getGameStatusCommand() + "\","; - msg += "\"command\": \"" + getEventCommand() + "\","; - msg += "\"scoreTeamA\": " + scoreA + ","; - msg += "\"scoreTeamB\": " + scoreB; - msg += "}"; - msg += (char)0x00; - - writeMsg(msg); - } - - - - public int clientCount() - { - return server.clientCount; - } - - public void stopServer() - { - server.stop(); - } - - public void writeMsg(String message) - { - if (server.clientCount > 0){ - server.write(message); - } - } - - public void checkMessages() - { - try - { - // Get the next available client - Client thisClient = server.available(); - // If the client is not null, and says something, display what it said - if (thisClient !=null) { - String whatClientSaid = thisClient.readString(); - if (whatClientSaid != null) { - - println("MSL Remote JSON: " + whatClientSaid); - - org.json.JSONObject jsonObj = new org.json.JSONObject(whatClientSaid); - - int pos = jsonObj.getInt("id"); - - char group = 'C'; - - buttonEvent(group, pos); - - } - } - - }catch(Exception e){ - println("Invalid JSON received from MSL Remote."); - } - } -*/ -} diff --git a/mslrb2015/RefreshButon.pde b/mslrb2015/RefreshButon.pde index 59f3f5f..6ac31f9 100644 --- a/mslrb2015/RefreshButon.pde +++ b/mslrb2015/RefreshButon.pde @@ -150,18 +150,6 @@ void RefreshButonStatus1() { } - // The switches are enabled only on pre-game - if(StateMachine.GetCurrentGameState() != GameStateEnum.GS_PREGAME) - { - for(int i = 0; i < bSlider.length; i++) { - //bSlider[i].disable(); - } - }else{ - for(int i = 0; i < bSlider.length; i++) { - //bSlider[i].enable(); - } - } - // Update End Part / End Game button String endPartOrEndGame = "End Part"; diff --git a/mslrb2015/StateMachine.pde b/mslrb2015/StateMachine.pde index c6b9a06..3e9bf2b 100644 --- a/mslrb2015/StateMachine.pde +++ b/mslrb2015/StateMachine.pde @@ -75,7 +75,7 @@ static class StateMachine needUpdate = true; // and enforce update of the state machine done = true; return; - } //<>// //<>// + } Popup.close(); break; } @@ -251,12 +251,6 @@ static class StateMachine for (int s = 0; s < bSlider.length; s++) { bSlider[s].disable(); - if(StateMachine.GetCurrentGameState() != GameStateEnum.GS_PREGAME) - { - //bSlider[i].disable(); - }else{ - //bSlider[i].enable(); - } } Popup.close(); break; @@ -302,8 +296,6 @@ static class StateMachine Popup.show(PopupTypeEnum.POPUP_ALIVE, MSG_ISALIVE, 8, 10, 0, 24, 380, 230); tBoxIsAlive.show(); tBoxIsAlive.clicked(); -// done = true; -// return; } else if(btnCurrent.isRepair()) @@ -348,8 +340,8 @@ static class StateMachine else t.newYellowCard = btnOn; } - else if(btnCurrent.isStop()) - { + else if(btnCurrent.isStop()) //<>// + { //<>// setPieceDelay.resetStopWatch(); setPieceDelay.stopTimer(); forceKickoff = false; diff --git a/mslrb2015/Team.pde b/mslrb2015/Team.pde index b52e545..16bccb0 100644 --- a/mslrb2015/Team.pde +++ b/mslrb2015/Team.pde @@ -269,15 +269,6 @@ class Team { this.nOfSubstitutions++; println("substituting robot " + robotID + " (on field) for robot (outside field) - " + nOfSubstitutions + " done."); } -/* @mbc Robot IDs are virtual [0 to 4] and corresponds to each of the circles in the interface - for (int i = 0; i < r.length; i++) { - if (this.r[i].state.equals("play") || this.r[i].state.equals("yellow")) { // only robots that are in play can substitute - send_event_v2(""+COMM_SUBSTITUTION, "substituting", this, robotID); - this.substitute_timer_start(i); - println("substituting robot " + i + " (on field) for robot " + robotID + " (outside field)"); - break; - } - } */ } //******************************************************************* diff --git a/mslrb2015/data/config.json b/mslrb2015/data/config.json index 904ef77..dd03913 100644 --- a/mslrb2015/data/config.json +++ b/mslrb2015/data/config.json @@ -11,6 +11,7 @@ } ], "basestationServerPort": 28097, + "autoRefereeServerPort": 28098, "enableRemote": false }, "rules": diff --git a/mslrb2015/mslrb2015.pde b/mslrb2015/mslrb2015.pde index 95e4acc..50b475d 100644 --- a/mslrb2015/mslrb2015.pde +++ b/mslrb2015/mslrb2015.pde @@ -1,5 +1,3 @@ -//<>// -//<>// /* ================================== MSL RefBox 2015 (Processing 3) LMFerreira @@ -49,9 +47,9 @@ public static final int CMDID_COMMON_CONFIG = 7; public static final int CMDID_COMMON_LENGHT = 8; public static ScoreClients scoreClients = null; -//public static MSLRemote mslRemote = null; public static MyServer BaseStationServer; public static Client connectingClient = null; +public static AutoReferee autoReferee; public static Team teamA, teamB, cTeam; public static Button[] bTeamAcmds = new Button[CMDID_TEAM_LENGHT]; @@ -155,7 +153,7 @@ void setup() { scoreClients = new ScoreClients(this); // Load score clients server BaseStationServer = new MyServer(this, Config.basestationServerPort); // Load basestations server - // mslRemote = new MSLRemote(this, Config.remoteServerPort); // Load module for MSL remote control + autoReferee = new AutoReferee(); teamA = new Team(Config.defaultLeftTeamColor,true); // Initialize Left team (Team A) teamB = new Team(Config.defaultRightTeamColor,false); // Initialize Right team (Team B) @@ -234,8 +232,7 @@ void draw() { long t=System.currentTimeMillis(); if ( (t-updateScoreClientslasttime) >= Config.scoreClientsUpdatePeriod_ms ) scoreClients.update_tTeams(gametime,gameruntime); - //verifyremotecontrol(); - //mslRemote.checkMessages(); + autoReferee.checkIncomingMessages(); checkBasestationsMessages(); @@ -353,7 +350,7 @@ void exit() { // Stop all servers scoreClients.stopServer(); BaseStationServer.stop(); - //mslRemote.stopServer(); + autoReferee.closeServer(); super.exit(); }