修改样式

This commit is contained in:
liuwu 2023-10-30 18:06:37 +08:00
parent c7ec831768
commit 7824fefaa0
5 changed files with 151 additions and 155 deletions

View File

@ -74,7 +74,7 @@
.btnc { .btnc {
margin-left: 15px; margin-left: 15px;
/* margin-right: 15px; */ /* margin-right: 15px; */
font-size: larger; font-size: x-large;
font-weight: 900; font-weight: 900;
border-radius: 20px; border-radius: 20px;
} }
@ -97,29 +97,30 @@
} }
.mui-toast-message { .mui-toast-message {
/* background: url(/app/themes/default/images/toast.png) no-repeat center 10px #407ae6; */ background: url(/app/themes/default/images/toast.png) no-repeat center 10px #407ae6;
opacity: 1; opacity: 1;
/* color: #fff; */ font-size: xx-large;
color: #fff;
width: 100%; width: 100%;
padding: 10px 5px 10px 5px; padding: 20px 10px 20px 10px;
} }
</style> </style>
<body> <body>
<div class="mui-row"> <div class="mui-row">
<!--头部信息开始--> <!--头部信息开始-->
<div class="head flex mui-row"> <div class="head flex mui-row">
<div class="mui-col-xs-7" style="display:flex;align-items: center;"> <div class="mui-col-xs-5" style="display:flex;align-items: center;">
<button id='showUserPicker' class="btnc mui-btn-inline mui-btn-primary" type='button'>请选择设备</button> <button id='showUserPicker' class="btnc mui-btn-inline mui-btn-primary" type='button'>请选择设备</button>
<text id='batchName' style="font-size: larger;margin-left:15px;font-weight: 900;"></text> <text id='batchName' style="font-size: x-large;margin-left:15px;font-weight: 900;"></text>
<button class="btnc mui-btn-inline mui-btn-primary" type='button' onclick="refreshDayPlan()">更新计划</button> <button class="btnc mui-btn-inline mui-btn-primary" type='button' onclick="refreshDayPlan()">更新计划</button>
<button class="btnc mui-btn-inline mui-btn-primary" type='button' onclick="reloadPage()">刷新页面</button> <!-- <button class="btnc mui-btn-inline mui-btn-primary" type='button' onclick="reloadPage()">刷新页面</button> -->
</div> </div>
<div class="mui-col-xs-5" style="display:flex;justify-content: flex-end;"> <div class="mui-col-xs-7" style="display:flex;justify-content: flex-end;">
<button class="btnc mui-btn-inline mui-btn-danger" onclick="closeApp()" type='button'>关闭系统</button> <button class="btnc mui-btn-inline mui-btn-danger" onclick="closeApp()" type='button'>关闭系统</button>
<button id="driveName" class="btnc mui-btn-info" type="button" onclick="handleBackSys()">机车手</button> <button id="driveName" class="btnc mui-btn-info" type="button" onclick="handleBackSys()">机车手</button>
<button id='wifiDom' class="btnc mui-btn-inline mui-btn-info" <button id='wifiDom' class="btnc mui-btn-inline mui-btn-info"
style="color: seagreen !important;" type='button'>暂未连接</button> style="color: seagreen !important;" type='button' onclick="rescan()"></button>
<button id='showBlePicker' class="btnc mui-btn-inline mui-btn-primary" type='button'>选择蓝牙</button> <button id='showBlePicker' class="btnc mui-btn-inline mui-btn-primary dis" type='button'>连接蓝牙</button>
</div> </div>
</div> </div>
<!--中间内容开始--> <!--中间内容开始-->
@ -127,7 +128,7 @@
<!--中间左边开始--> <!--中间左边开始-->
<div class="mui-col-xs-3 centerLeft"> <div class="mui-col-xs-3 centerLeft">
<ul class="mui-table-view" id="train" <ul class="mui-table-view" id="train"
style="text-align: left;line-height: 40px;font-size: larger;font-weight: 900;"> style="text-align: left;line-height: 60px;font-size: xx-large;font-weight: 900;">
</ul> </ul>
</div> </div>
<!--中间右边开始--> <!--中间右边开始-->
@ -139,12 +140,12 @@
<div id="echarts_main_one" class="mui-col-sm-6 echarts_item"></div> <div id="echarts_main_one" class="mui-col-sm-6 echarts_item"></div>
<div id="echarts_main_two" class="mui-col-sm-6 echarts_item"></div> <div id="echarts_main_two" class="mui-col-sm-6 echarts_item"></div>
<div class="mui-col-sm-12 flex2"> <div class="mui-col-sm-12 flex2">
<button class="btnc mui-btn-success" style="font-size: x-large;" type="button" id="fix" onclick="weightFix()">校准计划</button> <button class="btnc mui-btn-success" style="font-size: xx-large;" type="button" id="fix" onclick="weightFix()">校准计划</button>
<text id='nowFeed' style="font-size:x-large;font-weight: 900;margin-left:10px; "></text> <text id='nowFeed' style="font-size:x-large;font-weight: 900;margin-left:10px; "></text>
<text id='feedNum' style="font-size: x-large;font-weight: 900;"></text> <text id='feedNum' style="font-size: x-large;font-weight: 900;"></text>
<button class="btnc mui-btn-success" id="startLoad" style="font-size: x-large;width: 20%;;" <button class="btnc mui-btn-success" id="startLoad" style="font-size: xx-large;width: 20%;;"
onclick="startLoad()">开始装料</button> onclick="startLoad()">开始装料</button>
<button class="btnc mui-btn-success dis" id="submitData" style="font-size: x-large;" <button class="btnc mui-btn-success dis" id="submitData" style="font-size: xx-large;"
onclick="submitData()">上传</button> onclick="submitData()">上传</button>
</div> </div>
@ -154,7 +155,7 @@
<!--尾部信息开始--> <!--尾部信息开始-->
<div class="footer flex mui-row"> <div class="footer flex mui-row">
<div class="mui-col-xs-2" > <div class="mui-col-xs-2" >
<text id="text" style="margin-left: 20px;font-weight: 900;font-size: larger;" onclick="updateApp()"></text> <text id="text" style="margin-left: 20px;font-weight: 900;font-size: x-large;" onclick="updateApp()"></text>
</div> </div>
<div class="mui-col-xs-10" id="timeList" > <div class="mui-col-xs-10" id="timeList" >
@ -177,14 +178,14 @@
var weightMyChart = echarts.init(weightChartDom); var weightMyChart = echarts.init(weightChartDom);
var feedChartDom = document.getElementById('echarts_main_one'); var feedChartDom = document.getElementById('echarts_main_one');
var feedMyChart = echarts.init(feedChartDom); var feedMyChart = echarts.init(feedChartDom);
var _outerRadius = 165; var _outerRadius = 215;
var _innerRadius = 135; var _innerRadius = 185;
var feedName; var feedName;
var templateName; var templateName;
var templetType; var templetType;
var _pointerInnerRadius = 70; var _pointerInnerRadius = 120;
var _insidePanelRadius = 130; var _insidePanelRadius = 180;
var fontsize = 50; var fontsize = 80;
var feedList = []; var feedList = [];
var feedIndex = 0; var feedIndex = 0;
var classCode = 1; var classCode = 1;
@ -282,6 +283,16 @@
}); });
}; };
function rescan(){
if(!connetcedStatus){
if(bleData.length>0){
connect({peripheralUUID: bleData[0].value});
}else{
scan()
}
}
}
function initService() { function initService() {
initManager({single: true}); initManager({single: true});
} }
@ -313,7 +324,7 @@ function getDateStr(date) {
x: '65%', x: '65%',
y: '70%', y: '70%',
textStyle: { textStyle: {
fontSize: 28, fontSize: 60,
fontWeight: '100', fontWeight: '100',
color: '#5dc3ea', color: '#5dc3ea',
lineHeight: 16, lineHeight: 16,
@ -325,7 +336,7 @@ function getDateStr(date) {
x: '15%', x: '15%',
y: '70%', y: '70%',
textStyle: { textStyle: {
fontSize: 28, fontSize: 60,
fontWeight: '100', fontWeight: '100',
color: '#5dc3ea', color: '#5dc3ea',
lineHeight: 16, lineHeight: 16,
@ -360,7 +371,7 @@ function getDateStr(date) {
label: { label: {
normal: { normal: {
textStyle: { textStyle: {
fontSize: 56, fontSize: 86,
color: '#fff' color: '#fff'
} }
} }
@ -401,7 +412,7 @@ function getDateStr(date) {
label: { label: {
normal: { normal: {
textStyle: { textStyle: {
fontSize: 56, fontSize: 86,
color: '#fff' color: '#fff'
} }
} }
@ -560,9 +571,9 @@ function getDateStr(date) {
ret.data.forEach(function (e, index) { ret.data.forEach(function (e, index) {
trainArr.push(e.trainNumber); trainArr.push(e.trainNumber);
if (index == 0) { if (index == 0) {
html += '<li id="classeCode_' + e.classCode + 'train_' + index + '" class="mui-table-view-cell trains" onclick="handleCarClick(this,' + '\'' + e.classCode + '\',\'' + e.trainNumber + '\')">' + e.trainNumber + '(' + e.templetName + ')</li>'; html += '<li id="classeCode_' + e.classCode + 'train_' + index + '" class="mui-table-view-cell trains" onclick="handleCarClick(this,' + '\'' + e.classCode + '\',\'' + e.trainNumber + '\')">'+e.className + e.trainNumber + '(' + e.templetName + ')</li>';
} else { } else {
html += '<li id="classeCode_' + e.classCode + 'train_' + index + '" class="mui-table-view-cell" onclick="handleCarClick(this,' + '\'' + e.classCode + '\',\'' + e.trainNumber + '\')">' + e.trainNumber + '(' + e.templetName + ')</li>'; html += '<li id="classeCode_' + e.classCode + 'train_' + index + '" class="mui-table-view-cell" onclick="handleCarClick(this,' + '\'' + e.classCode + '\',\'' + e.trainNumber + '\')">'+e.className + e.trainNumber + '(' + e.templetName + ')</li>';
} }
}); });
document.getElementById('train').innerHTML = html; document.getElementById('train').innerHTML = html;
@ -611,9 +622,9 @@ function getDateStr(date) {
feedList = json; feedList = json;
json.forEach(function (j, index) { 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: large;font-weight: 900;">' + UNICODE_CHARS[index + 1] + j.name + ':' + Number(j.weight).toFixed(0) + '</span>'; 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 { } else {
html += '<span id="feed_' + index + '" class="mui-badge" style="font-size: large;font-weight: 900;">' + UNICODE_CHARS[index + 1] + j.name + ':' + Number(j.weight).toFixed(0) + '</span>'; 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>';
} }
}); });
document.getElementById('feedList').innerHTML = html; document.getElementById('feedList').innerHTML = html;
@ -630,7 +641,7 @@ function getDateStr(date) {
allow = json[0].allow; allow = json[0].allow;
// 计划 // 计划
_planSum = json[0].weight.toFixed(0); _planSum = json[0].weight.toFixed(0);
document.getElementById('feedNum').innerHTML = '<font style="color:blue">计划:' + _planSum + '</font>/<font style="color:green">已装:' + _feedNum + '</font>'; document.getElementById('feedNum').innerHTML = '<font style="color:blue">:' + _planSum + '</font>/<font style="color:green">已装:' + _feedNum + '</font>';
text = feedName + _planSum; text = feedName + _planSum;
batchName = e.className + e.trainNumber; batchName = e.className + e.trainNumber;
templateName = e.templetName; templateName = e.templetName;

View File

@ -42,7 +42,7 @@ export default {
phone:null, phone:null,
code:null, code:null,
resCode:null, resCode:null,
codeSwitch:false, codeSwitch:true,
isLoading:false, isLoading:false,
isLogin:true isLogin:true
} }

View File

@ -1,4 +1,5 @@
"use strict"; "use strict";
/*初始化蓝牙适配器*/
function initManager(param) { function initManager(param) {
ble.initManager(param, function (ret) { ble.initManager(param, function (ret) {
if (ret.state === "poweredOn") { if (ret.state === "poweredOn") {
@ -15,20 +16,22 @@ function initManager(param) {
var times = 5; var times = 5;
var sta = true; var sta = true;
var scanInter; var scanInter;
/*开始扫描*/
function scan(param) { function scan(param) {
// if (!uuid){ if (!uuid){
// uuid = api.getPrefs({ uuid = api.getPrefs({
// sync: true, sync: true,
// key: 'uuid' key: 'uuid'
// }); });
// } }
// if (uuid){ if (uuid){
// disconnect({peripheralUUID: uuid}); isConnected({peripheralUUID: uuid},function(ret){
// connect({peripheralUUID: uuid}); console.log("isConnected"+ret);
// return false if(ret){
// } disconnect({peripheralUUID: uuid});
sta = true }
})
}
clearInterval(scanInter) clearInterval(scanInter)
times = 5; times = 5;
ble.scan(param, function (ret) { ble.scan(param, function (ret) {
@ -36,83 +39,76 @@ function scan(param) {
scanInter = setInterval(function (){ scanInter = setInterval(function (){
if (times>0){ if (times>0){
times --; times --;
var wifiDom = document.getElementById('wifiDom');
wifiDom.innerHTML = "扫描中"+times;
api.showProgress({ api.showProgress({
title: '扫描中'+times+'...', title: '扫描中'+times+'...',
modal: true modal: true
}); });
}else { }else {
if (sta){ clearInterval(scanInter)
getPeripheral(); getPeripheral();
sta = false;
}
} }
},1000) },1000)
} }
}); });
} }
/*获取扫描结果*/
function getPeripheral() { function getPeripheral() {
ble.getPeripheral(function (ret) { ble.getPeripheral(function (ret) {
bleData = [] bleData = []
var ret2 = {}; var ret2 = {};
var wifiDom = document.getElementById('wifiDom');
if (ret.peripherals.length > 0) { if (ret.peripherals.length > 0) {
ret.peripherals.forEach(function (p) { ret.peripherals.forEach(function (p) {
if (undefined !== p.name) { if (undefined !== p.name) {
console.log(p.name); console.log(p.name);
if (p.name.indexOf("TMR_BLE") === -1){ if (p.name.indexOf("TMR_BLE") === -1){
return false return false
}else{
mui.toast("已扫描到" +p.name,{duration:3500,type:'div'});
wifiDom.innerHTML = p.name+'(未连接)';
document.getElementById('showBlePicker').setAttribute("class", 'btnc mui-btn-inline mui-btn-primary');
var json = { value: p.uuid, text: p.name };
bleData.push(json);
if (!uuid){
uuid = api.getPrefs({
sync: true,
key: 'uuid'
});
}
if (uuid && uuid === p.uuid){
document.getElementById('showBlePicker').innerHTML = p.name
isConnected({peripheralUUID: uuid},function(ret){
console.log("isConnected"+ret);
if(ret){
disconnect({peripheralUUID: uuid});
connect({peripheralUUID: uuid});
}else{
connect({peripheralUUID: uuid});
}
})
}
} }
var json = { value: p.uuid, text: p.name };
bleData.push(json);
if (!uuid){
uuid = api.getPrefs({
sync: true,
key: 'uuid'
});
}
if (uuid && uuid === p.uuid){
disconnect({peripheralUUID: uuid});
connect({peripheralUUID: uuid});
}
// if (p.name.indexOf("BLUE2USART") !== -1) {
// uuid = p.uuid;
// api.setPrefs({
// key: 'uuid',
// value: uuid
// });
// ret2 = p;
// if (ret2 !== {}) {
// var wifiDom = document.getElementById('wifiDom');
// wifiDom.innerHTML = "设备:" + ret2.name;
// api.hideProgress();
// api.showProgress({
// title: '设备连接中...',
// modal: true
// });
// document.getElementById('text').innerHTML = '设备连接中';
// connect({peripheralUUID: ret2.uuid});
// }
// }
} }
}); });
bleInit() if(!bleData.length>0){
// if (undefined === ret2.uuid){ mui.toast("暂未扫描到蓝牙设备",{duration:3500,type:'div'});
// mui.confirm('没有扫描到设备信息,继续扫描?', '提示', btnArray, function (e) { document.getElementById('showBlePicker').setAttribute("class", 'btnc mui-btn-inline mui-btn-primary dis');
// if (e.index === 0) {} else { wifiDom.innerHTML = "重新扫描";
// scan({clean: true}); }else{
// } bleInit()
// }); }
// }
} }
api.hideProgress(); api.hideProgress();
}); });
} }
// 连接失败次数
var connectTimes=0; var connectTimes=0;
/*开始连接*/
function connect(param) { function connect(param) {
var wifiDom = document.getElementById('wifiDom'); var wifiDom = document.getElementById('wifiDom');
wifiDom.innerHTML = "暂未连接"; wifiDom.innerHTML = "";
api.showProgress({ api.showProgress({
title: '蓝牙连接中...', title: '蓝牙连接中...',
modal: true modal: true
@ -120,8 +116,8 @@ function connect(param) {
ble.connect(param, function (ret, err) { ble.connect(param, function (ret, err) {
if (ret.status) { if (ret.status) {
connetcedStatus = true connetcedStatus = true
connectTimes = 0;
wifiDom.innerHTML = '已连接'; wifiDom.innerHTML = '已连接';
connectTimes = 0;
document.getElementById('text').innerHTML = '设备已连接'; document.getElementById('text').innerHTML = '设备已连接';
text = '设备已连接'; text = '设备已连接';
console.log('主机端连接成功') console.log('主机端连接成功')
@ -134,7 +130,7 @@ function connect(param) {
wifiDom.innerHTML = '连接失败'; wifiDom.innerHTML = '连接失败';
api.hideProgress(); api.hideProgress();
setTimeout(function (){ setTimeout(function (){
if (connectTimes < 5 && !connetcedStatus && uuid){ if (!connetcedStatus && uuid){
console.log("连接失败!尝试重连" + uuid); console.log("连接失败!尝试重连" + uuid);
wifiDom.innerHTML = '尝试重连'; wifiDom.innerHTML = '尝试重连';
connect({peripheralUUID: uuid}); connect({peripheralUUID: uuid});
@ -143,7 +139,7 @@ function connect(param) {
} }
}); });
} }
/*断开连接*/
function disconnect(param) { function disconnect(param) {
ble.disconnect(param, function (ret, err) { ble.disconnect(param, function (ret, err) {
if (ret.status) { if (ret.status) {
@ -153,22 +149,29 @@ function disconnect(param) {
} }
}); });
} }
/*判断是否已连接*/
function isConnected(param,callback){
ble.isConnected(param, function(ret) {
if (ret) {
console.log('已连接');
}
callback(ret.status)
});
}
var i; var i;
// 蓝牙uuid
var peripheralUUID ='' var peripheralUUID =''
// 蓝牙服务id
var serviceUUID ='' var serviceUUID =''
// 蓝牙特征id
var characteristicUUID ='' var characteristicUUID =''
// 蓝牙待发送消息列表
var msgLed = '';
var msgChan = '';
var msgVoice = '';
var sendStatus = true;
var msgList = []; var msgList = [];
// 清除消息定时任务
var timerLed = null; clearInterval(timerMsgList)
/*蓝牙消息发送定时任务150ms*/
clearInterval(timerssss) var timerMsgList = setInterval(function(){
var timerssss = setInterval(function(){
// console.log(new Date().getSeconds()+ ' ' + new Date().getMilliseconds() +' ' + msgList.length) // console.log(new Date().getSeconds()+ ' ' + new Date().getMilliseconds() +' ' + msgList.length)
if (msgList.length > 0) { if (msgList.length > 0) {
// 发送报文 // 发送报文
@ -185,41 +188,11 @@ var timerssss = setInterval(function(){
// console.log(ret.status) // console.log(ret.status)
}); });
} }
} }
},150) },150)
// 未装料状态计数采集达到10次发送一次停止蜂鸣指令
// 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; 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) {
@ -227,6 +200,7 @@ function discoverService(param) {
ret.services.forEach(function (ret4) { ret.services.forEach(function (ret4) {
if (ret4.indexOf("0000ffe") !== -1) { if (ret4.indexOf("0000ffe") !== -1) {
if (ret4 && ret4.length > 0) { if (ret4 && ret4.length > 0) {
//发现特征
discoverCharacteristics({ discoverCharacteristics({
serviceUUID: ret4, serviceUUID: ret4,
peripheralUUID: param.peripheralUUID peripheralUUID: param.peripheralUUID
@ -234,6 +208,7 @@ function discoverService(param) {
peripheralUUID = param.peripheralUUID; peripheralUUID = param.peripheralUUID;
serviceUUID =ret4; serviceUUID =ret4;
characteristicUUID =ret5; characteristicUUID =ret5;
//监听消息
setNotify({ setNotify({
peripheralUUID: param.peripheralUUID, peripheralUUID: param.peripheralUUID,
serviceUUID: ret4, serviceUUID: ret4,
@ -268,7 +243,8 @@ function discoverService(param) {
serviceUUID = ret4; serviceUUID = ret4;
characteristicUUID = ret5; characteristicUUID = ret5;
// console.log(_feedNum,_weightSum,_planSum); // console.log(_feedNum,_weightSum,_planSum);
document.getElementById('feedNum').innerHTML = '<font style="color:blue">计划:' + _planSum + '</font>/<font style="color:green">已装:' + _feedNum + '</font>'; document.getElementById('feedNum').innerHTML = '<font style="color:blue">:' + _planSum + '</font>/<font style="color:green">已装:' + _feedNum + '</font>';
// 组装led报文
if (ledStatus && !isNaN(nowWeight)) { if (ledStatus && !isNaN(nowWeight)) {
getMess({ getMess({
peripheralUUID: param.peripheralUUID, peripheralUUID: param.peripheralUUID,
@ -284,18 +260,20 @@ function discoverService(param) {
if (isNaN(feedErr)) { if (isNaN(feedErr)) {
return false return false
} }
// 蜂鸣器校验基础值大于500的饲料取500为标准
var count; var count;
if (_planSum >= 500) { if (_planSum >= 500) {
count = 500 count = 500
} else { } else {
count = _planSum count = _planSum
} }
// 计算饲料装料量与基础值的误差比例
var ration = feedErr / count; var ration = feedErr / count;
// console.log("ration" + ration.toFixed(2)); // console.log("ration" + ration.toFixed(2));
// 误差分为100%-20%(停止蜂鸣)10%-20%(间隔05)5%-10%(间隔03),2%-5%(间隔01),-100%-2%(长鸣)
if (ration > 0.2) { if (ration > 0.2) {
bleConunt ++; bleConunt ++;
if (statusEle || (bleConunt >= 10)===true) { if (statusEle || (bleConunt >= 10)) {
console.log("停止蜂鸣"+statusEle+' '+(bleConunt));
bleConunt=0; bleConunt=0;
ledStatus = false; ledStatus = false;
status = ''; status = '';
@ -373,9 +351,12 @@ function discoverService(param) {
}, 500) }, 500)
} }
} }
// 在误差范围内
if (feedErr <= allow) { if (feedErr <= allow) {
// 重量稳定计数
var filteredValue = weightDataFilter.filter(nowWeight); var filteredValue = weightDataFilter.filter(nowWeight);
if (weightDataFilter.dataBuffer.length == 40) { // 重量稳定自动跳转
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();
@ -393,7 +374,7 @@ function discoverService(param) {
} }
}); });
} }
/*扫描特征*/
function discoverCharacteristics(param, callback) { function discoverCharacteristics(param, callback) {
ble.discoverCharacteristics(param, function (ret) { ble.discoverCharacteristics(param, function (ret) {
var res = ''; var res = '';
@ -410,27 +391,27 @@ function discoverCharacteristics(param, callback) {
} }
}); });
} }
/*适配两种称数据解析*/
function StringToNum(hexx){ function StringToNum(hexx){
var hex = hexx.toString(); //force conversion var hex = hexx.toString(); //force conversion
var str = ''; var str = '';
var num = ''; var num = '';
for (var i = 0; i < hex.length; i += 2) { for (var i = 0; i < hex.length; i += 2) {
num = String.fromCharCode(parseInt(hex.substr(i, 2), 16)); num = String.fromCharCode(parseInt(hex.substr(i, 2), 16));
if((num >= '0' && num <= '9') || (num == '-')) if((num >= '0' && num <= '9') || (num === '-'))
{ {
str += num; str += num;
} }
else else
{ {
if(str.length != 0) if(str.length !== 0)
{ {
return str return str
} }
} }
}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))
@ -445,7 +426,7 @@ function setNotify(param, callback) {
callback(wei); callback(wei);
}); });
} }
/*发送消息到蓝牙*/
function writeValueForCharacteristic(param, callback) { function writeValueForCharacteristic(param, callback) {
if (param.value && connetcedStatus){ if (param.value && connetcedStatus){
ble.writeValueForCharacteristic(param, function (ret) { ble.writeValueForCharacteristic(param, function (ret) {
@ -459,8 +440,8 @@ function writeValueForCharacteristic(param, callback) {
}); });
} }
} }
var lastCmd = "";
var lastTime = new Date().getSeconds()*1000+ new Date().getMilliseconds(); var lastTime = new Date().getSeconds()*1000+ new Date().getMilliseconds();
// 接收重量数据计数
var count = 0; var count = 0;
/*组装报文并发数*/ /*组装报文并发数*/
function getMess(param, callback) { function getMess(param, callback) {
@ -482,6 +463,9 @@ function getMess(param, callback) {
msg: '' msg: ''
}; };
var newmsg = feedName; var newmsg = feedName;
if(!newmsg.length>0){
return false
}
var msglen = newmsg.getByteLen(); var msglen = newmsg.getByteLen();
var ttr = ''; var ttr = '';
if (Number(_planSum - _feedNum) >= 0) { if (Number(_planSum - _feedNum) >= 0) {
@ -502,19 +486,19 @@ function getMess(param, callback) {
param1.msg = newmsg + Math.abs(Number(_planSum - _feedNum)).toFixed(0) + 'kg'; param1.msg = newmsg + Math.abs(Number(_planSum - _feedNum)).toFixed(0) + 'kg';
// param1.msg = newmsg + Math.abs(Number(param.value)).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) { zfk.getMsg(param1, function (ret, err) {
var str = ret.sendMsg; var str = ret.sendMsg;
str = str.replace(/\s+/g, ""); str = str.replace(/\s+/g, "");
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 ++;
// 称重量数据3包取1包
if (count >= 3){ if (count >= 3){
msgList.push(param.value); 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 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;
// msgChan = "FF0a00"+strToHex(num1,2) + ms // 同步刷新图表
renderUnload(); renderUnload();
renderLoad(); renderLoad();
feedMyChart.setOption({ feedMyChart.setOption({
@ -531,7 +515,7 @@ function getMess(param, callback) {
} }
}); });
} }
/*字符串转16进制hex*/
function strToHex(str,length){ function strToHex(str,length){
var hex = Number(str).toString(16); var hex = Number(str).toString(16);
var append = ''; var append = '';
@ -542,6 +526,7 @@ function strToHex(str,length){
} }
return append+hex; return append+hex;
} }
/*初始化重量图表*/
function initWeight() { function initWeight() {
api.showProgress({ api.showProgress({
title: '图表数据加装中...', title: '图表数据加装中...',

View File

@ -1,5 +1,5 @@
"use strict"; "use strict";
/*CRC16Modbus crc算法*/
function calculateCRC16Modbus(dataHexString) { function calculateCRC16Modbus(dataHexString) {
var dataBytes = []; var dataBytes = [];
for (var i = 0; i < dataHexString.length; i += 2) { for (var i = 0; i < dataHexString.length; i += 2) {
@ -43,16 +43,16 @@ function calculateCRC16Modbus(dataHexString) {
return crc.toString(16).toUpperCase(); return crc.toString(16).toUpperCase();
} }
/*组装蜂鸣器控制报文*/
function getControlCmd(status, time) { function getControlCmd(status, time) {
var cmd = "FE1003F6000204" + status + "0000" + time; var cmd = "FE1003F6000204" + status + "0000" + time;
var crc = calculateCRC16Modbus(cmd); var crc = calculateCRC16Modbus(cmd);
return cmd + crc.substring(2, 4) + crc.substring(0, 2); return cmd + crc.substring(2, 4) + crc.substring(0, 2);
} }
var lastMsg = ''; var lastMsg = '';
/*发送控制消息到蓝牙*/
function control(status, time) { function control(status, time) {
var msg = "FFFF000D" + getControlCmd(status, time); var msg = "FFFF000D" + getControlCmd(status, time);
msgVoice = msg;
msgList=[] msgList=[]
msgList.push(msg); msgList.push(msg);
} }

View File

@ -72,7 +72,7 @@ function submitData() {
} }
}, function (ret, err) { }, function (ret, err) {
if (ret && ret.code == 200) { if (ret && ret.code == 200) {
mui.toast(param.name + " 已上传 " + param.feedWeight); mui.toast(param.name + " 已上传 " + param.feedWeight,{duration:3500,type:'div'});
beforeWeight = nowWeight; beforeWeight = nowWeight;
// document.getElementById('beforeWeight').innerHTML = '称实时/装料前:' + nowWeight + '/' + beforeWeight; // document.getElementById('beforeWeight').innerHTML = '称实时/装料前:' + nowWeight + '/' + beforeWeight;
feedIndex = feedIndex + 1; feedIndex = feedIndex + 1;