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