数据断帧的协议处理
By
admin
at 2020-11-12 • 1人收藏 • 1461人看过
一帧的数据断成了两节来接收, 还不能把后续的有效数据丢失, 那么不能用匹配了.
用下面的方法无论怎么断, 都可以正确解析出来.
import console; //全帧 //var num = ">[CH1]P:-64.17dBm [CH2]P:-37.86dBm <" //断帧1 //var num1 = ">[CH1]P:-64.17dBm [CH" //断帧2 //var num2 = "2]P:-37.86dBm <" //协议比对位 var func = function(i){ return ({ "["; "C"; "H"; "1"; "]"; "P"; ":"; "-"; "8"; "9"; "."; "8"; "8"; "d"; "B"; "m"; })[i]; } //当前对比位 var index=1; //通道号 var channel = 1; //存结果 var retdata; //模拟断帧接收 for(i=1;3;1){ var str = console.getText( "请输入文本:" ) var data = string.split(str) do{ if(data[1] == func(index) or index==4 or (index>=8 and index<=13)){ if(index==4){ channel = data[1]; } if(index>=8 and index<=13){ retdata = string.concat(retdata,data[1]); } index++; //连续符合 if(index>16){ //更新需要的值 console.log(channel,retdata) retdata = null; index = 1; } }else { retdata = null; index = 1; } table.remove(data); }while(#data); console.pause() } console.pause(true);
3 个回复 | 最后更新于 2020-11-18
登录后方可回帖
字符串可以通过[i]取acsii码,绝对下标[[i]]取值![](/static/editor/dialogs/emotion/images/pp/i_f25.png)