Harmony Ble蓝牙App(二)连接与发现服务

Ble蓝牙App(二)连接与发现服务

  • 前言
  • 正文
    • 一、BlePeripheral回调
    • 二、连接和断连
    • 三、连接状态回调
    • 四、发现服务
    • 五、服务提供者
    • 六、显示服务
    • 七、源码

前言

  在上一篇中我们进行扫描设备的处理,本文中进行连接和发现服务的数据处理,运行效果图如下所示:
在这里插入图片描述

正文

  现在我们在ScanSlice扫描设备,选中一个设备进入MainAbilitySlice,下面要对选中的设备进行处理,首先我们来做连接。

一、BlePeripheral回调

  在之前我们写了一个BleCore,这里面是对扫描的封装,那么对于连接来说我们同样可以封装到这里,我们可以在BleCore中写一个BleDeviceCallback 类,继承自BlePeripheralCallback, 代码如下所示:

    private class BleDeviceCallback extends BlePeripheralCallback {

        /**
         * 连接状态改变
         * @param connectionState 状态码
         */
        @Override
        public void connectionStateChangeEvent(int connectionState) {

        }

        /**
         * 发现服务
         * @param status 状态
         */
        @Override
        public void servicesDiscoveredEvent(int status) {

        }
    }

  因为本文要做的事情是连接和发现服务,所以我们就先重写这两个方法,注意一点的是,蓝牙的操作都是在子线程中进行的,如果我们需要知道当前是否连接,则需要写一个接口用于回调到MainAbilitySlice中,在core包下新建一个BleCallback接口,代码如下所示:

public interface BleCallback {
    
    /**
     * 设备的所有信息
     *
     * @param info 信息
     */
    void deviceInfo(String info);

    /**
     * 连接状态
     *
     * @param state true or false
     */
    void connectionStateChange(boolean state);

    /**
     * 发现服务
     *
     * @param services 服务列表
     */
    void servicesDiscovered(List<GattService> services);
}

  接口中定义了三个方法,通过注释我们清晰的知道都是什么作用,这里着重介绍第一个函数,这个函数会显示设备各个时候的状态信息,从连接之后的所有动作,如果我们需要保存设备的操作日志的话,可以通过这个来进行处理保存。

然后回到BleCore,声明变量和设置接口回调的方法:

    private final BleDeviceCallback mBleDeviceCallback;
    private BleCallback bleCallback;
    private BlePeripheralDevice mDevice;
    private boolean mIsConnected;
	
    public BleCore(Context context) {
        ...
        //蓝牙设备类
        mBleDeviceCallback = new BleDeviceCallback();
    }	
    
    public void setBleCallback(BleCallback bleCallback) {
        this.bleCallback = bleCallback;
    }

    private void deviceInfo(String info) {
        if (bleCallback != null) {
            bleCallback.deviceInfo(info);
        }
    }

    private void connectState(boolean state) {
        mIsConnected = state;
        if (bleCallback != null) {
            bleCallback.connectionStateChange(state);
        }
    }
    
    public void setDevice(BlePeripheralDevice device) {
        mDevice = device;
    }

这里就是对设备信息和连接做了一个处理,下面我们增加连接和断连的方法。

二、连接和断连

在BleCore中增加如下代码:

    public boolean isConnected() {
        return mIsConnected;
    }
    
    public void connect() {
        if (mDevice == null) return;
        deviceInfo("连接设备...");
        mDevice.connect(false, mBleDeviceCallback);
    }

    public void disconnect() {
        if (mDevice == null) return;
        deviceInfo("断开连接设备...");
        mDevice.disconnect();
    }

连接与断开连接,调用时会触发connectionStateChangeEvent()方法。

三、连接状态回调

下面修改这个方法的代码,如下所示:

        @Override
        public void connectionStateChangeEvent(int connectionState) {
            String address = mDevice.getDeviceAddr();
            if (connectionState == ProfileBase.STATE_CONNECTED) {
                deviceInfo("连接成功:" + address);
                connectState(true);
            } else if (connectionState == ProfileBase.STATE_DISCONNECTED) {
                deviceInfo("断开连接成功:" + address);
                connectState(false);
                mDevice.close();
            }
        }

  在回调中,连接成功和断开连接都会有一个对应的状态码,通过状态回调到接口函数中,然后回到MainAbilitySlice中使用一下这个回调,首先我们修改一下ability_main.xml中的代码,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:alignment="center"
    ohos:background_element="$color:bg_color"
    ohos:orientation="vertical">

    <DirectionalLayout
        ohos:height="50vp"
        ohos:width="match_parent"
        ohos:alignment="vertical_center"
        ohos:background_element="$color:blue"
        ohos:orientation="horizontal"
        ohos:start_padding="12vp">

        <Text
            ohos:height="match_content"
            ohos:width="match_content"
            ohos:text="操作设备"
            ohos:text_color="#FFF"
            ohos:text_font="HwChinese-medium"
            ohos:text_size="18fp"
            ohos:weight="1"/>

        <Text
            ohos:id="$+id:tx_disconnect"
            ohos:height="match_content"
            ohos:width="match_content"
            ohos:end_margin="6vp"
            ohos:padding="8vp"
            ohos:text="断开连接"
            ohos:text_color="#FFF"
            ohos:text_size="14fp"/>

    </DirectionalLayout>

    <Text
        ohos:id="$+id:tx_device_info"
        ohos:height="match_content"
        ohos:width="match_parent"
        ohos:text="设备信息"
        ohos:padding="12vp"
        ohos:text_size="14fp"/>

    <ListContainer
        ohos:id="$+id:lc_service"
        ohos:height="match_parent"
        ohos:width="match_parent"/>

</DirectionalLayout>

  在XML中只增加了两个Text,分别用于断连和显示设备状态,下面我们写Slice之间的跳转,也就是从ScanSlice跳转到MainAbilitySlice。首先我们在MainAbility中增加action,代码如下所示:

public class MainAbility extends Ability {
    @Override
    public void onStart(Intent intent) {
        ...

        // add action for ability
        addActionRoute("action.main", MainAbilitySlice.class.getName());
    }
}

然后去config.json中增加配置,如下图所示:

在这里插入图片描述

然后我们回到ScanSlice中,在Item的点击事件中添加如下代码:

        //列表item点击监听
        lcDevice.setItemClickedListener((listContainer, component, position, id) -> {
            //设置设备
            bleCore.setDevice(mList.get(position).getDevice());
            Intent jumpIntent = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withAction("action.main")
                    .withDeviceId("")
                    .withBundleName("com.llw.ble")
                    .withAbilityName("com.llw.ble.MainAbility")
                    .build();
            jumpIntent.setOperation(operation);
            startAbility(jumpIntent);
        });

  这里跳转的代码比较多,跳转之前设置了设备进去,这种方式也是官方推荐的方式。然后我们修改MainAbility中的代码,如下所示:

public class MainAbilitySlice extends AbilitySlice implements BleCallback {

    private static final String TAG = MainAbilitySlice.class.getSimpleName();
    private Text txDisconnect;
    private Text txDeviceInfo;
    private ListContainer lcService;

    private BleCore bleCore;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        txDisconnect = (Text) findComponentById(ResourceTable.Id_tx_disconnect);
        txDeviceInfo = (Text) findComponentById(ResourceTable.Id_tx_device_info);
        lcService = (ListContainer) findComponentById(ResourceTable.Id_lc_service);

        bleCore = BleApp.getBleCore();
        bleCore.setBleCallback(this);
        //连接设备
        bleCore.connect();

        txDisconnect.setClickedListener(component -> {
            if (bleCore.isConnected()) {
                bleCore.disconnect();
            } else {
                bleCore.connect();
            }
        });
    }

    @Override
    public void deviceInfo(String info) {
        getUITaskDispatcher().asyncDispatch(() -> {
            LogUtils.LogD(TAG, info);
            txDeviceInfo.setText(info);
        });
    }

    @Override
    public void connectionStateChange(boolean state) {
        getUITaskDispatcher().asyncDispatch(() -> txDisconnect.setText(state ? "断开连接" : "连接"));
    }

    @Override
    public void servicesDiscovered(List<GattService> services) {

    }
}

  使用BleCoreconnect()方法进行连接设备,在onStart()方法中进行BleCore的赋值,然后设置Ble的回调,实现BleCallback接口,重写里面的函数,当连接成功之后会通过回调deviceInfo()得到设备状态,因为是子线程所以在ui线程中渲染UI。而connectionStateChange()函数,回调连接成功或者失败,如果成功则为ture,就显示txDisconnect控件,此时连接成功,点击这个txDisconnect就会断开连接,点击监听就在onStart()中写好了,下面我们运行一下看看效果。

在这里插入图片描述

从这个效果图来看,我们连接成功之后有状态,点击断开连接也会有状态改变,那么连接就写好了。

四、发现服务

  连接写好了,下面可以写发现服务了,我们可以在连接成功的处理中进行发现服务,下面我们修改一下BleDeviceCallback中的connectionStateChangeEvent()方法中的代码,如下图所示:

在这里插入图片描述

通过mDevice.discoverServices()进行发现服务的动作,在此之前通过deviceInfo()设置当前的动作状态,发现服务执行会触发servicesDiscoveredEvent()回调,在这个回调中我们可以回调到页面,修改代码如下所示:

        @Override
        public void servicesDiscoveredEvent(int status) {
            if (status == BlePeripheralDevice.OPERATION_SUCC) {
                deviceInfo("发现" + mDevice.getServices().size() + "服务");
                if (bleCallback != null) {
                    bleCallback.servicesDiscovered(mDevice.getServices());
                }
            }
        }

  在回调中设置发现服务的个数,然后回调,因为服务是多个的,那么下面我们就需要使用一个列表是装载服务,之前我们就已经在ability_main.xml中写好了。

五、服务提供者

  要显示服务列表数据,首先需要一个提供者,而提供者又需要一个item去渲染数据,下面我们在layout下创建一个item_service.xml,代码如下所示:

<?xml version="1.0" encoding="utf-8"?>
<DependentLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_content"
    ohos:width="match_parent"
    ohos:background_element="$color:white"
    ohos:bottom_margin="2vp"
    ohos:bottom_padding="8vp"
    ohos:end_padding="16vp"
    ohos:start_padding="16vp"
    ohos:top_padding="8vp">

    <Text
        ohos:id="$+id:tx_service_name"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:text="服务"
        ohos:text_size="16fp"/>

    <Button
        ohos:id="$+id:tx_uuid_title"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:below="$id:tx_service_name"
        ohos:text="UUID:"
        ohos:text_color="$color:gray"
        ohos:text_size="16fp"
        ohos:top_margin="2vp"/>

    <Button
        ohos:id="$+id:tx_uuid"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:below="$id:tx_service_name"
        ohos:end_of="$id:tx_uuid_title"
        ohos:text="UUID"
        ohos:text_size="16fp"
        ohos:top_margin="2vp"/>

    <Button
        ohos:id="$+id:tx_service_info"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:below="$id:tx_uuid_title"
        ohos:text="PRIMARY SERVICE"
        ohos:text_color="$color:gray"
        ohos:text_size="16fp"
        ohos:top_margin="2vp"/>

</DependentLayout>

下面我们在ble包下新建一个BleUtils类,代码如下所示:

public class BleUtils {

    public static final String generic = "-0000-1000-8000-00805F9B34FB";

    public static String getServiceUUID(UUID uuid) {
        return "0x" + uuid.toString().substring(4, 8).toUpperCase();
    }

    /**
     * 获取蓝牙服务名称
     *
     * @param uuid UUID
     */
    public static String getServiceName(UUID uuid) {
        String targetUuid = getServiceUUID(uuid);
        switch (targetUuid) {
            case "0x1800":
                return "Generic Access service";
            case "0x1801":
                return "Generic Attribute service";
            case "0x1802":
                return "Immediate Alert service";
            case "0x1803":
                return "Link Loss service";
            case "0x1804":
                return "Tx Power service";
            case "0x1805":
                return "Current Time service";
            case "0x1806":
                return "Reference Time Update service";
            case "0x1807":
                return "Next DST Change service";
            case "0x1808":
                return "Glucose service";
            case "0x1809":
                return "Health Thermometer service";
            case "0x180A":
                return "Device Information service";
            case "0x180D":
                return "Heart Rate service";
            case "0x180E":
                return "Phone Alert Status service";
            case "0x180F":
                return "Battery service";
            case "0x1810":
                return "Blood Pressure service";
            case "0x1811":
                return "Alert Notification service";
            case "0x1812":
                return "Human Interface Device service";
            case "0x1813":
                return "Scan Parameters service";
            case "0x1814":
                return "Running Speed and Cadence service";
            case "0x1815":
                return "Automation IO service";
            case "0x1816":
                return "Cycling Speed and Cadence service";
            case "0x1818":
                return "Cycling Power service";
            case "0x1819":
                return "Location and Navigation service";
            case "0x181A":
                return "Environmental Sensing service";
            case "0x181B":
                return "Body Composition service";
            case "0x181C":
                return "User Data service";
            case "0x181D":
                return "Weight Scale service";
            case "0x181E":
                return "Bond Management service";
            case "0x181F":
                return "Continuous Glucose Monitoring service";
            case "0x1820":
                return "Internet Protocol Support service";
            case "0x1821":
                return "Indoor Positioning service";
            case "0x1822":
                return "Pulse Oximeter service";
            case "0x1823":
                return "HTTP Proxy service";
            case "0x1824":
                return "Transport Discovery service";
            case "0x1825":
                return "Object Transfer service";
            case "0x1826":
                return "Fitness Machine service";
            case "0x1827":
                return "Mesh Provisioning service";
            case "0x1828":
                return "Mesh Proxy service";
            case "0x1829":
                return "Reconnection Configuration service";
            case "0x183A":
                return "Insulin Delivery service";
            case "0x183B":
                return "Binary Sensor service";
            case "0x183C":
                return "Emergency Configuration service";
            case "0x183D":
                return "Authorization Control service";
            case "0x183E":
                return "Physical Activity Monitor service";
            case "0x183F":
                return "Elapsed Time service";
            case "0x1840":
                return "Generic Health Sensor service";
            case "0x1843":
                return "Audio Input Control service";
            case "0x1844":
                return "Volume Control service";
            case "0x1845":
                return "Volume Offset Control service";
            case "0x1846":
                return "Coordinated Set Identification service";
            case "0x1847":
                return "Device Time service";
            case "0x1848":
                return "Media Control service";
            case "0x1849":
                return "Generic Media Control service";
            case "0x184A":
                return "Constant Tone Extension service";
            case "0x184B":
                return "Telephone Bearer service";
            case "0x184C":
                return "Generic Telephone Bearer service";
            case "0x184D":
                return "Microphone Control service";
            case "0x184E":
                return "Audio Stream Control service";
            case "0x184F":
                return "Broadcast Audio Scan service";
            case "0x1850":
                return " Published Audio Capabilities service";
            case "0x1851":
                return "Basic Audio Announcement service";
            case "0x1852":
                return "Broadcast Audio Announcement service";
            case "0x1853":
                return "Common Audio service";
            case "0x1854":
                return "Hearing Access service";
            case "0x1855":
                return "Telephony and Media Audio service";
            case "0x1856":
                return "Public Broadcast Announcement service";
            case "0x1857":
                return "Electronic Shelf Label service";
            default:
                return "Unknown Service";
        }
    }
}

  这里需要说明一下蓝牙的UUID,蓝牙UUID(Universally Unique Identifier)是用于唯一标识蓝牙设备和服务的一种标识符。它是一个128位长的数字,在蓝牙通信中起到唯一标识的作用。蓝牙UUID按照标准分为两种类型:

  1. 16位UUID:这些UUID通常用于蓝牙标准定义的一些通用服务和特性。例如,设备名称服务的UUID是 00001800-0000-1000-8000-00805F9B34FB。

  2. 128位UUID:这些UUID通常用于自定义的服务和特性,以确保全球唯一性。可以自行生成一个128位的UUID作为自定义的服务或特性标识。例如,一个自定义的服务UUID可以是 0000XXXX-0000-1000-8000-00805F9B34FB,其中的 XXXX 部分可以是任意的16进制数字。

在蓝牙通信中,设备使用UUID来发布和查找服务以及识别特性。UUID是蓝牙设备之间进行通信时的重要标识,确保了设备和服务的唯一性。

那么getServiceName()中的键你就知道是什么意思了,0x1800就是16进制数字,而对应的值则是SIG定义的,可以参考这个文档:Assigned_Numbers.pdf。如果你的值找不到对应的,那说明它不是SIG规范的,你这个服务UUID就是自己公司自定义的。

下面我们写提供者,在provider包下新建一个ServiceProvider类,代码如下所示:

public class ServiceProvider extends BaseItemProvider {

    private final List<GattService> serviceList;
    private final AbilitySlice slice;

    public ServiceProvider(List<GattService> list, AbilitySlice slice) {
        this.serviceList = list;
        this.slice = slice;
    }

    @Override
    public int getCount() {
        return serviceList == null ? 0 : serviceList.size();
    }

    @Override
    public Object getItem(int position) {
        if (serviceList != null && position >= 0 && position < serviceList.size()) {
            return serviceList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public Component getComponent(int position, Component component, ComponentContainer componentContainer) {
        final Component cpt;
        ServiceHolder holder;

        GattService service = serviceList.get(position);
        if (component == null) {
            cpt = LayoutScatter.getInstance(slice).parse(ResourceTable.Layout_item_service, null, false);
            holder = new ServiceHolder(cpt);
            //将获取到的子组件信息绑定到列表项的实例中
            cpt.setTag(holder);
        } else {
            cpt = component;
            // 从缓存中获取到列表项实例后,直接使用绑定的子组件信息进行数据填充。
            holder = (ServiceHolder) cpt.getTag();
        }

        holder.txServiceName.setText(BleUtils.getServiceName(service.getUuid()));
        holder.txUuid.setText(BleUtils.getServiceUUID(service.getUuid()));
        
        return cpt;
    }

    /**
     * 用于保存列表项的子组件信息
     */
    public static class ServiceHolder {
        Text txServiceName;
        Text txUuid;
        public ServiceHolder(Component component) {
            txServiceName = (Text) component.findComponentById(ResourceTable.Id_tx_service_name);
            txUuid = (Text) component.findComponentById(ResourceTable.Id_tx_uuid);
        }
    }
}

这里的代码就是比较简单的,就是基本的写法,下面回到MainAbilitySlice中进行显示数据。

六、显示服务

首先声明变量:

    private final List<GattService> serviceList = new ArrayList<>();
    private ServiceProvider serviceProvider;

然后实现OnItemClickListener 接口

public class MainAbilitySlice extends AbilitySlice implements BleCallback, ListContainer.ItemClickedListener {

重写onItemClicked()方法,并且增加了一个showMsg,这个Toast的可定制化做的很多。

    @Override
    public void onItemClicked(ListContainer listContainer, Component component, int position, long id) {
        showMsg(serviceList.get(position).getUuid().toString());
    }

    private void showMsg(String msg) {
        ToastDialog toastDialog = new ToastDialog(getContext());
        toastDialog.setSize(DirectionalLayout.LayoutConfig.MATCH_CONTENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT);
        toastDialog.setDuration(2000);
        toastDialog.setText(msg);
        toastDialog.setAlignment(LayoutAlignment.CENTER);
        Text toastText = (Text) toastDialog.getComponent();
        if (toastText != null) {
            toastText.setMultipleLine(true);
            toastText.setTextSize(14, Text.TextSizeType.FP);
            toastText.setTextColor(Color.WHITE);
            toastText.setPadding(40, 20, 40, 20);
            ShapeElement toastBackground = new ShapeElement();
            toastBackground.setRgbColor(new RgbColor(24, 196, 124));
            toastBackground.setCornerRadius(60f);
            toastText.setBackground(toastBackground);
        }
        toastDialog.show();
    }

然后在onStart()方法中初始化服务提供者,代码如下所示:

    @Override
    public void onStart(Intent intent) {
        ...

        serviceProvider = new ServiceProvider(serviceList, this);
        lcService.setItemProvider(serviceProvider);
        lcService.setItemClickedListener(this);
    }

修改servicesDiscovered()方法,代码如下所示:

    @Override
    public void servicesDiscovered(List<GattService> services) {
        getUITaskDispatcher().asyncDispatch(() -> {
            serviceList.clear();
            serviceList.addAll(services);
            serviceProvider.notifyDataChanged();
        });
    }

这里的写法其实和扫描设备哪里如出一辙,下面我们运行一下看看,什么效果。

在这里插入图片描述

七、源码

如果对你有所帮助的话,不妨 StarFork,山高水长,后会有期~

源码地址:HarmonyBle-Java

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

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

相关文章

多数据库使用django-apscheduler时,migrate后并不能生成django_apscheduler_djangojob表的问题

先说一下django-apscheduler定时器的使用过程&#xff1a; django-apscheduler基本使用 1.安装django-apscheduler代码如下&#xff08;示例&#xff09;&#xff1a; pip install django-apscheduler 2.配置settings.py的INSTALLED_APPS代码如下&#xff08;示例&#xff09…

性能测试必备知识-使用MySQL存储过程构造大量数据:实例解析

在软件开发过程中&#xff0c;测试是一个不可或缺的环节。通过测试&#xff0c;我们可以发现并修复软件中的各种问题&#xff0c;提高软件的质量和稳定性。然而&#xff0c;手动编写大量的测试用例是一项耗时且容易出错的任务。为了解决这个问题&#xff0c;我们需要学会使用批…

ES ElasticSearch安装、可视化工具kibana安装

1、安装ES docker run -d --name es9200 -e "discovery.typesingle-node" -p 9200:9200 elasticsearch:7.12.1访问测试&#xff1a; http://域名:9200/ 2、安装kibana对es进行可视化操作 执行命令 docker run -d --name kibana5601 -p 5601:5601 kibana:7.1.12.修…

在线工具收集

在线工具收集 1、在线P图 https://www.photopea.com/ 一款类似于PS的在线抠图软件 ①去除图片中的文字&#xff0c;并填充背景色 第一步&#xff1a;使用矩形选中要清除的文字 第二步&#xff1a;点击编辑选择填充 第三步&#xff1a;选择内容识别&#xff0c;保留透明区域…

[MySQL] MySQL 表的增删查改

本篇文章对mysql表的增删查改进行了详细的举例说明解释。对表的增删查改简称CRUD : Create(创建), Retrieve(读取)&#xff0c;Update(更新)&#xff0c;Delete&#xff08;删除&#xff09;。其中重点是对查询select语句进行了详细解释&#xff0c;并且通过多个实际例子来帮助…

物联网AI MicroPython学习之语法 I2S音频总线接口

学物联网&#xff0c;来万物简单IoT物联网&#xff01;&#xff01; I2S 介绍 模块功能: I2S音频总线驱动模块 接口说明 I2S - 构建I2S对象 函数原型&#xff1a;I2S(id, sck, ws, sd, mode, bits, format, rate, ibuf)参数说明&#xff1a; 参数类型必选参数&#xff1f…

《洛谷深入浅出基础篇》P4017最大食物链————拓扑排序

上链接&#xff1a;P4017 最大食物链计数 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)https://www.luogu.com.cn/problem/P4017 上题干&#xff1a; 题目背景 你知道食物链吗&#xff1f;Delia 生物考试的时候&#xff0c;数食物链条数的题目全都错了&#xff0c;因为她总是…

力扣:178. 分数排名(Python3)

题目&#xff1a; 表: Scores ---------------------- | Column Name | Type | ---------------------- | id | int | | score | decimal | ---------------------- 在 SQL 中&#xff0c;id 是该表的主键。 该表的每一行都包含了一场比赛的分数。Score …

电子学会C/C++编程等级考试2023年03月(一级)真题解析

C/C++等级考试(1~8级)全部真题・点这里 第1题:字符长方形 给定一个字符,用它构造一个长为4个字符,宽为3个字符的长方形,可以参考样例输出。 时间限制:1000 内存限制:65536输入 输入只有一行, 包含一个字符。输出 该字符构成的长方形,长4个字符,宽3个字符。样例输入…

虚拟机VMware上安装Ubuntu系统(详细图文教程)

关于虚拟机VMware的安装教程&#xff0c;学者看我另外一篇博客&#xff1a;VMware详细安装教程 目录 一、Ubuntn系统准备二、VMware上安装Ubuntn系统2.1 答疑 三、导入Ubuntu系统四、总结 一、Ubuntn系统准备 先下载好Ubuntn系统&#xff0c;这里我提供一个&#xff0c;下载链…

一、用户管理

一、后端数据库初始化 1.1 因为版本问题&#xff0c;始终报错&#xff0c;按照报错信息去查询解决方案&#xff0c;无法解决 灵机一动&#xff1a; 网址&#xff1a; Spring Boot 3.0 升级 实战踩坑记录 - 掘金 (juejin.cn) &#xff11;.&#xff12; 个人配置【运行成功…

机器学习实战-第5章 Logistic回归

Logistic 回归 概述 Logistic 回归 或者叫逻辑回归 虽然名字有回归,但是它是用来做分类的。其主要思想是: 根据现有数据对分类边界线(Decision Boundary)建立回归公式,以此进行分类。 须知概念 Sigmoid 函数 回归 概念 假设现在有一些数据点,我们用一条直线对这些点进行…

KT404A远程更换语音芯片方案支持OTA 4G 蓝牙 wifi 物联网

目录 一、简介 2.1 芯片的硬件 2.2 测试的方法 一、简介 KT404A远程更换语音芯片方案支持OTA 4G 蓝牙 wifi 物联网 在线下载的mp3语音芯片ic&#xff0c;通过KT404A的uart直接更换内部的语音文件&#xff0c;从而实现动态的更新语音内容 物联网大潮的来袭。随着智能家居、…

OpenStack云计算平台-计算服务

目录 一、计算服务概览 二、安装并配置控制节点 1、先决条件 2、安全并配置组件 3、完成安装 三、安装和配置计算节点 1、安全并配置组件 2、完成安装 四、验证操作 一、计算服务概览 使用OpenStack计算服务来托管和管理云计算系统。OpenStack计算服务是基础设施即服务…

EI论文故障识别程序:DBN深度置信/信念网络的故障识别Matlab程序,数据由Excel导入,直接运行!

​适用平台&#xff1a;Matlab2021b版及以上 本程序参考中文EI期刊《基于变分模态分解和改进灰狼算法优化深度置信网络的自动转换开关故障识别》中的深度置信网络&#xff08;Deep Belief Network&#xff0c;DBN&#xff09;部分进行故障识别&#xff0c;程序注释清晰&#x…

深度学习卷积神经网络的花卉识别 计算机竞赛

文章目录 0 前言1 项目背景2 花卉识别的基本原理3 算法实现3.1 预处理3.2 特征提取和选择3.3 分类器设计和决策3.4 卷积神经网络基本原理 4 算法实现4.1 花卉图像数据4.2 模块组成 5 项目执行结果6 最后 0 前言 &#x1f525; 优质竞赛项目系列&#xff0c;今天要分享的是 基…

数十万QPS,百度热点大事件搜索的稳定性保障实践

作者 | 文燕 导读 在互联网行业里&#xff0c;业务迭代很快&#xff0c;系统变更频繁&#xff0c;尤其长青业务随着时间会积累越来越多历史包袱。阿拉丁作为百度搜索垂直化的产品&#xff0c;业务历经多年更迭&#xff0c;历史包袱很多&#xff0c;在应对大事件比如高考、东京奥…

【PyQt】QPixmap与numpy.array互转

这里给出QPixmap→numpy.ndarray的两条转换(一个是使用PIL.Image而另一个不用)&#xff0c; 以及numpy.ndarray→QPixmap两条转换(同样也是用不用PIL.Image的区别)。 代码运行结果&#xff1a; from PyQt5.QtCore import QPoint,QRect,Qt from PyQt5.QtWidgets import QLabel …

【UE5】五大基类及其使用

UObject UObject表示对象&#xff0c;准确来说&#xff0c;虚幻引擎中的对象基础类为UObject UObject提供了以下功能&#xff1a; 垃圾收集&#xff08;Garbage collection&#xff09;引用自动更新&#xff08;Reference updating&#xff09;反射&#xff08;Reflection&am…

SQLite3 数据库学习(六):Qt 嵌入式 Web 服务器详解

参考引用 SQLite 权威指南&#xff08;第二版&#xff09;SQLite3 入门 1. Apache 搭建 cgi 环境 1.1 什么是 Apache Apache 是世界使用排名第一的 Web 服务器软件 它可以运行在几乎所有广泛使用的计算机平台上&#xff0c;由于其跨平台和安全性被广泛使用 1.2 具体搭建流程…
最新文章