[编译] 6、开源两个简单且有用的安卓APP命令行开发工具和nRF51822命令行开发工具

星期四, 27. 九月 2018 12:00上午 - BEAUTIFULZZZZ

一、前言

前几天给大家介绍了如何手动搭建安卓APP命令行开发环境和nRF51822命令行开发环境,中秋这几天我把上面篇文章的操作流程全部做成了shell脚本,使得可以让其他人简单运行下脚本、就能够直接建立绿色开发环境,岂不美哉?


二、nrf_linux_tool开源项目介绍

2.1)项目简介

The project provides a nRF51 APP command-line development environment based on Linux system.

You can directly write、build、install APP(HEX/BIN) without using IDE.

git clone git@github.com:nbtool/nrf_linux_tool.git

2.2)如何使用

If it is the first time to compile, It is recommended to run goto tool directly, and then run the './run.sh tool' to download gcc、SDK、build-tools etc.

cd ./tool
./run.sh tool

Build the project(for example:app_nrf51_hids_keyboard):

cd ./app/app_nrf51_hids_keyboard/build
make clean
make all

Install the APP:

make erase
make flash_flash_softdevice
make flash

2.3)DEMO介绍

  • app_nrf51_peri_blinky > 简单工程,主要用nRF51的GPIO外设控制一个LED闪烁;
  • app_nrf51_ble_hrs > BLE工程,心律计,BLE DEMO级工程,展示心律、电池电量等特征;
  • app_nrf51_hids_mouse > BLE工程,蓝牙鼠标DEMO级工程,了解HID;
  • app_nrf51_hids_keyboard > BLE工程,蓝牙键盘DEMO级工程,按动按键给上位机发送hello;

2.4)工程结构介绍

未运行run.sh构建环境前的目录结构:(可见,当前app层只有4个简单的DEMO,tool里面只有一个run.sh脚本)

➜  nrf_linux_tool git:(master) tree -L 2
.
├── app
│   ├── app_nrf51_ble_hrs
│   ├── app_nrf51_hids_keyboard
│   ├── app_nrf51_hids_mouse
│   └── app_nrf51_peri_blinky
├── README.md
└── tool
    └── run.sh

构建之后的目录结构:(比未构建多了一个sdk/nRF5_SDK_12.3.0_d7731ad、gcc-arm编译器、和nRF5x命令行工具)

➜  nrf_linux_tool git:(master) tree -L 2
.
├── app
│   ├── app_nrf51_ble_hrs
│   ├── app_nrf51_hids_keyboard
│   ├── app_nrf51_hids_mouse
│   └── app_nrf51_peri_blinky
├── README.md
├── sdk
│   └── nRF5_SDK_12.3.0_d7731ad
└── tool
    ├── gcc-arm-none-eabi-5_4-2016q3
    ├── nRF5x-Command-Line-Tools_9_7_3
    └── run.sh

注: 之所以将SDK和GCC等工具通过构建产生,是为了减少git仓库的大小!


2.5)run.sh构建脚本介绍

run.sh脚本比较长,其最核心的在于tool函数,在该函数内是分别判断GCC、nRF5_Command_Lind、nRF5_SDK是否存在,如果不存在则下载:(以下载安装nRF5x command line tool为例)

echo "> install nRF5x command line tool ..."
if [ ! -d $NRF5X_COMMAND_LINE_PATH ]; then 
    pack=nRF5x-Command-Line-Tools_9_7_3_Linux-x86_64.tar
    wget  -O $pack $NRF5X_COMMAND_LINE_LINK
    mkdir $NRF5X_COMMAND_LINE_PATH
    tar -xvf $pack -C $NRF5X_COMMAND_LINE_PATH
    rm -rf $pack 
fi

特殊的,在博客《编译4》中介绍:SDK安装好之后需要更新/components/toolchain/gcc/Makefile.posix,这里我们也用脚本实现:

echo "> update the *.posix file, when the project root is changed ..."
t_arm_gcc_path=`pwd`/gcc-arm-none-eabi-5_4-2016q3
posix_file=$NRF5_SDK_12_3_0_PATH"/components/toolchain/gcc/Makefile.posix"
echo "GNU_INSTALL_ROOT := $t_arm_gcc_path" > $posix_file
echo "GNU_VERSION := 5.4.1" >> $posix_file
echo "GNU_PREFIX := arm-none-eabi" >> $posix_file

由于这里GNU_INSTALL_ROOT采用的是绝对路径,因此一旦整个工程的根目录发生变化,需要运行./run.sh tool更新posix文件。


2.6)典例DEMO介绍

BLE工程太过复杂,我们还是看看闪灯工程吧:

➜  app_nrf51_peri_blinky git:(master) tree
.
├── build
│   ├── blinky_gcc_nrf51.ld
│   ├── Makefile
│   ├── objects.mk
│   ├── sdk_config.h
│   └── sources.mk
└── main.c

其中main.c是唯一一个APP层代码文件,build目录下是一个简单的makefile框架,用来编译、烧写、擦除程序:

#include <stdbool.h>
#include <stdint.h>
#include "nrf_delay.h"
#include "boards.h"

/**
 * @brief Function for application main entry.
 */
int main(void)
{
    /* Configure board. */
    bsp_board_leds_init();

    /* Toggle LEDs. */
    while (true)
    {
	for (int i = 0; i < LEDS_NUMBER; i++)
	{
	    bsp_board_led_invert(i);
	    nrf_delay_ms(500);
	}
    }
}

注: APP中的4个DEMO是从SDK的example中移植上来的,改动比较小,后续会把更多DEMO移到APP里,并写博客介绍~


三、android_app_linux_tool开源项目介绍

3.1)项目简介

The project provides a Android APP command-line development environment based on Linux system.

You can directly write、build、install Android APP without using IDE.

git clone git@github.com:nbtool/android_app_linux_tool.git

3.2)如何使用

Enter the root directory of an example (for example: HelloAndroid).

If it is the first time to compile, It is recommended to run make tool to download platform、SDK、build-tools etc.

cd ./example/HelloAndroid
make tool

Build the project:

make build

Install the APP:

make program

3.3)DEMO介绍

第一个是hello world;第二个是蓝牙scan周边设备的信号强度;第三个是几年前做的一款小游戏:


3.4)工程结构介绍

类似上一个开源项目,未构建前只有DEMO:

➜  android_app_linux_tool git:(master) tree -L 3
.
├── example
│   ├── BluetoothScan
│   │   ├── run.sh
│   │   └── ...
│   ├── FlyGame  ...
│   └── HelloAndroid ...
└── readme.md

构建之后多了安卓SDK:

➜  android_app_linux_tool git:(master) tree -L 3
.
├── example
│   ├── BluetoothScan
│   │   ├── run.sh
│   │   └── ...
│   ├── FlyGame  ...
│   └── HelloAndroid ...
├── readme.md
└── tool
    └── android-sdk
	├── build-tools
	├── licenses
	├── platforms
	├── platform-tools
	└── tools

注: 安卓工程里的run.sh不是放在tool中,而是放在每个DEMO里面,因为每个DEMO所依赖的SDK和build工具的版本可能不一样!


3.5)run.sh构建脚本介绍

和上一个类似,tool函数用来下载相关SDK、编译工具、plantform-tool等,同时这里也把编译build、烧写program、和清除clean也集成进run.sh中了。真正用的时候是通过makefile调用run.sh实现:

➜  HelloAndroid git:(master) cat makefile 
tool:
	./run.sh tool
clean:
	./run.sh clean
build:
	./run.sh build
program:
	./run.sh program
all:
	./run.sh all

3.6)典例DEMO介绍

以Hello World为例:

➜  HelloAndroid git:(master) tree
.
├── AndroidManifest.xml
├── bin
├── libs
├── makefile
├── mykey.keystore
├── obj
├── res
│   ├── layout
│   │   └── activity_main.xml
│   └── values
│       └── strings.xml
├── run.sh
└── src
    └── com
	└── example
	    └── helloandroid
	        └── MainActivity.java

麻雀虽小、五脏俱全,该工程包含一个MainActivity.java文件、两个资源文件、一个Manifest.xml文件,最终生成的apk会存放到bin文件中。

同样的,今后我还会在Example中增加更多DEMO,并在博客中进行介绍。同时,也欢迎其他人来贡献DEMO ~

[1].nrf_linux_tool项目GITHUB地址
[2].android_app_linux_tool项目GITHUB地址
[3].在Linux下搭建nRF51822的开发烧写环境
[4].在Linux下搭建安卓APP的开发烧写环境

@beautifulzzzz
智能硬件、物联网,热爱技术,关注产品
博客:http://blog.beautifulzzzz.com
园友交流群:414948975
posted @ 2018-09-27 00:07  beautifulzzzz  阅读(1747)  评论(0编辑  收藏  举报