Time processing method and apparatus, computer device, and computer-readable storage medium
By obtaining candidate times from multiple clock sources and correcting them, the time overflow problem caused by 32-bit integer variables in the vehicle system was solved, and the accuracy of time synchronization and data transmission during the vehicle OTA upgrade process was achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHONGQING SELIS PHOENIX INTELLIGENT INNOVATION TECH CO LTD
- Filing Date
- 2024-10-08
- Publication Date
- 2026-04-21
AI Technical Summary
When vehicle systems or applications use 32-bit integer variables to represent time, overflow can easily occur, leading to time anomalies during OTA upgrades and preventing synchronization.
By acquiring candidate times from multiple candidate clock sources, selecting a reference time based on priority, and performing format conversion and correction, the target time is ensured to be within the timing format and overflow mechanism range of the local clock source, and the time of the local clock source is updated.
It improves the reliability and accuracy of time synchronization, ensures the accuracy and success rate of vehicle OTA upgrades, and enhances the adaptability of time synchronization.
Smart Images

Figure CN119300133B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of vehicle technology, and in particular to a time processing method, apparatus, computer device, and computer-readable storage medium. Background Technology
[0002] Over-the-Air (OTA) technology refers to the technology of automatically downloading upgrade packages via wireless network and remotely upgrading the vehicle's system or applications. OTA upgrades not only provide car owners with a more convenient way to upgrade their vehicles, but also bring a more intelligent and convenient driving experience.
[0003] Time management and data communication protocols are two key aspects of the OTA upgrade process. Currently, vehicle systems or applications use absolute time (such as UNIX timestamps) as a base clock to control time synchronization and data transmission during the OTA upgrade process, specifically using 32-bit integer variables to store and transmit time values.
[0004] However, using a 32-bit integer variable to represent time results in a maximum value of 2^31-1 (because one bit is used to represent positive or negative). This causes an overflow to occur approximately every 49 days, which is a time anomaly. In the event of a time anomaly, the vehicle's system or application may be unable to complete the OTA upgrade process. Therefore, improvements are urgently needed. Summary of the Invention
[0005] Therefore, it is necessary to provide a time processing method, apparatus, computer device, and computer-readable storage medium that can achieve time synchronization to address the aforementioned technical problems.
[0006] Firstly, this application provides a time processing method, which includes:
[0007] Upon detecting a time update event for the local clock source corresponding to the main controller, the corresponding candidate time is obtained from each candidate clock source other than the local clock source; wherein, each candidate clock source includes the system clock source of the target vehicle system carrying the main controller, and the external clock source of the external device communicating with the main controller.
[0008] Based on the priority of each candidate clock source, a reference time is selected from the acquired candidate times;
[0009] The reference time is corrected based on the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time; wherein, the timing format of the target time is consistent with the local timing format, and the time value of the target time is within the time range corresponding to the timing overflow mechanism.
[0010] The target time is used to update the local time of the local clock source.
[0011] In one embodiment, detecting a time update event for a local clock source corresponding to the main controller includes at least one of the following:
[0012] Received an OTA upgrade task for the target electronic control unit (ECU); the target ECU is the ECU managed by the main controller.
[0013] Received a time update command for the local clock source corresponding to the main controller;
[0014] A timing overflow was detected in the local clock source.
[0015] In one embodiment, each candidate clock source includes a system clock source of the target vehicle system carrying the main controller, and an external clock source of an external device communicating with the main controller.
[0016] The system clock source includes the interface time source of the operating system corresponding to the target vehicle system and / or the device clock source of the hardware devices deployed in the target vehicle system;
[0017] External devices include cloud platforms and / or vehicle gateway devices in the target vehicle.
[0018] In one embodiment, the reference time is corrected according to the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time, including:
[0019] If the current timing format corresponding to the reference time is inconsistent with the local timing format of the local clock source, the reference time is converted according to the format conversion relationship between the current timing format and the local timing format to obtain the alternative time under the local timing format.
[0020] The timing overflow mechanism of the local clock source is used to correct the alternative time and obtain the target time.
[0021] In one embodiment, a timing overflow mechanism from a local clock source is used to correct the candidate time to obtain the target time, including:
[0022] If the candidate time exceeds the overflow limit time corresponding to the timing overflow mechanism of the local clock source, the candidate time is subtracted from the overflow limit time to obtain the target time.
[0023] In one embodiment, a timing overflow mechanism from a local clock source is used to correct the candidate time to obtain the target time, including:
[0024] If the alternative time is less than the overflow limit time corresponding to the timing overflow mechanism of the local clock source, but greater than the update duration required for the time update event, then the reference time will be used as the target time.
[0025] In one embodiment, the reference time includes an integer time portion and a fractional time portion; the reference time is corrected according to the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time, including:
[0026] Based on the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source, the integer part of the reference time is corrected to obtain the target time.
[0027] The target time is used to update the local time of the local clock source, including:
[0028] The sum of the target time and its fractional part is used as the updated local time from the local clock source.
[0029] In one embodiment, the method further includes:
[0030] Upon receiving a time update request initiated by the controller, the updated local time corresponding to the local clock source is encrypted to obtain the encrypted time.
[0031] The encrypted time is sent to the slave controller so that the slave controller can update its local time based on the encrypted time.
[0032] Secondly, this application also provides a time processing apparatus, the apparatus comprising:
[0033] The multi-source time acquisition module is used to acquire the corresponding candidate time from each candidate clock source other than the local clock source when a time update event for the local clock source corresponding to the main controller is detected; wherein, each candidate clock source includes the system clock source of the target vehicle system carrying the main controller, and the external clock source of the external device communicating with the main controller.
[0034] The multi-source time selection module is used to select a reference time from the acquired candidate times based on the priority of each candidate clock source.
[0035] The time correction module is used to correct the reference time according to the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time; wherein, the timing format of the target time is consistent with the local timing format, and the time value of the target time is within the time range corresponding to the timing overflow mechanism.
[0036] The time update module is used to update the local time of the local clock source using the target time.
[0037] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0038] Upon detecting a time update event for the local clock source corresponding to the main controller, the corresponding candidate time is obtained from each candidate clock source other than the local clock source; wherein, each candidate clock source includes the system clock source of the target vehicle system carrying the main controller, and the external clock source of the external device communicating with the main controller.
[0039] Based on the priority of each candidate clock source, a reference time is selected from the acquired candidate times;
[0040] The reference time is corrected based on the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time; wherein, the timing format of the target time is consistent with the local timing format, and the time value of the target time is within the time range corresponding to the timing overflow mechanism.
[0041] The target time is used to update the local time of the local clock source.
[0042] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:
[0043] Upon detecting a time update event for the local clock source corresponding to the main controller, the corresponding candidate time is obtained from each candidate clock source other than the local clock source; wherein, each candidate clock source includes the system clock source of the target vehicle system carrying the main controller, and the external clock source of the external device communicating with the main controller.
[0044] Based on the priority of each candidate clock source, a reference time is selected from the acquired candidate times;
[0045] The reference time is corrected based on the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time; wherein, the timing format of the target time is consistent with the local timing format, and the time value of the target time is within the time range corresponding to the timing overflow mechanism.
[0046] The target time is used to update the local time of the local clock source.
[0047] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:
[0048] Upon detecting a time update event for the local clock source corresponding to the main controller, the corresponding candidate time is obtained from each candidate clock source other than the local clock source; wherein, each candidate clock source includes the system clock source of the target vehicle system carrying the main controller, and the external clock source of the external device communicating with the main controller.
[0049] Based on the priority of each candidate clock source, a reference time is selected from the acquired candidate times;
[0050] The reference time is corrected based on the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time; wherein, the timing format of the target time is consistent with the local timing format, and the time value of the target time is within the time range corresponding to the timing overflow mechanism.
[0051] The target time is used to update the local time of the local clock source.
[0052] The aforementioned time processing method, apparatus, computer equipment, and computer-readable storage medium, by acquiring candidate times from multiple candidate clock sources (including local clock sources and external clock sources), increase the data sources for time synchronization and improve the reliability of time synchronization. Even if a clock source fails or has a time deviation, accurate time information can still be obtained from other clock sources. Selecting a reference time based on the priority of each candidate clock source ensures the priority and accuracy of time synchronization. The priority of clock sources can be set according to actual conditions, prioritizing the use of more accurate and stable clock sources. After acquiring the reference time, it is corrected according to the current timing format of the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time. This step ensures the accuracy of time synchronization and avoids time deviations caused by mismatched timing formats or different overflow mechanisms. Through the adaptation and correction of the time format, the local clock source can accurately reflect the reference time, enhancing the adaptability of time synchronization. Even between different devices, accurate time synchronization can be achieved, ensuring accurate implementation of vehicle OTA upgrades. Attached Figure Description
[0053] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0054] Figure 1 This is a diagram illustrating the application environment of the time processing method in one embodiment;
[0055] Figure 2 This is a schematic diagram illustrating the OTA upgrade process in one embodiment;
[0056] Figure 3 This is a flowchart illustrating a time processing method in one embodiment;
[0057] Figure 4 This is a flowchart illustrating the process of obtaining the target time step in one embodiment;
[0058] Figure 5 This is a flowchart illustrating the steps for correcting the reference time in one embodiment;
[0059] Figure 6 This is a flowchart illustrating the steps of encrypting the updated local time corresponding to the local clock source in one embodiment.
[0060] Figure 7 This is a structural block diagram of a time processing device in one embodiment;
[0061] Figure 8 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0062] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0063] Over-the-Air (OTA) technology refers to the technology of automatically downloading upgrade packages via wireless network and remotely upgrading the vehicle's system or applications. OTA upgrades not only provide car owners with a more convenient way to upgrade their vehicles, but also bring a more intelligent and convenient driving experience.
[0064] Time management and data communication protocols are two key aspects of the OTA upgrade process. Currently, vehicle systems or applications use absolute time (such as UNIX timestamps) as a base clock to control time synchronization and data transmission during the OTA upgrade process.
[0065] Absolute timekeeping typically refers to the continuous accumulation of time in a certain unit of time (such as milliseconds or seconds) starting from a fixed starting point (e.g., system startup or a specific point in time). Taking a 32-bit integer variable as an example: while a 32-bit unsigned integer variable can indeed be used to store time values, its range and precision are limited by the variable type. Specifically, the maximum value of a 32-bit unsigned integer variable is 4,294,967,295. If time is measured in milliseconds, it can represent a maximum of approximately 49 days. Beyond this time, the variable will overflow, leading to timing errors.
[0066] During vehicle OTA upgrades, if the vehicle system or application cannot properly handle timestamp overflow (i.e., the aforementioned timing error), they may lose time synchronization with the server or other systems, leading to chaos or failure in the upgrade process.
[0067] Based on this, embodiments of this application provide a time processing method that can be applied to, for example... Figure 1 The application environment shown includes an OTA cloud platform, an OTA upgrade master control (UMC), an OTA upgrade agent (UA), and an OTA slave control (US).
[0068] Among them, UMC is responsible for the overall control and coordination of the entire OTA upgrade process. It is usually located in the vehicle's Car Multimedia Center (CDC) and uses the CDC's computing and storage resources to execute the upgrade strategy.
[0069] Among them, UA: As a bridge between UMC and US, it is responsible for transmitting upgrade data and instructions. It can be integrated into the vehicle gateway (Virtual Gateway, VGW) to achieve efficient interaction with CDC and Electronic Control Unit (ECU) by utilizing the network communication capabilities of VGW.
[0070] The US component, located within the ECU requiring upgrade, is responsible for receiving upgrade data and performing the flashing operation. It connects to the VGW via a CAN bus, receiving upgrade commands and data from the UMC.
[0071] During the OTA upgrade process, such as Figure 2 As shown, the UMC obtains the OTA upgrade package from a remote server or the cloud. The upgrade package may contain new ECU firmware, configuration files, etc. The UMC stores the upgrade package in the CDC's local storage or forwards it directly to the US via the UA. The UMC sends an upgrade preparation command to the US via the UA, including the upgrade package's version information, size, checksum, etc. After receiving the command, the US performs local storage preparation, backs up the current firmware, etc. The UMC sends the upgrade package data to the US in chunks or as a whole via the UA. Data transmission may use reliable communication protocols, such as TCP / IP (in Ethernet communication between the CDC and VGW) and CAN protocol (in communication between the VGW and ECU). After receiving the complete upgrade package data, the US performs the firmware flashing operation. The flashing process may include firmware verification, writing to flash memory, restarting the ECU, etc. After completing the flashing, the US sends an upgrade confirmation message to the UA. The UA forwards the confirmation message to the UMC, which records the upgrade status and may perform subsequent operations, such as updating the upgrade record, sending notifications, etc. In this embodiment, the CDC is equipped with an upgrade management module, which includes a timing management module and a state machine management module; the state machine management module includes a sending management module and a receiving management module.
[0072] In one exemplary embodiment, such as Figure 3 As shown, this embodiment provides a time processing method, which is applied to... Figure 1 Taking the main controller in the CDC as an example, the explanation includes:
[0073] S301, upon detecting a time update event for the local clock source corresponding to the main controller, obtains the corresponding candidate time from each candidate clock source other than the local clock source.
[0074] Understandably, the local clock source is mainly used to manage time management and synchronization within the main controller. It is usually an oscillator integrated inside the device, such as an RC oscillator or a crystal oscillator, located inside the main controller and serving as the main controller's own clock source.
[0075] Specifically, time update events for the local clock source corresponding to the main controller refer to a series of operations or conditions that affect or change the current time state of the local clock source. Optionally, the local clock source can automatically synchronize with an external high-precision clock source (such as GPS, network time server, etc.) periodically or based on specific conditions (such as time deviation reaching a certain threshold) to calibrate its own time. Users or system administrators can manually set the time of the local clock source through software interfaces, command-line tools, etc.
[0076] Among them, each candidate clock source includes the system clock source of the target vehicle system carrying the main controller, and the external clock source of the external device communicating with the main controller.
[0077] Understandably, the system clock source of the target vehicle system carrying the main controller refers to the clock source used to maintain time synchronization within the target vehicle system. It may be a combination of one or more high-precision clock sources used to provide a unified time reference for various parts of the system, and may be located at the center of the system or distributed across multiple nodes in the network.
[0078] In addition, the external clock source of the external device that communicates with the main controller is a clock signal source introduced from the outside. It is located outside the device and is connected to the device through physical connections (such as wires, interfaces, etc.), such as a network clock source.
[0079] S302 selects a reference time from the acquired candidate times based on the priority of each candidate clock source.
[0080] It is understandable that each candidate clock source is configured with a corresponding priority. Clock source priority refers to the priority value assigned to different clock sources. This value is used to guide the selection of the optimal clock source as the reference clock when multiple clock sources exist. The smaller the priority value, the higher the priority of the clock source. Optionally, users can manually set the clock source priority using configuration commands according to their actual needs. During configuration, the name of the clock source and its corresponding priority value must be specified.
[0081] S303 corrects the reference time based on the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time.
[0082] The target time has the same timing format as the local timing format, and the target time value is within the time range corresponding to the timing overflow mechanism.
[0083] In this embodiment, the local timing format of the local clock source can be the timing format based on the 32-bit integer variable described above.
[0084] Understandably, if the local clock source uses a 32-bit integer variable for timing, while the reference time uses a 64-bit integer variable, a timing overflow may occur in the local clock source. This is because the counting range of a 32-bit integer variable is limited. When the count value exceeds its upper limit, an overflow occurs, making it unable to correctly represent larger time values, and consequently causing the local time of the local clock source to fail to synchronize with the reference time.
[0085] In this scenario, the reference time is corrected based on its current timing format, the local clock source's local timing format, and its timing overflow mechanism. The target time can be obtained by: after confirming the overflow, calculating the time difference between the reference time and the local clock source's local time; and then correcting the local clock source's local time (local count value) based on this calculated time difference to ensure consistency with the reference time. This ensures the target time is adapted to the local clock source and synchronized with the reference time. In other words, the target time must be in a format that the local clock source can recognize and process. For example, if the local clock source uses a 32-bit unsigned integer variable for timing, then the target time must also be a 32-bit unsigned integer.
[0086] S304 uses the target time to update the local time of the local clock source.
[0087] Optionally, updating the local time of the local clock source using the target time means assigning the calibrated target time value to the local clock source to keep it synchronized with the reference time. Furthermore, when updating the local time of the local clock source using the target time, other characteristics of the local clock source, such as timing accuracy and resolution, are also considered.
[0088] In the aforementioned time processing method, this application increases the data sources for time synchronization and improves the reliability of time synchronization by obtaining candidate times from multiple candidate clock sources (including local clock sources and external clock sources). Even if a clock source fails or has a time deviation, accurate time information can still be obtained from other clock sources. The selection of a reference time based on the priority of each candidate clock source ensures the priority and accuracy of time synchronization. The priority of clock sources can be set according to actual conditions, prioritizing the use of more accurate and stable clock sources. After obtaining the reference time, it is corrected according to the current timing format of the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time. This step ensures the accuracy of time synchronization and avoids time deviations caused by mismatched timing formats or different overflow mechanisms. Through the adaptation and correction of the time format, the local clock source can accurately reflect the reference time, enhancing the adaptability of time synchronization. Even between different devices, accurate time synchronization can be achieved, thereby ensuring that vehicle OTA upgrades can be accurately implemented.
[0089] In one exemplary embodiment, detecting a time update event for the local clock source corresponding to the main controller includes at least one of the following:
[0090] (1) Received an OTA upgrade task for the target electronic control unit (ECU) using space download technology.
[0091] Among them, the target ECU is the ECU managed by the main controller.
[0092] Understandably, when the main controller receives an OTA upgrade task for one of the ECUs it manages, it needs to trigger a time update event to ensure time synchronization and accuracy during the upgrade process. This is because OTA upgrades typically involve software version updates, and the software version's timestamp and time control during the upgrade process are crucial for ensuring the success and security of the upgrade.
[0093] (2) Received a time update command for the local clock source corresponding to the main controller.
[0094] Optionally, the main controller may receive explicit time update instructions from higher-level systems, other controllers, or user interfaces. These instructions may stem from system maintenance, time calibration, or adjustments to time synchronization strategies. Upon receiving such an instruction, the main controller triggers a time update event to update the time of its local clock source according to the instruction.
[0095] (3) A timing overflow was detected in the local clock source.
[0096] Optionally, the local clock source may overflow due to a limited counting range, causing the time count to wrap around or reset. When the master controller detects such an overflow, a time update event needs to be triggered to maintain time continuity and accuracy. This typically involves handling the overflow, such as increasing the counting period, resetting the counter, or taking other corrective measures.
[0097] In one exemplary embodiment, the system clock source includes the interface time source of the operating system corresponding to the target vehicle system and / or the device clock source of the hardware devices deployed in the target vehicle system; external devices include a cloud platform and / or a vehicle gateway device in the target vehicle.
[0098] Understandably, the operating system's interface time source is the time interface provided by the operating system corresponding to the target vehicle system, typically used to obtain the system's current time. The operating system's time interface is usually based on the system clock, which is maintained by the operating system and may be synchronized with an external time source via a network time protocol (such as Network Time Protocol, NTP).
[0099] Device clock sources for hardware devices: The target vehicle system may deploy various hardware devices that may have their own clock sources to provide time information. For example, some sensors or controllers may have built-in real-time clock (RTC) modules to record and provide timestamps.
[0100] Furthermore, external devices are other devices located outside or inside the target vehicle system that communicate with the main controller; they may provide timing information as candidate time sources. These external devices may include:
[0101] OTA Cloud Platform: OTA cloud platforms typically provide accurate time services because they are based on network time synchronization protocols (such as NTP or PTP) for time synchronization. The main controller can obtain accurate time information by communicating with the OTA cloud platform.
[0102] Vehicle gateway device: The vehicle gateway acts as a bridge between the vehicle's internal network and the external network. It may integrate time synchronization functionality to ensure time consistency among devices within the vehicle. The main controller can obtain time information from the vehicle gateway device as a candidate time source.
[0103] In this embodiment, the cloud platform has a higher priority than the operating system, the operating system has a higher priority than the vehicle gateway, and the vehicle gateway has a higher priority than the hardware devices deployed in the target vehicle system.
[0104] In this embodiment, by including the cloud platform and vehicle gateway device within the scope of external devices and using them as candidate clock sources, the information sources for time synchronization can be further enriched, improving the flexibility and adaptability of time synchronization. Especially when the vehicle communicates or exchanges data with external networks, ensuring time consistency is crucial for guaranteeing data security and accuracy.
[0105] In one exemplary embodiment, such as Figure 4 As shown, the reference time is corrected according to the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time, including:
[0106] S401: When the current timing format corresponding to the reference time is inconsistent with the local timing format of the local clock source, the reference time is converted according to the format conversion relationship between the current timing format and the local timing format to obtain the alternative time under the local timing format.
[0107] Optionally, if the current timing format corresponding to the reference time is inconsistent with the local timing format of the local clock source, a format conversion is required first. This is because different timing formats may use different time representation methods, counting ranges, or resolutions, and direct comparison or application may lead to errors. To convert the reference time to the local timing format, the conversion relationship between the current timing format and the local timing format needs to be clearly defined. This may involve time unit conversion, counting range adjustment, timestamp format transformation, etc. By applying the format conversion relationship, the reference time is converted to a time representation in the local timing format, resulting in an alternative time. The alternative time is the equivalent representation of the reference time in the local timing format.
[0108] S402 uses a timing overflow mechanism from a local clock source to correct the alternative time and obtain the target time.
[0109] Understandably, due to the potential for timing overflow in the local clock source—that is, the count wraps around or resets after reaching a certain limit—overflow correction is necessary for the alternative time. Understanding the timing overflow mechanism of the local clock source is crucial for correcting the alternative time. This includes the conditions for overflow, the handling of overflow (such as wrap-around or reset), and the counting behavior after overflow. Based on the timing overflow mechanism, the alternative time is adjusted as necessary to ensure it is valid within the counting range of the local clock source and that the impact of overflow is taken into account. This may involve increasing the counting period, adjusting the starting point of the timestamp, or applying a specific correction algorithm. After overflow correction, the target time obtained is a time representation that is consistent with the reference time and valid on the local clock source.
[0110] In one possible implementation, a timing overflow mechanism of the local clock source is used to correct the candidate time to obtain the target time. This includes: if the candidate time exceeds the overflow limit time corresponding to the timing overflow mechanism of the local clock source, the candidate time is subtracted from the overflow limit time to obtain the target time.
[0111] Optionally, first clarify the timing overflow mechanism of the local clock source. Timing overflow typically occurs when the counter value reaches a preset upper limit, after which the counter wraps back to its starting value or resets to an initial state. This upper limit is the overflow upper limit time. When the alternative time exceeds the overflow upper limit time, it means that directly applying this time to the local clock source may lead to discontinuous or incorrect time counting. Therefore, correction is required. According to the timing overflow mechanism of the local clock source, if the alternative time exceeds the overflow upper limit time, the overflow upper limit time can be subtracted from the alternative time. The purpose of this is to "wrap back" the alternative time to the range that the counter can correctly represent. After the above correction, the obtained time is the target time. The target time is a time representation that is within the counting range of the local clock source and consistent with the reference time (considering the overflow effect).
[0112] For example, the absolute value of the reference time is compared with the largest unsigned integer of 32 bits (2 to the power of 32: 4,294,967,296). If it is greater than (note that if it is greater than 4,294,967,296, it indicates an overflow), then Y -4,294,967,296, until the absolute value of the reference time is less than 4,294,967,296.
[0113] In another possible implementation, the timing overflow mechanism of the local clock source is used to correct the candidate time to obtain the target time. This includes: if the candidate time is less than the overflow limit time corresponding to the timing overflow mechanism of the local clock source, and greater than the update duration required for the time update event, then the reference time is used as the target time.
[0114] The update duration required for a time update event is the difference between the upper limit of the overflow time and the lower limit of the overflow time corresponding to the timing overflow mechanism. For example, the lower limit of the overflow time corresponding to the timing overflow mechanism is 7 days. The update duration required for a time update event is the upper limit of the overflow time (49 days) - the lower limit of the overflow time (7 days), which represents the maximum time length that can be processed without overflow.
[0115] For example, if the absolute value of the reference time is less than 4,294,967,296, it is also necessary to determine whether the absolute value of the reference time is greater than the update duration required for the time update event. The update duration required for the time update event = 4,294,967,296 - 604,800,000 = 3,690,167.
[0116] The value 604,800,000 represents the absolute value of the 7-day running time, which is: 7 * 24 * 60 * 60 * 1000 = 604,800,000 milliseconds. This means that OTA can continuously upgrade and flash for 7 days without timeout or overflow. Generally, OTA upgrades and flashes do not exceed 4 hours, so reserving this value is sufficient to meet system requirements.
[0117] In the example above, the overflow upper limit is set to 49 days, and the overflow lower limit is 7 days. Therefore, the required update time for a time update event is 49 days minus 7 days, or 42 days. This means that within a 42-day timeframe, the system can process any time update event without overflowing.
[0118] If the alternative time is between the lower and upper overflow limits (i.e., between 7 and 49 days) and does not exceed any other timing restrictions or constraints, then we can directly use the alternative time (after the necessary format conversion) as the target time. If the alternative time exceeds the upper overflow limit or falls below the lower overflow limit, then additional correction logic is needed to ensure that the target time is within a valid counting range.
[0119] In one exemplary embodiment, the reference time includes an integer time portion and a fractional time portion; such as Figure 5 As shown, the reference time is corrected according to the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time, including:
[0120] S501 corrects the integer part of the reference time according to the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time.
[0121] Optionally, the current timing format corresponding to the reference time and the local timing format of the local clock source can be explicitly specified. These two formats may differ; for example, the reference time may be in milliseconds, while the local clock source may be in seconds or larger time units.
[0122] Furthermore, combining S401 to S402 above, based on the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source, the integer part of the reference time is corrected to obtain the target time, including:
[0123] Based on the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source, the integer part of the reference time is corrected to obtain the candidate time; the timing overflow mechanism of the local clock source is then used to correct the candidate time to obtain the target time.
[0124] S502 uses the target time to update the local time of the local clock source, including: using the sum of the target time and the fractional time part as the updated local time of the local clock source.
[0125] Specifically, based on the integer part of the reference time and the timing format of the local clock source, the integer part of the reference time is converted into a format that the local clock source can recognize. If the integer part of the reference time exceeds the overflow upper limit or falls below the overflow lower limit of the local clock source, appropriate correction logic needs to be applied. This may involve subtracting or adding a fixed value to ensure that the result is within the valid counting range of the local clock source.
[0126] For example, the integer part of the elapsed reference time is converted to the target time, denoted as Y, and the fractional part of the elapsed reference time is converted to delta milliseconds with a precision of 1 millisecond. Y = Y + delta is then used as the updated local time from the local clock source.
[0127] In one exemplary embodiment, such as Figure 6 As shown, the method also includes:
[0128] S601, upon receiving a time update request initiated by the controller, encrypts the updated local time corresponding to the local clock source to obtain the encrypted time.
[0129] The controller can be either the vehicle gateway or the ECU mentioned above.
[0130] Specifically, a time update request is received from the controller. This means the slave controller needs to update its local time to maintain synchronization with the master controller or other components. Upon receiving the time update request, the updated local time corresponding to the local clock source is encrypted. The purpose of encryption is to protect the authenticity and integrity of the time, preventing unauthorized intruders from tampering with or forging time information. The encryption process may involve using specific encryption algorithms and keys. The security of the keys is crucial and must be properly kept to prevent leakage to unauthorized intruders. After encryption, the encrypted time information is obtained. This encrypted time will be used for subsequent communication and time update processes.
[0131] S602 sends the encrypted time to the slave controller so that the slave controller can update its local time according to the encrypted time.
[0132] Specifically, the encrypted time is sent to the slave controller. This is typically achieved via network or bus communication, depending on the architecture and communication protocol. Upon receiving the encrypted time, the slave controller decrypts it using the appropriate decryption algorithm and key. The decrypted time becomes the updated local time. The slave controller updates its local time based on the decrypted time to ensure synchronization with the master controller or other components.
[0133] During the decryption process, the controller checks whether the base time in the upgrade package matches the actual base time read, or whether it is within the allowable error range. If the difference is significant (such as 1,438,100 milliseconds in the example above, far exceeding 2 seconds), it is determined to be an illegal upgrade request, and the OTA upgrade fails. When the controller detects a base time mismatch, it triggers a receive timeout mechanism, meaning the upgrade package is not processed, and a warning message may be sent to the user or the remote server. This timeout mechanism effectively prevents unauthorized intruders from bypassing security verification by forging base time.
[0134] Understandably, because the base time is dynamically changing and closely related to time, unauthorized intruders cannot simply replay previously captured legitimate upgrade packages to pass verification. The upgrade package contains sensitive information such as the base time during encryption; any tampering with the upgrade package will result in decryption failure, thus preventing unauthorized upgrades.
[0135] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0136] Based on the same inventive concept, this application also provides a time processing apparatus for implementing the time processing method described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method; therefore, the specific limitations in one or more time processing apparatus embodiments provided below can be found in the limitations of the time processing method described above, and will not be repeated here.
[0137] In one exemplary embodiment, such as Figure 7As shown, a time processing device is provided, including: a multi-source time acquisition module 11, a multi-source time selection module 12, a time correction module 13, and a time update module 14; wherein:
[0138] The multi-source time acquisition module 11 is used to acquire the corresponding candidate time from each candidate clock source other than the local clock source when a time update event for the local clock source corresponding to the main controller is detected; wherein, each candidate clock source includes the clock source of the target vehicle system carrying the main controller, and the external clock source of the external device communicating with the main controller.
[0139] The multi-source time selection module 12 is used to select a reference time from the acquired candidate times according to the priority of each candidate clock source;
[0140] The time correction module 13 is used to correct the reference time according to the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time; wherein, the timing format of the target time is consistent with the local timing format, and the time value of the target time is within the time range corresponding to the timing overflow mechanism.
[0141] The time update module 14 is used to update the local time of the local clock source using the target time.
[0142] In one embodiment, detecting a time update event for a local clock source corresponding to the main controller includes at least one of the following:
[0143] Received an OTA upgrade task for the target electronic control unit (ECU); the target ECU is the ECU managed by the main controller.
[0144] Received a time update command for the local clock source corresponding to the main controller;
[0145] A timing overflow was detected in the local clock source.
[0146] In one embodiment, the clock source includes the interface time source of the operation corresponding to the target vehicle system and / or the device clock source of the hardware devices deployed in the target vehicle system;
[0147] External devices include a cloud platform and / or a vehicle gateway device in the target vehicle. In one embodiment,
[0148] In one embodiment, the time correction module 13 is used to: when the current timing format corresponding to the reference time is inconsistent with the local timing format of the local clock source, convert the reference time according to the format conversion relationship between the current timing format and the local timing format to obtain the alternative time under the local timing format.
[0149] The timing overflow mechanism of the local clock source is used to correct the alternative time and obtain the target time.
[0150] In one embodiment, the time correction module 13 is used to: if the candidate time exceeds the overflow limit time corresponding to the timing overflow mechanism of the local clock source, subtract the overflow limit time from the candidate time to obtain the target time.
[0151] In one embodiment, the time correction module 13 is used to: if the alternative time is less than the overflow limit time corresponding to the timing overflow mechanism of the local clock source, and greater than the update duration required for the time update event, then the reference time is used as the target time.
[0152] In one embodiment, the time update module 14 is used to: correct the integer part of the reference time according to the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source, to obtain the target time;
[0153] The target time is used to update the local time of the local clock source, including:
[0154] The sum of the target time and its fractional part is used as the updated local time from the local clock source.
[0155] In one embodiment, the device further includes an encryption module, which is used to: encrypt the updated local time corresponding to the local clock source to obtain an encrypted time upon receiving a time update request initiated from the controller;
[0156] The encrypted time is sent to the slave controller so that the slave controller can update its local time based on the encrypted time.
[0157] Each module in the aforementioned time processing device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the operations corresponding to each module.
[0158] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 8As shown, this computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a bus, and the communication interface is connected to the bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores operations, computer programs, and a database. The internal memory provides an environment for the operation and execution of the computer programs stored in the non-volatile storage media. The database stores data for time processing methods. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a time processing method.
[0159] Those skilled in the art will understand that Figure 8 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0160] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0161] Upon detecting a time update event for the local clock source corresponding to the main controller, the corresponding candidate time is obtained from each candidate clock source other than the local clock source; wherein, each candidate clock source includes the clock source of the target vehicle system carrying the main controller, and the external clock source of the external device communicating with the main controller.
[0162] Based on the priority of each candidate clock source, a reference time is selected from the acquired candidate times;
[0163] The reference time is corrected based on the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time; wherein, the timing format of the target time is consistent with the local timing format, and the time value of the target time is within the time range corresponding to the timing overflow mechanism.
[0164] The target time is used to update the local time of the local clock source.
[0165] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, the computer program performing the following steps when executed by a processor:
[0166] Upon detecting a time update event for the local clock source corresponding to the main controller, the corresponding candidate time is obtained from each candidate clock source other than the local clock source; wherein, each candidate clock source includes the clock source of the target vehicle system carrying the main controller, and the external clock source of the external device communicating with the main controller.
[0167] Based on the priority of each candidate clock source, a reference time is selected from the acquired candidate times;
[0168] The reference time is corrected based on the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time; wherein, the timing format of the target time is consistent with the local timing format, and the time value of the target time is within the time range corresponding to the timing overflow mechanism.
[0169] The target time is used to update the local time of the local clock source.
[0170] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, performs the following steps:
[0171] Upon detecting a time update event for the local clock source corresponding to the main controller, the corresponding candidate time is obtained from each candidate clock source other than the local clock source; wherein, each candidate clock source includes the clock source of the target vehicle system carrying the main controller, and the external clock source of the external device communicating with the main controller.
[0172] Based on the priority of each candidate clock source, a reference time is selected from the acquired candidate times;
[0173] The reference time is corrected based on the current timing format corresponding to the reference time, the local timing format of the local clock source, and the timing overflow mechanism of the local clock source to obtain the target time; wherein, the timing format of the target time is consistent with the local timing format, and the time value of the target time is within the time range corresponding to the timing overflow mechanism.
[0174] The target time is used to update the local time of the local clock source.
[0175] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0176] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0177] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A time processing method, characterized in that, The method, applied to a main controller in a vehicle, includes: If a time update event is detected for the local clock source corresponding to the main controller, the corresponding candidate time is obtained from each candidate clock source other than the local clock source; Based on the priority of each candidate clock source, a reference time is selected from the acquired candidate times; If the current timing format corresponding to the reference time is inconsistent with the local timing format of the local clock source, the reference time is converted according to the format conversion relationship between the current timing format and the local timing format to obtain the alternative time under the local timing format; If the candidate time exceeds the overflow limit time corresponding to the timing overflow mechanism of the local clock source, the candidate time is subtracted from the overflow limit time to obtain the target time; or, if the candidate time is less than the overflow limit time and greater than the update duration required by the time update event, the reference time is used as the target time; wherein, the timing format of the target time is consistent with the local timing format, and the time value of the target time is within the time range corresponding to the timing overflow mechanism; The local time of the local clock source is updated using the target time.
2. The method according to claim 1, characterized in that, The detection of a time update event for the local clock source corresponding to the main controller includes at least one of the following: A OTA (Over-The-Air) upgrade task for a target Electronic Control Unit (ECU) is received; wherein the target ECU is the ECU managed by the main controller. Receives a time update command for the local clock source corresponding to the main controller; A timing overflow was detected in the local clock source.
3. The method according to claim 1, characterized in that, Each candidate clock source includes the system clock source of the target vehicle system carrying the main controller, and the external clock source of the external device communicating with the main controller; The system clock source includes the interface time source of the operating system corresponding to the target vehicle system and / or the device clock source of the hardware devices deployed in the target vehicle system; The external devices include a cloud platform and / or a vehicle gateway device in the target vehicle.
4. The method according to claim 1, characterized in that, The reference time includes an integer time part and a decimal time part; The step of converting the reference time according to the format conversion relationship between the current timing format and the local timing format to obtain the alternative time under the local timing format includes: Based on the format conversion relationship between the current timing format and the local timing format, the integer part of the reference time is converted to obtain the alternative time; The step of updating the local time of the local clock source using the target time includes: The sum of the target time and the fractional time portion is used as the updated local time of the local clock source.
5. The method according to claim 1, characterized in that, The method further includes: Upon receiving a time update request initiated by the controller, the updated local time corresponding to the local clock source is encrypted to obtain the encrypted time. The encrypted time is sent to the slave controller so that the slave controller can update its local time based on the encrypted time.
6. The method according to claim 1, characterized in that, The step of selecting a reference time from the acquired candidate times based on the priority of each candidate clock source includes: From all candidate clock sources, select the candidate clock source with the highest priority as the reference clock source; Obtain the reference time of the reference clock source; wherein, the smaller the priority value of each candidate clock source, the higher the priority of the candidate clock source.
7. A time processing device, characterized in that, A main controller configured in a vehicle, the device comprising: The multi-source time acquisition module is used to acquire corresponding candidate times from each candidate clock source other than the local clock source when a time update event for the local clock source corresponding to the main controller is detected. The multi-source time selection module is used to select a reference time from the acquired candidate times based on the priority of each candidate clock source. A time correction module is used to convert the reference time into a candidate time in the local time format when the current timing format corresponding to the reference time is inconsistent with the local timing format of the local clock source, based on the format conversion relationship between the current timing format and the local timing format. If the candidate time exceeds the overflow limit time corresponding to the timing overflow mechanism of the local clock source, the overflow limit time is subtracted from the candidate time to obtain the target time. Alternatively, if the candidate time is less than the overflow limit time and greater than the update duration required for the time update event, the reference time is used as the target time. The timing format of the target time is consistent with the local timing format, and the time value of the target time is within the time range corresponding to the timing overflow mechanism. The time update module is used to update the local time of the local clock source using the target time.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Synchronization time determination method, time synchronization device, time synchronization system and medium
CN117675072A
Time correction device and method and intelligent vehicle
CN117978317A