transition to kernel

This commit is contained in:
kepler155c@gmail.com
2018-01-13 15:17:26 -05:00
parent fc8d44b60d
commit bd37b57780
20 changed files with 336 additions and 223 deletions

View File

@@ -1,7 +1,10 @@
_G.requireInjector()
--[[
Adds the control-d hotkey to view the kernel log.
]]
local Terminal = require('terminal')
local Util = require('util')
local kernel = _G.kernel
local keyboard = _G.device.keyboard
@@ -9,19 +12,20 @@ local multishell = _ENV.multishell
local os = _G.os
local term = _G.term
_ENV._APP_TITLE = 'Debug'
if multishell and multishell.setTitle then
multishell.setTitle(multishell.getCurrent(), 'System Log')
end
term.redirect(Terminal.scrollable(term.current(), 50))
local tabId = multishell.getCurrent()
local routine = kernel.getCurrent()
local previousId
_G.debug = function(pattern, ...)
local oldTerm = term.current()
term.redirect(kernel.terminal)
Util.print(pattern, ...)
term.redirect(oldTerm)
end
kernel.window.reposition(1, 2)
Terminal.scrollable(kernel.window, 50)
routine.terminal = kernel.window
routine.window = kernel.window
term.redirect(routine.window)
kernel.hook('mouse_scroll', function(_, eventData)
local dir, y = eventData[1], eventData[3]
@@ -38,22 +42,15 @@ kernel.hook('mouse_scroll', function(_, eventData)
end
end)
print('Debug started')
print('Press ^d to activate debug window')
keyboard.addHotkey('control-d', function()
local currentId = multishell.getFocus()
if currentId ~= tabId then
previousId = currentId
multishell.setFocus(tabId)
local current = kernel.getFocused()
if current.uid ~= routine.uid then
previousId = current.uid
kernel.raise(routine.uid)
elseif previousId then
multishell.setFocus(previousId)
kernel.raise(previousId)
end
end)
os.pullEventRaw('terminate')
print('Debug stopped')
_G.debug = function() end
keyboard.removeHotkey('control-d')

View File

@@ -5,6 +5,7 @@ local Util = require('util')
local device = _G.device
local fs = _G.fs
local multishell = _ENV.multishell
local network = _G.network
local os = _G.os
local printError = _G.printError
@@ -13,7 +14,9 @@ if not device.wireless_modem then
return
end
_ENV._APP_TITLE = 'Net Daemon'
if multishell and multishell.setTitle then
multishell.setTitle(multishell.getCurrent(), 'Net Daemon')
end
print('Net daemon started')

View File

@@ -1,128 +0,0 @@
--[[
Low level socket protocol implementation.
* sequencing
* write acknowledgements
* background read buffering
]]--
local os = _G.os
_ENV._APP_TITLE = 'Net transport'
local computerId = os.getComputerID()
local transport = {
timers = { },
sockets = { },
}
_G.transport = transport
function transport.open(socket)
transport.sockets[socket.sport] = socket
socket.activityTimer = os.clock()
end
function transport.read(socket)
local data = table.remove(socket.messages, 1)
if data then
return unpack(data)
end
end
function transport.write(socket, data)
--debug('>> ' .. Util.tostring({ type = 'DATA', seq = socket.wseq }))
socket.transmit(socket.dport, socket.dhost, data)
--local timerId = os.startTimer(3)
--transport.timers[timerId] = socket
--socket.timers[socket.wseq] = timerId
socket.wseq = socket.wseq + 1
end
function transport.ping(socket)
--debug('>> ' .. Util.tostring({ type = 'DATA', seq = socket.wseq }))
if os.clock() - socket.activityTimer > 10 then
socket.activityTimer = os.clock()
socket.transmit(socket.dport, socket.dhost, {
type = 'PING',
seq = -1,
})
local timerId = os.startTimer(3)
transport.timers[timerId] = socket
socket.timers[-1] = timerId
end
end
function transport.close(socket)
transport.sockets[socket.sport] = nil
end
print('Net transport started')
while true do
local e, timerId, dport, dhost, msg, distance = os.pullEvent()
if e == 'timer' then
local socket = transport.timers[timerId]
if socket and socket.connected then
debug('transport timeout - closing socket ' .. socket.sport)
socket:close()
transport.timers[timerId] = nil
end
elseif e == 'modem_message' and dhost == computerId and msg then
local socket = transport.sockets[dport]
if socket and socket.connected then
--if msg.type then debug('<< ' .. Util.tostring(msg)) end
if msg.type == 'DISC' then
-- received disconnect from other end
socket.connected = false
socket:close()
elseif msg.type == 'ACK' then
local ackTimerId = socket.timers[msg.seq]
if ackTimerId then
os.cancelTimer(ackTimerId)
socket.timers[msg.seq] = nil
socket.activityTimer = os.clock()
transport.timers[ackTimerId] = nil
end
elseif msg.type == 'PING' then
socket.activityTimer = os.clock()
socket.transmit(socket.dport, socket.dhost, {
type = 'ACK',
seq = msg.seq,
})
elseif msg.type == 'DATA' and msg.data then
socket.activityTimer = os.clock()
if msg.seq ~= socket.rseq then
debug('transport seq error - closing socket ' .. socket.sport)
socket:close()
else
socket.rseq = socket.rseq + 1
table.insert(socket.messages, { msg.data, distance })
-- use resume instead ??
if not socket.messages[2] then -- table size is 1
os.queueEvent('transport_' .. socket.sport)
end
--debug('>> ' .. Util.tostring({ type = 'ACK', seq = msg.seq }))
--socket.transmit(socket.dport, socket.dhost, {
-- type = 'ACK',
-- seq = msg.seq,
--})
end
end
end
end
end