Initialize modular ATM10 CC control system

This commit is contained in:
2026-07-13 02:46:11 +02:00
commit 5362d31036
28 changed files with 331 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
return {
PROTOCOL = "atm10-control",
PROTOCOL_VERSION = 1,
STATES = {
OFFLINE = "OFFLINE", STARTING = "STARTING", RUNNING = "RUNNING",
IDLE = "IDLE", STOPPING = "STOPPING", MAINTENANCE = "MAINTENANCE",
FAULT = "FAULT", EMERGENCY = "EMERGENCY", UNLOADED = "UNLOADED",
},
}
+12
View File
@@ -0,0 +1,12 @@
local M = {}
function M.write(level, message)
local line = ("[%s] %-5s %s"):format(os.date("!%Y-%m-%dT%H:%M:%SZ"), level, tostring(message))
print(line)
local handle = fs.open("runtime/control.log", "a")
if handle then handle.writeLine(line); handle.close() end
end
function M.info(message) M.write("INFO", message) end
function M.warn(message) M.write("WARN", message) end
function M.error(message) M.write("ERROR", message) end
return M
+18
View File
@@ -0,0 +1,18 @@
local constants = require("core.constants")
local protocol = require("core.protocol")
local M = {}
function M.open()
for _, name in ipairs(peripheral.getNames()) do
if peripheral.hasType(name, "modem") then rednet.open(name) end
end
return rednet.isOpen()
end
function M.broadcast(message) rednet.broadcast(message, constants.PROTOCOL) end
function M.send(id, message) return rednet.send(id, message, constants.PROTOCOL) end
function M.receive(timeout)
local sender, message = rednet.receive(constants.PROTOCOL, timeout)
if sender and protocol.valid(message) then return sender, message end
return nil, nil
end
return M
+22
View File
@@ -0,0 +1,22 @@
local constants = require("core.constants")
local M = {}
function M.message(kind, source, target, payload)
return {
protocol = constants.PROTOCOL,
version = constants.PROTOCOL_VERSION,
type = kind,
source = source,
target = target,
requestId = ("%s-%d-%d"):format(source, os.getComputerID(), os.epoch("utc")),
timestamp = os.epoch("utc"),
payload = payload or {},
}
end
function M.valid(message)
return type(message) == "table"
and message.protocol == constants.PROTOCOL
and message.version == constants.PROTOCOL_VERSION
and type(message.type) == "string"
end
return M
+19
View File
@@ -0,0 +1,19 @@
local log = require("core.log")
local network = require("core.network")
local M = {}
local function loadConfig()
if not fs.exists("config/local.lua") then error("config/local.lua fehlt") end
return dofile("config/local.lua")
end
function M.run()
if not fs.exists("runtime") then fs.makeDir("runtime") end
local config = loadConfig()
os.setComputerLabel(config.nodeName)
network.open()
local role = require("roles." .. config.role)
log.info("Starte " .. config.nodeName .. " als " .. config.role)
role.run(config)
end
return M
+6
View File
@@ -0,0 +1,6 @@
local M = {}
function M.run()
print("Updater-Schnittstelle vorbereitet; atomisches Update folgt vor v0.1.0.")
end
return M