- {this.props.clocks.map((horizontalGroup, index) => (
+ {this.props.clocks_layout.map((horizontalGroup, index) => (
{horizontalGroup.map((element, index) => {
const verticalGroup = element instanceof Array ? element : [element];
return (
{verticalGroup.map((element, index) => {
- let timestamp = this.state.local;
+ let timestamp = this.props.clock.utc;
if (element.timezone === 'sidereal-greenwich') {
- timestamp = this.state.sidereal_greenwich;
+ timestamp = this.props.clock.sidereal_greenwich;
} else if (element.timezone === 'sidereal-summit') {
- timestamp = this.state.sidereal_summit;
+ timestamp = this.props.clock.sidereal_summit;
} else if (element.timezone === 'MJD') {
- timestamp = this.state.mjd;
+ timestamp = this.props.clock.mjd;
}
- return ;
+ return ;
})}
);
diff --git a/love/src/redux/actions/actionTypes.js b/love/src/redux/actions/actionTypes.js
index 71fa756cb..53894ae70 100644
--- a/love/src/redux/actions/actionTypes.js
+++ b/love/src/redux/actions/actionTypes.js
@@ -57,3 +57,6 @@ export const CHANGE_MODE = 'CHANGE_MODE';
export const RECEIVE_OBSERVING_LOG = 'RECEIVE_OBSERVING_LOG';
export const RECEIVE_TIME_DATA = 'RECEIVE_TIME_DATA';
+export const CLOCK_START = 'CLOCK_START';
+export const CLOCK_STOP = 'CLOCK_STOP';
+export const CLOCK_TICK = 'CLOCK_TICK';
diff --git a/love/src/redux/actions/auth.js b/love/src/redux/actions/auth.js
index c1a2fa8d5..04f694176 100644
--- a/love/src/redux/actions/auth.js
+++ b/love/src/redux/actions/auth.js
@@ -15,7 +15,7 @@ import { requestViews } from './uif';
import ManagerInterface from '../../Utils';
import { getToken } from '../selectors';
import { openWebsocketConnection, closeWebsocketConnection } from './ws';
-import { receiveServerTime } from './time';
+import { receiveServerTime, clockStart } from './time';
export const requestToken = (username, password) => ({ type: REQUEST_TOKEN, username, password });
@@ -84,6 +84,7 @@ export function doReceiveToken(username, token, permissions, time_data, request_
dispatch(receiveToken(username, token, permissions));
dispatch(receiveServerTime(time_data, request_time));
dispatch(openWebsocketConnection());
+ dispatch(clockStart());
localStorage.setItem('LOVE-TOKEN', token);
};
}
diff --git a/love/src/redux/actions/time.js b/love/src/redux/actions/time.js
index 5bf3472f9..6c778883e 100644
--- a/love/src/redux/actions/time.js
+++ b/love/src/redux/actions/time.js
@@ -1,10 +1,58 @@
import { DateTime } from 'luxon';
-import { RECEIVE_TIME_DATA } from './actionTypes';
+import {
+ RECEIVE_TIME_DATA,
+ CLOCK_START,
+ CLOCK_STOP,
+ CLOCK_TICK,
+} from './actionTypes';
+import { getAllTime } from '../selectors';
+import { siderealSecond } from '../../Utils';
export function receiveServerTime(time_data, request_time) {
return (dispatch) => {
const receive_time = DateTime.utc().toMillis() / 1000;
dispatch({ type: RECEIVE_TIME_DATA, time_data, request_time, receive_time});
+ dispatch({ type: CLOCK_START, time_data, request_time, receive_time});
};
+}
+
+export function tick() {
+ return (dispatch, getState) => {
+ const time = getAllTime(getState());
+ const diffLocalUtc = DateTime.utc().toSeconds() - (time.receive_time + time.request_time) / 2;
+ dispatch({
+ type: CLOCK_TICK,
+ clock: {
+ utc: DateTime.fromSeconds(time.server_time.utc + diffLocalUtc, { zone: 'utc' }),
+ tai: DateTime.fromSeconds(time.server_time.tai + diffLocalUtc, { zone: 'utc' }),
+ mjd: time.server_time.mjd + diffLocalUtc / (3600 * 24),
+ sidereal_summit: DateTime.fromSeconds(
+ time.server_time.sidereal_summit * 3600 + siderealSecond * diffLocalUtc,
+ { zone: 'utc' }
+ ),
+ sidereal_greenwich: DateTime.fromSeconds(
+ time.server_time.sidereal_greenwich * 3600 + siderealSecond * diffLocalUtc,
+ { zone: 'utc' }
+ ),
+ }
+ });
+ }
+};
+
+let timerID = null;
+export function clockStart() {
+ return (dispatch) => {
+ clearInterval(timerID);
+ timerID = setInterval(() => dispatch(tick()), 1000);
+ dispatch({ type: CLOCK_START });
+ dispatch(tick());
+ }
+}
+
+export function clockStop() {
+ return (dispatch) => {
+ clearInterval(timerID);
+ dispatch({ type: CLOCK_STOP });
+ }
}
\ No newline at end of file
diff --git a/love/src/redux/reducers/time.js b/love/src/redux/reducers/time.js
index f700ddd58..d2e7cfa7d 100644
--- a/love/src/redux/reducers/time.js
+++ b/love/src/redux/reducers/time.js
@@ -1,8 +1,17 @@
import {
- RECEIVE_TIME_DATA
+ RECEIVE_TIME_DATA,
+ CLOCK_START,
+ CLOCK_STOP,
+ CLOCK_TICK,
} from '../actions/actionTypes';
+export const clockStatuses = {
+ STARTED: 'STARTED',
+ STOPPED: 'STOPPED',
+}
+
+
const initialState = {
request_time: 0,
receive_time: 0,
@@ -13,6 +22,14 @@ const initialState = {
sidereal_summit: 0,
sidereal_greenwich: 0,
tai_to_utc: 0,
+ },
+ clock_status: clockStatuses.STOPPED,
+ clock: {
+ utc: 0,
+ tai: 0,
+ mjd: 0,
+ sidereal_summit: 0,
+ sidereal_greenwich: 0,
}
};
/**
@@ -36,6 +53,30 @@ export default function(state = initialState, action) {
},
});
}
+ case CLOCK_START:
+ {
+ return Object.assign({}, state, {
+ clock_status: clockStatuses.STARTED,
+ });
+ }
+ case CLOCK_STOP:
+ {
+ return Object.assign({}, state, {
+ clock_status: clockStatuses.STOPPED,
+ });
+ }
+ case CLOCK_TICK:
+ {
+ return Object.assign({}, state, {
+ clock: {
+ utc: action.clock.utc,
+ tai: action.clock.tai,
+ mjd: action.clock.mjd,
+ sidereal_summit: action.clock.sidereal_summit,
+ sidereal_greenwich: action.clock.sidereal_greenwich,
+ }
+ });
+ }
default:
return state;
}
diff --git a/love/src/redux/selectors/selectors.js b/love/src/redux/selectors/selectors.js
index 2198c6196..0b5f3ac74 100644
--- a/love/src/redux/selectors/selectors.js
+++ b/love/src/redux/selectors/selectors.js
@@ -12,6 +12,10 @@ export const getServerTimeReceive = (state) => state.time.receive_time;
export const getServerTime = (state) => ({...state.time.server_time});
+export const getAllTime = (state) => ({...state.time});
+
+export const getClock = (state) => ({...state.time.clock});
+
export const getTimeData = (state) => ({
receive_time: state.time.receive_time,
request_time: state.time.request_time,