Developing a hardware plugin:修订间差异
(创建页面,内容为“=我应该创建一个 C++ 硬件插件吗?= 可能不需要.<br><br>Domoticz 支持 Python 插件框架,无论从保证 Domoticz 核心系统更小还是更专注...”) |
无编辑摘要 |
||
第7行: | 第7行: | ||
只有不能被 Python 框架很好兼容的硬件才需要增加 C++ 插件.<br> | 只有不能被 Python 框架很好兼容的硬件才需要增加 C++ 插件.<br> | ||
=在硬件目录创建一个 .cpp 和一个 .h 文件= | =在硬件目录创建一个 .cpp 和一个 .h 文件= | ||
Look at other plugins for a good sample, and rename the files and the classes and definitions inside the files. | Look at other plugins for a good sample, and rename the files and the classes and definitions inside the files. |
2018年8月2日 (四) 15:13的版本
我应该创建一个 C++ 硬件插件吗?
可能不需要.
Domoticz 支持 Python 插件框架,无论从保证 Domoticz 核心系统更小还是更专注等方面都应该使用 Python.
细节请参考这里: Developing a Python plugin
只有不能被 Python 框架很好兼容的硬件才需要增加 C++ 插件.
在硬件目录创建一个 .cpp 和一个 .h 文件
Look at other plugins for a good sample, and rename the files and the classes and definitions inside the files. e.g., for a Sonos hardware plugin, I modified these files:
- hardware/SonosPlugin.cpp
- hardware/SonosPlugin.h
Add the new hardware to the appropriate global files
Next we need to make domoticz aware of the new plugins existence.
main/RFXNames.h
Add HTYPE_SonosPlugin to _eHardwareTypes
main/RFXNames.cpp
Add HTYPE_SonosPlugin to Hardware_Type_Desc
main/mainworker.cpp
Add #include "../hardware/SonosPlugin.h" to the end of the includes for hardware
Add instantiation (new) of CSonosPlugin to case for AddHardwareFromParams method
main/WebServer.cpp
Add handling of HTYPE_SonosPlugin within Cmd_UpdateHardware to ensure that all required hardware settings have values. When adding serial devices add the HTYPE to the IsSerialDevice in main/RFXNames.cpp.
Add the UI to create the new hardware in the Hardware tab
www/app/HardwareController.js
Add the Hardware to the field verifications in UpdateHardware and AddHardware (look for text.indexOf("YourModelPlugin")).
Don't forget to also edit the RefreshHardwareTable function, where the hardware items are referred by numeric id!!! I'm assuming here that no extra configuration data for hardware is needed. If you need it, other plugins reuse the hardware available fields from the database:
Address VARCHAR(20), Port INTEGER, Username VARCHAR(100), Password VARCHAR(100), Mode1 - Mode5 CHAR
If you need to let the user edit this fields, create the corresponding Edit* function in HardwareController.js (use available ones as inspiration).
www/html5.appcache
Increment the ref number on the second line so that the browser knows the js file has been updated and to force a refresh of the hardware list.
Change the makefile
CMakeLists.txt
Add hardware/SonosPlugin.cpp to Target - Trick: While debugging, add it close to the top (issues will arrive earlier); later add it as the last hardware code target.
Add the needed specific libraries for linking. In this case (in gcc you would use the -llibname syntax):
pthread gupnp-1.0 gssdp-1.0 gupnp-av-1.0 glib-2.0 gobject-2.0 gthread-2.0
Add the needed specific headers/includes.
Build Makefile
You change that modifying the CMakeLists.txt and then creating a makefile
cmake CMakeLists.txt (raspberry) or cmake -DCMAKE_BUILD_TYPE=Release . (cubieboard)
You have to add to the makefile all the libraries and includes needed for your specific plugin. And maybe other compiler/linker options. (The syntax for CMake is tricky. I've just added what I needed in a quick and dirty way. There's for sure a better way to do that.)
Install any prerequisite packages
for raspbian: sudo apt-get install sometimes you need the -dev version, you never know!.
In this case I had to install this libraries. Check the name of the latest available version using "apt-cache search". libgupnp-1.0-dev libgupnp-av-1.0-dev libgssdp-1.0-dev libsoup2.4-dev libxml2 // libg glib