wwtExport diff

创建于 差异永不过期
1 删除
272 行
9 添加
277 行
-- 新增外部库地址
-- 新增外部库地址
g_lfs=require('lfs')
g_lfs=require('lfs')
package.path = package.path..";"..g_lfs.writedir().."Scripts\\wwt\\?.lua"
package.path = package.path..";"..g_lfs.writedir().."Scripts\\wwt\\?.lua"
package.cpath = package.cpath..";"..g_lfs.writedir().."Scripts\\wwt\\?.dll"
package.cpath = package.cpath..";"..g_lfs.writedir().."Scripts\\wwt\\?.dll"
-- 定义dcs export函数
-- 定义dcs export函数
do
do
--初始化
--初始化
if g_winwingInit==nil then
if g_winwingInit==nil then
g_winwingInit=true
g_winwingInit=true
-- 声明
-- 声明
local _winwing={}
local _winwing={}
_winwing.selfData={}
_winwing.selfData={}
_winwing.mission=nil
_winwing.mission=nil
_winwing.mod=nil
_winwing.mod=nil
_winwing.output={}
_winwing.output={}
_winwing.common={}
_winwing.common={}
_winwing.clock=0
_winwing.clock=0
_winwing.delay=1.0
_winwing.delay=1.0
_winwing.interval=0.03
_winwing.interval=0.03
_winwing.json=loadfile("Scripts\\JSON.lua")()
_winwing.json=loadfile("Scripts\\JSON.lua")()
local _dev=nil
local _dev=nil
local _devVal=nil
local _devVal=nil
local _key=nil
local _key=nil
local _val=nil
local _val=nil
--加载网络库
--加载网络库
_winwing.net=require("wwtNetwork")
_winwing.net=require("wwtNetwork")
--启动网络
--启动网络
_winwing.net.start()
_winwing.net.start()
--网络就绪
--网络就绪
local _send={}
local _send={}
_send["func"]="net"
_send["func"]="net"
_send["msg"]="ready"
_send["msg"]="ready"
_winwing.net.send(_send)
_winwing.net.send(_send)
do
do
--定义函数
--定义函数
_winwing.LuaExportStart=function()
_winwing.LuaExportStart=function()
--记录日志
--记录日志
log.write("WWT",log.INFO,"Export start!")
log.write("WWT",log.INFO,"Export start!")
--任务就绪
--任务就绪
local _send={}
local _send={}
_send["func"]="mission"
_send["func"]="mission"
_send["msg"]="ready"
_send["msg"]="ready"
_winwing.net.send(_send)
_winwing.net.send(_send)
end
end
_winwing.LuaExportBeforeNextFrame=function()
_winwing.LuaExportBeforeNextFrame=function()
end
end


_winwing.getNet=function(t)
_winwing.getNet=function(t)
--任务开始(仅一次)
--任务开始(仅一次)
if _winwing.mission==nil then
if _winwing.mission==nil then
_winwing.mission=true
_winwing.mission=true
local _send={}
local _send={}
_send["func"]="mission"
_send["func"]="mission"
_send["msg"]="start"
_send["msg"]="start"
_winwing.net.send(_send)
_winwing.net.send(_send)
end
end
--获取机型
--获取机型
local _self=LoGetSelfData()
local _self=LoGetSelfData()
if _self~=nil then
if _self~=nil then
if _winwing.mod~=_self.Name then
if _winwing.mod~=_self.Name then
--记录机型
--记录机型
log.write("WWT",log.INFO,_self.Name)
log.write("WWT",log.INFO,_self.Name)
_winwing.mod=_self.Name
_winwing.mod=_self.Name
local _send={}
local _send={}
_send["func"]="mod"
_send["func"]="mod"
_send["msg"]=_self.Name
_send["msg"]=_self.Name
_winwing.net.send(_send)
_winwing.net.send(_send)
end
end
end
end
--接受网络数据并处理
--接受网络数据并处理
local _get=_winwing.net.get()
local _get=_winwing.net.get()
if type(_get)=="table" and _winwing.mod~=nil then
if type(_get)=="table" and _winwing.mod~=nil then
if _get["func"]=="addOutput" then--添加输出(变化输出)
if _get["func"]=="addOutput" then--添加输出(变化输出)
--遍历数据并添加
--遍历数据并添加
for _dev,_devVal in pairs(_get["args"]) do
for _dev,_devVal in pairs(_get["args"]) do
for _key,_valOld in pairs(_devVal) do
for _key,_valOld in pairs(_devVal) do
if type(_winwing.output[_dev])~="table" then
if type(_winwing.output[_dev])~="table" then
_winwing.output[_dev]={}
_winwing.output[_dev]={}
end
end
_winwing.output[_dev][_key]=_valOld
_winwing.output[_dev][_key]=_valOld
end
end
end
end
elseif _get["func"]=="getOutput" then--获取输出(仅一次)
elseif _get["func"]=="getOutput" then--获取输出(仅一次)
--遍历数据并回应
--遍历数据并回应
local _send={}
local _send={}
_send["func"]=_get["func"]
_send["func"]=_get["func"]
for _dev,_devVal in pairs(_get["args"]) do
for _dev,_devVal in pairs(_get["args"]) do
if _dev == nil or type(GetDevice(_dev))~='table' then
break
end
GetDevice(_dev):update_arguments()
GetDevice(_dev):update_arguments()
for _key,_valOld in pairs(_devVal) do
for _key,_valOld in pairs(_devVal) do
local _valNew=GetDevice(_dev):get_argument_value(_key)
local _valNew=GetDevice(_dev):get_argument_value(_key)
if type(_send["args"])~='table' then
if type(_send["args"])~='table' then
_send["args"]={}
_send["args"]={}
end
end
if type(_send["args"][_dev])~='table' then
if type(_send["args"][_dev])~='table' then
_send["args"][_dev]={}
_send["args"][_dev]={}
end
end
_send["args"][_dev][_key]=_valNew
_send["args"][_dev][_key]=_valNew
end
end