Cross-language communication method of internet of things gateway, gateway, device and storage medium
Patent Information
- Application Number
- CN202611171051.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-04
- Publication Date
- 2026-10-30
AI Technical Summary
[0004]有鉴于此,本公开提供了一种物联网网关的跨语言通信方法、网关、设备及存储介质,以解决相关物联网网关中的通信协议功能与网关程序耦合程度较高,且在网关侧编程语言与C++语言不同时,物联网网关难以调用和复用C++通信协议功能的问题
[0010]在本公开上述实施例的物联网网关的跨语言通信方法、网关、设备及存储介质中,通过在物联网网关中集成跨语言插件调用接口,并将不同通信协议对应的C++通信协议插件分别封装于相互独立的插件文件中,物联网网关能够根据目标通信协议的通信协议标识加载对应的插件文件并创建C++通信协议插件实例,使不同通信协议功能能够相互独立地接入物联网网关,降低通信协议功能与网关程序之间的耦合程度,提高物联网网关的协议扩展性和维护便利性。
Smart Images

Figure CN123020675A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of Internet of Things (IoT) platform technology, specifically to a cross-language communication method, gateway, device, and storage medium for an IoT gateway. Background Technology
[0002] IoT gateways are used to connect devices using different communication protocols. Existing IoT gateways typically use the same programming language as the gateway itself to develop communication protocol adaptation modules, which are then directly integrated into the gateway program. For example, the ThingsBoard gateway, implemented in Python, usually integrates a Python communication protocol adaptation module to support different communication protocols.
[0003] However, the above approach results in a high degree of coupling between the communication protocol adaptation module and the gateway program, making it difficult to independently extend and maintain the communication protocol. Furthermore, existing mature communication protocol libraries or implementations are primarily developed using C / C++, making it difficult to directly reuse corresponding communication protocol resources when the IoT gateway's implementation language differs from C++. Therefore, reducing the coupling between the communication protocol functionality and the IoT gateway, and enabling cross-language calls from the IoT gateway to C++ communication protocol functionality, has become a technical problem that needs to be solved. Summary of the Invention
[0004] In view of this, this disclosure provides a cross-language communication method, gateway, device and storage medium for IoT gateways, in order to solve the problem that the communication protocol function in related IoT gateways is highly coupled with the gateway program, and that it is difficult for IoT gateways to call and reuse C++ communication protocol functions when the programming language on the gateway side is different from C++.
[0005] This disclosure provides a cross-language communication method for an IoT gateway, the method being executed by the IoT gateway, the method comprising: Obtain the communication protocol identifier corresponding to the target communication protocol; The cross-language plugin calling interface integrated in the IoT gateway loads the corresponding plugin file according to the communication protocol identifier and creates a C++ communication protocol plugin instance in the plugin file. Different communication protocols correspond to different plugin files, and each plugin file is independent of the others. Each plugin file encapsulates a C++ communication protocol plugin that implements the C++ version plugin interface. The cross-language plugin calling interface includes a gateway-side interface implemented in the target programming language, which is different from C++. The gateway-side interface corresponds to the C++ version plugin interface. Through the cross-language plugin call interface, the call initiated by the IoT gateway through the gateway-side interface for the C++ communication protocol plugin instance is converted into a C++ interface call for the C++ version plugin interface; The C++ communication protocol plugin instance is invoked through the cross-language plugin call interface to communicate with a device that uses the target communication protocol.
[0006] This disclosure also provides an Internet of Things (IoT) gateway, including: Multiple plugin files, with different communication protocols corresponding to different plugin files. Each plugin file is independent of the others, and each plugin file encapsulates a C++ communication protocol plugin that implements the C++ version plugin interface. A cross-language plugin calling interface is integrated into the IoT gateway. The cross-language plugin calling interface includes a gateway-side interface implemented in a target programming language, which is different from C++. The gateway-side interface corresponds to the C++ version of the plugin interface. The protocol identifier acquisition module is used to acquire the communication protocol identifier corresponding to the target communication protocol; The plugin loading module is used to load the corresponding plugin file according to the communication protocol identifier through the cross-language plugin call interface, and create a C++ communication protocol plugin instance in the plugin file; The conversion module is used to convert the call initiated by the IoT gateway through the gateway-side interface for the C++ communication protocol plugin instance into a C++ interface call for the C++ version plugin interface through the cross-language plugin call interface. The communication module is used to call the C++ communication protocol plugin instance through the cross-language plugin call interface, so as to communicate with the device using the target communication protocol through the C++ communication protocol plugin instance.
[0007] This disclosure also provides an electronic device, including: a memory for storing a computer program; and a processor for executing the computer program to implement the steps of the cross-language communication method of any of the above-described Internet of Things gateways.
[0008] This disclosure also provides a computer-readable storage medium storing a computer program, wherein when executed by a processor, the computer program implements the steps of the cross-language communication method of any of the above-described IoT gateways.
[0009] This disclosure also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the cross-language communication method of any of the above-described Internet of Things gateways.
[0010] In the cross-language communication method, gateway, device, and storage medium of the IoT gateway in the above embodiments of this disclosure, by integrating a cross-language plugin calling interface into the IoT gateway and encapsulating the C++ communication protocol plugins corresponding to different communication protocols into mutually independent plugin files, the IoT gateway can load the corresponding plugin file and create a C++ communication protocol plugin instance according to the communication protocol identifier of the target communication protocol. This enables different communication protocol functions to be accessed by the IoT gateway independently, reduces the coupling between the communication protocol functions and the gateway program, and improves the protocol scalability and maintenance convenience of the IoT gateway.
[0011] By using cross-language plugin calling interfaces, calls initiated by IoT gateways through the gateway-side interface are converted into C++ interface calls targeting the C++ version of the plugin interface. This enables gateway-side interfaces implemented in target programming languages different from C++ to call C++ communication protocol plugins, thereby achieving cross-language access and reuse of C++ communication protocol functions by IoT gateways. This reduces the workload of repeatedly developing communication protocol functions using gateway-side programming languages and improves the access and development efficiency of communication protocols.
[0012] Furthermore, since different C++ communication protocol plugins all implement the aforementioned C++ plugin interface, the IoT gateway can load and call plugin instances corresponding to different communication protocols using a unified calling method. When adding, replacing, or updating communication protocols, deployment and maintenance can be performed on the corresponding plugin files, reducing modifications to the core program of the IoT gateway and facilitating the reuse of mature communication protocol resources developed based on C / C++. Attached Figure Description
[0013] To more clearly illustrate the embodiments of this disclosure, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0014] Figure 1 A flowchart illustrating a cross-language communication method for an IoT gateway provided in an embodiment of this disclosure; Figure 2 A schematic diagram of a specific cross-language communication architecture applied to the cross-language communication method of the Internet of Things gateway provided in this embodiment of the disclosure; Figure 3 This is a data interaction diagram illustrating a cross-language communication method for an IoT gateway provided in an embodiment of the present disclosure; Figure 4 A schematic diagram illustrating the class relationships of the C++ version plugin interface and the C++ communication protocol plugin provided in this embodiment of the disclosure; Figure 5This is a schematic diagram of the gateway-side class relationship when the target programming language is Python, as provided in the embodiments of this disclosure. Figure 6 This is a schematic diagram of the structure of an Internet of Things (IoT) gateway provided in an embodiment of this disclosure; Figure 7 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present disclosure. Detailed Implementation
[0015] The technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this disclosure.
[0016] In the description of this disclosure, the term "comprising" and its variations indicate open inclusion, that is, including the listed elements, but not excluding the inclusion of other elements. The terms "first," "second," etc., are used only to distinguish different objects and do not indicate that there is necessarily a sequential order between the objects.
[0017] In this disclosure, "IoT gateway" refers to a gateway program or a device that carries the gateway program, which is used to connect IoT platforms and devices and is capable of performing at least one function such as device access, data acquisition, message conversion, or control command issuance.
[0018] In this disclosure, "target programming language" refers to a programming language used on the gateway side that is different from C++ when the IoT gateway calls the C++ communication protocol plugin. In different implementations, the target programming language can be a programming language such as Python, Java, or C# that can call C++ programs through a cross-language calling mechanism.
[0019] The "cross-language plugin calling interface" in this disclosure refers to an interface layer set up between the IoT gateway and the C++ communication protocol plugin, used to convert calls initiated in the target programming language into C++ interface calls. The cross-language plugin calling interface includes at least a gateway-side interface for the IoT gateway to call, and may also include interface encapsulation code for completing parameter passing, data type conversion, return value conversion, object management, and callback conversion.
[0020] In this disclosure, "correspondence between the gateway-side interface and the C++ version plugin interface" can refer to a defined calling correspondence between methods in the gateway-side interface and methods in the C++ version plugin interface. The corresponding methods can have the same or corresponding functional semantics, and the conversion of parameter types, return value types, and calling forms is completed through the cross-language plugin calling interface. It is not required that the two interfaces use the same programming language syntax.
[0021] In this disclosure, "plugin files are independent" means that C++ communication protocol plugins corresponding to different communication protocols are encapsulated in separate plugin files. Replacing, loading, or unloading a plugin file does not require merging plugin files corresponding to other communication protocols into a single plugin file. The specific file format of the plugin files is not limited in the basic embodiment; dynamic link library files are one specific implementation form.
[0022] It should be noted that this disclosure first describes a basic cross-language calling scheme applicable to IoT gateways, and then describes further implementation methods such as dynamic link libraries, factory functions, SWIG encapsulation, plugin lifecycle, event callbacks, and data conversion. Each further implementation method is used to specifically limit the basic scheme in different directions, and does not mean that the basic scheme must simultaneously adopt all of the following further technical features.
[0023] In one embodiment, please refer to Figure 1 , Figure 1 This is a flowchart illustrating a cross-language communication method for an IoT gateway provided in an embodiment of this disclosure. The method may include the following steps: Step S101: Obtain the communication protocol identifier corresponding to the target communication protocol.
[0024] Specifically, the target communication protocol is the communication protocol used by the IoT gateway when it needs to communicate with the device.
[0025] Communication protocol identifiers are used to distinguish different communication protocols and to identify the plugin file corresponding to the target communication protocol.
[0026] Communication protocol identifiers can be obtained from the IoT gateway's device configuration, connector configuration, communication task configuration, or access request.
[0027] For example, if the target device is configured to use the IEC 104 protocol, the communication protocol identifier "Iec104" corresponding to the IEC 104 protocol can be obtained.
[0028] The communication protocol identifier can be a string, a number, or other information format that can uniquely or distinguishably represent the communication protocol. This disclosure does not limit the specific encoding method of the communication protocol identifier.
[0029] Step S102: Through the cross-language plugin call interface integrated in the IoT gateway, load the corresponding plugin file according to the communication protocol identifier, and create a C++ communication protocol plugin instance in the plugin file.
[0030] Specifically, different communication protocols correspond to different plugin files, and each plugin file is independent of the others.
[0031] Each plugin file encapsulates a C++ communication protocol plugin corresponding to the relevant communication protocol, and each C++ communication protocol plugin implements a pre-defined C++ plugin interface.
[0032] The C++ version of the plugin interface is used to define the interface used by IoT gateways when calling C++ communication protocol plugins.
[0033] C++ communication protocol plugins corresponding to different communication protocols provide communication functions with a consistent calling format to IoT gateways by implementing the same C++ plugin interface.
[0034] Cross-language plugin calling interfaces are integrated into IoT gateways, including gateway-side interfaces implemented in the target programming language.
[0035] The target programming language is different from C++, and the gateway-side interface corresponds to the C++ version of the plugin interface.
[0036] Therefore, IoT gateways can initiate plugin loading, instance creation, or plugin method calls through gateway-side interfaces expressed in the target programming language, without needing to directly call C++ communication protocol plugins using C++ syntax in the gateway business code.
[0037] The IoT gateway determines the corresponding plugin file based on the communication protocol identifier, initiates the plugin file loading operation through the cross-language plugin call interface, and creates an instance of the encapsulated C++ communication protocol plugin after the plugin file is loaded, thus obtaining the C++ communication protocol plugin instance corresponding to the target communication protocol.
[0038] It should be noted that in this embodiment, the specific file format of the plugin file and the specific method of creating the plugin instance are not limited, as long as the plugin files corresponding to different communication protocols are independent of each other and the corresponding plugin file can be loaded and the C++ communication protocol plugin instance can be created according to the communication protocol identifier.
[0039] Step S103: By using the cross-language plugin call interface, the call initiated by the IoT gateway through the gateway-side interface for the C++ communication protocol plugin instance is converted into a C++ interface call for the C++ version plugin interface.
[0040] Specifically, the IoT gateway initiates the call through the gateway-side interface implemented using the target programming language.
[0041] The cross-language plugin call interface determines the C++ interface corresponding to the method called in the gateway-side interface, and converts the parameters, return values or object references involved in the call process to form a C++ interface call that can be applied to the C++ communication protocol plugin instance.
[0042] For example, when the target programming language is Python, the IoT gateway can initiate a Python interface call. The cross-language plugin call interface converts Python objects, parameters, and method calls into corresponding C++ objects, parameters, and method calls.
[0043] When the target programming language is Java or C#, the conversion to C++ interface calls can also be completed through the gateway-side interface that matches the corresponding target programming language.
[0044] Step S104: Invoke the C++ communication protocol plugin instance through the cross-language plugin call interface to communicate with the device using the target communication protocol through the C++ communication protocol plugin instance.
[0045] Specifically, the IoT gateway calls a C++ communication protocol plugin instance through a cross-language plugin call interface, enabling the C++ communication protocol plugin instance to perform communication processing related to the target communication protocol.
[0046] C++ communication protocol plugin instances can establish or maintain communication connections with devices, receive device data, process device messages, or send control messages to devices.
[0047] In this process, the IoT gateway initiates a call to the gateway-side interface implemented in the target programming language, and the specific message sending and receiving and protocol processing of the communication protocol are completed by the corresponding C++ communication protocol plugin instance.
[0048] When changing the target communication protocol, the IoT gateway can load another corresponding plugin file based on the new communication protocol identifier, without having to directly write the specific implementations of different communication protocols into the core program of the IoT gateway.
[0049] In the cross-language communication method of the IoT gateway in the above embodiments of this disclosure, by integrating a cross-language plugin calling interface into the IoT gateway and encapsulating the C++ communication protocol plugins corresponding to different communication protocols into mutually independent plugin files, the IoT gateway can load the corresponding plugin file and create a C++ communication protocol plugin instance according to the communication protocol identifier of the target communication protocol. This enables different communication protocol functions to be accessed by the IoT gateway independently, reduces the coupling between the communication protocol functions and the gateway program, and improves the protocol scalability and maintenance convenience of the IoT gateway.
[0050] By using cross-language plugin calling interfaces, calls initiated by IoT gateways through the gateway-side interface are converted into C++ interface calls targeting the C++ version of the plugin interface. This enables gateway-side interfaces implemented in target programming languages different from C++ to call C++ communication protocol plugins, thereby achieving cross-language access and reuse of C++ communication protocol functions by IoT gateways. This reduces the workload of repeatedly developing communication protocol functions using gateway-side programming languages and improves the access and development efficiency of communication protocols.
[0051] Furthermore, since different C++ communication protocol plugins all implement the aforementioned C++ plugin interface, the IoT gateway can load and call plugin instances corresponding to different communication protocols using a unified calling method. When adding, replacing, or updating communication protocols, deployment and maintenance can be performed on the corresponding plugin files, reducing modifications to the core program of the IoT gateway and facilitating the reuse of mature communication protocol resources developed based on C / C++.
[0052] In one embodiment, step S102 above involves loading the corresponding plugin file based on the communication protocol identifier through the cross-language plugin call interface integrated in the IoT gateway, and creating a C++ communication protocol plugin instance in the plugin file, including: Step S1021: Dynamically load the dynamic link library file corresponding to the communication protocol identifier through the cross-language plugin call interface, and instantiate the C++ communication protocol plugin encapsulated in the dynamic link library file to obtain a C++ communication protocol plugin instance.
[0053] Specifically, the IoT gateway can determine the dynamic link library file corresponding to the target communication protocol based on the communication protocol identifier, and initiate the loading operation of the dynamic link library file through the cross-language plugin call interface.
[0054] Cross-language plugin calling interfaces can call the dynamic link library loading mechanism provided by the operating system or the encapsulated dynamic loading interface to load the corresponding dynamic link library file into the address space of the process where the IoT gateway is located.
[0055] Furthermore, after the dynamic link library file is loaded, the IoT gateway can call the plugin instantiation entry provided by the dynamic link library file through the cross-language plugin call interface, so that the C++ communication protocol plugin encapsulated in the dynamic link library file is instantiated, and a C++ communication protocol plugin instance implementing the C++ version plugin interface is obtained.
[0056] Furthermore, after obtaining a C++ communication protocol plugin instance, the IoT gateway can call the C++ version of the plugin interface implemented by the C++ communication protocol plugin instance through the cross-language plugin call interface, so that the C++ communication protocol plugin instance can perform communication processing corresponding to the target communication protocol.
[0057] Each plugin file is an independent dynamic link library file, and each dynamic link library file encapsulates a C++ communication protocol plugin that corresponds to a communication protocol and implements the C++ version plugin interface.
[0058] For example, the IEC 104 communication protocol and the IEC 61850 communication protocol can each correspond to different dynamic link library files.
[0059] The IEC 104 communication protocol dynamic link library file contains an IEC 104 communication protocol plugin that implements the C++ version of the plugin interface, and the IEC 61850 communication protocol dynamic link library file contains an IEC 61850 communication protocol plugin that implements the C++ version of the plugin interface.
[0060] Furthermore, each dynamic link library file can be stored, loaded, replaced, or updated separately, without needing to encapsulate C++ communication protocol plugins corresponding to different communication protocols into the same dynamic link library file.
[0061] In the cross-language communication method of the IoT gateway in the above embodiments of this disclosure, by encapsulating the C++ communication protocol plugins corresponding to different communication protocols into independent dynamic link library files, the IoT gateway can dynamically load the dynamic link library file corresponding to the target communication protocol according to the communication protocol identifier. This is beneficial for the independent deployment and updating of different communication protocol plugins and reduces the impact of changes in a single communication protocol plugin on the IoT gateway and other communication protocol plugins.
[0062] In one embodiment, step S1021 above involves dynamically loading the dynamic link library file corresponding to the communication protocol identifier through a cross-language plugin call interface, and instantiating the C++ communication protocol plugin encapsulated in the dynamic link library file to obtain a C++ communication protocol plugin instance, including: Step A1: Call the predefined factory function through the cross-language plugin call interface and pass the communication protocol identifier to the factory function.
[0063] Specifically, the factory function can serve as a shared entry point for creating multiple C++ communication protocol plugins. It is used to determine and load the dynamic link library file and create the corresponding C++ communication protocol plugin instance based on the passed communication protocol identifier.
[0064] The IoT gateway initiates factory function calls through the gateway-side interface implemented in the target programming language. The cross-language plugin call interface translates the factory function calls initiated by the gateway side into corresponding C++ function calls, and then passes the communication protocol identifier into a parameter form that the factory function can accept before passing it to the factory function.
[0065] Communication protocol identifiers can be in the form of strings, numbers, or enumeration values. For example, the communication protocol identifier corresponding to the IEC 104 communication protocol can be the string "Iec104".
[0066] Step A2: Based on the communication protocol identifier, dynamically load the corresponding dynamic link library file through the factory function.
[0067] Specifically, the factory function can determine the dynamic link library file corresponding to the communication protocol identifier based on the preset protocol mapping relationship.
[0068] Here, the protocol mapping relationship can be recorded in configuration files, internal lookup tables, or other mapping data structures, or it can be determined by the naming rules between the communication protocol identifier and the dynamic link library file name.
[0069] For example, the communication protocol identifier "Iec104" can be mapped to the dynamic link library file "libIec104Protocol.so", and the communication protocol identifier "Iec61850" can be mapped to the dynamic link library file "libIec61850Protocol.so".
[0070] After the factory function determines the dynamic link library file, it calls the dynamic link library loading interface provided by the operating system to load the dynamic link library file into the address space of the process where the IoT gateway resides.
[0071] For example, in Linux systems, dynamic link library files can be ".so" files; in Windows systems, dynamic link library files can be ".dll" files.
[0072] Step A3 involves calling the predefined creation function in the dynamic link library file through the factory function to obtain a C++ communication protocol plugin instance.
[0073] Specifically, the dynamic link library file can pre-configure a creation function for creating instances of the corresponding C++ communication protocol plugin.
[0074] After the dynamic link library file is loaded successfully, the factory function obtains the creation function through the dynamic symbol lookup interface and calls the creation function.
[0075] The creation function is used to instantiate the specific C++ communication protocol plugin class encapsulated in the dynamic link library file.
[0076] The specific C++ communication protocol plugin class implements the C++ version of the plugin interface, and the creation function returns the created specific C++ communication protocol plugin object as an object pointer or object reference of the C++ version of the plugin interface type.
[0077] For example, the dynamic link library file corresponding to the IEC 104 communication protocol may include a creation function "ProtocolCreate_Iec104". This creation function creates an object of the "Iec104Protocol" class and returns it as an object pointer to the C++ version of the plug-in interface "IProtocol".
[0078] In a specific example, the factory function can take the form of "IProtocol". ProtocolCreate(const char protocolName).
[0079] After receiving the communication protocol identifier, the factory function loads the corresponding dynamic link library file according to the communication protocol identifier, calls the creation function in the dynamic link library file, and returns the object returned by the creation function as a C++ communication protocol plugin instance to the cross-language plugin calling interface.
[0080] In the cross-language communication method of the IoT gateway in the above embodiments of this disclosure, the corresponding dynamic link library file is determined and loaded according to the communication protocol identifier by a predefined factory function, and then the creation function in the dynamic link library file is called to generate a C++ communication protocol plugin instance. This can shield the IoT gateway from the file names, specific plugin class names and instance creation process of different dynamic link library files, thereby reducing the coupling between the IoT gateway and the specific C++ communication protocol plugin.
[0081] In one embodiment, step S103 above, by using a cross-language plugin call interface, converts the call initiated by the IoT gateway through the gateway-side interface for the C++ communication protocol plugin instance into a C++ interface call for the C++ version plugin interface, including: Step S1031: The code encapsulates the code through the gateway-side interface to receive the call initiated by the IoT gateway for the C++ communication protocol plugin instance through the gateway-side interface.
[0082] Specifically, the gateway-side interface encapsulation code is represented in the target programming language and provides the IoT gateway with a gateway-side interface for calling C++ communication protocol plugin instances.
[0083] The IoT gateway can call the corresponding C++ interface in the C++ version of the plugin interface through the gateway-side interface, following the object call format of the target programming language.
[0084] The gateway-side interface encapsulation code receives calls initiated by the IoT gateway and obtains the corresponding method information, call parameters, and object reference information of the C++ communication protocol plugin instance.
[0085] For example, when the target programming language is Python, the gateway-side interface encapsulation code can include Python classes and corresponding Python methods. The IoT gateway initiates calls to the C++ communication protocol plugin instance by calling methods in the Python object.
[0086] Step S1032: Pass the call to the C++ interface encapsulation code corresponding to the gateway-side interface encapsulation code.
[0087] Specifically, there is a pre-established call correspondence between the gateway-side interface encapsulation code and the C++ interface encapsulation code.
[0088] After receiving a call initiated by the IoT gateway, the gateway-side interface encapsulation code passes the corresponding method information, call parameters, and object reference information to the C++ interface encapsulation code.
[0089] During the transmission process, the cross-language plugin call interface can convert object references in the target programming language into object identifiers or object pointer association information corresponding to the C++ communication protocol plugin instance, so that the C++ interface encapsulation code can determine the C++ communication protocol plugin instance targeted by this call.
[0090] Step S1033: Encapsulate the code through the C++ interface to convert the call into a C++ interface call for the C++ version of the plugin interface.
[0091] Specifically, the C++ interface encapsulation code determines the C++ interface corresponding to the gateway-side interface called by the IoT gateway based on the correspondence between the gateway-side interface and the C++ version of the plugin interface.
[0092] The C++ interface encapsulation code can convert the calling parameters in the target programming language into the corresponding C++ parameter types, and call the C++ interface implemented by the C++ communication protocol plugin instance based on the object pointer corresponding to the C++ communication protocol plugin instance.
[0093] When a C++ interface call generates a return value, the C++ interface encapsulation code can also convert the C++ return value into a return value that the target programming language can recognize, and then return it to the IoT gateway through the gateway-side interface encapsulation code.
[0094] The gateway-side interface is provided by the gateway-side interface encapsulation code, and the gateway-side interface in the gateway-side interface encapsulation code corresponds to the C++ interface in the C++ version plugin interface; the gateway-side interface encapsulation code and the C++ interface encapsulation code are generated by using the SWIG tool to encapsulate the C++ version plugin interface.
[0095] Specifically, SWIG can read the C++ header file or interface description file used to define the C++ version of the plugin interface, parse the classes, methods, parameter types and return value types in it, and generate the corresponding gateway-side interface encapsulation code and C++ interface encapsulation code according to the target programming language.
[0096] When the target programming language is Python, the gateway-side interface encapsulation code can include Python module code generated by SWIG; when the target programming language is Java or C#, the gateway-side interface encapsulation code can include Java interface encapsulation code or C# interface encapsulation code generated by SWIG respectively.
[0097] In the cross-language communication method of the IoT gateway in the above embodiments of this disclosure, the gateway-side interface encapsulation code receives calls initiated in the target programming language, and the corresponding C++ interface encapsulation code converts the calls into C++ interface calls for the C++ version of the plugin interface, enabling the IoT gateway to use the C++ communication protocol plugin according to the calling method of the target programming language. Using SWIG to generate corresponding interface encapsulation code reduces the workload of manually writing cross-language type conversion and call dispatch code.
[0098] In one embodiment, step S104 above, which involves calling a C++ communication protocol plugin instance through a cross-language plugin calling interface to communicate with a device using the target communication protocol, includes at least one of the following operations: Operation 1: Call the initialization method to initialize the C++ communication protocol plugin instance.
[0099] Specifically, the IoT gateway can call the initialization method implemented by the C++ communication protocol plugin instance through the cross-language plugin call interface, so that the C++ communication protocol plugin instance can perform the initialization process before communication.
[0100] Initialization processes may include reading configuration information related to the target communication protocol or target device, allocating operating resources, establishing internal data structures, or preparing connection parameters required for communication with the device.
[0101] In one specific embodiment, the initialization method may be named the "Init" method.
[0102] Operation 2: Call the callback setting method to set the event callback interface for the C++ communication protocol plugin instance.
[0103] Specifically, the IoT gateway can call the callback setting method implemented by the C++ communication protocol plugin instance through the cross-language plugin call interface, and pass the event callback interface used to receive plugin events to the C++ communication protocol plugin instance.
[0104] The C++ communication protocol plugin instance stores the correspondence between the event callback interface and the event handling object on the IoT gateway side, so that when the communication connection status changes or data arrives, the corresponding event is reported to the IoT gateway through the event callback interface.
[0105] In one specific implementation, the callback setting method can be named the "SetCallback" method.
[0106] Operation 3: Call the communication execution method to enable the C++ communication protocol plugin instance to perform communication tasks with the device.
[0107] Specifically, the IoT gateway can call the communication execution method implemented by the C++ communication protocol plugin instance through the cross-language plugin call interface, so that the C++ communication protocol plugin instance can start or continue to execute the communication task with the device.
[0108] Communication tasks can include at least one of the following: establishing or maintaining a communication connection, monitoring device data, receiving device messages, performing periodic data acquisition, and handling communication exceptions. Communication tasks can be executed in a separate thread, task, or event loop.
[0109] In one specific embodiment, the communication execution method may be named the "Communicate" method.
[0110] Operation 4: When issuing control commands to the device, call the control issuance method to pass the control message to the C++ communication protocol plugin instance.
[0111] Specifically, when an IoT gateway needs to control a device, the IoT gateway generates or obtains a control message based on the control task, and then calls the control delivery method implemented by the C++ communication protocol plugin instance through the cross-language plugin call interface to pass the control message to the C++ communication protocol plugin instance.
[0112] The C++ communication protocol plugin instance processes control messages according to the target communication protocol and sends the processed control messages to the device.
[0113] In one specific embodiment, the control delivery method can be named the "SendControl" method.
[0114] Operation 5: When the communication task is terminated, call the resource cleanup method to cause the C++ communication protocol plugin instance to perform resource cleanup.
[0115] Specifically, when the C++ communication protocol plugin instance is stopped, the communication task with the device is terminated, or the corresponding plugin file is uninstalled, the IoT gateway can call the resource cleanup method implemented by the C++ communication protocol plugin instance through the cross-language plugin call interface.
[0116] When a C++ communication protocol plugin instance responds to a call to a resource cleanup method, it stops the communication task and releases the resources it occupies, such as communication connections, threads, memory, or file handles.
[0117] In one specific embodiment, the resource cleanup method may be named the "Exit" method.
[0118] The C++ version of the plugin interface includes functional method interfaces corresponding to the initialization method, callback setting method, communication execution method, control distribution method, and resource cleanup method, as well as an event callback interface. The event callback interface includes a status change callback method for reporting communication connection status change events and a data arrival callback method for reporting data arrival events.
[0119] Specifically, the state change callback method can be used to report communication connection state change events such as connection establishment, connection disconnection, or reconnection. In a specific embodiment, the state change callback method can be named the "onConnectStateChanged" method.
[0120] The data arrival callback method can be used to report the data message to the IoT gateway after the C++ communication protocol plugin instance receives device data and forms a corresponding data message. In a specific embodiment, the data arrival callback method can be named the "onDataArrived" method.
[0121] It should be noted that the C++ version of the plugin interface can include all the above-mentioned functional method interfaces and event callback interfaces at the same time. However, during the execution of a specific method, the IoT gateway can call at least one of the above operations according to the current state of the C++ communication protocol plugin instance and the needs of the current communication task. It is not required that all methods be called again every time the method is executed.
[0122] For example, when the C++ communication protocol plugin instance has been initialized and is running continuously, the IoT gateway can call the control distribution method when performing a device control task, without needing to call the initialization method and communication execution method again in that device control task.
[0123] In the cross-language communication method of the IoT gateway in the above embodiments of this disclosure, by uniformly specifying the functional methods such as initialization, callback setting, communication execution, control distribution and resource cleanup, as well as the event callback methods such as state change and data arrival in the C++ version plugin interface, the IoT gateway can manage the C++ communication protocol plugins corresponding to different communication protocols in a consistent interface form, and complete the plugin lifecycle management and bidirectional event interaction.
[0124] In one embodiment, in operation 2 above, calling the callback setting method to set the event callback interface for the C++ communication protocol plugin instance includes: Step B1: Create a gateway-side callback object implemented in the target programming language. The gateway-side callback object includes callback implementation methods corresponding to the state change callback method and the data arrival callback method, respectively.
[0125] Specifically, the IoT gateway can define a callback implementation class using the target programming language and create a gateway-side callback object based on the callback implementation class.
[0126] The state change callback implementation method in the callback implementation class corresponds to the state change callback method in the C++ version plugin interface, and the data arrival callback implementation method corresponds to the data arrival callback method in the C++ version plugin interface.
[0127] IoT gateways can set communication status update, exception handling, or reconnection processing logic in the status change callback implementation method, and can set data reception, data verification, or data forwarding logic in the data arrival callback implementation method.
[0128] For example, when the target programming language is Python, the gateway-side callback object can be an instance of a callback implementation class implemented in Python; when the target programming language is Java or C#, the gateway-side callback object can be an instance of a callback implementation class implemented in Java or C# respectively.
[0129] Step B2: By calling the interface through the cross-language plugin, the gateway-side callback object is set as the event callback interface to the C++ communication protocol plugin instance.
[0130] Specifically, the IoT gateway calls the callback setting method of the C++ communication protocol plugin instance through the cross-language plugin call interface, and passes the gateway-side callback object to the cross-language plugin call interface.
[0131] The cross-language plugin call interface establishes a correspondence between the gateway-side callback object and the event callback interface in the C++ version plugin interface, enabling the gateway-side callback object to serve as the event receiving object when the C++ communication protocol plugin instance calls the event callback interface.
[0132] The C++ communication protocol plugin instance stores the configured event callback interfaces so that the corresponding event callback methods can be called when a change in the communication connection status is detected or when device data is received.
[0133] Furthermore, the method also includes: Step B3: In response to the C++ communication protocol plugin instance calling the event callback interface, the C++ callback call to the event callback interface is converted into a call to the corresponding callback implementation method in the gateway-side callback object through the cross-language plugin calling interface.
[0134] Specifically, when the C++ communication protocol plugin instance detects a change in the communication connection status with the device, the C++ communication protocol plugin instance calls the status change callback method in the event callback interface and passes in the corresponding connection status information.
[0135] The cross-language plugin call interface receives C++ callback calls for state change callback methods, converts the connection state information in C++ form into a data format that the target programming language can recognize, and calls the state change callback implementation method in the gateway-side callback object.
[0136] When the C++ communication protocol plugin instance receives device data and forms a data message, the C++ communication protocol plugin instance calls the data arrival callback method in the event callback interface and passes in the corresponding data message.
[0137] The cross-language plugin call interface receives C++ callback calls for the data arrival callback method, converts the C++ data message or object into a data format that the target programming language can recognize, and calls the data arrival callback implementation method in the gateway-side callback object.
[0138] In a specific implementation of using SWIG to generate cross-language plugin call interfaces, the gateway-side interface encapsulation code and C++ interface encapsulation code generated by SWIG can establish a reverse call channel between the C++ event callback interface and the gateway-side callback object, thereby forwarding the callback call initiated by the C++ communication protocol plugin instance to the gateway-side callback object implemented in the target programming language.
[0139] In the cross-language communication method of the IoT gateway in the above embodiments of this disclosure, by setting the gateway-side callback object implemented in the target programming language to the C++ communication protocol plugin instance, and converting the C++ callback call into a call to the gateway-side callback object, the C++ communication protocol plugin instance can proactively report communication connection status change events and data arrival events to the IoT gateway across programming language boundaries.
[0140] In one embodiment, step S104 above, which involves calling a C++ communication protocol plugin instance through a cross-language plugin call interface to communicate with a device using the target communication protocol, includes: Step S1041: Receive data messages reported by the C++ communication protocol plugin instance through the data arrival callback method.
[0141] Specifically, the C++ communication protocol plugin instance receives raw data packets reported by the device through the communication link between the device and the device. The raw data packets can be binary packets or text packets encoded according to the target communication protocol.
[0142] The C++ communication protocol plugin instance parses the raw data packets according to the target communication protocol to obtain structured data such as device identifiers, data points, time information, and data values contained in the raw data packets.
[0143] The C++ communication protocol plugin instance formats structured data into a data message format specified by the IoT gateway. The data message format specified by the IoT gateway may include device identifiers, timestamps, and one or more attribute values or telemetry values. For example, the data message may be in JSON format, but this disclosure is not limited to JSON format.
[0144] The C++ communication protocol plugin instance invokes the callback method when data arrives, reporting the formatted data message to the IoT gateway. The IoT gateway receives this callback call through the cross-language plugin call interface and obtains the data message reported by the C++ communication protocol plugin instance.
[0145] Therefore, the data message is a message obtained by parsing the raw data packets reported by the device into structured data according to the target communication protocol and formatting it into the data message format specified by the IoT gateway.
[0146] Step S1042: The control message is transmitted to the C++ communication protocol plugin instance through the control delivery method, so that the C++ communication protocol plugin instance assembles the control message into a control message that the device can recognize according to the target communication protocol, and then delivers the control message to the device.
[0147] Specifically, the IoT gateway generates or receives control messages for devices based on control tasks. These control messages may include control information such as the target device identifier, control point address, control type, and control value.
[0148] The IoT gateway invokes the control delivery method through the cross-language plugin calling interface and passes the control message to the C++ communication protocol plugin instance.
[0149] This C++ communication protocol plugin example parses control messages, obtains the target device and control content contained in the control message, and assembles the control content into a control message that the target device can recognize, according to the message structure, field format and encoding method specified by the target communication protocol.
[0150] The C++ communication protocol plugin example sends control messages to the target device through the communication link, enabling the target device to perform corresponding control operations based on the control messages.
[0151] It should be noted that this embodiment is a data communication implementation method based on the above-described plugin lifecycle implementation method, and is not necessarily bound to the specific implementation method of the aforementioned gateway-side callback object. The data arrival callback method can be implemented through the aforementioned gateway-side callback object, or it can be completed through other callback implementation methods that meet the requirements of the event callback interface.
[0152] In the cross-language communication method of the IoT gateway in the above embodiments of this disclosure, the original data packets of the device are parsed and converted into the data message format specified by the IoT gateway through a C++ communication protocol plugin instance, and the control messages of the IoT gateway are assembled into control messages that the device can recognize. This concentrates the message parsing, format conversion and message assembly processing related to the target communication protocol in the corresponding C++ communication protocol plugin, thereby reducing the coupling between the IoT gateway and the specific device communication protocol.
[0153] In one specific embodiment, please refer to Figure 2 , Figure 2 This diagram illustrates a specific cross-language communication architecture used in the cross-language communication method for the IoT gateway provided in this embodiment. In this embodiment, the target programming language is Python, the IoT gateway is a ThingsBoard gateway implemented in Python, the cross-language plugin call interface is generated using the SWIG tool, and each C++ communication protocol plugin is encapsulated in an independent dynamic link library file.
[0154] It should be noted that, Figure 2 The Python language, ThingsBoard gateway, SWIG tools, and dynamic link library files shown are all specific implementations of this disclosure and do not constitute a modification of the original work. Figure 1 The limitations of the basic embodiment shown.
[0155] like Figure 2 As shown, the architecture includes a Python gateway, a cross-language plugin calling interface, a C++ version plugin interface, and multiple C++ communication protocol plugins.
[0156] The Python gateway is a ThingsBoard gateway implemented in Python, used for device access, data processing, device management, and control command issuance. The Python gateway integrates a cross-language plugin interface and uses this interface to call C++ communication protocol plugins.
[0157] The cross-language plugin calling interface includes Python interface wrapper code and C++ interface wrapper code. The Python interface wrapper code provides the Python version of the plugin interface to the Python gateway, and the Python interface in the Python version of the plugin interface corresponds to the C++ interface in the C++ version of the plugin interface.
[0158] The Python gateway initiates a Python interface call to a C++ communication protocol plugin instance through the Python version plugin interface. The Python interface wrapper code receives this Python interface call and passes it to the C++ interface wrapper code. The C++ interface wrapper code converts the Python interface call into a C++ interface call for the C++ version plugin interface and passes the C++ interface call to the corresponding C++ communication protocol plugin instance.
[0159] In this embodiment, both the Python and C++ interface encapsulation codes are generated by the SWIG tool through encapsulating the C++ version of the plugin interface. The SWIG tool is used to generate the corresponding interface encapsulation code during the development phase, and the IoT gateway completes cross-language calls through the generated interface encapsulation code at runtime. Figure 2 In this context, SWIG represents the interface encapsulation relationship generated by SWIG, rather than the SWIG tool itself participating in the call processing during each runtime invocation.
[0160] The C++ version of the plugin interface specifies the common calling interface that different C++ communication protocol plugins must adhere to. Multiple C++ communication protocol plugins implement the C++ version of the plugin interface, thereby providing a unified calling method for the Python gateway.
[0161] Different communication protocols correspond to different C++ communication protocol plugins, and each C++ communication protocol plugin is encapsulated in an independent dynamic link library file. For example, C++ communication protocol plugin 1, C++ communication protocol plugin 2, and so on up to C++ communication protocol plugin N can be encapsulated in dynamic link library file 1, dynamic link library file 2, and so on up to dynamic link library file N, respectively.
[0162] Each C++ communication protocol plugin is used to implement communication processing such as connection management, message sending and receiving, message parsing, and control message assembly for a specific communication protocol. For example, multiple C++ communication protocol plugins can be used to implement IEC 104, IEC 61850, or other IoT communication protocols, respectively.
[0163] In the cross-language communication method of the IoT gateway in the above specific embodiments of this disclosure, the Python gateway converts Python interface calls into C++ interface calls through Python interface encapsulation code and C++ interface encapsulation code generated by SWIG, and calls the C++ communication protocol plugins encapsulated in independent dynamic link library files in a unified manner, thereby realizing cross-language calls between the Python gateway and the C++ communication protocol plugins and reducing the coupling between the Python gateway and the specific communication protocol implementation.
[0164] In one specific embodiment, please refer to Figure 3 , Figure 3 This is a schematic diagram of data interaction for a cross-language communication method of an IoT gateway provided in an embodiment of this disclosure. Figure 3 This illustrates the uplink data flow and downlink control flow between a Python gateway, a C++ communication protocol plugin instance, and devices when the target programming language is Python.
[0165] The uplink direction includes the reporting of communication connection status change events and the reporting of data messages.
[0166] During the reporting of communication connection status change events, the C++ communication protocol plugin instance detects the communication connection status with the device. When the communication connection status changes, the C++ communication protocol plugin instance calls the status change callback method to report the communication connection status change event. The cross-language plugin call interface converts the C++ callback call to the status change callback method into a call to the status change callback implementation method in the Python gateway-side callback object, enabling the Python gateway to obtain communication connection status change information.
[0167] Changes in communication connection status can include connection establishment, connection disconnection, reconnection, or connection error.
[0168] During the data message reporting process, the device first sends the raw data packet encoded according to the target communication protocol to the C++ communication protocol plugin instance.
[0169] The C++ communication protocol plugin example parses the raw data packets according to the target communication protocol, extracts structured data such as device identifiers, data points, time information, and data values from the raw data packets, and formats the structured data into the data message format specified by the Python gateway.
[0170] In this specific embodiment, the data message format specified by the Python gateway can be JSON format. This JSON format data message may include a device identifier, a timestamp, and one or more attribute values or telemetry values.
[0171] The C++ communication protocol plugin instance invokes the data arrival callback method to report formatted data messages. The cross-language plugin call interface converts the C++ callback call to the data arrival callback method into a call to the data arrival callback implementation method in the Python gateway-side callback object, enabling the Python gateway to receive the data messages reported by the C++ communication protocol plugin instance.
[0172] It should be noted that the C++ communication protocol plugin instance reports data messages through the data arrival callback method and reports communication connection status change events through the status change callback method. The two callbacks are used to transmit different types of information.
[0173] During the downlink control process, the Python gateway generates or retrieves control messages based on the device control task. In this specific embodiment, the control messages can be in JSON format and may include control information such as the target device identifier, control point address, control type, and control value.
[0174] The Python gateway calls the control delivery method of the C++ communication protocol plugin instance through the cross-language plugin call interface, and passes control messages to the C++ communication protocol plugin instance.
[0175] This C++ communication protocol plugin instance parses control messages, obtains the target device and control content, and assembles the control messages into a control message that the device can recognize, according to the message structure and encoding method specified by the target communication protocol. Subsequently, the C++ communication protocol plugin instance sends the control message to the target device through the communication link.
[0176] In the cross-language communication method of the IoT gateway in the above specific embodiments of this disclosure, the C++ communication protocol plugin instance parses and converts the original data packets reported by the device, and performs protocol assembly on the control messages issued by the Python gateway, so that the data processing related to the target communication protocol is concentrated in the C++ communication protocol plugin, thereby reducing the coupling between the Python gateway and the specific device communication protocol.
[0177] In one specific embodiment, please refer to Figure 4 , Figure 4 This diagram illustrates the class relationships of the C++ plugin interface and C++ communication protocol plugin provided in this embodiment of the disclosure. Figure 4As shown, the C++ version of the plugin interface includes the communication protocol base class IProtocol and the callback base class IProtocolCallback.
[0178] The base class IProtocol for communication protocols defines the functional method interfaces that are commonly implemented by different C++ communication protocol plugins, including the initialization method Init, the callback setting method SetCallback, the communication execution method Communicate, the control delivery method SendControl, and the resource cleanup method Exit.
[0179] The initialization method `Init` is used to initialize the C++ communication protocol plugin instance.
[0180] The `SetCallback` method is used to set the event callback interface for a C++ communication protocol plugin instance. `IProtocol` can store a pointer `m_cb` to an `IProtocolCallback` object, so that the C++ communication protocol plugin instance can invoke the event callback interface when the corresponding event occurs.
[0181] The Communicate method is used to enable a C++ communication protocol plugin instance to perform communication tasks with the device.
[0182] The SendControl method is used to receive control messages from the IoT gateway and enable the C++ communication protocol plugin instance to send control messages to the device according to the corresponding communication protocol.
[0183] The Exit method is used to perform resource cleanup when a communication task ends or a plugin exits.
[0184] The callback base class IProtocolCallback is used to define event callback interfaces, including the state change callback method onConnectStateChanged and the data arrival callback method onDataArrived.
[0185] The `onConnectStateChanged` callback method is used to report communication connection state changes between the C++ communication protocol plugin instance and the device. The `onDataArrived` callback method is used to report data messages obtained by the C++ communication protocol plugin instance based on the device's original data packets.
[0186] Figure 4The Iec104Protocol and Iec61850Protocol classes shown are specific C++ communication protocol plugin classes. The Iec104Protocol and Iec61850Protocol classes inherit from and implement the communication protocol base class IProtocol, thereby implementing the various functional methods specified in IProtocol.
[0187] The Iec104Protocol class can encapsulate the communication processing logic corresponding to the IEC 104 communication protocol, and the Iec61850Protocol class can encapsulate the communication processing logic corresponding to the IEC 61850 communication protocol.
[0188] In one specific implementation, the Iec104Protocol or Iec61850Protocol classes can internally call a communication protocol library implemented in C language to perform specific message parsing or message assembly processing. In this case, the C++ communication protocol plugin is still the one that implements the IProtocol interface externally and is called by the IoT gateway.
[0189] Different specific C++ communication protocol plugin classes provide a consistent functional method interface to the IoT gateway by implementing the same communication protocol base class IProtocol, thereby enabling the IoT gateway to call different C++ communication protocol plugins in a unified manner through cross-language plugin call interfaces.
[0190] In one specific embodiment, please refer to Figure 5 , Figure 5 This is a schematic diagram of the gateway-side class relationships when the target programming language is Python, as provided in the embodiments of this disclosure. Figure 5 As shown, the gateway-side classes include the connector base class Connector, the protocol connector subclass ProtocolConnector, the Python version of the IProtocol proxy class generated by SWIG, the Python version of the IProtocolCallback callback interface class generated by SWIG, and the gateway-side callback implementation subclass ProtocolConnectorCallback.
[0191] The Connector base class can be the original base class in the ThingsBoard gateway framework used to define the basic functions of the connector.
[0192] The ProtocolConnector subclass inherits from the Connector base class and is integrated into the ThingsBoard gateway as a connector for calling C++ communication protocol plugins.
[0193] The Protocol Connector subclass holds a member comm, which is an object of the Python version of the IProtocol proxy class generated by SWIG and corresponds to the created C++ communication protocol plugin instance.
[0194] The Protocol Connector subclass calls the corresponding Python method in the Python version of the IProtocol proxy class through the member `comm`. The cross-language plugin call interface translates this Python method call into a call to the corresponding C++ method in the C++ version of the plugin interface, thereby invoking the corresponding C++ communication protocol plugin instance.
[0195] The Python version of the IProtocolCallback callback interface class is a gateway-side callback interface class generated by SWIG based on the C++ version of the event callback interface. It includes Python methods corresponding to the state change callback method and the data arrival callback method, respectively.
[0196] The gateway-side callback implementation subclass ProtocolConnectorCallback inherits from the Python version of the IProtocolCallback callback interface class and implements the onConnectStateChanged method corresponding to the state change callback method and the onDataArrived method corresponding to the data arrival callback method.
[0197] The ProtocolConnectorCallback object constitutes the gateway-side callback object implemented in the target programming language. The ProtocolConnector subclass sets the ProtocolConnectorCallback object as an event callback interface to the C++ communication protocol plugin instance through the cross-language plugin call interface.
[0198] When a C++ communication protocol plugin instance calls a state change callback method or data arrives at a callback method, the cross-language plugin calling interface will convert the C++ callback call to the C++ event callback interface into a call to the corresponding Python callback implementation method in the ProtocolConnectorCallback object.
[0199] Thus, the ProtocolConnector subclass, on the one hand, makes forward calls to the C++ communication protocol plugin instance through the Python version of the IProtocol proxy class, and on the other hand, receives the reverse callback initiated by the C++ communication protocol plugin instance through the ProtocolConnectorCallback object, thereby forming a bidirectional cross-language call relationship between the Python ThingsBoard gateway and the C++ communication protocol plugin.
[0200] In one embodiment, an Internet of Things (IoT) gateway 600 is provided, which corresponds to the cross-language communication method of the IoT gateway in the above embodiments. For example... Figure 6 As shown, the IoT gateway 600 includes: Multiple plugin files 610, with different communication protocols corresponding to different plugin files 610. Each plugin file 610 is independent of the others, and each plugin file 610 encapsulates a C++ communication protocol plugin that implements the C++ version plugin interface. The cross-language plugin calling interface 620 is integrated into the IoT gateway 600. The cross-language plugin calling interface 620 includes a gateway-side interface implemented in the target programming language, which is different from C++. The gateway-side interface corresponds to the C++ version of the plugin interface. The protocol identifier acquisition module 601 is used to acquire the communication protocol identifier corresponding to the target communication protocol; The plugin loading module 602 is used to load the corresponding plugin file 610 according to the communication protocol identifier through the cross-language plugin call interface 620, and create a C++ communication protocol plugin instance in the plugin file 610. The conversion module 603 is invoked to convert the call initiated by the IoT gateway 600 through the gateway-side interface for the C++ communication protocol plugin instance into a C++ interface call for the C++ version plugin interface through the cross-language plugin call interface 620. The communication module 604 is used to call the C++ communication protocol plugin instance through the cross-language plugin call interface 620, so as to communicate with the device using the target communication protocol through the C++ communication protocol plugin instance.
[0201] In one embodiment, each plugin file 610 is an independent dynamic link library file, and each dynamic link library file encapsulates a C++ communication protocol plugin that corresponds to a communication protocol and implements the C++ version plugin interface. The plugin loading module 602 is specifically used to dynamically load the dynamic link library file corresponding to the communication protocol identifier through the cross-language plugin call interface 620, and instantiate the C++ communication protocol plugin encapsulated in the dynamic link library file to obtain a C++ communication protocol plugin instance.
[0202] In one embodiment, the plug-in loading module 602 is specifically used for: The predefined factory function is invoked through the cross-language plugin call interface 620, and the communication protocol identifier is passed to the factory function. Based on the communication protocol identifier, the corresponding dynamic link library file is dynamically loaded through the factory function; The C++ communication protocol plugin instance is obtained by calling the predefined creation function in the dynamic link library file through the factory function.
[0203] In one embodiment, calling the conversion module 603 is specifically used for: The code encapsulates the gateway-side interface to receive calls initiated by the IoT gateway 600 for the C++ communication protocol plugin instance through the gateway-side interface; The call is passed to the C++ interface encapsulation code corresponding to the gateway-side interface encapsulation code; The code is encapsulated through a C++ interface, converting the calls into C++ interface calls targeting the C++ version of the plugin interface; The gateway-side interface is provided by the gateway-side interface encapsulation code, and the gateway-side interface in the gateway-side interface encapsulation code corresponds to the C++ interface in the C++ version plugin interface; the gateway-side interface encapsulation code and the C++ interface encapsulation code are generated by using the SWIG tool to encapsulate the C++ version plugin interface.
[0204] In one embodiment, the communication module 604 is specifically used to perform at least one of the following operations: The initialization method is called to initialize the C++ communication protocol plugin instance; Call the callback setting method to set the event callback interface for the C++ communication protocol plugin instance; Invoke the communication execution method to enable the C++ communication protocol plugin instance to perform communication tasks with the device; When a control command is issued to the device, the control issuance method is invoked to pass the control message to the C++ communication protocol plugin instance; When the communication task ends, the resource cleanup method is invoked to cause the C++ communication protocol plugin instance to perform resource cleanup. The C++ version of the plugin interface includes functional method interfaces corresponding to the initialization method, callback setting method, communication execution method, control distribution method, and resource cleanup method, as well as an event callback interface. The event callback interface includes a status change callback method for reporting communication connection status change events and a data arrival callback method for reporting data arrival events.
[0205] In one embodiment, when the communication module 604 calls the callback setting method to set the event callback interface for the C++ communication protocol plugin instance, it is specifically used for: Create a gateway-side callback object implemented in the target programming language. The gateway-side callback object includes callback implementation methods corresponding to the state change callback method and the data arrival callback method, respectively. By calling interface 620 through the cross-language plugin, the gateway-side callback object is set as the event callback interface to the C++ communication protocol plugin instance; The cross-language plugin call interface 620 is also used to respond to the C++ communication protocol plugin instance call event callback interface, converting the C++ callback call to the event callback interface into a call to the corresponding callback implementation method in the gateway-side callback object.
[0206] In one embodiment, the communication module 604 is specifically used for: The data arrival callback method receives data messages reported by the C++ communication protocol plugin instance. The data message is the message obtained by the C++ communication protocol plugin instance parsing the raw data packets reported by the device into structured data according to the target communication protocol and formatting it into the data message format specified by the IoT gateway 600. By using the control delivery method, control messages are passed to the C++ communication protocol plugin instance, so that the C++ communication protocol plugin instance assembles the control messages into control messages that the device can recognize according to the target communication protocol, and then delivers the control messages to the device.
[0207] It should be noted that the above embodiments are only illustrative examples of the division into protocol identifier acquisition module 601, plug-in loading module 602, call conversion module 603, and communication module 604. In practical applications, the above processing can be assigned to different program modules as needed, that is, the internal structure of the IoT gateway 600 can be divided into different program modules to complete all or part of the processing described above. Furthermore, the above-mentioned IoT gateway 600 and... Figure 1 The method embodiments shown belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.
[0208] This disclosure also provides an electronic device for performing the cross-language communication method of the above-described Internet of Things gateway.
[0209] Figure 7 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present disclosure.
[0210] The following is a detailed reference. Figure 7The diagram illustrates a structural schematic suitable for implementing an electronic device according to embodiments of the present disclosure. The electronic device may include a processor (e.g., a central processing unit, graphics processor, etc.) 701, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 702 or a program loaded from memory 708 into random access memory (RAM) 703. The RAM 703 also stores various programs and data required for the operation of the electronic device. The processor 701, ROM 702, and RAM 703 are interconnected via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0211] Typically, the following devices can be connected to I / O interface 705: input devices 706 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 707 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; memory devices 708 including, for example, magnetic tapes, hard disks, etc.; and communication devices 709. Communication device 709 allows electronic devices to exchange data via wireless or wired communication with other devices. Although Figure 7 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown, and more or fewer devices may be implemented or have instead.
[0212] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication device 709, or installed from memory 708, or installed from ROM 702. When the computer program is executed by processor 701, it performs the functions defined in the cross-language communication method for an IoT gateway according to embodiments of this disclosure.
[0213] Figure 7 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.
[0214] This disclosure also provides a computer-readable storage medium in which the methods described in this disclosure can be implemented in hardware or firmware, or implemented as recordable on a storage medium, or implemented as computer code originally stored on a remote storage medium or a non-transitory machine-readable storage medium and subsequently stored on a local storage medium after being downloaded over a network. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium may also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code. When the software or computer code is accessed and executed by the computer, processor, or hardware, the cross-language communication method of the IoT gateway shown in the above embodiments is implemented.
[0215] A portion of this disclosure can be applied to computer program products, such as computer program instructions, which, when executed by a computer, can invoke or provide methods and / or technical solutions according to this disclosure through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, and installation package files. Accordingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions; the computer compiling the instructions and then executing the corresponding compiled program; the computer reading and executing the instructions; or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.
[0216] Although embodiments of the present disclosure have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the present disclosure, and such modifications and variations all fall within the scope defined by the appended claims.
Claims
1. A cross-language communication method for an Internet of Things (IoT) gateway, characterized in that, The method is executed by an IoT gateway, and the method includes: Obtain the communication protocol identifier corresponding to the target communication protocol; The cross-language plugin calling interface integrated in the IoT gateway loads the corresponding plugin file according to the communication protocol identifier and creates a C++ communication protocol plugin instance in the plugin file. Different communication protocols correspond to different plugin files, and each plugin file is independent of the others. Each plugin file encapsulates a C++ communication protocol plugin that implements the C++ version plugin interface. The cross-language plugin calling interface includes a gateway-side interface implemented in the target programming language, which is different from C++. The gateway-side interface corresponds to the C++ version plugin interface. Through the cross-language plugin call interface, the call initiated by the IoT gateway through the gateway-side interface for the C++ communication protocol plugin instance is converted into a C++ interface call for the C++ version plugin interface; The C++ communication protocol plugin instance is invoked through the cross-language plugin call interface to communicate with a device that uses the target communication protocol.
2. The method according to claim 1, characterized in that, The step of loading the corresponding plugin file according to the communication protocol identifier and creating a C++ communication protocol plugin instance in the plugin file through the cross-language plugin call interface integrated in the IoT gateway includes: The cross-language plugin calling interface dynamically loads the dynamic link library file corresponding to the communication protocol identifier, and instantiates the C++ communication protocol plugin encapsulated in the dynamic link library file to obtain the C++ communication protocol plugin instance. Each of the aforementioned plugin files is an independent dynamic link library file, and each of the aforementioned dynamic link library files encapsulates a C++ communication protocol plugin that corresponds to a communication protocol and implements the C++ version plugin interface.
3. The method according to claim 2, characterized in that, The process of dynamically loading the dynamic link library file corresponding to the communication protocol identifier through the cross-language plugin call interface, and instantiating the C++ communication protocol plugin encapsulated in the dynamic link library file to obtain the C++ communication protocol plugin instance includes: The predefined factory function is invoked through the cross-language plugin call interface, and the communication protocol identifier is passed to the factory function; Based on the communication protocol identifier, the corresponding dynamic link library file is dynamically loaded through the factory function; The C++ communication protocol plugin instance is obtained by calling the predefined creation function in the dynamic link library file through the factory function.
4. The method according to claim 1, characterized in that, The step of converting the call initiated by the IoT gateway through the gateway-side interface to the C++ communication protocol plugin instance into a C++ interface call to the C++ version plugin interface via the cross-language plugin call interface includes: The code encapsulates the gateway-side interface to receive calls initiated by the IoT gateway for the C++ communication protocol plugin instance through the gateway-side interface; The call is passed to the C++ interface encapsulation code corresponding to the gateway-side interface encapsulation code; The C++ interface encapsulates the code, converting the call into a C++ interface call targeting the C++ version of the plugin interface; The gateway-side interface is provided by the gateway-side interface encapsulation code, and the gateway-side interface in the gateway-side interface encapsulation code corresponds to the C++ interface in the C++ version plugin interface; the gateway-side interface encapsulation code and the C++ interface encapsulation code are generated by encapsulating the C++ version plugin interface using the SWIG tool.
5. The method according to claim 1, characterized in that, The step of invoking the C++ communication protocol plugin instance through the cross-language plugin call interface to communicate with a device using the target communication protocol via the C++ communication protocol plugin instance includes at least one of the following operations: The initialization method is invoked to initialize the C++ communication protocol plugin instance; Call the callback setting method to set the event callback interface for the C++ communication protocol plugin instance; The communication execution method is invoked to cause the C++ communication protocol plugin instance to perform a communication task with the device; When a control command is issued to the device, the control issuance method is invoked to pass the control message to the C++ communication protocol plugin instance; Upon termination of the communication task, the resource cleanup method is invoked to cause the C++ communication protocol plugin instance to perform resource cleanup. The C++ version of the plugin interface includes functional method interfaces corresponding to the initialization method, the callback setting method, the communication execution method, the control distribution method, and the resource cleanup method, as well as an event callback interface; the event callback interface includes a status change callback method for reporting communication connection status change events and a data arrival callback method for reporting data arrival events.
6. The method according to claim 5, characterized in that, The method for setting the callback is used to set the event callback interface for the C++ communication protocol plugin instance, including: Create a gateway-side callback object implemented in the target programming language, wherein the gateway-side callback object includes callback implementation methods corresponding to the state change callback method and the data arrival callback method, respectively; The gateway-side callback object is set as the event callback interface to the C++ communication protocol plugin instance through the cross-language plugin call interface; The method further includes: In response to the C++ communication protocol plugin instance calling the event callback interface, the C++ callback call to the event callback interface is converted into a call to the corresponding callback implementation method in the gateway-side callback object through the cross-language plugin call interface.
7. The method according to claim 5, characterized in that, The step of invoking the C++ communication protocol plugin instance through the cross-language plugin call interface to communicate with a device using the target communication protocol through the C++ communication protocol plugin instance includes: The data arrival callback method receives data messages reported by the C++ communication protocol plugin instance; wherein, the data message is a message obtained by the C++ communication protocol plugin instance after parsing the raw data packets reported by the device into structured data according to the target communication protocol and formatting it into the data message format specified by the IoT gateway; The control message is transmitted to the C++ communication protocol plugin instance through the control delivery method, so that the C++ communication protocol plugin instance assembles the control message into a control message that the device can recognize according to the target communication protocol, and then sends the control message to the device.
8. An Internet of Things (IoT) gateway, characterized in that, include: Multiple plugin files, with different communication protocols corresponding to different plugin files. Each plugin file is independent of the others, and each plugin file encapsulates a C++ communication protocol plugin that implements the C++ version plugin interface. A cross-language plugin calling interface is integrated into the IoT gateway. The cross-language plugin calling interface includes a gateway-side interface implemented in a target programming language, which is different from C++. The gateway-side interface corresponds to the C++ version of the plugin interface. The protocol identifier acquisition module is used to acquire the communication protocol identifier corresponding to the target communication protocol; The plugin loading module is used to load the corresponding plugin file according to the communication protocol identifier through the cross-language plugin call interface, and create a C++ communication protocol plugin instance in the plugin file; The conversion module is used to convert the call initiated by the IoT gateway through the gateway-side interface for the C++ communication protocol plugin instance into a C++ interface call for the C++ version plugin interface through the cross-language plugin call interface. The communication module is used to call the C++ communication protocol plugin instance through the cross-language plugin call interface, so as to communicate with the device using the target communication protocol through the C++ communication protocol plugin instance.
9. An electronic device, characterized in that, The device includes a memory and a processor, the memory being communicatively connected to the processor, the memory storing computer instructions, and the processor executing the computer instructions to perform the cross-language communication method of the IoT gateway according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing the computer to execute the cross-language communication method of the Internet of Things gateway according to any one of claims 1 to 7.
