1110 lines
39 KiB
HTML
1110 lines
39 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||
<title>Document</title>
|
||
<link rel="stylesheet" href="../css/mui_min.css">
|
||
<link href="../css/mui_picker_min.css" rel="stylesheet"/>
|
||
<link href="../css/mui_poppicker_css" rel="stylesheet"/>
|
||
<script src="../script/api.js"></script>
|
||
<script src="../script/mui.min.js"></script>
|
||
<script src="../script/mui.picker.min.js"></script>
|
||
<script src="../script/mui.poppicker.js"></script>
|
||
<script src="../script/echarts.js"></script>
|
||
|
||
</head>
|
||
<style>
|
||
.echarts_item {
|
||
width: 50%;
|
||
/*background-color: #007aff;*/
|
||
height: 68vh;
|
||
}
|
||
.flex{
|
||
/*flex 布局*/
|
||
display: flex;
|
||
/*实现垂直居中*/
|
||
align-items: center;
|
||
/*实现水平居中*/
|
||
justify-content: center;
|
||
text-align: justify;
|
||
width:100%;
|
||
}
|
||
.dis {
|
||
display: none;
|
||
font-size: 25px;
|
||
}
|
||
.btnCowshed{
|
||
margin-left: 5px;
|
||
font-size: xx-large;
|
||
font-weight: 900;
|
||
border-radius: 20px;
|
||
margin-top: 5px;
|
||
}
|
||
.btnc {
|
||
margin-left: 15px;
|
||
font-size: x-large;
|
||
font-weight: 900;
|
||
border-radius: 20px;
|
||
}
|
||
/*toast信息提示*/
|
||
.mui-toast-container {
|
||
bottom: 50% !important;
|
||
}
|
||
|
||
.mui-toast-message {
|
||
background: url(/app/themes/default/images/toast.png) no-repeat center 10px #407ae6;
|
||
opacity: 1;
|
||
font-size: xx-large;
|
||
color: #fff;
|
||
width: 100%;
|
||
padding: 20px 10px 20px 10px;
|
||
}
|
||
.htmlc{
|
||
height: 78vh;
|
||
box-sizing: border-box; border: 1px solid #a3caef;
|
||
overflow: auto;
|
||
}
|
||
.centerRight{
|
||
/*background-color: #007aff;*/
|
||
height: 79vh;
|
||
box-sizing: border-box; border: 1px solid #a3caef;
|
||
}
|
||
.centerLeft{
|
||
height: 79vh;
|
||
box-sizing: border-box; border: 1px solid #a3caef;
|
||
overflow: auto;
|
||
}
|
||
.head{
|
||
height: 10vh;
|
||
box-sizing: border-box; border: 1px solid #a3caef;
|
||
}
|
||
.content{
|
||
height: 79vh;
|
||
box-sizing: border-box; border: 1px solid #a3caef;
|
||
}
|
||
.footer{
|
||
height: 10vh;
|
||
box-sizing: border-box; border: 1px solid #a3caef;
|
||
}
|
||
.flex2{
|
||
/*flex 布局*/
|
||
display: flex;
|
||
/*实现垂直居中*/
|
||
align-items: center;
|
||
/*实现水平居中*/
|
||
justify-content: flex-end;
|
||
text-align: justify;
|
||
width:100%;
|
||
height: 10vh;
|
||
margin:0 auto;
|
||
}
|
||
</style>
|
||
<body>
|
||
<div class="mui-row">
|
||
<div class="head flex mui-row">
|
||
<div class="mui-col-sm-3" style="display:flex;align-items: center;">
|
||
<button class="btnc mui-btn-inline mui-btn-danger" onclick="handleBackMain()">返回</button>
|
||
<button class="btnc classes mui-btn-inline" onclick="handleClassClick(this,1,'早班')">早班</button>
|
||
<button class="btnc classes mui-btn-inline" onclick="handleClassClick(this,2,'中班')">中班</button>
|
||
<button class="btnc classes mui-btn-inline" onclick="handleClassClick(this,3,'晚班')">晚班</button>
|
||
</div>
|
||
<div class="mui-col-sm-9" style="display:flex;justify-content: flex-end;">
|
||
<button class="btnc mui-btn-inline mui-btn-danger" onclick="closeApp()" type='button'>关闭系统</button>
|
||
<button id='wifiDom' class="btnc mui-btn-inline mui-btn-info" onclick="rescan()"></button>
|
||
<button id='showBlePicker' class="btnc mui-btn-inline mui-btn-primary " type='button'>连接蓝牙</button>
|
||
</div>
|
||
</div>
|
||
<!--中间内容开始-->
|
||
<div class="mui-row content">
|
||
<div class="mui-row mui-col-sm-3 centerLeft">
|
||
<div id="htmlc" class="htmlc"></div>
|
||
</div>
|
||
<div class="mui-row mui-col-sm-9 contentRight" >
|
||
<div class="mui-row mui-col-sm-12" >
|
||
<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 class="mui-col-sm-12 flex2">
|
||
<button id="weightFix" class="btnc mui-btn-success flex dis" style="font-size: xx-large;width: 20%;" onclick="weightFix()">收集前校准</button>
|
||
<button id="nextCowshed" class="btnc mui-btn-success flex dis" style="font-size: xx-large;width: 20%;" onclick="nextCowshed()">上传</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="footer flex mui-row">
|
||
<div class="mui-col-sm-12 flex"style="width:100%;height:8vh;white-space: nowrap !important;overflow-x: scroll;" id="list">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<script type="text/javascript">
|
||
var batch = ''
|
||
var chartDom = document.getElementById('echarts_main_one');
|
||
var myChart = echarts.init(chartDom);
|
||
var option;
|
||
var chartDom1 = document.getElementById('echarts_main_two');
|
||
var myChart1 = echarts.init(chartDom1);
|
||
var option1;
|
||
|
||
var _panelImageURL = 'https://tmr.nxcyx.com/img/custom-gauge-panel.png';
|
||
var _animationDuration = 1000;
|
||
var _animationDurationUpdate = 1000;
|
||
var _animationEasingUpdate = 'quarticInOut';
|
||
var _valOnRadianMax = 200;
|
||
var _outerRadius = 200;
|
||
var _innerRadius = 170;
|
||
var _pointerInnerRadius = 40;
|
||
var _insidePanelRadius = 140;
|
||
var _currentDataIndex = 0;
|
||
var connetcedStatus = false;
|
||
|
||
var beforeWeight;
|
||
var nowWeight;
|
||
var _feedNum =0;
|
||
var cowshedList = []
|
||
var cowshedName = '收集重量'
|
||
var cowshedId
|
||
var btnArray = ['取消', '<b style="font-weight:900">确认</b>'];
|
||
|
||
//返回主页
|
||
function handleBackMain() {
|
||
mui.confirm('确认返回到首页?', '提示', btnArray, function (e) {
|
||
if (e.index == 0) {} else {
|
||
api.closeWin();
|
||
}
|
||
});
|
||
}
|
||
|
||
function handleClassClick(obj,b,name){
|
||
batch = b
|
||
mui.toast(name+'切换成功');
|
||
var doms = document.getElementsByClassName('classes');
|
||
if (doms.length > 0) {
|
||
for (var i = 0; i < doms.length; i++) {
|
||
doms[i].setAttribute("class", 'btnc classes mui-btn-inline');
|
||
}
|
||
}
|
||
obj.setAttribute("class", 'btnc classes mui-btn-inline mui-btn-primary');
|
||
}
|
||
|
||
function closeApp() {
|
||
mui.confirm('确认关闭TMR饲喂系统?', '提示', btnArray, function (e) {
|
||
if (e.index == 0) {} else {
|
||
api.closeWidget({
|
||
id: api.appId, //应用ID
|
||
retData: { name: 'closeWidget' },
|
||
silent: true
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
function getTmrCowshed(){
|
||
api.ajax({
|
||
url: 'https://tmr.nxcyx.com/api/app/tmr/getTmrCowshed?sourceCow=' + api.getPrefs({ sync: true, key: 'sourceCow' }),
|
||
// url: 'http://192.168.0.107:8088/app/tmr/getTmrCowshed?sourceCow=' + api.getPrefs({ sync: true, key: 'sourceCow' }),
|
||
method: 'get',
|
||
timeout: 5
|
||
}, function (ret, err) {
|
||
if (ret) {
|
||
var htmlc = ''
|
||
ret.data.forEach(c=>{
|
||
htmlc+='<button class="btnCowshed mui-btn-info btnCowshed" type="button" onclick="selectCowshed(this,' + '\'' + c.cowshed_name +'\''+ ',' + '\'' + c.id + '\')">'+c.cowshed_name+'</button>'
|
||
})
|
||
document.getElementById('htmlc').innerHTML = htmlc
|
||
} else {
|
||
mui.alert(err.msg);
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
|
||
function selectCowshed(obj,name,id){
|
||
cowshedName = name
|
||
cowshedId = id
|
||
var doms = document.getElementsByClassName('btnCowshed');
|
||
if (doms.length > 0) {
|
||
for (var i = 0; i < doms.length; i++) {
|
||
doms[i].setAttribute("class", 'btnCowshed mui-btn-info btnCowshed');
|
||
}
|
||
}
|
||
obj.setAttribute("class", 'btnCowshed mui-btn-success btnCowshed');
|
||
mui.toast(name+"切换成功");
|
||
document.getElementById('nextCowshed').innerHTML=name+'上传'
|
||
}
|
||
var allowAuto = false
|
||
function weightFix(){
|
||
if(cowshedName === '收集重量'){
|
||
mui.alert('请先选择圈舍')
|
||
return false
|
||
}
|
||
var btnArray1 = [cowshedName + '已完成', cowshedName + '未开始'];
|
||
mui.confirm('<b style="color:red">如果装料完成需要先上传</b>', '<b style="font-weight:900">校准前' + cowshedName + '状态</b>', btnArray1, function (e) {
|
||
if (e.index === 0) {
|
||
mui.toast('<b style="color:red">校准失败,已完成请先上传</b>');
|
||
} else {
|
||
beforeWeight = nowWeight;
|
||
allowAuto = true
|
||
mui.toast("校准完成");
|
||
}
|
||
});
|
||
}
|
||
|
||
function currTimeFn(_date) {
|
||
var _year = _date.getFullYear();
|
||
var _month = _date.getMonth() + 1 < 10 ? '0' + (_date.getMonth() + 1) : _date.getMonth() + 1;
|
||
var _day = _date.getDate() < 10 ? '0' + _date.getDate() : _date.getDate();
|
||
var _hour = _date.getHours() < 10 ? '0' + _date.getHours() : _date.getHours();
|
||
var _minutes = _date.getMinutes() < 10 ? '0' + _date.getMinutes() : _date.getMinutes();
|
||
var _seconds = _date.getSeconds() < 10 ? '0' + _date.getSeconds() : _date.getSeconds();
|
||
return _year + "-" + _month + "-" + _day + " " + _hour + ":" + _minutes + ":" + _seconds;
|
||
}
|
||
|
||
function nextCowshed(){
|
||
if(batch === ''){
|
||
mui.alert('请先选择班次')
|
||
return false
|
||
}
|
||
if(cowshedName === '收集重量'){
|
||
mui.alert('请先选择圈舍')
|
||
return false
|
||
}
|
||
cowshedList.push({name:cowshedName+':',wei:_feedNum,total:nowWeight});
|
||
var loginUser = api.getPrefs({sync: true, key: "loginUser"});
|
||
var obj = JSON.parse(loginUser);
|
||
var remainData = {
|
||
cowshedId: cowshedId,
|
||
batch: batch,
|
||
dateOf: currTimeFn(new Date()),
|
||
remain: _feedNum,
|
||
cowshedName: cowshedName,
|
||
sourceCow: api.getPrefs({ sync: true, key: 'sourceCow' }),
|
||
createBy: obj.nickName
|
||
}
|
||
console.log(JSON.stringify(remainData))
|
||
api.ajax({
|
||
url: 'https://tmr.nxcyx.com/api/app/tmr/resultRemainUpload',
|
||
headers: {
|
||
'Content-Type': 'application/json;charset=utf-8' //建议key使用首字母大写的形式,如 User-Agent
|
||
},
|
||
method: 'post',
|
||
data: {
|
||
body: remainData
|
||
}
|
||
}, function (ret, err) {
|
||
if (ret){
|
||
mui.toast(cowshedName+"上传成功");
|
||
cowshedName = '收集重量'
|
||
}
|
||
})
|
||
|
||
var html = '';
|
||
cowshedList.forEach(f=>{
|
||
html += '<span class="mui-badge" style="font-size: xx-large;font-weight: 900;">' + f.name + Number(f.wei).toFixed(0) + 'KG</span>';
|
||
// html+= '<div class="flex">'+f.name+f.wei+'KG</div>'
|
||
})
|
||
document.getElementById('list').innerHTML = html
|
||
beforeWeight = nowWeight
|
||
}
|
||
|
||
var wifiDom = document.getElementById('wifiDom');
|
||
|
||
function startCollect(){
|
||
initManager({single: true});
|
||
}
|
||
|
||
function initManager(param) {
|
||
ble.initManager(param, function (ret) {
|
||
if (ret.state === "poweredOn") {
|
||
scan({clean: true});
|
||
} else if (ret.state === 'poweredOff') {
|
||
api.hideProgress();
|
||
mui.alert('检查蓝牙是否打开');
|
||
}
|
||
});
|
||
}
|
||
|
||
function rescan(){
|
||
if(!connetcedStatus){
|
||
if(bleData.length>0){
|
||
connect({peripheralUUID: bleData[0].value});
|
||
}else{
|
||
scan()
|
||
}
|
||
}
|
||
}
|
||
|
||
var times = 5;
|
||
var ble;
|
||
var zfk;
|
||
var scanInter;
|
||
var uuid;
|
||
var connectTimes = 0;
|
||
var blePicker;
|
||
var bleData = [];
|
||
var bleListener = null;
|
||
var countLED = 0;
|
||
// 蓝牙uuid
|
||
var peripheralUUID =''
|
||
// 蓝牙服务id
|
||
var serviceUUID =''
|
||
// 蓝牙特征id
|
||
var characteristicUUID =''
|
||
var apiready = function apiready() {
|
||
ble = api.require('ble');
|
||
zfk = api.require("moduleDemo");
|
||
var connectId = api.getPrefs({
|
||
sync: true,
|
||
key: 'uuid'
|
||
});
|
||
if (connectId){
|
||
isConnected({peripheralUUID: connectId},function(ret){
|
||
if(ret){
|
||
disconnect({peripheralUUID: connectId});
|
||
}
|
||
})
|
||
}
|
||
startCollect()
|
||
getTmrCowshed()
|
||
}
|
||
|
||
function bleInit(){
|
||
(function ($, doc) {
|
||
$.init();
|
||
$.ready(function () {
|
||
/**
|
||
* 获取对象属性的值
|
||
* 主要用于过滤三级联动中,可能出现的最低级的数据不存在的情况,实际开发中需要注意这一点;
|
||
* @param {Object} obj 对象
|
||
* @param {String} param 属性名
|
||
*/
|
||
var _getParam = function _getParam(obj, param) {
|
||
return obj[param] || '';
|
||
};
|
||
if (blePicker) {} else {
|
||
blePicker = new $.PopPicker();
|
||
var showBlePickerButton = doc.getElementById('showBlePicker');
|
||
bleListener = null;
|
||
bleListener = showBlePickerButton.addEventListener('tap', function (event) {
|
||
blePicker.show(function (items) {
|
||
console.log('蓝牙'+JSON.stringify(items[0]));
|
||
showBlePickerButton.innerHTML = items[0].text;
|
||
uuid = items[0].value
|
||
connect({peripheralUUID: items[0].value});
|
||
});
|
||
}, false);
|
||
}
|
||
blePicker.setData(bleData);
|
||
});
|
||
})(mui, document);
|
||
}
|
||
/*开始扫描*/
|
||
function scan(param) {
|
||
if (!uuid){
|
||
uuid = api.getPrefs({
|
||
sync: true,
|
||
key: 'uuid'
|
||
});
|
||
}
|
||
if (uuid && connetcedStatus){
|
||
isConnected({peripheralUUID: uuid},function(ret){
|
||
console.log(uuid+ret);
|
||
var blename = api.getPrefs({
|
||
sync: true,
|
||
key: 'blename'
|
||
});
|
||
if(ret){
|
||
disconnect({peripheralUUID: uuid});
|
||
// connect({peripheralUUID: uuid,name:blename});
|
||
}else{
|
||
// connect({peripheralUUID: uuid,name:blename});
|
||
}
|
||
})
|
||
}else{
|
||
clearInterval(scanInter)
|
||
times = 5;
|
||
ble.scan(param, function (ret) {
|
||
if (ret.status) {
|
||
scanInter = setInterval(function (){
|
||
if (times>0){
|
||
times --;
|
||
wifiDom.innerHTML = "扫描中"+times;
|
||
api.showProgress({
|
||
title: '扫描中'+times+'...',
|
||
modal: true
|
||
});
|
||
}else {
|
||
stopScan()
|
||
clearInterval(scanInter)
|
||
getPeripheral();
|
||
}
|
||
},1000)
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
function stopScan(){
|
||
console.log("stopScan");
|
||
ble.stopScan()
|
||
}
|
||
/*获取扫描结果*/
|
||
function getPeripheral() {
|
||
ble.getPeripheral(function (ret) {
|
||
bleData = []
|
||
if (ret.peripherals.length > 0) {
|
||
ret.peripherals.forEach(function (p) {
|
||
if (undefined !== p.name) {
|
||
console.log(p.name);
|
||
if (p.name.indexOf("TMR_BLE") === -1){
|
||
return false
|
||
}else{
|
||
mui.toast("已扫描到" +p.name,{duration:3500,type:'div'});
|
||
wifiDom.innerHTML = p.name+'(未连接)';
|
||
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){
|
||
isConnected({peripheralUUID: uuid},function(ret){
|
||
if(ret){
|
||
disconnect({peripheralUUID: uuid});
|
||
connect({peripheralUUID: uuid,name:p.name});
|
||
}else{
|
||
connect({peripheralUUID: uuid,name:p.name});
|
||
}
|
||
})
|
||
}
|
||
}
|
||
}
|
||
});
|
||
|
||
if(!bleData.length>0){
|
||
mui.toast("暂未扫描到蓝牙设备",{duration:3500,type:'div'});
|
||
wifiDom.innerHTML = "重新扫描";
|
||
}else{
|
||
console.log("bleInit");
|
||
bleInit()
|
||
}
|
||
}
|
||
api.hideProgress();
|
||
});
|
||
}
|
||
/*判断是否已连接*/
|
||
function isConnected(param,callback){
|
||
ble.isConnected(param, function(ret) {
|
||
if (ret.status) {
|
||
console.log('已连接');
|
||
}
|
||
callback(ret.status)
|
||
});
|
||
}
|
||
|
||
function connect(param) {
|
||
var wifiDom = document.getElementById('wifiDom');
|
||
wifiDom.innerHTML = "";
|
||
api.showProgress({
|
||
title: '蓝牙连接中...',
|
||
modal: true
|
||
});
|
||
ble.connect(param, function (ret, err) {
|
||
if (ret.status) {
|
||
connetcedStatus = true
|
||
// 缓存蓝牙设备uuid方便自动连接
|
||
api.setPrefs({
|
||
key: 'uuid',
|
||
value: param.peripheralUUID
|
||
});
|
||
api.setPrefs({
|
||
key: 'blename',
|
||
value: param.name
|
||
});
|
||
wifiDom.innerHTML = '已连接';
|
||
document.getElementById('weightFix').setAttribute("class", 'btnc mui-btn-success flex');
|
||
document.getElementById('nextCowshed').setAttribute("class", 'btnc mui-btn-success flex');
|
||
connectTimes = 0;
|
||
text = '设备已连接';
|
||
api.hideProgress();
|
||
console.log('主机端连接成功')
|
||
ble.setMtu({
|
||
peripheralUUID: param.peripheralUUID,
|
||
mtu:120
|
||
},function(ret){
|
||
if(ret.status){
|
||
initWeight();
|
||
discoverService({peripheralUUID: param.peripheralUUID});
|
||
}else{
|
||
mui.alert(ret.code)
|
||
}
|
||
});
|
||
}else {
|
||
connetcedStatus = false
|
||
document.getElementById('weightFix').setAttribute("class", 'btnc mui-btn-success flex dis');
|
||
document.getElementById('nextCowshed').setAttribute("class", 'btnc mui-btn-success flex dis');
|
||
connectTimes ++;
|
||
console.log('主机端连接失败'+connectTimes+' '+uuid)
|
||
wifiDom.innerHTML = '连接失败';
|
||
api.hideProgress();
|
||
setTimeout(function (){
|
||
if (!connetcedStatus && uuid){
|
||
console.log("连接失败!尝试重连" + uuid);
|
||
wifiDom.innerHTML = '尝试重连';
|
||
connect({peripheralUUID: uuid,name:param.name});
|
||
}
|
||
},3000)
|
||
}
|
||
});
|
||
}
|
||
/*断开连接*/
|
||
function disconnect(param) {
|
||
ble.disconnect(param, function (ret, err) {
|
||
if (ret.status) {
|
||
console.log("断开连接成功!");
|
||
} else {
|
||
console.log("断开连接失败!");
|
||
}
|
||
});
|
||
}
|
||
|
||
function initWeight() {
|
||
api.showProgress({
|
||
title: '图表数据加装中...',
|
||
modal: true
|
||
});
|
||
renderUnload();
|
||
renderLoad();
|
||
myChart.setOption({
|
||
dataset: {
|
||
source: [[1, _feedNum]]
|
||
}
|
||
});
|
||
myChart1.setOption({
|
||
dataset: {
|
||
source: [[1, nowWeight]]
|
||
}
|
||
});
|
||
api.hideProgress();
|
||
}
|
||
|
||
function discoverService(param) {
|
||
ble.discoverService(param, function (ret) {
|
||
if (ret.services.length > 0) {
|
||
ret.services.forEach(function (ret4) {
|
||
if (ret4.indexOf("0000ffe") !== -1) {
|
||
if (ret4 && ret4.length > 0) {
|
||
//发现特征
|
||
discoverCharacteristics({
|
||
serviceUUID: ret4,
|
||
peripheralUUID: param.peripheralUUID
|
||
}, function (ret5) {
|
||
peripheralUUID = param.peripheralUUID;
|
||
serviceUUID =ret4;
|
||
characteristicUUID =ret5;
|
||
//监听消息
|
||
setNotify({
|
||
peripheralUUID: param.peripheralUUID,
|
||
serviceUUID: ret4,
|
||
characteristicUUID: ret5
|
||
}, function (ret6) {
|
||
if (ret6 !== undefined) {
|
||
if (isNaN(ret6)) {
|
||
return false
|
||
}
|
||
if(isNaN(beforeWeight)){
|
||
beforeWeight = nowWeight
|
||
}
|
||
nowWeight = ret6;
|
||
getMess({
|
||
peripheralUUID: param.peripheralUUID,
|
||
serviceUUID: ret4,
|
||
characteristicUUID: ret5,
|
||
value: ret6
|
||
}, function (ret7) {
|
||
});
|
||
_feedNum = nowWeight - beforeWeight;
|
||
renderUnload();
|
||
myChart.setOption({
|
||
dataset: {
|
||
source: [[1, _feedNum]]
|
||
}
|
||
});
|
||
// if (allowAuto){
|
||
// _feedNum = nowWeight - beforeWeight;
|
||
// renderUnload();
|
||
// myChart.setOption({
|
||
// dataset: {
|
||
// source: [[1, _feedNum]]
|
||
// }
|
||
// });
|
||
// }
|
||
// renderLoad();
|
||
// myChart1.setOption({
|
||
// dataset: {
|
||
// source: [[1, nowWeight]]
|
||
// }
|
||
// });
|
||
}
|
||
});
|
||
});
|
||
}
|
||
|
||
}
|
||
});
|
||
} else {
|
||
console.log("发现服务失败!");
|
||
}
|
||
});
|
||
}
|
||
|
||
var msgList = [];
|
||
var timerMsgList = null;
|
||
// 清除消息定时任务
|
||
clearInterval(timerMsgList)
|
||
/*蓝牙消息发送定时任务150ms*/
|
||
timerMsgList = 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: msg
|
||
};
|
||
if(connetcedStatus && peripheralUUID && serviceUUID && characteristicUUID){
|
||
writeValueForCharacteristic(param1, function (ret) {
|
||
// console.log(ret.status)
|
||
});
|
||
}
|
||
}
|
||
},150)
|
||
|
||
/*发送消息到蓝牙*/
|
||
function writeValueForCharacteristic(param, callback) {
|
||
if (param.value && connetcedStatus){
|
||
ble.writeValueForCharacteristic(param, function (ret) {
|
||
if (ret.status) {
|
||
// console.log("发送成功");
|
||
} else {
|
||
console.log("发送失败:"+param.value);
|
||
}
|
||
callback(ret);
|
||
});
|
||
}
|
||
}
|
||
|
||
String.prototype.getByteLen = function () {
|
||
var len = 0;
|
||
for (var i = 0; i < this.length; i++) {
|
||
this.charCodeAt(i) < 256 ? len += 1 : len += 2;
|
||
}
|
||
return len;
|
||
};
|
||
|
||
function getMess(param, callback) {
|
||
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: ''
|
||
};
|
||
var newmsg = cowshedName;
|
||
if(!newmsg.length>0){
|
||
return false
|
||
}
|
||
var msglen = newmsg.getByteLen();
|
||
if (msglen < 8) {
|
||
for (var i = 0; i < 8 - msglen; i++) {
|
||
newmsg = newmsg + ' ';
|
||
}
|
||
}
|
||
param1.msg = newmsg + (Number(_feedNum)).toFixed(0) + 'kg';
|
||
// param1.msg = newmsg + Math.abs(Number(param.value)).toFixed(0) + 'kg'
|
||
// 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;
|
||
countLED ++;
|
||
// 称重量数据3包取1包
|
||
if (countLED >= 3){
|
||
msgList.push(param.value);
|
||
renderUnload();
|
||
myChart.setOption({
|
||
dataset: {
|
||
source: [[1, _feedNum]]
|
||
}
|
||
});
|
||
renderLoad();
|
||
myChart1.setOption({
|
||
dataset: {
|
||
source: [[1, nowWeight]]
|
||
}
|
||
});
|
||
countLED = 0 ;
|
||
}
|
||
});
|
||
}
|
||
|
||
/*扫描特征*/
|
||
function discoverCharacteristics(param, callback) {
|
||
ble.discoverCharacteristics(param, function (ret) {
|
||
var res = '';
|
||
if (ret.characteristics.length > 0) {
|
||
// console.log("发现特征成功!");
|
||
ret.characteristics.forEach(function (s) {
|
||
if (s.serviceUUID === param.serviceUUID) {
|
||
callback(s.uuid);
|
||
}
|
||
});
|
||
} else {
|
||
console.log("发现特征失败!");
|
||
callback(res);
|
||
}
|
||
});
|
||
}
|
||
|
||
/*监听蓝牙数据,转换重量数据*/
|
||
function setNotify(param, callback) {
|
||
ble.setNotify(param, function (ret) {
|
||
var value = ret.characteristic.value;
|
||
if (ret && value.substr(0,4) === 'ff01') {
|
||
var wei = value.substr(8, value.length-8);
|
||
wei = Math.round(Number(StringToNum(wei)));
|
||
}
|
||
callback(wei);
|
||
});
|
||
}
|
||
|
||
/*适配两种称数据解析*/
|
||
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 renderItem(params, api) {
|
||
var valOnRadian = api.value(1);
|
||
var coords = api.coord([api.value(0), valOnRadian]);
|
||
var polarEndRadian = coords[3];
|
||
var imageStyle = {
|
||
image: _panelImageURL,
|
||
x: params.coordSys.cx - _outerRadius,
|
||
y: params.coordSys.cy - _outerRadius,
|
||
width: _outerRadius * 2,
|
||
height: _outerRadius * 2
|
||
};
|
||
return {
|
||
type: 'group',
|
||
children: [
|
||
{
|
||
type: 'image',
|
||
style: imageStyle,
|
||
clipPath: {
|
||
type: 'sector',
|
||
shape: {
|
||
cx: params.coordSys.cx,
|
||
cy: params.coordSys.cy,
|
||
r: _outerRadius,
|
||
r0: _innerRadius,
|
||
startAngle: 0,
|
||
endAngle: -polarEndRadian,
|
||
transition: 'endAngle',
|
||
enterFrom: {endAngle: 0}
|
||
}
|
||
}
|
||
},
|
||
{
|
||
type: 'image',
|
||
style: imageStyle,
|
||
clipPath: {
|
||
type: 'polygon',
|
||
shape: {
|
||
points: makePionterPoints(params, polarEndRadian)
|
||
},
|
||
extra: {
|
||
polarEndRadian: polarEndRadian,
|
||
transition: 'polarEndRadian',
|
||
enterFrom: {polarEndRadian: 0}
|
||
},
|
||
during: function (apiDuring) {
|
||
apiDuring.setShape(
|
||
'points',
|
||
makePionterPoints(params, apiDuring.getExtra('polarEndRadian'))
|
||
);
|
||
}
|
||
}
|
||
},
|
||
{
|
||
type: 'circle',
|
||
shape: {
|
||
cx: params.coordSys.cx,
|
||
cy: params.coordSys.cy,
|
||
r: _insidePanelRadius
|
||
},
|
||
style: {
|
||
fill: '#fff',
|
||
shadowBlur: 25,
|
||
shadowOffsetX: 0,
|
||
shadowOffsetY: 0,
|
||
shadowColor: 'rgba(76,107,167,0.4)'
|
||
}
|
||
},
|
||
{
|
||
type: 'text',
|
||
extra: {
|
||
valOnRadian: valOnRadian,
|
||
transition: 'valOnRadian',
|
||
enterFrom: {valOnRadian: 0}
|
||
},
|
||
style: {
|
||
text: makeText(valOnRadian),
|
||
fontSize: 50,
|
||
fontWeight: 700,
|
||
x: params.coordSys.cx,
|
||
y: params.coordSys.cy,
|
||
fill: 'rgb(0,10,190)',
|
||
align: 'center',
|
||
verticalAlign: 'middle',
|
||
enterFrom: {opacity: 0}
|
||
},
|
||
during: function (apiDuring) {
|
||
apiDuring.setStyle(
|
||
'text',
|
||
makeText(apiDuring.getExtra('valOnRadian'))
|
||
);
|
||
}
|
||
}
|
||
]
|
||
};
|
||
}
|
||
function renderItem1(params, api) {
|
||
var valOnRadian = api.value(1);
|
||
var coords = api.coord([api.value(0), valOnRadian]);
|
||
var polarEndRadian = coords[3];
|
||
var imageStyle = {
|
||
image: _panelImageURL,
|
||
x: params.coordSys.cx - _outerRadius,
|
||
y: params.coordSys.cy - _outerRadius,
|
||
width: _outerRadius * 2,
|
||
height: _outerRadius * 2
|
||
};
|
||
return {
|
||
type: 'group',
|
||
children: [
|
||
{
|
||
type: 'image',
|
||
style: imageStyle,
|
||
clipPath: {
|
||
type: 'sector',
|
||
shape: {
|
||
cx: params.coordSys.cx,
|
||
cy: params.coordSys.cy,
|
||
r: _outerRadius,
|
||
r0: _innerRadius,
|
||
startAngle: 0,
|
||
endAngle: -polarEndRadian,
|
||
transition: 'endAngle',
|
||
enterFrom: {endAngle: 0}
|
||
}
|
||
}
|
||
},
|
||
{
|
||
type: 'image',
|
||
style: imageStyle,
|
||
clipPath: {
|
||
type: 'polygon',
|
||
shape: {
|
||
points: makePionterPoints(params, polarEndRadian)
|
||
},
|
||
extra: {
|
||
polarEndRadian: polarEndRadian,
|
||
transition: 'polarEndRadian',
|
||
enterFrom: {polarEndRadian: 0}
|
||
},
|
||
during: function (apiDuring) {
|
||
apiDuring.setShape(
|
||
'points',
|
||
makePionterPoints(params, apiDuring.getExtra('polarEndRadian'))
|
||
);
|
||
}
|
||
}
|
||
},
|
||
{
|
||
type: 'circle',
|
||
shape: {
|
||
cx: params.coordSys.cx,
|
||
cy: params.coordSys.cy,
|
||
r: _insidePanelRadius
|
||
},
|
||
style: {
|
||
fill: '#fff',
|
||
shadowBlur: 25,
|
||
shadowOffsetX: 0,
|
||
shadowOffsetY: 0,
|
||
shadowColor: 'rgba(76,107,167,0.4)'
|
||
}
|
||
},
|
||
{
|
||
type: 'text',
|
||
extra: {
|
||
valOnRadian: valOnRadian,
|
||
transition: 'valOnRadian',
|
||
enterFrom: {valOnRadian: 0}
|
||
},
|
||
style: {
|
||
text: makeText1(valOnRadian),
|
||
fontSize: 50,
|
||
fontWeight: 700,
|
||
x: params.coordSys.cx,
|
||
y: params.coordSys.cy,
|
||
fill: 'rgb(0,10,190)',
|
||
align: 'center',
|
||
verticalAlign: 'middle',
|
||
enterFrom: {opacity: 0}
|
||
},
|
||
during: function (apiDuring) {
|
||
apiDuring.setStyle(
|
||
'text',
|
||
makeText1(apiDuring.getExtra('valOnRadian'))
|
||
);
|
||
}
|
||
}
|
||
]
|
||
};
|
||
}
|
||
function convertToPolarPoint(renderItemParams, radius, radian) {
|
||
return [
|
||
Math.cos(radian) * radius + renderItemParams.coordSys.cx,
|
||
-Math.sin(radian) * radius + renderItemParams.coordSys.cy
|
||
];
|
||
}
|
||
|
||
function makePionterPoints(renderItemParams, polarEndRadian) {
|
||
return [
|
||
convertToPolarPoint(renderItemParams, _outerRadius, polarEndRadian),
|
||
convertToPolarPoint(
|
||
renderItemParams,
|
||
_outerRadius,
|
||
polarEndRadian + Math.PI * 0.03
|
||
),
|
||
convertToPolarPoint(renderItemParams, _pointerInnerRadius, polarEndRadian)
|
||
];
|
||
}
|
||
|
||
function makeText(valOnRadian) {
|
||
// Validate additive animation calc.
|
||
// if (valOnRadian < -10) {
|
||
// alert('illegal during val: ' + valOnRadian);
|
||
// }
|
||
//return '泌乳3号\n20KG';
|
||
return cowshedName+'\n'+_feedNum+'KG';
|
||
}
|
||
|
||
function makeText1(valOnRadian) {
|
||
// Validate additive animation calc.
|
||
// if (valOnRadian < -10) {
|
||
// alert('illegal during val: ' + valOnRadian);
|
||
// }
|
||
// return '车内总重\n20KG';
|
||
return '车内总重\n'+nowWeight+'KG';
|
||
}
|
||
|
||
var nextSource = [[1, Math.round(Math.random() * _valOnRadianMax)]];
|
||
|
||
function renderUnload() {
|
||
option = {
|
||
animation: false,
|
||
dataset: {
|
||
source: [[1, _feedNum]]
|
||
},
|
||
tooltip: {},
|
||
angleAxis: {
|
||
type: 'value',
|
||
startAngle: 0,
|
||
show: false,
|
||
min: 0,
|
||
max: nowWeight
|
||
},
|
||
radiusAxis: {
|
||
type: 'value',
|
||
show: false
|
||
},
|
||
polar: {},
|
||
series: [{
|
||
type: 'custom',
|
||
coordinateSystem: 'polar',
|
||
renderItem: renderItem
|
||
}]
|
||
};
|
||
|
||
option && myChart.setOption(option);
|
||
}
|
||
|
||
function renderLoad(){
|
||
option1 = {
|
||
animation: false,
|
||
dataset: {
|
||
source: [[1, nowWeight]]
|
||
},
|
||
tooltip: {},
|
||
angleAxis: {
|
||
type: 'value',
|
||
startAngle: 0,
|
||
show: false,
|
||
min: 0,
|
||
max: nowWeight
|
||
},
|
||
radiusAxis: {
|
||
type: 'value',
|
||
show: false
|
||
},
|
||
polar: {},
|
||
series: [{
|
||
type: 'custom',
|
||
coordinateSystem: 'polar',
|
||
renderItem: renderItem1
|
||
}]
|
||
};
|
||
|
||
option1 && myChart1.setOption(option1);
|
||
}
|
||
|
||
</script>
|
||
</body>
|
||
|
||
</html>
|