Object model configuration method and apparatus, and computer-readable storage medium
By obtaining the Excel protocol parsing model of the target protocol, using Java syntax tree analysis technology to generate parsing code files, and using the Java reflection mechanism to automatically configure the object model, the problems of inconsistent object model configuration and process redundancy are solved, and efficient and accurate object model configuration is achieved.
Patent Information
- Application Number
- CN202211594673.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-13
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2042-12-13
AI Technical Summary
The configuration process of the object model in the existing technology has problems such as the protocol parsing file and the object model definition being out of sync, manual operation being prone to errors, and process redundancy, which leads to configuration inconsistency and low efficiency.
By obtaining the Excel protocol parsing model of the target protocol, using Java syntax tree analysis technology to generate parsing code files, and using the Java reflection mechanism to automatically configure the object model, the consistency of the object model and the protocol is ensured, reducing manual operations.
It achieves automatic consistency configuration of object models and protocols, reduces process redundancy, improves configuration efficiency and accuracy, and reduces human errors.
Smart Images

Figure CN115934098B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of Internet of Things, and in particular to a method and device for configuring a physical model, and a computer-readable storage medium. Background Art
[0002] With the rapid development of IoT technology, industrial gateways, vehicle-mounted terminals, and other devices in various smart factories collect a wide range of data and report it to IoT platforms via various protocols. IoT platforms parse these different protocols to restore the original data. The metadata for the data reported by these devices is called a thing model. In real-world environments, the definition of a thing model constantly changes with device updates. To dynamically upgrade the thing model definition through protocol parsing, the current mainstream approach involves the customer defining a new Excel protocol parsing model. IoT platform developers then develop a new dynamic parsing file based on the Excel protocol parsing model and deploy it to the IoT parsing environment. Operations and maintenance personnel then convert the Excel protocol parsing model into the new thing model and configure it within the IoT platform's products, completing the thing model upgrade. However, the above solution may have the following shortcomings: (1) Although the development of the protocol parsing file and the configuration of the object model are both based on the Excel protocol parsing model, they are divided into two steps. When the protocol parsing file changes frequently, it is easy to miss something, which will cause the parsing protocol of the object model to be out of sync with the object model definition version; (2) The configuration of the object model is manually entered by the operation and maintenance personnel, which is prone to errors and causes mismatch between the object model and the parsing protocol; (3) The process is redundant. The development and upgrade of the entire object model involves developers developing parsing protocols, and operation and maintenance personnel deploying protocols and configuring object models online. Summary of the Invention
[0003] The purpose of this application is to provide a physical model configuration method, device and computer-readable storage medium, which can ensure the consistency of the configured physical model with the protocol without manual operation, reduce process redundancy and improve the efficiency of physical model configuration.
[0004] To achieve the above objectives:
[0005] In a first aspect, an embodiment of the present application provides a method for configuring a physical model, the method comprising:
[0006] Obtaining an Excel protocol parsing model corresponding to a target protocol, wherein the Excel protocol parsing model corresponding to the target protocol includes protocol global attributes and protocol attribute points of the target protocol;
[0007] Parsing the Excel protocol parsing model corresponding to the target protocol to obtain a parsing code file for the target protocol; the parsing code file includes an object with annotations and a protocol parsing code, wherein the annotations are used to represent metadata definitions of the object model;
[0008] The object model corresponding to the target protocol is configured according to the parsed code file.
[0009] Optionally, parsing the protocol parsing model corresponding to the target protocol to obtain a parsing code file for the target protocol includes:
[0010] Using a code generation tool to read the protocol parsing model data corresponding to the target protocol, and obtain the protocol global attributes and protocol attribute points of the target protocol;
[0011] A parsing code file for the target protocol is generated according to the protocol global attributes and protocol attribute points of the target protocol.
[0012] Optionally, generating a parsing code file for the target protocol according to the protocol global attributes and protocol attribute points of the target protocol includes:
[0013] According to the protocol global attributes and protocol attribute points of the target protocol, a parsing code file for the target protocol is constructed and generated based on Java syntax tree analysis technology.
[0014] Optionally, constructing and generating a parsing code file for the target protocol based on Java syntax tree analysis technology according to the protocol global attributes and protocol attribute points of the target protocol includes:
[0015] Define a Java entity class;
[0016] The annotations of the Java objects under the Java entity class are defined based on the protocol global attributes of the target protocol, and the annotations of the member variables under the Java entity class are defined based on the protocol attribute points of the target protocol to obtain the parsed code file for the target protocol.
[0017] Optionally, configuring the object model corresponding to the target protocol according to the parsed code file includes:
[0018] Dynamically loading or replacing the protocol parsing code of the target protocol into the parsing environment;
[0019] Add or update the object model corresponding to the target protocol according to the annotated object.
[0020] Optionally, the adding or updating the object model corresponding to the target protocol according to the annotated object includes:
[0021] Read the annotated Java object based on the Java reflection mechanism to obtain the metadata definition of the object model;
[0022] Generate a physical model attribute point of the corresponding metadata according to the metadata definition;
[0023] The object model of the target protocol is newly added or updated according to the object model attribute points.
[0024] Optionally, the method further includes:
[0025] After the target data packet is acquired, the protocol parsing code of the target protocol in the parsing environment is called to parse the target data packet to obtain a parsing result of the target data packet.
[0026] In a second aspect, an embodiment of the present application provides a physical model configuration device, including:
[0027] An acquisition module is used to acquire an Excel protocol parsing model corresponding to a target protocol, wherein the Excel protocol parsing model corresponding to the target protocol includes protocol global attributes and protocol attribute points of the target protocol;
[0028] a parsing module, configured to parse an Excel protocol parsing model corresponding to the target protocol to obtain a parsing code file for the target protocol; the parsing code file includes an object with annotations and a protocol parsing code, wherein the annotations are used to represent metadata definitions of the object model;
[0029] A processing module is used to configure a physical model of the target protocol according to the parsed code file.
[0030] In a third aspect, an embodiment of the present application provides a physical model configuration device, comprising: a processor and a memory storing a computer program, wherein when the processor runs the computer program, the steps of the above-mentioned physical model configuration method are implemented.
[0031] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned physical model configuration method are implemented.
[0032] The object model configuration method, device and computer-readable storage medium provided in the embodiments of the present application include: obtaining an Excel protocol parsing model corresponding to a target protocol, wherein the Excel protocol parsing model corresponding to the target protocol includes the protocol global attributes and protocol attribute points of the target protocol; parsing the Excel protocol parsing model corresponding to the target protocol to obtain a parsing code file for the target protocol; the parsing code file includes objects containing annotations and protocol parsing codes, wherein the annotations are used to represent metadata definitions of the object model; and configuring the object model corresponding to the target protocol according to the parsing code file. In this way, by parsing the Excel protocol parsing model corresponding to the target protocol, a parsing code file including objects containing annotations and protocol parsing codes is obtained, and then the object model corresponding to the target protocol is configured based on the parsing code file, which can ensure the consistency of the configured object model with the protocol, without the need for manual operation, reducing process redundancy and improving the efficiency of object model configuration. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 A schematic diagram of a flow chart of a physical model configuration method provided in an embodiment of the present invention;
[0034] Figure 2 A schematic diagram of the structure of the physical model configuration device provided in an embodiment of the present invention Figure 1 ;
[0035] Figure 3 A schematic diagram of the process of configuring a physical model according to an embodiment of the present invention;
[0036] Figure 4 A schematic diagram of the structure of the physical model configuration device provided in an embodiment of the present invention Figure 2 . DETAILED DESCRIPTION
[0037] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
[0038] It should be noted that, in this document, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element. In addition, components, features, and elements with the same name in different embodiments of the present application may have the same meaning or different meanings, and their specific meanings need to be determined by their explanation in the specific embodiment or further combined with the context of the specific embodiment.
[0039] It should be understood that although the terms first, second, third, etc. may be used herein to describe various information, such information should not be limited to these terms. These terms are merely used to distinguish information of the same type from one another. For example, without departing from the scope of this document, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the term "if" as used herein may be interpreted as "at the time of," "when," or "in response to a determination." Furthermore, as used herein, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context indicates otherwise. It should be further understood that the terms "comprising" and "including" indicate the presence of the described features, steps, operations, elements, components, items, types, and / or groups, but do not exclude the presence, occurrence, or addition of one or more other features, steps, operations, elements, components, items, types, and / or groups. The terms "or" and "and / or" as used herein are to be interpreted as inclusive, meaning any one or any combination. Thus, “A, B, or C” or “A, B, and / or C” means “any of: A; B; C; A and B; A and C; B and C; A, B, and C.” An exception to this definition occurs only when a combination of elements, functions, steps, or operations are inherently mutually exclusive in some manner.
[0040] It should be understood that, although the various steps in the flowchart in the embodiment of the present application are shown in sequence according to the indication of the arrows, these steps are not necessarily performed in sequence in the order indicated by the arrows. Unless clearly stated herein, the execution of these steps is not strictly limited in order, and they can be performed in other orders. Moreover, at least a portion of the steps in the figure may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily performed at the same time, but can be performed at different times, and their execution order is not necessarily performed in sequence, but can be performed in turn or alternately with at least a portion of other steps or sub-steps or stages of other steps.
[0041] It should be noted that in this article, step codes such as S101 and S102 are used for the purpose of expressing the corresponding content more clearly and concisely, and do not constitute a substantial limitation on the order. When implementing the step, those skilled in the art may execute S102 first and then S101, etc., but these should all be within the scope of protection of this application.
[0042] It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application.
[0043] In the subsequent description, the use of suffixes such as "module", "component" or "unit" to represent elements is only for the purpose of facilitating the description of the present application and has no specific meaning. Therefore, "module", "component" or "unit" can be used interchangeably.
[0044] See Figure 1 , is a physical model configuration method provided in an embodiment of the present application. The physical model configuration method can be executed by a physical model configuration device provided in an embodiment of the present application. The physical model configuration device can be implemented in software and / or hardware. In this embodiment, the execution subject of the physical model configuration method is a server such as an Internet of Things platform. The physical model configuration method provided in this embodiment includes:
[0045] Step S101: Acquire an Excel protocol parsing model corresponding to a target protocol, where the Excel protocol parsing model corresponding to the target protocol includes protocol global attributes and protocol attribute points of the target protocol.
[0046] Optionally, the target protocol is a newly added protocol or one that requires updating. Optionally, a user can use a terminal device to create an Excel protocol parsing model for the protocol document of the target protocol to obtain the Excel protocol parsing model corresponding to the target protocol, and then send the Excel protocol parsing model corresponding to the target protocol to the IoT platform via the terminal device, so that the IoT platform can obtain the Excel protocol parsing model corresponding to the target protocol. Optionally, by creating an Excel protocol parsing model, the template of the protocol parsing model can be unified, facilitating subsequent acquisition of target protocol information. Optionally, the protocol global attributes belong to the overall definition of the protocol, including but not limited to the name, number, and version of the target protocol. Optionally, the protocol attribute points refer to attribute data reported by the terminal device that needs to be parsed by the IoT platform, and mainly include two parts: one part describes the parsing rules for each attribute point in the reported data packet, such as the starting position, length, and parsing method during data parsing; the other part describes the storage format of the data and the format for subsequent display, such as the data storage type, display type, display name, and unit.
[0047] Step S102: Parse the Excel protocol parsing model corresponding to the target protocol to obtain a parsing code file for the target protocol; the parsing code file includes an object with annotations and a protocol parsing code, wherein the annotations are used to represent metadata definitions of the object model.
[0048] Optionally, in order to obtain the protocol global attributes and protocol attribute points of the target protocol contained in the Excel protocol parsing model corresponding to the target protocol, the Internet of Things platform may parse the Excel protocol parsing model corresponding to the target protocol to obtain a parsing code file for the target protocol. Optionally, the object containing annotations can be set according to actual needs, such as a Java object containing annotations. Optionally, the parsing logic of the protocol parsing code is generated according to the parsing rules of the protocol attribute points of the target protocol. Optionally, the annotation is used to represent the metadata definition of the object model, which can be generated based on the protocol global attributes and protocol attribute points of the target protocol, such as the name, number, version of the target protocol and the data type and unit of the variable.
[0049] In one embodiment, parsing the Excel protocol parsing model corresponding to the target protocol to obtain a parsing code file for the target protocol includes:
[0050] Use a code generation tool to read the Excel protocol parsing model data corresponding to the target protocol to obtain the protocol global properties and protocol property points of the target protocol;
[0051] A parsing code file for the target protocol is generated according to the protocol global attributes and protocol attribute points of the target protocol.
[0052] Optionally, the Internet of Things platform can use a code generation tool to read the Excel protocol parsing model data corresponding to the target protocol to obtain the protocol global properties and protocol attribute points of the target protocol, and generate a parsing code file for the target protocol based on the protocol global properties and protocol attribute points of the target protocol. Optionally, the parsing logic of the protocol parsing code in the parsing code file is generated based on the parsing rules of the protocol attribute points of the target protocol. Optionally, the annotated objects in the parsing code file are generated based on the protocol global properties and protocol attribute points of the target protocol. Optionally, the parsing code file of the target protocol has two capabilities, one is the ability to parse reported data, and the other is the ability to provide object model definitions.
[0053] In one embodiment, generating a parsing code file for the target protocol based on the protocol global attributes and protocol attribute points of the target protocol includes:
[0054] According to the protocol global attributes and protocol attribute points of the target protocol, a parsing code file for the target protocol is constructed and generated based on Java syntax tree analysis technology.
[0055] Optionally, the Internet of Things platform can construct and generate a parsing code file for the target protocol based on the Java syntax tree analysis technology according to the protocol global attributes and protocol attribute points of the target protocol, thereby facilitating the quick and accurate acquisition of the parsing code file for the target protocol. Optionally, the construction and generation of the parsing code file for the target protocol based on the Java syntax tree analysis technology according to the protocol global attributes and protocol attribute points of the target protocol includes: defining a Java entity class; defining annotations for Java objects under the Java entity class based on the protocol global attributes of the target protocol, and defining annotations for member variables under the Java entity class based on the protocol attribute points of the target protocol, so as to obtain the parsing code file for the target protocol. Optionally, the Internet of Things platform can first define a Java entity class in the parsing code file of the target protocol, and add annotations for Java objects under the Java entity class based on the protocol global attributes of the target protocol, and add annotations for member variables under the Java entity class based on the protocol attribute points of the target protocol, so as to obtain the parsing code file for the target protocol including objects containing annotations and protocol parsing code. Alternatively, the Java object can be considered a physical model, and the member variables can be considered different variable data within the physical model, such as speed, fuel level, temperature, mileage, etc. Thus, during the configuration of the physical model for the protocol, annotations strictly identify the protocol's global properties and protocol attribute points, such as data types and version numbers, ensuring consistency between the physical model and the protocol's properties.
[0056] Step S103: configuring a physical model corresponding to the target protocol according to the parsed code file.
[0057] Optionally, after obtaining the parsing code file of the target protocol, the Internet of Things platform can automatically add or update the object model corresponding to the target protocol according to the parsing code file.
[0058] In one embodiment, configuring the object model corresponding to the target protocol according to the parsed code file includes:
[0059] Dynamically loading or replacing the protocol parsing code of the target protocol into the parsing environment;
[0060] Add or update the object model corresponding to the target protocol according to the annotated object.
[0061] Optionally, when the IoT platform needs to configure the thing model corresponding to the target protocol, the IoT platform can first dynamically load or replace the protocol parsing code of the target protocol into the parsing environment, add or update the protocol parsing code of the target protocol in the parsing environment, and add or update the thing model corresponding to the target protocol according to the object containing the annotation. In this way, by automatically updating the protocol parsing code and the thing model corresponding to the protocol, the step of manually configuring the thing model is omitted, the cost is reduced, and the configuration efficiency is further improved.
[0062] In an embodiment, the adding or updating the thing model corresponding to the target protocol according to the object containing the annotation comprises:
[0063] reading the Java object containing the annotation based on the Java reflection mechanism to obtain the metadata definition of the thing model;
[0064] generating the thing model attribute points corresponding to the metadata according to the metadata definition;
[0065] adding or updating the thing model of the target protocol according to the thing model attribute points.
[0066] Optionally, the Java reflection mechanism refers to that in the running state of a program, an object of any class can be constructed, the class to which any object belongs can be understood, the member variables and methods of any class can be understood, the attributes and methods of any object can be called, and the annotation information of any class, method, and variable can be obtained. Optionally, the IoT platform can read the Java object containing the annotation based on the Java reflection mechanism to obtain the metadata definition of the thing model. Then, the thing model attribute points corresponding to the metadata are generated according to the metadata definition. Further, the thing model of the target protocol is added or updated according to the thing model attribute points. In this way, the thing model is generated according to the protocol parsing class annotation definition, and the consistency of the thing model attribute point definition and the data to be parsed is ensured.
[0067] In summary, in the thing model configuration method provided in the above embodiments, the Excel protocol parsing model corresponding to the target protocol is parsed to obtain a parsing code file including an object containing an annotation and protocol parsing code. Then, the thing model corresponding to the target protocol is configured based on the parsing code file, the consistency of the configured thing model and the parsed protocol is ensured, manual operation is not needed, the process redundancy is reduced, and the thing model configuration efficiency is improved.
[0068] In an embodiment, the method further comprises:
[0069] After the target data packet is obtained, the protocol parsing code of the target protocol in the parsing environment is called to parse the target data packet, and a parsing result of the target data packet is obtained.
[0070] Optionally, after configuring the object model corresponding to the target protocol based on the Excel protocol parsing model corresponding to the target protocol sent by the terminal device, the IoT platform can associate the object model corresponding to the target protocol with the terminal device, such as establishing a correspondence between the device identifier of the terminal device and the object model identifier corresponding to the target protocol. If a target data packet sent by the terminal device is received, the object model corresponding to the target protocol is first determined based on the terminal device information, and then the protocol parsing code of the target protocol located in the parsing environment is called to parse the target data packet, thereby obtaining the parsing result of the target data packet. When the target data packet needs to be displayed, the IoT platform first matches the obtained parsing result with the object model corresponding to the target protocol to add attribute information to the data in the parsing result, and then outputs the processed parsing result. Optionally, during the parsing process of the target data packet, the IoT platform can use JS expressions to dynamically parse data through the JS engine to reduce the development of customized hard code. In this way, the data packet can be parsed quickly and accurately, improving the parsing efficiency of the object model.
[0071] Based on the same inventive concept as the above embodiments, refer to Figure 2 , an embodiment of the present application provides a physical model configuration device, including:
[0072] An acquisition module is used to acquire an Excel protocol parsing model corresponding to a target protocol, wherein the Excel protocol parsing model corresponding to the target protocol includes protocol global attributes and protocol attribute points of the target protocol;
[0073] a parsing module, configured to parse an Excel protocol parsing model corresponding to the target protocol to obtain a parsing code file for the target protocol; the parsing code file includes an object with annotations and a protocol parsing code, wherein the annotations are used to represent metadata definitions of the object model;
[0074] A processing module is used to configure a physical model of the target protocol according to the parsed code file.
[0075] In summary, in the object model configuration device provided by the above embodiment, by parsing the Excel protocol parsing model corresponding to the target protocol, a parsing code file including annotated objects and protocol parsing code is obtained, and then the object model corresponding to the target protocol is configured based on the parsing code file. This can ensure the consistency of the configured object model and the parsing protocol, without the need for manual operation, reducing process redundancy and improving the efficiency of object model configuration.
[0076] In one embodiment, the parsing module is specifically configured to:
[0077] Use a code generation tool to read the Excel protocol parsing model data corresponding to the target protocol to obtain the protocol global properties and protocol property points of the target protocol;
[0078] A parsing code file for the target protocol is generated according to the protocol global attributes and protocol attribute points of the target protocol.
[0079] In one embodiment, the parsing module is specifically configured to:
[0080] According to the protocol global attributes and protocol attribute points of the target protocol, a parsing code file for the target protocol is constructed and generated based on Java syntax tree analysis technology.
[0081] In one embodiment, the parsing module is specifically configured to:
[0082] Define a Java entity class;
[0083] The annotations of the Java objects under the Java entity class are defined based on the protocol global attributes of the target protocol, and the annotations of the member variables under the Java entity class are defined based on the protocol attribute points of the target protocol to obtain the parsed code file for the target protocol.
[0084] In one embodiment, the processing module is specifically configured to:
[0085] Dynamically loading or replacing the protocol parsing code of the target protocol into the parsing environment;
[0086] Add or update the object model corresponding to the target protocol according to the annotated object.
[0087] In one embodiment, the processing module is specifically configured to:
[0088] Read the annotated Java object based on the Java reflection mechanism to obtain the metadata definition of the object model;
[0089] Generate a physical model attribute point of the corresponding metadata according to the metadata definition;
[0090] The object model of the target protocol is newly added or updated according to the object model attribute points.
[0091] In one embodiment,
[0092] The acquisition module is further used to acquire the target data packet;
[0093] The parsing module is further configured to call the protocol parsing code of the target protocol in the parsing environment to parse the target data packet and obtain a parsing result of the target data packet.
[0094] Based on the same inventive concept as the above embodiments, the above embodiments are described in detail below through a specific example.
[0095] The IoT platform and communication terminals define the communication protocol, including the overall attributes of the protocol, such as name and version, as well as metadata such as the parsing rules, storage format, and display name of the attributes in the protocol. Platform developers code and develop parsing files based on the protocol definition and deploy them online. Operations and maintenance personnel add and configure object models on the platform based on the protocol definition. However, the development and upgrade of object models rely on multiple steps, including the addition of object models and configuration of attribute points, protocol parsing development, and protocol file deployment. If these steps are performed by different business parties, it is easy to cause process fragmentation and data and configuration synchronization issues. In addition, the configuration of object models is entirely done manually according to Excel protocol templates. When there are fewer protocol attribute points, the probability of problems is low. However, when there are hundreds, thousands, or even tens of thousands of protocol attribute points, it is very easy to cause definition errors.
[0096] In response to the above problems, the object model configuration method provided in this embodiment will be committed to solving the problem of inconsistency between the IoT protocol parsing definition and the object model configuration, and provides a set of technical solutions for automatically configuring the object model based on Java code annotations of the IoT parsing protocol. The main solutions include: using code to generate a corresponding parsing file from the Excel format protocol model, and then deploying the corresponding parsing file to the IoT platform. At the same time, the Java reflection mechanism is used to automatically generate the object model definition configuration to achieve consistency between the object model configuration and the parsing definition, avoiding process fragmentation due to operations of different business parties, and the problem of data and configuration being out of sync.
[0097] The following describes the implementation process of the physical model configuration method provided in this embodiment. Figure 3 When a new protocol is added or an existing protocol needs to be upgraded, the Excel protocol parsing model must first be modeled on the device side based on the original protocol document, and then the Excel protocol parsing model must be parsed using a code generation tool on the IoT platform. The code generation tool will read the Excel protocol parsing model data and generate a parsing code file based on the overall attribute definition and attribute points. After the parsing code file is deployed to the IoT platform, the IoT platform will dynamically load and replace the parsing code in the parsing environment, and read the annotated Java objects in the parsing code through the Java reflection mechanism to generate and update the object model definition configuration.
[0098] (1) Excel protocol analysis model design
[0099] The Excel protocol parsing model design is divided into two parts, namely the protocol global attributes and protocol attribute points. The detailed design is as follows:
[0100] (1) Protocol Global Attributes: Global attributes belong to the overall definition of the protocol, such as the name, number, and version of the current protocol. However, the data packets reported by the device do not contain such data. As shown in Table 1, the name of the current protocol, i.e., the name of the physical model, is Rotary Drilling Data Based on CAN Communication, the number of the current protocol, i.e., the physical model number, is ZR0001, and the version of the current protocol, i.e., the physical model version, is ZR0001.
[0101] Table 1
[0102] Object model name Rotary drilling data based on CAN communication Object model number ZR0001 Object Model Version 0.1 Remark Rotary Drilling Working Conditions Agreement
[0103] (2) Protocol attribute point: The protocol attribute point refers to the attribute data reported by the device and needs to be parsed by the IoT platform. Its format definition is mainly divided into two parts: (1) describing the rules for parsing each attribute point in the reported data packet, such as the clear start position, length, parsing algorithm, etc. when parsing data; (2) describing the storage format of the data and the format for subsequent display during use, such as data storage type, display type, display name, unit, etc., as shown in Table 2.
[0104] Table 2
[0105]
[0106]
[0107] (2) Analysis code design
[0108] The code generation tool reads the Excel protocol parsing model data and uses Java syntax tree analysis technology to build and generate parsing code based on the read protocol global attributes and attribute points.
[0109] The parsing code is divided into two parts:
[0110] (1) Metadata definition of the thing model: Define a Java entity class in the parsing file and add the global annotation @ThingModel corresponding to the parsing protocol to the object. The annotation content includes the protocol global attributes such as protocol name, protocol number, protocol version, and remarks. Add the corresponding annotation @ModelField to the member variables of the class. The annotation content includes the thing model attribute metadata such as data name, identifier, data type, primitive data type, unit, and remarks.
[0111] Java annotations are a form of metadata written in Java code and written before classes, methods, variables, and parameters. They serve as descriptions and configurations. Annotations do not change the operation of the program, but can be accessed during compilation and runtime. For example, a Java class defines a variable and a custom annotation @ThingModel as follows:
[0112] @ThingModel(name="Device Number", type="String")private StringvehicleNo="VEHICLE_001"
[0113] At this time, the current variable is vehicleNo, and its value is "VEHICLE_001". The name and type in its annotation @ThingMode are metadata attributes that mark the vehicleNo variable. name identifies the name of vehicleNo as "device number", and type identifies the type of vehicleNo as "string".
[0114] (2) Protocol parsing code: Define the Decode method in the parsing file. The input of the Decode method is the original reported data information, and the output result is the parsed data in the form of annotated Java objects. The parsing logic in the Decode method is generated according to the parsing rules of the protocol attribute points.
[0115] (3) Automatic generation of physical models
[0116] According to the automatically generated object model protocol parsing code, the metadata definition of the object model attribute points that have been defined in the parsing code can be obtained by the parsing program through the Java reflection mechanism. The object model attribute points of the corresponding metadata are generated according to the display type, attribute, name, unit, remarks and other fields of this metadata. The object model data of the protocol is automatically generated and configured, and automatically released when the parsing code is deployed.
[0117] The Java reflection mechanism means that in the running state of the program, you can construct objects of any class, understand the class to which any object belongs, understand the member variables and methods of any class, call the properties and methods of any object, and obtain annotation information of any class, method and variable.
[0118] In summary, the object model configuration method provided in this embodiment has the following main advantages: 1) It can strictly identify data types and version numbers through code annotations during the upgrade of dynamic parsing protocols, ensuring the consistency of types and versions between the object model and the parsing protocol; 2) During protocol development, the object model and parsing data are both generated by the protocol parsing class annotation definition, ensuring the consistency of the parsing data and the object model attribute point definition; 3) During the protocol upgrade and change process, the code automatically detects protocol annotation changes and automatically updates the object model, eliminating the steps of manually configuring the object model and reducing costs; 4) Protocol parsing annotations and documents automatically generate parsing code to achieve rapid development and upgrade of new protocols; 5) Through the IoT device metadata standard, a standardized data specification interface is provided, which also provides support for subsequent standardized data storage and improves device data quality.
[0119] Based on the same inventive concept as the above embodiments, the embodiment of the present invention provides a physical model configuration device, such as Figure 4 As shown, the device includes: a processor 310 and a memory 311 storing a computer program; wherein, Figure 4 The processor 310 shown in the figure is not used to indicate that the number of processors 310 is one, but is only used to indicate the positional relationship of the processor 310 relative to other devices. In actual applications, the number of processors 310 may be one or more; similarly, Figure 4 The memory 311 shown in the figure has the same meaning, that is, it is only used to refer to the position relationship of the memory 311 relative to other devices. In actual application, the number of memories 311 can be one or more. When the processor 310 runs the computer program, the physical model configuration method applied to the above-mentioned device is implemented.
[0120] The device may also include: at least one network interface 312. The various components in the device are coupled together via a bus system 313. It is understood that the bus system 313 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 313 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, Figure 4 Various buses are labeled as bus system 313.
[0121] Memory 311 may be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. Non-volatile memory may include read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), ferromagnetic random access memory (FRAM), flash memory, magnetic surface memory, optical disk, or compact disc read-only memory (CD-ROM); magnetic surface memory may include magnetic disk memory or magnetic tape memory. Volatile memory may include random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), synchronous static random access memory (SSRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct rambus random access memory (DRRAM).The memory 311 described in the embodiments of the present invention is intended to include, but is not limited to, these and any other suitable types of memories.
[0122] The memory 311 in the embodiment of the present invention is used to store various types of data to support the operation of the device. Examples of such data include: any computer program used to operate on the device, such as an operating system and an application; contact data; phone book data; messages; pictures; videos, etc. Among them, the operating system includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., which are used to implement various basic services and process hardware-based tasks. The application program can include various applications, such as a media player (Media Player), a browser (Browser), etc., which are used to implement various application services. Here, the program that implements the method of the embodiment of the present invention can be included in the application program.
[0123] Based on the same inventive concept as the above-mentioned embodiment, this embodiment further provides a computer storage medium, in which a computer program is stored. The computer storage medium may be a magnetic random access memory (FRAM), a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a flash memory (Flash Memory), a magnetic surface memory, an optical disc, or a read-only optical disc (CD-ROM) or other memory; or it may be various devices including one or any combination of the above-mentioned memories, such as a mobile phone, a computer, a tablet device, a personal digital assistant, etc. When the computer program stored in the computer storage medium is executed by the processor, the physical model configuration method applied to the above-mentioned device is implemented. For the specific steps implemented when the computer program is executed by the processor, please refer to Figure 1 The description of the illustrated embodiment will not be repeated here.
[0124] The technical features of the above-mentioned embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above-mentioned embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0125] As used herein, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion of elements other than the listed elements and may also include additional elements not specifically listed.
[0126] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any modifications or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in the present invention should be included in the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be based on the scope of protection of the claims.
Claims
1. A physical model configuration method, characterized in that: include: Obtaining an Excel protocol parsing model corresponding to a target protocol, wherein the Excel protocol parsing model corresponding to the target protocol includes protocol global attributes and protocol attribute points of the target protocol; Parse the Excel protocol parsing model corresponding to the target protocol to obtain a parsing code file for the target protocol; The parsing code file includes an object containing annotations and a protocol parsing code, wherein the annotations are used to represent metadata definitions of an object model; Configuring a physical model corresponding to the target protocol according to the parsed code file includes: Dynamically loading or replacing the protocol parsing code of the target protocol into the parsing environment; Read the annotated Java object based on the Java reflection mechanism to obtain the metadata definition of the object model; Generate a physical model attribute point of the corresponding metadata according to the metadata definition; The object model of the target protocol is newly added or updated according to the object model attribute points.
2. The physical model configuration method according to claim 1, characterized in that: The step of parsing the Excel protocol parsing model corresponding to the target protocol to obtain a parsing code file for the target protocol includes: Use a code generation tool to read the Excel protocol parsing model data corresponding to the target protocol to obtain the protocol global properties and protocol property points of the target protocol; A parsing code file for the target protocol is generated according to the protocol global attributes and protocol attribute points of the target protocol.
3. The physical model configuration method according to claim 2, characterized in that: The generating of a parsing code file for the target protocol according to the protocol global attributes and protocol attribute points of the target protocol includes: According to the protocol global attributes and protocol attribute points of the target protocol, a parsing code file for the target protocol is constructed and generated based on Java syntax tree analysis technology.
4. The physical model configuration method according to claim 3, characterized in that: The method of constructing and generating a parsing code file for the target protocol based on the Java syntax tree analysis technology according to the protocol global attributes and protocol attribute points of the target protocol includes: Define a Java entity class; The annotations of the Java objects under the Java entity class are defined based on the protocol global attributes of the target protocol, and the annotations of the member variables under the Java entity class are defined based on the protocol attribute points of the target protocol to obtain the parsed code file for the target protocol.
5. The physical model configuration method according to claim 1, characterized in that: The method further comprises: After the target data packet is acquired, the protocol parsing code of the target protocol in the parsing environment is called to parse the target data packet to obtain a parsing result of the target data packet.
6. A physical model configuration device, characterized in that: The device comprises: An acquisition module is used to acquire an Excel protocol parsing model corresponding to a target protocol, wherein the Excel protocol parsing model corresponding to the target protocol includes protocol global attributes and protocol attribute points of the target protocol; a parsing module, configured to parse an Excel protocol parsing model corresponding to the target protocol to obtain a parsing code file for the target protocol; the parsing code file includes an object with annotations and a protocol parsing code, wherein the annotations are used to represent metadata definitions of the object model; A processing module is used to configure the object model of the target protocol according to the parsing code file, including: dynamically loading or replacing the protocol parsing code of the target protocol into the parsing environment; reading the annotated Java object based on the Java reflection mechanism to obtain the metadata definition of the object model; generating object model attribute points of corresponding metadata according to the metadata definition; and adding or updating the object model of the target protocol according to the object model attribute points.
7. A physical model configuration device, characterized in that: include: A processor and a memory storing a computer program, wherein when the processor runs the computer program, the steps of the object model configuration method according to any one of claims 1 to 5 are implemented.
8. A computer-readable storage medium, characterized in that A computer program is stored, and when the computer program is executed by a processor, the steps of the object model configuration method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Protocol configuration method and device
CN107612919A
Protocol analysis method and device, soft gateway and storage medium
CN113596017A