Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9835556e6f | ||
|
|
033da0933c |
2
.package
2
.package
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
title = "Inventory Manager",
|
title = "Inventory Manager",
|
||||||
description = "Automated inventory management system for CC:Tweaked. Tracks items across networked storage, crafting turtles, furnaces, and alerts. Includes web dashboard via bridge computer.",
|
description = "Automated inventory management system for CC:Tweaked. Tracks items across networked storage, crafting turtles, furnaces, and alerts. Includes web dashboard via bridge computer.",
|
||||||
repository = "gitea://git.spatulaa.com/MayaTheShy/Inventory-Manager-CC/main/",
|
repository = "gitea://git.spatulaa.com/MayaTheShy/Inventory-Manager-CC/stable/",
|
||||||
exclude = {
|
exclude = {
|
||||||
"^web/", "^__tests__/", "^startup/",
|
"^web/", "^__tests__/", "^startup/",
|
||||||
"%.md$", "%.json$", "^%.git", "^LICENSE$", "^node_modules/",
|
"%.md$", "%.json$", "^%.git", "^LICENSE$", "^node_modules/",
|
||||||
|
|||||||
@@ -105,10 +105,14 @@ end
|
|||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
|
|
||||||
local function sendToMaster(message)
|
local function sendToMaster(message)
|
||||||
if not networkModem then return end
|
if not networkModem then
|
||||||
|
log.warn("NET", "sendToMaster: no modem, dropping %s", tostring(message.type))
|
||||||
|
return
|
||||||
|
end
|
||||||
if not message.commandId then
|
if not message.commandId then
|
||||||
message.commandId = newCommandId()
|
message.commandId = newCommandId()
|
||||||
end
|
end
|
||||||
|
log.info("NET", "TX -> ch %d: type=%s cmdId=%s", ORDER_CHANNEL, tostring(message.type), tostring(message.commandId))
|
||||||
networkModem.transmit(ORDER_CHANNEL, CLIENT_CHANNEL, message)
|
networkModem.transmit(ORDER_CHANNEL, CLIENT_CHANNEL, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -541,14 +541,23 @@ local function main()
|
|||||||
-- Task 13: Network order/command listener
|
-- Task 13: Network order/command listener
|
||||||
function()
|
function()
|
||||||
if not ctx.networkModem then
|
if not ctx.networkModem then
|
||||||
|
log.warn("NET", "No modem — listener disabled")
|
||||||
while true do sleep(3600) end
|
while true do sleep(3600) end
|
||||||
end
|
end
|
||||||
|
log.info("NET", "Listener started on channel %d (modem: %s)", cfg.ORDER_CHANNEL, ctx.networkModemName or "?")
|
||||||
|
local cmdCount = 0
|
||||||
while true do
|
while true do
|
||||||
|
log.info("NET", "Waiting for modem_message... (handled %d so far)", cmdCount)
|
||||||
local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
|
local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
|
||||||
|
log.info("NET", "Got modem_message: side=%s ch=%d reply=%d type=%s",
|
||||||
|
tostring(side), channel or -1, replyChannel or -1,
|
||||||
|
type(message) == "table" and tostring(message.type) or type(message))
|
||||||
if channel == cfg.ORDER_CHANNEL and type(message) == "table" then
|
if channel == cfg.ORDER_CHANNEL and type(message) == "table" then
|
||||||
if isCommandDuplicate(message.commandId) then
|
if isCommandDuplicate(message.commandId) then
|
||||||
log.debug("NET", "Duplicate command skipped: %s", tostring(message.commandId))
|
log.debug("NET", "Duplicate command skipped: %s", tostring(message.commandId))
|
||||||
else
|
else
|
||||||
|
cmdCount = cmdCount + 1
|
||||||
|
log.info("NET", "Command #%d accepted: type=%s cmdId=%s", cmdCount, tostring(message.type), tostring(message.commandId))
|
||||||
recordCommandId(message.commandId)
|
recordCommandId(message.commandId)
|
||||||
cleanupCommandIds()
|
cleanupCommandIds()
|
||||||
local handlerOk, handlerErr = pcall(function()
|
local handlerOk, handlerErr = pcall(function()
|
||||||
@@ -794,8 +803,12 @@ local function main()
|
|||||||
end) -- pcall handler
|
end) -- pcall handler
|
||||||
if not handlerOk then
|
if not handlerOk then
|
||||||
log.error("NET", "Handler error: %s", tostring(handlerErr))
|
log.error("NET", "Handler error: %s", tostring(handlerErr))
|
||||||
|
else
|
||||||
|
log.info("NET", "Command #%d handled OK", cmdCount)
|
||||||
end
|
end
|
||||||
end -- idempotency else
|
end -- idempotency else
|
||||||
|
else
|
||||||
|
log.info("NET", "Ignored: ch=%d (want %d) or not table", channel or -1, cfg.ORDER_CHANNEL)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user