| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042 |
- const util = require("../../../utils/util");
- const datagramHelp = require("../../../utils/datagramHelp")
- var app = getApp();
- var task_timer;
- Page({
- data: {
- devices: {
- deviceId: '',
- serviceId: '',
- characteristicId: '',
- connectedBluetoothName: ''
- },
- rtuInfo: {
- rtu_code: '',
- ip1: '',
- ip1_port: '',
- ip2: '',
- ip2_port: '',
- ip3: '',
- ip3_port: '',
- ip4: '',
- ip4_port: '',
- ipV6Checked1: false,
- ipV6Checked2: false,
- ipV6Checked3: false,
- ipV6Checked4: false,
- rtu_work_model: '',
- rtu_kind: '',
- collect_interval: '',
- water_level_base_point: '',
- water_level_correct_point: '',
- datagram_idx: '',
- collect_time: '',
- acc_rain: '',
- fiveMinute_rain: '',
- hour_rain: '',
- weater_level: '',
- power_v: '',
- rtu_ver: '',
- rtu_uuid: '',
- bt_v: '',
- rtu_rssi: '',
- rtu_temperature: '',
- lua_ver: '',
- netModel: '00',
- },
- netModels: [{
- value: '00',
- name: 'TCP',
- checked: true
- }, {
- value: '01',
- name: 'UDP',
- checked: false
- }, {
- value: '02',
- name: 'TCP-NDNS',
- checked: false
- }, {
- value: '03',
- name: 'UDP-NDNS',
- checked: false
- }, {
- value: '04',
- name: 'IPV6',
- checked: false
- }, {
- value: '05',
- name: 'DAPN',
- checked: false
- }],
- ip1Checkbox: [{
- value: 'IPV4',
- name: 'IPV4',
- checked: true
- },
- {
- value: 'IPV6',
- name: 'IPV6',
- checked: false
- }
- ],
- ip2Checkbox: [{
- value: 'IPV4',
- name: 'IPV4',
- checked: true
- },
- {
- value: 'IPV6',
- name: 'IPV6',
- checked: false
- }
- ],
- ip3Checkbox: [{
- value: 'IPV4',
- name: 'IPV4',
- checked: true
- },
- {
- value: 'IPV6',
- name: 'IPV6',
- checked: false
- }
- ],
- ip4Checkbox: [{
- value: 'IPV4',
- name: 'IPV4',
- checked: true
- },
- {
- value: 'IPV6',
- name: 'IPV6',
- checked: false
- }
- ],
- datagramBuff: '',
- datagramCache: [],
- trySendCount: 0,
- datagramIndex: 0,
- rtu_kind_code: ['P', 'H', 'K', 'Z', 'D', 'T', 'M', 'G', 'Q', 'I', 'O'],
- rtu_kind_name: ['P(降水)', 'H(河道)', 'K(水库/湖泊)', 'Z(闸坝)', 'D(泵站)', 'T(潮汐)', 'M(墒情)', 'G(地下水)', 'Q(水质)', 'I(取水口)', 'O(排水口)'],
- rtu_kind_index: 0,
- rtu_work_model_name: ['低功耗', '永在线'],
- rtu_work_model_index: 0,
- suspend: false,
- showSettingResult: false,
- settingResultText: '操作已完成!'
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- console.log('bluebooth home page load ', '**********************************************')
- let deviceId = options.deviceId;
- let serviceId = options.serviceId;
- let characteristicId = options.characteristicId;
- let connectedBluetoothName = options.connectedBluetoothName;
- console.log('name' + connectedBluetoothName)
- let devices = {}
- devices['deviceId'] = deviceId;
- devices['serviceId'] = serviceId;
- devices['characteristicId'] = characteristicId;
- devices['connectedBluetoothName'] = connectedBluetoothName;
- this.setData({
- devices: devices,
- trySendCount: 0,
- datagramIndex: 0,
- suspend: false
- })
- task_timer = undefined;
- this.getRtuBaseSetting();
- if (this.data.datagramCache.length > 0) {
- let datagram = this.data.datagramCache[this.data.datagramIndex];
- this.sendDatagramToRtu(datagram);
- let index = this.data.datagramIndex + 1;
- if (this.data.datagramCache.length == index) {
- index = 0;
- }
- let count = this.data.trySendCount + 1;
- this.setData({
- datagramIndex: index,
- trySendCount: count
- })
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- console.log('bluebooth baseSetting page onHide ', '**********************************************')
- this.cancelTime();
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- console.log('bluebooth baseSetting page onUnload ', '**********************************************')
- this.cancelTime();
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- console.log('bluebooth baseSetting page onShow ', '**********************************************')
- // if (!this.data.suspend) {
- this.timeCallback();
- // }
- },
- settingCompletTabEvent(e) {
- this.setData({
- showSettingResult: false
- })
- const btn = e.detail.index;
- if (btn == 0) {
- wx.navigateBack({
- delta: 2,
- });
- }
- },
- bindNewRtuCodeInput: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.rtu_code = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- bindIp1Input: function (e) {
- let rtuInfo = this.data.rtuInfo;
- let oldip = rtuInfo.ip1;
- let newip = e.detail.value;
- let ipv6checked = rtuInfo.ipV6Checked1;
- let maxLen = false;
- if (ipv6checked) {
- let ipitems = oldip.split(":");
- if (newip.length > oldip.length) {
- if (ipitems.length == 8) {
- let lastText = ipitems[ipitems.length - 1];
- if (lastText != null && lastText.length == 4) {
- maxLen = true;
- }
- }
- if (maxLen) {
- newip = oldip;
- } else {
- let ipitems = newip.split(":");
- let lastText = ipitems[ipitems.length - 1];
- if (lastText != null && lastText.length == 4) {
- if (ipitems.length < 8) {
- newip += ":";
- }
- }
- }
- }
- } else {
- let ipitems = oldip.split(".");
- if (newip.length > oldip.length) {
- if (ipitems.length == 4) {
- let lastText = ipitems[ipitems.length - 1];
- if (lastText != null && lastText.length == 3) {
- maxLen = true;
- }
- }
- if (maxLen) {
- newip = oldip;
- } else {
- let ipitems = newip.split(".");
- let lastText = ipitems[ipitems.length - 1];
- if (lastText != null && lastText.length == 3) {
- if (ipitems.length < 4) {
- newip += ".";
- }
- }
- }
- }
- }
- rtuInfo.ip1 = newip;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- bindIp2Input: function (e) {
- let rtuInfo = this.data.rtuInfo;
- let oldip = rtuInfo.ip2;
- let newip = e.detail.value;
- let ipv6checked = rtuInfo.ipV6Checked2;
- let maxLen = false;
- if (ipv6checked) {
- let ipitems = oldip.split(":");
- if (newip.length > oldip.length) {
- if (ipitems.length == 8) {
- let lastText = ipitems[ipitems.length - 1];
- if (lastText != null && lastText.length == 4) {
- maxLen = true;
- }
- }
- if (maxLen) {
- newip = oldip;
- } else {
- let ipitems = newip.split(":");
- let lastText = ipitems[ipitems.length - 1];
- if (lastText != null && lastText.length == 4) {
- if (ipitems.length < 8) {
- newip += ":";
- }
- }
- }
- }
- } else {
- let ipitems = oldip.split(".");
- if (newip.length > oldip.length) {
- if (ipitems.length == 4) {
- let lastText = ipitems[ipitems.length - 1];
- if (lastText != null && lastText.length == 3) {
- maxLen = true;
- }
- }
- if (maxLen) {
- newip = oldip;
- } else {
- let ipitems = newip.split(".");
- let lastText = ipitems[ipitems.length - 1];
- if (lastText != null && lastText.length == 3) {
- if (ipitems.length < 4) {
- newip += ".";
- }
- }
- }
- }
- }
- rtuInfo.ip2 = newip;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- bindIp3Input: function (e) {
- let rtuInfo = this.data.rtuInfo;
- let oldip = rtuInfo.ip3;
- let newip = e.detail.value;
- let ipv6checked = rtuInfo.ipV6Checked3;
- let maxLen = false;
- if (ipv6checked) {
- let ipitems = oldip.split(":");
- if (newip.length > oldip.length) {
- if (ipitems.length == 8) {
- let lastText = ipitems[ipitems.length - 1];
- if (lastText != null && lastText.length == 4) {
- maxLen = true;
- }
- }
- if (maxLen) {
- newip = oldip;
- } else {
- let ipitems = newip.split(":");
- let lastText = ipitems[ipitems.length - 1];
- if (lastText != null && lastText.length == 4) {
- if (ipitems.length < 8) {
- newip += ":";
- }
- }
- }
- }
- } else {
- let ipitems = oldip.split(".");
- if (newip.length > oldip.length) {
- if (ipitems.length == 4) {
- let lastText = ipitems[ipitems.length - 1];
- if (lastText != null && lastText.length == 3) {
- maxLen = true;
- }
- }
- if (maxLen) {
- newip = oldip;
- } else {
- let ipitems = newip.split(".");
- let lastText = ipitems[ipitems.length - 1];
- if (lastText != null && lastText.length == 3) {
- if (ipitems.length < 4) {
- newip += ".";
- }
- }
- }
- }
- }
- rtuInfo.ip3 = newip;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- bindIp4Input: function (e) {
- let rtuInfo = this.data.rtuInfo;
- let oldip = rtuInfo.ip4;
- let newip = e.detail.value;
- let ipv6checked = rtuInfo.ipV6Checked4;
- let maxLen = false;
- if (ipv6checked) {
- let ipitems = oldip.split(":");
- if (newip.length > oldip.length) {
- if (ipitems.length == 8) {
- let lastText = ipitems[ipitems.length - 1];
- if (lastText != null && lastText.length == 4) {
- maxLen = true;
- }
- }
- if (maxLen) {
- newip = oldip;
- } else {
- let ipitems = newip.split(":");
- let lastText = ipitems[ipitems.length - 1];
- if (lastText != null && lastText.length == 4) {
- if (ipitems.length < 8) {
- newip += ":";
- }
- }
- }
- }
- } else {
- let ipitems = oldip.split(".");
- if (newip.length > oldip.length) {
- if (ipitems.length == 4) {
- let lastText = ipitems[ipitems.length - 1];
- if (lastText != null && lastText.length == 3) {
- maxLen = true;
- }
- }
- if (maxLen) {
- newip = oldip;
- } else {
- let ipitems = newip.split(".");
- let lastText = ipitems[ipitems.length - 1];
- if (lastText != null && lastText.length == 3) {
- if (ipitems.length < 4) {
- newip += ".";
- }
- }
- }
- }
- }
- rtuInfo.ip4 = newip;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- bindIp1portInput: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.ip1_port = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- bindIp2portInput: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.ip2_port = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- bindIp3portInput: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.ip3_port = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- bindIp4portInput: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.ip4_port = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- bindWorkModelPickerChange: function (e) {
- console.log('picker发送选择改变,携带值为', e.detail.value)
- let index = e.detail.value;
- let rtuInfo = this.data.rtuInfo;
- if (index == 0) {
- rtuInfo['rtu_work_model'] = '0';
- } else {
- rtuInfo['rtu_work_model'] = '1';
- }
- this.setData({
- rtu_work_model_index: index,
- rtuInfo: rtuInfo
- })
- },
- bindRtuKindPickerChange: function (e) {
- console.log('picker发送选择改变,携带值为', e.detail.value)
- let rtuInfo = this.data.rtuInfo;
- let index = e.detail.value;
- let v = "" + this.data.rtu_kind_code[index];
- rtuInfo['rtu_kind'] = v;
- this.setData({
- rtu_kind_index: index,
- rtuInfo: rtuInfo
- })
- },
- checkIp(ip, port, ipV6Checked) {
- let formatError = false;
- if (ip != undefined && ip.length > 0) {
- if (ipV6Checked) {
- let ipitems = ip.split(":");
- if (ipitems.length == 8) {
- for (let i = 0; i < ipitems.length; i++) {
- let text = ipitems[i];
- let len = text.length;
- if (len == 4) {
- for (let j = 0; j < 3; j++) {
- let subText = text.charCodeAt(j);
- if ((subText >= 48 && subText <= 57) || (subText >= 65 && subText <= 70) || (subText >= 97 && subText <= 102)) {
- formatError = false;
- } else {
- formatError = true;
- break;
- }
- }
- if (formatError) {
- break;
- }
- } else {
- formatError = true;
- break;
- }
- }
- } else {
- formatError = true;
- }
- } else {
- let ipitems = ip.split(".");
- if (ipitems.length == 4) {
- for (let i = 0; i < ipitems.length; i++) {
- let text = ipitems[i];
- let len = text.length;
- if (len > 0) {
- for (let j = 0; j < len; j++) {
- let subText = text.charCodeAt(j);
- if (subText >= 48 && subText <= 57) {
- formatError = false;
- } else {
- formatError = true;
- break;
- }
- }
- if (formatError) {
- break;
- }
- } else {
- formatError = true;
- break;
- }
- }
- } else {
- formatError = true;
- }
- }
- let len = port.length;
- if (len > 0) {
- if (isNaN(Number(port, 10))) {
- formatError = true;
- }
- } else {
- formatError = true;
- }
- }
- return formatError;
- },
- baseSettingBtn: function () {
- let ip = this.data.rtuInfo['ip1'];
- let port = this.data.rtuInfo['ip1_port'];
- let ipV6Checked = this.data.rtuInfo['ipV6Checked1'];
- let formatError = this.checkIp(ip, port, ipV6Checked);
- if (formatError) {
- wx.showToast({
- title: '第1路IP地址格式错误,请检查!',
- icon: 'none',
- duration: 2000
- })
- return;
- }
- ip = this.data.rtuInfo['ip2'];
- port = this.data.rtuInfo['ip2_port'];
- ipV6Checked = this.data.rtuInfo['ipV6Checked2'];
- formatError = this.checkIp(ip, port, ipV6Checked);
- if (formatError) {
- wx.showToast({
- title: '第2路IP地址格式错误,请检查!',
- icon: 'none',
- duration: 2000
- })
- return;
- }
- ip = this.data.rtuInfo['ip3'];
- port = this.data.rtuInfo['ip3_port'];
- ipV6Checked = this.data.rtuInfo['ipV6Checked3'];
- formatError = this.checkIp(ip, port, ipV6Checked);
- if (formatError) {
- wx.showToast({
- title: '第3路IP地址格式错误,请检查!',
- icon: 'none',
- duration: 2000
- })
- return;
- }
- ip = this.data.rtuInfo['ip4'];
- port = this.data.rtuInfo['ip4_port'];
- ipV6Checked = this.data.rtuInfo['ipV6Checked4'];
- formatError = this.checkIp(ip, port, ipV6Checked);
- if (formatError) {
- wx.showToast({
- title: '第4路IP地址格式错误,请检查!',
- icon: 'none',
- duration: 2000
- })
- return;
- }
- this.cancelTime();
- this.setRtuBaseSetting(this.data.rtuInfo);
- },
- setRtuBaseSetting(rtuInfo) {
- let datagram = datagramHelp.datagram_40(rtuInfo);
- this.sendDatagramToRtu(datagram);
- },
- /**
- * 查询测站基础参数信息
- */
- getRtuBaseSetting() {
- let datagram = datagramHelp.datagram_41();
- let cache = this.data.datagramCache;
- cache.push(datagram);
- },
- pushDatagramBuff(datagram) {
- let tmpdatagramBuff = this.data.datagramBuff;
- if (tmpdatagramBuff.length > 0) {
- tmpdatagramBuff = tmpdatagramBuff + datagram;
- } else {
- tmpdatagramBuff = datagram;
- }
- console.log(" datagram buff ==========", tmpdatagramBuff)
- this.setData({
- datagramBuff: tmpdatagramBuff
- })
- this.processDatagram();
- },
- processDatagram() {
- let datagram = this.data.datagramBuff;
- if (datagram.length > 0) {
- for (let i = 0; i < datagram.length; i++) {
- if (datagram.indexOf("7e7e") == 0) {
- break;
- } else {
- datagram = datagram.substring(i, datagram.length);
- }
- }
- if (null != datagram && datagram.length > 0 && datagram.indexOf("7e7e") >= 0) {
- if (datagram.length >= 26) {
- var lenBuff = util.HexStr2Bytes(datagram.substring(22, 22 + 4));
- var len = util.byteToUint16(lenBuff); // 报文长度(int)
- var datagramlength = 11 + len + 6;
- if (datagram.length >= datagramlength * 2) {
- var onedatagram = datagram.substring(0, datagramlength * 2);
- if (!datagramHelp.crcCheck(onedatagram)) {
- wx.showToast({
- title: '数据CRC校验错误,请重试!',
- icon: 'none',
- duration: 2000
- })
- this.setData({
- datagramBuff: ''
- })
- return;
- }
- var count = 20;
- var funcode = datagram.substring(count, count + 2);
- count += 2;
- if (funcode == "f6") {
- } else if (funcode == "f7") {
- } else if (funcode == '45') {
- } else if (funcode == '47') {
- } else if (funcode == '48') {
- } else if (funcode == '41') {
- var info = datagramHelp.datagram_41_analyse(onedatagram)
- console.log(info)
- let rtuCode = info['rtu_code'];
- let workModel = info['rtu_work_model'];
- let rtuInfo = this.data.rtuInfo;
- rtuInfo['rtu_code'] = rtuCode;
- rtuInfo['ip1'] = info['ip1'];
- rtuInfo['ip2'] = info['ip2'];
- rtuInfo['ip3'] = info['ip3'];
- rtuInfo['ip4'] = info['ip4'];
- rtuInfo['ip1_port'] = info['ip1_port'];
- rtuInfo['ip2_port'] = info['ip2_port'];
- rtuInfo['ip3_port'] = info['ip3_port'];
- rtuInfo['ip4_port'] = info['ip4_port'];
- rtuInfo['rtu_kind'] = info['rtu_kind'];
- rtuInfo['ipV6Checked1'] = info['ipV6Checked1'];
- rtuInfo['ipV6Checked2'] = info['ipV6Checked2'];
- rtuInfo['ipV6Checked3'] = info['ipV6Checked3'];
- rtuInfo['ipV6Checked4'] = info['ipV6Checked4'];
- rtuInfo['netModel'] = info['net_model'];
- console.log("netModel" + rtuInfo['netModel']);
- let netModels = this.data.netModels;
- for (let i = 0; i < netModels.length; i++) {
- console.log("netModel " + i + " " + netModels[i].value);
- if (netModels[i].value === rtuInfo['netModel']) {
- netModels[i].checked = true;
- } else {
- netModels[i].checked = false;
- }
- }
- console.log("ipv61 " + rtuInfo['ipV6Checked1']);
- console.log("ipv62 " + rtuInfo['ipV6Checked2']);
- console.log("ipv63 " + rtuInfo['ipV6Checked3']);
- console.log("ipv64 " + rtuInfo['ipV6Checked4']);
- let checkbox1 = this.data.ip1Checkbox;
- let checkbox2 = this.data.ip2Checkbox;
- let checkbox3 = this.data.ip3Checkbox;
- let checkbox4 = this.data.ip4Checkbox;
- if (rtuInfo['ipV6Checked1']) {
- checkbox1[0].checked = false;
- checkbox1[1].checked = true;
- } else {
- checkbox1[0].checked = true;
- checkbox1[1].checked = false;
- }
- if (rtuInfo['ipV6Checked2']) {
- checkbox2[0].checked = false;
- checkbox2[1].checked = true;
- } else {
- checkbox2[0].checked = true;
- checkbox2[1].checked = false;
- }
- if (rtuInfo['ipV6Checked3']) {
- checkbox3[0].checked = false;
- checkbox3[1].checked = true;
- } else {
- checkbox3[0].checked = true;
- checkbox3[1].checked = false;
- }
- if (rtuInfo['ipV6Checked4']) {
- checkbox4[0].checked = false;
- checkbox4[1].checked = true;
- } else {
- checkbox4[0].checked = true;
- checkbox4[1].checked = false;
- }
- rtuInfo['rtu_work_model'] = workModel;
- let work_model_index = 0;
- if (workModel == "0") {
- work_model_index = 0;
- } else {
- work_model_index = 1;
- }
- let rtu_kind_index = 0;
- for (let i = 0; i < this.data.rtu_kind_code.length; i++) {
- let code = this.data.rtu_kind_code[i];
- if (code == rtuInfo['rtu_kind']) {
- rtu_kind_index = i;
- break;
- }
- }
- this.setData({
- rtuInfo: rtuInfo,
- netModels: netModels,
- ip1Checkbox: checkbox1,
- ip2Checkbox: checkbox2,
- ip3Checkbox: checkbox3,
- ip4Checkbox: checkbox4,
- rtu_work_model_index: work_model_index,
- rtu_kind_index: rtu_kind_index
- });
- let index = this.data.datagramIndex + 1;
- if (this.data.datagramCache.length == index) {
- index = 0;
- }
- this.setData({
- datagramIndex: index,
- trySendCount: 0
- })
- this.cancelTime();
- } else if (funcode == '40') {
- this.setData({
- showSettingResult: true,
- settingResultText: "基本参数配置已完成,请重新连接蓝牙!"
- })
- // wx.showToast({
- // title: 'RTU基本参数操作已完成!',
- // icon: 'ok',
- // duration: 2000 //持续的时间
- // })
- } else if (funcode == '43') {
- } else if (funcode == '42') {
- } else if (funcode == '4A') {
- } else if (funcode == '51') {
- } else if (funcode == 'f3') {
- }
- if (datagram.length - datagramlength * 2 > 0) {
- let tmp = datagram.substring(datagramlength * 2, datagram.length);
- this.setData({
- datagramBuff: tmp
- })
- } else {
- this.setData({
- datagramBuff: ""
- })
- }
- } else {
- this.setData({
- datagramBuff: datagram
- })
- }
- } else {
- this.setData({
- datagramBuff: datagram
- })
- }
- } else {
- if (null != datagram && datagram.length > 0) {
- this.setData({
- datagramBuff: datagram
- })
- } else {
- this.setData({
- datagramBuff: ''
- })
- }
- }
- }
- },
- sendDatagramToRtu(datagram) {
- console.log("will send datagram " + datagram);
- let buffer = util.HexStr2Bytes(datagram);
- var that = this;
- let count = 0;
- let inView = new DataView(buffer);
- while (true) {
- if (buffer.byteLength - count > 20) {
- let tmpBuff = new ArrayBuffer(20);
- let outView = new DataView(tmpBuff);
- for (let i = 0; i < 20; i++) {
- outView.setUint8(i, inView.getUint8(count + i))
- }
- wx.writeBLECharacteristicValue({
- deviceId: that.data.devices['deviceId'],
- serviceId: that.data.devices['serviceId'],
- characteristicId: that.data.devices['characteristicId'],
- value: tmpBuff,
- success(res) {
- console.log('writeBLECharacteristicValue success', res.errMsg)
- wx.onBLECharacteristicValueChange((characteristic) => {
- console.log("read datagram==============", util.ab2hex(characteristic.value))
- var datagram = util.ab2hex(characteristic.value);
- that.pushDatagramBuff(datagram);
- })
- wx.readBLECharacteristicValue({
- deviceId: that.data.devices['deviceId'],
- serviceId: that.data.devices['serviceId'],
- characteristicId: that.data.devices['characteristicId'],
- success: function (res) {
- console.log('readBLECharacteristicValue')
- }
- })
- },
- fail(res) {
- console.log('writeBLECharacteristicValue success', res.errMsg)
- }
- })
- count += 20;
- } else {
- let len = buffer.byteLength - count;
- let tmpBuff = new ArrayBuffer(len);
- let outView = new DataView(tmpBuff);
- for (let i = 0; i < len; i++) {
- outView.setUint8(i, inView.getUint8(count + i))
- }
- wx.writeBLECharacteristicValue({
- deviceId: that.data.devices['deviceId'],
- serviceId: that.data.devices['serviceId'],
- characteristicId: that.data.devices['characteristicId'],
- value: tmpBuff,
- success(res) {
- console.log('writeBLECharacteristicValue success', res.errMsg)
- wx.onBLECharacteristicValueChange((characteristic) => {
- console.log("read datagram==============", util.ab2hex(characteristic.value))
- var datagram = util.ab2hex(characteristic.value);
- that.pushDatagramBuff(datagram);
- })
- wx.readBLECharacteristicValue({
- deviceId: that.data.devices['deviceId'],
- serviceId: that.data.devices['serviceId'],
- characteristicId: that.data.devices['characteristicId'],
- success: function (res) {
- console.log('readBLECharacteristicValue')
- }
- })
- },
- fail(res) {
- console.log('writeBLECharacteristicValue success', res.errMsg)
- }
- })
- count += len;
- }
- if (count >= buffer.byteLength) {
- break;
- }
- }
- },
- timeCallback() {
- var that = this;
- task_timer = setTimeout(function () {
- console.log("------------------------------------Time CallBack----------------------------");
- if (that.data.trySendCount == 0) {
- if (that.data.datagramCache.length > 0) {
- let datagram = that.data.datagramCache[that.data.datagramIndex];
- that.sendDatagramToRtu(datagram);
- let index = that.data.datagramIndex + 1;
- if (that.data.datagramCache.length == index) {
- index = 0;
- }
- let count = that.data.trySendCount + 1;
- that.setData({
- datagramIndex: index,
- trySendCount: count
- })
- }
- } else {
- let count = that.data.trySendCount + 1;
- if (count >= 10) {
- count = 0;
- }
- that.setData({
- trySendCount: count
- })
- }
- that.timeCallback();
- }, 3000);
- },
- cancelTime() {
- if (task_timer != undefined) {
- clearTimeout(task_timer);
- task_timer = undefined;
- }
- this.setData({
- datagramIndex: 0,
- trySendCount: 0,
- suspend: true
- })
- },
- /**
- * 第一路IPV6勾选项
- * @param {} e
- */
- netModelsCheckedChange: function (e) {
- const netModels = this.data.netModels;
- let netModel = e.detail.value;
- for (let i = 0, len = netModels.length; i < len; ++i) {
- netModels[i].checked = netModels[i].value === e.detail.value
- }
- const rtuInfo = this.data.rtuInfo;
- rtuInfo.netModel = netModel;
- this.setData({
- netModels,
- rtuInfo
- })
- },
- /**
- * 第一路IPV6勾选项
- * @param {} e
- */
- ip1CheckedChange: function (e) {
- const ip1Checkbox = this.data.ip1Checkbox;
- let ipV6Checked1 = false;
- for (let i = 0, len = ip1Checkbox.length; i < len; ++i) {
- ip1Checkbox[i].checked = ip1Checkbox[i].value === e.detail.value
- if (e.detail.value === 'IPV6') {
- ipV6Checked1 = true;
- }
- }
- const rtuInfo = this.data.rtuInfo;
- rtuInfo.ipV6Checked1 = ipV6Checked1;
- this.setData({
- ip1Checkbox,
- rtuInfo
- })
- },
- /**
- * 第二路IP勾选项
- * @param {} e
- */
- ip2CheckedChange: function (e) {
- const ip2Checkbox = this.data.ip2Checkbox;
- let ipV6Checked2 = false;
- for (let i = 0, len = ip2Checkbox.length; i < len; ++i) {
- ip2Checkbox[i].checked = ip2Checkbox[i].value === e.detail.value
- if (e.detail.value === 'IPV6') {
- ipV6Checked2 = true;
- }
- }
- const rtuInfo = this.data.rtuInfo;
- rtuInfo.ipV6Checked2 = ipV6Checked2;
- this.setData({
- ip2Checkbox,
- rtuInfo
- })
- },
- /**
- * 第三路IP勾选项
- * @param {} e
- */
- ip3CheckedChange: function (e) {
- const ip3Checkbox = this.data.ip3Checkbox;
- let ipV6Checked3 = false;
- for (let i = 0, len = ip3Checkbox.length; i < len; ++i) {
- ip3Checkbox[i].checked = ip3Checkbox[i].value === e.detail.value
- if (e.detail.value === 'IPV6') {
- ipV6Checked3 = true;
- }
- }
- const rtuInfo = this.data.rtuInfo;
- rtuInfo.ipV6Checked3 = ipV6Checked3;
- this.setData({
- ip3Checkbox,
- rtuInfo
- })
- },
- /**
- * 第四路IP勾选项
- * @param {} e
- */
- ip4CheckedChange: function (e) {
- const ip4Checkbox = this.data.ip4Checkbox;
- let ipV6Checked4 = false;
- for (let i = 0, len = ip4Checkbox.length; i < len; ++i) {
- ip4Checkbox[i].checked = ip4Checkbox[i].value === e.detail.value
- if (e.detail.value === 'IPV6') {
- ipV6Checked4 = true;
- }
- }
- const rtuInfo = this.data.rtuInfo;
- rtuInfo.ipV6Checked4 = ipV6Checked4;
- this.setData({
- ip4Checkbox,
- rtuInfo
- })
- }
- })
|