Detailed Description
The following detailed description of specific embodiments of the present disclosure is provided in connection with the accompanying drawings. It should be understood that the detailed description and specific examples, while indicating the present disclosure, are given by way of illustration and explanation only, not limitation.
Firstly, an application scenario of the present disclosure is introduced, and the present disclosure is mainly applied to a process of automatically converting an LIN communication protocol file stored in the form of an Excel file into an LDF database file after the design of an LIN communication protocol of a vehicle is completed.
In the related art, a special LIN communication database file editing software (such as LIN Explorer of Vector company) can be used for converting an LIN communication protocol file stored in an Excel file form into an LDF database file, but the information such as nodes, messages, signals, scheduling tables and the like needs to be established one by one according to the LIN communication protocol.
In order to solve the existing problems, the present disclosure provides a file format conversion method, which may acquire a target LIN communication file to be converted, then read information to be converted from the target LIN communication file, and then write the information to be converted into a preset text file according to a preset LDF file format to obtain a converted target LDF file.
Specific embodiments of the present disclosure will be described in detail below with reference to the accompanying drawings.
Fig. 1 is a flowchart illustrating a file format conversion method according to an exemplary embodiment, as shown in fig. 1, the method including the steps of:
in step S101, a target LIN communication file to be converted is acquired.
The target LIN communication file is a file selected by a user and storing a designed LIN communication protocol file, and the target LIN communication file may include a file edited according to a preset format, such as an Excel file or a Word table file.
In step S102, the information to be converted is read from the target LIN communication file.
The information to be converted may include schedule information and at least one piece of message information, where the message information includes node information, message definition information, and signal information, where the schedule information is used to define information such as a transmission cycle, a transmission interval, a message transmission length, and the like of the message information, for example, it is defined in the schedule information that a message may be transmitted every 100ms (i.e., a transmission cycle) and 4 messages are transmitted every time, and a transmission interval between every 2 messages in the 4 messages is 10ms, which is only an example and is not limited by this disclosure.
In general, an LIN network is composed of a master node and one or more slave nodes, where one node may correspond to at least one message, each message also has a node corresponding to the message, and each message includes at least one signal, where the node information may include node attribute information and/or node identification information of the node corresponding to the message, for example, for a vehicle door control LIN network, the vehicle door control LIN network may include a master node, a rearview mirror slave node, a window lifter slave node, and a door lock slave node, where the node attribute information is used to indicate whether the node corresponding to the message is the master node or the slave node, and the node identification information indicates which node specifically is, for example, node name information or node ID information, etc.; the message definition information may include information such as a message name, a message ID, a message sending period, and a message length of the message; the signal information may include information such as a signal name, a signal start position, a signal length, a signal code, a unit, precision, an offset, a signal range, an initial value, a default value, a transceiving node, and the like of a signal included in the message.
In this step, the information to be converted may be read from the target LIN communication file in any one of the following two ways:
mode one, serial read mode
Reading the information in the target LIN communication file line by line from a first preset start line, so as to obtain the schedule table information and at least one piece of message information, wherein the first preset start line may include a message definition start line corresponding to a target message or a schedule table information start line corresponding to the schedule table information, the target message includes any one message, and the first preset start line may include a preset line whose line identifier is a first identifier.
Mode two, parallel read mode
In this step, in order to improve the efficiency of data reading, the information to be converted may also be read in parallel from the target LIN communication file, specifically, a second preset start line corresponding to each piece of message information in the target LIN communication file and a third preset start line corresponding to the scheduling table information are first obtained; and then reading each piece of message information and the scheduling table information in parallel according to the second preset initial line and the third preset initial line.
In step S103, the information to be converted is written into a preset text file according to a preset LDF file format, so as to obtain a converted target LDF file.
The LDF database file is used as a configuration information description file of the LIN bus, all defined elements have a specific standard format, the preset LDF file format is the specific standard format corresponding to the LDF database file, and specific preset fields are correspondingly arranged for different information to be converted in the preset LDF file format.
In this step, a preset field corresponding to the to-be-converted information defined by the preset LDF file format may be determined for each obtained to-be-converted information in the node information, the message definition information, the signal information, and the scheduling table information, then the to-be-converted information is written into the preset field corresponding to the preset text file, and the written preset text file is stored according to a preset storage policy to obtain the target LDF file, where the preset storage policy may be a storage path, a storage file name, and a stored file type for storing the target LDF file selected by a user.
By adopting the method, the target LIN communication file can be automatically converted into the LDF database file without manual editing of a user, the compiling efficiency of the LDF database file is improved, and the condition that the LDF file is edited wrongly can be effectively prevented.
Fig. 2 is a flowchart illustrating a file format conversion method according to an exemplary embodiment, as shown in fig. 2, the method including the steps of:
in step S201, a file format conversion request issued by a user is received, where the file format conversion request includes a file identifier of the target LIN communication file.
The target LIN communication file is a file selected by a user and storing a designed LIN communication protocol file, the target LIN communication file may include a file edited according to a preset format, such as an Excel file or a Word table file, and the file identifier may include a file name or a file storage path of the target LIN communication file.
In an actual application scenario, a user may automatically convert the target LIN communication file into an LDF database file by using file format conversion software, for example, the user may manually load the target LIN communication file on the file format conversion software, then select a saving path, a file name, and a saving format (generally, an LDF file) of the LDF database file after conversion, then may start file format conversion by triggering a "conversion" button, and after obtaining a triggering operation of triggering the conversion button by the user, the terminal may obtain the file format conversion request.
In step S202, the target LIN communication file is acquired according to the file identifier.
In step S203, the information to be converted is read from the target LIN communication file.
The information to be converted may include schedule information and at least one piece of message information, where the message information includes node information, message definition information, and signal information, where the schedule information is used to define information such as a transmission cycle, a transmission interval, a message transmission length, and the like of the message information, for example, it is defined in the schedule information that a message may be transmitted every 100ms (i.e., a transmission cycle) and 4 messages are transmitted every time, and a transmission interval between every 2 messages in the 4 messages is 10ms, which is only an example and is not limited by this disclosure.
In general, an LIN network is composed of a master node and one or more slave nodes, where one node may correspond to at least one message, each message also has a node corresponding to the message, and each message includes at least one signal, where the node information may include node attribute information and/or node identification information of the node corresponding to the message, for example, for a vehicle door control LIN network, the vehicle door control LIN network may include a master node, a rearview mirror slave node, a window lifter slave node, and a door lock slave node, where the node attribute information is used to indicate whether the node corresponding to the message is the master node or the slave node, and the node identification information indicates which node specifically is, for example, node name information or node ID information, etc.; the message definition information may include information such as a message name, a message ID, a message sending period, and a message length of the message; the signal information may include information such as a signal name, a signal start position, a signal length, a signal code, a unit, precision, an offset, a signal range, an initial value, a default value, a transceiving node, and the like of a signal included in the message.
In this step, the information to be converted may be read from the target LIN communication file in either of the following two ways.
Mode one, serial read mode
In a first mode, in an actual application scenario, a designed LIN communication protocol file may be edited and stored according to a preset format (or understood as being edited by using a fixed template), and schedule information and all message information included in the LIN communication file may be stored in the same table, where a first preset start line for storing the information may be predefined in the table, and then the schedule information and the message information may be stored line by line from the first preset start line in the table.
For example, assuming that the target LIN communication file is an Excel file, the first behavior in the Excel file may be preset to the first preset start line, and node information and message definition information for storing a first message in the first preset start line may be predefined, signal information included in the first message is stored in a line next to the first preset start line, and then other message information and schedule information are stored line by line.
Thus, when the information to be converted is read from the target LIN communication file, the information in the target LIN communication file may be read line by line from a first preset start line, so that the schedule table information and at least one piece of the message information may be obtained, where the first preset start line may include a message definition start line corresponding to a target message or a schedule table information start line corresponding to the schedule table information, the target message includes any one message, and the first preset start line may include a preset line whose line identifier is a first identifier.
It should be noted that, when the designed target LIN communication protocol file is edited and stored according to a preset format, the schedule table information may be stored first, and after the schedule table information is stored, the message information is stored continuously, in this case, the schedule table information start line corresponds to the first preset start line; if the message information is stored first, and the scheduling table information is stored continuously after the message information is stored, the first preset initial line corresponding to the situation is the message definition initial line.
In addition, a description is also needed for a judging mode of reading end of serially reading the information to be converted from the target LIN communication protocol file, in the present disclosure, whether the information to be converted is read can be determined by any one of the following two modes, in one possible implementation mode, the last message in the target LIN communication file to be converted can be predefined as a sleep instruction message, so that in one mode, under the condition that the first preset starting line is the starting line of the scheduling table information, whether the sleep instruction message is read is determined; under the condition that the sleep instruction message is determined to be read, the currently read message can be determined to be the last message, so that the information to be converted can be further determined to be read from the target LIN communication file; in another way, it can also be determined that the information to be converted has been read out, if no information has been read out from the target LIN communication file.
Here, whether or not the sleep instruction message is read may be determined by: determining whether the identifier of the corresponding message in the currently read message information is a preset identifier; in a case that the identifier of the message is determined to be the preset identifier, it is determined that the sleep instruction message is read, for example, if it is determined that the message ID of the corresponding message in the currently read message information is 0x3C, it may be determined that the sleep instruction message is read, which is only an example and is not limited by the present disclosure.
A specific implementation of the serial reading of the information to be converted from the target LIN communication file in the present disclosure is described below by way of example.
For example, assuming that the target LIN communication file is an Excel file, and a message corresponding to a first message of the first preset initiation behavior defines an initiation line, a process of serially reading the information to be converted from the Excel file at this time is as follows:
1. reading the definition of a first message from the message definition initial line, and retrieving node attribute, node name, message ID, message period and message length information;
2. reading the signal information in the first message line by line from the signal definition cell at the next line of the message definition initial line, and reading out the information such as signal name, signal initial position, signal length, signal coding, unit, precision, offset, signal range, initial value, default value, transceiving node and the like;
3. after the first message and the signal information contained in the first message are read, if other messages exist, the information is continuously read according to the steps 1 and 2, and whether the currently read message is the last message can be judged by judging whether the message is a sleep instruction message (namely the message with the message ID of 0x 3C) when the message definition information is read;
4. when the sleep instruction message is determined to be read, the schedule table information can be read line by line from the next line of the sleep instruction message, and when the read information is determined to be empty (i.e., the information is not read from the target LIN communication file), the information to be converted in the target LIN communication file can be determined to be completely read.
The information to be converted can be read from the target LIN communication file in series by executing the four steps, and the above example is also only illustrative and the disclosure does not limit the information.
Mode two, parallel read mode
In another possible implementation manner of this step, to improve the efficiency of data reading, the information to be converted may also be read in parallel from the target LIN communication file, and specifically, a second preset start line corresponding to each piece of message information in the target LIN communication file and a third preset start line corresponding to the scheduling table information are first obtained; and then reading each piece of message information and the scheduling table information in parallel according to the second preset initial line and the third preset initial line.
Exemplarily, assuming that the target LIN communication file stores schedule information of a corresponding LIN network and two pieces of message information, and a row identifier of the second preset start row corresponding to a first piece of message information is a, a row identifier of the second preset start row corresponding to a second piece of message information is B, and a row identifier of the third preset start row corresponding to the schedule information is C, three mutually independent reading processes may be started simultaneously in a process of reading the to-be-converted information in parallel from the target LIN communication file, where a first reading process is used to read a first piece of message information line by line from the row a to obtain node information, message definition information, and signal information corresponding to the first piece of message information; the second reading process is used for reading the second message information line by line from the B line to obtain node information, message definition information and signal information corresponding to the second message information; the third reading process is used to read the schedule information line by line starting from line C, and the above example is only illustrative and the present disclosure does not limit this.
In addition, for each reading process in the plurality of reading processes for reading the information to be converted in parallel, if it is determined that the reading end indication information returned by the reading process is received, it is determined that the reading process is ended, and therefore, it can be determined whether the information to be converted is completely read in the following manner in the process of reading the information to be converted in parallel:
and for each reading process in a plurality of reading processes for reading the information to be converted in parallel, acquiring reading ending indication information returned by the reading process, and determining that the information to be converted is read under the condition that the reading ending indication information is returned by all the reading processes.
When reading message information, if reading a sleep instruction message, returning the reading ending indication information; when the schedule information is read, if the read information is determined to be empty, the read end instruction information may be returned.
It should be further noted that, in the above description, a specific implementation manner of reading the to-be-converted information from the target LIN communication file in a row unit is introduced, and if the target LIN communication file sequentially stores the schedule table information and each piece of message information in a column unit, in another possible implementation manner of the present disclosure, the to-be-converted information may also be read from the target LIN communication file in a column unit, which is similar to the manner of reading in a row unit, and is not described herein again.
In step S204, for each to-be-converted information in the acquired node information, the message definition information, the signal information, and the scheduling table information, a preset field corresponding to the to-be-converted information defined in the preset LDF file format is determined.
The LDF database file is used as a configuration information description file of the LIN bus, wherein all defined elements have a specific standard format, the preset LDF file format is the specific standard format corresponding to the LDF database file, and specific preset fields are corresponding to different information to be converted in the preset LDF file format.
For example, the preset field corresponding to the node information includes a master node name >, < slave1_ name >, < slave2_ name >, < master _ name > in which a master node name can be written, and slave node names in < slave1_ name >, < slave2_ name > in which a slave node name can be written; the preset fields corresponding to the message definition information may include < frame _ name >, < frame _ ID >, < node _ name >, < frame _ size > and the like, and the message name, the message ID, the node name corresponding to the message, and the message length may be written in the preset fields respectively; the preset field corresponding to the signal information comprises < scale _ signal _ name >, < signal _ size > and the like, and the signal name and the signal length can be written in the preset field respectively; the preset field corresponding to the schedule information includes < schedule _ table _ name >, and the schedule name may be written in the preset field.
In step S205, the information to be converted is written into the corresponding predetermined field in the predetermined text file.
In this step, reading and writing may be performed while taking a row (or a column) as a unit, for example, after reading the definition of the first packet from the packet definition start row, the read information such as the node attribute, the node name, the packet ID, the packet cycle, the packet length information, and the like may be written in the corresponding preset field in the preset text file; after reading the signal information in the first message line by line from the signal definition cell starting from the next line of the message definition start line, the read information such as the signal name, the signal start position, the signal length, the signal code, the unit, the precision, the offset, the signal range, the initial value, the default value, the transceiving node, and the like may be written into the corresponding preset field in the preset text file.
In step S206, the written preset text file is stored according to a preset storage policy, so as to obtain the target LDF file.
The preset storage policy may be a storage path, a storage file name, and a stored file type for storing the target LDF file, which are selected by a user.
By adopting the method, the target LIN communication file can be automatically converted into the LDF database file without manual editing of a user, the compiling efficiency of the LDF database file is improved, and the condition that the LDF file is edited wrongly can be effectively prevented.
Fig. 3 is a block diagram illustrating a file format conversion apparatus according to an exemplary embodiment, as shown in fig. 3, the apparatus including:
an obtainingmodule 301, configured to obtain a target LIN communication file to be converted;
areading module 302, configured to read information to be converted from the target LIN communication file;
thefile writing module 303 is configured to write the information to be converted into a preset text file according to a preset LDF file format, so as to obtain a converted target LDF file.
With regard to the apparatus in the above-described embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.
By adopting the device, the target LIN communication file can be automatically converted into the LDF database file without manual editing of a user, the compiling efficiency of the LDF database file is improved, and the condition that the LDF file is edited wrongly can be effectively prevented.
Fig. 4 is a block diagram illustrating anelectronic device 400 according to an example embodiment. As shown in fig. 4, theelectronic device 400 may include: aprocessor 401 and amemory 402. Theelectronic device 400 may also include one or more of amultimedia component 403, an input/output (I/O)interface 404, and acommunications component 405.
Theprocessor 401 is configured to control the overall operation of theelectronic device 400, so as to complete all or part of the steps in the file format conversion method. Thememory 402 is used to store various types of data to support operations at theelectronic device 400, such data including, for example, instructions for any application or method operating on theelectronic device 400 and application-related data
In another exemplary embodiment, there is also provided a computer-readable storage medium including program instructions which, when executed by a processor, implement the steps of the file format conversion method described above. For example, the computer readable storage medium may be thememory 402 described above including program instructions that are executable by theprocessor 401 of theelectronic device 400 to perform the file format conversion method described above.
The preferred embodiments of the present disclosure are described in detail with reference to the accompanying drawings, however, the present disclosure is not limited to the specific details of the above embodiments, and various simple modifications may be made to the technical solution of the present disclosure within the technical idea of the present disclosure, and these simple modifications all belong to the protection scope of the present disclosure.
It should be noted that, in the foregoing embodiments, various features described in the above embodiments may be combined in any suitable manner, and in order to avoid unnecessary repetition, various combinations that are possible in the present disclosure are not described again.
In addition, any combination of various embodiments of the present disclosure may be made, and the same should be considered as the disclosure of the present disclosure, as long as it does not depart from the spirit of the present disclosure.