650完成,670完成部分
This commit is contained in:
@ -433,6 +433,7 @@ class BleHelper {
|
||||
|
||||
uni.onBLECharacteristicValueChange((receive) => {
|
||||
//订阅消息
|
||||
console.log("收到订阅消息",receive);
|
||||
let f=this.data.LinkedList.find((v) => {
|
||||
return v.deviceId == receive.deviceId;
|
||||
})
|
||||
@ -505,10 +506,8 @@ class BleHelper {
|
||||
this.cfg.receivDataCallback.forEach((rec) => {
|
||||
|
||||
if (rec.callback) {
|
||||
|
||||
}
|
||||
rec.callback(recData, f, path);
|
||||
|
||||
rec.callback(recData, f, path);
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
@ -1142,7 +1141,7 @@ class BleHelper {
|
||||
})); //没有找到指定设备
|
||||
return;
|
||||
}
|
||||
console.log("device=", device);
|
||||
// console.log("device=", device);
|
||||
uni.writeBLECharacteristicValue({
|
||||
deviceId: device.deviceId,
|
||||
serviceId: device.writeServiceId,
|
||||
|
@ -55,7 +55,10 @@ class BleReceive {
|
||||
console.log("该设备是650");
|
||||
return this.Receive_650(receive,f,path);
|
||||
}
|
||||
|
||||
if(f.detailPageUrl=='/pages/670/HBY670'){
|
||||
console.log("该设备是670");
|
||||
return this.Receive_670(receive,f,path);
|
||||
}
|
||||
|
||||
}
|
||||
console.log("已收到该消息,但无法处理",f);
|
||||
@ -63,7 +66,7 @@ class BleReceive {
|
||||
}
|
||||
|
||||
Receive_650(receive,f,path) {
|
||||
console.log("通用程序正在处理650的数据");
|
||||
console.log("通用程序正在处理650的数据",receive);
|
||||
|
||||
var parseData = () => {
|
||||
let bytes = receive.bytes;
|
||||
@ -74,6 +77,7 @@ class BleReceive {
|
||||
let staticLevelByte = bytes[1];
|
||||
let staticLevelText = '未知';
|
||||
let modeCurr = "";
|
||||
|
||||
switch (staticLevelByte) {
|
||||
case 0x65:
|
||||
staticLevelText = '高档';
|
||||
@ -190,6 +194,46 @@ class BleReceive {
|
||||
this.setBleFormData(formData,f);
|
||||
return formData;
|
||||
}
|
||||
else{
|
||||
let receiveData={a:1};
|
||||
try {
|
||||
let json=JSON.parse(str);
|
||||
|
||||
if("staBlue_picture" in json){
|
||||
//重发图片
|
||||
console.log("收到重新发送图片的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue_text" in json){
|
||||
//重发文本
|
||||
console.log("收到重新发送文本的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue_vidio" in json){
|
||||
//重发视频
|
||||
console.log("收到重新发送视频的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue" in json){
|
||||
if(json.staBlue=="finish"){
|
||||
console.log("收到设备回复,全部传输完成");
|
||||
receiveData=json;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
receiveData={};
|
||||
console.log("无法解析该文本");
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (error) {
|
||||
receiveData={};
|
||||
console.log("文本解析失败")
|
||||
}
|
||||
return receiveData;
|
||||
}
|
||||
return null;
|
||||
} catch (ex) {
|
||||
return null;
|
||||
@ -199,11 +243,149 @@ class BleReceive {
|
||||
}
|
||||
|
||||
let data=parseData();
|
||||
|
||||
console.log("data=",data);
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
Receive_670(receive,f,path){
|
||||
|
||||
var todo = (bytes) =>{
|
||||
|
||||
let receiveData = {};
|
||||
if (bytes[0] == 0x55) {
|
||||
try {
|
||||
// 跳过帧头(第一个字节),从第二个字节开始解析
|
||||
let staticLevelByte = bytes[1];
|
||||
let staticLevelText = '未知';
|
||||
switch (staticLevelByte) {
|
||||
case 0x65:
|
||||
staticLevelText = '高档';
|
||||
break
|
||||
case 0x66:
|
||||
staticLevelText = '中档';
|
||||
break
|
||||
case 0x67:
|
||||
staticLevelText = '低档';
|
||||
break
|
||||
case 0x68:
|
||||
staticLevelText = '关闭';
|
||||
break
|
||||
}
|
||||
|
||||
// 解析照明档位
|
||||
let lightingLevelByte = bytes[2];
|
||||
let lightingLevelText = lightingLevelByte === 0x6d ? '强光': lightingLevelByte === 0x6e ? '弱光': '关闭';
|
||||
|
||||
// 解析剩余照明时间(第三和第四字节,小端序)
|
||||
let lightingTime = (bytes[3] << 8) | bytes[4];
|
||||
|
||||
// 解析剩余电量 // 电量百分比范围检查
|
||||
let batteryLevelByte = bytes[5];
|
||||
|
||||
let batteryLevel = Math.max(0, Math.min(100, batteryLevelByte));
|
||||
|
||||
let warn = bytes[6];
|
||||
if (warn == 0x00) {
|
||||
warn = '无预警';
|
||||
} else if (warn == 0x01) {
|
||||
warn = '弱预警';
|
||||
} else if (warn == 0x02) {
|
||||
warn = '中预警';
|
||||
} else if (warn == 0x03) {
|
||||
warn = '强预警';
|
||||
} else if (warn == 0x04) {
|
||||
warn = '非常强预警';
|
||||
}
|
||||
|
||||
let staticWarn = bytes[7] == 0x01 ? '静止报警': '无静止报警';
|
||||
let fourGStrenth = bytes[8]; //4g信号强度
|
||||
let sosTxt = bytes[9] == 0x00 ? '关闭' : bytes[9] == 0x01 ? '爆闪模式' : '红蓝模式';
|
||||
|
||||
receiveData.staticLevel = staticLevelText;
|
||||
receiveData.lightingLevel = lightingLevelText;
|
||||
receiveData.lightingTime = lightingTime ;
|
||||
receiveData.batteryLevel = batteryLevel;
|
||||
receiveData.warnLevel = warn;
|
||||
receiveData.staticWarn = staticWarn;
|
||||
receiveData.fourGStrenth = fourGStrenth;
|
||||
receiveData.SOS=sosTxt;
|
||||
} catch(error) {
|
||||
console.log('数据解析错误:', error);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
let uint8Array = new Uint8Array(receive.value);
|
||||
let str = '';
|
||||
for (let i = 0; i < uint8Array.length; i++) {
|
||||
// 将每个字节转换为对应的字符
|
||||
str += String.fromCharCode(uint8Array[i]);
|
||||
}
|
||||
if (str.indexOf('mac address:') == 0) {
|
||||
receiveData.macAddress = str.split(':').slice(1).join(":");
|
||||
console.log('收到mac地址:', +this.receiveData.macAddress);
|
||||
} else if (str.indexOf('imei:') == 0) {
|
||||
receiveData.IMEI = str.split(':')[1];
|
||||
console.log('收到IEMI:', +this.receiveData.macAddress);
|
||||
|
||||
} else if (str.indexOf('longitude:') == 0) {
|
||||
receiveData.Lon = str.split(':')[1];
|
||||
console.log('收到经度:', +this.receiveData.macAddress);
|
||||
} else if (str.indexOf('latitude:') == 0) {
|
||||
receiveData.Lat = str.split(':')[1];
|
||||
console.log('收到纬度:', +this.receiveData.macAddress);
|
||||
} else {
|
||||
try {
|
||||
let json=JSON.parse(str);
|
||||
if("staBlue_picture" in json){
|
||||
//重发图片
|
||||
console.log("收到重新发送图片的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue_text" in json){
|
||||
//重发文本
|
||||
console.log("收到重新发送文本的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue_vidio" in json){
|
||||
//重发视频
|
||||
console.log("收到重新发送视频的命令");
|
||||
receiveData=json;
|
||||
}
|
||||
else if("staBlue" in json){
|
||||
if(json.staBlue=="finish"){
|
||||
console.log("收到设备回复,全部传输完成");
|
||||
receiveData=json;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
receiveData={};
|
||||
console.log("无法解析该文本");
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (error) {
|
||||
receiveData={};
|
||||
console.log("文本解析失败")
|
||||
}
|
||||
}
|
||||
} catch(ex) {
|
||||
receiveData={};
|
||||
console.log('将数据转文本失败', ex);
|
||||
}
|
||||
}
|
||||
|
||||
this.setBleFormData(receiveData,f);
|
||||
return receiveData;
|
||||
}
|
||||
|
||||
|
||||
let data=todo();
|
||||
|
||||
return data;
|
||||
}
|
||||
Receive_6155() {
|
||||
console.log("通用程序正在处理6155的数据");
|
||||
}
|
||||
|
218
utils/Common.js
Normal file
218
utils/Common.js
Normal file
@ -0,0 +1,218 @@
|
||||
var cfg={
|
||||
Version:'Uat',//Dev:开发环境,Uat:Uat环境,Relese正式环境
|
||||
DevApi:'http://192.168.110.54:8000/',//开发环境
|
||||
UatApi:'http://114.55.111.217/',//UAT环境
|
||||
ReleseApi:'http://relese:3169/api/'//Relese环境
|
||||
}
|
||||
export default {
|
||||
baseURL : cfg.Version=='Dev'?cfg.DevApi:(cfg.Version=='Uat'?cfg.UatApi:cfg.ReleseApi),
|
||||
guid:function generateUUID() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
const r = Math.random() * 16 | 0;
|
||||
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
},
|
||||
alert: function(title, content, callback) {
|
||||
if(!title){
|
||||
title='提示'
|
||||
}
|
||||
if(!content){
|
||||
content=title;
|
||||
}
|
||||
|
||||
uni.showModal({
|
||||
title: title,
|
||||
content: content,
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
console.log('用户点击确定');
|
||||
} else if (res.cancel) {
|
||||
console.log('用户点击取消');
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(res);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
showLoading:function(title,mask){
|
||||
uni.showLoading({
|
||||
title:title,
|
||||
mask:mask,
|
||||
})
|
||||
},
|
||||
hideLoading:function(){
|
||||
uni.hideLoading();
|
||||
},
|
||||
showToast:function(title,mask,duration,callback){
|
||||
if(!duration){
|
||||
duration=1500;
|
||||
}
|
||||
if(mask==undefined){
|
||||
mask=false;
|
||||
}
|
||||
uni.showToast({
|
||||
title:title,
|
||||
mask:mask,
|
||||
duration:duration,
|
||||
callback:callback,
|
||||
icon: 'none'
|
||||
})
|
||||
},
|
||||
GetData:function(url,data,method,contentType,succ,err,complete){
|
||||
var these=this;
|
||||
if(!url){
|
||||
console.error("url为空");
|
||||
return;
|
||||
}
|
||||
|
||||
if(url.toLowerCase().indexOf('http://')==-1 || url.toLowerCase().indexOf('https://')==-1){
|
||||
if(url.indexOf('/')==0){
|
||||
url=url.substr(1,url.length-1);
|
||||
}
|
||||
let ServerPath=these.DevApi;
|
||||
if(these.Version==='Dev'){
|
||||
ServerPath=these.DevApi;
|
||||
}
|
||||
else if(these.Version==='Uat'){
|
||||
ServerPath=these.UatApi;
|
||||
}
|
||||
else if(these.Version==='Relese'){
|
||||
ServerPath=these.ReleseApi;
|
||||
}else{
|
||||
these.DevApi
|
||||
}
|
||||
url=ServerPath+url;
|
||||
}
|
||||
|
||||
var these=this;
|
||||
if(!method){
|
||||
method='POST';
|
||||
}
|
||||
method=method.toUpperCase();
|
||||
|
||||
if(!contentType){
|
||||
contentType='application/json;charset=UTF-8';
|
||||
}
|
||||
|
||||
these.checkLAN(
|
||||
|
||||
function(){
|
||||
these.showLoading('请稍候..',true);
|
||||
setTimeout(function(){
|
||||
uni.request({
|
||||
url:url,
|
||||
data:data,
|
||||
header:{
|
||||
"Content-Type":contentType
|
||||
},
|
||||
method:method,
|
||||
timeout:60000,
|
||||
dataType:'json',
|
||||
success:function(json){
|
||||
|
||||
if(succ){
|
||||
succ(json);
|
||||
}
|
||||
},
|
||||
fail:function(ex){
|
||||
|
||||
if(err){
|
||||
err(ex);
|
||||
}
|
||||
},
|
||||
complete:function(){
|
||||
|
||||
if(complete){
|
||||
complete();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
},0);
|
||||
|
||||
}
|
||||
|
||||
,function(){
|
||||
these.showToast('无网络连接');
|
||||
});
|
||||
},
|
||||
checkLAN:function(succ,error){
|
||||
uni.getNetworkType({
|
||||
success: (res) => {
|
||||
const networkType = res.networkType;
|
||||
|
||||
|
||||
// 判断网络是否连接
|
||||
if (networkType === 'none') {
|
||||
console.error('无网络连接')
|
||||
if(error){
|
||||
error();
|
||||
}
|
||||
}else{
|
||||
if(succ){
|
||||
succ();
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('获取网络状态失败:', err);
|
||||
if(error){
|
||||
error();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
DateFormat: function(date, format) {
|
||||
if(!date){
|
||||
date=new Date();
|
||||
}
|
||||
if(!format){
|
||||
format='yyyy-MM-dd HH:mm:ss';
|
||||
}
|
||||
// 处理参数默认值
|
||||
if (typeof date === 'string' || typeof date === 'number') {
|
||||
date = new Date(date);
|
||||
}
|
||||
date = date instanceof Date ? date : new Date();
|
||||
format = format || 'yyyy-MM-dd';
|
||||
|
||||
// 检查日期是否有效
|
||||
if (isNaN(date.getTime())) {
|
||||
return 'Invalid Date';
|
||||
}
|
||||
|
||||
// 定义格式化映射
|
||||
const formatMap = {
|
||||
'yyyy': date.getFullYear(),
|
||||
'MM': String(date.getMonth() + 1).padStart(2, '0'),
|
||||
'dd': String(date.getDate()).padStart(2, '0'),
|
||||
'HH': String(date.getHours()).padStart(2, '0'),
|
||||
'mm': String(date.getMinutes()).padStart(2, '0'),
|
||||
'ss': String(date.getSeconds()).padStart(2, '0'),
|
||||
'SSS': String(date.getMilliseconds()).padStart(3, '0'),
|
||||
'M': date.getMonth() + 1,
|
||||
'd': date.getDate(),
|
||||
'H': date.getHours(),
|
||||
'm': date.getMinutes(),
|
||||
's': date.getSeconds(),
|
||||
'S': date.getMilliseconds()
|
||||
};
|
||||
|
||||
// 替换格式字符串中的占位符
|
||||
return format.replace(/(yyyy|MM|dd|HH|mm|ss|SSS|M|d|H|m|s|S)/g, (match) => {
|
||||
return formatMap[match];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
// 兼容性补丁:为 Paho MQTT 提供 uni-app 环境下的 WebSocket 实现
|
||||
(function(root) {
|
||||
// 如果未能找到全局对象,则无法应用补丁。
|
||||
console.log("root=",root);
|
||||
if (!root) {
|
||||
console.error("MQTT Polyfill: 未能找到全局对象 (global/window/self 均未定义)。");
|
||||
return;
|
||||
@ -165,13 +166,13 @@ class MqttClient {
|
||||
|
||||
this.client.onMessageArrived = (message) => {
|
||||
const topic = message.destinationName;
|
||||
const payload = message.payloadString;
|
||||
const payload = message.payloadString;
|
||||
console.log(`收到消息, 主题: ${topic}, 内容: ${payload}`);
|
||||
const potentialJsons = payload.replace(/}\s*{/g, '}|{').split('|');
|
||||
potentialJsons.forEach(jsonString => {
|
||||
if (jsonString.trim() === '') return;
|
||||
if (this.messageCallbacks.has(topic)) {
|
||||
this.messageCallbacks.get(topic)(jsonString);
|
||||
this.messageCallbacks.get(topic)(jsonString,message);
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -281,8 +282,10 @@ class MqttClient {
|
||||
mqttMessage.qos = 1;
|
||||
this.client.send(mqttMessage);
|
||||
console.log(`成功发布消息到主题 ${topic}: ${message}`);
|
||||
return true;
|
||||
} else {
|
||||
console.error('MQTT未连接,无法发布');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
153
utils/update.js
Normal file
153
utils/update.js
Normal file
@ -0,0 +1,153 @@
|
||||
/**
|
||||
* 检查并执行wgt热更新
|
||||
* @param {String} updateUrl - 检查更新的接口地址
|
||||
*/
|
||||
function checkAndUpdateWgt(updateUrl) {
|
||||
if(!plus){
|
||||
return;
|
||||
}
|
||||
// 显示加载提示
|
||||
|
||||
|
||||
// 1. 获取当前应用版本信息
|
||||
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
|
||||
const currentVersion = widgetInfo.version;
|
||||
console.log("当前版本:" + currentVersion);
|
||||
// 2. 调用后端接口检查是否有更新
|
||||
uni.request({
|
||||
url: updateUrl,
|
||||
method: 'GET',
|
||||
data: {
|
||||
currentVersion: currentVersion,
|
||||
platform: uni.getSystemInfoSync().platform
|
||||
},
|
||||
success: (res) => {
|
||||
uni.hideLoading();
|
||||
console.log("res=", res)
|
||||
if (res.statusCode === 200) {
|
||||
|
||||
const updateInfo = res.data.data;
|
||||
if (!updateInfo.hasUpdate) {
|
||||
return;
|
||||
}
|
||||
// 3. 显示更新提示
|
||||
uni.showModal({
|
||||
title: '检测到更新',
|
||||
content: updateInfo.description || '有新版本可用,是否立即更新?',
|
||||
confirmText: '立即更新',
|
||||
cancelText: '稍后更新',
|
||||
success: (modalRes) => {
|
||||
if (modalRes.confirm) {
|
||||
downloadAndInstallWgt(updateInfo.downloadUrl);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '当前已是最新版本',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: '检查更新失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
console.error('检查更新失败:', err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载并安装wgt更新包
|
||||
* @param {String} wgtUrl - wgt包下载地址
|
||||
*/
|
||||
function downloadAndInstallWgt(wgtUrl) {
|
||||
// 显示下载进度
|
||||
var wating=plus.nativeUI.showWaiting({
|
||||
title:"下载中0%"
|
||||
});
|
||||
// uni.showLoading({
|
||||
// title: '更新下载中...',
|
||||
// mask: true
|
||||
// });
|
||||
|
||||
// 1. 下载wgt包
|
||||
const downloadTask = uni.downloadFile({
|
||||
url: wgtUrl,
|
||||
success: (downloadRes) => {
|
||||
wating.setTitle("下载完成,正在安装");
|
||||
if (downloadRes.statusCode === 200) {
|
||||
// 2. 安装wgt包
|
||||
plus.runtime.install(downloadRes.tempFilePath, {
|
||||
force: true // 是否强制安装
|
||||
}, () => {
|
||||
uni.removeSavedFile({
|
||||
filePath: downloadRes.tempFilePath,
|
||||
success() {
|
||||
console.log("临时文件已删除");
|
||||
},
|
||||
fail() {
|
||||
console.log("无法删除临时文件");
|
||||
},
|
||||
complete() {
|
||||
wating.close();
|
||||
uni.showModal({
|
||||
title: '更新完成',
|
||||
content: '应用已更新,是否重启应用?',
|
||||
showCancel: false,
|
||||
success: () => {
|
||||
// 3. 重启应用
|
||||
plus.runtime.restart();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}, (error) => {
|
||||
|
||||
wating.close();
|
||||
uni.showToast({
|
||||
title: '安装失败: ' + error.message,
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
});
|
||||
console.error('wgt安装失败:', error);
|
||||
});
|
||||
|
||||
} else {
|
||||
wating.close();
|
||||
uni.showToast({
|
||||
title: '下载失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: '下载失败: ' + err.errMsg,
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
console.error('wgt下载失败:', err);
|
||||
}
|
||||
});
|
||||
|
||||
// 监听下载进度
|
||||
downloadTask.onProgressUpdate((progress) => {
|
||||
console.log('下载进度: ' + progress.progress + '%');
|
||||
wating.setTitle("下载中"+ progress.progress + '%');
|
||||
// 可以在这里更新自定义进度条
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
checkAndUpdateWgt
|
||||
};
|
Reference in New Issue
Block a user