A migration code processing method and device, electronic equipment and storage medium
By converting topic names, connection ports, and data formats, the code migration problem between the AP AUTOSAR platform and the ROS2 platform was solved, achieving seamless code migration and interoperability, and reducing development workload.
Patent Information
- Application Number
- CN202310105242.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2022-12-06
- Filing Date
- 2023-02-13
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2043-02-13
AI Technical Summary
The differences in topic names, connection port types, and data types between the AP AUTOSAR platform and the ROS2 platform necessitate code rewriting during migration, increasing the development workload and requirements for developers.
A method for processing migration code is provided, which obtains code migration instructions and converts the topic name, connection port, and data format of the code to be migrated into a form that can be recognized by the target platform, including the conversion of topic name code blocks, connection port code blocks, and data code blocks.
It enables code interoperability between different devices, reduces the workload of code rewriting, and simplifies the code migration process.
Smart Images

Figure CN116302091B_ABST
Abstract
Description
[0001] This application claims priority to the application filed on December 6, 2022, with application number 2022115577143, entitled "A method, apparatus, electronic device and storage medium for processing migration codes", the entire contents of which are incorporated herein by reference. Technical Field
[0002] This application relates to the field of Internet technology, and in particular to a migration code processing method, apparatus, electronic device and storage medium. Background Technology
[0003] AP AUTOSAR is a collaborative development framework for automotive electronic systems, involving global automakers, parts suppliers, and various research and service organizations. ROS2 is a middleware that has been adopted from the field of robotics and applied to the field of autonomous driving.
[0004] Most mainstream intelligent driving applications are currently developed based on the AP AUTOSAR platform and the ROS2 platform. However, due to differences in topic names, connection port types, and data types, the two platforms cannot communicate with each other.
[0005] Currently, to migrate AP AUTOSAR platform code to ROS2 platform, or ROS2 platform code to AP AUTOSAR platform, the migrated code needs to be rewritten, which increases the development workload and places higher demands on developers. Summary of the Invention
[0006] This application provides a migration code processing method, apparatus, electronic device, and storage medium.
[0007] On one hand, embodiments of this application provide a migration code processing method, the method comprising:
[0008] Obtain code migration instructions; code migration instructions include indication information of the code to be migrated; code migration instructions are used to instruct the code to be migrated from the first device to the second device;
[0009] In response to the code migration instruction, the code to be migrated corresponding to the instruction information is determined from the code block corresponding to the first device;
[0010] In the code to be migrated, the topic name code block corresponding to the first device is converted into the topic name code block corresponding to the second device.
[0011] In the code to be migrated, the first type of connection port code block corresponding to the first device is converted into the second type of connection port code block corresponding to the second device.
[0012] In the code to be migrated, the data code block in the first code format corresponding to the first device is converted into the data code block in the second code format corresponding to the second device.
[0013] In some possible embodiments,
[0014] The code migration command is used to instruct the code to be migrated from the AP AUTOSAR platform to the ROS2 platform;
[0015] or:
[0016] The code migration command is used to instruct the code to be migrated from the ROS2 platform to the AP AUTOSAR platform.
[0017] In some possible embodiments, in response to a code migration instruction, determining the code to be migrated corresponding to the indication information from the code block corresponding to the first device includes:
[0018] In response to a code migration instruction, if the code migration instruction is used to instruct the code to be migrated from the AP AUTOSAR platform to the ROS2 platform, the start and end statements of the code to be migrated are determined from the code block corresponding to the first device according to the instruction information.
[0019] The code to be migrated is determined based on the opening and closing statements of the code to be migrated.
[0020] In some possible embodiments, in response to a code migration instruction, determining the code to be migrated corresponding to the indication information from the code block corresponding to the first device further includes:
[0021] In response to a code migration instruction, if the code migration instruction is used to instruct the code to be migrated from the ROS2 platform to the AP AUTOSAR platform, the ROS2 platform includes at least one set of preset tag pairs, and the target preset tag pair is determined from the code block corresponding to the first device according to the instruction information; the target preset tag pair is a tag pair in at least one set of preset tag pairs;
[0022] The code to be migrated is determined based on the target preset tags.
[0023] In some possible embodiments,
[0024] The topic name of the code block corresponding to the first device is the topic name of the first type;
[0025] The topic name of the code block corresponding to the second device is the topic name of the second type;
[0026] The topic name of the first type matches the connection port code block of the first type;
[0027] The topic name of the second type matches the connection port code block of the second type;
[0028] The conversion of the topic name code block corresponding to the first device and the conversion of the connection port code block of the first type corresponding to the first device are performed simultaneously.
[0029] In some possible embodiments, converting the first type of connection port code block corresponding to the first device in the code to be migrated into the second type of connection port code block corresponding to the second device includes:
[0030] Obtain the connection port parameters contained in the first type of connection port code block corresponding to the first device;
[0031] Create a second type of connection port code block tab;
[0032] Based on the second type of connection port tab and connection port parameters, the first type of connection port code block in the code to be migrated is converted into the second type of connection port code block corresponding to the second device.
[0033] In some possible embodiments, converting a data code block in the code to be migrated, corresponding to a first code format for a first device, into a data code block in the second code format for a second device includes:
[0034] Obtain the data type mapping table, which contains the mapping relationship between the first preset data type corresponding to the first device and the second preset data type corresponding to the second device;
[0035] According to the data type mapping table, the code statements containing the first preset data type in the data code block of the first code format corresponding to the first device are converted into code statements containing the second preset data type;
[0036] Based on the code statements containing the second preset data type and the code statements in the data code block of the first code format corresponding to the first device that do not contain the first preset data type, a data code block of the second code format corresponding to the second device is generated.
[0037] On the other hand, a migration code processing apparatus is provided, which includes:
[0038] The acquisition module is used to acquire code migration instructions; the code migration instructions include indication information of the code to be migrated; the code migration instructions are used to instruct the code to be migrated from the first device to the second device;
[0039] The response module is used to determine the code to be migrated corresponding to the instruction information from the code block corresponding to the first device in response to the code migration instruction;
[0040] The first conversion module is used to convert the topic name code block corresponding to the first device in the code to be migrated into the topic name code block corresponding to the second device.
[0041] The second conversion module is used to convert the first type of connection port code block corresponding to the first device in the code to be migrated into the second type of connection port code block corresponding to the second device.
[0042] The third conversion module is used to convert the data code block in the first code format corresponding to the first device in the code to be migrated into the data code block in the second code format corresponding to the second device.
[0043] In some possible embodiments,
[0044] The code migration command is used to instruct the code to be migrated from the AP AUTOSAR platform to the ROS2 platform;
[0045] or:
[0046] The code migration command is used to instruct the code to be migrated from the ROS2 platform to the AP AUTOSAR platform.
[0047] In some possible embodiments, the response module is used for:
[0048] In response to a code migration instruction, if the code migration instruction is used to instruct the code to be migrated from the AP AUTOSAR platform to the ROS2 platform, the start and end statements of the code to be migrated are determined from the code block corresponding to the first device according to the instruction information.
[0049] The code to be migrated is determined based on the opening and closing statements of the code to be migrated.
[0050] In some possible embodiments, the response module is used for:
[0051] In response to a code migration instruction, if the code migration instruction is used to instruct the code to be migrated from the ROS2 platform to the AP AUTOSAR platform, the ROS2 platform includes at least one set of preset tag pairs, and the target preset tag pair is determined from the code block corresponding to the first device according to the instruction information; the target preset tag pair is a tag pair in at least one set of preset tag pairs;
[0052] The code to be migrated is determined based on the target preset tags.
[0053] In some possible embodiments,
[0054] The topic name of the code block corresponding to the first device is the topic name of the first type;
[0055] The topic name of the code block corresponding to the second device is the topic name of the second type;
[0056] The topic name of the first type matches the connection port code block of the first type;
[0057] The topic name of the second type matches the connection port code block of the second type;
[0058] The conversion of the topic name code block corresponding to the first device and the conversion of the connection port code block of the first type corresponding to the first device are performed simultaneously.
[0059] In some possible embodiments, the second conversion module is used for:
[0060] Obtain the connection port parameters contained in the first type of connection port code block corresponding to the first device;
[0061] Create a second type of connection port code block tab;
[0062] Based on the second type of connection port tab and connection port parameters, the first type of connection port code block in the code to be migrated is converted into the second type of connection port code block corresponding to the second device.
[0063] In some possible embodiments, the third conversion module is used for:
[0064] Obtain the data type mapping table, which contains the mapping relationship between the first preset data type corresponding to the first device and the second preset data type corresponding to the second device;
[0065] According to the data type mapping table, the code statements containing the first preset data type in the data code block of the first code format corresponding to the first device are converted into code statements containing the second preset data type;
[0066] Based on the code statements containing the second preset data type and the code statements in the data code block of the first code format corresponding to the first device that do not contain the first preset data type, a data code block of the second code format corresponding to the second device is generated.
[0067] On the other hand, an electronic device is provided, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the processor loads and executes any migration code processing method.
[0068] On the other hand, a computer-readable storage medium is provided, in which at least one instruction or at least one program is stored, wherein the at least one instruction or at least one program is loaded and executed by a processor to implement any migration code processing method.
[0069] On the other hand, a computer program product is provided, which includes a computer program stored in a readable storage medium, wherein at least one processor of a computer device reads from the readable storage medium and executes the computer program, causing the computer device to perform any of the migration code processing methods.
[0070] The migration code processing method, apparatus, electronic device, and storage medium provided in this application have the following technical effects:
[0071] The code to be migrated from the first device is divided into three parts: topic name code block, connection port code block, and data code block. Each of the three parts is then converted into a code block that the second device can recognize, thus completing the code migration between different devices, enabling information exchange between different devices, and reducing the workload of code rewriting caused by code migration between different devices. Attached Figure Description
[0072] To more clearly illustrate the technical solutions and advantages in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0073] Figure 1 This is a schematic diagram of an application environment provided in an embodiment of this application;
[0074] Figure 2 This is a flowchart illustrating a migration code processing method provided in an embodiment of this application;
[0075] Figure 3 This is a flowchart illustrating a method for determining code to be migrated, as provided in an embodiment of this application.
[0076] Figure 4 This is a flowchart illustrating a connection port code block conversion method provided in an embodiment of this application;
[0077] Figure 5 This is a flowchart illustrating a data code block conversion method provided in an embodiment of this application;
[0078] Figure 6 This is a schematic diagram of the structure of a migration code processing device provided in an embodiment of this application;
[0079] Figure 7 This is a hardware structure block diagram of a server for a migration code processing method provided in an embodiment of this application. Detailed Implementation
[0080] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0081] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.
[0082] Please see Figure 1 , Figure 1 This is a schematic diagram of an application environment provided in an embodiment of this application, which includes a first device 110 and a second device 120.
[0083] Specifically, the first device 110 may include an AP AUTOSAR platform or a ROS2 platform.
[0084] The second device 120 may include an AP AUTOSAR platform or a ROS2 platform. If the first device 110 refers to an AP AUTOSAR platform, then the second device refers to a ROS2 platform, and vice versa.
[0085] Optionally, the second device 120 can acquire a code migration instruction; the code migration instruction includes indication information of the code to be migrated; the code migration instruction is used to instruct the code to be migrated from the first device to the second device; in response to the code migration instruction, the code to be migrated corresponding to the indication information is determined from the code block corresponding to the first device; the topic name code block corresponding to the first device in the code to be migrated is converted into the topic name code block corresponding to the second device; the first type of connection port code block corresponding to the first device in the code to be migrated is converted into the second type of connection port code block corresponding to the second device; the first code format data code block corresponding to the first device in the code to be migrated is converted into the second code format data code block corresponding to the second device.
[0086] Alternatively, the first device 110 can acquire a code migration instruction; the code migration instruction includes indication information of the code to be migrated; the code migration instruction is used to instruct the code to be migrated from the first device to the second device; in response to the code migration instruction, the code to be migrated corresponding to the indication information is determined from the code block corresponding to the first device; the topic name code block corresponding to the first device in the code to be migrated is converted into the topic name code block corresponding to the second device; the first type of connection port code block corresponding to the first device in the code to be migrated is converted into the second type of connection port code block corresponding to the second device; the first code format data code block corresponding to the first device in the code to be migrated is converted into the second code format data code block corresponding to the second device.
[0087] The following describes a specific embodiment of a migration code processing method according to this application. Figure 2 This is a flowchart illustrating a migration code processing method provided in an embodiment of this application. This specification provides method operation steps as shown in the embodiments or flowcharts, but based on conventional or non-inventive labor, more or fewer operation steps may be included. The order of steps listed in the embodiments is merely one possible execution order among many and does not represent the only execution order. In actual system or server products, the method can be executed sequentially according to the embodiments or drawings, or in parallel (e.g., in a parallel processor or multi-threaded processing environment). Specifically, as shown... Figure 2 As shown, the method may include:
[0088] S201: Obtain code migration instructions; the code migration instructions include indication information of the code to be migrated; the code migration instructions are used to instruct the code to be migrated from the first device to the second device.
[0089] In this embodiment, the device can obtain a code migration instruction, which includes indication information about the code to be migrated. Optionally, the code migration instruction is used to instruct the code to be migrated from the first device to the second device. Optionally, the device here can refer to either the first device or the second device.
[0090] Optionally, when the device is the first device, the code migration instruction is used to instruct the code to be migrated from the first device to the second device. Alternatively, when the device is the second device, the code migration instruction is used to instruct the code to be migrated from the first device to the second device.
[0091] The code migration instructions are created by the user and can be stored in an XML file. The XML file contains a set of root element tags that identify the second device. <autosar>< / autosar> or <ros2>< / ros2> and at least one group <map>< / map> Tags; Tags <map>< / map>Set between the root element tags. Code migration instructions include at least one transformation pair, each pair consisting of an input and an output part; the input part includes a first-type topic name and a first-type connection port name; the output part includes a second-type topic name and a second-type connection port name. Each transformation pair is set between a set of tags. <map>< / map> Between, multiple sets of transformation pairs correspond to multiple sets of tags. <map>< / map> The topic names and connection port names for the input and output sections are determined by the user.
[0092] S202: In response to the code migration instruction, determine the code to be migrated corresponding to the instruction information from the code block corresponding to the first device;
[0093] In this embodiment of the application, the device can respond to the code migration instruction and determine the code to be migrated corresponding to the instruction information from the code block corresponding to the first device.
[0094] The instruction information may include the topic name.
[0095] In some possible embodiments, please refer to Figure 3 The diagram illustrates a flowchart for determining a method of code to be migrated, which may include:
[0096] S301: The device responds to the code migration instruction.
[0097] S302: The device judges the code migration instruction. If the code migration instruction is used to indicate that the code to be migrated is to be migrated from the AP AUTOSAR platform to the ROS2 platform, then step S303 is executed; otherwise, step S305 is executed.
[0098] S303: The device side determines the start and end statements of the code to be migrated from the code block corresponding to the first device according to the instruction information.
[0099] S304: The device determines the code to be migrated based on the header and footer statements of the code to be migrated.
[0100] S305: The device determines the target preset tag pair from the code block corresponding to the first device according to the instruction information.
[0101] S306: The device determines the code to be migrated based on the target preset tag.
[0102] Through steps S301 to S305, the code to be migrated can be determined from the first device.
[0103] The ROS 2 platform includes at least one set of preset label pairs. <header>< / header> The target preset tag pair is a tag pair from at least one set of preset tag pairs.
[0104] S203: Convert the topic name code block corresponding to the first device in the code to be migrated into the topic name code block corresponding to the second device.
[0105] In this embodiment of the application, the device can convert the topic name code block corresponding to the first device in the code to be migrated into the topic name code block corresponding to the second device.
[0106] S204: Convert the first type of connection port code block corresponding to the first device in the code to be migrated into the second type of connection port code block corresponding to the second device.
[0107] In this embodiment of the application, the device can convert the first type of connection port code block corresponding to the first device in the code to be migrated into the second type of connection port code block corresponding to the second device.
[0108] In some possible embodiments, please refer to Figure 4 The diagram shows a flowchart of a method for converting connection port code blocks, which may include:
[0109] S401: The device obtains the connection port parameters contained in the first type of connection port code block corresponding to the first device.
[0110] The connection port parameters may include: port number, address, and component name; the component name may refer to the source component name of the port information or the destination component name of the port information.
[0111] S402: The device creates a second type of connection port code block tab.
[0112] Specifically, the device can create a second-type connection port code block tab based on the second-type connection port name in the output of the conversion pair and / or the tab contained in the first-type connection port code block corresponding to the first device.
[0113] S403: The device side converts the first type of connection port code block corresponding to the first device in the code to be migrated into the second type of connection port code block corresponding to the second device based on the second type of connection port tab and connection port parameters.
[0114] In step S403, it is necessary to obtain a data type mapping table and convert the connection port parameters from the first preset data type corresponding to the first device to the second preset data type corresponding to the second device according to the data type mapping table.
[0115] If the ROS2 platform is being converted to the AP AUTOSAR platform, the SOME / IP or DDS communication protocol needs to be added to the second type of connection port code block corresponding to the second device.
[0116] The connection port code block conversion can be achieved through steps S401 to S403.
[0117] S205: Convert the data code block in the first code format corresponding to the first device in the code to be migrated into the data code block in the second code format corresponding to the second device.
[0118] In this embodiment, the device can convert a data code block in the code to be migrated, corresponding to a first code format for a first device, into a data code block in the second code format for a second device. The data code block can include all code to be migrated except for the topic name code block and the connection port code block.
[0119] In some possible embodiments, please refer to Figure 5 The diagram shows a flowchart of a data code block conversion method, which may include:
[0120] S501: The device obtains a data type mapping table, which contains the mapping relationship between the first preset data type corresponding to the first device and the second preset data type corresponding to the second device.
[0121] The data type mapping table is shown in Table 1:
[0122] AP AUTOSAR platform Ros2 platform StdCppImplementationDataType->bool bool StdCppImplementationDataType->float float32, float64 StdCppImplementationDataType->integer int32, int64 StdCppImplementationDataType->unsignedInteger uint32, uint64 StdCppImplementationDataType->string string <struct> < / struct> <header> < / header>
[0123] S502: The device reads the first statement of the data code block corresponding to the first code format of the first device.
[0124] S503: The device treats the first statement as the current code statement.
[0125] S504: The device determines whether the current code statement contains the first preset data type. If it does, it executes step S505; otherwise, it proceeds to step S509.
[0126] S505: The device converts code statements containing the first preset data type into code statements containing the second preset data type according to the data type mapping table.
[0127] S506: The device determines whether the current code statement is the last statement. If it is, execute S507; otherwise, proceed to step S508.
[0128] S507: Merge the code statements generated by S505 and S509 to generate a data code block in the second code format corresponding to the second device.
[0129] S508: The device updates the current code statement using the next statement after the current code statement, and executes step S504.
[0130] S509: The device copies the current code statement and proceeds to step S506.
[0131] Through the above steps S501 to S509, the conversion of data code blocks is achieved.
[0132] In summary, the migration code processing method proposed in this application realizes the migration of code between different devices by converting the topic name code block, connection port code block and data code block respectively. It can realize the migration of APAUTOSAR platform code to ROS2 platform, or the migration of ROS2 platform code to AP AUTOSAR platform, avoiding the need to rewrite the migrated code during the code migration process and reducing the workload of R&D personnel.
[0133] In some possible embodiments, the code migration instruction is used to instruct the code to be migrated from the AP AUTOSAR platform to the ROS2 platform; or: the code migration instruction is used to instruct the code to be migrated from the ROS2 platform to the AP AUTOSAR platform.
[0134] In some possible embodiments, the topic name of the topic name code block corresponding to the first device is a topic name of a first type; the topic name of the topic name code block corresponding to the second device is a topic name of a second type; the topic name of the first type matches the connection port code block of the first type; the topic name of the second type matches the connection port code block of the second type; the conversion of the topic name code block corresponding to the first device and the conversion of the connection port code block of the first type corresponding to the first device are performed synchronously.
[0135] The AP AUTOSAR platform has three connection port code block types: PPort, RPort, and PRPort; the ROS2 platform has two connection port code block types: publisher and subscriber. PPort corresponds to publisher; RPort corresponds to subscriber; and PRPort corresponds to both publisher and subscriber.
[0136] If the AP AUTOSAR platform code is migrated to the ROS2 platform, it is also necessary to merge the topic name code block corresponding to the converted second device, the second type of connection port code block corresponding to the second device, and the second code format data code block corresponding to the second device into a second device code block, and create another set of... <header>< / header> The tag, the second device code block is set in <header>< / header>Between tags. Alternatively, create a separate group for the topic name code block corresponding to the second device, the second type of connection port code block corresponding to the second device, and the second code format data code block corresponding to the second device. <header>< / header> Label.
[0137] After completing the conversion of the topic name code block, connection port code block, and data code block, users can perform algorithm porting and compile the project based on the CMakeLists.txt file.
[0138] This application also provides a migration code processing apparatus. Figure 6 This is a schematic diagram of the structure of a migration code processing device provided in an embodiment of this application, as shown below. Figure 6 As shown, the device includes a signal acquisition module 601, a response module 602, a first conversion module 603, a second conversion module 604, and a third conversion module 605.
[0139] The acquisition module 601 is used to acquire code migration instructions; the code migration instructions include indication information of the code to be migrated; the code migration instructions are used to instruct the code to be migrated from the first device to the second device;
[0140] The response module 602 is used to determine the code to be migrated corresponding to the instruction information from the code block corresponding to the first device in response to the code migration instruction;
[0141] The first conversion module 603 is used to convert the topic name code block corresponding to the first device in the code to be migrated into the topic name code block corresponding to the second device.
[0142] The second conversion module 604 is used to convert the first type of connection port code block corresponding to the first device in the code to be migrated into the second type of connection port code block corresponding to the second device.
[0143] The third conversion module 605 is used to convert the data code block in the first code format corresponding to the first device in the code to be migrated into the data code block in the second code format corresponding to the second device.
[0144] In some possible embodiments,
[0145] The code migration command is used to instruct the code to be migrated from the AP AUTOSAR platform to the ROS2 platform;
[0146] or:
[0147] The code migration command is used to instruct the code to be migrated from the ROS2 platform to the AP AUTOSAR platform.
[0148] In some possible embodiments, the response module 602 may be used to:
[0149] In response to a code migration instruction, if the code migration instruction is used to instruct the code to be migrated from the AP AUTOSAR platform to the ROS2 platform, the start and end statements of the code to be migrated are determined from the code block corresponding to the first device according to the instruction information.
[0150] The code to be migrated is determined based on the opening and closing statements of the code to be migrated.
[0151] In some possible embodiments, the response module 602 may also be used for:
[0152] In response to a code migration instruction, if the code migration instruction is used to instruct the code to be migrated from the ROS2 platform to the AP AUTOSAR platform, the ROS2 platform includes at least one set of preset tag pairs, and the target preset tag pair is determined from the code block corresponding to the first device according to the instruction information; the target preset tag pair is a tag pair in at least one set of preset tag pairs;
[0153] The code to be migrated is determined based on the target preset tags.
[0154] In some possible embodiments,
[0155] The topic name of the code block corresponding to the first device is the topic name of the first type;
[0156] The topic name of the code block corresponding to the second device is the topic name of the second type;
[0157] The topic name of the first type matches the connection port code block of the first type;
[0158] The topic name of the second type matches the connection port code block of the second type;
[0159] The conversion of the topic name code block corresponding to the first device and the conversion of the connection port code block of the first type corresponding to the first device are performed simultaneously.
[0160] In some possible embodiments, the second conversion module 604 is configured to:
[0161] Obtain the connection port parameters contained in the first type of connection port code block corresponding to the first device;
[0162] Create a second type of connection port code block tab;
[0163] Based on the second type of connection port tab and connection port parameters, the first type of connection port code block in the code to be migrated is converted into the second type of connection port code block corresponding to the second device.
[0164] In some possible embodiments, the third conversion module 605 is used for:
[0165] Obtain the data type mapping table, which contains the mapping relationship between the first preset data type corresponding to the first device and the second preset data type corresponding to the second device;
[0166] According to the data type mapping table, the code statements containing the first preset data type in the data code block of the first code format corresponding to the first device are converted into code statements containing the second preset data type;
[0167] Based on the code statements containing the second preset data type and the code statements in the data code block of the first code format corresponding to the first device that do not contain the first preset data type, a data code block of the second code format corresponding to the second device is generated.
[0168] The apparatus and method embodiments in this application are based on the same application concept.
[0169] The methods and embodiments provided in this application can be executed on a computer terminal, server, or similar computing device. Taking running on a server as an example, Figure 7 This is a hardware structure block diagram of a server for a migration code processing method provided in an embodiment of this application. For example... Figure 7 As shown, the server 700 can vary significantly due to different configurations or performance. It may include one or more central processing units (CPUs) 710 (CPUs 710 may include, but are not limited to, microprocessors such as MCUs or programmable logic devices such as FPGAs), a memory 730 for storing data, and one or more storage media 720 (e.g., one or more mass storage devices) for storing application programs 723 or data 722. The memory 730 and storage media 720 may be temporary or persistent storage. The program stored in the storage media 720 may include one or more modules, each module may include a series of instruction operations on the server. Furthermore, the CPU 710 may be configured to communicate with the storage media 720 and execute the series of instruction operations stored in the storage media 720 on the server 700. Server 700 may also include one or more power supplies 760, one or more wired or wireless network interfaces 750, one or more input / output interfaces 740, and / or one or more operating systems 721, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0170] The input / output interface 740 can be used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of server 700. In one example, the input / output interface 740 includes a network interface controller (NIC), which can connect to other network devices via a base station to communicate with the Internet.
[0171] Those skilled in the art will understand that Figure 7 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, server 700 may also include... Figure 7 The more or fewer components shown, or having the same Figure 7 The different configurations shown.
[0172] Embodiments of this application also provide a computer storage medium, which can be disposed in a server to store at least one instruction, at least one program, code set, or instruction set related to implementing a migration code processing method in the method embodiment. The at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by the processor to implement the above-described migration code processing method.
[0173] Optionally, in this embodiment, the storage medium may be located at at least one of the multiple network servers in a computer network. Optionally, in this embodiment, the storage medium may include, but is not limited to, various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0174] On the other hand, an electronic device is provided, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the processor loads and executes any migration code processing method.
[0175] On the other hand, a computer program product is provided, which includes a computer program stored in a readable storage medium, wherein at least one processor of a computer device reads from the readable storage medium and executes the computer program, causing the computer device to perform any of the migration code processing methods.
[0176] As can be seen from the embodiments of the migration code processing method, device, or storage medium provided in this application, this application obtains a code migration instruction; the code migration instruction includes indication information of the code to be migrated; the code migration instruction is used to instruct the code to be migrated from a first device to a second device; in response to the code migration instruction, the code to be migrated corresponding to the indication information is determined from the code block corresponding to the first device; the topic name code block corresponding to the first device in the code to be migrated is converted into a topic name code block corresponding to the second device; the first type of connection port code block corresponding to the first device in the code to be migrated is converted into a second type of connection port code block corresponding to the second device; the first code format data code block corresponding to the first device in the code to be migrated is converted into a second code format data code block corresponding to the second device. The embodiments of this application provide feasible technical means for realizing code migration between different devices by using topic name code blocks, connection port code blocks, and data code blocks.
[0177] It should be noted that the order of the embodiments described above is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. Furthermore, specific embodiments have been described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in a different order than that shown in the embodiments and still achieve the desired result. Additionally, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0178] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the device embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0179] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0180] The above description is only a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method of migrating code processing, the method comprising: The method comprises: obtaining a code migration instruction; the code migration instruction comprises indication information of to-be-migrated code; the code migration instruction is used to instruct migration of the to-be-migrated code from a first device to a second device; the code migration instruction is used to instruct migration of the to-be-migrated code from an AP AUTOSAR platform to a ROS2 platform; or: the code migration instruction is used to instruct migration of the to-be-migrated code from the ROS2 platform to the AP AUTOSAR platform; in response to the code migration instruction, determining the to-be-migrated code corresponding to the indication information from a code block corresponding to the first device; converting a topic name code block corresponding to the first device in the to-be-migrated code into a topic name code block corresponding to the second device; in the topic name code block conversion process, topic name types of the topic name code blocks corresponding to the first device and the second device respectively match types of corresponding connection port code blocks, and conversion of the topic name code block corresponding to the first device and the connection port code block is performed synchronously; obtaining a connection port parameter contained in a connection port code block of a first type corresponding to the first device; creating a connection port code block tab of a second type corresponding to the second device; converting the connection port code block of the first type corresponding to the first device in the to-be-migrated code into the connection port code block of the second type corresponding to the second device according to the connection port code block tab of the second type and the connection port parameter; the connection port code block tab of the second type is created according to a second type of connection port name output in a conversion pair and / or a tab contained in the connection port code block of the first type corresponding to the first device; converting a data code block of a first code format corresponding to the first device in the to-be-migrated code into a data code block of a second code format corresponding to the second device; in the data code block conversion process, performing data type conversion on the data code block of the first code format corresponding to the first device according to a data type mapping relationship between the first device and the second device; based on the code statement after data type conversion and the code statement of the data code block of the first code format corresponding to the first device which does not involve data type conversion, generating the data code block of the second code format corresponding to the second device.
2. The method of claim 1, wherein, The response to the code migration instruction, determining the to-be-migrated code corresponding to the indication information from the code block corresponding to the first device, comprises: in response to the code migration instruction, if the code migration instruction is used to instruct migration of the to-be-migrated code from an AP AUTOSAR platform to a ROS2 platform, determining head and tail statements of the to-be-migrated code from the code block corresponding to the first device according to the indication information; determining the to-be-migrated code according to the head and tail statements of the to-be-migrated code.
3. The method of claim 1, wherein, The response to the code migration instruction, determining the to-be-migrated code corresponding to the indication information from the code block corresponding to the first device, further comprises: in response to the code migration instruction, if the code migration instruction is used to indicate that the to-be-migrated code is migrated from a ROS2 platform to an AP AUTOSAR platform, the ROS2 platform includes at least one set of preset label pairs, a target preset label pair is determined from the code block corresponding to the first device according to the indication information; the target preset label pair is a label pair in the at least one set of preset label pairs; the to-be-migrated code is determined according to the target preset label pair.
4. The code migration processing method according to claim 1, characterized in that, the topic name of the topic name code block corresponding to the first device is a topic name of a first type; the topic name of the topic name code block corresponding to the second device is a topic name of a second type; the topic name of the first type matches the connection port code block of the first type; the topic name of the second type matches the connection port code block of the second type; the conversion of the topic name code block corresponding to the first device and the conversion of the connection port code block of the first type corresponding to the first device are performed synchronously.
5. The method of claim 1, wherein, The conversion of the data code block of the first code format corresponding to the first device in the to-be-migrated code into the data code block of the second code format corresponding to the second device includes: obtaining a data type mapping table, the data type mapping table including a mapping relationship between a first preset data type corresponding to the first device and a second preset data type corresponding to the second device; according to the data type mapping table, converting a code statement containing the first preset data type in the data code block of the first code format corresponding to the first device into a code statement containing the second preset data type; based on the code statement containing the second preset data type and the code statement not containing the first preset data type in the data code block of the first code format corresponding to the first device, generating the data code block of the second code format corresponding to the second device.
6. A migration code processing apparatus, characterized by, The device includes: an acquisition module, configured to acquire a code migration instruction; the code migration instruction includes indication information of to-be-migrated code; the code migration instruction is used to indicate that the to-be-migrated code is migrated from a first device to a second device; the code migration instruction is used to indicate that the to-be-migrated code is migrated from an AP AUTOSAR platform to a ROS2 platform; or: the code migration instruction is used to indicate that the to-be-migrated code is migrated from the ROS2 platform to the AP AUTOSAR platform; a response module, configured to determine, in response to the code migration instruction, to-be-migrated code corresponding to the indication information from a code block corresponding to the first device; The first conversion module is configured to convert the topic name code block corresponding to the first device in the to-be-migrated code into the topic name code block corresponding to the second device; during the conversion of the topic name code block, the topic name category of the topic name code block corresponding to the first device and the second device respectively matches the type of the corresponding connection port code block, and the conversion of the topic name code block corresponding to the first device and the connection port code block is performed synchronously. The second conversion module is configured to obtain the connection port parameter contained in the first type of connection port code block corresponding to the first device; create a second type of connection port code block tab corresponding to the second device; and convert the first type of connection port code block corresponding to the first device in the to-be-migrated code into the second type of connection port code block corresponding to the second device according to the second type of connection port code block tab and the connection port parameter; the second type of connection port code block tab is created according to the second type of connection port name output in the conversion pair and / or the tab contained in the first type of connection port code block corresponding to the first device. The third conversion module is configured to convert the data code block in the first code format corresponding to the first device in the to-be-migrated code into the data code block in the second code format corresponding to the second device; during the conversion of the data code block, the data code block in the first code format corresponding to the first device is subjected to data type conversion according to the data type mapping relationship between the first device and the second device; and the data code block in the second code format corresponding to the second device is generated based on the code statement after the data type conversion and the code statement in the data code block in the first code format corresponding to the first device that does not involve data type conversion.
7. An electronic device, comprising: The electronic device includes a processor and a memory, and the memory stores at least one instruction or at least one program, the at least one instruction or the at least one program is loaded and executed by the processor to implement the migration code processing method of any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, The computer readable storage medium stores at least one instruction or at least one program, the at least one instruction or the at least one program is loaded and executed by the processor to implement the migration code processing method of any one of claims 1-5.
Citation Information
Patent Citations
Method for synchronizing AUTOSAR (automotive open system architecture) model to Simulink model
CN102819426A
Message communication method, computer system and proxy device
CN113138864A
Code conversion method and device, equipment and storage medium
CN114610317A