--- /dev/null
+local modload = "cron", "cron.entry", "schedule", "unschedule",
+ "gpio", "HIGH", "LOW", "ALARM_AUTO",
+ "mqtt.socket",
+ "math", "floor", "unregister",
+ "error", "self"
+
+local ctfws = "ctfws", "ctfws_lcd", "ctfws_tmr",
+ "setupD", "roundD", "rounds", "startT", "endT", "flagsN", "flagsR", "flagsY",
+ "times", "config", "deconfig", "setFlags", "setEndTime",
+ "GAME NOT CONFIGURED!",
+ "GAME OVER @ %02d:%02d",
+ "START TIME IN FUTURE",
+ "TIME IS UP"
+
+local lcdpreload =
+ "define_char",
+ "lcd", "mtmr", "ftmr", "dl_elapsed", "dl_elapsed", "dl_remain", "dl_round",
+ "attnState", "reset", "drawTimes", "drawFlags", "drawMessage", "drawFlagsMessage",
+ "%02d:%02d.%d", "%02d.%d", "%d", "%-20s", "%d\000: R=%s Y=%s",
+ " CMUKGB CTFWS TIMER ", " ",
+ "GAME :",
+ "SETUP :",
+ "START IN :",
+ "GAME END :",
+ "JAILBREAK :",
+ "JB# %d/%d :",
+ "JB# %2d/%2d :"
+
+local init3load =
+ "flg_tmr", "lastMsgTime", "mqttUser", "msg_tmr", "dprint", "mqc",
+ "nwfmqtt.conf",
+ "* * * * *",
+ "ctfws/game/config",
+ "ctfws/game/endtime",
+ "ctfws/game/flags",
+ "ctfws/game/message",
+ "ctfws/game/message/jail",
+ "none",
+ "^%s*(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+).*$",
+ "^%s*(%d+)%s+(%d+).*$",
+ "^%s*(%d+)%s*(.*)$",
+ "^%s*%?.*$",
+ "^ctfws/game/message",
+ "CONNECTING...", "MQTT", "MQTT CONNECTED", "MQTT Disconnected", "DHCP %s",
+ "WIFI %s", "NET", "Trying reconn...",
+ "alive", "beat %d %s"
self.endT = t
end
-return function()
- local self = {}
- self.times = times
- self.config = config
- self.deconfig = deconfig
- self.setFlags = setFlags
- self.setEndTime = setEndTime
- return self
-end
+local self = {}
+self.times = times
+self.config = config
+self.deconfig = deconfig
+self.setFlags = setFlags
+self.setEndTime = setEndTime
+return self
+if node.flashindex() == nil then
+ -- no LFS image. Perhaps it failed to flash?
+ if file.exists("luac.out.stage") and not file.exists("luac.out") then
+ -- Looks like we tried once before, indeed. Try again.
+ node.flashreload("luac.out.stage")
+ end
+end
+file.remove("luac.out.stage") -- remove stage file from last attempt
+-- Do we have a new LFS blob? If so, install it.
+if file.exists("luac.out") then
+ print("Updating LFS image. Will reboot if things go well.")
+ file.rename("luac.out", "luac.out.stage")
+ node.flashreload("luac.out.stage")
+ error("Failed to update LFS!")
+end
+
-- It's early in boot, so we have plenty of RAM. Compile
-- the rest of the firmware from source if it's there.
-dofile("compileall.lc")
+OVL.compileall()
-- Grab some configuration parameters we might need,
-- notably, the LCD address
wifi.sta.sleeptype(wifi.NONE_SLEEP) -- don't power down radio
gpio.mode(5,gpio.OUTPUT) -- beeper on GPIO14
i2c.setup(0,2,1,i2c.SLOW) -- init i2c on GPIO4 and GPIO5
-lcd = dofile("lcd1602.lc")(ctfwshw.lcd or 0x27)
+lcd = OVL.lcd1602()(ctfwshw.lcd or 0x27)
-- give the LCD time to initialize properly
-tmr.create():alarm(125, tmr.ALARM_SINGLE, function() print("init2 go3") dofile("init3.lc") end)
+tmr.create():alarm(125, tmr.ALARM_SINGLE, function() print("init2 go3") OVL.init3() end)
dprint = function(...) print(...) end -- ON
-- common module initialization
-cron.schedule("*/5 * * * *", function(e) dofile("nwfnet-sntp.lc").dosntp(nil) end)
+cron.schedule("*/5 * * * *", function(e) OVL["nwfnet-sntp"]().dosntp(nil) end)
nwfnet = require "nwfnet"
-- Game logic modules
-ctfws = dofile("ctfws.lc")()
+ctfws = OVL.ctfws()
ctfws:setFlags(0,0)
msg_tmr = tmr.create()
flg_tmr = tmr.create()
-ctfws_lcd = dofile("ctfws-lcd.lc")(ctfws, lcd, msg_tmr, flg_tmr)
+ctfws_lcd = OVL["ctfws-lcd"]()(ctfws, lcd, msg_tmr, flg_tmr)
ctfws_tmr = tmr.create()
-- Draw the default display
ctfws_lcd:drawFlagsMessage("BOOT...")
-- MQTT plumbing
-mqc, mqttUser = dofile("nwfmqtt.lc").mkclient("nwfmqtt.conf")
+mqc, mqttUser = OVL.nwfmqtt().mkclient("nwfmqtt.conf")
local mqttBootTopic = string.format("ctfws/dev/%s/beat",mqttUser)
mqc:lwt(mqttBootTopic,"dead",1,1)
local function mqtt_reconn()
dprint("Trying reconn...")
mqtt_reconn_cronentry = cron.schedule("* * * * *", function(e)
- mqc:close(); dofile("nwfmqtt.lc").connect(mqc,"nwfmqtt.conf")
+ mqc:close(); OVL.nwfmqtt().connect(mqc,"nwfmqtt.conf")
end)
- dofile("nwfmqtt.lc").connect(mqc,"nwfmqtt.conf")
+ OVL.nwfmqtt().connect(mqc,"nwfmqtt.conf")
end
local mqtt_beat_cronentry
-- hook us up to the network!
ctfws_lcd:drawFlagsMessage("CONNECTING...")
--- dofile("nwfnet-diag.lc")(true)
-dofile("nwfnet-go.lc")
+-- OVL["nwfnet-diag"]()(true)
+OVL["nwfnet-go"]()
--- /dev/null
+#!/bin/bash
+
+set -e -u
+
+SOURCES=(
+ ctfws-lfs-strings.lua
+ core/_external/lcd1602.lua
+ core/fifo/fifo.lua
+ core/net/{fifosock,nwfmqtt,nwfnet*}.lua
+ core/telnetd/telnetd{,-{diag,file}}.lua
+ core/util/compileall.lua
+ core/util/diag.lua
+ core/util/lfs-strings.lua
+)
+
+rm -rf _lfs_build
+mkdir _lfs_build
+
+# for i in ${SOURCES[@]}; do
+# lua5.1 -e "package.path=package.path..';core/_external/luasrcdiet/?.lua'" \
+# core/_external/luasrcdiet/bin/luasrcdiet $i -o _lfs_build/`basename $i` --quiet
+# done
+cp ${SOURCES[@]} _lfs_build/
+
+if [ -z "${LUACROSS:-}" ]; then
+ LUACROSS=$(readlink -f $(dirname $0)/luac.cross)
+fi
+
+if ! [ -x "${LUACROSS}" ]; then
+ echo "Need cross compiler! Tried non-existant ${LUACROSS}."
+ exit 1
+fi
+
+(cd _lfs_build; $LUACROSS -f *.lua)
+ls -l _lfs_build/luac.out
. ./core/host/pushcommon.sh
pushsrc() {
- dopushcompile core/util/compileall.lua
- dopushlua core/net/nwfmqtt.lua
- dopushlua core/_external/lcd1602.lua
dopushlua ctfws.lua
dopushlua ctfws-lcd.lua
dopushlua init3.lua
done
}
+pushlfs() {
+ if [ -z ${LUACROSS:-} ]; then
+ ./core/host/pushinit.sh
+ else
+ ./mklfs.sh
+ dopushtext _lfs_build/luac.out
+ fi
+}
+
case "${1:-}" in
all)
pushconf
pushsrc
- ./core/host/pushinit.sh
+ pushlfs
;;
both)
pushconf
src)
pushsrc
;;
+ srcmore)
+ pushsrc
+ pushlfs
+ ;;
conf)
pushconf
;;
*)
- echo "Please specify push mode: {conf,src,both,all}"
+ echo "Please specify push mode: {conf,src,srcmore,both,all}"
exit 1
;;
esac