Time synchronization method and device based on AP and storage medium
By using the socket interface function library to communicate between the TS client and the gptp protocol stack in the AP, removing the TS server, and correcting the timestamp through the time difference, the contradiction between the concealment and time accuracy of the clock synchronization protocol in the AP is solved, and improves Improves time accuracy and reduces program running errors.
Patent Information
- Application Number
- CN202410733215.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-06
- Publication Date
- 2024-09-03
AI Technical Summary
In the AP, the gptp protocol stack clock synchronization protocol used by the TS module has a conflict between code concealment requirements and time accuracy, which cannot effectively meet the concealment requirements of the AP. At the same time, it leads to program running errors caused by clock desynchronization.
By using the socket interface function library to communicate between the TS client and the gptp protocol stack, the TS server is removed, and the time difference is used to correct the obtained timestamp, simplifying the communication process, reducing time delay, and improving time accuracy.
While meeting the code concealment requirements in the AP, it also improves the time accuracy obtained by the TS side, reduces program running errors caused by clock desynchronization, and ensures the stability of the program in the AP.
Smart Images

Figure CN118590171A
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of time synchronization, and in particular to an AP-based time synchronization method, device and storage medium. Background Art
[0002] AP (Adaptive Platform) is one of the latest versions of the AUTOSAR architecture. It is a service-oriented architecture that supports multiple communication protocols and multiple hardware platforms, and has high flexibility and scalability, designed to meet the needs of future automotive electronic systems. AP provides a standardized software platform for developing applications in automotive electronic systems, allowing applications to be easily integrated and deployed.
[0003] In the AP, the TS (time sensing) module is responsible for clock synchronization to keep the time of each system consistent. Among them, the TS module uses gptp (general precise time protocol), which is an open source protocol and complies with the open source license regulations. Therefore, if you want to modify gptp or use shared memory to communicate with the gptp protocol stack, you must disclose the code that implements communication with the gptp protocol stack, which does not meet the AP code concealment requirements. Summary of the invention
[0004] The present application aims to solve at least one of the technical problems in the related art to a certain extent. To this end, one purpose of the present application is to propose a time synchronization method, device and storage medium based on AP, which can not only meet the concealment requirements of AP, but also make the time obtained by TS more accurate.
[0005] In a first aspect, this embodiment provides an AP-based time synchronization method, which is applied to a TS client, including:
[0006] The socket-based interface function library sends a time acquisition request to the gptp protocol stack;
[0007] Receive response information, and obtain the time when the gptp protocol stack receives the time acquisition request and the time when the gptp protocol stack returns the response information; wherein the response information is generated by the gptp protocol stack based on the time acquisition request and returned through the interface function library;
[0008] The time difference is determined based on the time of sending the time acquisition request, the time of receiving the time acquisition request by the gptp protocol stack, the time of returning the response information by the gptp protocol stack, and the time of receiving the response information, so that the time obtained by calling the function of acquiring the current time of the system can be corrected according to the time difference.
[0009] In some embodiments, the interface function library includes a libnet library.
[0010] In some embodiments, sending a time acquisition request to the gptp protocol stack includes:
[0011] Send a time acquisition request to the gptp protocol stack through the first thread;
[0012] The receiving response information includes:
[0013] The response information is received through the second thread.
[0014] In some embodiments, determining the time difference based on the time of sending the time acquisition request, the time of receiving the time acquisition request by the gptp protocol stack, the time of returning the response information by the gptp protocol stack, and the time of receiving the response information includes:
[0015] The TS client determines the time difference based on the following formula:
[0016] offset = (t1 - t3 - t2 + t4) / 2;
[0017] Among them, offset represents the time difference; t1 represents the time when the TS client sends the time acquisition request; t2 represents the time when the gptp protocol stack receives the time acquisition request; t3 represents the time when the gptp protocol stack returns the response information; t4 represents the time when the TS client receives the response information.
[0018] In some embodiments, the step of correcting the time obtained by calling a function to obtain the current time of the system according to the time difference includes:
[0019] The TS client will call the function to obtain the current time of the system and obtain the time, and the sum of the time difference as the time of the gptp protocol stack.
[0020] In a second aspect, this embodiment provides an AP-based time synchronization method, which is applied to a gptp protocol stack, including:
[0021] Receive the time acquisition request sent by the TS client through the socket interface function library;
[0022] Generate response information based on the time acquisition request, and return the response information to the TS client through the interface function library, so that the TS client can obtain the time when the gptp protocol stack receives the time acquisition request and the time when the gptp protocol stack returns the response information based on the response information, so that the TS client can determine the time difference based on the time when the time acquisition request is sent, the time when the gptp protocol stack receives the time acquisition request, the time when the gptp protocol stack returns the response information, and the time when the response information is received, so that the TS client can correct the time obtained by calling the function to obtain the current time of the system according to the time difference.
[0023] In some embodiments, the AP-based time synchronization method further includes:
[0024] Receiving a plurality of the time acquisition requests respectively through a plurality of third threads;
[0025] The plurality of response messages are returned respectively through the plurality of fourth threads.
[0026] In a third aspect, this embodiment further provides an AP-based time synchronization device, which is applied to a TS client and includes:
[0027] A first sending unit, configured to send a time acquisition request to a gptp protocol stack based on a socket interface function library;
[0028] A first receiving unit is used to receive response information, and obtain the time when the gptp protocol stack receives the time acquisition request and the time when the gptp protocol stack returns the response information; wherein the response information is generated by the gptp protocol stack based on the time acquisition request and returned through the interface function library;
[0029] A determination unit is used to determine a time difference based on the time of sending the time acquisition request, the time of receiving the time acquisition request by the gptp protocol stack, the time of returning the response information by the gptp protocol stack, and the time of receiving the response information, so as to correct the time obtained by calling the function of acquiring the current time of the system according to the time difference.
[0030] In a fourth aspect, this embodiment further provides an AP-based time synchronization device, which is applied to a gptp protocol stack, including:
[0031] The second receiving unit is used to receive a time acquisition request sent by the TS client through the socket interface function library;
[0032] The second sending unit is used to generate response information based on the time acquisition request, and return the response information to the TS client through the interface function library, so that the TS client can obtain the time when the gptp protocol stack receives the time acquisition request and the time when the gptp protocol stack returns the response information based on the response information, so that the TS client can determine the time difference based on the time of sending the time acquisition request, the time when the gptp protocol stack receives the time acquisition request, the time when the gptp protocol stack returns the response information, and the time of receiving the response information, so that the TS client can correct the time obtained by calling the function of obtaining the current time of the system according to the time difference.
[0033] In a fifth aspect, this embodiment further provides a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, the method as described in any one of the above items is implemented.
[0034] The AP-based time synchronization method, device and storage medium provided in the present embodiment meet the AP's concealment requirements by removing the TS server during the communication between the TS client and the gptp protocol stack, and communicating through a socket-based interface function library; and can determine the time difference through the timestamp of data transmission between the TS client and the gptp protocol stack, so that the TS client can correct the time obtained by calling the function of obtaining the current time of the system according to the time difference. In this way, the present embodiment is conducive to simplifying the communication process between the TS client and the gptp protocol stack and reducing time delays. Combined with the correction through the time difference, the time obtained by the TS end can be made more accurate, reducing or even avoiding program running errors caused by clock asynchrony.
[0035] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 It is a flowchart of an AP-based time synchronization method (applied to a TS client) provided by an exemplary embodiment;
[0037] Figure 2 It is a flowchart of an AP-based time synchronization method (applied to the gptp protocol stack) provided by an exemplary embodiment;
[0038] Figure 3 It is a schematic diagram of an interaction process between a TS client and a gptp protocol stack provided by an exemplary embodiment;
[0039] Figure 4It is a structural diagram of an AP-based time synchronization device (applied to a TS client) provided by an exemplary embodiment;
[0040] Figure 5 It is a structural diagram of an AP-based time synchronization device (applied to the gptp protocol stack) provided by an exemplary embodiment. DETAILED DESCRIPTION
[0041] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limiting the present application.
[0042] In related technologies, in order to meet the code hiding requirements of AP, TS_consumer (also known as TS client) can use socket to communicate with gptp protocol stack to achieve isolation. Exemplary, the communication scenario may include: TS_consumer, TS_server (also known as TS server), gptp protocol library. The communication link is: TS_consumer, TS_server, gptp protocol library; gptp protocol library, TS_server, TS_consumer.
[0043] TS_consumer and TS_server use socket communication to obtain the current time. After TS_consumer sends a request, when it receives the current time message returned by TS_server, some time has passed since TS_consumer sent the request to obtain the current time, that is, there is a delay in transmission time, which will lead to poor accuracy of the time obtained by the TS module, and the delay will make the time of each communication transmission end inconsistent, which is very easy to cause unpredictable errors in program operation and affect the stability of program operation in AP.
[0044] This embodiment provides an AP-based time synchronization method. During the communication between the TS client and the gptp protocol stack, the TS server is removed, and communication is performed through a socket-based interface function library to meet the AP's concealment requirements; and the TS client can determine the time difference through the timestamp of data transmission with the gptp protocol stack, so that the TS client can correct the time obtained by calling a function to obtain the current time of the system according to the time difference. In this way, this embodiment is conducive to simplifying the communication process between the TS client and the gptp protocol stack and reducing time delays. Combined with the correction through the time difference, the time obtained by the TS end can be made more accurate, reducing or even avoiding program running errors caused by clock asynchrony, which is conducive to ensuring the stability of program running in the AP.
[0045] The implementation process of the AP-based time synchronization method of the embodiment of the present application is described below with reference to the accompanying drawings.
[0046] Please refer to Figure 1 The AP-based time synchronization method provided in this embodiment is applied to a TS client and includes the following steps S101 to S103:
[0047] S101, sending a time acquisition request to the gptp protocol stack;
[0048] S102, receiving response information, and obtaining the time when the gptp protocol stack receives the time acquisition request and the time when the gptp protocol stack returns the response information; wherein the response information is generated by the gptp protocol stack based on the time acquisition request and returned through the interface function library;
[0049] S103, determining the time difference based on the time of sending the time acquisition request, the time of receiving the time acquisition request by the gptp protocol stack, the time of returning the response information by the gptp protocol stack, and the time of receiving the response information, so as to correct the time obtained by calling the function of acquiring the current time of the system according to the time difference.
[0050] In step S101, after the TS client generates a time acquisition request for acquiring time data, the TS client calls a communication interface in a socket-based interface function library and sends the time acquisition request to the gptp protocol stack.
[0051] In some examples, the TS client may also generate a time acquisition request based on the data requesting the time acquisition and the gptp data, and send the time acquisition request to the gptp protocol stack through a socket-based interface function library.
[0052] Correspondingly, the gptp protocol stack receives the time acquisition request and performs parsing processing, the gptp protocol stack obtains the time requested by the TS client based on the parsed information, the gptp protocol stack generates response information based on the time requested by the TS client, and the gptp protocol stack returns the response information to the TS client through a socket-based interface function library. The time requested by the TS client may include: the time when the gptp protocol stack receives the time acquisition request and the time when the gptp protocol stack returns the response information.
[0053] In other examples, the data requested by the TS client to obtain the time can be divided into the first type of data and the second type of data according to the confidentiality requirements, and the confidentiality of the first type of data is lower than that of the second type of data. The TS client merges the first type of data with the gptp data and sends it directly to the gptp protocol stack; the TS client generates a time acquisition request based on the second type of data and sends it to the gptp protocol stack based on the socket interface function library. Among them, the first type of data and the second type of data have the same or matching identifiers, so that the gptp protocol stack can identify the corresponding first type of data and second type of data.
[0054] Correspondingly, the gptp protocol stack receives the time acquisition request and the first type of data and performs parsing processing. The gptp protocol stack obtains the time requested by the TS client based on the parsed information to return the time requested by the TS client to the TS client. Among them, the gptp protocol stack divides the data to be returned into the first type of data and the second type of data according to the confidentiality requirements, and the confidentiality of the first type of data is lower than that of the second type of data; the gptp protocol stack can return the first type of data directly to the TS client, and generate response information for the second data and return it to the TS client through the socket-based interface function library.
[0055] In step S102, in some examples, when the gptp protocol stack generates response information based on the time requested by the TS client and returns it to the TS client through the socket-based interface function library, the TS client obtains the requested time based on the response information after receiving the response information. The requested time includes: the time when the gptp protocol stack receives the time acquisition request and the time when the gptp protocol stack returns the response information.
[0056] In other examples, the gptp protocol stack returns the first type of data directly to the TS client, and generates response information from the second data and returns it to the TS client through a socket-based interface function library. The TS client obtains the time requested by the TS client based on the response information and the first type of data.
[0057] In step S103, the TS client calculates the time difference according to the time of sending the time acquisition request, the time of receiving the time acquisition request by the gptp protocol stack, the time of returning the response information by the gptp protocol stack, and the time of receiving the response information. After obtaining the time difference, the TS client can correct the time obtained by calling the function GetCurrentTime() according to the time difference to obtain a more accurate current time of gptp.
[0058] The AP-based time synchronization method provided in this embodiment removes the TS server during the communication between the TS client and the gptp protocol stack, and communicates through a socket-based interface function library to meet the concealment requirements of the AP; and can determine the time difference through the timestamp of data transmission between the TS client and the gptp protocol stack, so that the TS client can correct the time obtained by calling the function of obtaining the current time of the system according to the time difference. In this way, this embodiment is conducive to simplifying the communication process between the TS client and the gptp protocol stack and reducing time delays. Combined with the correction through the time difference, the time obtained by the TS end can be made more accurate, reducing or even avoiding program running errors caused by clock asynchrony, which is conducive to ensuring the stability of program running in the AP.
[0059] In some embodiments, the interface function library includes a libnet library. The libnet library is a socket-based communication library. This embodiment uses the libnet library for communication. According to the requirements of the open source license, the core code in the TS client may not be open source.
[0060] Among them, the TS client and the gptp protocol stack are both configured with the function of calling the communication interface provided by the libnet library, so that the TS client and the gptp protocol stack can call the communication interface provided by the libnet library to send and receive communication data.
[0061] In other embodiments, the interface function library may also be other communication libraries with similar functions to meet the concealment requirements of the AP.
[0062] In some embodiments, this embodiment can also enable the TS client and the gptp protocol stack to achieve high-concurrency asynchronous communication through the libnet library.
[0063] In some examples, step S101, sending a time acquisition request to the gptp protocol stack includes: sending a time acquisition request to the gptp protocol stack through a first thread. Step S102, receiving response information includes: receiving response information through a second thread. In this way, sending a time acquisition request and receiving a response information do not need to be synchronously waited for processing by the same thread, thereby improving the application work efficiency of the TS client.
[0064] In some embodiments, step S103, determining the time difference based on the time of sending the time acquisition request, the time of receiving the time acquisition request by the gptp protocol stack, the time of returning the response information by the gptp protocol stack, and the time of receiving the response information, may include:
[0065] The time difference is determined based on the following formula:
[0066] offset=(t1-t3-t2+t4) / 2(Formula 1);
[0067] Among them, offset represents the time difference; t1 represents the time when the TS client sends the time acquisition request; t2 represents the time when the gptp protocol stack receives the time acquisition request; t3 represents the time when the gptp protocol stack returns the response information; t4 represents the time when the TS client receives the response information.
[0068] T2 can be specifically the ptp device hardware time and the time deviation between it and the gptp protocol stack when the gptp protocol stack receives the time acquisition request. T3 can be specifically the ptp hardware device time and the time deviation between it and the gptp protocol stack when the gptp protocol stack returns the response information. The ptp device hardware time is the system time.
[0069] Specifically, taking the transmission time of communication data from the TS client to the gptp protocol stack as delay as an example, we can get:
[0070] t1+delay=t2+offset (Formula 2);
[0071] t3+delay=t4−offset (Formula 3).
[0072] By processing the above equations 2 and 3, we can get:
[0073] delay=(t2+t4-t1-t3) / 2(Formula 4);
[0074] offset=(t1-t3-t2+t4) / 2 (Formula 1).
[0075] In some embodiments, the time obtained by calling the function for obtaining the current time of the system is corrected according to the time difference, including:
[0076] The sum of the time obtained by calling the function to obtain the current system time and the time difference is used as the time of the gptp protocol stack. The time of the gptp protocol stack may refer to the current system time obtained by obtaining the current system time function and corrected.
[0077] Specifically, the TS client calls the function GetCurrentTime() to obtain the current system time, and uses the sum of the current system time and offset as the time of the gptp protocol stack that the TS client wants to obtain.
[0078] The method provided in this embodiment optimizes the calculation scheme of the time difference between the TS client and the gptp protocol stack by removing the TS_server end, using the libnet library, using the pipline high concurrency and supporting asynchronous communication, reducing the time delay, making the time obtained by the TS client more accurate, and reducing application operation errors caused by clock asynchrony.
[0079] Please refer to Figure 2 This embodiment also provides an AP-based time synchronization method, which is applied to the gptp protocol stack and includes the following steps S201 to S202:
[0080] Step S201, receiving a time acquisition request sent by the TS client through the socket interface function library;
[0081] Step S202, generate response information based on the time acquisition request, and return the response information to the TS client through the interface function library, so that the TS client can obtain the time when the gptp protocol stack receives the time acquisition request and the time when the gptp protocol stack returns the response information based on the response information, so that the TS client can determine the time difference based on the time of sending the time acquisition request, the time when the gptp protocol stack receives the time acquisition request, the time when the gptp protocol stack returns the response information, and the time when the response information is received, so that the TS client can correct the time obtained by calling the function to obtain the current time of the system according to the time difference.
[0082] The implementation process of step 201 and step S02 may refer to the relevant description of the implementation process of the aforementioned TS client step S101 to step S103, which will not be repeated here.
[0083] In some examples, the gptp protocol stack needs to provide time synchronization for multiple application processes on multiple vehicle ECUs. In order to improve the response efficiency of the gptp protocol stack and reduce time delays, the gptp protocol stack is configured with a pipline high concurrency mode.
[0084] Specifically, the method of this embodiment further includes the following steps a1 and a2:
[0085] Step a1, the gptp protocol stack receives multiple time acquisition requests respectively through multiple third threads;
[0086] Step a2: The gptp protocol stack returns multiple response messages respectively through multiple fourth threads.
[0087] In step a1, in some examples, the gptp protocol stack can create a third thread for each TS client communicating with it, that is, each application of each vehicle ECU. The gptp protocol stack receives the time acquisition request of each application of each vehicle ECU through each third thread.
[0088] In other examples, the gptp protocol stack may also create a third thread for each vehicle ECU communicating with it. The gptp protocol stack receives the time acquisition request of each vehicle ECU through each third thread. Among them, multiple applications on the same vehicle ECU may correspond to the same third thread.
[0089] In other examples, the gptp protocol stack can also create a third thread for each application communicating with it. The gptp protocol stack receives the time acquisition request of each application through each third thread. Among them, the same application on different vehicle ECUs can correspond to the same third thread, and multiple applications on the same vehicle ECU can correspond to different third threads.
[0090] In other examples, a third thread may be created for the TS client based on a load balancing or random mechanism.
[0091] After receiving the time acquisition request, the third process may continue to process the time acquisition request to obtain the time requested by the TS client. Alternatively, the gptp protocol stack may create a new process to process the time acquisition request to obtain the time requested by the TS client.
[0092] In step a2, in some examples, the gptp protocol stack can create a fourth thread for each TS client communicating with it, that is, each application of each vehicle ECU. The gptp protocol stack returns response information through each fourth thread.
[0093] In other examples, the gptp protocol stack may also create a fourth thread for each vehicle ECU communicating with it. The gptp protocol stack returns response information through each fourth thread. Among them, multiple applications on the same vehicle ECU may correspond to the same fourth thread.
[0094] In other examples, the gptp protocol stack can also create a fourth thread for each application communicating with it. The gptp protocol stack returns response information through each fourth thread. Among them, the same application on different vehicle ECUs can correspond to the same fourth thread, and multiple applications on the same vehicle ECU can correspond to different fourth threads.
[0095] In other examples, a fourth thread may be created for the TS client based on a load balancing or random mechanism.
[0096] Please refer to Figure 3 The following is an example of the interaction process between the TS client and the gptp protocol stack in this embodiment, which specifically includes the following steps:
[0097] S301, the TS client sends a time acquisition request to the gptp protocol stack; optionally, the TS client sends a time acquisition request to the gptp protocol stack through a first thread;
[0098] S302, the gptp protocol stack receives a time acquisition request sent by the TS client through the socket interface function library; optionally, the gptp protocol stack receives multiple time acquisition requests respectively through multiple third threads;
[0099] S303, the gptp protocol stack generates response information based on the time acquisition request, and returns the response information to the TS client through the interface function library; optionally, the gptp protocol stack returns multiple response information respectively through multiple fourth threads;
[0100] S304, the TS client receives the response information, and obtains the time when the gptp protocol stack receives the time acquisition request and the time when the gptp protocol stack returns the response information; wherein the response information is generated by the gptp protocol stack based on the time acquisition request and returned through the interface function library; optionally, the TS client receives the response information through the second thread;
[0101] S305. The TS client determines the time difference based on the time of sending the time acquisition request, the time of receiving the time acquisition request by the gptp protocol stack, the time of returning the response information by the gptp protocol stack, and the time of receiving the response information, so as to correct the time obtained by calling the function of obtaining the current time of the system according to the time difference.
[0102] The AP-based time synchronization method provided in this embodiment optimizes the calculation scheme of the time difference between the TS client and the gptp protocol stack by removing the TS client, using the libnet library, using the pipline high concurrency and supporting asynchronous communication, reducing time delay, making the time obtained by the TS client more accurate, and reducing application operation errors caused by clock asynchrony. Moreover, the gptp protocol stack can respond quickly in the case of high concurrent requests, which can further reduce time delay.
[0103] In order to better implement the AP-based time synchronization method applied to the TS client of the embodiment of the present application, the embodiment of the present application also provides an AP-based time synchronization device applied to the TS client. Figure 4 For a schematic diagram of the structure of an AP-based time synchronization device applied to a TS client provided in an embodiment of the present application, please refer to Figure 4The AP-based time synchronization device includes the following units:
[0104] The first sending unit 401 is used to send a time acquisition request to the gptp protocol stack based on the socket interface function library;
[0105] The first receiving unit 402 is used to receive the response information, and obtain the time when the gptp protocol stack receives the time acquisition request and the time when the gptp protocol stack returns the response information; wherein the response information is generated by the gptp protocol stack based on the time acquisition request and returned through the interface function library;
[0106] The determination unit 403 is used to determine the time difference based on the time of sending the time acquisition request, the time of receiving the time acquisition request by the gptp protocol stack, the time of returning the response information by the gptp protocol stack, and the time of receiving the response information, so as to correct the time obtained by calling the function of obtaining the current time of the system according to the time difference.
[0107] In some embodiments, the interface function library includes a libnet library.
[0108] In some embodiments, the first sending unit is specifically used to: send a time acquisition request to the gptp protocol stack through the first thread;
[0109] The first receiving unit is specifically configured to receive response information through the second thread.
[0110] In some embodiments, the determining unit is specifically configured to:
[0111] The TS client determines the time difference based on the following formula:
[0112] offset = (t1 - t3 - t2 + t4) / 2;
[0113] Among them, offset represents the time difference; t1 represents the time when the TS client sends the time acquisition request; t2 represents the time when the gptp protocol stack receives the time acquisition request; t3 represents the time when the gptp protocol stack returns the response information; t4 represents the time when the response information is received.
[0114] In some embodiments, the determination unit is specifically used for: the TS client uses the sum of the time obtained by calling the function of obtaining the current time of the system and the time difference as the time of the gptp protocol stack.
[0115] In order to facilitate better implementation of the AP-based time synchronization method applied to the gptp protocol stack of the embodiment of the present application, the embodiment of the present application also provides an AP-based time synchronization device applied to the gptp protocol stack. Figure 5For a structural diagram of an AP-based time synchronization device applied to a gptp protocol stack provided in an embodiment of the present application, please refer to Figure 5 The AP-based time synchronization device includes the following units:
[0116] The second receiving unit 501 is used to receive a time acquisition request sent by the TS client through the socket interface function library;
[0117] The second sending unit 502 is used to generate response information based on the time acquisition request, and return the response information to the TS client through the interface function library, so that the TS client can obtain the time when the gptp protocol stack receives the time acquisition request and the time when the gptp protocol stack returns the response information based on the response information, so that the TS client can determine the time difference based on the time of sending the time acquisition request, the time when the gptp protocol stack receives the time acquisition request, the time when the gptp protocol stack returns the response information, and the time of receiving the response information, so that the TS client can correct the time obtained by calling the function of obtaining the current time of the system according to the time difference.
[0118] In some embodiments, the first receiving unit is specifically used to: respectively receive multiple time acquisition requests through multiple third threads;
[0119] The second sending unit is specifically used to return multiple response information respectively through multiple fourth threads.
[0120] In the embodiment of the AP-based time synchronization device of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories), or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit. The above-mentioned "modules" or "units" can be embedded in or independent of the processor in the electronic device in the form of hardware, or can be stored in the memory in the electronic device in the form of software, so that the processor can call and execute the operations corresponding to the above-mentioned units.
[0121] The AP-based time synchronization device in the above embodiment may be integrated in a terminal or server that has a storage device and a processor installed therein and has computing capability, or the AP-based time synchronization device in the above embodiment is the terminal or server.
[0122] The present application also provides an electronic device, including a memory and a processor, wherein the memory is used to store executable instructions of the processor, and the processor is configured to perform the steps in the above-mentioned method embodiments by executing the executable instructions.
[0123] The processor may include one or more processing cores. The memory may include one or more computer-readable storage media. The memory stores a computer program, which can be run on the processor. The processor is electrically connected to the memory. In addition, the electronic device may also include an input function or input state to facilitate human-computer interaction.
[0124] Those skilled in the art will appreciate that the computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown in the figure, or a combination of certain components, or a different arrangement of components.
[0125] The processor of the embodiment of the present application may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method embodiment can be completed by the hardware integrated logic circuit or software instructions in the processor. The above processor can be a general processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding processor to perform, or the hardware and software modules in the decoding processor are combined and performed. The software module can be located in a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, and other mature storage media in the art. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.
[0126] The memory in the embodiments of the present application may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct memory bus random access memory (DR RAM). It should be noted that the memory of the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0127] The above-mentioned memory is exemplary but not restrictive. For example, the memory in the embodiment of the present application may also be static random access memory (static RAM, SRAM), dynamic random access memory (dynamic RAM, DRAM), synchronous dynamic random access memory (synchronous DRAM, SDRAM), double data rate synchronous dynamic random access memory (double data rate SDRAM, DDR SDRAM), enhanced synchronous dynamic random access memory (enhanced SDRAM, ESDRAM), synchronous link dynamic random access memory (synch link DRAM, SLDRAM) and direct memory bus random access memory (Direct Rambus RAM, DR RAM), etc. That is to say, the memory in the embodiment of the present application is intended to include but not limited to these and any other suitable types of memory.
[0128] The electronic device may also include a power module, a wireless fidelity module, a Bluetooth module, etc., which will not be described in detail here.
[0129] In some embodiments, the present application further provides a computer-readable storage medium, which stores a computer program. The computer-readable storage medium can be applied to an electronic device, and the computer program enables the electronic device to execute the corresponding process in the method in the embodiment of the present application, which will not be described here for the sake of brevity.
[0130] In some embodiments, the present application further provides a computer program product, which includes a computer program stored in a computer-readable storage medium. The processor of the electronic device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the electronic device executes the corresponding process in the method in the embodiment of the present application, which will not be described here for the sake of brevity.
[0131] In some embodiments, the present application further provides a computer program, which includes a computer program, and the computer program is stored in a computer-readable storage medium. The processor of the electronic device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the electronic device executes the corresponding process in the method in the embodiment of the present application, which will not be repeated here for the sake of brevity.
[0132] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0133] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0134] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0135] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0136] In addition, each functional unit in the embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0137] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions for an electronic device (which can be a personal computer, a server) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a ROM, a RAM, a magnetic disk or an optical disk.
[0138] It should be noted that the logic and / or steps represented in the flowchart or described in other ways herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, device or equipment (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or equipment and execute instructions), or used in combination with these instruction execution systems, devices or equipment.
[0139] For the purposes of this specification, a "computer readable medium" may be any device that can contain, store, communicate, propagate or transport a program for use with or in conjunction with an instruction execution system, apparatus or device. More specific examples (a non-exhaustive list) of computer readable media include the following: an electrical connection with one or more wires (electronic device), a portable computer disk case (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disk read-only memory (CDROM).
[0140] In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or processing in other suitable ways if necessary, and then stored in a computer memory.
[0141] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in this field can change, modify, replace and modify the above embodiments within the scope of the present application.
Claims
1. A time synchronization method based on AP, applied to TS client, It is characterized in that include: The socket-based interface function library sends a time acquisition request to the gptp protocol stack; Receive response information, and obtain the time when the gptp protocol stack receives the time acquisition request and the time when the gptp protocol stack returns the response information; wherein the response information is generated by the gptp protocol stack based on the time acquisition request and returned through the interface function library; The time difference is determined based on the time of sending the time acquisition request, the time of receiving the time acquisition request by the gptp protocol stack, the time of returning the response information by the gptp protocol stack, and the time of receiving the response information, so that the time obtained by calling the function of acquiring the current time of the system can be corrected according to the time difference.
2. The AP-based time synchronization method according to claim 1, It is characterized in that The interface function library includes a libnet library.
3. The AP-based time synchronization method according to any one of claims 1 or 2, It is characterized in that The sending of a time acquisition request to the gptp protocol stack includes: Send a time acquisition request to the gptp protocol stack through the first thread; The receiving response information includes: The response information is received through the second thread.
4. The AP-based time synchronization method according to claim 1, It is characterized in that The determining the time difference based on the time of sending the time acquisition request, the time of receiving the time acquisition request by the gptp protocol stack, the time of returning the response information by the gptp protocol stack, and the time of receiving the response information includes: The TS client determines the time difference based on the following formula: offset = (t1 - t3 - t2 + t4) / 2; Among them, offset represents the time difference; t1 represents the time when the TS client sends the time acquisition request; t2 represents the time when the gptp protocol stack receives the time acquisition request; t3 represents the time when the gptp protocol stack returns the response information; t4 represents the time when the TS client receives the response information.
5. The AP-based time synchronization method according to claim 1, It is characterized in that The step of correcting the time obtained by calling a function to obtain the current time of the system according to the time difference includes: The time obtained by calling the function to obtain the current time of the system and the sum of the time difference are used as the time of the gptp protocol stack.
6. A time synchronization method based on AP, applied to gptp protocol stack, It is characterized in that include: Receive the time acquisition request sent by the TS client through the socket interface function library; Generate response information based on the time acquisition request, and return the response information to the TS client through the interface function library, so that the TS client can obtain the time when the gptp protocol stack receives the time acquisition request and the time when the gptp protocol stack returns the response information based on the response information, so that the TS client can determine the time difference based on the time when the time acquisition request is sent, the time when the gptp protocol stack receives the time acquisition request, the time when the gptp protocol stack returns the response information, and the time when the response information is received, so that the TS client can correct the time obtained by calling the function to obtain the current time of the system according to the time difference.
7. The AP-based time synchronization method according to claim 6, It is characterized in that Also includes: Receiving a plurality of the time acquisition requests respectively through a plurality of third threads; The plurality of response messages are returned respectively through the plurality of fourth threads.
8. A time synchronization device based on AP, applied to TS client, It is characterized in that include: A first sending unit, configured to send a time acquisition request to a gptp protocol stack based on a socket interface function library; A first receiving unit is used to receive response information, and obtain the time when the gptp protocol stack receives the time acquisition request and the time when the gptp protocol stack returns the response information; wherein the response information is generated by the gptp protocol stack based on the time acquisition request and returned through the interface function library; A determination unit is used to determine a time difference based on the time of sending the time acquisition request, the time of receiving the time acquisition request by the gptp protocol stack, the time of returning the response information by the gptp protocol stack, and the time of receiving the response information, so as to correct the time obtained by calling the function of acquiring the current time of the system according to the time difference.
9. A time synchronization device based on AP, applied to gptp protocol stack, It is characterized in that include: The second receiving unit is used to receive a time acquisition request sent by the TS client through the socket interface function library; The second sending unit is used to generate response information based on the time acquisition request, and return the response information to the TS client through the interface function library, so that the TS client can obtain the time when the gptp protocol stack receives the time acquisition request and the time when the gptp protocol stack returns the response information based on the response information, so that the TS client can determine the time difference based on the time of sending the time acquisition request, the time when the gptp protocol stack receives the time acquisition request, the time when the gptp protocol stack returns the response information, and the time of receiving the response information, so that the TS client can correct the time obtained by calling the function of obtaining the current time of the system according to the time difference.
10. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
