Disclosure of Invention
In order to solve the defect that the communication stability and the driving safety of a vehicle are influenced by taking invalid time source time as synchronization time in the prior art, the invention provides a time synchronization method of a vehicle-mounted terminal, which comprises the following steps:
acquiring system time generated by a timing module;
acquiring time source time and judging the validity of the time source time;
and if the time source time is valid, taking the time source time as synchronous time, otherwise, taking the system time as synchronous time.
Preferably, the step of obtaining the time source time and judging the validity of the time source time includes:
recording the system time as system recording time while acquiring the time source time, and obtaining a difference time by taking a difference value between the time source time and the system recording time;
if the difference time is smaller than a preset threshold value, the time source time is judged to be valid, otherwise, the time source time is judged to be invalid.
Preferably, the threshold is a theoretical error of the timing module.
Preferably, before the acquiring the time source time, the method further includes: and taking the system time as a synchronization time. The invention also provides a time synchronization system of the vehicle-mounted terminal, which comprises:
the timing module is used for generating and acquiring system time;
the time source module is used for acquiring the time source time and judging the validity of the time source time;
and the first synchronization module is used for taking the time source time as the synchronization time when the time source time is effective, and taking the system time as the synchronization time otherwise.
Preferably, the time source time judging module includes:
the computing module is used for obtaining a difference value by taking a difference value between the time source time and the system recording time;
and the judging module is used for judging that the time source time is valid if the difference time is smaller than a preset threshold, and otherwise, the time source time is invalid.
Preferably, the vehicle-mounted terminal time synchronization system further includes:
and the second synchronization module is used for taking the system time as the synchronization time before the time source time is acquired.
The present invention also provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps described in a vehicle-mounted terminal time synchronization method as provided by the present invention.
The method can effectively judge the validity of the time for the vehicle system to acquire the positioning satellite or the internet server, prevent the potential hazards that the data communication is failed or the vehicle-mounted intelligent driving system is influenced due to the fact that the time information is obtained wrongly when the vehicle passes through a tunnel, a mountain area or in cloud, fog, rain and snow weather, and improve the stability of the data communication between the vehicle system and the outside and the safety of vehicle driving.
Detailed Description
In order to further explain the time synchronization method of the vehicle-mounted terminal provided by the present invention, the embodiment is described in detail with reference to fig. 1.
Step S1: and acquiring the system time recorded by the timing module.
The vehicle-mounted terminal provided in this embodiment includes, but is not limited to, vehicle-mounted terminals such as a vehicle instrument system, a multimedia system, a navigation system, an intelligent (auxiliary) driving system, and an internet of vehicles system. The time source may be a satellite positioning system (GPS, beidou, etc.) or an internet server. After the vehicle-mounted terminal is powered on, the vehicle-mounted terminal starts to operate, message data, operation state data and the like are generated during operation, and the system recorded data carry time information so as to be used as a judgment requirement for keeping information synchronization between the vehicle-mounted terminal and a satellite positioning system or an internet server and analyze the vehicle-mounted terminal recorded data in the future.
The vehicle-mounted terminal is provided with a timing module, and the timing module can record the system time T1 in real time during the power-off or power-on period of the vehicle-mounted terminal. The timing module may be a timing program written in the vehicle-mounted terminal, or may be a system timer embedded in the vehicle-mounted terminal, such as a timing clock.
Step S2: and acquiring time source time and judging the validity of the time source time.
It is understood that the acquisition time source time may be the time source time T2 directly acquired by the vehicle-mounted terminal directly requesting the satellite positioning system or the internet server, or may be time information extracted from real-time communication data of the satellite positioning system or the internet server and the vehicle-mounted terminal as the time source time T2.
Since the situation that the time is not acquired smoothly due to data communication is wrong may exist when the vehicle passes through a tunnel, in a mountain area or in cloud, fog, rain and snow weather, if wrong time information is synchronized into the vehicle-mounted terminal, hidden dangers that data communication fails or the vehicle-mounted intelligent driving system is affected may be generated, the validity of the time source time needs to be judged firstly after the time source time is acquired from the satellite positioning system or the internet server, and other operations such as time synchronization are adopted after the time source time is ensured to be valid. The specific process of judging the validity of the time source time is that the timing module of the vehicle-mounted terminal records the system recording time T3 generated by the system timer when the time source module acquires the time source time T2. The time source module then calculates the difference between the time source time T2 and the system recording time T3 to obtain the difference time T1.
If the difference time T1 is smaller than a preset threshold, the time source time T2 is determined to be valid, and if the difference time T1 is larger than the preset threshold, the time source time T2 is determined to be invalid. The threshold is the same as the theoretical error of the timing module, or may be another value set according to the actual use condition, for example, in the automatic driving stage of the vehicle, the requirement for the accuracy of time synchronization is high, and in this case, a certain value smaller than the theoretical error of the timing module may be set as the threshold according to the specific design requirement, so as to improve the judgment standard of the time validity of the time source.
Step S3: and if the time source time is valid, taking the time source time as the synchronous time, and otherwise, taking the system time as the synchronous time.
It can be understood that if the time source time T2 is valid, the synchronization time T4 is updated based on the time source time T2 and serves as a uniform time for the vehicle-mounted terminal, so as to ensure that the time of each functional module of the vehicle-mounted terminal is consistent during data processing or interaction with the satellite positioning system or the internet server. If the time source time T2 is invalid, the synchronization time T4 is updated to the system time T1.
For some special cases, for example, when a vehicle is started for the first time and the vehicle-mounted terminal is powered on, each functional module in the vehicle-mounted terminal may have a time synchronization requirement to ensure that data recording time of each functional module is consistent when data is exchanged, but at this time, the time of the vehicle-mounted terminal is not required to be highly consistent with that of the satellite positioning system or the internet server, and no time source time is required to be acquired, or when the vehicle enters a tunnel, a mountain area, or in some extreme weather, the vehicle-mounted terminal has a requirement to acquire the time source time, but the vehicle-mounted terminal cannot establish communication with the satellite positioning system or the internet server, and cannot acquire the time source time, in this special case, in order to ensure that each functional module of the vehicle-mounted terminal can still maintain time consistency, the embodiment further provides an optimal scheme, as shown in fig. 2, that is before the vehicle-mounted terminal acquires the time, the system time is taken as the synchronization time. It should be noted that, whether the vehicle-mounted terminal has a need to acquire the time source time and whether the vehicle-mounted terminal can successfully establish communication with the satellite positioning system or the internet server can be obtained through conventional technical means or common knowledge by those skilled in the art, and details are not described herein again.
It is understood that the time information in the system recording data generated when the in-vehicle terminal operates in the time period from the power-on to the acquisition of the time source time is provided by the timing module, that is, the timing module records the system time T1 corresponding to the time when the in-vehicle terminal recording data is generated. The synchronization module updates the system time T1 recorded by the timing module to each vehicle-mounted system as the synchronization time T4, so that the time of each functional module of the vehicle-mounted system is kept consistent. The optimal time synchronization method of the vehicle-mounted terminal comprises the following steps:
step S11: acquiring system time generated by a timing module;
step S21: before the time source time is obtained, taking the system time as the synchronization time;
step S31: acquiring time source time and judging the validity of the time source time;
step S41: and if the time source time is valid, taking the time source time as the synchronous time, and otherwise, taking the system time as the synchronous time.
The embodiment further discloses a vehicle-mounted terminal time synchronization system 100, as shown in fig. 3, the vehicle-mounted terminal time synchronization system 100 includes:
the timing module 101 is used for acquiring system time T1;
the time source module 102 is configured to obtain a time source time T2 and determine validity of the time source time T2;
a first synchronization module 103 for updating the synchronization time T4 to the time source time T2 when the time source time T2 is valid; when the time source time T2 is invalid, the synchronization time T4 is updated to the system time T1.
In some embodiments, as shown in fig. 4, the timing module 101 includes:
a system timer 1011 for recording the system time T1 in real time;
a system time recording module 1012, configured to record the system time generated by the system timer 1011 as a system recording time T3 while the time source module 102 obtains the time source time T2.
In some embodiments, as shown in fig. 5, the time source module 102 includes:
a time source obtaining module 1021, configured to obtain a time source time T2;
the time source determining module 1022 is configured to determine validity of the time source time.
In some embodiments, as shown in fig. 6, the time source determining module 1022 includes:
the calculating module 1023 is used for obtaining a difference value time T1 by taking the difference value between the time source time T2 and the system recording time T3;
the determining module 1024 is configured to determine that the time source time T2 is valid if the difference time T1 is smaller than a preset threshold, and otherwise, the time source time T2 is invalid.
As shown in fig. 7, preferably, the vehicle-mounted terminal time synchronization system further includes:
and a second synchronization module 104, configured to take the system time as the synchronization time before acquiring the time source time.
The time synchronization system of the vehicle-mounted terminal provided in the embodiment of the present disclosure may be configured to perform the steps of the time synchronization method of the vehicle-mounted terminal described in any one of the above, and the related concepts and the specific implementation manners may refer to the description of the time synchronization method of the vehicle-mounted terminal described in any one of the above, which are not described herein again.
The embodiment of the present disclosure further provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps of the time synchronization method for a vehicle-mounted terminal are implemented, and the same technical effects can be achieved, and in order to avoid repetition, the details are not repeated here. The computer-readable storage medium includes, but is not limited to, a Read-Only Memory (ROM), a Random Access Memory (RAM), a usb disk, a removable hard disk, or an optical disk.
In the present invention, the term "comprises" is not an exclusive inclusion, i.e. includes not only the listed technical contents for implementing the technical solution of the present invention, but also the technical contents which are not explicitly listed for assisting the implementation of the technical solution of the present invention, which can be obtained by the conventional technical means or common general knowledge by those skilled in the art, and will not be described herein again.
The above is only a preferred embodiment of the present invention, and it should be noted that the above preferred embodiment should not be considered as limiting the present invention, and the protection scope of the present invention should be subject to the scope defined by the claims. It will be apparent to those skilled in the art that various substitutions and modifications can be made without departing from the spirit and scope of the invention, and these substitutions and modifications should also be construed as within the scope of the invention.