CN104834510A - Method and device for generating CAN (Controller Area Network) protocol code source file - Google Patents

Method and device for generating CAN (Controller Area Network) protocol code source file Download PDF

Info

Publication number
CN104834510A
CN104834510A CN201410804251.5A CN201410804251A CN104834510A CN 104834510 A CN104834510 A CN 104834510A CN 201410804251 A CN201410804251 A CN 201410804251A CN 104834510 A CN104834510 A CN 104834510A
Authority
CN
China
Prior art keywords
content
file
source file
array
column
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201410804251.5A
Other languages
Chinese (zh)
Other versions
CN104834510B (en
Inventor
周平
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beiqi Foton Motor Co Ltd
Beijing Treasure Car Co Ltd
Original Assignee
Beiqi Foton Motor Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beiqi Foton Motor Co Ltd filed Critical Beiqi Foton Motor Co Ltd
Priority to CN201410804251.5A priority Critical patent/CN104834510B/en
Publication of CN104834510A publication Critical patent/CN104834510A/en
Application granted granted Critical
Publication of CN104834510B publication Critical patent/CN104834510B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides a method and a device for generating a CAN (Controller Area Network) protocol code source file. The method comprises the following steps: reading a preset file, wherein the preset file comprises CAN protocol information; adopting a preset script to analyze the preset file and generate the CAN protocol code source file of a preset category; and outputting the CAN protocol code source file. The method can realize the automatic generation of the CAN protocol code source file.

Description

The generation method and apparatus of CAN protocol code source file
Technical field
The present invention relates to field of automobile, particularly relate to the generation method and apparatus of a kind of controller local area network (Controller AreaNetwork, CAN) protocol code source file.
Background technology
Now, automobile electronic controller application is in the car more and more extensive, has become the important composition affecting automotive performance.The construction cycle of automobile electronic controller program and quality, as a ring of automobile research cycle and quality, more and more receive the concern of automotive development business.
The exploitation of CAN protocol code is a very important job in controller bottom software development project.The code regularity of this part is comparatively strong, but the variable involved and file more, size of code is large.
In prior art, CAN protocol code source file adopts the mode of manual compiling and amendment, but artificial treatment mode not only wastes time and energy, and is very easy to make mistakes.
Summary of the invention
The present invention is intended to solve one of technical matters in correlation technique at least to a certain extent.
For this reason, one object of the present invention is a kind of generation method proposing CAN protocol code source file, and the method can realize the automatic generation of CAN protocol code source file.
Another object of the present invention is the generating apparatus proposing a kind of CAN protocol code source file.
For achieving the above object, the generation method of the CAN protocol code source file that first aspect present invention embodiment proposes, comprising: read in default file, comprises CAN protocol information in described default file; Adopt the script preset, resolve described default file, generate the CAN protocol code source file of pre-set categories; Export described CAN protocol code source file.
The generation method of the CAN protocol code source file that first aspect present invention embodiment proposes, by CAN protocol information is included in default file, and adopt default script to resolve default file, the automatic generation of CAN protocol code source file can be realized, and raise the efficiency and accuracy rate by automatically generating, reduce the construction cycle, reduce costs.
For achieving the above object, the generating apparatus of the CAN protocol code source file that second aspect present invention embodiment proposes, comprising: read in module, for reading in default file, comprising CAN protocol information in described default file; Processing module, for adopting default script, resolves described default file, generates the CAN protocol code source file of pre-set categories; Output module, for exporting described CAN protocol code source file.
The generating apparatus of the CAN protocol code source file that second aspect present invention embodiment proposes, by CAN protocol information is included in default file, and adopt default script to resolve default file, the automatic generation of CAN protocol code source file can be realized, and raise the efficiency and accuracy rate by automatically generating, reduce the construction cycle, reduce costs.
The aspect that the present invention adds and advantage will part provide in the following description, and part will become obvious from the following description, or be recognized by practice of the present invention.
Accompanying drawing explanation
The present invention above-mentioned and/or additional aspect and advantage will become obvious and easy understand from the following description of the accompanying drawings of embodiments, wherein:
Fig. 1 is the schematic flow sheet of the generation method of the CAN protocol code source file that one embodiment of the invention proposes;
Fig. 2 is the schematic flow sheet of the generation method of the CAN protocol code source file that another embodiment of the present invention proposes;
Fig. 3 is the schematic flow sheet of the generation method of the CAN protocol code source file that another embodiment of the present invention proposes;
Fig. 4 is the schematic flow sheet generating var.h file in the embodiment of the present invention;
Fig. 5 is the schematic flow sheet generating can_process.h file in the embodiment of the present invention;
Fig. 6 is the schematic flow sheet generating can_process.c file in the embodiment of the present invention;
Fig. 7 is the structural representation of the generating apparatus of the CAN protocol code source file that another embodiment of the present invention proposes;
Fig. 8 is the structural representation of the generating apparatus of the CAN protocol code source file that another embodiment of the present invention proposes.
Embodiment
Be described below in detail embodiments of the invention, the example of described embodiment is shown in the drawings, and wherein same or similar label represents same or similar element or has element that is identical or similar functions from start to finish.Being exemplary below by the embodiment be described with reference to the drawings, only for explaining the present invention, and can not limitation of the present invention being interpreted as.On the contrary, embodiments of the invention comprise fall into attached claims spirit and intension within the scope of all changes, amendment and equivalent.
Fig. 1 is the schematic flow sheet of the generation method of the CAN protocol code source file that one embodiment of the invention proposes, and the method comprises:
S11: read in default file, comprises CAN protocol information in described default file.
Wherein, default file specifically can comprise the file of separator, concrete as, character separation value (Comma-SeparatedValues, CSV) file.
Csv file also can be called comma separated value file, and it is such as numeral or text that its file stores form data form data with plain text.Plain text means that this file is a character string, and not containing must by the data understood as binary digit.Csv file is made up of the record of arbitrary number, separates between record with certain newline; Every bar record is made up of field, and the separator of interfield is other character or character string, and modal is comma or tab.Usually, all records have identical field sequence.
In the present embodiment, can by CAN protocol information definition in csv file.
See Fig. 2, the csv file 21 comprising CAN protocol information can be called: 32bit_CAN_Definition.csv.
S12: adopt the script preset, resolve described default file, generates the CAN protocol code source file of pre-set categories.
Optionally, see Fig. 2, default script 22 can be perl script.
Perl is commonly referred to as practical form and extracts language (Practical Extraction and Report Language), the characteristic of its borrow C, sed, awk, shell scripting and much other program languages.Wherein most important characteristic is the function that its inside is integrated with regular expression, and huge third party code storehouse CPAN.In brief, perl is powerful as C, convenient as the script descriptive languages such as awk, sed.
Optionally, the CAN protocol code source file of pre-set categories can comprise: for the source file of variable-definition, the source file of definition is resolved for CAN protocol, for the source file of CAN protocol dissection process, for the source file of interface, wherein, the source text for interface comprises for the source file of interface definition or the source file for interface process.
In the present embodiment, source file for variable-definition can be expressed as: vars.h file, the source file of resolving definition for CAN protocol can be expressed as: can_process.h file, source file for CAN protocol dissection process can be expressed as: can_process.c file, source file for interface definition can be expressed as: com.h file, the source file for interface process can be expressed as: com.c file.
S13: export described CAN protocol code source file.
See Fig. 2, the source file 23 of output comprises: vars.h file, can_process.h file, can_process.c file, com.h file, and com.c file.
In addition, when needs amendment CAN protocol information, can revise in csv file, adopt perl script to run afterwards again, obtain source file.
The present embodiment is by being included in default file by CAN protocol information, and adopt default script to resolve default file, the automatic generation of CAN protocol code source file can be realized, and raise the efficiency and accuracy rate by automatically generating, reduce the construction cycle, reduce costs.
Fig. 3 is the schematic flow sheet of the generation method of the CAN protocol code source file that another embodiment of the present invention proposes, and the present embodiment is csv file for default file, and the method comprises:
S31: read in the csv file comprising CAN protocol code, sorts to the content in described csv file, generates temporary file.
See Fig. 3, this step can represent with sort_io_spec.
Concrete, the content in csv file can be divided into multirow and multiple row, and can sort to every row content according to the value size of content in default row, obtain temporary file, temporary file can be expressed as temp.csv file.
The row that default row such as represent for following field: Column_IO_Type, Column_CAN_Channel, Column_ID, or, Column_CAN_Start_Bit.
Such as, suppose that row sequence number is from 0, line order is number from 1, when carrying out ascending order arrangement with the content of Column_IO_Type field, wherein, Column_IO_Type is shown in the 0th list of csv file, if then the value of the 0th row of the 1st row of csv file is greater than the value that the 2nd row the 0th arranges, then after sequence, the 1st line ordering of csv file is after the 2nd row.
S32: resolve described temporary file, generates the array that each described source file is corresponding.
See Fig. 3, this step can represent with creat_can_messages.
In an embodiment, when described source file is the source file for variable-definition, the described temporary file of described parsing, generates the array that each described source file is corresponding, comprising:
From described temporary file, read often row content respectively, correspondence often row content performs:
When the content of the Column_Var_Type field of described temporary file is can_input or can_out, by the content of the Column_Var_Type field of the described temporary file content as the type type field of described source file, and, by the content of the Column_Var_Name field of the described temporary file content as the title varname field of described source file;
The content of the name field of the content of the type field of described source file and described source file is written in initial array as the variate-value of initial array;
Described initial array is defined as array corresponding to described source file, or write head content in described initial array, is defined as array corresponding to described source file by the array after write head content.
Concrete, see Fig. 4, the flow process generating vars.h file can comprise:
S401: read a line content from temp.csv file.
S402: judge that whether the content of current reading is empty, if so, perform S408, otherwise, perform S403.
S403: var_str assignment is become template character string: type and varname.
Wherein, $ var_str is self-defining column vector, for generating array corresponding to vars.h file.
$ var_str comprises two field: type and varname.
" $ " represents column vector.
S404: judge whether $ Column_Var_Type field contents is can_input or can_output, if so, performs S405, otherwise, perform S408.
Wherein, $ Column_Var_Type field is the field in temp.csv file.
Temp.csv file can with ", " for separately often arranging, and often row sequence number is above line number, and suppose that row sequence number is from 0, then $ Column_Var_Type field is shown in the 2nd list.
S405: the content of content as type field using $ Column_Var_Type field.
Such as, when the content of $ Column_Var_Type field is can_input, then the content of type field is exactly can_input.
See Fig. 4, this step is expressed as: replace type with $ Column_Var_Type.
S406: the content of content as varname field using $ Column_Var_Name field.
The field that 1st row of temp.csv file are corresponding is $ Column_Var_Name field.
See Fig. 4, this step is expressed as: replace varname with $ Column_Var_Name.
S407: amended $ var_str is put in array@STR_VARS.
Through S405 and S406, obtain the content of field type in $ var_str and varname, using the $ var_str that obtains after content as amended $ var_str.
Array@STR_VARS is the initial array that vars.h file is corresponding, the initial value of this numerical value can be empty, often obtain an amended column vector $ var_str, this column vector is put in array@STR_VARS, obtain the array@STR_VARS of content."@" represents array.
Afterwards, array@STR_VARS can be defined as array corresponding to vars.h file, or in array@STR_VARS, add a content, the array adding a content is defined as array corresponding to vars.h file, head content is such as notes content etc.Column vector in the array that vars.h file is corresponding can be expressed as: $ VARS_H.
S408: circulation continues (Loop).
Wherein, circulation continues to refer to that the next line content continuing to read temporary file is until all provisional capitals of temporary file are traversed.
S409: close temp.csv file.
In an embodiment, when described source file is that when resolving the source file of definition for CAN protocol, the described temporary file of described parsing, generates the array that each described source file is corresponding, comprising:
From described temporary file, read often row content respectively, correspondence often row content performs:
When the content of the Column_IO_Type field of described temporary file is can_input_message, according to the content of the CAN_ID field of described temporary file, generate the structure definition of input variable, and write in the first subnumber group;
When the content of the Column_IO_Type field of described temporary file is can_output_message, according to the content of the CAN_ID field of described temporary file, generate the structure definition of output variable, and write in the second subnumber group;
When the content of the Column_Var_Type field of described temporary file is can_input or can_out, by the content of the Column_Var_Type field of the described temporary file content as the type type field of described source file, and, by the content of the Column_Var_Name field of the described temporary file content as the title varname field of described source file;
By in the content of the name field of the content of the type field of described source file and described source file write the 3rd subnumber group;
Combine described first subnumber group, the second subnumber group and the 3rd subnumber group, obtain initial array, described initial array is defined as array corresponding to described source file, or write head content in described initial array, is defined as array corresponding to described source file by the array after write head content.
Concrete, see Fig. 5, the flow process generating can_process.h file can comprise:
S501: read a line content from temp.csv file.
S502: judge that whether the content of current reading is empty, if so, perform S513, otherwise, perform S503.
S503: judge whether $ Column_IO_Type field contents is can_input_message, if so, performs S504, otherwise, perform S505.
Wherein, $ Column_IO_Type field contents is the content of the 0th row of temp.csv file.
S504: the structure definition generating corresponding input variable (message) according to CAN_ID, and the structure generated is defined in write first subnumber group.Perform S511 afterwards.
CAN_ID is the content of the 6th row of temp.csv file.
CAN_ID can represent the form that structure defines, and CAN_ID is different, and corresponding structure definition is different.
After obtaining above described structure definition, can be written in the first subnumber group of self-defined title, such as, the first subnumber group is called type_in array.
S505: judge whether $ Column_IO_Type field contents is can_output_message, if so, performs S506, otherwise, perform S507.
S506: the structure definition generating corresponding output variable (message) according to CAN_ID, and the structure generated is defined in write second subnumber group.Perform S511 afterwards.
The structure definition of output variable can be identical with the generating principle that the structure of input variable as implied above defines, and do not repeat them here.
Second subnumber group is such as called@type_out array.
S507: judge whether $ Column_IO_Type field contents is can_input, if so, performs S509, otherwise, perform S508.
S508: judge whether $ Column_IO_Type field contents is can_output, if so, performs S509, otherwise, perform S512.
S509: obtain amended $ can_process_h_str.
Wherein, $ can_process_h_str is self-defining column vector, for generating array corresponding to can_process file.
$ can_process_h_str comprises two field: type and varname.
By the content of the $ Column_Var_Type field content as type field, and, by the content of the $ Column_Var_Name field content as varname field.
Replacement flow process shown in this flow process with Fig. 4 is identical, does not repeat them here.
S510: amended $ can_process_h_str is put into the 3rd subnumber group.
Through previous step, obtain the content of field type in $ can_process_h_str and varname, using the $ can_process_h_str that obtains after content as amended $ can_process_h_str.
S511: combine the first subnumber group, the second subnumber group and the 3rd subnumber group, obtain array@STR_CAN_PROCESS_H.
Array@STR_CAN_PROCESS_H is the initial array that can_process.h file is corresponding, the initial value of this numerical value can be empty, often obtain an amended column vector $ can_process_h_str, this column vector is put in array@STR_CAN_PROCESS_H, and subnumber group corresponding with $ can_process_h_str for subnumber group corresponding for structure definition is combined, obtain the array@STR_CAN_PROCESS_H of content.
Afterwards, array@STR_CAN_PROCESS_H can be defined as array corresponding to can_process.h file, or, a content is added in array@STR_CAN_PROCESS_H, the array adding a content is defined as array corresponding to can_process.h file, head content is such as notes content etc.Column vector in the array that can_process.h file is corresponding can be expressed as: $ CAN_PROCESS_H.
In the embodiment of the present invention, combination subnumber group can specifically using each subnumber group as combination after the partial content of array, spliced by little array and obtain large array.
S512: circulation continues (Loop).
Wherein, circulation continues to refer to that the next line content continuing to read temporary file is until all provisional capitals of temporary file are traversed.
S513: close temp.csv file.
In an embodiment, when described source file is the source file for CAN protocol dissection process, the described temporary file of described parsing, generates the array that each described source file is corresponding, comprising:
From described temporary file, read often row content respectively, correspondence often row content performs:
When the content of the Column_IO_Type field of described temporary file is can_input_message, generates the buffer zone buffer that input variable is corresponding, and write in the first subnumber group;
When the content of the Column_IO_Type field of described temporary file is can_output_message, generate the buffer zone buffer that output variable is corresponding, and the buffer corresponding according to described output variable generates the transmission function of output variable, and write in the second subnumber group;
When the content of the Column_IO_Type field of described temporary file is can_input, generate corresponding get function according to each input variable, and generate the transmission function of input variable according to get function, and write in the 3rd subnumber group;
When the content of the Column_IO_Type field of described temporary file is can_output, generates corresponding set function according to each output variable, and write in the 4th subnumber group;
Combine described first subnumber group, the second subnumber group and the 3rd subnumber group, obtain initial array, described initial array is defined as array corresponding to described source file, or write head content in described initial array, is defined as array corresponding to described source file by the array after write head content.
Concrete, see Fig. 6, the flow process generating can_process.c file can comprise:
S601: read a line content from temp.csv file.
S602: judge that whether the content of current reading is empty, if so, perform S513, otherwise, perform S603.
S603: judge whether $ Column_IO_Type field contents is can_input_message, if so, performs S604, otherwise, perform S605.
S604: generate the buffer that ci_message is corresponding, and this buffer is written in the first subnumber group.Perform S613 afterwards.
Ci_message represents input variable, and buffer represents buffer zone.
Input variable is the variable between can_input_message and can_input_message.
Such as, according to preset rules arrangement input variable, buffer is obtained.
S605: judge whether $ Column_IO_Type field contents is can_output_message, if so, performs S606, otherwise, perform S608.
S606: generate the buffer that co_message is corresponding.
Co_message represents output variable.
Output variable is the variable between can_output_message and can_output_message.
S607: the buffer corresponding according to co_message generates can_output_drive_main function content, and is write in the second subnumber group by can_output_drive_main function content.Perform S613 afterwards.
Can_output_drive_main function refers to the transmission function of output variable.
Transmission function can be generated by buffer according to preset rules.
S608: judge whether $ Column_IO_Type field contents is can_input, if so, performs S609, otherwise, perform S611.
S609: according to input variable, each input variable generates corresponding get function.
S610: generate can_input_drive_main function content according to get function, and $ can_process_h_str is write in the 3rd subnumber group.Perform S613 afterwards.
Can_input_drive_main function refers to the transmission function of input variable.
S611: judge whether $ Column_IO_Type field contents is can_output, if so, performs S612, otherwise, perform S614.
S612: according to output variable, each output variable generates corresponding set function, and by set function write the 4th subnumber group.
S613: combine the first subnumber group, the second subnumber group, the 3rd subnumber group and the 4th subnumber group, obtain array@STR_CAN_PROCESS_C.
Array@STR_CAN_PROCESS_C is the initial array that can_process.c file is corresponding, afterwards, array@STR_CAN_PROCESS_C can be defined as array corresponding to can_process.c file, or, a content is added in array@STR_CAN_PROCESS_C, the array adding a content is defined as array corresponding to can_process.c file, head content is such as notes content etc.Column vector in the array that can_process.c file is corresponding can be expressed as: $ CAN_PROCESS_C.
S614: circulation continues (Loop).
Wherein, circulation continues to refer to that the next line content continuing to read temporary file is until all provisional capitals of temporary file are traversed.
S615: close temp.csv file.
In an embodiment, when described source file is the source file for interface, the described source text for interface comprises for the source file of interface definition or the source file for interface process, the described temporary file of described parsing, generate the array that each described source file is corresponding, comprising:
According to the content needed for the described template corresponding for the source file of interface, from described temporary file, directly obtain corresponding content, generate the described numerical value corresponding for the source file of interface.
After generating array corresponding to each described source file, the content in described array can be written in the source file being initially empty correspondence, obtain the described source file of content.Concrete, following source file can be exported respectively:
S33: export vars.h file.
Such as, content in $ VARS_H is written in vars.h file.
S34: export can_process.h file.
Such as, content in $ CAN_PROCESS_H is written in can_process.h file.
S35: export can_process.c file.
Such as, content in $ CAN_PROCESS_C is written in can_process.c file.
S36: export com.h file.
Such as, com.h file correspondence is that the column vector in array represents with $ COM_H, then content in $ COM_H be written in com.h file.
S37: export com.c file.
Such as, com.c file correspondence is that the column vector in array represents with $ COM_C, then content in $ COM_C be written in com.c file.
Be understandable that, output order just a kind of example of above-mentioned source file, also can adopt other Sequential outputs.
S38: delete temp.csv file.
In the present embodiment, artificial treatment is instead of with perl script, only need the related content of various CAN protocol be defined in csv file, automatically csv file content is read by perl script, by read content according to required sequence, extract required variable by the definition, title etc. of each class variable and modify, integrate, finally exporting required Sources file.Instead of artificial treatment by software process, therefore one of its advantage saves human cost, shortens the construction cycle, improves development efficiency, and two of advantage reduces error rate, improves development quality.The work that the source file of the interface between software and hardware variable-definition done due to the present invention generates has universality, be applicable in different development platforms, therefore three of its advantage is portable high, can move in different development platforms, avoid repeated work by after its amendment a little.
Fig. 7 is the structural representation of generating apparatus of the CAN protocol code source file that another embodiment of the present invention proposes, and this device 70 comprises and reads in module 71, processing module 72 and output module 73.
Reading in module 71 for reading in default file, in described default file, comprising CAN protocol information;
Default file specifically can comprise the file of separator, such as, and csv file.
Csv file also can be called comma separated value file, and it is such as numeral or text that its file stores form data form data with plain text.Plain text means that this file is a character string, and not containing must by the data understood as binary digit.Csv file is made up of the record of arbitrary number, separates between record with certain newline; Every bar record is made up of field, and the separator of interfield is other character or character string, and modal is comma or tab.Usually, all records have identical field sequence.
In the present embodiment, can by CAN protocol information definition in csv file.
Processing module 72, for adopting default script, resolves described default file, generates the CAN protocol code source file of pre-set categories;
Optionally, described default script is perl script.
Perl is commonly referred to as practical form and extracts language (Practical Extraction and Report Language), the characteristic of its borrow C, sed, awk, shell scripting and much other program languages.Wherein most important characteristic is the function that its inside is integrated with regular expression, and huge third party code storehouse CPAN.In brief, perl is powerful as C, convenient as the script descriptive languages such as awk, sed.
Optionally, the CAN protocol code source file of pre-set categories can comprise: for the source file of variable-definition, the source file of definition is resolved for CAN protocol, for the source file of CAN protocol dissection process, for the source file of interface, wherein, the source text for interface comprises for the source file of interface definition or the source file for interface process.
In the present embodiment, source file for variable-definition can be expressed as: vars.h file, the source file of resolving definition for CAN protocol can be expressed as: can_process.h file, source file for CAN protocol dissection process can be expressed as: can_process.c file, source file for interface definition can be expressed as: com.h file, the source file for interface process can be expressed as: com.c file.
Output module 73 is for exporting described CAN protocol code source file.
Such as, the source file of output comprises: vars.h file, can_process.h file, can_process.c file, com.h file, and com.c file.
In another embodiment, see Fig. 8, described processing module 72 comprises:
First module 721, for sorting to the content in described default file, generates temporary file;
Concrete, be csv file for default file, the content in csv file can be divided into multirow and multiple row, and can sort to every row content according to the value size of content in default row, obtain temporary file, temporary file can be expressed as temp.csv file.
The row that default row such as represent for following field: Column_IO_Type, Column_CAN_Channel, Column_ID, or, Column_CAN_Start_Bit.
Such as, suppose that row sequence number is from 0, line order is number from 1, when carrying out ascending order arrangement with the content of Column_IO_Type field, wherein, Column_IO_Type is shown in the 0th list of csv file, if then the value of the 0th row of the 1st row of csv file is greater than the value that the 2nd row the 0th arranges, then after sequence, the 1st line ordering of csv file is after the 2nd row.
Second unit 722, for resolving described temporary file, generates the array that each described source file is corresponding;
3rd unit 723, for the content in described array being written in the source file of the correspondence being initially sky, obtains the described source file of content.
In another embodiment, see Fig. 8, this device 70 also comprises:
Removing module 72, for deleting described temporary file.
Optionally, when described source file is the source file for variable-definition, described second unit 722 specifically for:
From described temporary file, read often row content respectively, correspondence often row content performs:
When the content of the Column_Var_Type field of described temporary file is can_input or can_out, by the content of the Column_Var_Type field of the described temporary file content as the type type field of described source file, and, by the content of the Column_Var_Name field of the described temporary file content as the title varname field of described source file;
The content of the name field of the content of the type field of described source file and described source file is written in initial array as the variate-value of initial array;
Described initial array is defined as array corresponding to described source file, or write head content in described initial array, is defined as array corresponding to described source file by the array after write head content.
Optionally, when described source file be for CAN protocol resolve definition source file time, described second unit 722 specifically for:
From described temporary file, read often row content respectively, correspondence often row content performs:
When the content of the Column_IO_Type field of described temporary file is can_input_message, according to the content of the CAN_ID field of described temporary file, generate the structure definition of input variable, and write in the first subnumber group;
When the content of the Column_IO_Type field of described temporary file is can_output_message, according to the content of the CAN_ID field of described temporary file, generate the structure definition of output variable, and write in the second subnumber group;
When the content of the Column_Var_Type field of described temporary file is can_input or can_out, by the content of the Column_Var_Type field of the described temporary file content as the type type field of described source file, and, by the content of the Column_Var_Name field of the described temporary file content as the title varname field of described source file;
By in the content of the name field of the content of the type field of described source file and described source file write the 3rd subnumber group;
Combine described first subnumber group, the second subnumber group and the 3rd subnumber group, obtain initial array, described initial array is defined as array corresponding to described source file, or write head content in described initial array, is defined as array corresponding to described source file by the array after write head content.
Optionally, when described source file is the source file for CAN protocol dissection process, described second unit 722 specifically for:
From described temporary file, read often row content respectively, correspondence often row content performs:
When the content of the Column_IO_Type field of described temporary file is can_input_message, generates the buffer zone buffer that input variable is corresponding, and write in the first subnumber group;
When the content of the Column_IO_Type field of described temporary file is can_output_message, generate the buffer zone buffer that output variable is corresponding, and the buffer corresponding according to described output variable generates the transmission function of output variable, and write in the second subnumber group;
When the content of the Column_IO_Type field of described temporary file is can_input, generate corresponding get function according to each input variable, and generate the transmission function of input variable according to get function, and write in the 3rd subnumber group;
When the content of the Column_IO_Type field of described temporary file is can_output, generates corresponding set function according to each output variable, and write in the 4th subnumber group;
Combine described first subnumber group, the second subnumber group and the 3rd subnumber group, obtain initial array, described initial array is defined as array corresponding to described source file, or write head content in described initial array, is defined as array corresponding to described source file by the array after write head content.
Optionally, when described source file is the source file for interface, the described source text for interface comprises source file for interface definition or source file for interface process, described second unit 722 specifically for:
According to the content needed for the described template corresponding for the source file of interface, from described temporary file, directly obtain corresponding content, generate the described numerical value corresponding for the source file of interface.
Be understandable that, the concrete contents processing of above-mentioned second unit see the corresponding description in embodiment of the method, can not repeat them here.
The present embodiment is by being included in default file by CAN protocol information, and adopt default script to resolve default file, the automatic generation of CAN protocol code source file can be realized, and raise the efficiency and accuracy rate by automatically generating, reduce the construction cycle, reduce costs.
It should be noted that, in describing the invention, term " first ", " second " etc. only for describing object, and can not be interpreted as instruction or hint relative importance.In addition, in describing the invention, except as otherwise noted, the implication of " multiple " is two or more.
Describe and can be understood in process flow diagram or in this any process otherwise described or method, represent and comprise one or more for realizing the module of the code of the executable instruction of the step of specific logical function or process, fragment or part, and the scope of the preferred embodiment of the present invention comprises other realization, wherein can not according to order that is shown or that discuss, comprise according to involved function by the mode while of basic or by contrary order, carry out n-back test, this should understand by embodiments of the invention person of ordinary skill in the field.
Should be appreciated that each several part of the present invention can realize with hardware, software, firmware or their combination.In the above-described embodiment, multiple step or method can with to store in memory and the software performed by suitable instruction execution system or firmware realize.Such as, if realized with hardware, the same in another embodiment, can realize by any one in following technology well known in the art or their combination: the discrete logic with the logic gates for realizing logic function to data-signal, there is the special IC of suitable combinational logic gate circuit, programmable gate array (PGA), field programmable gate array (FPGA) etc.
Those skilled in the art are appreciated that realizing all or part of step that above-described embodiment method carries is that the hardware that can carry out instruction relevant by program completes, described program can be stored in a kind of computer-readable recording medium, this program perform time, step comprising embodiment of the method one or a combination set of.
In addition, each functional unit in each embodiment of the present invention can be integrated in a processing module, also can be that the independent physics of unit exists, also can be integrated in a module by two or more unit.Above-mentioned integrated module both can adopt the form of hardware to realize, and the form of software function module also can be adopted to realize.If described integrated module using the form of software function module realize and as independently production marketing or use time, also can be stored in a computer read/write memory medium.
The above-mentioned storage medium mentioned can be ROM (read-only memory), disk or CD etc.
In the description of this instructions, specific features, structure, material or feature that the description of reference term " embodiment ", " some embodiments ", " example ", " concrete example " or " some examples " etc. means to describe in conjunction with this embodiment or example are contained at least one embodiment of the present invention or example.In this manual, identical embodiment or example are not necessarily referred to the schematic representation of above-mentioned term.And the specific features of description, structure, material or feature can combine in an appropriate manner in any one or more embodiment or example.
Although illustrate and describe embodiments of the invention above, be understandable that, above-described embodiment is exemplary, can not be interpreted as limitation of the present invention, and those of ordinary skill in the art can change above-described embodiment within the scope of the invention, revises, replace and modification.

Claims (10)

1. a generation method for CAN protocol code source file, is characterized in that, comprising:
Read in default file, in described default file, comprise CAN protocol information;
Adopt the script preset, resolve described default file, generate the CAN protocol code source file of pre-set categories;
Export described CAN protocol code source file.
2. method according to claim 1, is characterized in that, the described default file of described parsing, generates the CAN protocol code source file of pre-set categories, comprising:
Content in described default file is sorted, generates temporary file;
Resolve described temporary file, generate the array that each described source file is corresponding;
Content in described array is written in the source file being initially empty correspondence, obtains the described source file of content.
3. method according to claim 2, is characterized in that, when described source file is the source file for variable-definition, the described temporary file of described parsing, generates the array that each described source file is corresponding, comprising:
From described temporary file, read often row content respectively, correspondence often row content performs:
When the content of the Column_Var_Type field of described temporary file is can_input or can_out, by the content of the Column_Var_Type field of the described temporary file content as the type type field of described source file, and, by the content of the Column_Var_Name field of the described temporary file content as the title varname field of described source file;
The content of the name field of the content of the type field of described source file and described source file is written in initial array as the variate-value of initial array;
Described initial array is defined as array corresponding to described source file, or write head content in described initial array, is defined as array corresponding to described source file by the array after write head content.
4. method according to claim 2, is characterized in that, when described source file is that when resolving the source file of definition for CAN protocol, the described temporary file of described parsing, generates the array that each described source file is corresponding, comprising:
From described temporary file, read often row content respectively, correspondence often row content performs:
When the content of the Column_IO_Type field of described temporary file is can_input_message, according to the content of the CAN_ID field of described temporary file, generate the structure definition of input variable, and write in the first subnumber group;
When the content of the Column_IO_Type field of described temporary file is can_output_message, according to the content of the CAN_ID field of described temporary file, generate the structure definition of output variable, and write in the second subnumber group;
When the content of the Column_Var_Type field of described temporary file is can_input or can_out, by the content of the Column_Var_Type field of the described temporary file content as the type type field of described source file, and, by the content of the Column_Var_Name field of the described temporary file content as the title varname field of described source file;
By in the content of the name field of the content of the type field of described source file and described source file write the 3rd subnumber group;
Combine described first subnumber group, the second subnumber group and the 3rd subnumber group, obtain initial array, described initial array is defined as array corresponding to described source file, or write head content in described initial array, is defined as array corresponding to described source file by the array after write head content.
5. method according to claim 2, is characterized in that, when described source file is the source file for CAN protocol dissection process, the described temporary file of described parsing, generates the array that each described source file is corresponding, comprising:
From described temporary file, read often row content respectively, correspondence often row content performs:
When the content of the Column_IO_Type field of described temporary file is can_input_message, generates the buffer zone buffer that input variable is corresponding, and write in the first subnumber group;
When the content of the Column_IO_Type field of described temporary file is can_output_message, generate the buffer zone buffer that output variable is corresponding, and the buffer corresponding according to described output variable generates the transmission function of output variable, and write in the second subnumber group;
When the content of the Column_IO_Type field of described temporary file is can_input, generate corresponding get function according to each input variable, and generate the transmission function of input variable according to get function, and write in the 3rd subnumber group;
When the content of the Column_IO_Type field of described temporary file is can_output, generates corresponding set function according to each output variable, and write in the 4th subnumber group;
Combine described first subnumber group, the second subnumber group and the 3rd subnumber group, obtain initial array, described initial array is defined as array corresponding to described source file, or write head content in described initial array, is defined as array corresponding to described source file by the array after write head content.
6. a generating apparatus for CAN protocol code source file, is characterized in that, comprising:
Reading in module, for reading in default file, in described default file, comprising CAN protocol information;
Processing module, for adopting default script, resolves described default file, generates the CAN protocol code source file of pre-set categories;
Output module, for exporting described CAN protocol code source file.
7. device according to claim 6, is characterized in that, described processing module comprises:
First module, for sorting to the content in described default file, generates temporary file;
Second unit, for resolving described temporary file, generates the array that each described source file is corresponding;
Unit the 3rd, for the content in described array being written in the source file of the correspondence being initially sky, obtains the described source file of content.
8. device according to claim 7, is characterized in that, when described source file is the source file for variable-definition, described second unit specifically for:
From described temporary file, read often row content respectively, correspondence often row content performs:
When the content of the Column_Var_Type field of described temporary file is can_input or can_out, by the content of the Column_Var_Type field of the described temporary file content as the type type field of described source file, and, by the content of the Column_Var_Name field of the described temporary file content as the title varname field of described source file;
The content of the name field of the content of the type field of described source file and described source file is written in initial array as the variate-value of initial array;
Described initial array is defined as array corresponding to described source file, or write head content in described initial array, is defined as array corresponding to described source file by the array after write head content.
9. device according to claim 7, is characterized in that, when described source file be for CAN protocol resolve definition source file time, described second unit specifically for:
From described temporary file, read often row content respectively, correspondence often row content performs:
When the content of the Column_IO_Type field of described temporary file is can_input_message, according to the content of the CAN_ID field of described temporary file, generate the structure definition of input variable, and write in the first subnumber group;
When the content of the Column_IO_Type field of described temporary file is can_output_message, according to the content of the CAN_ID field of described temporary file, generate the structure definition of output variable, and write in the second subnumber group;
When the content of the Column_Var_Type field of described temporary file is can_input or can_out, by the content of the Column_Var_Type field of the described temporary file content as the type type field of described source file, and, by the content of the Column_Var_Name field of the described temporary file content as the title varname field of described source file;
By in the content of the name field of the content of the type field of described source file and described source file write the 3rd subnumber group;
Combine described first subnumber group, the second subnumber group and the 3rd subnumber group, obtain initial array, described initial array is defined as array corresponding to described source file, or write head content in described initial array, is defined as array corresponding to described source file by the array after write head content.
10. device according to claim 7, is characterized in that, when described source file is the source file for CAN protocol dissection process, described second unit specifically for:
From described temporary file, read often row content respectively, correspondence often row content performs:
When the content of the Column_IO_Type field of described temporary file is can_input_message, generates the buffer zone buffer that input variable is corresponding, and write in the first subnumber group;
When the content of the Column_IO_Type field of described temporary file is can_output_message, generate the buffer zone buffer that output variable is corresponding, and the buffer corresponding according to described output variable generates the transmission function of output variable, and write in the second subnumber group;
When the content of the Column_IO_Type field of described temporary file is can_input, generate corresponding get function according to each input variable, and generate the transmission function of input variable according to get function, and write in the 3rd subnumber group;
When the content of the Column_IO_Type field of described temporary file is can_output, generates corresponding set function according to each output variable, and write in the 4th subnumber group;
Combine described first subnumber group, the second subnumber group and the 3rd subnumber group, obtain initial array, described initial array is defined as array corresponding to described source file, or write head content in described initial array, is defined as array corresponding to described source file by the array after write head content.
CN201410804251.5A 2014-12-19 2014-12-19 The generation method and device of CAN protocol code source file Active CN104834510B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410804251.5A CN104834510B (en) 2014-12-19 2014-12-19 The generation method and device of CAN protocol code source file

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410804251.5A CN104834510B (en) 2014-12-19 2014-12-19 The generation method and device of CAN protocol code source file

Publications (2)

Publication Number Publication Date
CN104834510A true CN104834510A (en) 2015-08-12
CN104834510B CN104834510B (en) 2018-06-19

Family

ID=53812421

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410804251.5A Active CN104834510B (en) 2014-12-19 2014-12-19 The generation method and device of CAN protocol code source file

Country Status (1)

Country Link
CN (1) CN104834510B (en)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106534267A (en) * 2016-10-19 2017-03-22 中国银行股份有限公司 File uploading and resolving method and device
CN106603482A (en) * 2016-05-26 2017-04-26 欣旺达电子股份有限公司 Method and device for automatically generating CAN communication protocol code
CN106817366A (en) * 2016-12-31 2017-06-09 惠州市蓝微新源技术有限公司 A kind of CAN document analysis and again store method
CN107247582A (en) * 2017-04-14 2017-10-13 惠州市蓝微新源技术有限公司 It is a kind of to automatically generate the method that CAN sends and receives code
CN107438048A (en) * 2016-05-25 2017-12-05 宝沃汽车(中国)有限公司 CAN protocol generation method, device and there is its vehicle
CN107479526A (en) * 2017-04-24 2017-12-15 宝沃汽车(中国)有限公司 The source file automatic generation method and system of CAN signal
CN108600192A (en) * 2018-04-03 2018-09-28 南京越博动力系统股份有限公司 A kind of DBC document analysis and message analysis method based on regular expression
CN112416324A (en) * 2020-11-24 2021-02-26 歌尔光学科技有限公司 Script function implementation method based on python language, terminal equipment and storage medium
CN113626390A (en) * 2021-08-20 2021-11-09 中国第一汽车股份有限公司 BB file generation method and device, electronic equipment and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103049619A (en) * 2012-12-31 2013-04-17 上海宇芯科技有限公司 Method for completing chip design integrated functions by forms
CN103777934A (en) * 2012-10-23 2014-05-07 广州汽车集团股份有限公司 Method and system for generating controller CAN interaction layer based on MATLAB

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103777934A (en) * 2012-10-23 2014-05-07 广州汽车集团股份有限公司 Method and system for generating controller CAN interaction layer based on MATLAB
CN103049619A (en) * 2012-12-31 2013-04-17 上海宇芯科技有限公司 Method for completing chip design integrated functions by forms

Cited By (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107438048A (en) * 2016-05-25 2017-12-05 宝沃汽车(中国)有限公司 CAN protocol generation method, device and there is its vehicle
CN106603482A (en) * 2016-05-26 2017-04-26 欣旺达电子股份有限公司 Method and device for automatically generating CAN communication protocol code
CN106603482B (en) * 2016-05-26 2023-01-13 欣旺达电动汽车电池有限公司 Method and device for automatically generating CAN communication protocol code
CN106534267A (en) * 2016-10-19 2017-03-22 中国银行股份有限公司 File uploading and resolving method and device
CN106817366A (en) * 2016-12-31 2017-06-09 惠州市蓝微新源技术有限公司 A kind of CAN document analysis and again store method
CN107247582A (en) * 2017-04-14 2017-10-13 惠州市蓝微新源技术有限公司 It is a kind of to automatically generate the method that CAN sends and receives code
CN107479526A (en) * 2017-04-24 2017-12-15 宝沃汽车(中国)有限公司 The source file automatic generation method and system of CAN signal
CN108600192A (en) * 2018-04-03 2018-09-28 南京越博动力系统股份有限公司 A kind of DBC document analysis and message analysis method based on regular expression
CN108600192B (en) * 2018-04-03 2021-03-30 南京越博动力系统股份有限公司 Regular expression based DBC file analysis and message analysis method
CN112416324A (en) * 2020-11-24 2021-02-26 歌尔光学科技有限公司 Script function implementation method based on python language, terminal equipment and storage medium
CN112416324B (en) * 2020-11-24 2024-02-09 歌尔科技有限公司 Script function implementation method based on python language, terminal equipment and storage medium
CN113626390A (en) * 2021-08-20 2021-11-09 中国第一汽车股份有限公司 BB file generation method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN104834510B (en) 2018-06-19

Similar Documents

Publication Publication Date Title
CN104834510A (en) Method and device for generating CAN (Controller Area Network) protocol code source file
CN107273286B (en) Scene automatic test platform and method for task application
CN106293664A (en) Code generating method and device
CN103559449B (en) The detection method of a kind of code change and device
CN103729186A (en) Method for generating multi-channel apk file packages in batches
CN104011723A (en) Boolean logic in a state machine lattice
CN103309904A (en) Method and device for generating data warehouse ETL (Extraction, Transformation and Loading) codes
CN105354239A (en) Configuration data processing model based processing center data stream processing method
CN104699613B (en) A kind of spacecraft-testing demand automatic creation system and its method
CN104268072A (en) Graphical script editor and method for fast developing communication equipment testing script
CN103903086A (en) Method and system for developing management information system based on service model driving
US20160350087A1 (en) Parsing source code into a linear array
CN106030524A (en) Method and device for visually implementing software code
CN104731588B (en) Page layout document generating method and page layout file creating apparatus
US20160350082A1 (en) Hardware/software agnostic design generation
CN101675415B (en) Program pattern analyzer, pattern appearance status information production method, pattern information generating device, and program
CN105468797A (en) Information processing method and apparatus
US20180330026A1 (en) Exceptional logic element management
CN105488089A (en) Automatic generation method and system of quality evaluation report
CN110019111A (en) Data processing method, device, storage medium and processor
CN107526746A (en) The method and apparatus of management document index
CN104090995B (en) The automatic generation method of rebar unit grids in a kind of ABAQUS tire models
CN105279138A (en) Automatic generation system of message research report
CN104424239A (en) Resource file loading method and device
CN110221577A (en) Numerical control device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
EXSB Decision made by sipo to initiate substantive examination
SE01 Entry into force of request for substantive examination
TA01 Transfer of patent application right

Effective date of registration: 20180416

Address after: No. 188, Miyun District, Miyun District, Beijing, Beijing

Applicant after: Beijing treasure Car Co.,Ltd.

Address before: 102206 Changping District City, Shahe, Sha Yang Road, Beijing

Applicant before: BEIQI FOTON MOTOR Co.,Ltd.

TA01 Transfer of patent application right
GR01 Patent grant
GR01 Patent grant
CP03 Change of name, title or address

Address after: No. 188, Miyun District, Miyun District, Beijing, Beijing

Patentee after: Beijing baowo Automobile Co.,Ltd.

Country or region after: China

Address before: No. 188, Miyun District, Miyun District, Beijing, Beijing

Patentee before: Beijing treasure Car Co.,Ltd.

Country or region before: China

CP03 Change of name, title or address
TR01 Transfer of patent right

Effective date of registration: 20240206

Address after: 102206, Beijing, Shahe, Changping District Town, Sha Yang Road, Lao Wan Village North

Patentee after: BEIQI FOTON MOTOR Co.,Ltd.

Country or region after: China

Address before: No. 188, Miyun District, Miyun District, Beijing, Beijing

Patentee before: Beijing baowo Automobile Co.,Ltd.

Country or region before: China

TR01 Transfer of patent right