为硬件开发插件

来自Domoticz
跳转到导航 跳转到搜索

我需要用C++为硬件开发一个插件吗?

不需要。

Domoticz支持Python插件框架,请使用这个框架来保持核心Domoticz系统的尽可能小型化。

细节在这里: 开发Python插件

当硬件添加不适用于Python框架时,再通过C++开发。

在硬件目录中创建一个.cpp和一个.h文件 查看其他插件以获取良好示例,然后重命名文件以及文件中的文件和类和定义。 例如,对于Sonos硬件插件,我修改了这些文件:

  • hardware/SonosPlugin.cpp
  • hardware/SonosPlugin.h

将新硬件添加到适当的全局文件中

接下来我们需要让domoticz意识到新的插件存在.

main/RFXNames.h

将HTYPE_SonosPlugin添加到_eHardwareTypes

main/RFXNames.cpp

将HTYPE_SonosPlugin添加到Hardware_Type_Desc

main/mainworker.cpp

将#include“../ hardware / SonosPlugin.h”添加到硬件包含的末尾

添加CSonosPlugin的实例化(新)到AddHardwareFromParams方法的情况

main/WebServer.cpp

在Cmd_UpdateHardware中添加HTYPE_SonosPlugin的处理,以确保所有必需的硬件设置都具有值。添加串行设备时,将HTYPE添加到main / RFXNames.cpp中的IsSerialDevice。

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

Compile and have fun