修改样式,小于100的饲料不点击校准不自动跳转,班次完成一直显示饲喂完成,车内总重量实时显示,led屏幕一直显示班次完成
This commit is contained in:
parent
03cfb549bb
commit
ab1b5f183e
|
@ -496,10 +496,6 @@ function getDateStr(date) {
|
|||
console.log('蓝牙'+JSON.stringify(items[0]));
|
||||
showBlePickerButton.innerHTML = items[0].text;
|
||||
uuid = items[0].value
|
||||
api.setPrefs({
|
||||
key: 'uuid',
|
||||
value: uuid
|
||||
});
|
||||
connect({peripheralUUID: items[0].value});
|
||||
});
|
||||
}, false);
|
||||
|
@ -621,7 +617,7 @@ function getDateStr(date) {
|
|||
var json = [].concat(_toConsumableArray(e.feedJson), _toConsumableArray(e.cowshedJson));
|
||||
feedList = json;
|
||||
json.forEach(function (j, index) {
|
||||
if (index == 0) {
|
||||
if (index === 0) {
|
||||
html += '<span id="feed_' + index + '" class="mui-badge mui-badge-purple" style="font-size: xx-large;font-weight: 900;">' + UNICODE_CHARS[index + 1] + j.name + ':' + Number(j.weight).toFixed(0) + '</span>';
|
||||
} else {
|
||||
html += '<span id="feed_' + index + '" class="mui-badge" style="font-size: xx-large;font-weight: 900;">' + UNICODE_CHARS[index + 1] + j.name + ':' + Number(j.weight).toFixed(0) + '</span>';
|
||||
|
@ -641,6 +637,7 @@ function getDateStr(date) {
|
|||
allow = json[0].allow;
|
||||
// 计划
|
||||
_planSum = json[0].weight.toFixed(0);
|
||||
allowAuto = _planSum >= 100;
|
||||
document.getElementById('feedNum').innerHTML = '<font style="color:blue">:' + _planSum + '</font>/<font style="color:green">已装:' + _feedNum + '</font>';
|
||||
text = feedName + _planSum;
|
||||
batchName = e.className + e.trainNumber;
|
||||
|
|
304
script/ble.js
304
script/ble.js
|
@ -116,6 +116,11 @@ function connect(param) {
|
|||
ble.connect(param, function (ret, err) {
|
||||
if (ret.status) {
|
||||
connetcedStatus = true
|
||||
// 缓存蓝牙设备uuid方便自动连接
|
||||
api.setPrefs({
|
||||
key: 'uuid',
|
||||
value: param.peripheralUUID
|
||||
});
|
||||
wifiDom.innerHTML = '已连接';
|
||||
connectTimes = 0;
|
||||
document.getElementById('text').innerHTML = '设备已连接';
|
||||
|
@ -192,6 +197,8 @@ var timerMsgList = setInterval(function(){
|
|||
},150)
|
||||
// 未装料状态计数,采集达到10次,发送一次停止蜂鸣指令
|
||||
var bleConunt=0;
|
||||
// 默认不自动跳转
|
||||
var allowAuto = false;
|
||||
/*扫描蓝牙服务*/
|
||||
function discoverService(param) {
|
||||
ble.discoverService(param, function (ret) {
|
||||
|
@ -214,36 +221,34 @@ function discoverService(param) {
|
|||
serviceUUID: ret4,
|
||||
characteristicUUID: ret5
|
||||
}, function (ret6) {
|
||||
if(!feedStatus){
|
||||
return false
|
||||
}
|
||||
if (ret6 !== undefined) {
|
||||
if (isNaN(ret6)) {
|
||||
return false
|
||||
}
|
||||
nowWeight = ret6;
|
||||
// console.log(ret6)
|
||||
if (first) {
|
||||
first = false;
|
||||
beforeWeight = nowWeight;
|
||||
}
|
||||
if (load) {
|
||||
_feedNum = nowWeight - beforeWeight;
|
||||
} else {
|
||||
_feedNum = beforeWeight - nowWeight;
|
||||
}
|
||||
text = feedName + _planSum;
|
||||
if (!isNaN(nowWeight)) {
|
||||
// 实时重量保存
|
||||
totalList.push({
|
||||
time: currTimeFn(new Date()),
|
||||
nowWeight: nowWeight
|
||||
});
|
||||
// 装料状态
|
||||
if(feedStatus){
|
||||
if (first) {
|
||||
first = false;
|
||||
beforeWeight = nowWeight;
|
||||
}
|
||||
if (load) {
|
||||
_feedNum = nowWeight - beforeWeight;
|
||||
} else {
|
||||
_feedNum = beforeWeight - nowWeight;
|
||||
}
|
||||
text = feedName + _planSum;
|
||||
if (!isNaN(nowWeight)) {
|
||||
// 实时重量保存
|
||||
totalList.push({
|
||||
time: currTimeFn(new Date()),
|
||||
nowWeight: nowWeight
|
||||
});
|
||||
}
|
||||
document.getElementById('feedNum').innerHTML = '<font style="color:blue">:' + _planSum + '</font>/<font style="color:green">已装:' + _feedNum + '</font>';
|
||||
}
|
||||
serviceUUID = ret4;
|
||||
characteristicUUID = ret5;
|
||||
// console.log(_feedNum,_weightSum,_planSum);
|
||||
document.getElementById('feedNum').innerHTML = '<font style="color:blue">:' + _planSum + '</font>/<font style="color:green">已装:' + _feedNum + '</font>';
|
||||
// 组装led报文
|
||||
if (ledStatus && !isNaN(nowWeight)) {
|
||||
getMess({
|
||||
|
@ -252,114 +257,117 @@ function discoverService(param) {
|
|||
characteristicUUID: ret5,
|
||||
value: ret6
|
||||
}, function (ret7) {
|
||||
// console.log(JSON.stringify(ret7))
|
||||
});
|
||||
}
|
||||
// 计划-饲喂
|
||||
var feedErr = _planSum-_feedNum;
|
||||
if (isNaN(feedErr)) {
|
||||
return false
|
||||
}
|
||||
// 蜂鸣器校验基础值,大于500的饲料,取500为标准
|
||||
var count;
|
||||
if (_planSum >= 500) {
|
||||
count = 500
|
||||
} else {
|
||||
count = _planSum
|
||||
}
|
||||
// 计算饲料装料量与基础值的误差比例
|
||||
var ration = feedErr / count;
|
||||
// console.log("ration" + ration.toFixed(2));
|
||||
// 误差分为100%-20%(停止蜂鸣),10%-20%(间隔05),5%-10%(间隔03),2%-5%(间隔01),-100%-2%(长鸣)
|
||||
if (ration > 0.2) {
|
||||
bleConunt ++;
|
||||
if (statusEle || (bleConunt >= 10)) {
|
||||
bleConunt=0;
|
||||
ledStatus = false;
|
||||
status = '';
|
||||
statusEle = false;
|
||||
msgList = [];
|
||||
control("00", "00");
|
||||
setTimeout(function () {
|
||||
ledStatus = true;
|
||||
}, 500);
|
||||
// 装料状态
|
||||
if(feedStatus){
|
||||
// 计划-饲喂
|
||||
var feedErr = _planSum-_feedNum;
|
||||
if (isNaN(feedErr)) {
|
||||
return false
|
||||
}
|
||||
} 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 = '间隔';
|
||||
statusEle = true;
|
||||
msgList = [];
|
||||
console.log("开始蜂鸣" + time);
|
||||
control("60", time);
|
||||
setTimeout(function () {
|
||||
ledStatus = true;
|
||||
}, 500);
|
||||
// 蜂鸣器校验基础值,大于500的饲料,取500为标准
|
||||
var count;
|
||||
if (_planSum >= 500) {
|
||||
count = 500
|
||||
} else {
|
||||
count = _planSum
|
||||
}
|
||||
} 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 = '间隔';
|
||||
statusEle = true;
|
||||
msgList = [];
|
||||
console.log("开始蜂鸣" + time);
|
||||
control("60", time);
|
||||
setTimeout(function () {
|
||||
ledStatus = true;
|
||||
}, 500);
|
||||
}
|
||||
} 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 = '间隔';
|
||||
statusEle = true;
|
||||
msgList = [];
|
||||
console.log("开始蜂鸣" + time);
|
||||
control("60", time);
|
||||
setTimeout(function () {
|
||||
ledStatus = true;
|
||||
}, 500);
|
||||
}
|
||||
} else {
|
||||
if (status === '间隔' || status === '') {
|
||||
console.log(feedErr + ' ' + allow + ' ' + _feedNum + ' ' + _planSum);
|
||||
ledStatus = false;
|
||||
status = '长鸣';
|
||||
statusEle = true;
|
||||
msgList = [];
|
||||
console.log("开始长鸣");
|
||||
control("40", "02");
|
||||
setTimeout(function () {
|
||||
ledStatus = true;
|
||||
}, 500);
|
||||
|
||||
setTimeout(function() {
|
||||
console.log("开始长鸣")
|
||||
control("40", "02");
|
||||
setTimeout(function() {
|
||||
// 计算饲料装料量与基础值的误差比例
|
||||
var ration = feedErr / count;
|
||||
// console.log("ration" + ration.toFixed(2));
|
||||
// 误差分为100%-20%(停止蜂鸣),10%-20%(间隔05),5%-10%(间隔03),2%-5%(间隔01),-100%-2%(长鸣)
|
||||
if (ration > 0.2) {
|
||||
bleConunt ++;
|
||||
if (statusEle || (bleConunt >= 10)) {
|
||||
bleConunt=0;
|
||||
ledStatus = false;
|
||||
status = '';
|
||||
statusEle = false;
|
||||
msgList = [];
|
||||
control("00", "00");
|
||||
setTimeout(function () {
|
||||
ledStatus = true;
|
||||
}, 500);
|
||||
}
|
||||
} 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 = '间隔';
|
||||
statusEle = true;
|
||||
msgList = [];
|
||||
console.log("开始蜂鸣" + time);
|
||||
control("60", time);
|
||||
setTimeout(function () {
|
||||
ledStatus = true;
|
||||
}, 500);
|
||||
}
|
||||
} 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 = '间隔';
|
||||
statusEle = true;
|
||||
msgList = [];
|
||||
console.log("开始蜂鸣" + time);
|
||||
control("60", time);
|
||||
setTimeout(function () {
|
||||
ledStatus = true;
|
||||
}, 500);
|
||||
}
|
||||
} 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 = '间隔';
|
||||
statusEle = true;
|
||||
msgList = [];
|
||||
console.log("开始蜂鸣" + time);
|
||||
control("60", time);
|
||||
setTimeout(function () {
|
||||
ledStatus = true;
|
||||
}, 500);
|
||||
}
|
||||
} else {
|
||||
if (status === '间隔' || status === '') {
|
||||
console.log(feedErr + ' ' + allow + ' ' + _feedNum + ' ' + _planSum);
|
||||
ledStatus = false;
|
||||
status = '长鸣';
|
||||
statusEle = true;
|
||||
msgList = [];
|
||||
console.log("开始长鸣");
|
||||
control("40", "02");
|
||||
setTimeout(function () {
|
||||
ledStatus = true;
|
||||
}, 500);
|
||||
|
||||
setTimeout(function() {
|
||||
console.log("开始长鸣")
|
||||
control("40", "02");
|
||||
setTimeout(function() {
|
||||
ledStatus = true;
|
||||
}, 500)
|
||||
}, 500)
|
||||
}, 500)
|
||||
}
|
||||
}
|
||||
}
|
||||
// 在误差范围内
|
||||
if (feedErr <= allow) {
|
||||
// 重量稳定计数
|
||||
var filteredValue = weightDataFilter.filter(nowWeight);
|
||||
// 重量稳定自动跳转
|
||||
if (weightDataFilter.dataBuffer.length === 40) {
|
||||
console.log("重量稳定", currTimeFn(new Date()));
|
||||
weightDataFilter.dataBuffer = []
|
||||
document.getElementById('submitData').click();
|
||||
// console.log(weightStabilization("weightStabilization"+nowWeight))
|
||||
// 在误差范围内
|
||||
if (feedErr <= allow && allowAuto) {
|
||||
// 重量稳定计数
|
||||
var filteredValue = weightDataFilter.filter(nowWeight);
|
||||
// 重量稳定自动跳转
|
||||
if (weightDataFilter.dataBuffer.length === 40) {
|
||||
console.log("重量稳定", currTimeFn(new Date()));
|
||||
weightDataFilter.dataBuffer = []
|
||||
document.getElementById('submitData').click();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -483,7 +491,23 @@ function getMess(param, callback) {
|
|||
} else {
|
||||
newmsg = feedName + ttr;
|
||||
}
|
||||
param1.msg = newmsg + Math.abs(Number(_planSum - _feedNum)).toFixed(0) + 'kg';
|
||||
// 不是装料状态班次饲喂完成显示
|
||||
if(!feedStatus){
|
||||
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 + '饲喂完成';
|
||||
}else{
|
||||
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)
|
||||
//组装字符卡LED报文
|
||||
|
@ -499,13 +523,16 @@ function getMess(param, callback) {
|
|||
// 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;
|
||||
// 同步刷新图表
|
||||
renderUnload();
|
||||
// 饲喂状态刷新实时状态,否则不刷新装料信息
|
||||
if(feedStatus){
|
||||
renderUnload();
|
||||
feedMyChart.setOption({
|
||||
dataset: {
|
||||
source: [[1, _feedNum]]
|
||||
}
|
||||
});
|
||||
}
|
||||
renderLoad();
|
||||
feedMyChart.setOption({
|
||||
dataset: {
|
||||
source: [[1, _feedNum]]
|
||||
}
|
||||
});
|
||||
weightMyChart.setOption({
|
||||
dataset: {
|
||||
source: [[1, nowWeight]]
|
||||
|
@ -559,3 +586,20 @@ function initWeight() {
|
|||
document.getElementById('text').innerHTML = 'V' + api.appVersion;
|
||||
api.setGlobalData({key: 'startTime', value: currTimeFn(new Date())});
|
||||
}
|
||||
|
||||
var lastWeight = 0;
|
||||
function weightStabilization(weight) {
|
||||
// 计算当前重量与上一次记录的重量之间的差值
|
||||
var diff = weight - lastWeight;
|
||||
// 如果差值在一定范围内,则认为重量是稳定的
|
||||
if (Math.abs(diff) < 2) {
|
||||
weight = weight;
|
||||
lastWeight = weight;
|
||||
return true;
|
||||
} else {
|
||||
// 如果差值超过一定范围,则认为重量是不稳定的,重新开始计算
|
||||
weight = 0;
|
||||
lastWeight = weight;
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -172,6 +172,8 @@ function submitData() {
|
|||
document.querySelector('#feed_' + feedIndex).scrollIntoView(true);
|
||||
allow = feedList[feedIndex].allow;
|
||||
_planSum = feedList[feedIndex].weight.toFixed(0);
|
||||
// 误差小于100必须校准才能自动跳转
|
||||
allowAuto = _planSum >= 100;
|
||||
text = feedName + _planSum;
|
||||
document.getElementById('nowFeed').innerHTML = '<font style="color:blue;margin-left:10px;">' + batchName + ',' + feedName + '</font>';
|
||||
ledStatus = false;
|
||||
|
|
Loading…
Reference in New Issue