uniapp 小程序低功耗蓝牙配网 ble配网 物联网

 1.获取蓝牙列表  bleList.vue

<template>
  <view>
    <button @touchstart="startSearch">获取蓝牙列表</button>
    <scroll-view :scroll-top="scrollTop" scroll-y class="content-pop">
      <view
        class="bluetoothItem"
        v-for="(item, index) in bluetoohList"
        :key="index"
        @click="openControl(item)"
      >
        <view class="textItem">蓝牙:{{ item.name }}</view>
        <view>{{ item.deviceId }}</view>
      </view>
    </scroll-view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      bluetoohList: [],
    };
  },
  onLoad: function (options) {
    this.startSearch();
  },
  methods: {
    // 连接蓝牙
    startSearch() {
      let that = this;
      that.$ble.openBluetoothAdapter(
        (res) => {
          that.$ble.getBluetoothAdapterState((res) => {
            if (res.available) {
              if (res.discovering) {
                that.$ble.stopBluetoothDevicesDiscovery();
              } else {
                that.getBluetoothDevices();
              }
              that.checkPemission();
            } else {
              that.$tip.toast("本机蓝牙不可用");
            }
          });
        },
        (err) => {
          that.openSetting();
        }
      );
    },
    openSetting() {
      let params = {
        title: "检测到您没打开蓝牙权限,是否去设置打开?",
        showCancel: true,
      };
      this.$tip.showModal(params, (res) => {
        if (res.confirm) {
          this.$ble.openSetting();
        }
      });
    },
    checkPemission() {
      //android 6.0以上需授权地理位置权限
      var that = this;
      const sys = uni.getSystemInfoSync();
      if (sys.platform == "ios") {
        that.getBluetoothDevices();
      } else if (sys.platform == "android") {
        console.log(
          app
            .getSystem()
            .substring(
              app.getSystem().length - (app.getSystem().length - 8),
              app.getSystem().length - (app.getSystem().length - 8) + 1
            )
        );
        if (
          app.globalData
            .getSystem()
            .substring(
              app.globalData.getSystem().length -
                (app.globalData.getSystem().length - 8),
              app.globalData.getSystem().length -
                (app.globalData.getSystem().length - 8) +
                1
            ) > 5
        ) {
          uni.getSetting({
            success: (res) => {
              console.log(res);
              if (!res.authSetting["scope.userLocation"]) {
                uni.authorize({
                  scope: "scope.userLocation",
                  complete: (res) => {
                    that.getBluetoothDevices();
                  },
                });
              } else {
                that.getBluetoothDevices();
              }
            },
          });
        }
      }
    },
    //获取蓝牙设备信息
    getBluetoothDevices() {
      that.$tip.loading("蓝牙搜索中");
      this.$ble.getBluetoothDevices((res) => {
        this.bluetoohList = res;
        this.$tip.loaded();
      });
    },
    // 连接蓝牙 跳转到连接页面
    openControl(item) {
      let params = {
        list: this.bluetoohList,
        info: item,
      };
      this.$tip.redirectTo("/pagesA/bleDevice/bleWifiSuccess", params);
    },
  },
};
</script>

<style scoped>
.content-pop {
  width: 100vw;
  max-height: 55vh;
  padding: 0 30rpx;
}
.bluetoothItem {
  padding: 20rpx 0;
  font-weight: 400;
  font-size: 28rpx;
  border-bottom: 1rpx solid #f4f4f4;
  text-align: left;
}
.textItem {
  display: block;
  margin-bottom: 10rpx;
}
</style>

2.选择蓝牙进行连接  blefi.vue

<script>
export default {
  data() {
    return {
      bluInfo: {},
      services: [],
      bleServiceId: "",
      serviceId: 0,
      writeCharacter: false,
      readCharacter: false,
      notifyCharacter: false,
      BLEInformation: {
        serveiceId: "",
        config_write_char_id: "",
        cmd_write_char_id: "",
        config_read_char_id: "",
        cmd_read_char_id: "",
      },
    };
  },
  onLoad(option) {
    // 接收页面传递的数据
    this.bluInfo = JSON.parse(decodeURIComponent(option.info));
    this.bluetooh(this.bluInfo.info.deviceId);
  },
  methods: {
    bluetooh(deviceId) {
      var that = this;
      that.$ble.stopBluetoothDevicesDiscovery();
      that.$ble.createBLEConnection(
        deviceId,
        (res) => {
          that.getSeviceId(deviceId);
        },
        (err) => {
          console.log(err, "11111111");
          that.bluetoothFail();
        }
      );
    },
    // 连接成功后保存连接状态
    getSeviceId(deviceId) {
      var that = this;
      that.$ble.getBLEDeviceServices(
        deviceId,
        (res) => {
          that.services = res.services;
          that.bleServiceId = res.services[0].uuid;
          this.BLEInformation.serveiceId = res.services[0].uuid;
          that.getCharacteristics(deviceId);
        },
        (err) => {
          console.log(err, "2222222");
          that.bluetoothFail();
        }
      );
    },
    getCharacteristics(deviceId) {
      var that = this;
      var list = that.services;
      var num = that.serviceId;
      var write = that.writeCharacter;
      var read = that.readCharacter;
      var notify = that.notifyCharacter;
      that.$ble.getBLEDeviceCharacteristics(
        deviceId,
        that.bleServiceId,
        (res) => {
          for (var i = 0; i < res.characteristics.length; ++i) {
            var properties = res.characteristics[i].properties;
            if (!notify) {
              if (properties.notify) {
                notify = true;
              }
            }
            if (!write) {
              if (properties.write) {
                this.BLEInformation.config_write_char_id =
                  res.characteristics[2].uuid;
                this.BLEInformation.cmd_write_char_id =
                  res.characteristics[0].uuid;
                write = true;
              }
            }
            if (!read) {
              if (properties.read) {
                this.BLEInformation.config_read_char_id =
                  res.characteristics[3].uuid;
                this.BLEInformation.cmd_read_char_id =
                  res.characteristics[1].uuid;
                read = true;
              }
            }
          }
          if (!write || !notify || !read) {
            num++;
            (that.writeCharacter = write),
              (that.readCharacter = read),
              (that.notifyCharacter = notify),
              (that.serviceId = num);
            if (num == list.length) {
              // console.log("找不到该读写的特征值")
              that.bluetoothFail();
            } else {
              that.getCharacteristics(deviceId);
            }
          } else {
            that.bluetoothSuccess(res);
          }
        },
        (err) => {
          console.log(err, "4444444");
          that.bluetoothFail();
        }
      );
    },
    // 蓝牙连接打印机
    bluetoothSuccess(res) {
      uni.setStorageSync("blefiInfo", this.BLEInformation);
      let params = {
        title: "连接成功",
        confirmText: "继续",
        showCancel: false,
      };
      this.$tip.showModal(params, (res) => {
        if (res.confirm) {
          // 蓝牙连接成功
          this.$tip.redirectTo("/pages/ble/bleWifi");
        }
      });
    },
    bluetoothFail() {
      // 蓝牙连接失败
      this.$tip.redirectTo("/pages/ble/bleFail");
    },
  },
};
</script>

<style scoped>
.zai-box {
  padding: 0;
  margin: 0;
  height: 100%;
  background-color: #fff;
}

.container {
  padding: 30rpx;
  margin: 0;
  font-size: 28rpx;
  color: #20212b;
  background-color: #fff;
  text-align: left;
  font-weight: 400;
}

image {
  width: 362rpx;
  height: 362rpx;
  margin-top: 30rpx;
}

.textTitle {
  display: block;
  font-size: 36rpx;
  font-weight: bold;
  color: #20212b;
  display: block;
  margin-bottom: 30rpx;
}

.textItem {
  display: block;
  font-size: 24rpx;
  font-weight: 400;
  color: #999999;
  line-height: 36rpx;
}
</style>

3. 低功耗蓝牙连接WiFi  blefiWifi.vue

<template>
    <view>
      <text>{{ SSID }}</text>
      <input type="text" placeholder="请输入密码" v-model="password" />
      <button @click="settiing">连接</button>
    </view>
  </template>
  
  <script>
  import APToast from "@/util/APToast.js";
  export default {
    data() {
      return {
        SSID: "your SSID",
        password: "",
        connected: true,
        wifiCountDown: 0,
        wifiCountInterval: null, // 定时器
        blefiInfo: {},
      };
    },
    // 二级页面清除
    onUnload() {
      this.$ble.offBLEConnectionStateChange();
      this.clearIntervalWifi();
    },
    onLoad(options) {
      this.blefiInfo = uni.getStorageSync("blefiInfo");
      let sys = uni.getStorageSync("phoneInfo");
      if (sys.platform == "android") {
        // this.$ble.onBLEMTUChange((res) => {
        //   console.log(res, "androidMTU");
        // });
  
        // this.$ble.getBLEMTU(this.blefiInfo.deviceId, (res) => {
        //   console.log(res, "mtu");
        // });
  
        const mtu = 512;
        this.$ble.setBLEMTU(
          this.blefiInfo.deviceId,
          mtu,
          (res) => {
            console.log(res, "512");
          },
          (err) => {
            console.log(err, "000");
          }
        );
      }
  
      this.$ble.getBLEDeviceServices(this.blefiInfo.deviceId, (res) => {
        this.$ble.getBLEDeviceCharacteristics(
          this.blefiInfo.deviceId,
          this.blefiInfo.serveiceId,
          (res) => {
            this.$ble.notifyBLECharacteristicValueChange(
              true,
              this.blefiInfo.deviceId,
              this.blefiInfo.serveiceId,
              this.blefiInfo.readCharId,
              (res) => {
                console.log("启用notify成功");
              }
            );
          }
        );
      });
  
      this.$ble.onBLEConnectionStateChange((res) => {
        this.connected = res.connected;
        if (!res.connected) {
            this.$tip.loaded();
          // 蓝牙连接失败,跳转到失败页面
          this.$tip.redirectTo("/pages/ble/bleFail");
        }
      });
  
      // 接收配网打印机回传的数据
      this.$ble.onBLECharacteristicValueChange((res) => {
        if (!res || res.value.byteLength == 0) return;
        this.clearIntervalWifi();
        this.$tip.loaded();
        let num = new Int32Array(res.value)[0];
        console.log(num, "NUM");
        let tip = APToast.find((item) => item.id == num);
        if (num == 0) {
          // 连接wifi成功
          this.$tip.redirectTo("/pages/ble/WifiSuccess");
        } else {
          // 连接WiFi失败
          this.$tip.redirectTo("/pages/ble/WifiFile");
        }
      });
    },
  
    methods: {
      settiing() {
        this.startSMSTimer("60");
        this.$tip.loading("连接中");
        if (this.connected) {
          this.sendWifi();
        } else {
            this.$tip.loaded();
          // 蓝牙连接失败,跳转到失败页面
          this.$tip.redirectTo("/pages/ble/bleFail");
        }
      },
      // 转UTF-8
      sendWifi() {
        let msg = {
          event: "network",
          data: { ssid: this.SSID, password: this.password, authmode: 4 },
        };
        let buffer = this.stringToUint8Array(JSON.stringify(msg));
        this.bleSendWifi(buffer);
      },
      // json字符串数据转Uint8Array
      stringToUint8Array(str) {
        // 方法一
        // var arr = [];
        // for (var i = 0, j = str.length; i < j; ++i) {
        //   arr.push(str.charCodeAt(i));
        // }
        // var tmpUint8Array = new Uint8Array(arr);
        // return tmpUint8Array.buffer;
  
        // 方法二
        let buffer = new ArrayBuffer(str.length);
        let dataView = new DataView(buffer);
        for (var i = 0; i < str.length; i++) {
          dataView.setUint8(i, str.charCodeAt(i));
        }
        return buffer;
      },
      bleSendWifi(payload) {
        if (this.connected) {
          this.$ble.writeBLECharacteristicValueOnce(
            this.blefiInfo.deviceId,
            this.blefiInfo.serveiceId,
            this.blefiInfo.writecharId,
            payload
          );
          if (this.blefiInfo.readCharId) {
            this.$ble.readBLECharacteristicValue(
              this.blefiInfo.deviceId,
              this.blefiInfo.serveiceId,
              this.blefiInfo.readCharId
            );
          }
        }
      },
      startSMSTimer(val) {
        this.wifiCountDown = val;
        this.wifiCountInterval = setInterval(() => {
          this.wifiCountDown--;
          // console.log(this.wifiCountDown);
          if (this.wifiCountDown <= 0) {
            clearInterval(this.wifiCountInterval);
            this.wifiCountInterval = null;
            this.$tip.loaded();
            // 连接WiFi失败
            this.$tip.redirectTo("/pages/ble/WifiFile");
          }
        }, 1000);
      },
      clearIntervalWifi() {
        this.wifiCountDown = 0;
        if (this.wifiCountInterval) {
          clearInterval(this.wifiCountInterval);
          this.wifiCountInterval = null;
        }
      },
    },
  };
  </script>
  

4. 手机连接蓝牙失败、蓝牙连接WiFi成功/失败(关闭蓝牙连接)

<script>
export default {
  onLoad() {
      // 使用完成后在合适的时机断开连接和关闭蓝牙适配器
      this.$ble.closeBLEConnection(this.deviceId);
      this.$ble.closeBluetoothAdapter();
  },
};
</script>

5.ble.js

let data = {
  devices: [],
  log: [],
  connected: true, //原本是false
  chs: [],
  deviceId: "",
  writeDeviceId: "",
  writeServiceId: "",
  writeCharacteristicId: "",
  packData: [], // 分包数据
  cmd: null, // 命令码
  statusCode: null, // 状态码
  datalength: null, // 数据长度
  checkSums: null, // 校验和
  req_key_id: "",
};

class ble {
  openBluetoothAdapter(success, failure) {
    uni.openBluetoothAdapter({
      success: (res) => {
        success(res);
      },
      fail: (err) => {
        failure(err);
      },
    });
  }

  getBluetoothAdapterState(success) {
    uni.getBluetoothAdapterState({
      success: (res) => {
        success(res);
      },
    });
  }

  //停止搜寻附近的蓝牙外围设备
  stopBluetoothDevicesDiscovery() {
    uni.stopBluetoothDevicesDiscovery();
  }

  //获取蓝牙设备信息
  getBluetoothDevices(success) {
    // 开始搜寻附近的蓝牙外围设备
    uni.startBluetoothDevicesDiscovery({
      success: (res) => {
        setTimeout(() => {
          // 获取搜索到的设备信息
          uni.getBluetoothDevices({
            success: (res) => {
              let bluetoohList = [];
              var num = 0;
              for (var i = 0; i < res.devices.length; ++i) {
                if (res.devices[i].name != "未知设备") {
                  bluetoohList[num] = res.devices[i];
                  num++;
                }
              }
              this.stopBluetoothDevicesDiscovery();
              success(bluetoohList);
            },
          });
        }, 5000);
        // that.onBluetoothDeviceFound();
      },
    });
  }

  openSetting() {
    uni.openSetting({
      //opensetting是调起设置页面的
      success: (res) => {
        if (res.authSetting == true) {
          //判断res.authsetting的值是true还是false
          uni.openBluetoothAdapter();
        }
      },
    });
  }

  //断开与低功耗蓝牙设备的连接
  closeBLEConnection(deviceId) {
    uni.closeBLEConnection({
      deviceId: deviceId,
    });
  }

  offBLEConnectionStateChange() {
    wx.offBLEConnectionStateChange();
  }

  //连接低功耗蓝牙设备
  createBLEConnection(deviceId, success, failure) {
    uni.createBLEConnection({
      deviceId: deviceId,
      success: (res) => {
        success(res);
      },
      fail: (err) => {
        failure(err);
      },
    });
  }

  //获取蓝牙设备所有服务
  getBLEDeviceServices(deviceId, success, failure) {
    wx.getBLEDeviceServices({
      deviceId: deviceId,
      success: (res) => {
        success(res);
      },
      fail(err) {
        failure(err);
      },
    });
  }

  //获取蓝牙设备某个服务中所有特征值
  getBLEDeviceCharacteristics(deviceId, serviceId, success, failure) {
    wx.getBLEDeviceCharacteristics({
      deviceId: deviceId,
      serviceId: serviceId,
      success: (res) => {
        success(res);
      },
      fail(err) {
        failure(err);
      },
    });
  }

  notifyBLECharacteristicValueChange(
    state,
    deviceId,
    serviceId,
    characteristicId,
    success
  ) {
    wx.notifyBLECharacteristicValueChange({
      state: state,
      deviceId: deviceId,
      serviceId: serviceId,
      characteristicId: characteristicId,
      success: function (res) {
        success(res);
      },
    });
  }

  onBLEConnectionStateChange(success) {
    wx.onBLEConnectionStateChange((res) => {
      success(res);
    });
  }

  // 接收配网打印机回传的数据
  onBLECharacteristicValueChange(success) {
    wx.onBLECharacteristicValueChange((res) => {
      success(res);
    });
  }

  //关闭蓝牙模块
  closeBluetoothAdapter() {
    wx.closeBluetoothAdapter();
  }

  // 不分包写入蓝牙
  writeBLECharacteristicValueOnce(
    deviceId,
    serviceId,
    characteristicId,
    value
  ) {
    wx.writeBLECharacteristicValue({
      deviceId: deviceId,
      serviceId: serviceId,
      characteristicId: characteristicId,
      value: value,
    });
  }

  readBLECharacteristicValue(deviceId, serviceId, characteristicId) {
    wx.readBLECharacteristicValue({
      deviceId: deviceId,
      serviceId: serviceId,
      characteristicId: characteristicId,
    });
  }

  getBLEMTU(deviceId, success) {
    wx.getBLEMTU({
      deviceId: deviceId,
      writeType: "write",
      success(res) {
        success(res.mtu);
      },
    });
  }

  onBLEMTUChange(success) {
    wx.onBLEMTUChange(function (res) {
      success(res.mtu);
    });
  }

  setBLEMTU(deviceId, mtu, success, failure) {
    wx.setBLEMTU({
      deviceId: deviceId,
      mtu: mtu,
      success: (res) => {
        success(res);
      },
      fail: (res) => {
        failure(res);
      },
    });
  }
}
const bleDevice = new ble();
export default bleDevice;

6.APToast.js

const message = [
    {
        id:0,
        type:"WIFI_REASON_SUCCESS",
        message:"打印机连接成功"
    },
    {
        id:2,
        type:"WIFI_REASON_AUTH_EXPIRE",
        message:"身份验证超时"
    },
    {
        id:3,
        type:"WIFI_REASON_AUTH_LEAVE",
        message:"连接中断"
    },
    {
        id:8,
        type:"WIFI_REASON_ASSOC_LEAVE",
        message:"连接中断"
    },
    {
        id:15,
        type:"WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT",
        message:"密码错误"
    },
    {
        id:201,
        type:"WIFI_REASON_NO_AP_FOUND",
        message:"未找到可用的网络"
    },
    {
        id:202,
        type:"WIFI_REASON_AUTH_FAIL",
        message:"密码错误或身份验证超时"
    },
    {
        id:203,
        type:"WIFI_REASON_ASSOC_FAIL",
        message:"设备无法与WiFi成功关联"
    },
    {
        id:204,
        type:"WIFI_REASON_HANDSHAKE_TIMEOUT",
        message:"密码错误"
    },
    {
        id:205,
        type:"WIFI_REASON_CONNECTION_FAIL",
        message:"连接失败"
    }, 
]

export default message;

7.tip.js

export default class Tips { 

  /**
   * 弹出提示框
   */
  static success(title, duration = 1000) {
    setTimeout(() => {
      uni.showToast({
        title: title,
        icon: "success",
        mask: true,
        duration: duration,
      });
    }, 300);
    if (duration > 0) {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve();
        }, duration);
      });
    }
  }

  /**
   * 弹出加载提示
   */
  static loading(title = "加载中") {
    if (Tips.isLoading) {
      return;
    }
    Tips.isLoading = true;
    uni.showLoading({
      title: title,
      mask: true,
    });
  }

  /**
   * 加载完毕
   */
  static loaded() {
    if (Tips.isLoading) {
      Tips.isLoading = false;
      uni.hideLoading();
    }
  }
 
  /**
   * 关闭当前页面,跳转到新页面
   */
  static redirectTo(urls, item) {
    uni.redirectTo({
      url: item
        ? urls + "?info=" + encodeURIComponent(JSON.stringify(item))
        : urls, //  JSON.parse(decodeURIComponent(option.info));
    });
  }

 /**
   * 弹出确认窗口
   */
  static showModal(val, success) {
    uni.showModal({
      title: val.title ? val.title : "",
      content: val.content ? val.content : "",
      showCancel: val.showCancel,
      confirmText: val.confirmText ? val.confirmText : "确定",
      cancelText: val.cancelText ? val.cancelText : "取消",
      cancelColor: "#999999", //取消按钮颜色
      confirmColor: "#00A0E9", //确定按钮颜色
      success: (res) => {
        success(res);
      },
    });
  }
}


/**
 * 静态变量,是否加载中
 */
Tips.isLoading = false;

8.main.js

import ble from "./common/util/ble.js";
import tip from "./common/util/tip.js";

// ble
Vue.prototype.$ble = ble;
// tip
Vue.prototype.$tip = tip;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/605085.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Java 11 到 Java 8 的兼容性转换

Java 11 到 Java 8 的兼容性转换 欲倚绿窗伴卿卿&#xff0c;颇悔今生误道行。有心持钵丛林去&#xff0c;又负美人一片情。 静坐修观法眼开&#xff0c;祈求三宝降灵台&#xff0c;观中诸圣何曾见&#xff1f;不请情人却自来。 入山投谒得道僧&#xff0c;求教上师说因明。争奈…

HFSS学习-day3-HFSS的工作界面

工作界面也称为用户界面&#xff0c;是HFSS软件使用者的工作环境:了解、熟悉这个工作环境是掌握HFSS软件使用的第一步 HFSS工作环境介绍 1.HFSS工作界面简单的组成说明2.工作界面中各个工作窗口功能主菜单工具栏项目管理窗口属性窗口信息管理窗口进程窗口三维模型窗口 3.HFSS主…

【qt】动态属性(下)

动态属性目录 一.最简单的属性二.访问类的所有属性三.运行时添加属性&#xff08;动态属性&#xff09;★四.总结 一.最简单的属性 想要对一个数据成员进行读和写我们一般都会使用set或者get这种类型的自定义的函数去间接访问&#xff0c;且使用非常的频繁。 因此咱们有一个最…

基于PSO粒子群优化的配电网可靠性指标matlab仿真

目录 1.程序功能描述 2.测试软件版本以及运行结果展示 3.核心程序 4.本算法原理 4.1 PSO算法应用于配电网优化的基本原理 5.完整程序 1.程序功能描述 基于PSO粒子群优化的配电网可靠性指标matlab仿真&#xff0c;指标包括saifi, saidi, caidi, aens四个。 2.测试软件版本…

【CTF Web】XCTF GFSJ0480 simple_js Writeup(JS分析+ASCII码)

simple_js 小宁发现了一个网页&#xff0c;但却一直输不对密码。(Flag格式为 Cyberpeace{xxxxxxxxx} ) 解法 查看网页源代码。 function dechiffre(pass_enc){var pass "70,65,85,88,32,80,65,83,83,87,79,82,68,32,72,65,72,65";var tab pass_enc.split(,);var …

VSCode-vue3.0-安装与配置-export default简单例子

文章目录 1.下载VSCode2.修改语言为中文3.辅助插件列表4.vue3模板文件简单例子5.总结 1.下载VSCode 从官网下载VSCode&#xff0c;并按下一步安装成功。 2.修改语言为中文 点击确认修改&#xff0c;如下图所示&#xff1a; 或者打开命令面板&#xff1a;输入Configure Displ…

93、动态规划-最长回文子串

思路 首先从暴力递归开始&#xff0c;回文首尾指针相向运动肯定想等。就是回文&#xff0c;代码如下&#xff1a; public String longestPalindrome(String s) {if (s null || s.length() 0) {return "";}return longestPalindromeHelper(s, 0, s.length() - 1);…

嵌入式开发八:STM32启动过程分析

本次给大家分析 STM32F4 的启动过程&#xff0c;这里的启动过程是指从 STM32 芯片上电复位执行的第一条指令开始&#xff0c;到执行用户编写的 main 函数这之间的过程。我们编写程序&#xff0c;基本都是用 C 语言编写&#xff0c;并且以 main 函数作为程序的入口。但是事实上&…

洛谷 P4148:简单题 ← KD-Tree模板题

【题目来源】https://www.luogu.com.cn/problem/P4148【题目描述】 你有一个 NN 的棋盘&#xff0c;每个格子内有一个整数&#xff0c;初始时的时候全部为 0&#xff0c;现在需要维护两种操作&#xff1a; ● 1 x y A → 1≤x,y≤N&#xff0c;A 是正整数。将格子 (x,y) 里的数…

【Shell脚本】Shell编程之条件语句

目录 一.条件测试 1.test命令 1.1.test命令是内部命令 1.2.格式一 1.3.格式二 2.文件测试 2.1.常用的测试操作符 3.整数值测试 3.1.常用的测试操作符 3.2.格式一 3.3.格式二 4.字符串比较 4.1.格式一 4.2.格式二 注意&#xff1a; 5.逻辑测试 5.1.常用的测试操…

机器学习 - 梯度下降算法推导

要逐步推导多变量线性回归的梯度计算过程&#xff0c;我们首先需要明确模型和损失函数的形式&#xff0c;然后逐步求解每个参数的偏导数。这是梯度下降算法核心部分&#xff0c;因为这些偏导数将指导我们如何更新每个参数以最小化损失函数。 模型和损失函数 考虑一个多变量线…

“人工智能+”推进新质生产力发展论坛暨工作室实践实训基地授牌仪式圆满结束

4月27日&#xff0c;由江西财经大学现代经济管理学院主办的“人工智能”推进新质生产力发展论坛暨“江财现经管泰迪数智技术”校企工作室实践实训基地授牌仪式在江西财经大学现代经济管理学院共青城校区举行&#xff0c;学院院长王金海&#xff0c;副院长丁美东&#xff0c;副院…

为什么选择ATECLOUD自动化测试平台?

在当今飞速发展的时代&#xff0c;一切都在不断进步与变革&#xff0c;电测行业也由手动测试逐步转向了自动化测试。但是随着科技的发展&#xff0c;对于产品的测试要求也越来越高&#xff0c;传统的自动化测试系统已经无法满足用户日益增长的测试需求&#xff0c;全新的ATE测试…

[沫忘录]MySQL储存对象

[沫忘录]MySQL储存对象 视图 视图本质是对原表(基表)显示上的裁剪&#xff0c;可以当作表进行操作&#xff0c;其操作的结果会直接反馈到原表上&#xff0c;即对视图的操作实质上是对原表的操作。 MySQL不仅支持为基表创建视图&#xff0c;同时也支持为视图创建视图。 基本语…

【C++】详解STL容器之一的 vector

目录 概述 迭代器 数据结构 优点和缺点 接口介绍 begin end rbegin rend resize reseve insert erase 其他一些接口 模拟实现 框架 获取迭代器 深浅拷贝 赋值重载 reseve resize 拷贝构造 构造 析构 insert erase 其他 概述 vector是STL的容器之一。…

用户页面触发点击事件和 js 执行点击事件的区别

文章目录 情景展示情况一&#xff1a;用户点击页面触发情况二&#xff1a;通过 js 触发点击 结果分析情况一情况二 其实这个谜底揭开之后&#xff0c;第一反应都是&#xff0c;哦~&#xff0c;非常简单&#xff0c;但是细节决定成败&#xff0c;我被这个细节毁掉了&#xff0c;…

[嵌入式系统-72]:RT-Thread-组件:单元测试框架utest

目录 utest 测试框架 ​编辑 测试用例定义 测试单元定义 utest 应用框图 2. utest API assert 宏 测试单元函数运行宏 测试用例导出宏 测试用例 LOG 输出接口 3. 配置使能 4. 应用范式 5. 测试用例运行要求 6. 运行测试用例 测试结果分析 7. 测试用例运行流程 …

RAG 场景对Milvus Cloud向量数据库的需求

虽然向量数据库成为了检索的重要方式,但随着 RAG 应用的深入以及人们对高质量回答的需求,检索引擎依旧面临着诸多挑战。这里以一个最基础的 RAG 构建流程为例:检索器的组成包括了语料的预处理如切分、数据清洗、embedding 入库等,然后是索引的构建和管理,最后是通过 vecto…

webpack从零到1 构建 vue3

为什么要手写webpack 不用cli &#xff08;无的放矢&#xff09;并不是 其实是为了加深我们对webpack 的了解方便以后灵活运用webpack 的技术 初始化项目结构&#xff08;跟cli 结构保持一致&#xff09; 新建 public src 等文件夹npm init -y 创建package.json文件tsc --init…

【Ubuntu20.04安装java-8-openjdk】

1 下载 官网下载链接&#xff1a; https://www.oracle.com/java/technologies/downloads/#java8 下载 最后一行 jdk-8u411-linux-x64.tar.gz&#xff0c;并解压&#xff1a; tar -zxvf jdk-8u411-linux-x64.tar.gz2 环境配置 1、打开~/.bashrc文件 sudo gedit ~/.bashrc2、…
最新文章