修改班次饲喂完成led显示饲喂完成不刷新数据,间隔两秒发送停止蜂鸣,重量稳定跳料,兼容两种协议称,修改led三丢一,修改稳定40包跳转
This commit is contained in:
parent
be8ee40a27
commit
c7ec831768
|
@ -584,9 +584,8 @@ function getDateStr(date) {
|
||||||
}
|
}
|
||||||
// 初始化当前车次饲料信息
|
// 初始化当前车次饲料信息
|
||||||
function initOne(param) {
|
function initOne(param) {
|
||||||
if (sid) {
|
|
||||||
document.getElementById('submitData').setAttribute("class", 'btnc mui-btn-success');
|
document.getElementById('submitData').setAttribute("class", 'btnc mui-btn-success');
|
||||||
}
|
feedStatus = true
|
||||||
api.ajax({
|
api.ajax({
|
||||||
url: 'https://tmr.nxcyx.com/api/app/tmr/planDay',
|
url: 'https://tmr.nxcyx.com/api/app/tmr/planDay',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
123
script/ble.js
123
script/ble.js
|
@ -163,38 +163,63 @@ var msgLed = '';
|
||||||
var msgChan = '';
|
var msgChan = '';
|
||||||
var msgVoice = '';
|
var msgVoice = '';
|
||||||
var sendStatus = true;
|
var sendStatus = true;
|
||||||
|
var msgList = [];
|
||||||
|
|
||||||
var timerLed = null;
|
var timerLed = null;
|
||||||
|
|
||||||
clearInterval(timerLed)
|
clearInterval(timerssss)
|
||||||
timerLed = setInterval(function(){
|
var timerssss = setInterval(function(){
|
||||||
if (sendStatus && connetcedStatus && peripheralUUID && serviceUUID && characteristicUUID) {
|
// console.log(new Date().getSeconds()+ ' ' + new Date().getMilliseconds() +' ' + msgList.length)
|
||||||
sendStatus = false;
|
if (msgList.length > 0) {
|
||||||
|
// 发送报文
|
||||||
|
var msg = msgList[0];
|
||||||
|
msgList.splice(0, 1);
|
||||||
var param1 = {
|
var param1 = {
|
||||||
peripheralUUID: peripheralUUID,
|
peripheralUUID: peripheralUUID,
|
||||||
serviceUUID: serviceUUID,
|
serviceUUID: serviceUUID,
|
||||||
characteristicUUID: characteristicUUID,
|
characteristicUUID: characteristicUUID,
|
||||||
value: msgLed
|
value: msg
|
||||||
};
|
};
|
||||||
// console.log("msgLed"+new Date().getMilliseconds())
|
if(connetcedStatus && peripheralUUID && serviceUUID && characteristicUUID){
|
||||||
writeValueForCharacteristic(param1, function (ret) {});
|
writeValueForCharacteristic(param1, function (ret) {
|
||||||
setTimeout(function () {
|
// console.log(ret.status)
|
||||||
param1.value = msgVoice
|
});
|
||||||
// console.log("msgVoice"+new Date().getMilliseconds())
|
}
|
||||||
writeValueForCharacteristic(param1, function (ret) {});
|
|
||||||
setTimeout(function () {
|
|
||||||
param1.value = msgChan
|
|
||||||
// console.log("msgChan"+new Date().getMilliseconds())
|
|
||||||
writeValueForCharacteristic(param1, function (ret) {});
|
|
||||||
setTimeout(function () {
|
|
||||||
// console.log("sendStatus"+new Date().getMilliseconds())
|
|
||||||
sendStatus = true
|
|
||||||
}, 30);
|
|
||||||
}, 50);
|
|
||||||
}, 50);
|
|
||||||
}
|
}
|
||||||
},150)
|
},150)
|
||||||
|
|
||||||
|
// clearInterval(timerLed)
|
||||||
|
// timerLed = setInterval(function(){
|
||||||
|
// if (sendStatus && connetcedStatus && peripheralUUID && serviceUUID && characteristicUUID) {
|
||||||
|
// sendStatus = false;
|
||||||
|
// var param1 = {
|
||||||
|
// peripheralUUID: peripheralUUID,
|
||||||
|
// serviceUUID: serviceUUID,
|
||||||
|
// characteristicUUID: characteristicUUID,
|
||||||
|
// value: msgLed
|
||||||
|
// };
|
||||||
|
// // console.log("msgLed"+new Date().getMilliseconds())
|
||||||
|
// writeValueForCharacteristic(param1, function (ret) {});
|
||||||
|
// setTimeout(function () {
|
||||||
|
// param1.value = msgVoice
|
||||||
|
// // console.log("msgVoice"+new Date().getMilliseconds())
|
||||||
|
// writeValueForCharacteristic(param1, function (ret) {});
|
||||||
|
// setTimeout(function () {
|
||||||
|
// param1.value = msgChan
|
||||||
|
// // console.log("msgChan"+new Date().getMilliseconds())
|
||||||
|
// writeValueForCharacteristic(param1, function (ret) {});
|
||||||
|
// setTimeout(function () {
|
||||||
|
// // console.log("sendStatus"+new Date().getMilliseconds())
|
||||||
|
// sendStatus = true
|
||||||
|
// }, 30);
|
||||||
|
// }, 50);
|
||||||
|
// }, 50);
|
||||||
|
// }
|
||||||
|
// },150)
|
||||||
|
|
||||||
|
var bleConunt=0;
|
||||||
|
|
||||||
function discoverService(param) {
|
function discoverService(param) {
|
||||||
ble.discoverService(param, function (ret) {
|
ble.discoverService(param, function (ret) {
|
||||||
if (ret.services.length > 0) {
|
if (ret.services.length > 0) {
|
||||||
|
@ -214,6 +239,9 @@ function discoverService(param) {
|
||||||
serviceUUID: ret4,
|
serviceUUID: ret4,
|
||||||
characteristicUUID: ret5
|
characteristicUUID: ret5
|
||||||
}, function (ret6) {
|
}, function (ret6) {
|
||||||
|
if(!feedStatus){
|
||||||
|
return false
|
||||||
|
}
|
||||||
if (ret6 !== undefined) {
|
if (ret6 !== undefined) {
|
||||||
if (isNaN(ret6)) {
|
if (isNaN(ret6)) {
|
||||||
return false
|
return false
|
||||||
|
@ -264,13 +292,15 @@ function discoverService(param) {
|
||||||
}
|
}
|
||||||
var ration = feedErr / count;
|
var ration = feedErr / count;
|
||||||
// console.log("ration" + ration.toFixed(2));
|
// console.log("ration" + ration.toFixed(2));
|
||||||
if (ration > 0.2 ) {
|
if (ration > 0.2) {
|
||||||
if (statusEle) {
|
bleConunt ++;
|
||||||
console.log(feedErr + ' ' + allow + ' ' + _feedNum + ' ' + _planSum);
|
if (statusEle || (bleConunt >= 10)===true) {
|
||||||
|
console.log("停止蜂鸣"+statusEle+' '+(bleConunt));
|
||||||
|
bleConunt=0;
|
||||||
ledStatus = false;
|
ledStatus = false;
|
||||||
status = '';
|
status = '';
|
||||||
statusEle = false;
|
statusEle = false;
|
||||||
console.log("停止蜂鸣");
|
msgList = [];
|
||||||
control("00", "00");
|
control("00", "00");
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
ledStatus = true;
|
ledStatus = true;
|
||||||
|
@ -284,6 +314,7 @@ function discoverService(param) {
|
||||||
ledStatus = false;
|
ledStatus = false;
|
||||||
status = '间隔';
|
status = '间隔';
|
||||||
statusEle = true;
|
statusEle = true;
|
||||||
|
msgList = [];
|
||||||
console.log("开始蜂鸣" + time);
|
console.log("开始蜂鸣" + time);
|
||||||
control("60", time);
|
control("60", time);
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
@ -298,6 +329,7 @@ function discoverService(param) {
|
||||||
ledStatus = false;
|
ledStatus = false;
|
||||||
status = '间隔';
|
status = '间隔';
|
||||||
statusEle = true;
|
statusEle = true;
|
||||||
|
msgList = [];
|
||||||
console.log("开始蜂鸣" + time);
|
console.log("开始蜂鸣" + time);
|
||||||
control("60", time);
|
control("60", time);
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
@ -312,6 +344,7 @@ function discoverService(param) {
|
||||||
ledStatus = false;
|
ledStatus = false;
|
||||||
status = '间隔';
|
status = '间隔';
|
||||||
statusEle = true;
|
statusEle = true;
|
||||||
|
msgList = [];
|
||||||
console.log("开始蜂鸣" + time);
|
console.log("开始蜂鸣" + time);
|
||||||
control("60", time);
|
control("60", time);
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
@ -324,6 +357,7 @@ function discoverService(param) {
|
||||||
ledStatus = false;
|
ledStatus = false;
|
||||||
status = '长鸣';
|
status = '长鸣';
|
||||||
statusEle = true;
|
statusEle = true;
|
||||||
|
msgList = [];
|
||||||
console.log("开始长鸣");
|
console.log("开始长鸣");
|
||||||
control("40", "02");
|
control("40", "02");
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
@ -341,9 +375,9 @@ function discoverService(param) {
|
||||||
}
|
}
|
||||||
if (feedErr <= allow) {
|
if (feedErr <= allow) {
|
||||||
var filteredValue = weightDataFilter.filter(nowWeight);
|
var filteredValue = weightDataFilter.filter(nowWeight);
|
||||||
if (weightDataFilter.dataBuffer.length === 80) {
|
if (weightDataFilter.dataBuffer.length == 40) {
|
||||||
console.log("重量稳定", currTimeFn(new Date()));
|
console.log("重量稳定", currTimeFn(new Date()));
|
||||||
weightDataFilter.dataBuffer = [];
|
weightDataFilter.dataBuffer = []
|
||||||
document.getElementById('submitData').click();
|
document.getElementById('submitData').click();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -377,13 +411,36 @@ function discoverCharacteristics(param, callback) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function StringToNum(hexx){
|
||||||
|
var hex = hexx.toString(); //force conversion
|
||||||
|
var str = '';
|
||||||
|
var num = '';
|
||||||
|
for (var i = 0; i < hex.length; i += 2) {
|
||||||
|
num = String.fromCharCode(parseInt(hex.substr(i, 2), 16));
|
||||||
|
if((num >= '0' && num <= '9') || (num == '-'))
|
||||||
|
{
|
||||||
|
str += num;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(str.length != 0)
|
||||||
|
{
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}return str;
|
||||||
|
}
|
||||||
|
|
||||||
function setNotify(param, callback) {
|
function setNotify(param, callback) {
|
||||||
ble.setNotify(param, function (ret) {
|
ble.setNotify(param, function (ret) {
|
||||||
// console.log(JSON.stringify(ret))
|
// console.log(JSON.stringify(ret))
|
||||||
var value = ret.characteristic.value;
|
var value = ret.characteristic.value;
|
||||||
if (ret && value.indexOf('ff01') !== -1) {
|
// if (ret && value.indexOf('ff01') !== -1) {
|
||||||
var wei = value.substr(12, 12);
|
if (ret && value.substr(0,4) === 'ff01') {
|
||||||
wei = Math.round(Number(hex2a(wei)));
|
var wei = value.substr(8, value.length-8);
|
||||||
|
// var wei = value.substr(12, 12);
|
||||||
|
// wei = Math.round(Number(hex2a(wei)));
|
||||||
|
wei = Math.round(Number(StringToNum(wei)));
|
||||||
}
|
}
|
||||||
callback(wei);
|
callback(wei);
|
||||||
});
|
});
|
||||||
|
@ -452,8 +509,8 @@ function getMess(param, callback) {
|
||||||
var num = str.length / 2;
|
var num = str.length / 2;
|
||||||
param.value = "FF0500" + num.toString(16) + str;
|
param.value = "FF0500" + num.toString(16) + str;
|
||||||
count ++;
|
count ++;
|
||||||
if (count >= 5){
|
if (count >= 3){
|
||||||
// msgList.push(param.value);
|
msgList.push(param.value);
|
||||||
msgLed = param.value;
|
msgLed = 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 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;
|
// var num1 = ms.length / 2;
|
||||||
|
@ -491,7 +548,7 @@ function initWeight() {
|
||||||
modal: true
|
modal: true
|
||||||
});
|
});
|
||||||
weightStatus = true;
|
weightStatus = true;
|
||||||
weightDataFilter = new WeightDataFilter(80, _weightSum);
|
weightDataFilter = new WeightDataFilter(40, _weightSum);
|
||||||
renderUnload();
|
renderUnload();
|
||||||
renderLoad();
|
renderLoad();
|
||||||
feedMyChart.setOption({
|
feedMyChart.setOption({
|
||||||
|
|
|
@ -53,4 +53,6 @@ var lastMsg = '';
|
||||||
function control(status, time) {
|
function control(status, time) {
|
||||||
var msg = "FFFF000D" + getControlCmd(status, time);
|
var msg = "FFFF000D" + getControlCmd(status, time);
|
||||||
msgVoice = msg;
|
msgVoice = msg;
|
||||||
|
msgList=[]
|
||||||
|
msgList.push(msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,8 +81,64 @@ function submitData() {
|
||||||
trainIndex = trainIndex + 1;
|
trainIndex = trainIndex + 1;
|
||||||
// 没有下一个车次,饲喂完成
|
// 没有下一个车次,饲喂完成
|
||||||
if (trainIndex > trainArr.length - 1) {
|
if (trainIndex > trainArr.length - 1) {
|
||||||
mui.toast('本班次饲喂完成');
|
// mui.alert("本班次饲喂完成");
|
||||||
|
feedStatus = false
|
||||||
|
_feedNum = batchName+'次饲喂完成'
|
||||||
|
renderUnload();
|
||||||
|
renderLoad();
|
||||||
|
feedMyChart.setOption({
|
||||||
|
dataset: {
|
||||||
|
source: [[1, _feedNum]]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
weightMyChart.setOption({
|
||||||
|
dataset: {
|
||||||
|
source: [[1, nowWeight]]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var param1 = {
|
||||||
|
SF: "AA A5 ",
|
||||||
|
LEN: '1A 00 ',
|
||||||
|
DES: 'FF FF ',
|
||||||
|
SRC: '12 34 ',
|
||||||
|
TID: 'B0 A1 ',
|
||||||
|
CMD1: '38 02 ',
|
||||||
|
X: '00 00 ',
|
||||||
|
Y: '00 00 ',
|
||||||
|
WIDTH: '40 00 ',
|
||||||
|
HEIGHT: '20 00 ',
|
||||||
|
FORMAT: '00 00 01 00 ',
|
||||||
|
CNT: '04 00 ',
|
||||||
|
CRC: '00 00 ',
|
||||||
|
EF: '5A 55 ',
|
||||||
|
msg: ''
|
||||||
|
};
|
||||||
|
// param1.msg = batchName+'饲喂完成'
|
||||||
|
var newmsg = batchName+'次';
|
||||||
|
var msglen = newmsg.getByteLen();
|
||||||
|
var ttr = '';
|
||||||
|
if (msglen < 8) {
|
||||||
|
for (var i = 0; i < 8 - msglen; i++) {
|
||||||
|
newmsg = newmsg + ' ';
|
||||||
|
}
|
||||||
|
newmsg = newmsg + ttr;
|
||||||
|
} else {
|
||||||
|
newmsg = feedName + ttr;
|
||||||
|
}
|
||||||
|
param1.msg = newmsg + '饲喂完成';
|
||||||
|
|
||||||
|
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;
|
||||||
|
msgList.push(param.value);
|
||||||
|
})
|
||||||
document.getElementById('submitData').setAttribute("class", 'btnc mui-btn-success dis');
|
document.getElementById('submitData').setAttribute("class", 'btnc mui-btn-success dis');
|
||||||
|
setTimeout(function(){
|
||||||
|
console.log("停止蜂鸣");
|
||||||
|
control("00", "00");
|
||||||
|
},500)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// 自动点击下一车,并定位,同时刷新下一个开始装料时间
|
// 自动点击下一车,并定位,同时刷新下一个开始装料时间
|
||||||
|
@ -143,6 +199,7 @@ var serviceUUID = '';
|
||||||
var characteristicUUID = '';
|
var characteristicUUID = '';
|
||||||
var lastTime = "";
|
var lastTime = "";
|
||||||
var time = "";
|
var time = "";
|
||||||
|
var feedStatus = false;
|
||||||
|
|
||||||
|
|
||||||
var connetcedStatus = false;
|
var connetcedStatus = false;
|
||||||
|
@ -363,8 +420,9 @@ function renderItemFeed(params, api) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeTextFeed(valOnRadian) {
|
function makeTextFeed(valOnRadian) {
|
||||||
// if (load) {
|
if (isNaN(_feedNum )) {
|
||||||
if (Math.abs(_planSum - _feedNum) >= 0) {
|
return batchName + '次' + '\n' + '饲喂完成'
|
||||||
|
}else if (Math.abs(_planSum - _feedNum) >= 0) {
|
||||||
// return '剩余应装\n' + valOnRadian.toFixed(1) + 'kg';
|
// return '剩余应装\n' + valOnRadian.toFixed(1) + 'kg';
|
||||||
return feedName + '\n' + echartsType + Math.abs(_planSum - _feedNum).toFixed(0) + 'kg';
|
return feedName + '\n' + echartsType + Math.abs(_planSum - _feedNum).toFixed(0) + 'kg';
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue