Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
Master robot designation display (#687)
Browse files Browse the repository at this point in the history
* update_masterRobot

* Master robot updates

* Master Robot

* update

* testing

* Save changes on masterRobot branch

* teamNumber and teamColor update

* ipAddress

* Implemented master robot designation

* Remove console.log debugging message

* Create pull request for master robot designation
  • Loading branch information
ewc340 authored and lawrencechen14 committed Apr 4, 2019
1 parent 803be86 commit 0668de0
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 2 deletions.
5 changes: 4 additions & 1 deletion dawn/main/networking/FieldControl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import io from 'socket.io-client';
import { updateRobot, updateHeart } from '../../renderer/actions/FieldActions';
import { updateRobot, updateHeart, updateMaster } from '../../renderer/actions/FieldActions';
import RendererBridge from '../RendererBridge';
import { Logger } from '../../renderer/utils/utils';
import Ansible from './Ansible';
Expand Down Expand Up @@ -33,6 +33,9 @@ class FCInternals {
this.logger.log('Trying to send FC Info to Disconnected Robot');
}
});
this.socket.on('master', (data) => {
RendererBridge.reduxDispatch(updateMaster(JSON.parse(data)));
});
});
}

Expand Down
6 changes: 6 additions & 0 deletions dawn/renderer/actions/FieldActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export const updateHeart = () => ({
type: ActionTypes.UPDATE_HEART,
});

export const updateMaster = msg => ({
type: ActionTypes.UPDATE_MASTER,
alliance: msg.alliance,
teamNumber: msg.team_number,
});

export const updateMatch = msg => ({
type: ActionTypes.UPDATE_MATCH,
matchNumber: msg.match_number,
Expand Down
4 changes: 4 additions & 0 deletions dawn/renderer/actions/InfoActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export const runtimeConnect = () => ({
type: 'RUNTIME_CONNECT',
});

export const masterStatus = () => ({
type: 'MASTER_ROBOT',
});

export const runtimeDisconnect = () => ({
type: 'RUNTIME_DISCONNECT',
});
Expand Down
3 changes: 3 additions & 0 deletions dawn/renderer/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class AppComponent extends React.Component {
<DNav
startTour={this.startTour}
runtimeStatus={this.props.runtimeStatus}
masterStatus={this.props.masterStatus}
connectionStatus={this.props.connectionStatus}
isRunningCode={this.props.isRunningCode}
/>
Expand Down Expand Up @@ -150,6 +151,7 @@ class AppComponent extends React.Component {
AppComponent.propTypes = {
connectionStatus: PropTypes.bool.isRequired,
runtimeStatus: PropTypes.bool.isRequired,
masterStatus: PropTypes.bool.isRequired,
isRunningCode: PropTypes.bool.isRequired,
asyncAlerts: PropTypes.array.isRequired,
onAlertDone: PropTypes.func.isRequired,
Expand All @@ -159,6 +161,7 @@ AppComponent.propTypes = {
const mapStateToProps = state => ({
connectionStatus: state.info.connectionStatus,
runtimeStatus: state.info.runtimeStatus,
masterStatus: state.fieldStore.masterStatus,
isRunningCode: state.info.isRunningCode,
asyncAlerts: state.asyncAlerts,
});
Expand Down
1 change: 1 addition & 0 deletions dawn/renderer/components/ConfigBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ConfigBoxComponent extends React.Component {
this.handleClose = this.handleClose.bind(this);
}


componentDidMount() {
storage.get('ipAddress', (err, data) => {
if (err) {
Expand Down
19 changes: 19 additions & 0 deletions dawn/renderer/components/DNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@ class DNavComponent extends React.Component {
return `Dawn v${VERSION}`;
}

createMaster() {
if (this.props.fieldControlStatus) {
return this.props.masterStatus;
}
return false;
}

render() {
return (
<Navbar fixedTop fluid>
<UpdateBox
isRunningCode={this.props.isRunningCode}
connectionStatus={this.props.connectionStatus}
runtimeStatus={this.props.runtimeStatus}
masterStatus={this.props.masterStatus}
shouldShow={this.state.showUpdateModal}
ipAddress={this.props.ipAddress}
hide={this.toggleUpdateModal}
Expand Down Expand Up @@ -75,6 +83,11 @@ class DNavComponent extends React.Component {
<StatusLabel
connectionStatus={this.props.connectionStatus}
runtimeStatus={this.props.runtimeStatus}
masterStatus={this.props.masterStatus}
teamColor={this.props.teamColor}
teamNumber={this.props.teamNumber}
ipAddress={this.props.ipAddress}
fieldControlStatus={this.props.fieldControlStatus}
/>
</Navbar.Text>
<Navbar.Form
Expand Down Expand Up @@ -121,16 +134,22 @@ class DNavComponent extends React.Component {
DNavComponent.propTypes = {
connectionStatus: PropTypes.bool.isRequired,
runtimeStatus: PropTypes.bool.isRequired,
masterStatus: PropTypes.bool.isRequired,
isRunningCode: PropTypes.bool.isRequired,
ipAddress: PropTypes.string.isRequired,
startTour: PropTypes.func.isRequired,
runtimeVersion: PropTypes.string.isRequired,
robotState: PropTypes.number.isRequired,
heart: PropTypes.bool.isRequired,
fieldControlStatus: PropTypes.bool.isRequired,
teamColor: PropTypes.string.isRequired,
teamNumber: PropTypes.number.isRequired,
};

const mapStateToProps = state => ({
masterStatus: state.fieldStore.masterStatus,
teamNumber: state.fieldStore.teamNumber,
teamColor: state.fieldStore.teamColor,
robotState: state.info.robotState,
heart: state.fieldStore.heart,
ipAddress: state.info.ipAddress,
Expand Down
27 changes: 26 additions & 1 deletion dawn/renderer/components/StatusLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import numeral from 'numeral';
const StatusLabelComponent = (props) => {
let labelStyle = 'default';
let labelText = 'Disconnected';
const masterRobotHeader = 'Master Robot: Team ';
const teamIP = props.ipAddress.substring(props.ipAddress.length - 2, props.ipAddress.length);
let masterRobotStyle = ' ';
if (props.teamColor === 'blue') {
masterRobotStyle = 'primary';
} else if (props.teamColor === 'gold') {
masterRobotStyle = 'warning';
}

if (props.connectionStatus) {
if (!props.runtimeStatus) {
labelStyle = 'danger';
Expand All @@ -20,7 +29,14 @@ const StatusLabelComponent = (props) => {
}
}
return (
<Label bsStyle={labelStyle}>{labelText}</Label>
<div id="parent">
<Label bsStyle={labelStyle}>{labelText}</Label>
{' '}
<Label bsStyle={masterRobotStyle !== ' ' ? masterRobotStyle : labelStyle}>
{(parseInt(teamIP, 10) === props.teamNumber &&
props.fieldControlStatus) ? masterRobotHeader + teamIP : null}
</Label>
</div>
);
};

Expand All @@ -29,12 +45,21 @@ StatusLabelComponent.propTypes = {
runtimeStatus: PropTypes.bool.isRequired,
batteryLevel: PropTypes.number.isRequired,
batterySafety: PropTypes.bool.isRequired,
teamColor: PropTypes.string.isRequired,
teamNumber: PropTypes.number.isRequired,
ipAddress: PropTypes.string.isRequired,
fieldControlStatus: PropTypes.bool.isRequired,
};


const mapStateToProps = state => ({
batteryLevel: state.peripherals.batteryLevel,
batterySafety: state.peripherals.batterySafety,
masterStatus: state.fieldStore.masterStatus,
teamNumber: state.fieldStore.teamNumber,
teamColor: state.fieldStore.teamColor,
ipAddress: state.info.ipAddress,
fieldControlStatus: state.fieldStore.fieldControl,
});

const StatusLabel = connect(mapStateToProps)(StatusLabelComponent);
Expand Down
2 changes: 2 additions & 0 deletions dawn/renderer/constants/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const PeripheralTypes = keyMirror({
BatteryBuzzer: null,
TeamFlag: null,
GameValues: null,
master: null,
});

export const ActionTypes = keyMirror({
Expand All @@ -39,6 +40,7 @@ export const ActionTypes = keyMirror({
UPDATE_HEART: null,
UPDATE_ROBOT: null,
UPDATE_MATCH: null,
UPDATE_MASTER: null,
ADD_ALERT: null,
REMOVE_ALERT: null,
CLEAR_CONSOLE: null,
Expand Down
10 changes: 10 additions & 0 deletions dawn/renderer/reducers/FieldStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ const initialFieldState = {
rTeamNumber: 0,
rTeamName: 'Unknown',
heart: false,
masterStatus: false,
mMatchNumber: 0,
mTeamNumbers: [0, 0, 0, 0],
mTeamNames: ['Offline', 'Offline', 'Offline', 'Offline'],
teamNumber: 0,
teamColor: 'Unknown',
};

const fieldStore = (state = initialFieldState, action) => {
Expand All @@ -30,6 +33,13 @@ const fieldStore = (state = initialFieldState, action) => {
...state,
heart: !state.heart,
};
case ActionTypes.UPDATE_MASTER:
return {
...state,
masterStatus: true,
teamNumber: action.teamNumber,
teamColor: action.alliance,
};
case ActionTypes.UPDATE_MATCH:
return {
...state,
Expand Down
6 changes: 6 additions & 0 deletions dawn/renderer/reducers/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const initialInfoState = {
isRunningCode: false,
connectionStatus: false,
runtimeStatus: false,
masterStatus: false,
notificationHold: 0,
fieldControlDirective: robotState.TELEOP,
fieldControlActivity: false,
Expand Down Expand Up @@ -40,6 +41,11 @@ const info = (state = initialInfoState, action) => {
...state,
runtimeStatus: true,
};
case 'MASTER_ROBOT':
return {
...state,
masterStatus: true,
};
case 'RUNTIME_DISCONNECT':
return {
...state,
Expand Down

0 comments on commit 0668de0

Please sign in to comment.