local Scheduler = require("ELScheduler") local chronos = require("chronos") local fs = require("fs") local math = require("math") local scheduler = Scheduler() local ls = require "lsocket" unix={} unix.MSG_UART_RXDATA="receive" unix.MSG_UART_TX_DONE="sent" unix.INF_TIMEOUT="int_timeout" unix.MSG_TIMER="timeout" unix.MSG_PDP_DEACT_IND="pdp_deact" unix.POWERON_CHARGER="power_charger" unix.MSG_INT="pin_int" unix.MSG_SOCK_RECV_IND="sock_recv_ind" unix.MSG_SOCK_CLOSE_CNF="sock_close_cnf" unix.MSG_SOCK_CONN_CNF="sock_conn_cnf" unix.MSG_SOCK_SEND_CNF="sock_send_cnf" unix.MSG_SOCK_CLOSE_IND="sock_close_ind" local function callback(timer) local id = timer.param end function unix.restart(...) log.debug("============== 系统马上关闭 ============",...) os.exit(0,...) end function unix.tick() return math.modf(chronos.nanotime()*1000) end function unix.get_fs_free_size(...) return 1000 end function unix.make_dir(...) return fs.mkdir(...) end function unix.set_trace_port(port) log.debug("os-unix",string.format("trace port[%d] ",port)) end function unix.poweron_reason() return unix.POWERON_CHARGER end function unix.receive(msg_id) if msg_id == unix.INF_TIMEOUT then while true do local ret,timer = scheduler:tick(unix.tick()) if ret and ret == true then local msg = nil msg = unix.MSG_TIMER return msg, timer.param end if sys.poll_socket then if type(sys.poll_socket) == "function" then msg = sys.poll_socket() elseif type(sys.poll_socket) == "table" then local func = sys.poll_socket[sys.poll_socket_index] if func then msg = func() end if sys.poll_socket_index >= #sys.poll_socket then sys.poll_socket_index = 1 else sys.poll_socket_index = sys.poll_socket_index + 1 end end return msg end ls.select({},{},0.01) end end return nil end function unix.timer_stop(id) for _, timer in ipairs(scheduler.timers) do if timer.param == id then timer:remove() end end end function unix.timer_start(id,ms) if not id or not ms then return 0 end scheduler:timer(ms, 1,nil,id) return 1 end function unix.get_version() return "virtual luat" end return unix