|
|
@@ -0,0 +1,1042 @@
|
|
|
+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
|
|
|
+ })
|
|
|
+ }
|
|
|
+})
|