+
+
关闭系统
机车手
0) {
@@ -263,24 +265,22 @@
// speed = '30';
// }
// }, 2000);
- });
+ // });
initPage();
- setTimeout(function(){
- initService()
- },1000)
- api.addEventListener({
- name: 'keyback'
- }, function (ret, err) {
- mui.confirm('确认关闭TMR饲喂系统?', '提示', btnArray, function (e) {
- if (e.index == 0) {} else {
- api.closeWidget({
- id: api.appId, //应用ID
- retData: { name: 'closeWidget' },
- silent: true
- });
- }
- });
- });
+ initService()
+ // api.addEventListener({
+ // name: 'keyback'
+ // }, function (ret, err) {
+ // mui.confirm('确认关闭TMR饲喂系统?', '提示', btnArray, function (e) {
+ // if (e.index == 0) {} else {
+ // api.closeWidget({
+ // id: api.appId, //应用ID
+ // retData: { name: 'closeWidget' },
+ // silent: true
+ // });
+ // }
+ // });
+ // });
};
function rescan(){
@@ -637,7 +637,14 @@ function getDateStr(date) {
allow = json[0].allow;
// 计划
_planSum = json[0].weight.toFixed(0);
- allowAuto = _planSum >= 100;
+ renderUnload();
+ feedMyChart.setOption({
+ dataset: {
+ source: [[1, _feedNum]]
+ }
+ });
+ // 误差小于100必须校准才能自动跳转
+ allowAuto = false;
document.getElementById('feedNum').innerHTML = ':' + _planSum + ' /已装:' + _feedNum + ' ';
text = feedName + _planSum;
batchName = e.className + e.trainNumber;
@@ -709,12 +716,26 @@ function getDateStr(date) {
networkStatus = true;
api.hideProgress();
document.getElementById('text').innerHTML = '设备初始化成功';
- sbId = ret.data[0].sbId;
- document.getElementById('showUserPicker').innerHTML = ret.data[0].name;
- ret.data.forEach(function (e) {
- var json = { value: e.sbId, text: e.name };
- pickData.push(json);
+ var initsb = api.getPrefs({
+ sync: true,
+ key: 'initsb'
});
+ ret.data.forEach(function (e) {
+ if (initsb === e.name){
+ var json = { value: e.sbId, text: e.name };
+ pickData.push(json);
+ }
+ });
+ ret.data.forEach(function (e) {
+ if (initsb !== e.name){
+ var json = { value: e.sbId, text: e.name };
+ pickData.push(json);
+ }
+ });
+ // sbId = ret.data[0].sbId;
+ // document.getElementById('showUserPicker').innerHTML = ret.data[0].name;
+ sbId = pickData[0].value;
+ document.getElementById('showUserPicker').innerHTML = pickData[0].text;
muiInit();
initTime();
} else {
@@ -727,11 +748,16 @@ function getDateStr(date) {
}
// 刷新页面
function reloadPage() {
- mui.confirm('确认重新初始化页面么?', '提示', btnArray, function (e) {
- if (e.index == 0) {} else {
- getWifiInfo();
- }
- });
+ api.openWin({
+ name: 'collection',
+ reload:true,
+ url:'../html/collection.html'
+ })
+ // mui.confirm('确认重新初始化页面么?', '提示', btnArray, function (e) {
+ // if (e.index == 0) {} else {
+ // getWifiInfo();
+ // }
+ // });
}
var sid;
// 获取WiFi信息,并刷新页面数据
diff --git a/pages/login.stml b/pages/login.stml
index 75695b8..4476feb 100644
--- a/pages/login.stml
+++ b/pages/login.stml
@@ -59,7 +59,7 @@ export default {
api.openWin({
name: 'index',
reload:true,
- url:'../html/index1.html'
+ url:'../html/index.html'
})
}
},
@@ -263,7 +263,7 @@ export default {
api.openWin({
name: 'index',
reload:true,
- url:'../html/index1.html'
+ url:'../html/index.html'
})
// if (ret.loginUser.sourceCow !=2 ) {
// api.openWin({
diff --git a/script/ble.js b/script/ble.js
index d63003c..7143ae5 100644
--- a/script/ble.js
+++ b/script/ble.js
@@ -3,7 +3,6 @@
function initManager(param) {
ble.initManager(param, function (ret) {
if (ret.state === "poweredOn") {
- // console.log("初始化成功");
scan({clean: true});
} else if (ret.state === 'poweredOff') {
api.hideProgress();
@@ -46,6 +45,7 @@ function scan(param) {
modal: true
});
}else {
+ stopScan()
clearInterval(scanInter)
getPeripheral();
}
@@ -53,6 +53,11 @@ function scan(param) {
}
});
}
+
+function stopScan(){
+ ble.stopScan()
+}
+
/*获取扫描结果*/
function getPeripheral() {
ble.getPeripheral(function (ret) {
@@ -126,12 +131,22 @@ function connect(param) {
document.getElementById('text').innerHTML = '设备已连接';
text = '设备已连接';
console.log('主机端连接成功')
- initWeight();
- discoverService({peripheralUUID: param.peripheralUUID});
+ ble.setMtu({
+ peripheralUUID: param.peripheralUUID,
+ mtu:50
+ },function(ret){
+ if(ret.status){
+ initWeight();
+ discoverService({peripheralUUID: param.peripheralUUID});
+ }else{
+ mui.alert(ret.code)
+ }
+ });
}else {
connetcedStatus = false
connectTimes ++;
console.log('主机端连接失败'+connectTimes+' '+uuid)
+ addNotice(sbId + '主机端连接失败'+connectTimes+'次 '+uuid);
wifiDom.innerHTML = '连接失败';
api.hideProgress();
setTimeout(function (){
@@ -173,10 +188,11 @@ var serviceUUID =''
var characteristicUUID =''
// 蓝牙待发送消息列表
var msgList = [];
+var timerMsgList = null;
// 清除消息定时任务
clearInterval(timerMsgList)
/*蓝牙消息发送定时任务150ms*/
-var timerMsgList = setInterval(function(){
+timerMsgList = setInterval(function(){
// console.log(new Date().getSeconds()+ ' ' + new Date().getMilliseconds() +' ' + msgList.length)
if (msgList.length > 0) {
// 发送报文
@@ -186,7 +202,8 @@ var timerMsgList = setInterval(function(){
peripheralUUID: peripheralUUID,
serviceUUID: serviceUUID,
characteristicUUID: characteristicUUID,
- value: msg
+ value: msg,
+ writeType:'withoutResponse'
};
if(connetcedStatus && peripheralUUID && serviceUUID && characteristicUUID){
writeValueForCharacteristic(param1, function (ret) {
@@ -195,6 +212,7 @@ var timerMsgList = setInterval(function(){
}
}
},150)
+
// 未装料状态计数,采集达到10次,发送一次停止蜂鸣指令
var bleConunt=0;
// 默认不自动跳转
@@ -212,6 +230,10 @@ function discoverService(param) {
serviceUUID: ret4,
peripheralUUID: param.peripheralUUID
}, function (ret5) {
+ if(ret5.indexOf("0000ffe2")!==-1){
+ return false
+ }
+ console.log(ret5)
peripheralUUID = param.peripheralUUID;
serviceUUID =ret4;
characteristicUUID =ret5;
@@ -226,8 +248,15 @@ function discoverService(param) {
return false
}
nowWeight = ret6;
+ getMess({
+ peripheralUUID: param.peripheralUUID,
+ serviceUUID: ret4,
+ characteristicUUID: ret5,
+ value: ret6
+ }, function (ret7) {
+ });
// 装料状态
- if(feedStatus){
+ if(feedStatus && allowAuto){
if (first) {
first = false;
beforeWeight = nowWeight;
@@ -249,18 +278,18 @@ function discoverService(param) {
}
serviceUUID = ret4;
characteristicUUID = ret5;
- // 组装led报文
- if (ledStatus && !isNaN(nowWeight)) {
- getMess({
- peripheralUUID: param.peripheralUUID,
- serviceUUID: ret4,
- characteristicUUID: ret5,
- value: ret6
- }, function (ret7) {
- });
- }
+ // // 组装led报文
+ // if (ledStatus && !isNaN(nowWeight)) {
+ // // getMess({
+ // // peripheralUUID: param.peripheralUUID,
+ // // serviceUUID: ret4,
+ // // characteristicUUID: ret5,
+ // // value: ret6
+ // // }, function (ret7) {
+ // // });
+ // }
// 装料状态
- if(feedStatus){
+ if(feedStatus && allowAuto){
// 计划-饲喂
var feedErr = _planSum-_feedNum;
if (isNaN(feedErr)) {
@@ -293,7 +322,6 @@ function discoverService(param) {
} else if (0.1 < ration && ration <= 0.2) {
time = "05";
if (!statusEle || lastTime !== time) {
- console.log(feedErr + ' ' + allow + ' ' + _feedNum + ' ' + _planSum);
lastTime = time;
ledStatus = false;
status = '间隔';
@@ -308,7 +336,6 @@ function discoverService(param) {
} else if (0.05 < ration && ration <= 0.1) {
time = "03";
if (!statusEle || lastTime !== time) {
- console.log(feedErr + ' ' + allow + ' ' + _feedNum + ' ' + _planSum);
lastTime = time;
ledStatus = false;
status = '间隔';
@@ -323,7 +350,6 @@ function discoverService(param) {
} else if (0.02 < ration && ration <= 0.05) {
time = "01";
if (!statusEle || lastTime !== time) {
- console.log(feedErr + ' ' + allow + ' ' + _feedNum + ' ' + _planSum);
lastTime = time;
ledStatus = false;
status = '间隔';
@@ -337,7 +363,6 @@ function discoverService(param) {
}
} else {
if (status === '间隔' || status === '') {
- console.log(feedErr + ' ' + allow + ' ' + _feedNum + ' ' + _planSum);
ledStatus = false;
status = '长鸣';
statusEle = true;
@@ -422,7 +447,6 @@ function StringToNum(hexx){
/*监听蓝牙数据,转换重量数据*/
function setNotify(param, callback) {
ble.setNotify(param, function (ret) {
- // console.log(JSON.stringify(ret))
var value = ret.characteristic.value;
// if (ret && value.indexOf('ff01') !== -1) {
if (ret && value.substr(0,4) === 'ff01') {
@@ -434,11 +458,11 @@ function setNotify(param, callback) {
callback(wei);
});
}
+
/*发送消息到蓝牙*/
function writeValueForCharacteristic(param, callback) {
if (param.value && connetcedStatus){
ble.writeValueForCharacteristic(param, function (ret) {
- // console.log(JSON.stringify(ret));
if (ret.status) {
// console.log("发送成功");
} else {
@@ -450,7 +474,7 @@ function writeValueForCharacteristic(param, callback) {
}
var lastTime = new Date().getSeconds()*1000+ new Date().getMilliseconds();
// 接收重量数据计数
-var count = 0;
+var countLED = 0;
/*组装报文并发数*/
function getMess(param, callback) {
var param1 = {
@@ -509,22 +533,22 @@ function getMess(param, callback) {
param1.msg = newmsg + Math.abs(Number(_planSum - _feedNum)).toFixed(0) + 'kg';
}
// param1.msg = newmsg + Math.abs(Number(param.value)).toFixed(0) + 'kg'
- console.log(param1.msg)
+ // console.log(param1.msg)
//组装字符卡LED报文
zfk.getMsg(param1, function (ret, err) {
var str = ret.sendMsg;
str = str.replace(/\s+/g, "");
var num = str.length / 2;
param.value = "FF0500" + num.toString(16) + str;
- count ++;
+ countLED ++;
// 称重量数据3包取1包
- if (count >= 3){
+ if (countLED >= 3){
msgList.push(param.value);
// var ms = strToHex(sbId,4)+strToHex(classCode,2)+strToHex(trainNumber,2)+strToHex(feedIndex,2)+strToHex(_planSum,4)+strToHex(_feedNum,4)+strToHex(nowWeight,4);
// var num1 = ms.length / 2;
// 同步刷新图表
// 饲喂状态刷新实时状态,否则不刷新装料信息
- if(feedStatus){
+ if(feedStatus && allowAuto){
renderUnload();
feedMyChart.setOption({
dataset: {
@@ -538,7 +562,7 @@ function getMess(param, callback) {
source: [[1, nowWeight]]
}
});
- count = 0 ;
+ countLED = 0 ;
}
});
}
diff --git a/script/index.js b/script/index.js
index 7db2323..9d802a2 100644
--- a/script/index.js
+++ b/script/index.js
@@ -173,8 +173,14 @@ function submitData() {
document.querySelector('#feed_' + feedIndex).scrollIntoView(true);
allow = feedList[feedIndex].allow;
_planSum = feedList[feedIndex].weight.toFixed(0);
+ renderUnload();
+ feedMyChart.setOption({
+ dataset: {
+ source: [[1, _feedNum]]
+ }
+ });
// 误差小于100必须校准才能自动跳转
- allowAuto = _planSum >= 100;
+ allowAuto = false;
text = feedName + _planSum;
document.getElementById('nowFeed').innerHTML = '' + batchName + ',' + feedName + ' ';
ledStatus = false;
@@ -595,24 +601,30 @@ function hex2a(hexx) {
}return str;
}
-function speakTest(text, speed) {
- // IFlyVoice.stopSpeaking();
- IFlyVoice.startSynthetic({
- text: text,
- commonPath_Android: 'widget://res/aisound/common.jet',
- pronouncePath_Android: 'widget://res/aisound/xiaofeng.jet',
- commonPath_iOS: 'widget://res/aisound/common.jet',
- pronouncePath_iOS: 'widget://res/aisound/xiaofeng.jet',
- pronounceName: 'xiaofeng',
- volume: '100',
- speed: speed
- }, function (ret, err) {
- if (ret.status) {
- console.log('合成成功');
- } else {}
+// function speakTest(text, speed) {
+// // IFlyVoice.stopSpeaking();
+// IFlyVoice.startSynthetic({
+// text: text,
+// commonPath_Android: 'widget://res/aisound/common.jet',
+// pronouncePath_Android: 'widget://res/aisound/xiaofeng.jet',
+// commonPath_iOS: 'widget://res/aisound/common.jet',
+// pronouncePath_iOS: 'widget://res/aisound/xiaofeng.jet',
+// pronounceName: 'xiaofeng',
+// volume: '100',
+// speed: speed
+// }, function (ret, err) {
+// if (ret.status) {
+// console.log('合成成功');
+// } else {}
+// });
+// }
+function handleBackMain() {
+ mui.confirm('确认返回到首页?', '提示', btnArray, function (e) {
+ if (e.index == 0) {} else {
+ api.closeWin();
+ }
});
}
-
function closeApp() {
mui.confirm('确认关闭TMR饲喂系统?', '提示', btnArray, function (e) {
if (e.index == 0) {} else {
@@ -656,7 +668,6 @@ var WeightDataFilter = function () {
this.dataBuffer.shift();
}
var filteredValue = this.getAverageValue();
- // console.log(filteredValue,Math.abs(filteredValue - this.lastValidValue),this.maxDeviation);
if (isNaN(this.lastValidValue) || Math.abs(filteredValue - this.lastValidValue) <= this.maxDeviation) {
this.lastValidValue = filteredValue;
return filteredValue;