anlory / ledhidl Goto Github PK
View Code? Open in Web Editor NEWhidl demo
hidl demo
hidl demo 1. 以控制LED为例进行demo的编写 1.1 编写led.hal 和types.hal 1.2 执行update-makefiles.sh 编译文件 新建defalut文件夹 1.3 实现[email protected]和[email protected] 编写android.bp cc_library_shared { name: "[email protected]", defaults: ["hidl_defaults"], relative_install_path: "hw", proprietary: true, srcs: ["Consumerled.cpp"], shared_libs: [ "libhidlbase", "libhidltransport", "libhardware", "liblog", "libutils", "[email protected]", ], } cc_binary { relative_install_path: "hw", defaults: ["hidl_defaults"], name: "[email protected]", proprietary: true, init_rc: ["[email protected]"], srcs: ["service.cpp"], shared_libs: [ "liblog", "libhardware", "libhidlbase", "libhidltransport", "libutils", "[email protected]", ], } 接下来,使用相应功能填写存根并设置守护进程。守护进程代码(支持直通)示例: #include <hidl/LegacySupport.h> int main(int /* argc */, char* /* argv */ []) { return defaultPassthroughServiceImplementation<INfc>("nfc"); } defaultPassthroughServiceImplementation 将对提供的 -impl 库执行 dlopen() 操作,并将其作为绑定式服务提供。守护进程代码(对于纯绑定式服务)示例: int main(int /* argc */, char* /* argv */ []) { sp nfc = new Nfc(); const status_t status = nfc->registerAsService(); if (status != ::android::OK) { return 1; // or handle error } // join pool or do other things } add the code to the manifest.xm 以至于hwservicemanager 查找到指定的hidl service About HIDL configures device/linaro/hikey/manifest.xml <hal format="hidl"> <name>android.hardware.led</name> <transport>hwbinder</transport> <version>1.0</version> <interface> <name>ILed</name> <instance>default</instance> </interface> </hal> 2. 实现java调用hidl service的例子 2.1 添加库: 将以下内容添加到 Android.mk 中: LOCAL_JAVA_LIBRARIES += android.hardware.foo-V1.0-java 或 将以下内容添加到 Android.bp 中: shared_libs: [ /* … */ "android.hardware.foo-V1.0-java", ], 该库还存在静态版:android.hardware.foo-V1.0-java-static。 2.2 将以下内容添加到您的 Java 文件中: import android.hardware.foo.V1_0.IFoo; ... // retry to wait until the service starts up if it is in the manifest IFoo server = IFoo.getService(true /* retry */); // throws NoSuchElementException if not available IFoo anotherServer = IFoo.getService("second_impl", true /* retry */); server.doSomething(…); 3. 实现C++ 调用hidl service的例子 首先将 HAL 库添加到 makefile 中: Make:LOCAL_SHARED_LIBRARIES += [email protected] Soong:shared_libs: [ …, [email protected] ] 接下来,添加 HAL 头文件: #include <android/hardware/nfc/1.0/IFoo.h> … // in code: sp<IFoo> client = IFoo::getService(); client->doThing(); 4. 编写LED驱动
绑定式HAL,java客户端调用Service和C++调用能传对象吗?
实现java调用hidl service的例子
2.1 添加库:
将以下内容添加到 Android.mk 中:
LOCAL_JAVA_LIBRARIES += android.hardware.foo-V1.0-java
或
将以下内容添加到 Android.bp 中:
shared_libs: [
/* … /
"android.hardware.foo-V1.0-java",
],
该库还存在静态版:android.hardware.foo-V1.0-java-static。
2.2 将以下内容添加到您的 Java 文件中:
import android.hardware.foo.V1_0.IFoo;
...
// retry to wait until the service starts up if it is in the manifest
IFoo server = IFoo.getService(true / retry /); // throws NoSuchElementException if not available
IFoo anotherServer = IFoo.getService("second_impl", true / retry */);
server.doSomething(…);
实现C++ 调用hidl service的例子
首先将 HAL 库添加到 makefile 中:
Make:LOCAL_SHARED_LIBRARIES += [email protected]
Soong:shared_libs: [ …, [email protected] ]
接下来,添加 HAL 头文件:
#include <android/hardware/nfc/1.0/IFoo.h>
…
// in code:
sp client = IFoo::getService();
client->doThing();
你好 能否留下联系方式,led.cpp作为client 他是直通式吗?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.