#!/opt/lnxall_app/bin/lua local bit32 = require 'bit32' local posix = require 'posix' local cjson = require 'cjson' local invoker = require 'invoker' local g_tty = { [1] = '/dev/ttyACM1', [2] = '/dev/ttyACM2', [3] = '/dev/ttyACM0', [4] = '/dev/ttyS7', [5] = '/dev/ttyS5', [6] = '/dev/ttyS4', [7] = '/dev/ttyS8', [8] = '/dev/ttyS0', } local lan2selfip = '192.168.5.101' local lan3selfip = '192.168.6.101' local lan4selfip = '192.168.7.101' local lan2pingip = '192.168.5.100' local lan3pingip = '192.168.6.100' local lan4pingip = '192.168.7.100' local function netdev_hasipv4(ndev) local okay, output = invoker.invoke(invoker.OUTPUT, "ip", "addr", "show", "dev", ndev) if okay ~= 0 or type(output) ~= "string" then return false end local ipaddr = string.match(output, "inet%s+([%d%.]+)/") if not ipaddr then io.stdout:write(string.format("Error, no ipv4 found for '%s'\n", ndev)) io.stdout:flush() return false end io.stdout:write(string.format("IPv4 address found for '%s': %s\n", ndev, ipaddr)) io.stdout:flush() return true end local function test_dido() local errv0,errv1 -- set XL9555/0x23 as output invoker.invoke(0, 'i2cset', '-y', '0', '0x23', '0x6', '0x0') invoker.invoke(0, 'i2cset', '-y', '0', '0x23', '0x7', '0x0') local rval = true -- output all ones invoker.invoke(0, 'i2cset', '-y', '0', '0x23', '0x2', '0xff') invoker.invoke(0, 'i2cset', '-y', '0', '0x23', '0x3', '0xff') invoker.msleep(200) -- read input local ok0, in0 = invoker.invoke(invoker.OUTPUT + invoker.TRIMEND, 'i2cget', '-y', '0', '0x21', '0x0', 'w') if ok0 ~= 0 or in0 ~= "0x000f" then rval = false errv0 = tonumber(in0) if type(ok0) ~= "number" then ok0 = -1 end if type(in0) ~= "string" then in0 = "wtf0" end io.stdout:write(string.format("Error, DI/DO test1 has failed: %d, %s\n", ok0, in0)) io.stdout:flush() else errv0 = 0x000f end -- output all zeros invoker.invoke(0, 'i2cset', '-y', '0', '0x23', '0x2', '0x0') invoker.invoke(0, 'i2cset', '-y', '0', '0x23', '0x3', '0x0') invoker.msleep(200) -- read input local ok1, in1 = invoker.invoke(invoker.OUTPUT + invoker.TRIMEND, 'i2cget', '-y', '0', '0x21', '0x0', 'w') if ok1 ~= 0 or in1 ~= "0xfff0" then rval = false errv1 = tonumber(in1) if type(ok1) ~= "number" then ok1 = -1 end if type(in1) ~= "string" then in1 = "wtf1" end io.stdout:write(string.format("Error, DI/DO test2 has failed: %d, %s\n", ok1, in1)) io.stdout:flush() else errv1 = 0xfff0 end if rval then io.stdout:write("Test DI/DO OKAY!!!\n") io.stdout:flush() else local errv3 local error_note = "" local n = 1 if type(errv0) ~= "number" or type(errv1) ~= "number" then io.stdout:write(string.format("Error,DI/DO read empty\n")) io.stdout:flush() error_note = "all error" return rval,err_note else errv3 = bit32.bxor(errv0, errv1) end if errv3 == 0 then error_note = "all error" io.stdout:write(string.format("DI/DO is all error\n")) io.stdout:flush() else while errv3 > 0 do local remainder = errv3 % 2 if remainder == 0 then error_note = error_note .. n .. "," io.stdout:write(string.format("DI%d is error\n", n)) io.stdout:flush() end n = n + 1 errv3 = math.floor(errv3 / 2) end while n < 17 do error_note = error_note .. n .. "," io.stdout:write(string.format("DI%d is error\n", n)) io.stdout:flush() n = n + 1 end end if not error_note then error_note = "error" end io.stdout:write(string.format("D1/DO error is %s\n", error_note)) io.stdout:flush() return rval,error_note end return rval,nil end local function test_rs485(p0, p1) local wtf = posix.stat(p0) if type(wtf) ~= "table" or wtf['type'] ~= 'character device' then io.stdout:write(string.format("Error, invalid RS485 device: %s\n", p0)) io.stdout:flush() return false end wtf = posix.stat(p1) if type(wtf) ~= "table" or wtf['type'] ~= 'character device' then io.stdout:write(string.format("Error, invalid RS485 device: %s\n", p1)) io.stdout:flush() return false end -- for debian based system, we have a very strong `stty invoker.invoke(0, 'stty', '-F', p0, "raw", "9600", "cs8", "-hupcl", "-onlcr", "-iexten", "-echo", "-echoe", "-echok", "-echoctl", "-echoke", "-parenb") invoker.invoke(0, 'stty', '-F', p1, "raw", "9600", "cs8", "-hupcl", "-onlcr", "-iexten", "-echo", "-echoe", "-echok", "-echoctl", "-echoke", "-parenb") local rawstr = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' local rstr = invoker.randstr(0x8, rawstr) local tmpfile = "/tmp/tmp-" .. rstr local catpid = invoker.invoke(invoker.NOWAIT, "/bin/sh", "-c", string.format("TTY_READ=1 exec tty_rw %s > %s", p0, tmpfile)) if type(catpid) ~= "number" then io.stdout:write(string.format("Error, failed to execute 'cat %s'\n", p0)) io.stdout:flush() posix.unlink(tmpfile) return false end invoker.msleep(10) invoker.invoke(0, 'tty_rw', p1, string.format('=%s=%s=\n', rstr, rstr)) invoker.msleep(50) invoker.kill(catpid, posix.SIGKILL) invoker.kill(catpid, posix.SIGTERM) invoker.waitpid(catpid, false) local output = invoker.readfile(tmpfile, invoker.TRIMEND) posix.unlink(tmpfile) if type(output) ~= "string" or not string.find(output, rstr, 1, true) then io.stdout:write(string.format("Error, test RS485 port has failed: %s => %s\n", p1, p0)) if type(output) == "string" then io.stdout:write(string.format("\tExpected: %s, output: %s\n", rstr, output)) end io.stdout:flush() return false end io.stdout:write(string.format("INFO: test RS485 port OKAY: %s => %s\n", p1, p0)) if type(output) == "string" then io.stdout:write(string.format("\tExpected: %s, output: %s\n", rstr, output)) end io.stdout:flush() return true end local function can_get() local cans = { "can0", "can1", "lnxcan1", "lnxcan2" } local can_dev = {} for _, can in ipairs(cans) do local okay, output = invoker.invoke(invoker.OUTPUT, "ip", "addr", "show", can) if okay and type(output) == "string" then local dev = string.match(output, ":%s(.-):") if dev then can_dev[#can_dev+1] = dev end end if #can_dev == 2 then return can_dev end end return can_dev end local function setup_can(candev) invoker.invoke(0, 'ip', 'link', 'set', 'dev', candev, 'down') invoker.msleep(100) invoker.invoke(0, 'ip', 'link', 'set', 'dev', candev, 'type', 'can', 'bitrate', '500000', 'triple-sampling', 'on') invoker.msleep(100) invoker.invoke(0, 'ip', 'link', 'set', 'dev', candev, 'up') invoker.msleep(100) end local function can_test(p0, p1) setup_can(p0) setup_can(p1) local cdata = invoker.randstr(16, "12345678ABCDEF") local tmpfile = "/tmp/candump.txt" posix.unlink(tmpfile) local cpid = invoker.invoke(invoker.NOWAIT, "/bin/sh", "-c", string.format("exec candump -L -T 4000 %s > %s 2>/dev/null", p0, tmpfile)) invoker.msleep(50) invoker.invoke(0, "cangen", "-x", "-n", "3", "-I", "0x124", "-D", cdata, p1) invoker.waitpid(cpid, false) local output = invoker.readfile(tmpfile) posix.unlink(tmpfile) if type(output) ~= "string" or not string.find(output, cdata, 1, true) then io.stdout:write(string.format("Error, CAN test has failed: %s => %s\n", p1, p0)) io.stdout:flush() return false end io.stdout:write(string.format("CAN test OKAY: %s => %s\n", p1, p0)) io.stdout:flush() return true end local function update_resolv() local res = invoker.readfile('/etc/resolv.conf') local myres = "nameserver 114.114.114.114\nnameserver 8.8.8.8\n" if res ~= myres then io.stdout:write("Updating /etc/resolv.conf...\n") io.stdout:flush() local filp = io.open('/etc/resolv.conf', 'wb') if filp then filp:write(myres) filp:close() filp = nil end end return true end local function ping_with(ifname, host) if not host then host = 'mqtt.lnxall.com' end if not netdev_hasipv4(ifname) then return false end io.stdout:write(string.format("Ping '%s' with interface '%s'...\n", host, ifname)) io.stdout:flush() local cmds = { "ping", "-c10", "-I", ifname, host } local _, output = invoker.invoke(invoker.OUTPUT + invoker.NOSTDIO, cmds) if type(output) == "string" and string.find(output, "packet loss", 1, true) then if string.find(output, "100% packet loss", 1, true) then return false end return true end return false end local function get_lan_host() local ipaddr = {} local arpfile = io.open("/proc/net/arp", "rb") if not arpfile then io.stdout:write("Error, failed to open arp file.\n") io.stdout:flush() return ipaddr end for line in arpfile:lines() do if string.find(line, "br-lan", 1, true) then local ip = string.match(line, "^([%d%.]+)") if invoker.isipv4(ip) then ipaddr[#ipaddr + 1] = ip end end end if #ipaddr == 0 then io.stdout:write("Error, no device connected to LAN\n") io.stdout:flush() end return ipaddr end local function findtype(text,info) local start = string.find(text,info) if start then start_quote = string.find(text, '"', start) end_quote = string.find(text, '"', start_quote + 1) if start_quote and end_quote then final_type = string.sub(text, start_quote + 1, end_quote - 1) end return final_type else return "can't get info" end end local function findnumber(text,info) local start = string.find(text,info) if start then start = start + string.len(info) + 1 end_n = string.find(text, "\n", start) if end_n then final_number = string.sub(text, start, end_n - 1) end return final_number else return "can't get info" end end local function get_moudle_info(datj) print("MOUDLE INFO SETTINGS TEST START!") local eval,finfo = invoker.invoke(invoker.OUTPUT,"/opt/lnxall_app/platspec/moudleinfo") if eval and type(finfo) == "string" then Producer = findtype(finfo,"Producer:") if Producer == "no_modem" then datj["MOUDLE_INFO"] = nil else IMEI = findnumber(finfo,"imei info:") ICCID = findnumber(finfo,"iccid info:") SIGNAL = findnumber(finfo,"signal info:") if #ICCID < 20 then ICCID = "no sim card" sim_SP = "no sim card" else sim_SP_number = findnumber(finfo,"+COPS:") if #sim_SP_number > 10 then sim_SP = findtype(finfo,"+COPS:") else sim_SP = "sim card locked " end end if Producer == "Quectel" then _,_,moudle_4G_type = string.find(finfo,'Revision: (%w+)') end if Producer == "AirM2M" then moudle_4G_type = findtype(finfo,"+CGMM:") end end datj["MOUDLE_INFO"] = { ["IMEI"] = IMEI, ["moudle_4G_sp"] = Producer, ["moudle_4G_type"] = moudle_4G_type, ["iccid"] = ICCID, ["sim_sp"] = sim_SP, ["signal"] = SIGNAL } else print("MOUDLE INFO SETTINGS TEST FAILED!!") return false end print(datj["MOUDLE_INFO"]["IMEI"]) print(datj["MOUDLE_INFO"]["moudle_4G_sp"]) print(datj["MOUDLE_INFO"]["moudle_4G_type"]) print(datj["MOUDLE_INFO"]["iccid"]) print(datj["MOUDLE_INFO"]["sim_sp"]) print(datj["MOUDLE_INFO"]["signal"]) print("MOUDLE INFO SETTINGS TEST OK") return true end local function test_led() local result = {} local leds = { "net", "run", "wifi" } for idx = 1, 8 do local wval = string.format("%d\n", bit32.band(idx, 0x1)) for _, led in ipairs(leds) do local okay = false local ledp = string.format("/sys/class/leds/%s/brightness", led) if posix.access(ledp) == 0 then local lfile = io.open(ledp, "wb") if lfile then okay = true lfile:write(wval) lfile:close() lfile = nil end end if okay then result[led] = { interfaces = led, error_code = 0, error_msg = "success" } else result[led] = { interfaces = led, error_code = 1, error_msg = string.format("led_%s not found", led) } end end invoker.msleep(250) end local result_led = {} result_led[1] = result["net"] result_led[2] = result["run"] result_led[3] = result["wifi"] return result_led end local function write_random_file(filepath) local n = 1 local filename = filepath .. ".bin" while true do if not posix.stat(filename) then break end filename = filepath .. "_" .. n .. ".bin" n = n + 1 io.stdout:write("File exists, using filename: " .. filename .. "\n") io.stdout:flush() end local orig_md5_cmd = "dd if=/dev/urandom bs=8192 count=1 2>/dev/null | tee " .. filename .. " | md5sum - | awk '{print $1}'" local orig_md5 = io.popen(orig_md5_cmd):read("*a"):gsub("\n", "") os.execute("sync") os.execute("echo 3 > /proc/sys/vm/drop_caches") local file = io.open(filename, "rb") if not file then io.stdout:write("Failed to open file: " .. filename .. "\n") io.stdout:flush() return false end file:seek("end") local size = file:seek() file:close() if size ~= 8192 then io.stdout:write("File size is not 8192 bytes: " .. filename .. "\n") io.stdout:flush() return false end local written_md5_cmd = "md5sum " .. filename .. " | awk '{print $1}'" local written_md5 = io.popen(written_md5_cmd):read("*a"):gsub("\n", "") if orig_md5 ~= written_md5 then io.stdout:write("File content is not the same: " .. filename .. "\n") io.stdout:flush() return false end os.execute("rm -f " .. filename) io.stdout:write(string.format("%s write success.\n",filename)) io.stdout:flush() return true end local function test_ssd(level) if not invoker.mountpoint('/mnt/ssd') then io.stdout:write("SSD not mounted.\n") io.stdout:flush() return false end if not posix.stat('/dev/nvme0n1') or posix.stat('/dev/nvme0n1')['type'] ~= 'block device' then io.stdout:write("SSD not found.\n") io.stdout:flush() return false end local okay, output = invoker.invoke(invoker.OUTPUT, "nvme", "smart-log", "/dev/nvme0n1") if okay ~= 0 or type(output) ~= "string" then io.stdout:write("Failed to get SSD health data.\n") io.stdout:flush() return false end local value_spare = string.match(output, "available_spare%s*:%s*(%d+)") local value_used = string.match(output, "percentage_used%s*:%s*(%d+)") local spare_num = value_spare and tonumber(value_spare) or 0 local used_num = value_used and tonumber(value_used) or 0 if spare_num and used_num then io.stdout:write(string.format("SSD result - spare_num: %d%%, used_num: %d%%\n", spare_num, used_num)) io.stdout:flush() if level == "1" and spare_num >= 90 and used_num <= 10 then return true end if level == "0" and spare_num >= 70 and used_num <= 30 then return true end end io.stdout:write("Failed to get SSD health data or SSD not health.\n") io.stdout:flush() return false end local function search_logs() if posix.chdir("/var/log/last_syslog") == 0 then local okay, output = invoker.invoke(invoker.OUTPUT, "/bin/sh", "-c", "cat /var/log/last_syslog/kern* | grep -e 'critical medium error'") if okay == 0 and type(output) == "string" and #output > 0 then io.stdout:write("Found critical medium error!!!!!!!!!!!!!!!!!!!!!!!!!!\n") io.stdout:write("Found critical medium error!!!!!!!!!!!!!!!!!!!!!!!!!!\n") io.stdout:write("Found critical medium error!!!!!!!!!!!!!!!!!!!!!!!!!!\n") io.stdout:flush() return false end end if posix.chdir("/var/log") == 0 then if posix.stat("kern.log.1") then local okay, output = invoker.invoke(invoker.OUTPUT, "/bin/sh", "-c", "cat /var/log/last_syslog/kern* | grep -e 'critical medium error'") if okay == 0 and type(output) == "string" and #output > 0 then io.stdout:write("Found critical medium error!!!!!!!!!!!!!!!!!!!!!!!!!!\n") io.stdout:write("Found critical medium error!!!!!!!!!!!!!!!!!!!!!!!!!!\n") io.stdout:write("Found critical medium error!!!!!!!!!!!!!!!!!!!!!!!!!!\n") io.stdout:flush() return false end end end local okay, output = invoker.invoke(invoker.OUTPUT, "/bin/sh", "-c", "dmesg -T | grep -e 'critical medium error'") if okay == 0 and type(output) == "string" then io.stdout:write("Found critical medium error!!!!!!!!!!!!!!!!!!!!!!!!!!\n") io.stdout:write("Found critical medium error!!!!!!!!!!!!!!!!!!!!!!!!!!\n") io.stdout:write("Found critical medium error!!!!!!!!!!!!!!!!!!!!!!!!!!\n") io.stdout:flush() return false end return true end local function test_mmc(level) local device = "" if posix.stat('/dev/mmcblk0') and posix.stat('/dev/mmcblk0')['type'] == 'block device' then device = "/dev/mmcblk0" elseif posix.stat('/dev/mmcblk1') and posix.stat('/dev/mmcblk1')['type'] == 'block device' then device = "/dev/mmcblk1" else io.stdout:write("Error, not found mmc device\n") io.stdout:flush() return false end local okay, output = invoker.invoke(invoker.OUTPUT, "mmc", "extcsd", "read", device) if okay ~= 0 or type(output) ~= "string" then io.stdout:write("Error, failed to read MMC extcsd\n") io.stdout:flush() return false end local value_A = string.match(output, "Life Time Estimation A.-:%s*0x([%x]+)") local value_B = string.match(output, "Life Time Estimation B.-:%s*0x([%x]+)") local dec_value_A = value_A and tonumber(value_A, 16) or 0 local dec_value_B = value_B and tonumber(value_B, 16) or 0 local percent_A = dec_value_A * 10 local percent_B = dec_value_B * 10 if percent_A and percent_B then io.stdout:write(string.format("MMC result - percent_A: %d%%, percent_B: %d%%\n", percent_A, percent_B)) io.stdout:flush() if level == "1" and percent_A <= 10 and percent_B <= 10 then return true end if level == "0" and percent_A <= 30 and percent_B <= 30 then return true end end io.stdout:write("Failed to read MMC extcsd or MMC not health.\n") io.stdout:flush() return false end local function get_simnum() local cmds = { "/opt/lnxall_app/platspec/ec800g-switch-simcard.sh", "get"} local _, output = invoker.invoke(invoker.OUTPUT + invoker.NOSTDIO, cmds) if type(output) ~= "string" then return false, "can't get info" end io.stdout:write(string.format("output = %s\n", output)) io.stdout:flush() local simnum = "can't get info" local start = string.find(output,"+QDSIM:") if start then start = start + string.len("+QDSIM:") + 1 local end_n = string.find(output, "\n", start) if end_n then simnum = string.sub(output, start, end_n - 1) simnum = string.gsub(simnum,"\r","") end end if string.match(output, "ERROR: 10") or (simnum ~= "1" and simnum ~= "0") then io.stdout:write(string.format("Error, failed to get simnum %s\n", simnum)) io.stdout:flush() return false, "can't get info" end return true, simnum end local function change_using_4g(key) if not key or (key ~= "1" and key ~= "0") then io.stdout:write("Error, invaild simnum\n") io.stdout:flush() return false end local i = 0 local cmds = { "/opt/lnxall_app/platspec/ec800g-switch-simcard.sh", key } invoker.invoke(invoker.OUTPUT + invoker.NOSTDIO, cmds) invoker.msleep(300) local result, key2 = get_simnum() while(key2 ~= key) do i = i+1 if result == false then return result end invoker.invoke(invoker.OUTPUT + invoker.NOSTDIO, cmds) invoker.msleep(300) result, key2 = get_simnum() if i > 3 then io.stdout:write("Error, failed to change 4G-NET\n") io.stdout:flush() return false end end return true end local function i2c_test() local okay, result = invoker.invoke(invoker.OUTPUT, "cat", "/var/log/Xorg.0.log", "|", "grep", "-e", "goodix-ts") if okay ~= 0 or type(result) ~= "string" then io.stdout:write("Error, '' has failed.\n") io.stdout:flush() return false end return true end local function maindiag(arg1,arg2) local summary = {} local finalsummary = {} finalsummary["MOUDLE_INFO"] = {} local sim0_info = {} sim0_info["MOUDLE_INFO"] = {} local sim1_info = {} sim1_info["MOUDLE_INFO"] = {} if not arg1 then io.stdout:write("Error, invaild input, ignore 4G test.\n") io.stdout:flush() arg1 = "0" end if not arg2 then io.stdout:write("Error, invaild input, set mmc/ssd lever to 10%.\n") io.stdout:flush() arg2 = "1" end local okay, facini = invoker.invoke(invoker.OUTPUT, "factory", "get") if okay ~= 0 or type(facini) ~= "string" then io.stdout:write("Error, 'factory get' has failed.\n") io.stdout:flush() return 1 end local gwsn = string.match(facini, "SN=([^\r\n]+)") local hwver = string.match(facini, "HWVER=([^\r\n]+)") or "" local macaddr = string.match(facini, "MAC=([^\r\n]+)") or "" local gwpro = string.match(facini, "PRODUCT=([^\r\n]+)") if not gwsn or not gwpro then io.stdout:write("Error, gateway SN or PRODUCT not found.\n") io.stdout:flush() return 2 end local softver = invoker.readfile("/lib/dyiot/issue", invoker.TRIMEND) if type(softver) ~= "string" or #softver == 0 then softver = invoker.readfile("/etc/issue", invoker.TRIMEND) if type(softver) ~= "string" or #softver == 0 then softver = "unknown" end end invoker.invoke(0, "ifconfig", "br-lan:0", lan2selfip, "netmask", "255.255.255.0", "up") invoker.invoke(0, "ifconfig", "br-lan:1", lan3selfip, "netmask", "255.255.255.0", "up") invoker.invoke(0, "ifconfig", "br-lan:2", lan4selfip, "netmask", "255.255.255.0", "up") finalsummary["sn"] = gwsn finalsummary["timestamp"] = os.time() finalsummary["MAC"] = macaddr finalsummary["HWVER"] = hwver finalsummary["SWVER"] = softver summary["ioDetect"] = test_led() local ports = {} if test_rs485(g_tty[1], g_tty[2]) then ports[#ports + 1] = { interfaces = "RS485_1", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RS485_1", error_msg = "CANNOT WORK", error_code = 1 } end if test_rs485(g_tty[2], g_tty[1]) then ports[#ports + 1] = { interfaces = "RS485_2", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RS485_2", error_msg = "CANNOT WORK", error_code = 1 } end if test_rs485(g_tty[3], g_tty[4]) then ports[#ports + 1] = { interfaces = "RS485_3", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RS485_3", error_msg = "CANNOT WORK", error_code = 1 } end if test_rs485(g_tty[4], g_tty[3]) then ports[#ports + 1] = { interfaces = "RS485_4", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RS485_4", error_msg = "CANNOT WORK", error_code = 1 } end if test_rs485(g_tty[5], g_tty[6]) then ports[#ports + 1] = { interfaces = "RS485_5", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RS485_5", error_msg = "CANNOT WORK", error_code = 1 } end if test_rs485(g_tty[6], g_tty[5]) then ports[#ports + 1] = { interfaces = "RS485_6", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RS485_6", error_msg = "CANNOT WORK", error_code = 1 } end if test_rs485(g_tty[7], g_tty[8]) then ports[#ports + 1] = { interfaces = "RS485_7", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RS485_7", error_msg = "CANNOT WORK", error_code = 1 } end if test_rs485(g_tty[8], g_tty[7]) then ports[#ports + 1] = { interfaces = "RS485_8", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RS485_8", error_msg = "CANNOT WORK", error_code = 1 } end local can_dev = can_get() if not can_dev[1] or not can_dev[2] then ports[#ports + 1] = { interfaces = "CAN0", error_msg = "CANNOT WORK", error_code = 1 } ports[#ports + 1] = { interfaces = "CAN1", error_msg = "CANNOT WORK", error_code = 1 } else if can_test(can_dev[1], can_dev[2]) or can_test(can_dev[1], can_dev[2]) or can_test(can_dev[1], can_dev[2]) or can_test(can_dev[1], can_dev[2]) or can_test(can_dev[1], can_dev[2])then ports[#ports + 1] = { interfaces = "CAN0", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "CAN0", error_msg = "CANNOT WORK", error_code = 1 } end if can_test(can_dev[2], can_dev[1]) or can_test(can_dev[2], can_dev[1]) or can_test(can_dev[2], can_dev[1]) or can_test(can_dev[2], can_dev[1]) or can_test(can_dev[2], can_dev[1]) then ports[#ports + 1] = { interfaces = "CAN1", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "CAN1", error_msg = "CANNOT WORK", error_code = 1 } end end if posix.access('/dev/rtc0') == 0 then ports[#ports + 1] = { interfaces = "RTC", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RTC", error_msg = "RTC0 NOT FOUND", error_code = 1 } end local rval, binary = test_dido() if rval then ports[#ports + 1] = { interfaces = "DI_TEST", error_code = 0, error_msg = "success" } ports[#ports + 1] = { interfaces = "DO_TEST", error_code = 0, error_msg = "success" } else ports[#ports + 1] = { interfaces = "DI_TEST", error_code = 1, error_msg = binary } ports[#ports + 1] = { interfaces = "DO_TEST", error_code = 1, error_msg = binary } end if test_ssd(arg2) and write_random_file("/mnt/ssd/random_data") and search_logs() then ports[#ports + 1] = { interfaces = "SSD", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "SSD", error_msg = "NOT OKAY", error_code = 1 } end if test_mmc(arg2) and write_random_file("/random_data") then ports[#ports + 1] = { interfaces = "MMC", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "MMC", error_msg = "NOT OKAY", error_code = 1 } end summary["OnBoardPort"] = ports local netw = {} update_resolv() if ping_with('eth0') or ping_with('eth0', '114.114.114.114') then netw[#netw + 1] = { interfaces = "WAN", error_msg = "success", error_code = 0 } else netw[#netw + 1] = { interfaces = "WAN", error_msg = "NOT OKAY", error_code = 1 } end invoker.invoke(0,'nmcli', 'con', 'down' ,'wan') update_resolv() if ping_with('eth1') or ping_with('eth1', '114.114.114.114') then netw[#netw + 1] = { interfaces = "WAN2", error_msg = "success", error_code = 0 } else netw[#netw + 1] = { interfaces = "WAN2", error_msg = "NOT OKAY", error_code = 1 } end if arg1 ~= "0" then io.stdout:write(string.format("Simcard DeliveryMethood: %s\n",arg1)) io.stdout:flush() invoker.invoke(0,'nmcli', 'con', 'down' ,'wan1') invoker.msleep(1000) if string.match(hwver,"2.0") or string.match(hwver,"2.1") then update_resolv() local cmds = { "chmod", "+x", "/opt/lnxall_app/platspec/ec800g-switch-simcard.sh"} invoker.invoke(invoker.OUTPUT + invoker.NOSTDIO, cmds) local result, value = get_simnum() if not result then result, value = get_simnum() end if result and ping_with('usb0') or ping_with('usb0', '114.114.114.114') then netw[#netw + 1] = { interfaces = "4G-Net" .. value, error_msg = "success", error_code = 0 } else netw[#netw + 1] = { interfaces = "4G-Net" .. value, error_msg = "NOT OKAY", error_code = 1 } end if string.match(value,"1") then get_moudle_info(sim1_info) elseif string.match(value,"0") and arg1 == "2" then get_moudle_info(sim0_info) end local value2 = value == "1" and "0" or value == "0" and "1" or nil local result2 = change_using_4g(value2) if not result2 then result2 = change_using_4g(value2) end if result2 and ping_with('usb0') or ping_with('usb0', '114.114.114.114') then netw[#netw + 1] = { interfaces = "4G-Net" .. value2, error_msg = "success", error_code = 0 } else netw[#netw + 1] = { interfaces = "4G-Net" .. value2, error_msg = "NOT OKAY", error_code = 1 } end if string.match(value2,"1") then get_moudle_info(sim1_info) elseif string.match(value2,"0") and arg1 == "2" then get_moudle_info(sim0_info) end else update_resolv() if ping_with('usb0') or ping_with('usb0', '114.114.114.114') then netw[#netw + 1] = { interfaces = "4G-Net", error_msg = "success", error_code = 0 } else netw[#netw + 1] = { interfaces = "4G-Net", error_msg = "NOT OKAY", error_code = 1 } end end invoker.invoke(0,'nmcli', 'con', 'up' ,'wan1') end invoker.invoke(0,'nmcli', 'con', 'up' ,'wan') local landevs, lanokay = get_lan_host(), false for _, ip in pairs(landevs) do if ping_with('br-lan', ip) then lanokay = true break end end if lanokay then netw[#netw + 1] = { interfaces = "LAN", error_msg = "success", error_code = 0 } else netw[#netw + 1] = { interfaces = "LAN", error_msg = "NOT OKAY", error_code = 1 } end if ping_with('br-lan', lan2pingip) then netw[#netw + 1] = { interfaces = "LAN2", error_msg = "success", error_code = 0 } else netw[#netw + 1] = { interfaces = "LAN2", error_msg = "NOT OKAY", error_code = 1 } end if ping_with('br-lan', lan3pingip) then netw[#netw + 1] = { interfaces = "LAN3", error_msg = "success", error_code = 0 } else netw[#netw + 1] = { interfaces = "LAN3", error_msg = "NOT OKAY", error_code = 1 } end if ping_with('br-lan', lan4pingip) then netw[#netw + 1] = { interfaces = "LAN4", error_msg = "success", error_code = 0 } else netw[#netw + 1] = { interfaces = "LAN4", error_msg = "NOT OKAY", error_code = 1 } end if not string.find(gwpro,"O") then if invoker.invoke(invoker.OUTPUT,"ip", "link", "show", "dev", "wlan0") == 0 then netw[#netw + 1] = { interfaces = "wlan0", error_msg = "success", error_code = 0} else netw[#netw + 1] = { interfaces = "wlan0", error_msg = "NOT OKAY", error_code = 1} end end summary["NetWork"] = netw if string.find(gwpro,"S") then local screen = {} if i2c_test then screen[#screen + 1] = { interfaces = "goodix-ts-1", error_msg = "success", error_code = 0 } else screen[#screen + 1] = { interfaces = "goodix-ts-1", error_msg = "NOT OKAY", error_code = 1 } end summary["goodix-ts"] = screen end finalsummary["data"] = summary if arg1 ~= "0" then if string.match(hwver,"2.0") or string.match(hwver,"2.1") then finalsummary["MOUDLE_INFO"]["moudle_4G_sp"] = sim1_info["MOUDLE_INFO"]["moudle_4G_sp"] finalsummary["MOUDLE_INFO"]["moudle_4G_type"] = sim1_info["MOUDLE_INFO"]["moudle_4G_type"] finalsummary["MOUDLE_INFO"]["addid"] = sim1_info["MOUDLE_INFO"]["iccid"] finalsummary["MOUDLE_INFO"]["addsp"] = sim1_info["MOUDLE_INFO"]["sim_sp"] finalsummary["MOUDLE_INFO"]["IMEI"] = sim1_info["MOUDLE_INFO"]["IMEI"] if arg1 == "2" then finalsummary["MOUDLE_INFO"]["iccid"] = sim0_info["MOUDLE_INFO"]["iccid"] finalsummary["MOUDLE_INFO"]["sim_sp"] = sim0_info["MOUDLE_INFO"]["sim_sp"] end else get_moudle_info(finalsummary) end end io.stdout:write("\n---TEST SUMMARY---\ntest_result:") io.stdout:write(cjson.encode(finalsummary)) io.stdout:write("\n") io.stdout:flush() invoker.invoke(0, "ifconfig", "br-lan:0", lan2selfip, "netmask", "255.255.255.0", "down") invoker.invoke(0, "ifconfig", "br-lan:1", lan3selfip, "netmask", "255.255.255.0", "down") invoker.invoke(0, "ifconfig", "br-lan:2", lan4selfip, "netmask", "255.255.255.0", "down") end posix.setenv("PATH", "/opt/lnxall_app/bin:/usr/bin:/usr/sbin:/bin:/sbin", true) maindiag(arg[1],arg[2]) os.exit(0)