| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893 |
- 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: '',
- ip2: '',
- ip3: '',
- ip4: '',
- rtu_work_model: '',
- rtu_kind: '',
- collect_interval: '',
- water_level_base_point: '',
- water_level_correct_point: '',
- rain_precision: '',
- rain_extra_datagram_threshold: '',
- water_se_agreement: '',
- water_se_id: '',
- water_se_address: '',
- water_se_format: '',
- water_se_adjust: '',
- water_se_symbol: '',
- addIntervalTime: '',
- intervalTime: '',
- datagram_idx: '',
- collect_time: '',
- acc_rain: '',
- fiveMinute_rain: '',
- hour_rain: '',
- weater_level: '',
- power_v: '',
- riverDeep: '',
- riverWide: '',
- riverAngle: '',
- radarHigh: '',
- faceCoe: '',
- speedCoe: '',
- flowModelCoe: '',
- rtu_ver: '',
- rtu_uuid: '',
- bt_v: '',
- rtu_rssi: '',
- rtu_temperature: '',
- lua_ver: '',
- agreement: 'sw2014',
- datagramTimes: [{
- value: '5',
- name: '5分钟',
- },
- {
- value: '60',
- name: '1小时',
- checked: true
- },
- {
- value: '120',
- name: '2小时'
- },
- {
- value: '180',
- name: '3小时'
- },
- {
- value: '240',
- name: '4小时'
- },
- {
- value: '360',
- name: '6小时'
- },
- {
- value: '480',
- name: '8小时'
- },
- {
- value: '720',
- name: '12小时'
- },
- {
- value: '1440',
- name: '24小时'
- }
- ],
- waterLevelSensorKind: [{
- value: '0',
- name: '未连接',
- checked: true
- },
- {
- value: '1',
- name: '数字量'
- },
- {
- value: '2',
- name: '模似量'
- }
- ],
- flowRateSensorKind: [{
- value: '0',
- name: '未连接',
- checked: true
- },
- {
- value: '1',
- name: '数字量'
- },
- {
- value: '2',
- name: '模似量'
- }
- ],
- flowRateSensorProtocolType: [{
- value: '0',
- name: 'modbus',
- checked: true
- },
- {
- value: '1',
- name: '老百特流量计'
- },
- {
- value: '2',
- name: '插入式超声波流量计'
- },
- {
- value: '3',
- name: 'LMAG流量计'
- },
- {
- value: '4',
- name: '京仪流速计'
- },
- {
- value: '5',
- name: '91雷达流量计'
- },
- {
- value: '6',
- name: '华聚流速计'
- },
- {
- value: '7',
- name: '模拟流量计'
- },
- {
- value: '8',
- name: '华儒流速计'
- },
- {
- value: '9',
- name: '鹰格流速计'
- },
- {
- value: '10',
- name: '协议10'
- },
- {
- value: '11',
- name: '协议11'
- },
- {
- value: '12',
- name: '协议12'
- },
- {
- value: '13',
- name: '协议13'
- },
- {
- value: '14',
- name: '协议14'
- }
- ],
- flowRateSensorId:'',
- },
- datagramBuff: '',
- datagramCache: [],
- trySendCount: 0,
- datagramIndex: 0,
- showSettingResult: false,
- settingResultText: '操作已完成!'
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- console.log('bluebooth info 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
- })
- task_timer = undefined;
- this.getRtuRunSetting();
- 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 runSetting page onHide ', '**********************************************')
- this.cancelTime();
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- console.log('bluebooth runSetting page onUnload ', '**********************************************')
- this.cancelTime();
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- console.log('bluebooth runSetting page onShow ', '**********************************************')
- this.timeCallback();
- },
- settingCompletTabEvent(e) {
- this.setData({
- showSettingResult: false
- })
- const btn = e.detail.index;
- if (btn == 0) {
- wx.navigateBack();
- }
- },
- radioChange: function (e) {
- let intervalTime = e.detail.value;
- let radioItems = this.data.rtuInfo.datagramTimes;
- for (let i = 0, len = radioItems.length; i < len; ++i) {
- radioItems[i].checked = radioItems[i].value == intervalTime;
- }
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.datagramTimes = radioItems;
- rtuInfo.intervalTime = intervalTime;
- this.setData({
- rtuInfo: rtuInfo
- });
- },
- waterLevelSensorKindRadioChange: function (e) {
- var rtuInfo = this.data.rtuInfo;
- var radioItems = this.data.rtuInfo.waterLevelSensorKind;
- for (var i = 0, len = radioItems.length; i < len; ++i) {
- radioItems[i].checked = radioItems[i].value == e.detail.value;
- }
- rtuInfo.waterLevelSensorKind = radioItems;
- this.setData({
- rtuInfo: rtuInfo
- });
- },
- flowRateSensorKindRadioChange: function (e) {
- var rtuInfo = this.data.rtuInfo;
- var radioItems = this.data.rtuInfo.flowRateSensorKind;
- for (var i = 0, len = radioItems.length; i < len; ++i) {
- radioItems[i].checked = radioItems[i].value == e.detail.value;
- }
- rtuInfo.flowRateSensorKind = radioItems;
- this.setData({
- rtuInfo: rtuInfo
- });
- },
- flowRateProtocolRadioChange: function (e) {
- var rtuInfo = this.data.rtuInfo;
- var radioItems = this.data.rtuInfo.flowRateSensorProtocolType;
- for (var i = 0, len = radioItems.length; i < len; ++i) {
- radioItems[i].checked = radioItems[i].value == e.detail.value;
- }
- rtuInfo.flowRateSensorProtocolType = radioItems;
- this.setData({
- rtuInfo: rtuInfo
- });
- },
- addDatagramInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.addIntervalTime = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- waterBaseValueInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.water_level_base_point = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- waterCorrectValueInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.water_level_correct_point = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- rainPrecisionInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.rain_precision = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- rainExtraDatagramThresholdInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.rain_extra_datagram_threshold = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- waterSeAgreementInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.water_se_agreement = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- waterSeIdInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.water_se_id = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- waterSeAddressInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.water_se_address = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- waterSeFormatInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.water_se_format = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- waterSeAdjustInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.water_se_adjust = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- waterSeSymbolInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.water_se_symbol = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- riverDeepInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.riverDeep = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- riverWideInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.riverWide = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- riverAngleInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.riverAngle = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- radarHighInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.radarHigh = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- faceCoeInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.faceCoe = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- speedCoeInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.speedCoe = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- flowModelCoeInputHandle: function (e) {
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.flowModelCoe = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- flowRateSensorIdInputHandle: function(e){
- let rtuInfo = this.data.rtuInfo;
- rtuInfo.flowRateSensorId = e.detail.value;
- this.setData({
- rtuInfo: rtuInfo
- })
- },
- submitRunsetting: function () {
- this.cancelTime();
- let datagram = datagramHelp.datagram_42(this.data.rtuInfo);
- this.sendDatagramToRtu(datagram);
- },
- getRtuRunSetting() {
- let datagram = datagramHelp.datagram_43();
- 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') {
- } else if (funcode == '40') {
- } else if (funcode == '43') {
- var info = datagramHelp.datagram_43_analyse(onedatagram)
- console.log(info)
- let rtuInfo = this.data.rtuInfo;
- let intervalTime = info['intervalTime'];
- let datagramTimes = rtuInfo.datagramTimes;
- // let it = {};
- //it['name'] = "5分钟";
- // it['value'] = "5";
- if (intervalTime == "5") {
- datagramTimes[0]['checked'] = true;
- } else {
- datagramTimes[0]['checked'] = false;
- }
- // datagramTimes.push(it);
- // it = {};
- // it['name'] = "1小时";
- // it['value'] = "60";
- if (intervalTime == "60") {
- datagramTimes[1]['checked'] = true;
- } else {
- datagramTimes[1]['checked'] = false;
- }
- //datagramTimes.push(it);
- //it = {};
- //it['name'] = "2小时";
- //it['value'] = "120";
- if (intervalTime == "120") {
- datagramTimes[2]['checked'] = true;
- } else {
- datagramTimes[2]['checked'] = false;
- }
- //datagramTimes.push(it);
- //it = {};
- //it['name'] = "3小时";
- //it['value'] = "180";
- if (intervalTime == "180") {
- datagramTimes[3]['checked'] = true;
- } else {
- datagramTimes[3]['checked'] = false;
- }
- //datagramTimes.push(it);
- //it = {};
- //it['name'] = "4小时";
- //it['value'] = "240";
- if (intervalTime == "240") {
- datagramTimes[4]['checked'] = true;
- } else {
- datagramTimes[4]['checked'] = false;
- }
- //datagramTimes.push(it);
- //it = {};
- //it['name'] = "6小时";
- //it['value'] = "360";
- if (intervalTime == "360") {
- datagramTimes[5]['checked'] = true;
- } else {
- datagramTimes[5]['checked'] = false;
- }
- //datagramTimes.push(it);
- //it = {};
- //it['name'] = "8小时";
- //it['value'] = "480";
- if (intervalTime == "480") {
- datagramTimes[6]['checked'] = true;
- } else {
- datagramTimes[6]['checked'] = false;
- }
- //datagramTimes.push(it);
- //it = {};
- //it['name'] = "12小时";
- //it['value'] = "720";
- if (intervalTime == "720") {
- datagramTimes[7]['checked'] = true;
- } else {
- datagramTimes[7]['checked'] = false;
- }
- //datagramTimes.push(it);
- //it = {};
- //it['name'] = "24小时";
- //it['value'] = "1440";
- if (intervalTime == "1440") {
- datagramTimes[8]['checked'] = true;
- } else {
- datagramTimes[8]['checked'] = false;
- }
- //datagramTimes.push(it);
- rtuInfo['intervalTime'] = intervalTime;
- rtuInfo['datagramTimes'] = datagramTimes;
- var v = info['addIntervalTime'];
- if (null != v && v.length > 0) {
- rtuInfo['addIntervalTime'] = info['addIntervalTime'];
- }
- v = info['water_level_base_point'];
- if (null != v && v.length > 0) {
- rtuInfo['water_level_base_point'] = info['water_level_base_point'];
- }
- v = info['water_level_correct_point'];
- if (null != v && v.length > 0) {
- rtuInfo['water_level_correct_point'] = info['water_level_correct_point'];
- }
- v = info['rain_precision'];
- if (null != v && v.length > 0) {
- rtuInfo['rain_precision'] = info['rain_precision'];
- }
- v = info['rain_extra_datagram_threshold'];
- if (null != v && v.length > 0) {
- rtuInfo['rain_extra_datagram_threshold'] = info['rain_extra_datagram_threshold'];
- }
- v = info['water_se_agreement'];
- if (null != v && v.length > 0) {
- rtuInfo['water_se_agreement'] = info['water_se_agreement'];
- }
- v = info['water_se_id'];
- if (null != v && v.length > 0) {
- rtuInfo['water_se_id'] = info['water_se_id'];
- }
- v = info['water_se_address'];
- if (null != v && v.length > 0) {
- rtuInfo['water_se_address'] = info['water_se_address'];
- }
- v = info['water_se_format'];
- if (null != v && v.length > 0) {
- rtuInfo['water_se_format'] = info['water_se_format'];
- }
- v = info['water_se_adjust'];
- if (null != v && v.length > 0) {
- rtuInfo['water_se_adjust'] = info['water_se_adjust'];
- }
- v = info['water_se_symbol'];
- if (null != v && v.length > 0) {
- rtuInfo['water_se_symbol'] = info['water_se_symbol'];
- }
- v = info['riverDeep'];
- if (null != v && v.length > 0) {
- rtuInfo['riverDeep'] = info['riverDeep'];
- }
- v = info['riverWide'];
- if (null != v && v.length > 0) {
- rtuInfo['riverWide'] = info['riverWide'];
- }
- v = info['riverAngle'];
- if (null != v && v.length > 0) {
- rtuInfo['riverAngle'] = info['riverAngle'];
- }
- v = info['radarHigh'];
- if (null != v && v.length > 0) {
- rtuInfo['radarHigh'] = info['radarHigh'];
- }
- v = info['faceCoe'];
- if (null != v && v.length > 0) {
- rtuInfo['faceCoe'] = info['faceCoe'];
- }
- v = info['speedCoe'];
- if (null != v && v.length > 0) {
- rtuInfo['speedCoe'] = info['speedCoe'];
- }
- v = info['flowModelCoe'];
- if (null != v && v.length > 0) {
- rtuInfo['flowModelCoe'] = info['flowModelCoe'];
- }
- let waterLevelSensorKind = rtuInfo.waterLevelSensorKind;
- let waterLevelSensorKindValue = info['waterLevelSensorKind'];
- for(let i=0;i<3;i++){
- if (waterLevelSensorKindValue == i) {
- waterLevelSensorKind[i]['checked'] = true;
- } else {
- waterLevelSensorKind[i]['checked'] = false;
- }
- }
- let flowRateSensorKind = rtuInfo.flowRateSensorKind;
- let flowRateSensorKindValue = info['flowRateSensorKind'];
- for(let i=0;i<3;i++){
- if (flowRateSensorKindValue == i) {
- flowRateSensorKind[i]['checked'] = true;
- } else {
- flowRateSensorKind[i]['checked'] = false;
- }
- }
- let flowRateSensorProtocolType = rtuInfo.flowRateSensorProtocolType;
- let flowRateSensorProtocolTypeValue = info['flowRateSensorProtocolType'];
- for(let i=0;i<15;i++){
- if (flowRateSensorProtocolTypeValue == i) {
- flowRateSensorProtocolType[i]['checked'] = true;
- } else {
- flowRateSensorProtocolType[i]['checked'] = false;
- }
- }
- let flowRateSensorId = info['flowRateSensorId'];
- if (null != flowRateSensorId && flowRateSensorId.length > 0) {
- rtuInfo['flowRateSensorId'] = flowRateSensorId;
- }
- this.setData({
- rtuInfo: rtuInfo
- });
- this.cancelTime();
- } else if (funcode == '42') {
- this.setData({
- showSettingResult: true,
- settingResultText: "运行参数配置已完成!"
- })
- // wx.showToast({
- // title: 'RTU运行参数设置已完成!',
- // icon: 'ok',
- // duration: 2000 //持续的时间
- // })
- } 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: 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) {
- 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
- })
- }
- })
|