首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

OpenHarmony鸿蒙( Beta5.0)智能门铃开发实践

  • 25-03-03 07:02
  • 2637
  • 13294
blog.csdn.net

   鸿蒙开发往期必看:

一分钟了解”纯血版!鸿蒙HarmonyOS Next应用开发!

“非常详细的” 鸿蒙HarmonyOS Next应用开发学习路线!(从零基础入门到精通)

 “一杯冰美式的时间” 了解鸿蒙HarmonyOS Next应用开发路径!


样例简介

智能门铃通过监控来访者信息,告诉主人门外是否有人按铃、有陌生人靠近或者无人状态。主人可以在数字管家中远程接收消息,并根据需要进行远程取消报警和一键开锁。同时,也可以通过室内屏幕获取门外状态。室内屏幕显示界面使用DevEco Studio 编写的js应用,具有很好的兼容和移植特性。硬件上采用了带有HDF框架的驱动模型,通过GPIO来获取传感器采集信息并驱动报警器进行动作。

image-20211228172423071​

运行效果

image-20220402103912059​

样例原理

​

如上图所示,智能门铃整体方案原理图可以大致分成:智能门铃设备、数字管家应用、云平台三部分。智能门铃通过MQTT协议连接华为IOT物联网平台,从而实现命令的接收和属性上报。 关于智能设备接入华为云IoT平台的细节可以参考 连接IOT云平台指南;智能设备同数字管家应用之间的设备模型定义可以参考profile 。

工程版本
  • 系统版本/API版本:OpenHarmony 3.1 Beta

  • hb版本:0.4.4

  • 工具链版本:gcc-arm-none-eabi-10.3-2021.10

快速上手

准备硬件环境
  • 欧智通V200Z-R开发板

  • 润和智能家居套件-红绿灯板

  • 润和智能家居套件-炫彩灯板

  • 预装HarmonyOS手机一台

    注:HarmonyOS是华为基于开源项目OpenHarmony开发的面向多种全场景智能设备的商用版本

准备开发环境
安装必备软件

开发基础环境由 windows 工作台和 Linux 编译服务器组成。windows 工作台可以通过 samba 服务或 ssh 方式访问 Linux编译服务器。其中 windows 工作台用来烧录和代码编辑,Linux 编译服务器用来编译 OpenHarmony 代码,为了简化步骤,Linux 编译服务器推荐安装 Ubuntu20.04。

安装编译依赖基础软件
sudo apt-get install -y build-essential gcc g++ make zlib* libffi-dev git git-lfs
安装和配置Python
  • 打开Linux终端。

  • 输入如下命令,查看python版本号,需要使用python3.7以上版本。

python3 --version
  • 安装并升级Python包管理工具(pip3)。
  1. sudo apt-get install python3-setuptools python3-pip -y
  2. sudo pip3 install --upgrade pip
  • 设置pip的国内镜像
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple requests
安装hb
  • 输入如下命令确认hb是否为version 0.4.4
hb -v

a. 若提示如下内容,则表示未安装可以从第2步开始操作。

bash: /home/***/.local/bin/hb: No such file or directory

b.若提示如下内容,需要先卸载该版本,然后再执行第2步操作步骤。

[OHOS INFO] hb version 0.4.3

卸载命令:

pip3 uninstall ohos-build
  • 运行如下命令安装hb
pip3 install build/lite   // 该命令需在OpenHarmony源码根目录下执行
  • 设置环境变量
vim ~/.bashrc

将以下命令拷贝到.bashrc文件的最后一行,保存并退出。

export PATH=~/.local/bin:PATH

执行如下命令更新环境变量。

source ~/.bashrc
  • 再次执行”hb -v“,有以下版本显示则表示安装的hb版本正确。
[OHOS INFO] hb version 0.4.4
安装交叉编译环境

在Linux编译服务器上搭建好基础开发环境后,需要安装OpenHarmony 编译V200Z-R平台特有的开发环境。

安装arm-none-eabi-gcc
  • 打开Linux终端。

  • 下载arm-none-eabi-gcc编译工具。

  • 安装arm-none-eabi-gcc

解压 gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 安装包至~/toolchain/路径下。

  1. mkdir -p ~/toolchain/
  2. tar -jxvf gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 -C ~/toolchain/

设置环境变量。

vim ~/.bashrc

将以下命令拷贝到.bashrc文件的最后一行,保存并退出。

export PATH=~/toolchain/gcc-arm-none-eabi-10.3-2021.10/bin:PATH

执行如下命令更新环境变量。

source ~/.bashrc
  • 再次执行”hb -v“,有以下版本显示则表示安装的hb版本正确。
[OHOS INFO] hb version 0.4.4
安装交叉编译环境

在Linux编译服务器上搭建好基础开发环境后,需要安装OpenHarmony 编译V200Z-R平台特有的开发环境。

安装arm-none-eabi-gcc
  • 打开Linux终端。

  • 下载arm-none-eabi-gcc编译工具。

  • 安装arm-none-eabi-gcc

解压 gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 安装包至~/toolchain/路径下。

  1. mkdir -p ~/toolchain/
  2. tar -jxvf gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 -C ~/toolchain/

设置环境变量。

vim ~/.bashrc

将以下命令拷贝到.bashrc文件的最后一行,保存并退出。

export PATH=~/toolchain/gcc-arm-none-eabi-10.3-2021.10/bin:PATH

生效环境变量。

source ~/.bashrc
  • 在命令行中输入如下命令,如果能正确显示编译器版本号,表明编译器安装成功。
arm-none-eabi-gcc -v
准备工程

本用例采用repo的方式从码云官仓下载系统系统源码以及开发板适配代码,使用git从gitee的sig仓库拉取设备应用代码。

配置git
  • 提前注册准备码云gitee账号。

  • git工具下载安装

    1. sudo apt install git
    2. sudo apt install git-lfs
  • 生成/添加SSH密钥:生成密钥

    使用gitee账号绑定的邮箱生成密钥对

    ssh-keygen -t ed25519 -C "[email protected]"
    
  • 查看生成的密钥

    cat ~/.ssh/id_ed25519.pub
    
  • 复制生成后的 ssh key,返回gitee个人主页,通过主页 「个人设置」->「安全设置」->「SSH 公钥」 ,将生成的“SSH密钥”添加到仓库中。

  • 配置git用户信息

    1. git config --global user.name "yourname"
    2. git config --global user.email "your-email-address"
    3. git config --global credential.helper store
准备repo
  1. sudo curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo
  2. chmod a+x /usr/local/bin/repo
  3. pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple requests
准备系统源码
  1. #特别注意:请下载OpenHarmony 3.1 Beta版本
  2. mkdir ~/OpenHarmony_3.1_Beta
  3. cd ~/OpenHarmony_3.1_Beta
  4. repo init -u [email protected]:openharmony/manifest.git -b refs/tags/OpenHarmony-v3.1-Beta --no-repo-verify
  5. repo sync -c
  6. repo forall -c 'git lfs pull'

注意:

  • 权限问题请参考生成/添加SSH公钥。

  • 若在已安装python3.8后,执行repo init 时,仍显示如下错误:

/usr/bin/env: ‘python’: No such file or directory

执行如下命令后,进行重试:

sudo ln -s /usr/bin/python3.8 /usr/bin/python
准备设备侧应用代码

使用git 命令下载

git clone [email protected]:openharmony-sig/knowledge_demo_smart_home.git --depth=1
编译前准备
  • 代码拷贝

team_x源码拷贝

  1. mkdir ~/OpenHarmony_3.1_Beta/vendor/team_x
  2. cp -rfa ~/knowledge_demo_smart_home/dev/team_x/smart_door_bell ~/OpenHarmony_3.1_Beta/vendor/team_x

common库拷贝

cp -rfa ~/knowledge_demo_smart_home/dev/team_x/common ~/OpenHarmony_3.1_Beta/vendor/team_x

iot_link库拷贝

cp -rfa ~/knowledge_demo_smart_home/dev/third_party/iot_link ~/OpenHarmony_3.1_Beta/third_party/
  • kernel/liteos_m 修改

步骤1、下载patch 地址

​ 点击上述链接进入浏览器,将该网页中内容全部复制。

​ 本地创建一个名为bes_kernle.patch文件,并将已经复制的内容粘贴到该文件中。

步骤2、 打上步骤1中的patch

  1. cd ~/OpenHarmony_3.1_Beta/kernel/liteos_m
  2. patch -p1 < bes_kernle.patch
  • device/soc/bestechnic 修改

步骤1、下载patch 地址

​ 点击上述链接进入浏览器,将该网页中内容全部复制。

​ 本地创建一个名为bes_device.patch文件,并将已经复制的内容粘贴到该文件中。

步骤2、 打上步骤1中的patch

  1. cd ~/OpenHarmony_3.1_Beta/device/soc/bestechnic
  2. patch -p1 < bes_device.patch
  • third_party/mbedtls 修改

参考如下代码段修改 mbedtls/library/platform.c

  1. diff --git a/library/platform.c b/library/platform.c
  2. index c4c3fd3..214173b 100755
  3. --- a/library/platform.c
  4. +++ b/library/platform.c
  5. @@ -86,9 +86,24 @@ static void platform_free_uninit( void *ptr )
  6. static void * (*mbedtls_calloc_func)( size_t, size_t ) = MBEDTLS_PLATFORM_STD_CALLOC;
  7. static void (*mbedtls_free_func)( void * ) = MBEDTLS_PLATFORM_STD_FREE;
  8. +#include "los_memory.h"
  9. +
  10. void * mbedtls_calloc( size_t nmemb, size_t size )
  11. {
  12. - return (*mbedtls_calloc_func)( nmemb, size );
  13. + //return (*mbedtls_calloc_func)( nmemb, size );
  14. + size_t real_size;
  15. + void *ptr = NULL;
  16. +
  17. + if (nmemb == 0 || size == 0) {
  18. + return NULL;
  19. + }
  20. +
  21. + real_size = (size_t)(nmemb * size);
  22. + ptr = LOS_MemAlloc(OS_SYS_MEM_ADDR, real_size);
  23. + if (ptr != NULL) {
  24. + (void)memset_s(ptr, real_size, 0, real_size);
  25. + }
  26. + return ptr;
  27. }

参考如下代码段修改 mbedtls/BUILD.gn

  1. diff --git a/BUILD.gn b/BUILD.gn
  2. index 9ecb37a..30dbb2e 100755
  3. --- a/BUILD.gn
  4. +++ b/BUILD.gn
  5. @@ -124,6 +124,7 @@ if (ohos_kernel_type == "liteos_m") {
  6. include_dirs = [
  7. "//kernel/liteos_m/kal/posix/include",
  8. "//kernel/liteos_m/kernel/include",
  9. "//kernel/liteos_m/utils",
  10. "//third_party/musl/porting/liteos_m/kernel/include/",
  11. + "//kernel/liteos_m/kernel/include/",
  12. ]
  13. }
  14. output_name = "mbedtls"
  • third_party/lwip 修改

修改src/api/netdb.c 文件

  1. diff --git a/src/api/netdb.c b/src/api/netdb.c
  2. index 52a6fdf..2043636 100644
  3. --- a/src/api/netdb.c
  4. +++ b/src/api/netdb.c
  5. @@ -100,7 +100,7 @@ lwip_gethostbyname(const char *name)
  6. err = netconn_gethostbyname(name, &addr);
  7. if (err != ERR_OK) {
  8. LWIP_DEBUGF(DNS_DEBUG, ("lwip_gethostbyname(%s) failed, err=%d\n", name, err));
  9. - h_errno = HOST_NOT_FOUND;
  10. + //h_errno = HOST_NOT_FOUND;
  11. return NULL;
  12. }
  • third_party/iot_link 修改

参考如下代码段修改 third_party/iot_link/network/dtls/BUILD.gn

  1. diff --git a/third_party/iot_link/network/dtls/BUILD.gn b/third_party/iot_link/network/dtls/BUILD.gn
  2. index 035805d709075ef2bc9d9388e73edb84dc1ee943..ac7256cf2bc93a0a998388f31910f152bf306fa9 100755
  3. --- a/third_party/iot_link/network/dtls/BUILD.gn
  4. +++ b/third_party/iot_link/network/dtls/BUILD.gn
  5. @@ -41,7 +41,8 @@ dtls_cflags = [
  6. "-Wno-unused-parameter",
  7. ]
  8. -static_library("dtls") {
  9. +#static_library("dtls") {
  10. +source_set("dtls") {
  11. cflags = dtls_cflags
  12. defines = dtls_def
  13. sources = dtls_src

参考如下代码段修改 third_party/iot_link/network/dtls/mbedtls/mbedtls_port/dtls_interface.c

  1. diff --git a/third_party/iot_link/network/dtls/mbedtls/mbedtls_port/dtls_interface.c b/third_party/iot_link/network/dtls/mbedtls/mbedtls_port/dtls_interface.c
  2. index 9f87c6fae041b17af4522d5d89114b69005a00be..73e406893a33385a9888a82cf6d1b3706a81387d 100755
  3. --- a/third_party/iot_link/network/dtls/mbedtls/mbedtls_port/dtls_interface.c
  4. +++ b/third_party/iot_link/network/dtls/mbedtls/mbedtls_port/dtls_interface.c
  5. @@ -56,6 +56,7 @@
  6. #include "dtls_interface.h"
  7. #include "mbedtls/net_sockets.h"
  8. #include "mbedtls/ssl_internal.h"
  9. +#include "mbedtls/platform.h"
  10. #include "cmsis_os2.h"
  11. #include "string.h"
  12. @@ -157,6 +158,7 @@ mbedtls_ssl_context *dtls_ssl_new(dtls_establish_info_s *info, char plat_type)
  13. #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
  14. if (info->psk_or_cert == VERIFY_WITH_PSK)
  15. {
  16. + #if 0
  17. if ((ret = mbedtls_ssl_conf_psk(conf,
  18. info->v.p.psk,
  19. info->v.p.psk_len,
  20. @@ -166,6 +168,7 @@ mbedtls_ssl_context *dtls_ssl_new(dtls_establish_info_s *info, char plat_type)
  21. MBEDTLS_LOG("mbedtls_ssl_conf_psk failed: -0x%x", -ret);
  22. goto exit_fail;
  23. }
  24. + #endif
  25. }
  26. #endif
  27. @@ -548,5 +551,5 @@ void dtls_init(void)
  28. {
  29. (void)mbedtls_platform_set_calloc_free(calloc, free);
  30. (void)mbedtls_platform_set_snprintf(snprintf);
  31. - (void)mbedtls_platform_set_printf(printf);
  32. + //(void)mbedtls_platform_set_printf(printf);
  33. }

参考如下代码段修改 third_party/iot_link/network/mqtt/BUILD.gn

  1. diff --git a/third_party/iot_link/network/mqtt/BUILD.gn b/third_party/iot_link/network/mqtt/BUILD.gn
  2. index 5a4a8e0ded129b91ce550a5d16f04e0784fddd45..d6bc39b8ede5735d79c74a6ab562c6141bd0b377 100755
  3. --- a/third_party/iot_link/network/mqtt/BUILD.gn
  4. +++ b/third_party/iot_link/network/mqtt/BUILD.gn
  5. @@ -16,6 +16,7 @@ mqtt_paho_inc = [
  6. "paho_mqtt/paho/MQTTPacket/src",
  7. "paho_mqtt/port",
  8. "../../inc",
  9. + "//third_party/musl/porting/liteos_m/kernel/include/",
  10. "//kernel/liteos_m/components/cmsis/2.0",
  11. "//vendor/hisi/hi3861/hi3861/third_party/lwip_sack/include/",
  12. ]
  13. @@ -50,7 +51,8 @@ mqtt_cflags = [
  14. "-Wno-unused-function",
  15. ]
  16. -static_library("mqtt") {
  17. +#static_library("mqtt") {
  18. +source_set("mqtt") {
  19. cflags = mqtt_cflags
  20. defines = mqtt_paho_defs
  21. sources = mqtt_paho_src

参考如下代码段修改 third_party/iot_link/network/mqtt/paho_mqtt/port/paho_mqtt_port.c

  1. diff --git a/third_party/iot_link/network/mqtt/paho_mqtt/port/paho_mqtt_port.c b/third_party/iot_link/network/mqtt/paho_mqtt/port/paho_mqtt_port.c
  2. index a213b74c7286c68061e3285c0c3ac6c440949f26..d0900c8d88149f08c93fe885f34f4d2affa30885 100755
  3. --- a/third_party/iot_link/network/mqtt/paho_mqtt/port/paho_mqtt_port.c
  4. +++ b/third_party/iot_link/network/mqtt/paho_mqtt/port/paho_mqtt_port.c
  5. @@ -180,6 +180,50 @@ static int __socket_read(void *ctx, unsigned char *buf, int len, int timeout)
  6. int fd;
  7. int ret = 0;
  8. +#if 1
  9. + int bytes = 0;
  10. + fd_set fdset;
  11. +
  12. + struct timeval timedelay = {timeout / 1000, (timeout % 1000) * 1000};
  13. + if(NULL== buf)
  14. + {
  15. + return ret;
  16. + }
  17. +
  18. + fd = (int)(intptr_t)ctx; ///< socket could be zero
  19. +
  20. + if (timedelay.tv_sec < 0 || (timedelay.tv_sec == 0 && timedelay.tv_usec <= 0))
  21. + {
  22. + timedelay.tv_sec = 0;
  23. + timedelay.tv_usec = 100;
  24. + }
  25. + timedelay.tv_sec = 5;
  26. + FD_ZERO(&fdset);
  27. + FD_SET(fd, &fdset);
  28. +
  29. + ret = select(fd + 1, &fdset, NULL, NULL, &timedelay);
  30. + printf("[%s|%s|%d]fd = %d, ret = %d\n", __FILE__,__func__,__LINE__, fd, ret);
  31. + if (ret > 0) {
  32. + while (bytes < len) {
  33. + int rc = recv(fd, &buf[bytes], (size_t)(len - bytes), 0);
  34. + printf("[%s|%s|%d]fd = %d, rc = %d\n", __FILE__,__func__,__LINE__, fd, rc);
  35. + if (rc == -1) {
  36. + if (errno != EAGAIN && errno != EWOULDBLOCK) {
  37. + bytes = -1;
  38. + }
  39. + break;
  40. + } else if (rc == 0) {
  41. + bytes = 0;
  42. + break;
  43. + } else {
  44. + bytes += rc;
  45. + }
  46. + }
  47. + }
  48. +
  49. + return bytes;
  50. +#else
  51. +
  52. struct timeval timedelay = {timeout / 1000, (timeout % 1000) * 1000};
  53. if(NULL== buf)
  54. {
  55. @@ -216,7 +260,7 @@ static int __socket_read(void *ctx, unsigned char *buf, int len, int timeout)
  56. }
  57. }
  58. return bytes;
  59. -
  60. + #endif
  61. }
  62. @@ -586,7 +630,7 @@ static void * __connect(mqtt_al_conpara_t *conparam)
  63. attr.cb_mem = NULL;
  64. attr.cb_size = 0U;
  65. attr.stack_mem = NULL;
  66. - attr.stack_size = 1024 * 2;
  67. + attr.stack_size = 1024 * 4;
  68. attr.priority = 28;
  69. cb->task = osThreadNew((osThreadFunc_t)__loop_entry, cb, &attr);
  70. if(NULL == cb->task)

参考如下代码段修改 third_party/iot_link/network/mqtt/paho_mqtt/port/paho_osdepends.h

  1. diff --git a/third_party/iot_link/network/mqtt/paho_mqtt/port/paho_osdepends.h b/third_party/iot_link/network/mqtt/paho_mqtt/port/paho_osdepends.h
  2. index 2c6cab1b90bef7be82891637c200cdb664e9735b..38e3dce3867d2b2d538858c72b36bee7330c7b4f 100755
  3. --- a/third_party/iot_link/network/mqtt/paho_mqtt/port/paho_osdepends.h
  4. +++ b/third_party/iot_link/network/mqtt/paho_mqtt/port/paho_osdepends.h
  5. @@ -84,6 +84,7 @@
  6. #include "ohos_init.h"
  7. #include "cmsis_os2.h"
  8. +#include "sys/time.h"
  9. #include <mqtt_al.h>
  10. #define MQTT_TASK 1
  11. @@ -117,6 +118,13 @@ typedef struct Thread
  12. int ThreadStart(Thread*, void (*fn)(void*), void* arg);
  13. +#define timeradd(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \
  14. + ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \
  15. + ((a)->tv_usec -= 1000000, (a)->tv_sec++) )
  16. +#define timersub(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec - (t)->tv_sec, \
  17. + ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \
  18. + ((a)->tv_usec += 1000000, (a)->tv_sec--) )
  19. +
  20. typedef struct Network
  21. {
  22. void *ctx; ///< if it is tls, then it is tls context, else it is socket fd

参考如下代码段修改 third_party/iot_link/oc_mqtt/BUILD.gn

  1. diff --git a/third_party/iot_link/oc_mqtt/BUILD.gn b/third_party/iot_link/oc_mqtt/BUILD.gn
  2. index c777c5e4f2e79646a5c76471f22c5437e9d4b3ee..1e3e07ddb6c0bc52465a60c415c8550608a21e55 100755
  3. --- a/third_party/iot_link/oc_mqtt/BUILD.gn
  4. +++ b/third_party/iot_link/oc_mqtt/BUILD.gn
  5. @@ -11,7 +11,8 @@
  6. # See the License for the specific language governing permissions and
  7. # limitations under the License.
  8. -static_library("oc_mqtt") {
  9. +#static_library("oc_mqtt") {
  10. +source_set("oc_mqtt") {
  11. sources = [
  12. "oc_mqtt_al/oc_mqtt_al.c",
  13. "oc_mqtt_profile_v5/oc_mqtt_profile.c",
  • communicationkit相关修改

参考下方代码修改foundation/ace/ace_engine_lite/frameworks/module_manager/ohos_module_config.h

  1. diff --git a/frameworks/module_manager/ohos_module_config.h b/frameworks/module_manager/ohos_module_config.h
  2. index f8eb744..3bb25d1 100644
  3. --- a/frameworks/module_manager/ohos_module_config.h
  4. +++ b/frameworks/module_manager/ohos_module_config.h
  5. @@ -47,6 +47,10 @@ extern void InitNativeApiFs(JSIValue exports);
  6. extern void InitNativeApiKv(JSIValue exports);
  7. #endif
  8. +#if (FEATURE_MODULE_COMMUNICATIONKIT == 1)
  9. +extern void InitNativeApiCommunicationKit(JSIValue exports);
  10. +#endif
  11. +
  12. #if (FEATURE_MODULE_DEVICE == 1)
  13. extern void InitDeviceModule(JSIValue exports);
  14. #endif
  15. @@ -98,11 +102,13 @@ const Module OHOS_MODULES[] = {
  16. #if (FEATURE_MODULE_DIALOG == 1)
  17. {"prompt", InitDialogModule},
  18. #endif // FEATURE_MODULE_DIALOG
  19. -
  20. #if (FEATURE_MODULE_STORAGE == 1)
  21. {"file", InitNativeApiFs},
  22. {"storage", InitNativeApiKv},
  23. #endif
  24. +#if (FEATURE_MODULE_COMMUNICATIONKIT == 1)
  25. + {"CommunicationKit", InitNativeApiCommunicationKit},
  26. +#endif
  27. #if (FEATURE_MODULE_DEVICE == 1)
  28. {"device", InitDeviceModule},
  29. #endif
  • flash_size配置修改

根据开发板的硬件版本不同,还需更改配置文件中flash_size的值。具体路径为/device/board/fnlink/v200zr/liteos_m/config.gni。其中v1.0版本对应16,2.0版本对应32,硬件版本打印在了开发板正面。

  1. diff --git a/v200zr/liteos_m/config.gni b/v200zr/liteos_m/config.gni
  2. index b288101..6489dd2 100644
  3. --- a/v200zr/liteos_m/config.gni
  4. +++ b/v200zr/liteos_m/config.gni
  5. @@ -47,7 +47,7 @@ if (product_path != "") {
  6. bsp_bin_list = product_conf.bsp_bin_list
  7. pack_burn = product_conf.pack_burn
  8. }
  9. -flash_size = 16
  10. +flash_size = 32
  • hdf配置文件修改

参考下方代码修改device/board/fnlink/shields/v200zr-evb-t1/v200zr-evb-t1.hcs

  1. diff --git a/shields/v200zr-evb-t1/v200zr-evb-t1.hcs b/shields/v200zr-evb-t1/v200zr-evb-t1.hcs
  2. index 44212eb..4fc99da 100644
  3. --- a/shields/v200zr-evb-t1/v200zr-evb-t1.hcs
  4. +++ b/shields/v200zr-evb-t1/v200zr-evb-t1.hcs
  5. @@ -17,12 +17,17 @@ root {
  6. platform {
  7. gpio_config {
  8. match_attr = "gpio_config";
  9. - pin = [0, 1];
  10. + pin = [0, 1, 2, 3, 4, 5, 6, 7];
  11. // touch_ztw523: TSP_RST - GPIO12, TSP_INT-GPIO27
  12. // touch_fts: TSP_RST - GPIO05, TSP_INT-GPIO27
  13. - realPin = [5, 27];
  14. - config = [5, 2];
  15. - pinNum = 2;
  16. + realPin = [5, 27, 1, 11, 15, 10, 14, 13];
  17. + config = [5, 2, 2, 4, 5, 5, 5, 2];
  18. + pinNum = 8;
  19. + }
  20. + pwm0_config{
  21. + match_attr = "pwm0_config";
  22. + pwmId = 0;
  23. + pwmPin = 20;
  24. }
  25. i2c_config {
  26. i2c0 {
  • gpio hdf框架相关修改。

根据下方代码修改drivers/adapter/platform/gpio/gpio_bes.c

  1. diff --git a/platform/gpio/gpio_bes.c b/platform/gpio/gpio_bes.c
  2. index ed4d18b..890d528 100755
  3. --- a/platform/gpio/gpio_bes.c
  4. +++ b/platform/gpio/gpio_bes.c
  5. @@ -257,7 +257,7 @@ static int32_t GpioDriverBind(struct HdfDeviceObject *device)
  6. }
  7. gpioCntlr.device.hdfDev = device;
  8. - device->service = gpioCntlr.device.service;
  9. + device->service = &(gpioCntlr.device);
  10. return HDF_SUCCESS;
  11. }
  • 将pwm_if.c纳入编译。

参考下方代码修改drivers\adapter\khdf\liteos_m\platform\BUILD.gn

  1. diff --git a/khdf/liteos_m/platform/BUILD.gn b/khdf/liteos_m/platform/BUILD.gn
  2. index 84c9152..8a4016a 100755
  3. --- a/khdf/liteos_m/platform/BUILD.gn
  4. +++ b/khdf/liteos_m/platform/BUILD.gn
  5. @@ -63,7 +63,10 @@ hdf_driver("hdf_platform_lite") {
  6. }
  7. if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_PWM)) {
  8. - sources += [ "HDF_FRAMEWORKS_PATH/support/platform/src/pwm/pwm_core.c" ]
  9. + sources += [
  10. + "HDF_FRAMEWORKS_PATH/support/platform/src/pwm/pwm_core.c" ]
  11. + sources += [
  12. + "HDF_FRAMEWORKS_PATH/support/platform/src/pwm/pwm_core.c",
  13. + "$HDF_FRAMEWORKS_PATH/support/platform/src/pwm/pwm_if.c",
  14. + ]
  15. }
  16. if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_RTC)) {
  • 将JS应用合入工程。

关于JS应用开发请参考从零开始学习L0: JS开发系列。本节为可选章节,忽略本节内容不影响智能门铃项目的展示和运行。但若想要在本项目的基础上进行涉及到显示的内容修改与新规开发,例如增加天气预报的图标,则需完整的阅读本节及链接内容。

  • 下载并安装DevEco Studio。

​

  • 打开js工程。

工程目录为:knowledge_demo_smart_home/dev/team_x/smart_door_bell/FA

​

  • 在DevEco Studio的SDK中添加@system.communicationkit.d.ts文件。

将@system.communicationkit.d.ts文件(源文件目录:~/knowledge_demo_smart_home/dev/interface/sdk-js/api/common/@system.communicationkit.d.ts)拷贝到在DevEco Studio的SDK中(目标目录:HarmonyOS Legacy SDK/js/3.0.0.0/api/common)。HarmonyOS Legacy SDK目录在DevEco Studio安装时,由用户配置,该目录位置可在设置(ctrl+alt+s)中查找。

​

  • 编译hap包。

依次选择构建 -> Build Hap(s)/APP(s) -> Build Hap(s)进行hap包编译,编译后的hap包目录为:FA\entry\build\outputs\hap\debug\entry-debug-lite-unsigned.hap。

​

  • 将js代码合入OpenHarmonySDK。

将entry-debug-lite-unsigned.hap修改后缀为zip并解压。在解压后的目录:entry-debug-lite-unsigned/assets/js/default目录中除app.js.map外的的数据全部拷贝到OpenHarmonySDK中的vendor/team_x/smart_door_bell/fs/data/data/js目录下。

工程效果

整合并修改完成后的代码目录结构如下图:

image-20211228205514766​

编译

编译命令:

hb set  // 如果是第一次编译,Input code path 命令行中键入"./" 指定OpenHarmony工程编译根目录后回车。

image-20211228205557170​

如下图所示,使用键盘上下键选中智能门铃 “smart_door_bell”(注:工程名字根据实际要编译的工程来):

​

hb build // 如果需要全量编译,可以添加-f 选项

编译通过,生成固件成功,如图:

image-20211228205659402​

烧录/安装
  • 安装CP2102驱动

  • 固件编译完成以后拷贝/out/v200zr/smart_door_bell/write_flash_gui文件夹到windows下,并点击Wifi_download_main.exe

​

  • 点击工具上的文件夹图标

​

  • 选择List按钮

​

  • 在显示出来的串口列表中选择需要烧录的串口,并点击开始按钮。

​

  • 在开发板上点击reset按键,或者重新上电。

​

  • 进入烧录状态

​

  • 烧录成功

​

​ 注意:固件烧录完成后需将烧录窗口关闭,再按下设备Reset键设备才能启动。如果未将烧录窗口关闭,设备会再次进行烧写状态。

操作体验
设备配网
  • 在设备上电前需准备好安装了数字管家应用的HarmonyOS手机, 并在设置中开启手机的NFC功能

  • 写设备NFC标签,详细操作见设备NFC标签指导文档;

  • 烧录完成后,上电。开发者在观察开发板上状态LED灯以1Hz的频率闪烁时,将手机上半部靠近开发板NFC标签处;

  • 手机将自动拉起数字管家应用并进入配网状态,根据手机提示连接到设备热点teamX-DoorBell01后返回数字管家APP,输入路由账号密码,点击确定后,手机将信息传输到设备侧,设备开始联网。

    ​

设备控制
  • 有陌生人靠近:

​

  • 有人按门铃:

​

  • 远程一键开门:

​

最后

小编在之前的鸿蒙系统扫盲中,有很多朋友给我留言,不同的角度的问了一些问题,我明显感觉到一点,那就是许多人参与鸿蒙开发,但是又不知道从哪里下手,因为体系杂乱无章,教授的人也多,无从选择。有很多小伙伴不知道学习哪些鸿蒙开发技术?不知道需要重点掌握哪些鸿蒙应用开发知识点?而且学习时频繁踩坑,最终浪费大量时间。所以有一份实用的鸿蒙(HarmonyOS NEXT)文档用来跟着学习是非常有必要的。 

为了确保高效学习,建议规划清晰的学习路线,涵盖以下关键阶段:

希望这一份鸿蒙学习文档能够给大家带来帮助~

GitCode - 全球开发者的开源社区,开源代码托管平台

​

鸿蒙NEXT全套学习资料
微信名片
注:本文转载自blog.csdn.net的让开,我要吃人了的文章"https://blog.csdn.net/weixin_55362248/article/details/142142615"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2024 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top