Disclosure of Invention
In view of this, embodiments of the present invention provide a data processing method and a terminal device, so as to solve the problems in the prior art that a set of acquisition and analysis logic needs to be implemented for each development of a protocol based on IEC104, and multiplexing and expansion cannot be performed due to coupling of service logic, and a message analysis method is not structured and designed, so that a message is easy to make a mistake during message analysis, and is not easy to be checked after a mistake is made.
A first aspect of an embodiment of the present invention provides a data processing method, including:
receiving a message;
according to a preset message analysis chain, carrying out segmented analysis on the message to obtain analyzed data;
and carrying out data grouping on the data and storing the data.
In an embodiment, the step of performing a segment analysis on the packet according to the preset packet analysis chain to obtain analyzed data includes:
A. determining bytes to be analyzed in the message corresponding to the analysis chain subclass;
B. analyzing the corresponding bytes to be analyzed according to the analysis chain subclass;
and circularly executing the steps A and B until the message is analyzed, and obtaining analyzed data.
In an embodiment, the data grouping and storing the data includes:
according to the analyzed data, obtaining a remote number in an Iec104 protocol used for transmitting the data;
and storing the data by taking the corresponding remote number as an index.
In an embodiment, the data grouping and storing the data includes:
according to the analyzed data, inquiring a pre-stored service attribute table to obtain a service attribute name of the data, wherein at least one pair of data and a corresponding service attribute name are stored in the service attribute table;
and storing the data by taking the service attribute name as an index.
In an embodiment, after the data is packetized and stored, the method further includes:
and inquiring a data value corresponding to the data in the service attribute table according to the service attribute name of the data, and setting the data value of the data, wherein at least one pair of service attribute name and corresponding data value is stored in the service attribute table.
In an embodiment, after the setting the data value of the data, the method further includes:
and processing the data according to the corresponding service logic according to the data value of the data.
In one embodiment, the analyzed data corresponds to different point locations, and each point location is bound with an analyzer;
the processing the data according to the corresponding service logic includes:
setting all the analyzers corresponding to the stored data into a binary tree structure;
and traversing each analyzer in the binary tree structure in a mode of middle-order traversal. .
A second aspect of an embodiment of the present invention provides an apparatus for data processing, including:
the receiving module is used for receiving the message;
the analysis module is used for carrying out segmented analysis on the message according to a preset message analysis chain to obtain analyzed data;
and the storage module is used for carrying out data grouping on the data and storing the data.
A third aspect of an embodiment of the present invention provides a terminal device, including: a memory, a processor and a computer program stored in the memory and executable on the processor, the processor implementing the steps of the method as described above for data processing when executing the computer program.
A fourth aspect of an embodiment of the present invention provides a computer-readable storage medium, including: the computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the method as described above for data processing.
Compared with the prior art, the embodiment of the invention has the following beneficial effects: by receiving a message; according to a preset message analysis chain, carrying out segmented analysis on the message to obtain analyzed data; the data is grouped and stored, and a set of good design of message acquisition, message analysis, data processing and data storage based on the IEC104 protocol is provided, so that the messages, analysis messages and data processing acquired by the IEC104 can be well decoupled, and multiplexing, expansion and maintenance are facilitated.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the invention. It will be apparent, however, to one skilled in the art that the present invention may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present invention with unnecessary detail.
In order to explain the technical means of the present invention, the following description will be given by way of specific examples.
An embodiment of the present invention provides a data processing method, as shown in fig. 1, the method includes the following steps:
step 101, receiving a message.
Optionally, an asynchronous non-blocking IEC-104 protocol master station is constructed in this embodiment, and a complete implementation method is provided. Asynchronization and synchronization are relative concepts, and synchronization refers to that when a call instruction is sent out, the result of the call is not returned until the result is not obtained, and a return value is obtained once the call is returned. Asynchronous is the opposite, and the call is directly returned after the call instruction is issued, so no result is returned, i.e. after an asynchronous procedure call is issued, the caller does not get the result immediately, but after the call is issued, the callee notifies the caller through state and notification, or processes the call through a callback function. And when the calling result is obtained, the result is sent in a callback mode. Non-blocking is a relative concept to blocking, which concerns the state of a program while waiting for the result of a call (message or return value). Blocking the call means that the current thread is suspended before the call result is returned, and the call thread is returned only after the result is obtained. A non-blocking call refers to a call that does not block the current thread until the result is not immediately available.
Optionally, the Client object receives the message, and the Client object may be an IEC-104 Client. The IEC-104Client realizes the start and stop of a main station program based on an asynchronous non-blocking IEC-104 protocol and the start of all actions of the program.
Step 102, according to a preset message analysis chain, carrying out segmented analysis on the message to obtain analyzed data.
Optionally, the message analysis chain is designed in a responsibility chain mode, and a plurality of analysis chain subclasses forming the message analysis chain can be implemented to analyze the message in segments, as shown in fig. 2, the message analysis chain includes: chain01_ Start initiator, Chain02_ Length successor Length, Chain03_ Ctrl control field, Chain03b _ Package _ SS frame, Chain03c _ Package _ UU frame, Chain03a _ Package _ II frame, Chain04_ Type, Chain05_ Changeable variable structure qualifier, Chain06_ Reason transport Reason, Chain07_ FTUAddress FTU site, Chain08_ DataParse data body, and other parse Chain subclasses.
Optionally, each parsing chain sub-class in the message parsing chain may parse a plurality of bytes in the message. The message analysis comprises the following steps:
A. determining bytes to be analyzed in the message corresponding to the analysis chain subclass;
B. analyzing the corresponding bytes to be analyzed according to the analysis chain subclass;
and circularly executing the steps A and B until the message is analyzed, and obtaining analyzed data.
Optionally, for example, according to a first parsing chain subclass of a message parsing chain, N to be parsed in the message corresponding to the first parsing chain subclass is determined1One byte, the N1Greater than or equal to 1; analyzing the N according to the first analysis chain subclass1A byte;
for another example, according to a second parsing chain subclass of a message parsing chain, determining N to be parsed in the message corresponding to the second parsing chain subclass2One byte, the N2Greater than or equal to 1; analyzing the N according to the first analysis chain subclass2A byte; and sequentially analyzing all bytes of the message according to all analysis chain subclasses of the message analysis chain to obtain analyzed data.
The following illustrates the message parsing process. The received message is represented by hexadecimal, and can be: 681 c 00000000018 f 14003300010200; 010001000100010001000100010001.
chain01_ Start parses initiator 1 byte, i.e., parses 68, and automatically performs the next step.
Chain02_ length resolves the subsequent length, i.e. resolves 1c, 1c to decimal 28, indicating that the subsequent 28 bytes are resolved and the next step is performed automatically.
Chain03_ Ctrl parses 4 bytes, i.e., parses 00000000. And judging whether the data frame is an I frame or not, and if the data frame is the I frame, automatically executing the next step according to the trend of the I frame.
Optionally, the I frame is an information frame, used for user data transmission, and includes an information field. The S frame is a monitoring frame and is used for monitoring and controlling a data link and completing functions of receiving confirmation, retransmission request, transmission pause request and the like of the I frame, and the S frame has no information field. The U frame is a non-numbered frame and is used for controlling a data link, is not numbered and can be sent out at any required moment without influencing the exchange sequence of numbered information frames.
The Chain04_ Type parses one byte, namely parse 01, to indicate that the message Type is single point telemetry, and then automatically executes the next step.
Chain05_ Changeable parses one byte, i.e., parses 8f, which is converted to binary 10001111, representing 15 consecutive telemetry data.
The resolution of 2 bytes, namely the resolution 1400, of the Chain06_ Reason is converted into decimal 20, which indicates that the message transmission Reason is the call of the corresponding station.
Chain07_ FTUAddress parses 2 bytes, i.e., parses 3300, which is converted to 51 decimal, indicating that the FTU site is 51.
Chain07_ DataParse parses 3 bytes, i.e., parses 010200, which indicates the starting address of the data volume: 0201H.
010001000100010001000100010001 denotes information element data, i.e. values of 15 remote signalling data. The 15 telesignaling data obtained after analysis are:
Index=0201H,value=01H&0x01=1;
Index=0202H,value=00H&0x01=0;
……
Index=020dH,value=01H&0x01=1;
Index=020eH,value=00H&0x01=0;
Index=020fH,value=01H&0x01=1。
the embodiment realizes the analysis of the message by adopting the responsibility chain mode design, so that the message analysis process is clearer and errors are not easy to occur.
And 103, grouping the data and storing the data.
As an implementable manner, this step may include: according to the analyzed data, obtaining a remote number in an Iec104 protocol used for transmitting the data; and storing the data by taking the corresponding remote number as an index. The analyzed data flows into a point location, namely Iec104Pointer, and the data on the point location is stored into a point table according to a remote number in a Iec104 protocol adopted for transmitting the data, namely the point table is a point location set taking the remote number as an index. The data is grouped by remote number and the grouped data enters Iec104Table group point Table interface.
The main capabilities and characteristics of a point site include: holds references and indexes for the belonging Iec104 Entity; saving and acquiring data values; acquiring a last data value; and each point location is bound with an analyzer, and the bound analyzer is executed after the point location collects the data scanning value.
As another possible embodiment, the present step may include: and inquiring a data value corresponding to the data in the service attribute table according to the analyzed data, wherein at least one pair of data and a corresponding service attribute name are stored in the service attribute table.
The data is grouped by service attribute name and the grouped data enters Iec104Entity interface. Iec104Entity "the main capabilities and characteristics of the interface include: the inheritance Map interface is a dynamic object interface; holding a point location set with a service attribute name as an index; and acquiring a data value according to the attribute name and acquiring the data value according to the attribute name.
Further, the method can further comprise the following steps: according to the business attribute name of the data, inquiring Iec104Entity input interface data in a business attribute table to obtain data value of the data; and setting the data value of the data according to the service attribute name of the data. At least one pair of service attribute names and corresponding data values are stored in the service attribute table. It will be appreciated that a service attribute table holds a number of corresponding records for data, service attribute names and data values.
Optionally, when the service needs to be executed, the data is set to a data value, and then the data is subjected to service processing according to the data value and the service logic corresponding to the data value.
Optionally, when the data has data values, the bound parser may be executed, that is, Iec104Parse is executed with parser "interface, and Iec104Parse with parser" interface main capabilities and characteristics include: the analyzer is arranged in a binary tree structure and is executed in the order of the middle-order traversal; setting a front analyzer and a rear analyzer; obtaining a first analyzer leaf node in the middle-sequence traversal order; acquiring leaf nodes of a last analyzer in the middle-sequence traversal sequence; the most common abstraction base class is BaseIec104 Parse.
Optionally, according to the characteristic of the interface of the Iec104Parsea analyzer ", the data is processed according to the corresponding service logic according to the data value of the data.
Optionally, after this step, the method may further include: setting all the analyzers corresponding to the stored data into a binary tree structure; and traversing each analyzer in the binary tree structure in a mode of middle-order traversal.
Optionally, the analyzer is further configured to decouple system business logic unrelated to the acquisition. After the data is collected, the data is decoupled from the service, the data can be analyzed differently through an analyzer, or the data can be considered as an analyzer for data configuration, so that the same data can be analyzed and aggregated differently through different analyzers, and the desired service requirement is realized. The relationship to the system business logic depends on the logic in the parser.
The embodiment provides a data storage mode and a data flow direction link design, and the data provides an external call interface from message analysis to data aggregation and storage, so that the development and application of the IEC104 protocol master station are more regular and the stability is strong.
The embodiment of the invention provides a data processing method, which comprises the steps of receiving a message; according to a preset message analysis chain, carrying out segmented analysis on the message to obtain analyzed data; the data is grouped and stored, a set of good design of message acquisition, message analysis, data processing and data storage based on the IEC104 protocol is provided, so that the messages, analysis messages and data processing acquired by the IEC104 are well decoupled, and multiplexing and expansion are facilitated.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
An embodiment of the present invention provides a data processing apparatus, as shown in fig. 3, the apparatus includes: a receiving module 301, a parsing module 302 and a storing module 303.
The receiving module 301 is configured to receive a message.
The parsing module 302 is configured to perform segmented parsing on the packet according to a preset packet parsing chain, so as to obtain parsed data.
Optionally, the parsing module 302 is configured to a determine a byte to be parsed in the message corresponding to the parsing chain subclass; B. analyzing the corresponding bytes to be analyzed according to the analysis chain subclass; and circularly executing the steps A and B until the message is analyzed, and obtaining analyzed data.
And the storage module 303 is configured to perform data grouping on the data and store the data.
Optionally, the storage module 303 is configured to obtain, according to the analyzed data, a remote number in an Iec104 protocol used for transmitting the data; and storing the data by taking the corresponding remote number as an index.
Optionally, the storage module 303 is configured to query a pre-stored service attribute table according to the analyzed data to obtain a service attribute name of the data, where the service attribute table stores at least one pair of data and a corresponding service attribute name; and storing the data by taking the service attribute name as an index.
Further, after storing the data, the apparatus is further configured to query, according to the service attribute name of the data, a data value corresponding to the data in the service attribute table, and set a data value of the data, where at least one pair of the service attribute name and the corresponding data value is stored in the service attribute table. And processing the data according to the corresponding business logic according to the data value of the data
Optionally, the analyzed data corresponds to different point locations, and each point location is bound with an analyzer; the device is used for setting all the analyzers corresponding to the stored data into a binary tree structure; and traversing each analyzer in the binary tree structure in a mode of middle-order traversal.
The embodiment of the invention provides a data processing device, which comprises a receiving module, a processing module and a processing module, wherein the receiving module is used for receiving a message; according to a preset message analysis chain, an analysis module carries out segmented analysis on the message to obtain analyzed data; the embodiment of the invention provides a set of good design of message acquisition, message analysis, data processing and data storage based on the IEC104 protocol, so that the messages, analysis messages and data processing acquired by the IEC104 are well decoupled, and multiplexing and expansion are more convenient.
Fig. 4 is a schematic diagram of a terminal device according to an embodiment of the present invention. As shown in fig. 4, the terminal device 4 of this embodiment includes: a processor 401, a memory 402 and a computer program 403, such as a detection program for a dc bias of a transformer core, stored in said memory 402 and executable on said processor 401. The processor 401 implements the steps in the above-described method embodiments of data processing, such as the steps 101 to 103 shown in fig. 1, when executing the computer program 403. The processor 401, when executing the computer program 403, implements the functions of the modules in the device embodiments described above, such as the functions of the modules 301 to 303 shown in fig. 3.
Illustratively, the computer program 403 may be partitioned into one or more modules that are stored in the memory 402 and executed by the processor 401 to implement the present invention. The one or more modules may be a series of computer program instruction segments capable of performing specific functions, which are used for describing the execution process of the computer program 403 in the data processing apparatus or terminal device 4. For example, the computer program 403 may be divided into a receiving module 301, an analyzing module 302, and a storing module 303, and specific functions of the modules are shown in fig. 3, which is not described herein again.
The terminal device 4 may be a desktop computer, a notebook, a palm computer, a cloud server, or other computing devices. The terminal device may include, but is not limited to, a processor 401, a memory 402. Those skilled in the art will appreciate that fig. 4 is merely an example of a terminal device 4 and does not constitute a limitation of terminal device 4 and may include more or fewer components than shown, or some components may be combined, or different components, e.g., the terminal device may also include input-output devices, network access devices, buses, etc.
The Processor 401 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The storage 402 may be an internal storage unit of the terminal device 4, such as a hard disk or a memory of the terminal device 4. The memory 402 may also be an external storage device of the terminal device 4, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the terminal device 4. Further, the memory 402 may also include both an internal storage unit and an external storage device of the terminal device 4. The memory 402 is used for storing the computer programs and other programs and data required by the terminal device 4. The memory 402 may also be used to temporarily store data that has been output or is to be output.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus/terminal device and method may be implemented in other ways. For example, the above-described embodiments of the apparatus/terminal device are merely illustrative, and for example, the division of the modules or units is only one logical division, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated modules/units, if implemented in the form of software functional units and sold or used as separate products, may be stored in a computer readable storage medium. Based on such understanding, all or part of the flow of the method according to the embodiments of the present invention may also be implemented by a computer program, which may be stored in a computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method embodiments may be implemented. . Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present invention, and are intended to be included within the scope of the present invention.