nana_sen 2 years ago
parent
commit
2226b1b1fb
10 changed files with 309 additions and 170 deletions
  1. 1 0
      .gitignore
  2. 13 0
      cmd.json
  3. 3 3
      config.lua
  4. 1 0
      g33mqtt.lua
  5. 1 1
      logModuel.lua
  6. 7 1
      main.lua
  7. 93 41
      modbusTT.lua
  8. 9 1
      mqtt_recieve.lua
  9. 3 1
      powerManage.lua
  10. 178 122
      sdModuel.lua

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+.luatide

+ 13 - 0
cmd.json

@@ -1,3 +1,16 @@
 [
     {"OpType":"directive","CntType":"Config","CntVersion":"1667360654125","Content":{"gpsLng":"120.411725","gpsLat":"30.361992", "gpsTime": 1663579568}}
+]
+
+[
+    {"OpType":"directive","CntType":"Config","CntVersion":"0","Content":{"localCntVersion":"0"}}
+]
+
+[
+    {"OpType":"directive","CntType":"SysCMD","CntVersion":"1669861389576","Content":{"cmd_content":"FormatSD"}}
+]
+
+
+[
+    {"OpType":"directive","CntType":"File","CntVersion":"1678609498695","Content":{"file_name":"/sdcard0/common/Wind-3"}}
 ]

+ 3 - 3
config.lua

@@ -9,7 +9,7 @@ otaUrl = "47.114.185.186:11113/api/site/firmware_upgrade"
 --ota升级检查周期
 otaCheckInterval = 1200
 -- 本地数据最新版本号
-localCntVersion = "1667542282722"
+localCntVersion = "1680602372206"
 localCntUpdateTime = "0"
 -- 心跳间隔/s
 heartbeatInterval = 600
@@ -17,10 +17,10 @@ restartInterval = 86400
 
 -- GPS相关
 gpsEnable = 1
-gpsLng = "120.411725"
+gpsLng = "120.605499"
 lngType = "X"
 --GPS主动定位纬度
-gpsLat = "30.361992"
+gpsLat = "32.3999"
 latType = "X"
 --gps主动定位时间
 gpsTime = 1663579568

+ 1 - 0
g33mqtt.lua

@@ -55,6 +55,7 @@ sys.taskInit(
                         ["SHEGCL/IntelligenTool/UpdateToolInfo/"..imei] = 0, 
                         ["SHEGCL/IntelligenTool/UploadWorkRecordMA/"..imei]=0,
                         ["SHEGCL/IntelligenTool/UploadWorkRecordFA/"..imei]=0,
+                        ["SHEGCL/IntelligenTool/UploadWorkRecordSimple/"..imei]=0,
                         ["SHEGCL/IntelligenTool/Heart/"..imei]=0
                     }
                     if mqttClient:subscribe(topics) then

+ 1 - 1
logModuel.lua

@@ -4,7 +4,7 @@ module(...,package.seeall)
 
 local logSize = 32 -- 单位kb
 local logDir = '/sdcard0/log' -- 日志目录
-local logCnt = 5 -- 保留日志文件个数
+local logCnt = 50 -- 保留日志文件个数
 
 function hex_tonumber(hex_str)
     local num = tonumber(hex_str, 16)

+ 7 - 1
main.lua

@@ -1,8 +1,9 @@
 PROJECT = "Rlian-GATEWAY-G33"
-VERSION = "1.0.20"
+VERSION = "1.0.35"
 PRODUCT_KEY = "ddd0422aef65441cbe1c6cccd84e2fa0"
 require 'log'
 LOG_LEVEL = log.LOGLEVEL_TRACE
+_G.COROUTINE_ERROR_RESTART = true
 require 'sys'
 
 require "ntp"
@@ -11,10 +12,14 @@ require "net"
 require "nvm"
 require "config"
 
+
+
 nvm.init("config.lua")
 --开机次数+1
 nvm.set("bootNum", nvm.get("bootNum") + 1)	
 
+net.startQueryAll(60000,600000) --1分钟查询1次信号强度,10分钟查询1次基站信息
+
 require "netLed"
 
 ntp.timeSync()
@@ -29,7 +34,7 @@ errDump.request(errorLogReportUrl,errorLogReportInterval*1000)
 require "devTool"
 require "sdModuel"
 require "logModuel"
+require "gpsTask"
 require "ledTask"
 require "g33mqtt"
 require "modbusTT"

+ 93 - 41
modbusTT.lua

@@ -95,6 +95,13 @@ end
 function getAscii2StringHexBe( str, width )
     -- body
     local hexStr = ""
+    
+    -- log.info(str)
+    if type(str) == "userdata" then
+        -- body
+        str = "\0"
+    end
+
 
     if width == 0 then
         -- body
@@ -910,7 +917,21 @@ local function query0067Res()
     -- body
     respRegAddress = "00cb"
 
-    local result, count, desc = getBaseInfo_ununique("Wind", nil, "/sdcard0/common")  
+
+    local conds = table.concat(queryCondRegValue)
+
+    local wnum = ""
+    if  #conds == 10 then
+        wnum =  getByte2AsciiStr(conds:sub(1, 10))
+    end
+    local result, count, desc
+
+    if wnum ~= "" then
+        -- body
+        result, count, desc = getBaseInfo_ununique_dim("Wind", {number=wnum}, "/sdcard0/common") 
+    else
+        result, count, desc = getBaseInfo_ununique_dim("Wind", nil, "/sdcard0/common") 
+    end
 
     queryFlagReg["0067"] = "0000"
     queryCondRegValue = {}--清空查询条件
@@ -924,40 +945,36 @@ local function query0067Res()
     end
     local fitWindTable, gpsLng, gpsLat, gpsTime = {}, nvm.get("gpsLng"), nvm.get("gpsLat"), nvm.get("gpsTime")
     
-    local fieldDisplayRadius = nvm.get("fieldDisplayRadius") or 20
+    local fieldDisplayRadius = nvm.get("fieldDisplayRadius") or 200
 
     print("aaaaaaaaaaaa")
-
-    log.info("lastWorkField",lastWorkField)
-
     if not result  then
         --无全风场列表显示上次作业风场
         -- body
         print("bbbbbbbbbbb")
         result = getBaseInfo("Wind", {number=lastWorkField}, "/sdcard0/common")
     else
-        if gpsTime == 0 or gpsTime == "0" then
+        if gpsTime == 0 or gpsTime == "0" or wnum ~= "" then
             --有风场列表,但GPS未定位成功过显示上次作业风场
             -- body
-            print("cccccccccccccc")
-            if lastWorkField ~= "" then
-                -- body
-                print("dddddddddddddd")
-                result = getBaseInfo("Wind", {number=lastWorkField}, "/sdcard0/common")
-            end
+            table.sort(result, function(l,t)
+                return l.number < t.number
+            end)
             
         else
             print("eeeeeeeeeeeeeee")
-            for k,v in pairs(result) do
-                --过滤风场列表中不在方圆20Km内的风场
-                local dist = devTool.getDistance( v.lat, v.lon, gpsLat, gpsLng)
-                log.info("dist:",dist)
-                if dist  <  fieldDisplayRadius then
-                    -- body
-                    -- log.info("cicle",v.lat)
-                    table.insert(fitWindTable, v)
-                end
-            end
+            -- for k,v in pairs(result) do
+            --     --过滤风场列表中不在方圆20Km内的风场
+            --     local dist = devTool.getDistance( v.lat, v.lon, gpsLat, gpsLng)
+            --     log.info("dist:",dist, json.encode(v))
+            --     if dist  <  fieldDisplayRadius then
+            --         -- body
+            --         -- log.info("cicle",v.lat)
+            --         v.dist = dist
+            --         table.insert(fitWindTable, v)
+            --     end
+            -- end
+            fitWindTable = result
             if table_leng(fitWindTable) == 0 then
                 --若过滤后无风场则显示上次作业风场
                 -- body
@@ -969,8 +986,11 @@ local function query0067Res()
                 end
             else
                 print("hhhhhhhhhhhhhhhhhhhhhhhh")
+                table.sort(fitWindTable, function(l,t)
+                    return l.dist < t.dist
+                end)
                 result = fitWindTable
-                log.info("fittable:", json.encode(fitWindTable))
+                -- log.info("fittable:", json.encode(fitWindTable))
             end
         end
 
@@ -1001,7 +1021,7 @@ local function query0067Res()
         end
         local nameHex = ucs2Bytes:toHex()..getAscii2StringHexBe("\0", 40-#ucs2Bytes)
         
-        log.info("number:",numberHex, "name:",nameHex)
+        -- log.info("namehex:",v.nameHex, "numberhex:",v.numberHex, "dist:", v.dist, "number", v.number, "name:", v.name)
         regValueHex = regValueHex..numberHex..nameHex
     end
 
@@ -1132,6 +1152,10 @@ local function query006aRes()
     local regValueHex = ""
     for k,v in pairs(result) do
         local ucs2Bytes = common.utf8ToUcs2be(v.name)
+        if #ucs2Bytes > 20 then
+            -- body
+            ucs2Bytes = ucs2Bytes:sub(1, 20)
+        end
         local nameHex = ucs2Bytes:toHex()..getAscii2StringHexBe("\0", 20-#ucs2Bytes)
         regValueHex = regValueHex..nameHex
     end
@@ -1160,7 +1184,9 @@ local function query006bRes()
     local fmdel = getByte2AsciiStr(conds:sub(1, 20))
     local ucs2Byte = conds:sub(21, 40)
     local Parts = ucs2deleteZero(ucs2Byte)
-    local result, count, desc = getBaseInfo_ununique("WorkingPosition", { fmodel=fmdel, Parts=Parts }, "/sdcard0/common")  
+    -- local result, count, desc = getBaseInfo_ununique("WorkingPosition", { fmodel=fmdel, Parts=Parts }, "/sdcard0/common")
+    local result, count, desc = getBaseInfo_ununique("WorkingPosition", { Parts=Parts }, "/sdcard0/common")
+    -- log.info("ddddddddddddddddddddddd--------",json.encode(result)) 
     queryFlagReg["006b"] = "0000"
     queryCondRegValue = {}--清空查询条件
     if not result then
@@ -1175,6 +1201,11 @@ local function query006bRes()
     local regValueHex = ""
     for k,v in pairs(result) do
         local ucs2Bytes = common.utf8ToUcs2be(v.name)
+
+        if #ucs2Bytes > 40 then
+            -- body
+            ucs2Bytes = ucs2Bytes:sub(1, 40)
+        end
         local nameHex = ucs2Bytes:toHex()..getAscii2StringHexBe("\0", 40-#ucs2Bytes)
         regValueHex = regValueHex..nameHex
     end
@@ -1259,8 +1290,9 @@ local function query006cRes(  )
     --     sys.publish("LOCAL_PUB_MSG", json.encode({["topic"]="SHEGCL/IntelligenTool/UploadWorkRecordMA",["data"]=upTable}))
     --     local uploadRes,msgid = sys.waitUntil("WAIT_UPDATA_RESP_SUCCESS")
     -- else
-        saveBaseInfo("wait2upload", {["topic"]="SHEGCL/IntelligenTool/UploadWorkRecordMA",["data"]=upTable,["id"]=msgid}, "/sdcard0/common/temp")
-    -- end
+        saveBaseInfo("wait2upload", {["topic"]="SHEGCL/IntelligenTool/UploadWorkRecordFA",["data"]=upTable,["id"]=msgid}, "/sdcard0/common/temp")
+        logModuel.debug_log("保存本地待上传作业记录FA, msgid:"..msgid)
+        -- end
 
     -- 工作记录表 boltTotal, fastenNm  风场编号+机位号+风机型号+部件号+工作位置
     local localRecord = {
@@ -1342,7 +1374,9 @@ local function query006dRes()
     --     -- body
     --     sys.publish("LOCAL_PUB_MSG", json.encode({["topic"]="SHEGCL/IntelligenTool/UploadWorkRecordFA",["data"]=upTable}))
     -- else
-        saveBaseInfo("wait2upload", {["topic"]="SHEGCL/IntelligenTool/UploadWorkRecordFA",["data"]=upTable,["id"]=msgid}, "/sdcard0/common/temp")
+        saveBaseInfo("wait2upload", {["topic"]="SHEGCL/IntelligenTool/UploadWorkRecordMA",["data"]=upTable,["id"]=msgid}, "/sdcard0/common/temp")
+
+        logModuel.debug_log("保存本地待上传作业记录MA, msgid:"..msgid)
     -- end
 
     -- 工作记录表 boltTotal, fastenNm  风场编号+机位号+风机型号+部件号+工作位置
@@ -1356,13 +1390,11 @@ local function query006dRes()
         bnum = upTable.BoltTotal,
         torque = upTable.FasteningTorque
     }
-    log.info("local record", json.encode(localRecord))
 
     local result,count, desc =  updateBaseInfo("WorkRecord", localRecord, "/sdcard0/"..localRecord.wnum )
 
     if not result and desc:sub(1, 29) == "this data not found where id=" then
         -- body
-        log.info("oooooooooooooooo")
         result, desc =  saveBaseInfo("WorkRecord", localRecord, "/sdcard0/"..localRecord.wnum  )
     end
     log.info("local result", result)
@@ -1387,28 +1419,26 @@ local function query006eRes()
         queryFlagReg["006e"] = "0000"
         return false
     end
+    local msgid = devTool.guid()
     local upTable = {
         Username =getByte2AsciiStr(conds:sub(1, 20)),  --用户名          string
         SetStress = tonumber(conds:sub(21,22):toHex(), 16), --设定压力bar    u16
-        FasteningStress = tonumber(conds:sub(23,24):toHex(), 16) --紧固压力bar    u16
+        FasteningStress = tonumber(conds:sub(23,24):toHex(), 16), --紧固压力bar    u16
+        msgid = msgid,
+        netWorkSaveTime = os.time(),
+        id = msgid
     }
 
     -- 待上传 upTable 全部 
-    local result
-    if socket.isReady() then
-        -- body
-        sys.publish("LOCAL_PUB_MSG", json.encode({["topic"]="SHEGCL/IntelligenTool/UploadWorkRecordSimple",["data"]=upTable}))
-        result = true
-    else
-        result = saveBaseInfo(" ", {["topic"]="SHEGCL/IntelligenTool/UploadWorkRecordSimple",["data"]=upTable}, "/sdcard0/common")
-    end
-
+    local result = saveBaseInfo("wait2upload", {["topic"]="SHEGCL/IntelligenTool/UploadWorkRecordSimple",["data"]=upTable,["id"]=msgid}, "/sdcard0/common/temp")
+    
     queryFlagReg["006e"] = "0000"
     if not result then
         -- body
         queryFlagResReg[respRegAddress] = "0002"
         logModuel.debug_log("上传维护模式操作(仅次数)记录--写本地工作记录文件失败, desc:"..desc)
     else
+        logModuel.debug_log("保存本地待上传作业记录SA, msgid:"..msgid)
         queryFlagResReg[respRegAddress] = "0001"  --结果置1表示操作成功
     end
 end
@@ -1443,11 +1473,18 @@ local function query006fRes()
     for k,v in pairs(result) do
         local pnum = getAscii2StringHexBe(v.pnum, 20)
         local ucs2Bytes = common.utf8ToUcs2be(v.info)
+
+        if #ucs2Bytes > 40 then
+            -- body
+            ucs2Bytes = ucs2Bytes:sub(1, 40)
+        end
+        
         local info = ucs2Bytes:toHex()..getAscii2StringHexBe("\0", 40-#ucs2Bytes)
         log.info("pnum:", pnum, "info:", info)
         regValueHex = regValueHex..pnum..info
     end
 
+
     local j = 1
     for i=1410, 1409 + 30*table_leng(result) do
         local regHex = string.format("%04x", i)
@@ -1488,6 +1525,20 @@ local function query0070Res()
     local wname =  common.utf8ToUcs2be(singleRes.wname)
     local parts =  common.utf8ToUcs2be(singleRes.parts)
     local work = common.utf8ToUcs2be(singleRes.work)
+
+    if #wname > 40 then
+        -- body
+        wname = wname:sub(1, 40)
+    end
+    if #parts > 20 then
+        -- body
+        parts = parts:sub(1, 20)
+    end
+    if #work > 40 then
+        -- body
+        work = work:sub(1, 40)
+    end
+
     local resT = {
         getAscii2StringHexBe(singleRes.wnum, 10),
         wname:toHex()..getAscii2StringHexBe("\0", 40-#wname),
@@ -1798,12 +1849,13 @@ sys.timerLoopStart(checkPumbHeartbeatExtra,60000)
 local heartbeatInterval = nvm.get("heartbeatInterval") or 600 
 -- 定时心跳
 sys.taskInit(function()
-    sys.wait(5000)
+    sys.wait(6000)
     while true do
         if socket.isReady() then    --连上网再开始运行
 
             -- sys.waitUntil("pub_gps_location_success_msg", 120*1000)
 
+
             local heartBeatData = getHeartbeatContent()
             log.info("pblish heartbeat msg!!!")
             sys.publish("LOCAL_PUB_MSG", json.encode({["topic"]="SHEGCL/IntelligenTool/Heart",["data"]=heartBeatData}))

+ 9 - 1
mqtt_recieve.lua

@@ -118,6 +118,11 @@ function operateFs(op, cntType, cntVersion, content )
                 opRes = true
                 sys.restart("Sever send reboot CMD! ")
             end
+            if content.cmd_content == "ResetUploadCache" then
+                -- body
+                rtos.remove_dir("/sdcard0/common/temp")
+                sys.restart("Server send ResetUploadCache CMD! ")
+            end
             if content.cmd_content == "FormatSD" then
                 -- body
                 local fg = io.format(io.SDCARD)
@@ -287,8 +292,11 @@ function uploadOfflineData(  )
                 for k,v in pairs(uploadData) do
                     sys.publish("LOCAL_PUB_MSG", json.encode(v) )
                     local uploadRes,msgid = sys.waitUntil("WAIT_UPDATA_RESP_SUCCESS", 3000)
+
+                    -- log.info("msgid:", msgid, "v.data.msgid:", v.data.msgid)
                     if  uploadRes and msgid then
-                        local re,be,ce = delBaseInfo("wait2upload",msgid,"/sdcard0/common/temp")
+                        local re,be,ce = delBaseInfo("wait2upload",v.data.msgid,"/sdcard0/common/temp")
+                        -- log.info("re:",re,"be:",be, "ce:",ce)
                     end
                     sys.wait(500)
                 end

+ 3 - 1
powerManage.lua

@@ -4,6 +4,8 @@ require "pins"
 
 local BAT_ADC_ID,DC_ADC_ID = 2,3
 
+power24Flag = nil
+
 local function powerInterrupt( msg )
     -- body
     log.info("msg:", msg)
@@ -45,7 +47,7 @@ end
 
 local function powerTaskFnc(  )
     -- body
-    sys.wait(10000)
+    sys.wait(4000)
 
     power24Flag = setGpio11Fnc()
     log.info("当前24V电平:", power24Flag)

+ 178 - 122
sdModuel.lua

@@ -192,7 +192,6 @@ function getAllFiles( dir, file )
             local fType, fName, fSize = io.readdir()
             -- log.info("file or dir",fType, fName, fSize)
             if fType == 32 then
-                -- log.info("common file", fName, fSize)
                 local tname = split(fName,'-')
                 -- log.debug('func:getAllFiles tname',tname,tname[1],tname[2])
                 if tname[1] == file then
@@ -271,6 +270,7 @@ end
         return false,count,'filename not fount'
     end
     if not dirPath then
+
         log.error('func:getBaseInfo','dirPath not fount')
         return false,count,'dirPath not fount'
     end
@@ -280,55 +280,63 @@ end
     if not files then
         return false,count,desc
     end
+    local succ_cnt = 0; --比较成功个数
     for i,file in pairs(files) do
+        local isbreak = false
         local path = dirPath..'/'..file
         local filehandle = io.open(path, "r") -- 第一个参数是文件名,第二个是打开方式,'r'读模式,'w'写模式,对数据进行覆盖,'a'附加模式,'b'加在模式后面表示以二进制形式打开
         if not filehandle then -- 判断文件是否存在
-            break --不存在 跳过 查询下个文件
+            isbreak = true
         end
         fileval = filehandle:read("*all") -- 读出文件内容
         -- print(fileval)
         if not fileval then
-                break --空文件 跳过读取下一个文件
+                isbreak = true
         end
         local filevaltable = split(fileval,delimiter)
         local table_length = table_leng(filevaltable)
         if table_length <= 1 then
-            break --无'-'标识符 跳过读取下一个文件
+            isbreak = true
         end
-        local isBreak = false
-
-        for a = 1,table_length-1 do
-            local val = json.decode(filevaltable[a])
-
-            if param then --有查询参数
-                local p_length = table_leng(param) --条件长度
-                local succ_cnt = 0; --比较成功个数
-                for p,s in pairs(param) do
-                    if filename == "Users" then
-                        if p == 'pwd' then
-                            s =  string.sub(string.upper(crypto.md5(s,#s,16)),9,24) --密码加密  加密结果32位  取16位(第9-24)字符
+        
+        -- log.info("isbreak:", isbreak, table_length)
+
+        if not isbreak then
+            -- body
+            for a = 1,table_length-1 do
+                local val = json.decode(filevaltable[a])
+    
+                if param then --有查询参数
+                    local p_length = table_leng(param) --条件长度
+                    for p,s in pairs(param) do
+                        if filename == "Users" then
+                            if p == 'pwd' then
+                                s =  string.sub(string.upper(crypto.md5(s,#s,16)),9,24) --密码加密  加密结果32位  取16位(第9-24)字符
+                            end
+                        end
+                        -- log.info("val[p] ", val[p] , "s", s, succ_cnt)
+                        if val[p] == s then
+                            succ_cnt = succ_cnt + 1
+                        else
+                            break
                         end
                     end
-                    if val[p] == s then
-                        succ_cnt = succ_cnt + 1
-                    else
+                    if p_length == succ_cnt then --找到结果 停止继续查找下个文件
+                        selectRes[i] = val
+                        isbreak = true
                         break
                     end
-                end
-                if p_length == succ_cnt then --找到结果 停止继续查找下个文件
+                else --无查询参数  查询所有
                     selectRes[i] = val
-                    isBreak = true
-                    break
                 end
-            else --无查询参数  查询所有
-                selectRes[i] = val
             end
         end
+
+
         count = i
-        if isBreak then --找到结果 停止继续查找下个文件
-            break;
-        end
+        -- if isbreak then --找到结果 停止继续查找下个文件
+        --     break;
+        -- end
         filehandle:close() -- 关闭文件
     end
     -- print(table_leng(selectRes),json.encode(selectRes))
@@ -359,49 +367,57 @@ function getBaseInfo_ununique( filename,param,dirPath)
     if not files then
         return false,count,desc
     end
+    local succ_cnt = 0; --比较成功个数
     for i,file in pairs(files) do
+        local isbreak = false
         local path = dirPath..'/'..file
         local filehandle = io.open(path, "r") -- 第一个参数是文件名,第二个是打开方式,'r'读模式,'w'写模式,对数据进行覆盖,'a'附加模式,'b'加在模式后面表示以二进制形式打开
         if not filehandle then -- 判断文件是否存在
-            break --不存在 跳过 查询下个文件
+            isbreak = true
         end
         fileval = filehandle:read("*all") -- 读出文件内容
         -- print(fileval)
         if not fileval then
-                break --空文件 跳过读取下一个文件
+                isbreak = true
         end
         local filevaltable = split(fileval,delimiter)
         local table_length = table_leng(filevaltable)
         if table_length <= 1 then
-            break --无'-'标识符 跳过读取下一个文件
+            isbreak = true
         end
-        local isBreak = false
-
-        for a = 1,table_length-1 do
-            local val = json.decode(filevaltable[a])
+        
 
-            if param then --有查询参数
-                local p_length = table_leng(param) --条件长度
-                local succ_cnt = 0; --比较成功个数
-                for p,s in pairs(param) do
+        if not isbreak then
+            -- body
+            for a = 1,table_length-1 do
+                local val = json.decode(filevaltable[a])
+                succ_cnt = 0
+                if param then --有查询参数
+                    local p_length = table_leng(param) --条件长度
+                    for p,s in pairs(param) do
 
-                    if val[p] == s then
-                        succ_cnt = succ_cnt + 1
-                    else
-                        break
+                         
+    
+                        if val[p] == s then
+                            -- log.info("val[p]:", val[p], "s:",s)
+                            succ_cnt = succ_cnt + 1
+                        else
+                            break
+                        end
                     end
-                end
-
-                if p_length == succ_cnt then --找到结果 停止继续查找下个文件
+    
+                    if p_length == succ_cnt then --找到结果 停止继续查找下个文件
+                        table.insert(selectRes, val)
+                    end
+                    
+                else --无查询参数  查询所有
                     table.insert(selectRes, val)
                 end
-                
-            else --无查询参数  查询所有
-                table.insert(selectRes, val)
             end
         end
+
         count = i
-        -- if isBreak then --找到结果 停止继续查找下个文件
+        -- if isbreak then --找到结果 停止继续查找下个文件
         --     break;
         -- end
         filehandle:close() -- 关闭文件
@@ -434,67 +450,97 @@ function getBaseInfo_ununique_dim( filename,param,dirPath)
     if not files then
         return false,count,desc
     end
+    local succ_cnt = 0; --比较成功个数
     for i,file in pairs(files) do
+        local isbreak = false
         local path = dirPath..'/'..file
         local filehandle = io.open(path, "r") -- 第一个参数是文件名,第二个是打开方式,'r'读模式,'w'写模式,对数据进行覆盖,'a'附加模式,'b'加在模式后面表示以二进制形式打开
         if not filehandle then -- 判断文件是否存在
-            break --不存在 跳过 查询下个文件
+            isbreak = true
+            -- isbreak = true
         end
         fileval = filehandle:read("*all") -- 读出文件内容
         -- print(fileval)
         if not fileval then
-                break --空文件 跳过读取下一个文件
+            isbreak = true
+            -- isbreak = true
         end
         local filevaltable = split(fileval,delimiter)
         local table_length = table_leng(filevaltable)
         if table_length <= 1 then
-            break --无'-'标识符 跳过读取下一个文件
+            isbreak = true
+            -- isbreak = true
         end
-        local isBreak = false
-
-        for a = 1,table_length-1 do
-            local val = json.decode(filevaltable[a])
-
-            if param then --有查询参数
-                local p_length = table_leng(param) --条件长度
-                local succ_cnt = 0; --比较成功个数
-                local pattern = ""
-                for p,s in pairs(param) do
-
-                    if succ_cnt > 19 then
-                        -- body
-                        break
-                    end
-
-
-                    local wholeStr = val[p]
-                    if type(val[p]) ~= "userdata" then
-                        -- body
-                        pattern = string.gsub(s, "[%[%]&=+%%%c%(%)%-%/%+]", function(c)
-                            return "%"..c
-                        end)
-                        local a,b = string.find(wholeStr,pattern) 
-                        local transMatchres = string.match(wholeStr,pattern)
+       
+        if not isbreak then
+            -- body
+            for a = 1,table_length-1 do
+                local val = json.decode(filevaltable[a])
     
-                        
-                        if a and (b-a+1) == #transMatchres then
-                            succ_cnt = succ_cnt + 1
-                            table.insert(selectRes, val) 
+                if param then --有查询参数
+                    local p_length = table_leng(param) --条件长度
+                    local pattern = ""
+                    for p,s in pairs(param) do
+    
+                        if succ_cnt > 49 then
+                            -- body
+                            break
+                        end
+    
+                        -- log.info("val[p]:", val[p], "s:",s)
+    
+                        local wholeStr = val[p]
+                        if type(val[p]) ~= "userdata" then
+                            -- body
+                            pattern = string.gsub(s, "[%[%]&=+%%%c%(%)%-%/%+]", function(c)
+                                return "%"..c
+                            end)
+                            local a,b = string.find(wholeStr,pattern) 
+                            local transMatchres = string.match(wholeStr,pattern)
+        
+                            
+                            if a and (b-a+1) == #transMatchres then
+                                succ_cnt = succ_cnt + 1
+                                table.insert(selectRes, val) 
+                            end
                         end
+    
                     end
+    
+                    -- if p_length == succ_cnt then --找到结果 停止继续查找下个文件
+                    --     table.insert(selectRes, val) 
+                    -- end
+                    
+                else --无查询参数  查询所有
+                    if succ_cnt > 49 then
+                        -- body
+                    else
 
+                        if filename == "Wind" then
+                            -- body
+                            local fieldDisplayRadius = nvm.get("fieldDisplayRadius") or 200
+                            local gpsLng, gpsLat = nvm.get("gpsLng"), nvm.get("gpsLat")
+                            local dist = devTool.getDistance( val.lat, val.lon, gpsLat, gpsLng)
+                            -- log.info("dist:",dist, json.encode(v))
+                            if dist  <  fieldDisplayRadius then
+                                -- body
+                                -- log.info("cicle",v.lat)
+                                val.dist = dist
+                                table.insert(selectRes, val)
+                                succ_cnt = succ_cnt+1
+                            end
+                        else
+                            table.insert(selectRes, val)
+                            succ_cnt = succ_cnt+1
+                        end
+                    end
+                    
                 end
-
-                -- if p_length == succ_cnt then --找到结果 停止继续查找下个文件
-                --     table.insert(selectRes, val) 
-                -- end
-                
-            else --无查询参数  查询所有
-                table.insert(selectRes, val)
             end
         end
+
         count = i
-        -- if isBreak then --找到结果 停止继续查找下个文件
+        -- if isbreak then --找到结果 停止继续查找下个文件
         --     break;
         -- end
         filehandle:close() -- 关闭文件
@@ -542,35 +588,40 @@ function delBaseInfo(filename,id,dirPath)
     end
     local isCurFile = false --要删除文件是否找到
     for i,file in pairs(files) do
+        local isbreak = false
         local path = dirPath..'/'..file
         local filehandle = io.open(path, "r") -- 第一个参数是文件名,第二个是打开方式,'r'读模式,'w'写模式,对数据进行覆盖,'a'附加模式,'b'加在模式后面表示以二进制形式打开
         if not filehandle then -- 判断文件是否存在
-            break --不存在 跳过 查询下个文件
+            isbreak = true
         end
         fileval = filehandle:read("*all") -- 读出文件内容
         if not fileval then
-            break --空文件 跳过读取下一个文件
+            isbreak = true
         end
         local filevaltable = split(fileval,delimiter)
         local table_lenght = table_leng(filevaltable)
         if table_lenght <= 1 then
-            break --无'-'标识符 跳过读取下一个文件
+            isbreak = true
         end
         local newfileval = "" --删除后文件内容
-        for a = 1,table_lenght-1 do
-            local val = json.decode(filevaltable[a])
-
-            if val.id ~= id then
-                data = json.encode(val)
-                if newfileval ~= "" then
-                    newfileval = newfileval..data..delimiter
+        if not isbreak then
+            -- body
+            for a = 1,table_lenght-1 do
+                local val = json.decode(filevaltable[a])
+    
+                if val.id ~= id then
+                    data = json.encode(val)
+                    if newfileval ~= "" then
+                        newfileval = newfileval..data..delimiter
+                    else
+                        newfileval = data..delimiter
+                    end
                 else
-                    newfileval = data..delimiter
+                    isCurFile = true
                 end
-            else
-                isCurFile = true
             end
         end
+
         filehandle:close() -- 关闭文件
         if isCurFile then
             --删除旧文件
@@ -625,41 +676,46 @@ function updateBaseInfo( filename,data,dirPath)
     end
     local isCurFile = false --要修改数据文件是否找到
     for i,file in pairs(files) do
+        local isbreak = false
         local path = dirPath..'/'..file
         local filehandle = io.open(path, "r") -- 第一个参数是文件名,第二个是打开方式,'r'读模式,'w'写模式,对数据进行覆盖,'a'附加模式,'b'加在模式后面表示以二进制形式打开
         if not filehandle then -- 判断文件是否存在
-            break --不存在 跳过 查询下个文件
+            isbreak = true
         end
         fileval = filehandle:read("*all") -- 读出文件内容
         if not fileval then
-            break --空文件 跳过读取下一个文件
+            isbreak = true
         end
         local filevaltable = split(fileval,delimiter)
         local table_length = table_leng(filevaltable)
         if table_length <= 1 then
-            break --无'-'标识符 跳过读取下一个文件
+            isbreak = true
         end
         local newfileval = nil --删除后文件内容
-        for a = 1,table_length-1 do
-            local val = json.decode(filevaltable[a])
-            if val.id ~= data.id then --过滤要修改的那条数据
-                dataStr = json.encode(val)
-                if newfileval then
-                    newfileval = newfileval..dataStr..delimiter
-                else
-                    newfileval = dataStr..delimiter
-                end
-            else
-                --将新数据放入新的文件内容中
-                local newData = json.encode(data)
-                if newfileval then
-                    newfileval = newfileval..newData..delimiter
+        if not isbreak then
+            -- body
+            for a = 1,table_length-1 do
+                local val = json.decode(filevaltable[a])
+                if val.id ~= data.id then --过滤要修改的那条数据
+                    dataStr = json.encode(val)
+                    if newfileval then
+                        newfileval = newfileval..dataStr..delimiter
+                    else
+                        newfileval = dataStr..delimiter
+                    end
                 else
-                    newfileval = newData..delimiter
+                    --将新数据放入新的文件内容中
+                    local newData = json.encode(data)
+                    if newfileval then
+                        newfileval = newfileval..newData..delimiter
+                    else
+                        newfileval = newData..delimiter
+                    end
+                    isCurFile = true
                 end
-                isCurFile = true
             end
         end
+
         filehandle:close() -- 关闭文件
         if isCurFile then
            if newfileval then