summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2017-12-27 10:51:32 +0800
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2017-12-27 10:51:32 +0800
commit96e5f8cbe57d55a274cfba1ac7f4961b29bab6fe (patch)
tree45450fcb4b27fccf0235c3a8c4bcb2f9a9d4fa56
parentceb0875f1a2c90de826450f1de127450b62bcd9b (diff)
mobile: Add lua examples for basic functions that are available
Link to Lua docs, link to our manual. Demo logging, timer, MS on/off, sms sending and sms receiving. For the MM state I will need to export constants/names to make this usable. Currently it is a bit of a hack (first time to MM_IDLE) to send a SMS. We would know when we attached though. Change-Id: I10ac656330b65e3905d6cbbb7865aa0f969cd9ff
-rw-r--r--doc/examples/mobile/lua_helloworld.lua9
-rw-r--r--doc/examples/mobile/lua_ms_on_off.lua23
-rw-r--r--doc/examples/mobile/lua_sms_on_attach.lua32
-rw-r--r--doc/examples/mobile/lua_sms_receive.lua15
-rw-r--r--doc/examples/mobile/lua_timer.lua12
5 files changed, 91 insertions, 0 deletions
diff --git a/doc/examples/mobile/lua_helloworld.lua b/doc/examples/mobile/lua_helloworld.lua
new file mode 100644
index 0000000..fd5abcc
--- /dev/null
+++ b/doc/examples/mobile/lua_helloworld.lua
@@ -0,0 +1,9 @@
+-- See https://www.lua.org/manual/5.3/ for Lua
+-- See http://ftp.osmocom.org/docs/latest/osmocombb-usermanual.pdf -- Scripting with Lua
+
+-- Standard print and log_* are forwarded to the Osmocom logging framework
+print("Hellp from Lua");
+log_notice("Notice from lua");
+log_debug("Debug from Lua");
+log_error("Error from Lua");
+log_fatal("Fatal from Lua");
diff --git a/doc/examples/mobile/lua_ms_on_off.lua b/doc/examples/mobile/lua_ms_on_off.lua
new file mode 100644
index 0000000..57e492d
--- /dev/null
+++ b/doc/examples/mobile/lua_ms_on_off.lua
@@ -0,0 +1,23 @@
+-- See https://www.lua.org/manual/5.3/ for Lua
+-- See http://ftp.osmocom.org/docs/latest/osmocombb-usermanual.pdf -- Scripting with Lua
+
+
+-- Switch the MS on/off but this can only be done if the MS
+-- is in the right state. This assumes that the MS is fully
+-- connected and doesn't stall.
+
+local start = false
+osmo.ms().start()
+function toggle_ms_state()
+ timer = osmo.timeout(20, function()
+ if start then
+ print("STARTING", osmo.ms().start())
+ start = false
+ else
+ print("STOPPING", osmo.ms().stop(true))
+ start = true
+ end
+ toggle_ms_state()
+ end)
+end
+toggle_ms_state()
diff --git a/doc/examples/mobile/lua_sms_on_attach.lua b/doc/examples/mobile/lua_sms_on_attach.lua
new file mode 100644
index 0000000..8d73f2f
--- /dev/null
+++ b/doc/examples/mobile/lua_sms_on_attach.lua
@@ -0,0 +1,32 @@
+-- See https://www.lua.org/manual/5.3/ for Lua
+-- See http://ftp.osmocom.org/docs/latest/osmocombb-usermanual.pdf -- Scripting with Lua
+
+
+-- State change
+local sent_sms = false
+function mm_cb(new_state, new_substate, old_substate)
+ -- The system has attached and returned to idle. Send a SMS the first time
+ -- it happens.
+ if new_state == 19 and new_substate == 1 then
+ if not sent_sms then
+ sent_sms = true
+ osmo.ms():sms_send_simple("1234", "21321324", "fooooooo", 23)
+ end
+ end
+end
+
+-- Called when a new SMS arrives or status for delivery
+-- is updated. Check the msg_ref field.
+function sms_cb(sms, cause, valid)
+ print("SMS data cb", sms, cause, valid)
+ for i, v in pairs(sms) do
+ print(i, v)
+ end
+end
+
+-- We need to register a callback
+local cbs = {
+ Sms=sms_cb,
+ Mm=mm_cb
+}
+osmo.ms():register(cbs)
diff --git a/doc/examples/mobile/lua_sms_receive.lua b/doc/examples/mobile/lua_sms_receive.lua
new file mode 100644
index 0000000..4be4e0a
--- /dev/null
+++ b/doc/examples/mobile/lua_sms_receive.lua
@@ -0,0 +1,15 @@
+-- See https://www.lua.org/manual/5.3/ for Lua
+-- See http://ftp.osmocom.org/docs/latest/osmocombb-usermanual.pdf -- Scripting with Lua
+
+function sms_cb(sms, cause, valid)
+ print("SMS data cb", sms, cause, valid)
+ for i, v in pairs(sms) do
+ print(i, v)
+ end
+end
+
+local cbs = {
+ Sms=sms_cb,
+}
+
+osmo.ms():register(cbs)
diff --git a/doc/examples/mobile/lua_timer.lua b/doc/examples/mobile/lua_timer.lua
new file mode 100644
index 0000000..1119af8
--- /dev/null
+++ b/doc/examples/mobile/lua_timer.lua
@@ -0,0 +1,12 @@
+-- See https://www.lua.org/manual/5.3/ for Lua
+-- See http://ftp.osmocom.org/docs/latest/osmocombb-usermanual.pdf -- Scripting with Lua
+
+-- Start and stop timer with callback. Schedule a timeout and
+-- resume execution then.
+
+-- Timeout in 10 seconds
+local timer = osmo.timeout(10, function()
+ print("Timeout occurred");
+end)
+-- We can cancel it. The callback will not be called
+timer:cancel()