CCCPaste

StartupServer

term.setBackgroundColor(colours.black)
term.clear()
term.setCursorPos(1,1)
--
local airshipConfig = textutils.unserialize(fs.open("airshipConfig.txt",'r').readAll())
local airshipName = airshipConfig.airshipName
local airshipChannel = tonumber(airshipConfig.airshipChannel)

local modem = peripheral.wrap('top')
local wiredModem = peripheral.wrap('right')
--
local axis = {
    strafe_x = 0,
    strafe_y = 0,
    strafe_z = 0,
    --
    turn_x = 0,
    turn_y = 0,
    turn_z = 0
}

local last_axis
--

local function transmitCommand(command_axes)
    local airshipTransmission = {'airshipTransmission',airshipName,command_axes}
    --
    modem.transmit(airshipChannel,airshipChannel+1,airshipTransmission)
end

local function sendMovementCommand(command_axes)
    if command_axes ~= last_axis then
        transmitCommand(command_axes)
    end
end

--
local temp_axes = axis
wiredModem.open(airshipChannel+2)
parallel.waitForAll(function ()
    while true do
        local function handleTransmission(event, modemSide, senderChannel, replyChannel, transmission, senderDistance)
            if event == 'modem_message' and transmission[1] and transmission[1] == 'airshipTransmission' then
                if transmission[2] == airshipName then
                    print('Received Airship Command Transmission:',airshipName)
                    --
                    local command_axes = transmission[3]
                    temp_axes = command_axes

                end
            end
        end
        local airshipTransmission = handleTransmission(os.pullEvent())
    end
end,
function ()
    while true do
        sendMovementCommand(temp_axes)
        last_axis = temp_axes
        sleep(0.5)
    end
end)