CN113824621B - CAN communication method based on signals and CAN controller - Google Patents
CAN communication method based on signals and CAN controller Download PDFInfo
- Publication number
- CN113824621B CN113824621B CN202111107022.4A CN202111107022A CN113824621B CN 113824621 B CN113824621 B CN 113824621B CN 202111107022 A CN202111107022 A CN 202111107022A CN 113824621 B CN113824621 B CN 113824621B
- Authority
- CN
- China
- Prior art keywords
- signal
- function code
- code information
- target
- data frame
- 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.)
- Active
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
- H04L12/40006—Architecture of a communication node
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/901—Indexing; Data structures therefor; Storage structures
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/903—Querying
- G06F16/9032—Query formulation
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
- H04L2012/40208—Bus networks characterized by the use of a particular bus standard
- H04L2012/40215—Controller Area Network CAN
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02P—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
- Y02P90/00—Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
- Y02P90/02—Total factory control, e.g. smart factories, flexible manufacturing systems [FMS] or integrated manufacturing systems [IMS]
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Software Systems (AREA)
- Mathematical Physics (AREA)
- Computational Linguistics (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Communication Control (AREA)
Abstract
The invention provides a signal-based CAN communication method and a CAN controller. The method is applied to the CAN controller and comprises the following steps: the function code information module receives the target data frame and identifies target function code information in the target data frame according to a preset function code information identification mode; the function code information module sends the index information of the signal numerical value area corresponding to the target function code information to the signal numerical value area module; the signal value area module searches all signals corresponding to the target function code information according to the signal value area index information; and the signal numerical region module processes the target data frame according to the respective corresponding preset processing modes of all the signals. The invention CAN solve the problem of complicated protocol code compiling in adapting to different CAN communication protocols.
Description
Technical Field
The invention relates to the technical field of data communication, in particular to a signal-based CAN communication method and a CAN controller.
Background
A Controller Area Network (CAN) bus is a serial communication protocol bus, and is increasingly emphasized by people due to its high performance, high reliability and unique design, and is widely used in many fields, such as the field of automobile communication.
At present, a plurality of modules that charge in the electric automobile fills electric pile are generally connected to and carry out mutual communication on the CAN bus, fill electric pile complete machine and also generally CAN carry out the CAN communication with the external world. As the functional requirements become more complex, the communication protocol based on the CAN also become more complex and more varied according to different car factories or charging stations. In order to adapt to different CAN communication protocols, corresponding protocol codes are often required to be written for various CAN communication protocols, and the problem of complex operation exists.
Disclosure of Invention
The embodiment of the invention provides a signal-based CAN communication method and a CAN controller, which aim to solve the problem of complicated protocol code compiling in the process of adapting to different CAN communication protocols.
In a first aspect, an embodiment of the present invention provides a signal-based CAN communication method, which is applied to a CAN controller, where the CAN controller includes a function code information module and a signal value area module, and the method includes:
the function code information module receives the target data frame and identifies target function code information in the target data frame according to a preset function code information identification mode;
the function code information module sends the index information of the signal numerical value area corresponding to the target function code information to the signal numerical value area module;
the signal value area module searches all signals corresponding to the target function code information according to the signal value area index information;
and the signal numerical region module processes the target data frame according to the respective corresponding preset processing modes of all the signals.
In a second aspect, an embodiment of the present invention provides a CAN controller, including a function code information module and a signal value area module, where:
the function code information module is used for receiving the target data frame, identifying target function code information in the target data frame according to a preset function code information identification mode, and sending signal numerical value area index information corresponding to the target function code information to the signal numerical value area module;
and the signal value area module is used for searching all signals corresponding to the target function code information according to the signal value area index information and processing the target data frame according to the preset processing modes corresponding to all the signals.
In a third aspect, an embodiment of the present invention provides a CAN controller, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, the steps of the method according to the first aspect are implemented.
The embodiment of the invention provides a signal-based CAN communication method and a CAN controller, wherein an ID information module of the CAN controller CAN receive a target data frame and identify target function code information in the target data frame according to a preset function code information identification mode. And then, the function code information module sends the signal numerical value area index information corresponding to the target function code information to the signal numerical value area module. And then, the signal value area module searches all signals corresponding to the target function code information according to the signal value area index information. Therefore, the signal value area module processes the target data frame according to the respective corresponding preset processing modes of all the signals.
Therefore, the unified communication architecture for different CAN communication protocols carrying multiple signals is provided, the corresponding protocol codes do not need to be independently compiled for different types of CAN communication protocols, for different CAN communication protocols, the function codes of the CAN communication protocols and the preset processing modes corresponding to the signals are only needed to be configured in advance, the codes do not need to be modified, and the advantage of strong reusability is achieved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required to be used in the embodiments or the prior art description will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings may be obtained according to these drawings without inventive labor.
Fig. 1 is a flowchart illustrating steps of a signal-based CAN communication method according to an embodiment of the present invention;
fig. 2 is a schematic diagram of a communication architecture according to an embodiment of the present invention;
fig. 3 is a schematic flow chart illustrating a receiving processing function of a signal value field module according to an embodiment of the present invention;
fig. 4 is a schematic flow chart illustrating a sending processing function of a signal value field module according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of a process flow of packing data according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of a CAN controller according to an embodiment of the present invention;
fig. 7 is a schematic diagram of a CAN controller according to an embodiment of the present invention.
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 make the objects, technical solutions and advantages of the present invention more apparent, the following description is made by way of specific embodiments with reference to the accompanying drawings.
As described in the background art, in order to adapt to different CAN communication protocols, it is often necessary to write corresponding protocol codes for various CAN communication protocols, and there is a problem of cumbersome operation.
According to research, the CAN communication protocol generally has the following functions:
1. a certain parameter or parameters are set.
2. A certain parameter or parameters are read.
3. A loop is required to obtain a certain parameter or parameters.
In other words, the CAN communication protocol CAN be divided into setting and readback of the reception protocol, and cyclic transmission parameters of the transmission protocol. The processed data frame, whether a receiving protocol or a transmitting protocol, is composed of an ID region and a data region, wherein some protocols carry one or more information in the ID region and some protocols carry one or more information in the data region. For convenience of description, information in the ID area or the data area may be collectively referred to as a signal, and thus, one or more signals may be carried in a data frame. As shown in table one, a protocol example corresponding to various signals is shown.
Watch 1
It can be seen that the signals may be characterized in the ID as well as in the data, and that there are typically one or more signals per protocol. In addition, whether the signal is characterized in the ID area or the data area, the data frame (i.e. the sum of the ID and all data of the data) has a function code for characterizing the function. For example, similar to signal 1 in protocol 1 and protocol 2, the protocol 1 function code is in the data area (the function codes are different under the same ID), and the protocol 2 function code is in the ID area (there are differences in part of the IDs, and the function codes are different); for protocol 3, the function code characterizing the function is the ID number itself of protocol 3, and then protocol 3 has signal 3: the ID number. In addition, each function code may include one or more signals, and when the function codes are different, the function and the number of the signals represented by the data frame may be different.
Based on this, because the type of CAN communication protocol is complicated and changeable, lead to CAN not unified the processing, do not have the commonality. Therefore, in order to communicate with the modules adopting different protocols, corresponding protocol codes need to be independently written for different types of CAN communication protocols, and the problem of complex operation exists.
In order to solve the problem of the prior art, embodiments of the present invention provide a signal-based CAN communication method and a CAN controller. First, a signal-based CAN communication method provided in an embodiment of the present invention will be described.
Referring to fig. 1, it shows a flowchart of an implementation of the signal-based CAN communication method provided in the embodiment of the present invention, including the following steps:
step S110, the function code information module receives the target data frame, and identifies the target function code information in the target data frame according to a preset function code information identification mode.
In some embodiments, the target data frame may be any one of the data frames received by the CAN controller. After receiving the target data frame, the function code information module may identify the function code information in the target data frame according to a preset function code information identification mode, where the function code information may be referred to as target function code information.
A specific identification method of the preset function code information is given below. Firstly, the ID number of the target data frame can be identified, and then the numerical values of the positions corresponding to the starting address and the address length of the function code are respectively extracted from the target data frame according to the starting address and the address length of the function code which are configured in advance and correspond to the ID number of the target data frame, wherein the numerical values are target function code information.
Step S120, the function code information module sends the signal value area index information corresponding to the target function code information to the signal value area module.
In some embodiments, the signal value section index information includes a signal value section start address and a signal value section address length.
Specifically, the function code information module may pre-configure index information of a signal value area of the CAN communication protocol corresponding to different function code information based on a received corresponding control instruction, for example, a control instruction sent to the function code information module by a technician through corresponding equipment, and may locate the signal value area corresponding to the corresponding function code information through the index information of the signal value area, where all signals corresponding to the function code information are pre-configured, and a corresponding pre-set processing mode, such as a processing mode of reading or writing, sending, and the like.
Step S130, the signal value region module searches for all signals corresponding to the target function code information according to the signal value region index information.
In some embodiments, the signal value range module may determine a signal value range formed by a start address of the signal value range and an address length of the signal value range after receiving the signal value range index information, and then may determine signals belonging to the signal value range as all signals corresponding to the target function code information. Therefore, the signal numerical value area module can search all signals corresponding to the target function code information.
Step S140, the signal value region module processes the target data frame according to the preset processing modes corresponding to all the signals.
In some embodiments, when all the signals corresponding to the target function code information are found by the signal value area module, the target data frame may be processed sequentially according to the arrangement sequence of the signals in the signal value area and the preset processing mode of the corresponding signals.
In some embodiments, the signal value area module may pre-record respective signals of a plurality of preset function code information and preset processing modes thereof; the target function code information is any one of a plurality of preset function code information.
Optionally, the type of the target function code information may be determined according to the type of the target function code information, where the type of the target function code information includes a receiving processing type and a sending processing type. As for the receiving processing type, the signal may include a read flag start address, a read flag address length, a read true value, and a response ID number, and accordingly, the specific processing of step S140 may be as follows: under the condition that the type of the target function code information is a receiving processing type, a signal value area module extracts a reading mark value of a position corresponding to a reading mark initial address and a reading mark address length of a target signal from a target data frame; the target signal is any one of all signals; if the reading mark value is the same as the reading true value of the target signal, reading the target data frame; if the read flag value and the read true value of the target signal are not the same, a write process is performed on the target data frame.
In some embodiments, the signal may further include a signal start address, a signal address length, a logic signal flag, and a logic true value or a logic false value, and accordingly, the specific procedure of the writing process may be as follows: extracting a signal value of a position corresponding to a signal start address and a signal address length of a target signal from a target data frame; if the logic signal mark corresponding to the signal value is a non-logic mark, writing the signal value into a position corresponding to the target function code information; if the logic signal sign corresponding to the signal value is a logic sign, judging whether the signal value is a logic true value; if the signal value is a logic true value, setting the position corresponding to the target function code information as 1; and if the signal value is a logic false value, setting the position corresponding to the target function code information as 0.
Optionally, for the target function code information of the sending processing type, correspondingly, the specific processing in step S140 may be as follows: under the condition that the type of the target function code information is a sending processing type, the signal value area module extracts signal values of corresponding positions corresponding to respective signal starting addresses and signal address lengths of all signals in a target data frame; the target signal is any one of all signals; packing the signal values of all corresponding positions according to a preset packing mode to obtain a data packet; and sending the data packet according to the response ID number, the data size end format and the CAN port number corresponding to the target function code information.
To better understand the signal-based CAN communication method provided by the embodiment of the present invention, as shown in fig. 2, a schematic diagram of a communication architecture is provided, where the communication architecture may be designed by using a C + + object-oriented method, and the communication architecture has the following functions:
the communication structure comprises a function code information module and a signal numerical area module, and by using the modules, various different signals sig corresponding to the function codes of the communication structure CAN be accurately found for data frames of a CAN communication protocol carrying multiple signals, and then the communication structure is set one by one or read back according to different signals.
The function 2 and the function code information module can register each function code information fn, the initial address of the signal value area of the function code information fn, and the address length of the signal value area of the function code information fn in advance, so that all signals contained in the data frame can be found, and meanwhile, one function code uniquely corresponds to one signal position, so that the specific address of the signal can be indexed through the index information of the signal value area, such as the initial address of the signal value area, the address of the signal value area, and the like.
The function 3 and semaphore area module can register the read tag address length, read true value, and response ID number of the signal corresponding to different function code information, for identifying whether the received data is set or read. In addition, the name value, signal start address, signal address length, logic signal flag, logic true value, logic false value, resolution, and offset of the signal corresponding to different function code information may also be registered for identifying what function the received or transmitted data specifically represents. It is worth mentioning that the signals corresponding to the same function code can be written together, the signals corresponding to different function codes are partitioned, and the signals corresponding to the same function code are decoupled.
Thus, the signal value area module can register two types of information, wherein the first type is reading the length of a mark address, reading a true value and a response ID number; the second category is signal name value, signal start address, signal address length, logic flag, logic true value, logic false value, resolution, offset. Thus, through the first type of information, setting or read-back can be determined, and if the read-back operation is performed, the response ID number also needs to be determined; through the second type of information, the function preset by the information can be determined when the received information is set, and the packet sending mode of the sent information and the read-back information can be determined at the same time.
It CAN be seen that the signal value area module, as a key module for processing data frames of the CAN communication protocol carrying "multiple signals", has two main functions: receiving and processing functions, such as setting and readback; and a loop transmission processing function.
It should be noted that some CAN communication protocols are only write-in operations and do not represent read-write functions by signals, and at this time, only corresponding true values need to be written into 0 xfffffffff, and then the read flag start address and the address length are written into a number with a small data length to ensure that the read flag start address and the read flag start address are not 0 xfffffffffff, so that a 'non-read' operation CAN be given, and the write-in operation is realized. In addition, the logic signal, i.e. the control operation signal, for example, 0xAA indicates power on, and 0x55 indicates power off; the value signal, i.e., the operation signal of the value, such as 130 indicates that the current value is set to 130A.
By using the functions, different CAN communication protocols carrying 'multiple signals' CAN be unified under the communication framework, the corresponding protocol codes do not need to be independently compiled for the different types of CAN communication protocols, for the different CAN communication protocols, the function codes of the CAN communication protocols and the preset processing modes corresponding to the signals are only needed to be configured in advance, the codes do not need to be modified, and the advantage of strong reusability is achieved.
Referring to fig. 3, a detailed description will be given of a data processing flow of the receiving processing function of the signal value field module.
Firstly, after a data frame is received, traversing all signals in a signal value area corresponding to a certain function code in the data frame one by one, and then processing each signal according to a preset processing mode until all signals in the signal value area corresponding to the certain function code are completely traversed. When each signal is processed in a preset mode, the specific value of the data frame at the corresponding position can be obtained according to the starting address of the reading mark and the address length of the reading mark, and then the specific value is compared with a preset reading true value, if the specific value is the same as the reading true value, the reading operation is performed, otherwise, the writing operation is considered, and the data setting is performed.
Specifically, if the operation is a read operation, the current function code and the response ID are stored, and the read flag bit is set, which facilitates subsequent read-back packaging processing. If the operation is a write operation, the signal value of the data frame is obtained according to the signal initial address and the address length thereof, and whether the signal is a logic signal or a non-logic signal is judged at the same time. If the signal is a logic signal, it needs to further determine whether it is a logic true value (true) or a logic false value (false). If the logic true value is true, setting the corresponding position under the function code to be 1; if the logic false value is found, the corresponding position under the function code is set to 0.
Therefore, the receiving protocol function operation can be well processed through the receiving processing function of the signal value area module.
Referring to fig. 4, a data processing flow of the sending processing function of the signal value field module will be described in detail.
Firstly, after a data frame is received, assigning the ID number value and the function code value of the parameter to an ID variable and a function code variable, and initializing a high 32-bit data variable and a low 32-bit data variable to be 0. And traversing all signals in a signal numerical region corresponding to a certain function code in the data frame one by one, acquiring the signal value of the received data frame according to the signal starting address and the address length thereof, and packing the signals one by one according to a specified format until all the signals in the signal numerical region corresponding to the certain function code are completely traversed. And then, judging whether the sending data is in a big-end format or a small-end format, respectively integrating according to the corresponding formats, resetting the functional code and generating a sending signal to the bottom layer, wherein the information carried by the sending signal is an ID number, high 32-bit data, low 32-bit data and a CAN sending port number.
It should be noted that, if the read-back operation is performed, the following determination process is only required to be added before the sending process function: reading whether the flag bit is set; if the ID variable is set, sending processing is carried out, then the reading flag bit is cleared to 0, and meanwhile the response ID is used as a parameter, namely, the flow is entered to enable the ID variable to be assigned by the response ID.
It should be noted that, the above process of packing data according to a specified format is actually a process of obtaining a final ID number, 32 upper bits and 32 lower bits, and for better understanding of the process, as shown in fig. 5, the following describes the process of packing data in detail.
Firstly, judging whether a function code entering a packing function is a logic signal or a numerical signal, and if the function code is the numerical signal, directly converting the function code into a required numerical value according to the registered resolution offset; if the logic signal is a logic signal, it is necessary to determine whether the logic value is true (1) or false (0). If true, synthesizing the required value by using a logic true value; if false, the desired value is synthesized using a logical false value. Then, judging whether the signal is in an ID area or a data area, and if the signal is in the ID area, re-synthesizing an ID number according to the signal initial address and the address length thereof; if the data area is provided, the synthesized protocol value is placed according to the appointed data position according to the signal starting address and the address length thereof so as to obtain the upper 32-bit data and the lower 32-bit data.
In the embodiment of the invention, the ID information module of the CAN controller CAN receive the target data frame and identify the target function code information in the target data frame according to the preset function code information identification mode. And then, the function code information module sends the signal value area index information corresponding to the target function code information to the signal value area module. And then, the signal value area module searches all signals corresponding to the target function code information according to the signal value area index information. Therefore, the signal value area module processes the target data frame according to the respective corresponding preset processing modes of all the signals. Therefore, the unified communication architecture for different CAN communication protocols carrying multiple signals is provided, the corresponding protocol codes do not need to be independently compiled for different types of CAN communication protocols, for different CAN communication protocols, the function codes of the CAN communication protocols and the preset processing modes corresponding to the signals are only needed to be configured in advance, the codes do not need to be modified, and the advantage of strong reusability is achieved.
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.
The following are embodiments of the apparatus of the invention, reference being made to the corresponding method embodiments described above for details which are not described in detail therein.
Fig. 6 shows a schematic structural diagram of a CAN controller provided in an embodiment of the present invention, and for convenience of description, only parts related to the embodiment of the present invention are shown, which are detailed as follows:
as shown in fig. 6, the CAN controller 600 includes a function code information module 610 and a signal value field module 620, wherein:
a function code information module 610, configured to receive the target data frame, identify target function code information in the target data frame according to a preset function code information identification manner, and send signal value area index information corresponding to the target function code information to the signal value area module 620;
and a signal value area module 620, configured to search all signals corresponding to the target function code information according to the signal value area index information, and process the target data frame according to a preset processing manner corresponding to each of all signals.
In one possible implementation, the signal value field index information includes a signal value field start address and a signal value field address length.
In one possible implementation, the signal value region module is further configured to:
determining a signal value area range formed by a signal value area initial address and a signal value area address length;
and determining the signals belonging to the range of the signal value area as all signals corresponding to the target function code information.
In a possible implementation manner, the signal value area module records respective signals of multiple preset function code information and preset processing modes thereof in advance; the target function code information is any one of a plurality of preset function code information.
In one possible implementation, the signals include a read tag start address, a read tag address length, a read true value, a response ID number;
correspondingly, the signal value area module is further configured to:
under the condition that the type of the target function code information is a receiving processing type, a signal value area module extracts a reading mark value of a position corresponding to a reading mark initial address and a reading mark address length of a target signal from a target data frame; the target signal is any one of all signals;
if the reading flag value is the same as the reading true value of the target signal, performing reading processing on the target data frame;
if the read flag value and the read true value of the target signal are different, a write process is performed on the target data frame.
In one possible implementation, the signal further includes a signal start address, a signal address length, a logic signal flag, and a logic true value or a logic false value;
correspondingly, the signal value area module is further configured to:
extracting a signal value of a position corresponding to a signal start address and a signal address length of a target signal from a target data frame;
if the logic signal mark corresponding to the signal value is a non-logic mark, writing the signal value into a position corresponding to the target function code information;
if the logic signal sign corresponding to the signal value is a logic sign, judging whether the signal value is a logic true value;
if the signal value is a logic true value, setting the position corresponding to the target function code information as 1; and if the signal value is a logic false value, setting the position corresponding to the target function code information as 0.
In one possible implementation, the signal value region module is further configured to:
under the condition that the type of the target function code information is a sending processing type, the signal value area module extracts signal values of corresponding positions corresponding to respective signal starting addresses and signal address lengths of all signals in a target data frame; the target signal is any one of all signals;
packing the signal values of all corresponding positions according to a preset packing mode to obtain a data packet;
and sending the data packet according to the response ID number, the data size end format and the CAN port number corresponding to the target function code information.
In the embodiment of the invention, the ID information module of the CAN controller CAN receive the target data frame and identify the target function code information in the target data frame according to the preset function code information identification mode. And then, the function code information module sends the signal value area index information corresponding to the target function code information to the signal value area module. And then, the signal value area module searches all signals corresponding to the target function code information according to the signal value area index information. Therefore, the signal value area module processes the target data frame according to the respective corresponding preset processing modes of all the signals. Therefore, the unified communication architecture for different CAN communication protocols carrying multiple signals is provided, the corresponding protocol codes do not need to be independently compiled for different types of CAN communication protocols, for different CAN communication protocols, the function codes of the CAN communication protocols and the preset processing modes corresponding to the signals are only needed to be configured in advance, the codes do not need to be modified, and the advantage of strong reusability is achieved.
Fig. 7 is a schematic diagram of the CAN controller 7 according to the embodiment of the present invention. As shown in fig. 7, the CAN controller 7 of this embodiment includes: a processor 70, a memory 71 and a computer program 72 stored in said memory 71 and executable on said processor 70. The processor 70, when executing the computer program 72, implements the steps of the various embodiments of the signal-based CAN communication method described above, such as steps 110 to 140 shown in fig. 1. Alternatively, the processor 70, when executing the computer program 72, implements the functions of the modules in the above device embodiments, such as the functions of the modules 610 to 620 shown in fig. 6.
Illustratively, the computer program 72 may be partitioned into one or more modules that are stored in the memory 71 and executed by the processor 70 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 to describe the execution of the computer program 72 in the CAN controller 7. For example, the computer program 72 may be divided into the modules 610 to 620 shown in fig. 6.
The CAN controller 7 may include, but is not limited to, a processor 70, a memory 71. It will be appreciated by a person skilled in the art that fig. 7 is only an example of a CAN controller 7 and does not constitute a limitation of the CAN controller 7 and may comprise more or less components than shown, or combine certain components, or different components, e.g. the CAN controller may also comprise input output devices, network access devices, buses, etc.
The Processor 70 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field 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 memory 71 may be an internal storage unit of the CAN controller 7, such as a hard disk or a memory of the CAN controller 7. The memory 71 may also be an external storage device of the CAN controller 7, such as a plug-in hard disk provided on the CAN controller 7, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like. Further, the memory 71 may also include both an internal storage unit and an external storage device of the CAN controller 7. The memory 71 is used to store the computer program and other programs and data required by the CAN controller. The memory 71 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 type of logical function division, and other division manners may be available in actual implementation, for example, multiple 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 through some interfaces, indirect coupling or communication connection of 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 position, or may be distributed on multiple 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 module, if implemented in the form of a software functional unit and sold or used as a separate product, may be stored in a computer-readable storage medium. Based on such understanding, all or part of the flow in the method according to the above embodiments may 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 above embodiments of the signal-based CAN communication method 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.
Claims (8)
1. A CAN communication method based on signals is characterized in that the method is applied to a CAN controller, the CAN controller comprises a function code information module and a signal value area module, and the method comprises the following steps:
the function code information module receives a target data frame and identifies target function code information in the target data frame according to a preset function code information identification mode;
the function code information module sends the signal numerical value area index information corresponding to the target function code information to the signal numerical value area module;
the signal value area module searches all signals corresponding to the target function code information according to the signal value area index information;
the signal numerical region module processes the target data frame according to the respective corresponding preset processing modes of all the signals;
the preset function code information identification mode is as follows: identifying an ID number of the target data frame; according to a preset function code starting address and address length corresponding to an ID number of a target data frame, respectively extracting numerical values of positions corresponding to the function code starting address and the address length from the target data frame, and determining the numerical values of the positions corresponding to the function code starting address and the address length as target function code information;
the signal numerical region module records respective signals of a plurality of preset function code information and preset processing modes thereof in advance; the target function code information is any one of the preset function code information;
the signal value area module processes the target data frame according to the respective corresponding preset processing modes of all the signals, and the processing method comprises the following steps: under the condition that the type of the target function code information is a sending processing type, the signal value area module extracts signal values of corresponding positions corresponding to respective signal starting addresses and signal address lengths of all the signals from the target data frame; packing the signal numerical values of all the corresponding positions according to a preset packing mode to obtain a data packet; and sending the data packet according to the response ID number, the data size end format and the CAN port number corresponding to the target function code information.
2. The method of claim 1, wherein the semaphore value region index information comprises a semaphore value region start address and a semaphore value region address length.
3. The method of claim 2, wherein the signal value field module searches for all signals corresponding to the target function code information according to the signal value field index information, including:
determining a signal value area range formed by the signal value area initial address and the signal value area address length;
and determining the signals belonging to the range of the signal value area as all the signals corresponding to the target function code information.
4. The method of claim 1, wherein the signals include a read tag start address, a read tag address length, a read true value, a response ID number;
the signal value area module processes the target data frame according to the respective corresponding preset processing modes of all the signals, and the processing method includes:
under the condition that the type of the target function code information is a receiving processing type, the signal value area module extracts a reading mark value of a position corresponding to a reading mark initial address and a reading mark address length of a target signal from the target data frame; wherein the target signal is any one of the signals;
if the reading mark value is the same as the reading true value of the target signal, performing reading processing on the target data frame;
and if the reading mark value is different from the reading true value of the target signal, performing writing processing on the target data frame.
5. The method of claim 4, wherein the signal further comprises a signal start address, a signal address length, a logic flag, and a logic true value or a logic false value;
the performing write processing on the target data frame includes:
extracting a signal value of a position corresponding to a signal start address and a signal address length of a target signal from the target data frame;
if the logic signal mark corresponding to the signal value is a non-logic mark, writing the signal value into a position corresponding to the target function code information;
if the logic signal sign corresponding to the signal value is a logic sign, judging whether the signal value is a logic true value;
if the signal value is a logic true value, setting the position corresponding to the target function code information as 1; and if the signal value is a logic false value, setting the position corresponding to the target function code information as 0.
6. The CAN controller is characterized by comprising a function code information module and a signal value area module, wherein:
the function code information module is used for receiving a target data frame, identifying target function code information in the target data frame according to a preset function code information identification mode, and sending signal numerical value area index information corresponding to the target function code information to the signal numerical value area module;
the signal value area module is used for searching all signals corresponding to the target function code information according to the signal value area index information and processing the target data frame according to the preset processing modes corresponding to all the signals;
the preset function code information identification mode is as follows: identifying an ID number of the target data frame; respectively extracting numerical values of positions corresponding to the function code starting address and the address length from a target data frame according to a preset function code starting address and address length corresponding to an ID number of the target data frame, and determining the numerical values of the positions corresponding to the function code starting address and the address length as target function code information;
the signal numerical region module records respective signals of a plurality of preset function code information and preset processing modes thereof in advance; the target function code information is any one of the preset function code information;
the signal value area module is further configured to:
under the condition that the type of the target function code information is a sending processing type, the signal value area module extracts signal values of corresponding positions corresponding to respective signal starting addresses and signal address lengths of all the signals from the target data frame; packing the signal numerical values of all the corresponding positions according to a preset packing mode to obtain a data packet; and sending the data packet according to the response ID number, the data size end format and the CAN port number corresponding to the target function code information.
7. The CAN controller of claim 6, wherein the signal value field index information comprises a signal value field start address and a signal value field address length.
8. A CAN controller comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor when executing the computer program implements the steps of the method according to any one of claims 1 to 5.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202111107022.4A CN113824621B (en) | 2021-09-22 | 2021-09-22 | CAN communication method based on signals and CAN controller |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202111107022.4A CN113824621B (en) | 2021-09-22 | 2021-09-22 | CAN communication method based on signals and CAN controller |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN113824621A CN113824621A (en) | 2021-12-21 |
| CN113824621B true CN113824621B (en) | 2023-04-14 |
Family
ID=78920802
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202111107022.4A Active CN113824621B (en) | 2021-09-22 | 2021-09-22 | CAN communication method based on signals and CAN controller |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN113824621B (en) |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN115438713B (en) * | 2022-07-29 | 2026-01-20 | 科华数据股份有限公司 | Winding group number identification method for electric module, electric module and storage medium |
Citations (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113177015A (en) * | 2021-05-24 | 2021-07-27 | 石家庄通合电子科技股份有限公司 | Frame header-based serial port communication method and serial port chip |
Family Cites Families (9)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6363083B1 (en) * | 1999-03-12 | 2002-03-26 | Otis Elevator Company | Bilevel node identifiers in control area network (CAN) protocol |
| CN101626333B (en) * | 2009-08-07 | 2011-11-23 | 北京和利时电机技术有限公司 | Controller area network (CAN) bus system and application layer communication method in same |
| CN101808132A (en) * | 2010-03-23 | 2010-08-18 | 武汉若比特机器人有限公司 | Communication method of application layer in CAN bus system |
| CN104331292B (en) * | 2014-11-03 | 2019-01-22 | 重庆邮电大学 | A configuration generation method for protocol conversion of Internet of Vehicles middleware |
| CN106549840B (en) * | 2016-12-09 | 2020-11-06 | 滕敏 | Data interaction system, method and device |
| CN106712902B (en) * | 2016-12-19 | 2019-09-27 | 上海东软载波微电子有限公司 | Coding, coding/decoding method and encoder, the decoder of Modbus document of agreement |
| CN106952184B (en) * | 2017-01-22 | 2022-07-22 | 斑马信息科技有限公司 | Automobile service management system, automobile service management method and adaptation method thereof |
| CN112235302B (en) * | 2020-10-15 | 2023-03-24 | 天津津航计算技术研究所 | Protocol analysis method suitable for multiple buses |
| CN113381974A (en) * | 2021-05-06 | 2021-09-10 | 北京工业大学 | Protocol conversion method between field bus and Modbus-TCP applied to special communication |
-
2021
- 2021-09-22 CN CN202111107022.4A patent/CN113824621B/en active Active
Patent Citations (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113177015A (en) * | 2021-05-24 | 2021-07-27 | 石家庄通合电子科技股份有限公司 | Frame header-based serial port communication method and serial port chip |
Also Published As
| Publication number | Publication date |
|---|---|
| CN113824621A (en) | 2021-12-21 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN113127338A (en) | Firmware testing method, server and computer readable storage medium | |
| CN103092798B (en) | The method of the access means under SOC(system on a chip) and bus | |
| CN112231251B (en) | Board card slot identification method and device, communication equipment and readable storage medium | |
| CN113852531B (en) | CAN communication method and CAN controller for function code matching | |
| CN112558584B (en) | Diagnostic data acquisition method and device and diagnostic equipment | |
| CN109426796A (en) | Detection method of license plate, apparatus and system | |
| CN116996601A (en) | Message format conversion method, device, electronic equipment and storage medium | |
| CN113824621B (en) | CAN communication method based on signals and CAN controller | |
| CN111552268A (en) | Vehicle remote diagnosis method, equipment connector and vehicle connector | |
| CN112202632A (en) | Message extraction method and device, electronic equipment and computer readable storage medium | |
| CN112910838B (en) | Composite protocol analysis method, device, equipment, system and storage medium | |
| CN113177015B (en) | Frame header-based serial port communication method and serial port chip | |
| CN113177014A (en) | Serial port communication method based on inspection mode and serial port chip | |
| CN115474164B (en) | Bluetooth broadcast filtering method and system | |
| CN112423104A (en) | Audio mixing method and system for multi-channel audio in live scene | |
| CN113079052B (en) | Model training method, device, equipment and storage medium, and method and device for identifying data of Internet of things | |
| CN113852532B (en) | CAN communication method for machine number matching and CAN controller | |
| CN111898713A (en) | Reading method and device of multi-protocol composite electronic tag | |
| CN114326666A (en) | Vehicle parameter configuration method and device, electronic equipment and storage medium | |
| CN110874195B (en) | Printing language identification method, device, electronic equipment and storage medium | |
| CN108491745B (en) | Data acquisition method and device and computer readable storage medium | |
| CN115938022B (en) | Vehicle entity key safety authentication method and system | |
| CN220085381U (en) | Device for remote reading and writing of serial port equipment | |
| US20240362160A1 (en) | Method for extracting data from a data memory | |
| TW201339984A (en) | Radio frequency identification reader |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |

