The introduction method of a kind of LIN network description file LDF based on ANTLR
Technical field
The present invention relates to the network design technology in automotive electronics software development, especially relate to the introduction method of a kind of LIN network description file LDF based on ANTLR.
Background technology
LIN(Local Interconnect Network) being a kind of vehicle-mounted Intranet cheaply, is that one of existing vehicle-mounted complex network is supplemented.LIN attempts to carry out further improving performance by realizing the In-vehicle networking of classification, reduces the cost of exploitation, generation, service and logistics in automotive electronics simultaneously.With CAN(Controller Area Network, controller local area network) bus compares, and LIN bus has smaller bandwidth, and complicacy is also relatively low.LDF is a kind of configuration information description document of LIN bus.It mainly comprises the following information of LIN bus: bus version information, Bus Speed definition, communication node definition, communication node attribute definition, signal definition (also having diagnostic signal), the definition of signal group, frame definition (also having dynamic frame, discrete frames, Event triggered frame and diagnosis frame), dispatch list definition etc.The all elements defining in LDF file is all have specific standard grammatical, meets BNF(Backus-Naur Form) Bacchus-Nore normal form.The design that can effectively carry out LIN bus by LDF defines the communication bunch based on LIN bus simultaneously.
The speech recognizer ANTLR increasing income, compared with Lex/Yacc, ANTLR provides a more powerful speech recognition framework.It can, according to user-defined grammatical file, generate morphology recognizer and the grammatical recognizer of plurality of target language (Java, C#, C++, Python etc.).Meanwhile, ANTLR recovers to provide very effective support to the processing of semantic tree, error reporting, mistake.
Network design process in automotive electronics software development at present, generally can not start from scratch and carry out the design of particular network.Zero-based network design is the process of a more complicated.If can provide one efficiently, the design tool of similar DaVinci Network Designer intuitively, can improve the efficiency of network configuration so to a certain extent.Nowadays the method conventionally adopting is to import existing network model, carries out relevant configuration and comes Rapid Establishment to meet the network model of application needs.
LDF file has good readability.Based on this point, although thereby can directly process based on text-string the object that LDF file reaches importing.But the processing based on text-string lacks accuracy, efficiency is lower, and more loaded down with trivial details, and complexity is higher.
To sum up, face in order to make full use of the demand of existing network model, especially in order to meet AUTOSAR(automobile open system framework, the specific demand of the network design that Automotive Open System Architecture) in methodology, the system configuration stage carries out, needs a kind of method that correctly imports efficiently LDF file.
Summary of the invention
In order effectively to utilize the development of existing network design, overcome fallibility, poor efficiency and loaded down with trivial details shortcoming that the file lead-in mode based on text-string brings, the invention provides a kind of efficient LDF file introduction method and complete the effective utilization to existing LIN bus network model.
In order to solve the problems of the technologies described above, technical scheme of the present invention is as follows:
An introduction method of the LIN network description file LDF of ANTLR, comprises the steps:
1) utilize the syntax of the LDF standard of LIN bus version regulation, write the syntax that meet the speech recognizer ANTLR regulation of increasing income, combination obtains LDF syntax file;
2) by the LDF syntax file described in step 1) is imported in described ANTLR, the parameter configuration in ANTLR is set, generates the morphology recognizer and the speech recognizer that obtain LDF file;
3) by described ANTLR, generate described abstract semantics traversal of tree device, write the grammatical file of traversal abstract semantics tree, described walker travels through for the element in described LDF syntax file according to the grammatical file of the traversal abstract semantics tree of writing, extract the information that application needs, and can define on demand certain logic;
4) importing LDF file by step 2) described morphology recognizer and speech recognizer obtain its abstract semantics and set;
5) by the walker described in step 3), travel through described abstract semantics and set each nodal information, in conjunction with self-defining LDF element class model, remove the redundant information in described abstract semantics tree, complete the conversion of setting concrete internal memory class model from abstract semantics.
Further, described LDF file comprises bus version information element, Bus Speed definition element, communication node definition element, communication node attribute definition element, signal definition element, signal group definition element, frame definition element, and dispatch list defines element and meets BNF normal form.
Further, described step 5) in, when setting each nodal information, finishes when finding not have to travel through the described abstract semantics of traversal, obtain non-leaf nodes information with and all child node information, judge whether child node is all leaf node, if not continue to obtain non-leaf nodes information with and all child node information, if it is merge all child node information and in conjunction with self-defining LDF element class model, remove the redundant information in described abstract semantics tree, complete the conversion of setting concrete internal memory class model from abstract semantics.
Further, described LDF file meets LIN2.0 network standard.
The present invention has following beneficial effect:
1. the present invention supports the importing of the LDF file of LIN2.0 standard, the speech recognizer ANTLR increasing income, for the importing of LDF file provides strong support, very the processing LDF file of convenient and efficient, has avoided the fallibility based on text character string manipulation loaded down with trivial details.
2. the present invention is based on ANTLR, its importing for LDF file provides powerful framework support, can be according to actual application needs, when traversal abstract semantics tree, do self-defining business logic processing, while is also for the checking of LDF file provides condition, be conducive to identify the file that does not meet LDF syntax gauge, even can realize wrong location.
3. the present invention supports the LIN bus network model importing can effectively utilize existing development, for carrying out the iterative development of network model, or carrying out network configuration, network analysis and diagnosis provides the foundation, also for meeting the specific demand of the network design that in AUTOSAR methodology, the system configuration stage carries out, provide condition, enriched the development approach of AUTOSAR simultaneously.
Accompanying drawing explanation
Fig. 1 main process flow diagram of the present invention;
The part abstract semantics tree schematic diagram of Fig. 2 embodiment of the present invention;
The concrete internal memory class model of the part schematic diagram of Fig. 3 embodiment of the present invention.
Embodiment
Below in conjunction with the drawings and specific embodiments, the present invention is described further.
An introduction method of the LIN network description file LDF of ANTLR, comprises the steps:
1) utilize the syntax of the LDF standard of LIN bus version regulation, write the syntax that meet the speech recognizer ANTLR regulation of increasing income, combination obtains LDF syntax file;
2) by the LDF syntax file described in step 1) is imported in described ANTLR, the parameter configuration in ANTLR is set, generates the morphology recognizer and the speech recognizer that obtain LDF file;
3) by described ANTLR, generate described abstract semantics traversal of tree device, write the grammatical file of traversal abstract semantics tree, described walker travels through for the element in described LDF syntax file according to the grammatical file of the traversal abstract semantics tree of writing, extract the information that application needs, and can define on demand certain logic;
4) importing LDF file by step 2) described morphology recognizer and speech recognizer obtain its abstract semantics and set;
5) by the walker described in step 3), travel through described abstract semantics and set each nodal information, in conjunction with self-defining LDF element class model, remove the redundant information in described abstract semantics tree, complete the conversion of setting concrete internal memory class model from abstract semantics.
Technical conceive of the present invention is: LDF file is a kind of preservation form of LIN bus network configuration.If can make full use of the demand of existing network model, especially in order to meet the specific demand of the network design that in AUTOSAR methodology, the system configuration stage carries out, the method that imports so efficiently LDF file must be conducive to the network model that Rapid Establishment meets application needs, and then can improve the efficiency of network configuration.
LDF document definition all total line elements of LIN, and the syntax of these elements are standards, meet BNF normal form.The speech recognizer ANTLR that increases income supports the syntax of BNF normal form, can generate morphology recognizer and the speech recognizer of different target language, and the effective support that provides the processing of abstract semantics tree and error reporting, mistake to recover.
The grammar definition of LDF standard, adds the efficient speech recognizer that ANTLR increases income, and for the importing (identifying and be converted into memory model) of LDF file provides very efficiently, supports.Based on ANTLR, import existing LIN bus network model and can effectively utilize existing development, for carrying out the iterative development of network model, or carry out network configuration, network analysis and diagnosis and provide the foundation.
Fig. 1 has pointed out main process flow diagram of the present invention, specific as follows:
11) write LDF syntax file.
12) by ANTLR, generate morphology recognizer and speech recognizer.
13) by ANTLR, generate abstract semantics tree walker.
(13.1) write the grammatical file of traversal abstract semantics tree.
(13.2) based on ANTLR, import LDF syntax file, finally generate abstract semantics tree walker.
14) import any one LDF file and obtain its abstract semantics tree.
15) be converted into concrete internal memory class model.
Detailed step is described as follows:
Step 1, writes LDF syntax file.LDF document definition all total line elements of LIN, and the syntax of these elements are standards, meet BNF normal form.The element that LDF mainly comprises is as follows: bus version information, Bus Speed definition, communication node definition, communication node attribute definition, signal definition (also having diagnostic signal), the definition of signal group, frame definition (also having dynamic frame, discrete frames, Event triggered frame and diagnosis frame), dispatch list definition etc.Some difference in the definition of element in different LIN bus version (1.3,2.0,2.1, J2602_1_1.0).Need to write the syntax that meet ANTLR regulation for the syntax of each element, the final synthetic syntax that obtain whole LDF file.In this application case, the LDF syntax are to meet LIN2.0 standard.The LDF syntax that now obtain not are the syntax for certain LDF file, therefore write the LDF syntax file obtaining and have versatility.
Step 2, generates morphology recognizer and speech recognizer by ANTLR.Speech recognizer ANTLR based on increasing income, import the LDF syntax file that step 1 is write, add that the target language that some simple parameter configuration: language=Java(generates is Java simultaneously), output=AST(identification is output as abstract semantics tree) etc., can generate the morphology recognizer and the speech recognizer that obtain LDF file.In this application case, the version that ANTLR adopts is ANTLR 3.X.Because LDF syntax file has versatility, the morphology recognizer and the speech recognizer that therefore by ANTLR, generate have versatility too.After completing steps 2, now possessed the ability of any LDF file of identification.
Step 3, generates abstract semantics tree walker by ANTLR.Write the grammatical file of traversal abstract semantics tree, walker travels through for the element in LDF syntax file according to the grammatical file of abstract semantics tree, extracts the information that application needs, and can define certain logic simultaneously.In this application case, the syntax of abstract semantics walker are corresponding with the LDF syntax standard in step 1.Because LDF syntax file has versatility, the abstract semantics tree walker therefore generating by ANTLR has versatility too.After completing steps 3, now possessed the ability that imports any LDF file.
Step 4, imports any one LDF file and obtains its abstract semantics tree.LDF file can carry out hand-coding according to the syntax of LDF.Hand-coding is more loaded down with trivial details, and workload is larger, and fallibility.At present thereby general LDF file is all to utilize the design tool of existing similar DaVinci Network Designer to carry out network design to generate and obtain.In this application case, what directly use is the LDF file that meets LIN2.0 standard in the LIN demo that provides of CANoe 7.0.Fig. 2 has provided importing LDF file and has obtained some the important element nodes in its corresponding abstract semantics tree.From Fig. 2, can find that this LDF meets LIN2.0 standard, Bus Speed is 19.2kbps; The master node that has a host node 1 by name in this LIN bus, its time reference is 5ms, has the shake of a 0.1ms; Have two slave nodes, name is respectively: from node 1, from node 2; In addition also have signal messages all in bus, frame information, schedule information etc.Meanwhile, also can find that this abstract semantics tree exists a certain amount of meaningless information, such as comma, branch, parantheses etc., they are mainly used in standardization and the readability of the LDF syntax.
Step 5, is converted into concrete internal memory class model.The abstract semantics tree walker generating based on step 3, in conjunction with self-defining LDF element class model, can remove the redundant information in abstract semantics tree according to application demand, concrete as shown in Fig. 1 right-hand component, by ANTLR, generate abstract semantics traversal of tree device, when setting each nodal information, finishes when finding not have to travel through this walker traversal abstract semantics, obtain non-leaf nodes information with and all child node information, judge whether child node is all leaf node, if not continue to obtain non-leaf nodes information with and all child node information, if it is merge all child node information and be converted into corresponding internal memory class model.The final conversion that becomes to set concrete internal memory class model from abstract semantics.In this application case, Fig. 3 has provided concrete memory model corresponding to abstract semantics tree of describing in Fig. 2.
The above is only the preferred embodiment of the present invention; it should be pointed out that for those skilled in the art, without departing from the inventive concept of the premise; can also make some improvements and modifications, these improvements and modifications also should be considered as in protection domain of the present invention.