From 28c67733f24c05ccf668f67985e7aef2551df6b4 Mon Sep 17 00:00:00 2001 From: Jorrit Olthuis Date: Tue, 19 Apr 2022 20:01:57 +0200 Subject: [PATCH 1/2] Remove unused files --- .../RefreshButon5408860871915498609.autosave | 379 ------------------ mslrb2015/gui.pde | 4 - 2 files changed, 383 deletions(-) delete mode 100644 mslrb2015/RefreshButon5408860871915498609.autosave delete mode 100644 mslrb2015/gui.pde diff --git a/mslrb2015/RefreshButon5408860871915498609.autosave b/mslrb2015/RefreshButon5408860871915498609.autosave deleted file mode 100644 index 42527ba..0000000 --- a/mslrb2015/RefreshButon5408860871915498609.autosave +++ /dev/null @@ -1,379 +0,0 @@ -//********************************************************************* -void RefreshButonStatus1() { - - switch(StateMachine.GetCurrentGameState()) - { - // PRE-GAME - case GS_PREGAME: - if (Popup.isEnabled() && (Popup.getType() == PopupTypeEnum.POPUP_WAIT)) Popup.close(); - - buttonAdisableAll(0); //team A commands - buttonBdisableAll(0); //team B commands - buttonCdisable(); //common commands - - if(StateMachine.setpiece) - { - if(StateMachine.setpiece_left){ - buttonFromEnum(ButtonsEnum.BTN_L_KICKOFF).activate(); - buttonFromEnum(ButtonsEnum.BTN_R_KICKOFF).disable(); - - }else{ - buttonFromEnum(ButtonsEnum.BTN_L_KICKOFF).disable(); - buttonFromEnum(ButtonsEnum.BTN_R_KICKOFF).activate(); - } - - buttonFromEnum(ButtonsEnum.BTN_RESET).disable(); - buttonFromEnum(ButtonsEnum.BTN_START).enable(); - buttonFromEnum(ButtonsEnum.BTN_STOP).activate(); - buttonFromEnum(ButtonsEnum.BTN_CONFIG).disable(); - - }else{ - - buttonFromEnum(ButtonsEnum.BTN_L_KICKOFF).enable(); - buttonFromEnum(ButtonsEnum.BTN_R_KICKOFF).enable(); - - buttonFromEnum(ButtonsEnum.BTN_START).disable(); - buttonFromEnum(ButtonsEnum.BTN_STOP).activate(); - buttonFromEnum(ButtonsEnum.BTN_RESET).activate(); - buttonFromEnum(ButtonsEnum.BTN_CONFIG).activate(); - } - - - break; - - case GS_GAMEON_H1: - case GS_GAMEON_H2: - case GS_GAMEON_H3: - case GS_GAMEON_H4: - refreshbutton_game_on(); - break; - - case GS_GAMESTOP_H1: - case GS_GAMESTOP_H2: - case GS_GAMESTOP_H3: - case GS_GAMESTOP_H4: - refreshbutton_game_stopped(); - if(StateMachine.setpiece){ - buttonAdisable(); //team A commands - buttonBdisable(); //team B commands - buttonCdisable(); //common commands - buttonFromEnum(StateMachine.setpiece_button).activate(); - buttonFromEnum(ButtonsEnum.BTN_START).enable(); - buttonFromEnum(ButtonsEnum.BTN_PARK).disable(); - }else{ - buttonFromEnum(ButtonsEnum.BTN_START).disable(); - } - break; - - case GS_HALFTIME: - case GS_OVERTIME: - case GS_HALFTIME_OVERTIME: - buttonAdisableAll(0); //team A commands - buttonBdisableAll(0); //team B commands - buttonCdisable(); //common commands - bTeamAcmds[CMDID_TEAM_GOAL].disable(); // Disable goal button if part ended with a goal - bTeamBcmds[CMDID_TEAM_GOAL].disable(); // Disable goal button if part ended with a goal - - if (StateMachine.GetCurrentGameState() == GameStateEnum.GS_OVERTIME){ - buttonFromEnum(ButtonsEnum.BTN_ENDPART).enable(); - } - - // Alternate Kick-Offs - boolean enableLeft = StateMachine.firstKickoffLeft; - if(StateMachine.GetCurrentGameState() == GameStateEnum.GS_HALFTIME || StateMachine.GetCurrentGameState() == GameStateEnum.GS_HALFTIME_OVERTIME) - enableLeft = !enableLeft; - - if(StateMachine.setpiece) - { - buttonFromEnum(StateMachine.setpiece_button).activate(); - buttonFromEnum(ButtonsEnum.BTN_START).enable(); - buttonFromEnum(ButtonsEnum.BTN_STOP).activate(); - buttonFromEnum(ButtonsEnum.BTN_PARK).disable(); - buttonFromEnum(ButtonsEnum.BTN_RESET).disable(); - }else{ - if(enableLeft) - { - buttonFromEnum(ButtonsEnum.BTN_L_KICKOFF).enable(); - buttonFromEnum(ButtonsEnum.BTN_R_KICKOFF).disable(); - }else{ - buttonFromEnum(ButtonsEnum.BTN_L_KICKOFF).disable(); - buttonFromEnum(ButtonsEnum.BTN_R_KICKOFF).enable(); - } - buttonFromEnum(ButtonsEnum.BTN_START).disable(); - buttonFromEnum(ButtonsEnum.BTN_STOP).activate(); - buttonFromEnum(ButtonsEnum.BTN_PARK).activate(); - if(StateMachine.GetCurrentGameState() == GameStateEnum.GS_OVERTIME) - buttonFromEnum(ButtonsEnum.BTN_RESET).activate(); - } - break; - - case GS_PENALTIES: - refreshbutton_game_stopped(); - buttonAdisable(); //team A commands - buttonBdisable(); //team B commands - buttonCdisable(); //common commands - - bTeamAcmds[CMDID_TEAM_PENALTY].enable(); - bTeamBcmds[CMDID_TEAM_PENALTY].enable(); - - if(StateMachine.setpiece) - buttonFromEnum(StateMachine.setpiece_button).activate(); - buttonFromEnum(ButtonsEnum.BTN_START).enable(); - buttonFromEnum(ButtonsEnum.BTN_STOP).activate(); - buttonFromEnum(ButtonsEnum.BTN_PARK).disable(); - buttonFromEnum(ButtonsEnum.BTN_RESET).disable(); - - bCommoncmds[CMDID_COMMON_DROP_BALL].disable(); - bCommoncmds[CMDID_COMMON_HALFTIME].enable(); - break; - - case GS_PENALTIES_ON: - refreshbutton_game_on(); - break; - - case GS_ENDGAME: - buttonAdisableAll(0); //team A commands - buttonBdisableAll(0); //team B commands - buttonCdisable(); //common commands - -// bCommoncmds[CMDID_COMMON_DROP_BALL].disable(); -// bCommoncmds[CMDID_COMMON_SUBS].disable(); -// bCommoncmds[CMDID_COMMON_HALFTIME].disable(); -// bCommoncmds[CMDID_COMMON_CONFIG].disable(); - - bCommoncmds[CMDID_COMMON_RESET].activate(); - bCommoncmds[CMDID_COMMON_PARKING].activate(); - buttonCSTARTdisable(); - buttonCSTOPactivate(); - break; - - default: - buttonAenable(); //team A commands - buttonBenable(); //team B commands - buttonCenable(); //common commands - buttonCSTOPactivate(); - break; - - } - - // 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"; - switch(StateMachine.GetCurrentGameState()) - { - case GS_HALFTIME: - case GS_GAMEON_H2: - case GS_GAMEON_H4: - case GS_GAMESTOP_H2: - case GS_GAMESTOP_H4: - endPartOrEndGame = "End Game"; - break; - case GS_PENALTIES: - case GS_OVERTIME: - endPartOrEndGame = "Game Over"; - break; - } - - bCommoncmds[CMDID_COMMON_HALFTIME].Label = endPartOrEndGame; -} - -//********************************************************************* -// Start button has been pressed and game is now ON -void refreshbutton_game_on() -{ - buttondisableAll(); - buttonCSTARTdisable(); - buttonCSTOPactivate(); -} - -//********************************************************************* -// -void refreshbutton_game_stopped() -{ - if(bTeamAcmds[CMDID_TEAM_GOAL].isActive()) { - buttonAdisable(); - buttonBdisable(); - buttonCdisable(); - bTeamBcmds[CMDID_TEAM_KICKOFF].enable(); - bTeamBcmds[CMDID_TEAM_GOAL].disable(); - bCommoncmds[CMDID_COMMON_HALFTIME].enable(); - } - else if(bTeamBcmds[CMDID_TEAM_GOAL].isActive()) { - buttonAdisable(); - buttonBdisable(); - buttonCdisable(); - bTeamAcmds[CMDID_TEAM_KICKOFF].enable(); - bTeamAcmds[CMDID_TEAM_GOAL].disable(); - bCommoncmds[CMDID_COMMON_HALFTIME].enable(); - } - else { - if(!StateMachine.setpiece) { - buttonA_setpieces_en(); //team A commands - buttonB_setpieces_en(); //team B commands - - bCommoncmds[CMDID_COMMON_DROP_BALL].enable(); - bCommoncmds[CMDID_COMMON_HALFTIME].enable(); - bCommoncmds[CMDID_COMMON_PARKING].disable(); - bCommoncmds[CMDID_COMMON_RESET].disable(); - bTeamAcmds[CMDID_TEAM_GOAL].enable(); - bTeamBcmds[CMDID_TEAM_GOAL].enable(); - bCommoncmds[CMDID_COMMON_SUBS].enable(); - buttonCSTARTdisable(); // Turn OFF START button - } - else - { - bTeamAcmds[CMDID_TEAM_GOAL].disable(); - bTeamBcmds[CMDID_TEAM_GOAL].disable(); - } - - for(int i = CMDID_TEAM_REPAIR_OUT; i <= CMDID_TEAM_YELLOWCARD; i++) - { - if(!bTeamAcmds[i].isActive()) - bTeamAcmds[i].enable(); - - if(!bTeamBcmds[i].isActive()) - bTeamBcmds[i].enable(); - } - } - buttonCSTOPactivate(); // Turn ON STOP button - - if (teamA.numberOfPlayingRobots() < 3) bTeamAcmds[CMDID_TEAM_REPAIR_OUT].disable(); - if (teamB.numberOfPlayingRobots() < 3) bTeamBcmds[CMDID_TEAM_REPAIR_OUT].disable(); -} - -// ============================ - -//********************************************************************* -void buttonA_setpieces_en() -{ - for (int i=CMDID_TEAM_FREEKICK; i <= CMDID_TEAM_ISALIVE; i++) - bTeamAcmds[i].enable(); - if (forceKickoff == true) - bTeamAcmds[CMDID_TEAM_KICKOFF].enable(); - else - bTeamAcmds[CMDID_TEAM_KICKOFF].disable(); -} - -//********************************************************************* -void buttonB_setpieces_en() -{ - for (int i=CMDID_TEAM_FREEKICK; i <= CMDID_TEAM_ISALIVE; i++) - bTeamBcmds[i].enable(); - if (forceKickoff == true) - bTeamBcmds[CMDID_TEAM_KICKOFF].enable(); - else - bTeamBcmds[CMDID_TEAM_KICKOFF].disable(); -} - -//********************************************************************* -void buttonAenable() { - for (int i=0; i6 && bTeamAcmds[i].isActive()) ; //maintains goals+repair+cards - else bTeamAcmds[i].enable(); - } -} -//********************************************************************* -void buttonBenable() { - for (int i=0; i6 && bTeamBcmds[i].isActive()) ; //maintains repair+cards - else bTeamBcmds[i].enable(); - } -} - -//********************************************************************* -void buttonCenable() { - for (int i=2; i Date: Tue, 19 Apr 2022 20:02:46 +0200 Subject: [PATCH 2/2] Send WELCOME message only to team that is connecting --- mslrb2015/Comms.pde | 18 ++++++++++++++---- mslrb2015/MyServer.java | 6 ++++++ mslrb2015/Team.pde | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/mslrb2015/Comms.pde b/mslrb2015/Comms.pde index 46fc5db..79803bd 100644 --- a/mslrb2015/Comms.pde +++ b/mslrb2015/Comms.pde @@ -40,7 +40,7 @@ public static void clientValidation(MyServer whichServer, Client whichClient) { } -public static void send_to_basestation(String c, String teamIP, int robotID){ +public static void send_to_basestation(String c, String teamIP, int robotID, Client client){ JSONObject jsonObject = new JSONObject(); jsonObject.put("command", c); @@ -51,7 +51,11 @@ public static void send_to_basestation(String c, String teamIP, int robotID){ } String send = jsonObject.toString() + "\0"; System.out.println(send); - BaseStationServer.write(send); + if (client == null) { + BaseStationServer.write(send); + } else { + BaseStationServer.write(send, client); + } } public static void event_message_v2(ButtonsEnum btn, boolean on) @@ -80,8 +84,9 @@ public static void event_message_v2(ButtonsEnum btn, boolean on) msg > string with description message to send to scoreclients @mbc (check if needed) t > id of the team. If null, message is to both teams robotID > ID number of the target robot. (-1) means no robot + client > Selectively send event to one client, null is sending to all client teams */ -public static void send_event_v2(String cmd, String msg, Team t, int robotID) +public static void send_event_v2(String cmd, String msg, Team t, int robotID, Client client) { String teamIP, teamName; @@ -93,7 +98,7 @@ public static void send_event_v2(String cmd, String msg, Team t, int robotID) teamIP = t.multicastIP; teamName = t.team; } - send_to_basestation(cmd, teamIP, robotID); //send to basestation + send_to_basestation(cmd, teamIP, robotID, client); //send to basestation scoreClients.update_tEvent(cmd, msg, teamName, robotID); //send to referee client //mslRemote.update_tEvent(cmd, msg, t); //remote command @@ -103,6 +108,11 @@ public static void send_event_v2(String cmd, String msg, Team t, int robotID) } +public static void send_event_v2(String cmd, String msg, Team t, int robotID) +{ + send_event_v2(cmd, msg, t, robotID, null); +} + public static boolean setteamfromip(String s) { String clientipstr="127.0.0.*"; String[] iptokens; diff --git a/mslrb2015/MyServer.java b/mslrb2015/MyServer.java index f4c398a..147dcc2 100644 --- a/mslrb2015/MyServer.java +++ b/mslrb2015/MyServer.java @@ -407,4 +407,10 @@ public void write(String data) { } } } + + public void write(String data, Client client) { + if (client.active()) { + client.write(data); + } + } } diff --git a/mslrb2015/Team.pde b/mslrb2015/Team.pde index ab7c5ae..74ff7f5 100644 --- a/mslrb2015/Team.pde +++ b/mslrb2015/Team.pde @@ -131,7 +131,7 @@ class Team { BaseStationServer.disconnect(connectedClient); connectedClient = connectingClient; - send_event_v2(COMM_WELCOME,COMM_WELCOME, this ,-1); + send_event_v2(COMM_WELCOME, COMM_WELCOME, this , -1, connectedClient); connectingClient = null; if(this.logFile == null || this.logFileOut == null)