Added a project file for ocbuild
Got connection working! Need to implement read proper.
This commit is contained in:
parent
efe1c07cea
commit
970809f433
4 changed files with 99 additions and 2 deletions
|
|
@ -1,2 +0,0 @@
|
||||||
-- Placeholder!
|
|
||||||
|
|
||||||
14
lua/main.lua
Normal file
14
lua/main.lua
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
-- Placeholder!
|
||||||
|
|
||||||
|
require "serial"
|
||||||
|
|
||||||
|
local mt = require("thread")
|
||||||
|
|
||||||
|
|
||||||
|
modem_connect()
|
||||||
|
modem_initialize()
|
||||||
|
read_thread()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
os.exit()
|
||||||
2
lua/mcbbs.proj
Normal file
2
lua/mcbbs.proj
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
serial.lua
|
||||||
|
main.lua
|
||||||
83
lua/serial.lua
Normal file
83
lua/serial.lua
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
-- High level abstraction for our serial connection
|
||||||
|
|
||||||
|
net = require("internet")
|
||||||
|
handle = 0
|
||||||
|
STOP = false
|
||||||
|
-- io = require("io")
|
||||||
|
buffer = ""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function cleanup()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function serial_nextline()
|
||||||
|
buffer = ""
|
||||||
|
while buffer == "" do
|
||||||
|
buffer = handle:read("*l")
|
||||||
|
end
|
||||||
|
return buffer
|
||||||
|
end
|
||||||
|
|
||||||
|
function modem_connect()
|
||||||
|
handle = net.open("192.168.1.10", 8889)
|
||||||
|
if handle == nil then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function modem_initialize()
|
||||||
|
if handle == nil then
|
||||||
|
print("Modem connect fail!")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
handle:flush()
|
||||||
|
print("Initializing modem...\n")
|
||||||
|
print("[SERVER]ATZ...")
|
||||||
|
handle:write("ATZ\r") --Disable echo
|
||||||
|
|
||||||
|
modemin = ""
|
||||||
|
|
||||||
|
while modemin ~= "OK" do
|
||||||
|
modemin = serial_nextline()
|
||||||
|
io.stdout:write("[MODEM]")
|
||||||
|
print(modemin)
|
||||||
|
end
|
||||||
|
handle:setTimeout(math.huge)
|
||||||
|
print("\nModem Ready!\nIdle for ring...")
|
||||||
|
|
||||||
|
while modemin ~= "RING" do
|
||||||
|
modemin = serial_nextline()
|
||||||
|
print("[MODEM]" .. modemin)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print("Answering...\n[SERVER]ATA")
|
||||||
|
handle:write("ATA\r")
|
||||||
|
|
||||||
|
while string.find(modemin, "CONNECT") == nil do
|
||||||
|
modemin = serial_nextline()
|
||||||
|
print("[MODEM]" .. modemin)
|
||||||
|
end
|
||||||
|
|
||||||
|
print("CONNECTED!")
|
||||||
|
handle:flush()
|
||||||
|
io.stdout:flush()
|
||||||
|
-- we're connected! Say hi :)
|
||||||
|
|
||||||
|
handle:write("MCBBS0.1a\r\n")
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function read_thread()
|
||||||
|
|
||||||
|
while STOP == false do
|
||||||
|
input = serial_nextline()
|
||||||
|
print("[REMOTE]" .. input)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue