From b84f271a40f97af0f3764b39f274a6402f9af6e2 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Mon, 30 May 2022 09:08:25 +0200 Subject: [PATCH] Improved installer, and added more info to readme. --- README.md | 6 ++++++ .../live/ComponentDownlinkService.java | 17 +++++++++++++++++ src/main/resources/driver/cc/installer.lua | 14 +++++++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 15ea018..320d824 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ # Rail Signal A comprehensive solution to tracking and managing your rail system, in real time. +## Setup +To set up your own Rail Signal, system, you will need to follow the following steps: +1. Download and run the Rail Signal API and web app. Go to the [releases](https://github.com/andrewlalis/RailSignalAPI/releases) page to download the latest release. Then, place the JAR file in your desired location, and run it with `java -jar rail-signal.jar`. +2. Open the web app (http://localhost:8080 by default) and create a new rail system, and add components and segments to build your network. More information about this will be given later. +3. Add components to your actual rail system, and install a driver script onto your device. For Minecraft rail systems using Immersive railroading and some computer mod, you can run `pastebin run jKyAiE8k` to run an installation script. *Please make an issue if you have a system for which there is not yet any available driver.* + ## Development To work on and develop Rail Signal, you will need to run both the Java/Spring-Boot backend API, and the Vue/Quasar frontend app. diff --git a/src/main/java/nl/andrewl/railsignalapi/live/ComponentDownlinkService.java b/src/main/java/nl/andrewl/railsignalapi/live/ComponentDownlinkService.java index a4a1b7d..b03be01 100644 --- a/src/main/java/nl/andrewl/railsignalapi/live/ComponentDownlinkService.java +++ b/src/main/java/nl/andrewl/railsignalapi/live/ComponentDownlinkService.java @@ -6,8 +6,12 @@ import nl.andrewl.railsignalapi.dao.ComponentRepository; import nl.andrewl.railsignalapi.dao.LinkTokenRepository; import nl.andrewl.railsignalapi.live.dto.ComponentDataMessage; import nl.andrewl.railsignalapi.live.dto.ComponentMessage; +import nl.andrewl.railsignalapi.live.dto.SegmentStatusMessage; +import nl.andrewl.railsignalapi.live.dto.SwitchUpdateMessage; import nl.andrewl.railsignalapi.live.websocket.AppUpdateService; import nl.andrewl.railsignalapi.model.component.Component; +import nl.andrewl.railsignalapi.model.component.Signal; +import nl.andrewl.railsignalapi.model.component.Switch; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -52,6 +56,19 @@ public class ComponentDownlinkService { downlink.send(msg); appUpdateService.sendUpdate(c.getRailSystem().getId(), msg); + // Send initial data updates to make sure that devices' state is up to date immediately. + if (c instanceof Signal sig) { + downlink.send(new SegmentStatusMessage(c.getId(), sig.getSegment().getId(), sig.getSegment().isOccupied())); + } else if (c instanceof Switch sw) { + long activeConfigId; + if (sw.getActiveConfiguration() != null) { + activeConfigId = sw.getActiveConfiguration().getId(); + } else { + activeConfigId = sw.getPossibleConfigurations().stream().findAny().orElseThrow().getId(); + } + downlink.send(new SwitchUpdateMessage(c.getId(), activeConfigId)); + } + Set downlinks = downlinksByCId.computeIfAbsent(c.getId(), aLong -> new HashSet<>()); downlinks.add(downlink); } diff --git a/src/main/resources/driver/cc/installer.lua b/src/main/resources/driver/cc/installer.lua index 2bba3af..6063adf 100644 --- a/src/main/resources/driver/cc/installer.lua +++ b/src/main/resources/driver/cc/installer.lua @@ -148,12 +148,20 @@ end -- SCRIPT START local config = {} +local args = {...} print("Rail Signal Driver Installer for CC:Tweaked") print("-------------------------------------------") -print("Please enter the base URL for your Rail System site.") -print(" For example: http://localhost:8080") -local baseUrl = readUrl() +if #args < 1 then + print("Error: Missing required baseURL argument.") + return +end +local baseUrl = args[1] config.apiUrl = baseUrl .. "/api" +local statusResponse = http.get(config.apiUrl .. "/status") +if not statusResponse then + print("Error: Could not reach the the Rail Signal system at " .. config.apiUrl .. "/status") + return +end if startsWith(baseUrl, "https") then config.wsUrl = "wss" .. string.sub(baseUrl, 6) .. "/api/ws/component" else