当前位置:网站首页>Huawei cloud 14 day Hongmeng device development -day1 source code acquisition
Huawei cloud 14 day Hongmeng device development -day1 source code acquisition
2022-07-29 06:13:00 【Q-Stark】
Catalog
Preface
In the previous article, the environment was built , The next step is to do the code , First of all, we have to have the source code , And then in Windows Can open edit , Next, let's try .
First, give a few open source websites
Source source repository :https://gitee.com/openharmony
Device development learning website :https://device.harmonyos.com/cn/home
HPM Website :https://developer.harmonyos.com/cn/home/
One 、 Access to the source code
1. Source code acquisition method
1.1 Get... From the mirror site
Download compressed files from the image site , Then, as in the previous article , Create one code Catalog , Drag and drop the compressed file to unzip .
https://repo.huaweicloud.com/harmonyos/os/1.0/code-1.0.tar.gz
a. Create a code directory under the root directory
mkdir code # Create a file called code Folder
cd code/
ls
mkdir code_1
cd code_1/
ls# View the contents of the current directory
b. Directly from Windows Drag and drop in
c. Unzip to the current directory
tar -xvf code-1.0.tar.gz
It can also be in Linux The terminal enters the specified directory , Use wget Instruction get compressed package , Then perform the decompression operation .
1.2 from HPM Website component access
HPM Website :https://hpm.harmonyos.com/#/cn/home
Soft environment requirements :Linux Environmental installation 12.13.0+ Of Node.js
Therefore, the following installation should be carried out in this way
a. install Node.js
# download Nodejs
wget https://nodejs.org/dist/v14.15.1/node-v14.15.1-linux-x64.tar.xz
# decompression
tar -xvf node-v14.15.1-linux-x64.tar.xz-C ~/
# Use ln Command to set up the soft connection
sudo ln -s ~/node-v14.15.1-linux-x64/bin/npm /usr/bin/
sudo ln -s ~/node-v14.15.1-linux-x64/bin/node /usr/bin/
b. install hpm Command line tools
npm install -g @ohos/hpm-cli
sudo ln -s ~/node-v14.15.1-linux-x64/bin/hpm /usr/bin/
c. adopt hpm install Command to install components
stay Windows From the system HPM Choose the components you need on the website , And click to download directly , Then drag and drop Linux Under the specified directory of the virtual machine , Decompress and execute hpm Installation instructions for (hpm install), Will automatically download components and install . Drag and drop to unzip. Refer to the commands in the previous method .
cd code/
ls
mkdir code_2
cd code_2/
unzip demo.zip
cd demo/
hpm install
1.3 Use the package manager command line to get
Applicable scenario
- Users have obtained the source code through component acquisition , One or several components in the source code need to be upgraded independently .
- Users are already familiar with HarmonyOS Develop the system and master the use of command line tools .
This method also needs to install the tools in the second method .
For example, the obtained component name is @bearpi/bearpi_hm_nano, The specific operation is as follows :
1、 Enter the Development Directory , Execute the following command , Create a development project using the default template
cd code/
ls
mkdir code_3
cd code_3/
hpm init -t default
2、 Execute the following command , Installation of components @bearpi/bearpi_hm_nanohpm install @bearpi/bearpi_hm_nano
3、 The tool will automatically download all dependent components from the server , If the download is successful, it will display Installed.
from HPM When downloading components from the website, you can customize and add other component packages , The default dependent component package cannot be deleted .
1.4 Get from the code repository
download Harmony OS Source code
Before that, you need to register gitee account number , And configure the mailbox .
Source link :https://gitee.com/bearpi/bearpi-hm_nano
First in Linux Create a directory to store code .
stay Linux Execute the following commands under the terminal
git config --global user.name "yourname"
git config --global user.email “your-email-address"
git clone https://gitee.com/bearpi/bearpi-hm_nano.git -b master
Compile command
python build.py BearPi-HM_Nano
This is the easy way , I use this method . Note that you need to install git.
sudo apt install git
Two 、 stay Windows Open the project source code
Introduction to source directory 
1. Mapping project source code
at present HarmonyOS The source code only supports Linux Compile in the system , Can be Linux The project directory in the environment is mapped to Windows In the environment , And then use VS Code open , And in Windows Burning and debugging in the environment . This shared folder method requires samba. The mapping method is as follows :
1、 stay Linux On , Set up HarmonyOS The folder where the source code is located is a shared folder .
# install Samba
sudo apt-get install samba
# To configure Samba
sudo vim /etc/samba/smb.conf
# Add the following
[HarmonyOS_Code]
path = /home/YOUR_USER_NAME/code
available = yes
valid users = YOUR_USER_NAME
read only = no
browsable = yes
public = yes
writable = yes
# Set up Samba User name and password
sudo smbpasswd -a YOUR_USER_NAME
# restart samba service
sudo /etc/init.d/smbd restart
2. Import project source code
- stay Windows On , Right click “ This computer ”, choice “ Mapping network drives (N).
- Select an unused drive , And set up HarmonyOS Path of source code , The format is “\Linux IP Address \ Shared folder name ”, Such as :\192.168.0.224\HarmonyOS_Code, Click on “ complete ”.
3. Open the source code of the project
Double click to enter the shared folder , Directly drag and drop the corresponding directory to VS CODE You can open it in .
3、 ... and 、Hello World
1. To write Hello World Program
- newly added my_app Folder
stay./applications/BearPi/BearPi-HM_Nano/sampleCreate a new one under the pathmy_appCatalog , Used to store business source code files . - newly added hello_world.c file
stay./applications/BearPi/BearPi-HM_Nano/sample/my_appCreate a new one under the pathhello_world.cfile , This file is the business source code file . - newly added BUILD.gn file
stay./applications/BearPi/BearPi-HM_Nano/sample/my_appCreate a new one under the pathBUILD.gnfile , This file compiles the script for the business source code .
This step is a little similar to Cmake.
And then start writing code .
Business code
stayhello_world.cCreate a new business entry function inHello_World, And implement business logic . And at the bottom of the code , Use HarmonyOS Start the recovery module interfaceAPP_FEATURE_INIT()Start the business .(APP_FEATURE_INIT It's defined in ohos_init.h In file )
#include <stdio.h>
#include "ohos_init.h"
void Hello_World(void)
{
printf("Hello World!\r\n");
}
APP_FEATURE_INIT(Hello_World);
gn File code
instructions : Hi3861 The platform only supports libgcc Static links to runtime libraries , Developers are not recommended to use libgcc Dynamic link of runtime library , It will cause commercial distribution to be GPL V3 Pollution .
- Write a code for building a business into a static library BUILD.gn file
stay./applications/BearPi/BearPi-HM/sample/my_appUnder theBUILD.gnAdd the following code to the file .
static_library("myapp") {
sources = [
"hello_world.c"
]
include_dirs = [
"//utils/native/lite/include",
]
}
- static_library The compilation result of the specified business module in , For static library files
libmyapp.a, The developer shall fill in according to the actual situation . - sources Specify a static library in .a The dependent .c File and its path , If the path contains "//“ Absolute path ( Here is the code root path ), If it doesn't include ”//" Indicates the relative path .
- include_dirs It is specified in source What we need to rely on .h File path .
- Writing module BUILD.gn file , Specify the feature modules to be built .
stay./applications/BearPi/BearPi-HM/sampleUnder theBUILD.gnAdd the following code to the file .
- my_app Is a relative path , Point to ./applications/BearPi/BearPi-HM/sample/my_app/BUILD.gn.
- myapp Is the target , Point to ./applications/BearPi/BearPi-HM/sample/my_app/BUILD.gn Medium static_library(“myapp”).
2. Compiling and burning programs
Device manager check the board COM mouth

open HiBurn Change port , The baud rate is set to 921600
Select burn file

Check Auto burn, Click on connect, Press the development board reset Key , Start the download .

When the download is complete , Click on disconnect.
3. debugging
- stay Visual Studio Code Bottom , Click on “ A serial port ” Button icon .
- Enter the port number , Other parameters remain the default configuration .
- Press the development board RESET Key , Log information can be output .
边栏推荐
- Set automatic build in idea - change the code, and refresh the page without restarting the project
- 智慧能源管理系统解决方案
- PyTorch的数据读取机制
- 逻辑回归-项目实战-信用卡检测任务(下)
- Migration learning robot visual domain adaptation with low rank reconstruction
- 4、 Application of one hot and loss function
- 基于FPGA:多目标运动检测(手把手教学①)
- CS5340国产替代DP5340多比特音频 A/D 转换器
- Fasttext learning - text classification
- 一、Focal Loss理论及代码实现
猜你喜欢

1、 Focal loss theory and code implementation

一、迁移学习与fine-tuning有什么区别?

2022春招——芯动科技FPGA岗技术面(一面心得)

京微齐力:基于HMEP060的OLED字符显示(及FUXI工程建立演示)

预训练语言模型的使用方法

物联网倾斜监测解决方案

Wechat applet source code acquisition (download with tools)

基于STM32:情侣互动玩偶(设计方案+源码+3D图纸+AD电路)

Error in installing pyspider under Windows: Please specify --curl dir=/path/to/build/libcurl solution

一、常见损失函数的用法
随机推荐
Transfer feature learning with joint distribution adaptation
2022春招——上海安路FPGA岗面经(以及乐鑫SOC面试)
入门到入魂:单片机如何利用TB6600高精度控制步进电机(42/57)
Reading papers on fake news detection (2): semi supervised learning and graph neural networks for fake news detection
Wechat built-in browser prohibits caching
Hal library learning notes-14 ADC and DAC
一、multiprocessing.pool.RemoteTraceback
Model building in pytorch
ML6自学笔记
六、基于深度学习关键点的指针式表计识别
ML7自学笔记
1、 Usage of common loss function
华为云14天鸿蒙设备开发-Day1环境搭建
ABSA1: Attentional Encoder Network for Targeted Sentiment Classification
D3.js vertical relationship diagram (with arrows and text description of connecting lines)
ML4自学笔记
MySQL inserts millions of data (using functions and stored procedures)
一、迁移学习与fine-tuning有什么区别?
How to perform POC in depth with full flash distribution?
智能温度控制系统