|
|
@ -15,9 +15,9 @@ let score_red = 0;
|
|
|
|
let score_blue = 0;
|
|
|
|
let score_blue = 0;
|
|
|
|
let teams_red = ["6659A", "6659B"];
|
|
|
|
let teams_red = ["6659A", "6659B"];
|
|
|
|
let teams_blue = ["210Z", "210Y"];
|
|
|
|
let teams_blue = ["210Z", "210Y"];
|
|
|
|
let timer_running = false;
|
|
|
|
|
|
|
|
let timer_start = undefined;
|
|
|
|
let timer_start = undefined;
|
|
|
|
let timer_duration = undefined;
|
|
|
|
let timer_end = undefined;
|
|
|
|
|
|
|
|
let timer_next_tick = undefined;
|
|
|
|
let timer = "Scheduled";
|
|
|
|
let timer = "Scheduled";
|
|
|
|
|
|
|
|
|
|
|
|
const client = mqtt.connect("ws://127.0.0.1:8883");
|
|
|
|
const client = mqtt.connect("ws://127.0.0.1:8883");
|
|
|
@ -49,6 +49,28 @@ client.on("connect", () => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function stop_timer() {
|
|
|
|
|
|
|
|
if(timer_next_tick === undefined) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
clearInterval(timer_next_tick);
|
|
|
|
|
|
|
|
timer_next_tick = undefined;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function tick_timer() {
|
|
|
|
|
|
|
|
const now = new Date()
|
|
|
|
|
|
|
|
const time_diff = timer_end - now;
|
|
|
|
|
|
|
|
if (time_diff <= 0) {
|
|
|
|
|
|
|
|
timer = "0:00";
|
|
|
|
|
|
|
|
stop_timer();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const seconds_total = Math.ceil(time_diff/ 1000);
|
|
|
|
|
|
|
|
const minutes = Math.floor(seconds_total / 60);
|
|
|
|
|
|
|
|
const seconds = seconds_total - (minutes * 60);
|
|
|
|
|
|
|
|
timer = `${minutes}:${seconds.toString().padStart(2, '0')}`;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
client.on("message", (topic, message) => {
|
|
|
|
client.on("message", (topic, message) => {
|
|
|
|
let topic_str = topic.toString();
|
|
|
|
let topic_str = topic.toString();
|
|
|
|
let message_str = message.toString();
|
|
|
|
let message_str = message.toString();
|
|
|
@ -63,39 +85,39 @@ client.on("message", (topic, message) => {
|
|
|
|
// TODO: fill match name based off metadata
|
|
|
|
// TODO: fill match name based off metadata
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case arena_state_topic:
|
|
|
|
case arena_state_topic:
|
|
|
|
|
|
|
|
stop_timer();
|
|
|
|
|
|
|
|
|
|
|
|
const state_obj = JSON.parse(message_str);
|
|
|
|
const state_obj = JSON.parse(message_str);
|
|
|
|
// Convert seconds to ms *1000 convert ns to ms /1000000
|
|
|
|
// Convert seconds to ms *1000 convert ns to ms /1000000
|
|
|
|
const start_time = new Date((state_obj.start_s * 1000) + (state_obj.start_ns / 1000000));
|
|
|
|
const start_ms = (state_obj.start_s * 1000) + (state_obj.start_ns / 1000000);
|
|
|
|
|
|
|
|
const start_time = new Date(start_ms);
|
|
|
|
switch(state_obj.state) {
|
|
|
|
switch(state_obj.state) {
|
|
|
|
case "SCHEDULED":
|
|
|
|
case "SCHEDULED":
|
|
|
|
timer = "Scheduled";
|
|
|
|
timer = "Scheduled";
|
|
|
|
timer_running = false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "TIMEOUT":
|
|
|
|
case "TIMEOUT":
|
|
|
|
timer = "Timeout";
|
|
|
|
timer = "Timeout";
|
|
|
|
timer_running = false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "DRIVER":
|
|
|
|
case "DRIVER":
|
|
|
|
timer_running = true;
|
|
|
|
|
|
|
|
timer_start = start_time;
|
|
|
|
timer_start = start_time;
|
|
|
|
timer_duration = 105000;
|
|
|
|
timer_end = new Date(start_ms + 105000);
|
|
|
|
|
|
|
|
tick_timer();
|
|
|
|
|
|
|
|
timer_next_tick = setInterval(tick_timer, 50);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "DRIVER_DONE":
|
|
|
|
case "DRIVER_DONE":
|
|
|
|
timer = "Driver Done";
|
|
|
|
timer = "Driver Done";
|
|
|
|
timer_running = false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "AUTONOMOUS":
|
|
|
|
case "AUTONOMOUS":
|
|
|
|
timer_running = true;
|
|
|
|
|
|
|
|
timer_start = start_time;
|
|
|
|
timer_start = start_time;
|
|
|
|
timer_duration = 15000;
|
|
|
|
timer_end = new Date(start_ms + 15000);
|
|
|
|
|
|
|
|
tick_timer();
|
|
|
|
|
|
|
|
timer_next_tick = setInterval(tick_timer, 50);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "AUTONOMOUS_DONE":
|
|
|
|
case "AUTONOMOUS_DONE":
|
|
|
|
timer = "Auton Done";
|
|
|
|
timer = "Auton Done";
|
|
|
|
timer_running = false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "ABANDONED":
|
|
|
|
case "ABANDONED":
|
|
|
|
timer = "Abandoned";
|
|
|
|
timer = "Abandoned";
|
|
|
|
timer_running = false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|