说明: 在添加安全子系统时,可直接通过配置feature来选择安全子系统特性。

{
   "subsystem": "security",
   "components": [
     { "component": "hichainsdk", "features":[] },
     { "component": "huks", "features":
       [
         "disable_huks_binary = false",
         "disable_authenticate = false"
       ]
     }
   ]
 },
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">

移植通信子系统

通信子系统目前涉及Wi-Fi和蓝牙适配,厂商应当根据芯片自身情况进行适配。

移植指导

Wi-Fi编译文件内容如下:

路径:“foundation/communication/wifi_lite/BUILD.gn”

group("wifi") {
  deps = [ "$ohos_board_adapter_dir/hals/communication/wifi_lite/wifiservice:wifiservice" ]
}
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">

从中可以看到厂商适配相关接口的.c文件存放目录应为“$ohos_board_adapter_dir/hals/communication/wifi_lite/wifiservice”,且该目录下BUILD.gn文件中的目标应为“wifiservice”。需要厂商适配的Wi-Fi接口见表1 、表2 和表3,蓝牙接口见表4和表5。

表1 wifi_device.h

class="table-box">
接口作用
EnableWifi启用Wi-Fista模式。
DisableWifi禁用Wi-Fi sta模式。
IsWifiActive检查Wi-Fi sta模式是否启用。
Scan扫描热点信息。
GetScanInfoList获取所有扫描到的热点列表。
AddDeviceConfig配置连接到的热点信息。
GetDeviceConfigs获取配置连接到的热点信息。
RemoveDevice删除指定的热点配置信息。
ConnectTo接到指定的热点。
Disconnect断开Wi-Fi连接。
GetLinkedInfo获取热点连接信息。
RegisterWifiEvent为指定的Wi-Fi事件注册回调。
UnRegisterWifiEvent取消注册以前为指定Wi-Fi事件注册的回调。
GetDeviceMacAddress获取设备的MAC地址。
AdvanceScan根据指定参数启动Wi-Fi扫描。

表2 wifi_hotspot_config.h

class="table-box">
接口作用
SetBand设置该热点的频段。
GetBand获取该热点的频段。

表3 wifi_hotspot.h

class="table-box">
接口作用
EnableHotspot启用Ap热点模式。
DisableHotspot禁用Ap热点模式。
SetHotspotConfig设置指定的热点配置。
GetHotspotConfig获取指定的热点配置。
IsHotspotActive检查Ap热点模式是否启用。
GetStationList获取连接到此热点的一系列STA。
GetSignalLevel获取指定接收信号强度指示器(RSSI)和频带指示的信号电平。
DisassociateSta使用指定的MAC地址断开与STA的连接。
AddTxPowerInfo将hotspot功率发送到beacon。

表4 ohos_bt_gatt.h

class="table-box">
接口作用
InitBtStack初始化蓝牙协议栈。
EnableBtStack使能蓝牙协议栈。
DisableBtStack禁用蓝牙协议栈。
SetDeviceName设置蓝牙设备名称。
BleSetAdvData设置广播数据。
BleStartAdv开始广播。
BleStartAdvEx传入构建好的广播数据,参数,开启蓝牙广播。
BleStopAdv停止发送广播。
BleUpdateAdv更新advertising参数。
BleSetSecurityIoCap设置蓝牙的IO能力为NONE,配对方式为justworks。
BleSetSecurityAuthReq设置蓝牙是否需要配对绑定。
BleGattSecurityRsp响应安全连接请求。
ReadBtMacAddr获取设备MAC地址。
BleSetScanParameters设置扫描参数。
BleStartScan开始扫描。
BleStopScan停止扫描。
BleGattRegisterCallbacks注册gap,GATT事件回调函数。

表5 ohos_bt_gatt_server.h

class="table-box">
接口作用
BleGattsRegister使用指定的应用程序UUID注册GATT服务器。
BleGattsUnRegister断开GATT服务器与客户端的连接。
BleGattsDisconnect断开GATT服务器与客户端的连接。
BleGattsAddService添加了一个服务。
BleGattsAddIncludedService将包含的服务添加到指定的服务。
BleGattsAddCharacteristic向指定的服务添加特征。
BleGattsAddDescriptor将描述符添加到指定的特征。
BleGattsStartService启动一个服务。
BleGattsStopService停止服务。
BleGattsDeleteService删除一个服务。
BleGattsClearServices清除所有服务。
BleGattsSendResponse向接收到读取或写入请求的客户端发送响应。
BleGattsSendIndication设备侧向APP发送蓝牙数据。
BleGattsSetEncryption设置GATT连接的加密类型。
BleGattsRegisterCallbacks注册GATT服务器回调。
BleGattsStartServiceEx根据传入的服务列表,创建gatt服务。
BleGattsStopServiceEx传入gatt服务句柄,停止gatt服务。

说明: 不同版本接口可能存在差异,需要根据当前版本的具体文件进行适配。

适配实例

  1. 在“config.json”中添加communication子系统。 路径:“vendor/MyVendorCompany/MyProduct/config.json”

修改如下:

    { 
        "subsystem": "communication", 
        "components": [ 
            { "component": "wifi_lite", "features":[] }
        ] 
    },
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
  1. 添加适配文件。

在“vendor/MyVendorCompany/MyProduct/config.json”文件中,通常将配置“ohos_board_adapter_dir”配置为 “//vendor/MyVendorCompany/MyProduct/adapter”。

在“ohos_board_adapter_dir”目录下根据上述适配指导中提到的头文件,适配Wi-Fi、蓝牙接口。

移植外设驱动子系统

外设驱动子系统提供OpenHarmony专有的外部设备操作接口。本模块提供设备操作接口有:FLASH, GPIO, I2C, PWM, UART, WATCHDOG等。

OpenHarmony提供了两种驱动适配方式:使用外设驱动子系统、使用HDF驱动框架。由于轻量级系统的资源有限,这里建议使用IOT子系统方式。

移植指导

厂商需要根据OpenHarmony提供的接口定义实现其功能,IOT子系统接口定义的头文件如下:

base/iot_hardware/peripheral/
├── BUILD.gn
└── interfaces
    └── kits
        ├── iot_errno.h
        ├── iot_flash.h
        ├── iot_gpio.h
        ├── iot_i2c.h
        ├── iot_pwm.h
        ├── iot_uart.h
        ├── iot_watchdog.h
        ├── lowpower.h
        └── reset.h
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">

其中“base/iot_hardware/peripheral/BUILD.gn”文件如下:

import("//build/lite/config/subsystem/lite_subsystem.gni")
import("//build/lite/ndk/ndk.gni")

lite_subsystem("iothardware") {
  subsystem_components = [
    "$ohos_vendor_adapter_dir/hals/iot_hardware/wifiiot_lite:hal_iothardware",
  ]
}
if (ohos_kernel_type == "liteos_m") {
  ndk_lib("iothardware_ndk") {
    deps = [
      "$ohos_vendor_adapter_dir/hals/iot_hardware/wifiiot_lite:hal_iothardware", #依赖厂商的适配
    ]
    head_files = [ "//base/iot_hardware/peripheral/interfaces/kits" ]
  }
}
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}"> class="hide-preCode-box">

从中可以看到厂商适配相关接口的存放目录应为“$ohos_vendor_adapter_dir/hals/iot_hardware/wifiiot_lite”,且该目录下BUILD.gn文件中的目标应为hal_iothardware。

移植实例

  1. 在“config.json”中添加iot_hardware子系统。 路径:“vendor/MyVendorCompany/MyProduct/config.json”

修改如下:

    { 
        subsystem": "iot_hardware", 
        components": [ 
            { "component": "iot_controller", "features":[] }
        ] 
    },
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
  1. 添加适配文件。

在“vendor/MyVendorCompany/MyProduct/config.json”文件中,通常将配置“vendor_adapter_dir”配置为 “//device/MyDeviceCompany/MyBoard/adapter”。

在“vendor_adapter_dir”目录下进行适配:

    hals/iot_hardware/wifiiot_lite
    ├── BUILD.gn
    ├── iot_flash.c
    ├── iot_gpio.c
    ├── iot_i2c.c
    ├── iot_lowpower.c
    ├── iot_pwm.c
    ├── iot_reset.c
    ├── iot_uart.c
    └── iot_watchdog.c
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">

其中BUILD.gn内容如下:

    static_library("hal_iothardware") {   #目标名
        sources = [                       #厂商适配的源文件
          "iot_watchdog.c",
          "iot_reset.c",
          "iot_flash.c",
          "iot_i2c.c",
          "iot_gpio.c",
          "iot_pwm.c",
          "iot_uart.c"
        ]
        include_dirs = [ ]
    }
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">

其中,“include_dirs”需要根据工程实际情况包含两个路径:

配置其他子系统

除上述子系统之外,还有一些必要但是无需进行移植的子系统。如:分布式任务调度子系统、DFX子系统。

这些子系统添加方式比较简单,在“vendor/MyVendorCompany/MyProduct/config.json”文件中进行如下配置即可:

{
  "subsystem": "distributed_schedule",
  "components": [
    { "component": "system_ability_manager", "features":[] }  # 此处部件名不同版本可能有变化,请根据实际代码填写
  ]
},
{
  "subsystem": "hiviewdfx",
  "components": [
    { "component": "hilog_lite", "features":[] },
    { "component": "hievent_lite", "features":[] }
  ]
},
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">

如果大家想更加深入的学习 OpenHarmony(鸿蒙南向) 开发的全栈内容,不妨可以参考以下相关学习文档进行学习,助你快速提升自己:

OpenHarmony 开发环境搭建:https://qr18.cn/CgxrRy

《OpenHarmony源码解析》:https://qr18.cn/CgxrRy

系统架构分析:https://qr18.cn/CgxrRy

OpenHarmony 设备开发学习手册:https://qr18.cn/CgxrRy

在这里插入图片描述

OpenHarmony面试题(内含参考答案):https://qr18.cn/CgxrRy

写在最后

data-report-view="{"mod":"1585297308_001","spm":"1001.2101.3001.6548","dest":"https://blog.csdn.net/maniuT/article/details/140824406","extend1":"pc","ab":"new"}">> id="blogExtensionBox" style="width:400px;margin:auto;margin-top:12px" class="blog-extension-box"> class="blog_extension blog_extension_type2" id="blog_extension"> class="extension_official" data-report-click="{"spm":"1001.2101.3001.6471"}" data-report-view="{"spm":"1001.2101.3001.6471"}"> class="blog_extension_card_left"> class="blog_extension_card_cont"> 鸿蒙开发学习资料领取!!! class="blog_extension_card_cont_r"> 微信名片
注:本文转载自blog.csdn.net的沧海一笑-dj的文章"https://blog.csdn.net/dengjin20104042056/article/details/95630795"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接

评论记录:

未查询到任何数据!