Przeglądaj źródła

del:删除基站定位demo

wanglong 3 lat temu
rodzic
commit
11f6048c50
3 zmienionych plików z 0 dodań i 621 usunięć
  1. 0 311
      demo/lbsLoc_demo/common.lua
  2. 0 144
      demo/lbsLoc_demo/libnet.lua
  3. 0 166
      demo/lbsLoc_demo/main.lua

+ 0 - 311
demo/lbsLoc_demo/common.lua

@@ -1,311 +0,0 @@
----模块功能:通用库函数、编码格式转换、时区时间转换
--- @module common
--- @author openLuat
--- @license MIT
--- @copyright openLuat
--- @release 2022.12.14
---定义模块,导入依赖库
-
-local common={}
-
---加载常用的全局函数至本地
-local tinsert, ssub, sbyte, schar, sformat, slen = table.insert, string.sub, string.byte, string.char, string.format, string.len
-
---- ascii字符串的unicode编码的16进制字符串 转化为 ascii字符串
--- @string inNum 待转换字符串
--- @return string data,转换后的字符串
--- @usage 
--- local data = common.ucs2ToAscii("0031003200330034")
--- data is "1234"
-function common.ucs2ToAscii(inNum)
-    local tonum = {}
-    for i = 1, slen(inNum), 4 do
-        tinsert(tonum, tonumber(ssub(inNum, i, i + 3), 16) % 256)
-    end
-    return schar(unpack(tonum))
-end
---- ascii字符串 转化为 ascii字符串的unicode编码的16进制字符串(仅支持数字和+)
--- @string inNum 待转换字符串
--- @return string data,转换后的字符串
--- @usage 
--- local data = common.nstrToUcs2Hex("+1234")
--- data is "002B0031003200330034"
-function common.nstrToUcs2Hex(inNum)
-    local hexs = ""
-    local elem = ""
-    for i = 1, slen(inNum) do
-        elem = ssub(inNum, i, i)
-        if elem == "+" then
-            hexs = hexs .. "002B"
-        else
-            hexs = hexs .. "003" .. elem
-        end
-    end
-    return hexs
-end
-
---- ASCII字符串 转化为 BCD编码格式字符串(仅支持数字)
--- @string inStr 待转换字符串
--- @number destLen 转换后的字符串期望长度,如果实际不足,则填充F
--- @return string data,转换后的字符串
--- @usage 
--- local data = common.numToBcdNum("8618126324567")
--- data is "688121364265f7" (表示第1个字节是0x68,第2个字节为0x81,......)
-function common.numToBcdNum(inStr,destLen)
-    local l,t,num = string.len(inStr or ""),{}
-    
-    destLen = destLen or (inStr:len()+1)/2
-
-    for i=1,l,2 do
-        num = tonumber(inStr:sub(i,i+1),16)
-
-        if i==l then
-            num = 0xf0+num
-        else
-            num = (num%0x10)*0x10 + (num-(num%0x10))/0x10
-        end
-
-        table.insert(t,num)
-    end
-
-    local s = string.char(unpack(t))
-
-    l = slen(s)
-    if l < destLen then
-        s = s .. string.rep("\255",destLen-l)
-    elseif l > destLen then
-        s = ssub(s,1,destLen)
-    end
-
-    return s
-end
-
---- BCD编码格式字符串 转化为 号码ASCII字符串(仅支持数字)
--- @string num 待转换字符串
--- @return string data,转换后的字符串
--- @usage 
--- local data = common.bcdNumToNum(common.fromHex("688121364265f7")) --表示第1个字节是0x68,第2个字节为0x81,......
--- data is "8618126324567"
-function common.bcdNumToNum(num)
-	local byte,v1,v2
-	local t = {}
-
-	for i=1,num:len() do
-		byte = num:byte(i)
-		v1,v2 = bit.band(byte,0x0f),bit.band(bit.rshift(byte,4),0x0f)
-
-		if v1 == 0x0f then break end
-		table.insert(t,v1)
-
-		if v2 == 0x0f then break end
-		table.insert(t,v2)
-	end
-
-	return table.concat(t)
-end
-
---- unicode小端编码 转化为 gb2312编码
--- @string ucs2s unicode小端编码数据
--- @return string data,gb2312编码数据
--- @usage local data = common.ucs2ToGb2312(ucs2s)
-function common.ucs2ToGb2312(ucs2s)
-    local cd = iconv.open("gb2312", "ucs2")
-    return cd:iconv(ucs2s)
-end
-
---- gb2312编码 转化为 unicode小端编码
--- @string gb2312s gb2312编码数据
--- @return string data,unicode小端编码数据
--- @usage local data = common.gb2312ToUcs2(gb2312s)
-function common.gb2312ToUcs2(gb2312s)
-    local cd = iconv.open("ucs2", "gb2312")
-    return cd:iconv(gb2312s)
-end
-
---- unicode大端编码 转化为 gb2312编码
--- @string ucs2s unicode大端编码数据
--- @return string data,gb2312编码数据
--- @usage data = common.ucs2beToGb2312(ucs2s)
-function common.ucs2beToGb2312(ucs2s)
-    local cd = iconv.open("gb2312", "ucs2be")
-    return cd:iconv(ucs2s)
-end
-
---- gb2312编码 转化为 unicode大端编码
--- @string gb2312s gb2312编码数据
--- @return string data,unicode大端编码数据
--- @usage local data = common.gb2312ToUcs2be(gb2312s)
-function common.gb2312ToUcs2be(gb2312s)
-    local cd = iconv.open("ucs2be", "gb2312")
-    return cd:iconv(gb2312s)
-end
-
---- unicode小端编码 转化为 utf8编码
--- @string ucs2s unicode小端编码数据
--- @return string data,utf8编码数据
--- @usage data = common.ucs2ToUtf8(ucs2s)
-function common.ucs2ToUtf8(ucs2s)
-    local cd = iconv.open("utf8", "ucs2")
-    return cd:iconv(ucs2s)
-end
-
---- utf8编码 转化为 unicode小端编码
--- @string utf8s utf8编码数据
--- @return string data,unicode小端编码数据
--- @usage local data = common.utf8ToUcs2(utf8s)
-function common.utf8ToUcs2(utf8s)
-    local cd = iconv.open("ucs2", "utf8")
-    return cd:iconv(utf8s)
-end
-
---- unicode大端编码 转化为 utf8编码
--- @string ucs2s unicode大端编码数据
--- @return string data,utf8编码数据
--- @usage data = common.ucs2beToUtf8(ucs2s)
-function common.ucs2beToUtf8(ucs2s)
-    local cd = iconv.open("utf8", "ucs2be")
-    return cd:iconv(ucs2s)
-end
-
---- utf8编码 转化为 unicode大端编码
--- @string utf8s utf8编码数据
--- @return string data,unicode大端编码数据
--- @usage local data = common.utf8ToUcs2be(utf8s)
-function common.utf8ToUcs2be(utf8s)
-    local cd = iconv.open("ucs2be", "utf8")
-    return cd:iconv(utf8s)
-end
-
---- utf8编码 转化为 gb2312编码
--- @string utf8s utf8编码数据
--- @return string data,gb2312编码数据
--- @usage local data = common.utf8ToGb2312(utf8s)
-function common.utf8ToGb2312(utf8s)
-    local cd = iconv.open("ucs2", "utf8")
-    local ucs2s = cd:iconv(utf8s)
-    cd = iconv.open("gb2312", "ucs2")
-    return cd:iconv(ucs2s)
-end
-
---- gb2312编码 转化为 utf8编码
--- @string gb2312s gb2312编码数据
--- @return string data,utf8编码数据
--- @usage local data = common.gb2312ToUtf8(gb2312s)
-function common.gb2312ToUtf8(gb2312s)
-    local cd = iconv.open("ucs2", "gb2312")
-    local ucs2s = cd:iconv(gb2312s)
-    cd = iconv.open("utf8", "ucs2")
-    return cd:iconv(ucs2s)
-end
-
-local function timeAddzone(y, m, d, hh, mm, ss, zone)
-    if not y or not m or not d or not hh or not mm or not ss then
-        return
-    end
-    hh = hh + zone
-    if hh >= 24 then
-        hh = hh - 24
-        d = d + 1
-        if m == 4 or m == 6 or m == 9 or m == 11 then
-            if d > 30 then
-                d = 1
-                m = m + 1
-            end
-        elseif m == 1 or m == 3 or m == 5 or m == 7 or m == 8 or m == 10 then
-            if d > 31 then
-                d = 1
-                m = m + 1
-            end
-        elseif m == 12 then
-            if d > 31 then
-                d = 1
-                m = 1
-                y = y + 1
-            end
-        elseif m == 2 then
-            if (((y + 2000) % 400) == 0) or (((y + 2000) % 4 == 0) and ((y + 2000) % 100 ~= 0)) then
-                if d > 29 then
-                    d = 1
-                    m = 3
-                end
-            else
-                if d > 28 then
-                    d = 1
-                    m = 3
-                end
-            end
-        end
-    end
-    local t = {}
-    t.year, t.month, t.day, t.hour, t.min, t.sec = y, m, d, hh, mm, ss
-    return t
-end
-local function timeSubZone(y, m, d, hh, mm, ss, zone)
-    if not y or not m or not d or not hh or not mm or not ss then
-        return
-    end
-    hh = hh + zone
-    if hh < 0 then
-        hh = hh + 24
-        d = d - 1
-        if m == 2 or m == 4 or m == 6 or m == 8 or m == 9 or m == 11 then
-            if d < 1 then
-                d = 31
-                m = m - 1
-            end
-        elseif m == 5 or m == 7 or m == 10 or m == 12 then
-            if d < 1 then
-                d = 30
-                m = m - 1
-            end
-        elseif m == 1 then
-            if d < 1 then
-                d = 31
-                m = 12
-                y = y - 1
-            end
-        elseif m == 3 then
-            if (((y + 2000) % 400) == 0) or (((y + 2000) % 4 == 0) and ((y + 2000) % 100 ~= 0)) then
-                if d < 1 then
-                    d = 29
-                    m = 2
-                end
-            else
-                if d < 1 then
-                    d = 28
-                    m = 2
-                end
-            end
-        end
-    end
-    local t = {}
-    t.year, t.month, t.day, t.hour, t.min, t.sec = y, m, d, hh, mm, ss
-    return t
-end
-
---- 时区时间转换
--- @number y 源时区年份
--- @number m 源时区月份
--- @number d 源时区天
--- @number hh 源时区小时
--- @number mm 源时区分
--- @number ss 源时区秒
--- @number srcTimeZone 源时区
--- @number dstTimeZone 目的时区
--- @return table dstZoneTime,返回目的时区对应的时间,{year,month,day,hour,min,sec}
--- @usage
--- local dstZoneTime = common.timeZoneConvert(2018,1,1,18,00,00,0,8)
--- dstZoneTime为{year=2018,month=1,day=2,hour=2,min=0,sec=0}
-function common.timeZoneConvert(y, m, d, hh, mm, ss, srcTimeZone, dstTimeZone)
-    local t = {}
-    local zone = dstTimeZone-srcTimeZone
-    
-    if zone >= 0 and zone < 23 then
-        t = timeAddzone(y, m, d, hh, mm, ss, zone)
-    elseif zone < 0 and zone >= -24 then
-        t = timeSubZone(y, m, d, hh, mm, ss, zone)
-    end
-    return t
-end
-
-return common

+ 0 - 144
demo/lbsLoc_demo/libnet.lua

@@ -1,144 +0,0 @@
-local libnet = {}
-
---- 阻塞等待网卡的网络连接上,只能用于任务函数中
--- @string 任务标志
--- @int 超时时间,如果==0或者空,则没有超时一致等待
--- @... 其他参数和socket.linkup一致
--- @return 失败或者超时返回false 成功返回true
-function libnet.waitLink(taskName, timeout, ...)
-	local is_err, result = socket.linkup(...)
-	if is_err then
-		return false
-	end
-	if not result then
-		result = sys_wait(taskName, socket.LINK, timeout)
-	else
-		return true
-	end
-	if type(result) == 'table' and result[2] == 0 then
-		return true
-	else
-		return false
-	end
-end
-
---- 阻塞等待IP或者域名连接上,如果加密连接还要等握手完成,只能用于任务函数中
--- @string 任务标志
--- @int 超时时间,如果==0或者空,则没有超时一致等待
--- @... 其他参数和socket.connect一致
--- @return 失败或者超时返回false 成功返回true
-function libnet.connect(taskName,timeout, ... )
-	local is_err, result = socket.connect(...)
-	if is_err then
-		return false
-	end
-	if not result then
-		result = sys_wait(taskName, socket.ON_LINE, timeout)
-	else
-		return true
-	end
-	if type(result) == 'table' and result[2] == 0 then
-		return true
-	else
-		return false
-	end
-end
-
---- 阻塞等待客户端连接上,只能用于任务函数中
--- @string 任务标志
--- @int 超时时间,如果==0或者空,则没有超时一致等待
--- @... 其他参数和socket.listen一致
--- @return 失败或者超时返回false 成功返回true
-function libnet.listen(taskName,timeout, ... )
-	local is_err, result = socket.listen(...)
-	if is_err then
-		return false
-	end
-	if not result then
-		result = sys_wait(taskName, socket.ON_LINE, timeout)
-	else
-		return true
-	end
-	if type(result) == 'table' and result[2] == 0 then
-		return true
-	else
-		return false
-	end
-end
-
---- 阻塞等待数据发送完成,只能用于任务函数中
--- @string 任务标志
--- @int 超时时间,如果==0或者空,则没有超时一致等待
--- @... 其他参数和socket.tx一致
--- @return 
--- @boolean 失败或者超时返回false,缓冲区满了或者成功返回true
--- @boolean 缓存区是否满了
-function libnet.tx(taskName,timeout, ...)
-	local is_err, is_full, result = socket.tx(...)
-	if is_err then
-		return false, is_full
-	end
-	if is_full then
-		return true, true
-	end
-	if not result then
-		result = sys_wait(taskName, socket.TX_OK, timeout)
-	else
-		return true, is_full
-	end
-	if type(result) == 'table' and result[2] == 0 then
-		return true, false
-	else
-		return false, is_full
-	end
-end
-
---- 阻塞等待新的网络事件或者特定事件,只能用于任务函数中
--- @string 任务标志
--- @int 超时时间,如果==0或者空,则没有超时一致等待
--- @... 其他参数和socket.wait一致
--- @return 
--- @boolean 网络异常返回false,其他返回true
--- @table or boolean 超时返回false,有新的数据到返回true,被其他事件退出的,返回接收到的事件
-function libnet.wait(taskName,timeout, netc)
-	local is_err, result = socket.wait(netc)
-	if is_err then
-		return false,false
-	end
-	if not result then
-		result = sys_wait(taskName, socket.EVENT, timeout)
-	else
-		return true,true
-	end
-	if type(result) == 'table' then
-		if result[2] == 0 then
-			return true, true
-		else
-			return false, false
-		end
-	else
-		return true, false
-	end
-end
-
---- 阻塞等待网络断开连接,只能用于任务函数中
--- @string 任务标志
--- @int 超时时间,如果==0或者空,则没有超时一致等待
--- @... 其他参数和socket.close一致
--- @return 无
-function libnet.close(taskName,timeout, netc)
-	local is_err, result = socket.discon(netc)
-	if is_err then
-		socket.close(netc)
-		return
-	end
-	if not result then
-		result = sys_wait(taskName, socket.CLOSED, timeout)
-	else
-		socket.close(netc)
-		return
-	end
-	socket.close(netc)
-end
-
-return libnet

+ 0 - 166
demo/lbsLoc_demo/main.lua

@@ -1,166 +0,0 @@
--- LuaTools需要PROJECT和VERSION这两个信息
-PROJECT = "lbsLoc_demo"
-VERSION = "1.0.0"
-
-local PRODUCT_KEY = "VmhtOb81EgZau6YyuuZJzwF6oUNGCbXi"
-
-log.info("main", PROJECT, VERSION)
-
--- sys库是标配
-_G.sys = require("sys")
-_G.sysplus = require("sysplus")
-
-local d1Name = "D1_TASK"
-local libnet = require "libnet"
-local common =require "common"
-local function netCB(msg)
-	log.info("未处理消息", msg[1], msg[2], msg[3], msg[4])
-end
-
-
-local function enCellInfo(s)
-    local ret,t,mcc,mnc,lac,ci,rssi,k,v,m,n,cntrssi = "",{}
-        for k,v in pairs(s) do
-            mcc,mnc,lac,ci,rssi = v.mcc,v.mnc,v.tac,v.cid,((v.rsrq + 144) >31) and 31 or (v.rsrq + 144)
-            local handle = nil
-            for k,v in pairs(t) do
-                if v.lac == lac and v.mcc == mcc and v.mnc == mnc then
-                    if #v.rssici < 8 then
-                        table.insert(v.rssici,{rssi=rssi,ci=ci})
-                    end
-                    handle = true
-                break
-                end
-            end
-            if not handle then
-                table.insert(t,{mcc=mcc,mnc=mnc,lac=lac,rssici={{rssi=rssi,ci=ci}}})
-            end
-            log.info("rssi、mcc、mnc、lac、ci", rssi,mcc,mnc,lac,ci)
-        end
-        for k,v in pairs(t) do
-            ret = ret .. pack.pack(">HHb",v.lac,v.mcc,v.mnc)
-            for m,n in pairs(v.rssici) do
-                cntrssi = bit.bor(bit.lshift(((m == 1) and (#v.rssici-1) or 0),5),n.rssi)
-                ret = ret .. pack.pack(">bi",cntrssi,n.ci)
-            end
-        end
-        --log.info("ret",json.encode(ret))
-        return string.char(#t)..ret
-end
-
-local function enWifiInfo(tWifi)
-    local ret,cnt,k,v = "",0
-    if tWifi then
-        for k,v in pairs(tWifi) do
-            log.info("lbsLoc.enWifiInfo",k,v)
-            ret = ret..pack.pack("Ab",(k:gsub(":","")):fromHex(),(v<0) and (v+255) or v)
-            cnt = cnt+1
-        end
-    end
-    return string.char(cnt)..ret
-end
-
-local function enMuid()   --获取模块MUID
-    local muid = mobile.muid()
-    return string.char(muid:len())..muid
-end
-
-local function trans(str)  --如果字符串<10,则用0补到10位
-    local s = str
-    if str:len()<10 then
-        s = str..string.rep("0",10-str:len())
-    end
-
-    return s:sub(1,3).."."..s:sub(4,10)
-end
-
------------------------------------------------------------------------------------------------------------------------------------------------------
-local function taskClient(cbFnc, reqAddr, timeout, productKey, host, port,reqTime, reqWifi)
-    while not mobile.status() do
-        if not sys.waitUntil("IP_READY", timeout) then return cbFnc(1) end
-    end
-    sys.wait(3000)
-    local reqStr = pack.pack("bAbAAAA", productKey:len(), productKey,
-                             (reqAddr and 2 or 0) + (reqTime and 4 or 0) + 8 +(reqWifi and 16 or 0) + 32, 
-                             "",
-                             common.numToBcdNum(mobile.imei()), 
-                             enMuid(),
-                             enCellInfo(mobile.getCellInfo()))
-    log.info("reqStr", reqStr:toHex())
-    local rx_buff = zbuff.create(17)
-    while true do
-        sys.wait(5000)
-        netc = socket.create(nil, d1Name) -- 创建socket对象
-        if netc then
-            log.info("创建socket对象成功")
-            socket.debug(netc, true)
-            socket.config(netc, nil, true, nil)
-            libnet.waitLink(d1Name, 0, netc)
-            local result = libnet.connect(d1Name, 15000, netc, host, port)
-            if result then
-                while true do
-                    sys.wait(20000);
-                    log.info("socket connect true")
-                    local result, isfull = libnet.tx(d1Name, 0, netc, reqStr) ---发送数据
-                    if result then
-                        sys.wait(10000);
-                        local is_err, param, _, _ = socket.rx(netc, rx_buff) -- 接收数据
-                        log.info("是否接收和数据长度", is_err, param)
-                        if not is_err and (param > 0) then -- 如果接收成功
-                            -- socket.close(netc)    --关闭连接
-                            local read_buff = rx_buff:toStr(0, param)
-                            log.info("lbsLoc receive", read_buff:toHex())
-                            if read_buff:len() >= 11 and(read_buff:byte(1) == 0 or read_buff:byte(1) ==0xFF) then
-                                local locType = read_buff:byte(1)
-                                cbFnc(0, trans(common.bcdNumToNum(read_buff:sub(2, 6))),
-                                    trans(common.bcdNumToNum(read_buff:sub(7, 11))),
-                                    reqAddr and read_buff:sub(13,12 + read_buff:byte(12)) or nil, 
-                                    read_buff:sub(reqAddr and (13 + read_buff:byte(12)) or 12, -1), 
-                                    locType)
-
-                            else
-                                log.warn("lbsLoc.query","根据基站查询经纬度失败")
-                                if read_buff:byte(1) == 2 then
-                                    log.warn("lbsLoc.query", "main.lua中的PRODUCT_KEY和此设备在iot.openluat.com中所属项目的ProductKey必须一致,请去检查")
-                                else
-                                    log.warn("lbsLoc.query","基站数据库查询不到所有小区的位置信息")
-                                    log.warn("lbsLoc.query","在trace中向上搜索encellinfo,然后在电脑浏览器中打开http://bs.openluat.com/,手动查找encellinfo后的所有小区位置")
-                                    log.warn("lbsLoc.query", "如果手动可以查到位置,则服务器存在BUG,直接向技术人员反映问题")
-                                    log.warn("lbsLoc.query","如果手动无法查到位置,则基站数据库还没有收录当前设备的小区位置信息,向技术人员反馈,我们会尽快收录")
-                                end
-                                cbFnc(5)
-                            end
-
-                        else
-                            socket.close(netc)
-                            cbFnc(4)
-                            break
-                        end
-                    else
-                        socket.close(netc)
-                        cbFnc(3) -- 发送数据失败
-                        break
-                    end
-                end
-            else
-                socket.close(netc)
-            end
-        end
-    end
-
-end
-local function cbFnc(result, lat, lng, addr, time, locType)
-    log.info("testLbsLoc.getLocCb", result, lat, lng)
-    -- 获取经纬度成功
-    if result == 0 then
-        log.info("服务器返回的时间", time:toHex())
-        log.info("定位类型,基站定位成功返回0", locType)
-        -- 失败
-    end
-
-end
-sysplus.taskInitEx(taskClient, d1Name, netCB, cbFnc,nil,20000, PRODUCT_KEY,"bs.openluat.com",12411,nil,nil)
--- 用户代码已结束---------------------------------------------
--- 结尾总是这一句
-sys.run()
--- sys.run()之后后面不要加任何语句!!!!!