Time correction method and device for network system in local area network

文档序号:1492508 发布日期:2020-02-04 浏览:6次 中文

阅读说明:本技术 一种局域网内网络系统的校时方法及装置 (Time correction method and device for network system in local area network ) 是由 郑林 于 2018-07-24 设计创作,主要内容包括:本发明公开了一种局域网内网络系统的校时方法及装置,所述网络系统包括带有时钟电路的主设备,以及连接到该主设备的终端设备,本发明局域网内网络系统的校时方法,首先由监测主设备时钟电路电池电量,当电池电量小于设定的阈值时,周期性将当前时间写入到配置文件中;然后在主设备重启时,比较主设备当前时间与配置文件中记录的时间,当主设备当前时间大于配置文件记录的时间时,认为主设备时间正常,否则认为主设备时间异常,选择接入主设备的终端设备的当前时间作为系统时间。本发明的方法及装置整个时间校正过程中不需要额外连接公网,不需要额外的部署时间服务器,不需要人工干预,极大的减少了维护成本。(The invention discloses a time correction method and a device of a network system in a local area network, wherein the network system comprises a main device with a clock circuit and a terminal device connected to the main device; and then when the main equipment is restarted, comparing the current time of the main equipment with the time recorded in the configuration file, when the current time of the main equipment is greater than the time recorded in the configuration file, considering that the time of the main equipment is normal, or else, considering that the time of the main equipment is abnormal, and selecting the current time of the terminal equipment accessing the main equipment as the system time. The method and the device do not need to be additionally connected with a public network, an additional time server and manual intervention in the whole time correction process, and greatly reduce the maintenance cost.)

1. A timing method of a network system in a local area network, the network system including a master device having a clock circuit and a terminal device connected to the master device, the timing method of the network system in the local area network comprising:

monitoring the battery electric quantity of a clock circuit of the master equipment, and periodically writing the current time into a configuration file when the battery electric quantity is smaller than a set threshold value;

when the main equipment is restarted, comparing the current time of the main equipment with the time recorded in the configuration file, when the current time of the main equipment is greater than the time recorded in the configuration file, considering that the time of the main equipment is normal, or else, considering that the time of the main equipment is abnormal, and selecting the current time of the terminal equipment accessing the main equipment as the system time.

2. The method according to claim 1, wherein selecting the current time of the terminal device accessing the master device as the system time comprises:

and randomly selecting the current time of one terminal device as the system time.

3. The method according to claim 1, wherein selecting the current time of the terminal device accessing the master device as the system time comprises:

and acquiring the current time of the terminal equipment one by one, comparing the current time of the terminal equipment with the time recorded in the configuration file, and selecting the current time of the terminal equipment as the system time when the previous time of the terminal equipment is greater than the time recorded in the configuration file.

4. The method according to claim 1, wherein selecting the current time of the terminal device accessing the master device as the system time comprises:

and acquiring the current time of all the terminal devices, comparing the current time of the terminal devices with the time recorded in the configuration file one by one, and selecting the current time of the terminal device with the largest time difference value between the current time and the time recorded in the configuration file as the system time from the terminal devices of which the current time is greater than the time recorded in the configuration file.

5. The method according to claim 1, further comprising:

when the time of the main equipment is abnormal and the current time of all the terminal equipment accessed to the main equipment is less than or equal to the time recorded by the configuration file, sending an alarm;

and replacing the terminal equipment with accurate current time, and taking the current time of the terminal equipment as the system time.

6. A timing apparatus of a network system in a local area network, the network system including a master device having a clock circuit and a terminal device connected to the master device, the timing apparatus of the network system in the local area network comprising:

the monitoring module is used for monitoring the battery electric quantity of the clock circuit of the master device, and periodically writing the current time into the configuration file when the battery electric quantity is smaller than a set threshold value;

and the time correcting module is used for comparing the current time of the main equipment with the time recorded in the configuration file when the main equipment is restarted, considering that the time of the main equipment is normal when the current time of the main equipment is greater than the time recorded in the configuration file, and selecting the current time of the terminal equipment accessing the main equipment as the system time when the time of the main equipment is abnormal otherwise.

7. The apparatus of claim 6, wherein the timing module selects a current time of the terminal device accessing the host device as a system time, and performs the following operations:

and randomly selecting the current time of one terminal device as the system time.

8. The apparatus of claim 6, wherein the timing module selects a current time of the terminal device accessing the host device as a system time, and performs the following operations:

and acquiring the current time of the terminal equipment one by one, comparing the current time of the terminal equipment with the time recorded in the configuration file, and selecting the current time of the terminal equipment as the system time when the previous time of the terminal equipment is greater than the time recorded in the configuration file.

9. The apparatus of claim 6, wherein the timing module selects a current time of the terminal device accessing the host device as a system time, and performs the following operations:

and acquiring the current time of all the terminal devices, comparing the current time of the terminal devices with the time recorded in the configuration file one by one, and selecting the current time of the terminal device with the largest time difference value between the current time and the time recorded in the configuration file as the system time from the terminal devices of which the current time is greater than the time recorded in the configuration file.

10. The apparatus for timing a network system in a lan according to claim 6, further comprising:

the alarm module is used for sending an alarm when the time of the main equipment is abnormal and the current time of all the terminal equipment accessed to the main equipment is less than or equal to the time recorded by the configuration file;

the time correcting module selects the current time of the terminal equipment accessed to the main equipment as the system time, and executes the following operations:

and adopting the current time of a newly replaced terminal device as the system time, wherein the current time of the newly replaced terminal device is the accurate current time.

Technical Field

The invention belongs to the technical field of real-time clock synchronization, and particularly relates to a time correction method and device for a network system in a local area network.

Background

With the rapid development of electronic science and technology, the requirements of computer systems, communication network systems, video monitoring systems and the like on system clocks are more and more strict. For example, in a video monitoring system, time accuracy is particularly important, and if the time of the equipment is disordered, the video storage, the video retrieval and playback of the equipment are disordered, and even the whole system is broken down.

When the current electronic device performs timing based on RTC (Real-Time Clock), the RTC is a Clock circuit composed of a crystal oscillator and related circuits. At present, the RTC is generally powered by a battery, the current battery power supply energy efficiency is basically only about two years, and after the RTC battery is invalid, the system is disordered under the condition that the RTC battery cannot be calibrated in other modes.

At present, a mature technical scheme is that timing is performed based on an NTP timing server or a cloud server on a network, and equipment acquires accurate time from a time server on the network at regular time and then synchronizes to local equipment. When the network is based on the NTP timing server or the cloud server, the device is required to be on a public network to be capable of communicating with a remote server.

However, in practice, in the field of video monitoring, on one hand, for privacy, most of the video is not connected to a public network and is generally located in a local area network; in addition, in many places, although there is a video monitoring requirement, the video monitoring system does not have the condition of being externally connected to a public network, so that the video monitoring system can only be built in a local area network. The video monitoring system in the local area network cannot perform timing based on the NTP timing server or the cloud server on the network, and often uses the RTC of the network monitoring host to perform timing. If the RTC battery is invalid and is not connected with the external network, the time of the network monitoring host can be recovered to the default time (such as 1970/01/0100:00:00) after power failure and restart, and further the whole video recording device has disordered video recording and the whole video monitoring system is paralyzed.

Disclosure of Invention

The invention aims to provide a time correction method and a time correction device for a network system in a local area network, which are used for solving the problem of system paralysis caused by the fact that a RTC battery can not be used for correcting time with a public network under the condition that the RTC battery is possibly invalid.

In order to achieve the purpose, the technical scheme of the invention is as follows:

a time calibration method of a network system in a local area network, wherein the network system comprises a main device with a clock circuit and a terminal device connected to the main device, the time calibration method of the network system in the local area network comprises the following steps:

monitoring the battery electric quantity of a clock circuit of the master equipment, and periodically writing the current time into a configuration file when the battery electric quantity is smaller than a set threshold value;

when the main equipment is restarted, comparing the current time of the main equipment with the time recorded in the configuration file, when the current time of the main equipment is greater than the time recorded in the configuration file, considering that the time of the main equipment is normal, or else, considering that the time of the main equipment is abnormal, and selecting the current time of the terminal equipment accessing the main equipment as the system time.

Further, the selecting a current time of the terminal device accessing the master device as a system time includes:

and randomly selecting the current time of one terminal device as the system time.

Or, the selecting the current time of the terminal device accessing the master device as the system time includes:

and acquiring the current time of the terminal equipment one by one, comparing the current time of the terminal equipment with the time recorded in the configuration file, and selecting the current time of the terminal equipment as the system time when the previous time of the terminal equipment is greater than the time recorded in the configuration file.

Or, the selecting the current time of the terminal device accessing the master device as the system time includes:

and acquiring the current time of all the terminal devices, comparing the current time of the terminal devices with the time recorded in the configuration file one by one, and selecting the current time of the terminal device with the largest time difference value between the current time and the time recorded in the configuration file as the system time from the terminal devices of which the current time is greater than the time recorded in the configuration file.

Further, the timing method of the network system in the local area network further includes:

when the time of the main equipment is abnormal and the current time of all the terminal equipment accessed to the main equipment is less than or equal to the time recorded by the configuration file, sending an alarm;

and replacing the terminal equipment with accurate current time, and taking the current time of the terminal equipment as the system time.

The invention also provides a timing device of a network system in the local area network, wherein the network system comprises a main device with a clock circuit and a terminal device connected to the main device, and the timing device of the network system in the local area network comprises:

the monitoring module is used for monitoring the battery electric quantity of the clock circuit of the master device, and periodically writing the current time into the configuration file when the battery electric quantity is smaller than a set threshold value;

and the time correcting module is used for comparing the current time of the main equipment with the time recorded in the configuration file when the main equipment is restarted, considering that the time of the main equipment is normal when the current time of the main equipment is greater than the time recorded in the configuration file, and selecting the current time of the terminal equipment accessing the main equipment as the system time when the time of the main equipment is abnormal otherwise.

Further, the timing module selects the current time of the terminal device accessing the master device as the system time, and executes the following operations:

and randomly selecting the current time of one terminal device as the system time.

Or, the timing module selects the current time of the terminal device accessing the main device as the system time, and executes the following operations:

and acquiring the current time of the terminal equipment one by one, comparing the current time of the terminal equipment with the time recorded in the configuration file, and selecting the current time of the terminal equipment as the system time when the previous time of the terminal equipment is greater than the time recorded in the configuration file.

Or, the timing module selects the current time of the terminal device accessing the main device as the system time, and executes the following operations:

and acquiring the current time of all the terminal devices, comparing the current time of the terminal devices with the time recorded in the configuration file one by one, and selecting the current time of the terminal device with the largest time difference value between the current time and the time recorded in the configuration file as the system time from the terminal devices of which the current time is greater than the time recorded in the configuration file.

Further, the timing device of the network system in the local area network further includes:

the alarm module is used for sending an alarm when the time of the main equipment is abnormal and the current time of all the terminal equipment accessed to the main equipment is less than or equal to the time recorded by the configuration file;

the time correcting module selects the current time of the terminal equipment accessed to the main equipment as the system time, and executes the following operations:

and adopting the current time of a newly replaced terminal device as the system time, wherein the current time of the newly replaced terminal device is the accurate current time.

The timing method and the timing device for the network system in the local area network can solve the problems of disordered monitoring video recording time and incapability of using the system due to failure of an RTC battery of monitoring networking equipment under the local area network to a great extent; in the whole time correction process, no additional public network connection, no additional time server deployment and no manual intervention are needed, so that the maintenance cost is greatly reduced; in extreme cases the loss of rapid recovery is minimal in the event of a total system failure. When the time of the whole system is abnormal, the system can be completely recovered only by replacing a terminal device with accurate time, so that the replacement of the monitoring master device (the replacement of the monitoring master device can cause all the previous stored data to be lost) can be avoided, meanwhile, the whole system is prevented from being reconfigured, and the system can be recovered at the fastest speed.

Drawings

FIG. 1 is a schematic networking diagram of a video monitoring system in a local area network;

fig. 2 is a flowchart of a timing method of a network system in a local area network according to the present invention.

Detailed Description

The technical solutions of the present invention are further described in detail below with reference to the drawings and examples, which should not be construed as limiting the present invention.

The embodiment is described by taking a video monitoring system in a local area network as an example, and is also applicable to other network systems in the local area network, such as an internet of things system. As shown in fig. 1, a video monitoring system in a local area network generally includes a network monitoring host device and each network camera IPC connected to the network monitoring host device. The network monitoring master device is generally a network video recorder NVR or a hard disk video recorder DVR. After the network monitoring master equipment is installed and started for the first time, the RTC clock circuit provides a clock, and the network monitoring master equipment synchronizes the clock to all the connected network cameras, so that the whole video monitoring system adopts the same system time. However, after the battery of the RTC is dead, the network monitoring host recovers to the default time (e.g. 1970/01/0100:00:00) after power failure and restart, which may cause the video recording of the whole video recording device to be disordered and the whole video monitoring system to be paralyzed. The technical scheme of the invention is to solve the problem.

As shown in fig. 2, the present embodiment is a timing method for a network system in a local area network, where the network system includes a master device with a clock circuit and a terminal device connected to the master device. The embodiment of the invention provides a timing method of a network system in a local area network, which is applied to a main device and comprises the following steps:

and step S1, monitoring the battery power of the clock circuit of the master device, and periodically writing the current time into a configuration file when the battery power is less than a set threshold value.

The accuracy of time is crucial to the video monitoring system, and the RTC battery of equipment often probably became invalid about 2 years, and many equipment RTC batteries and mainboard are the integration, can not change at all. In addition, because the video monitoring system in the local area network is not connected with a public network in many times, the monitoring equipment cannot carry out time correction on the network server.

In a video monitoring system, a network monitoring main device is generally a Network Video Recorder (NVR), and after the NVR is installed for the first time, the network monitoring main device sets a correct time and synchronizes the time to a connected terminal device as a system time, so that the whole system adopts the same system time. Thereafter, since the RTC circuit on the network monitoring master device operates normally, the system always operates at the correct time no matter whether the network monitoring master device is restarted.

In order to avoid the problem that the time is recovered to the default time after the power failure and the restart due to the failure of the RTC battery, and the system time is wrong, the present embodiment monitors the battery capacity of the clock circuit, and periodically writes the current time into the configuration file at regular intervals when the battery capacity is smaller than the set threshold. Wherein the set threshold may be 90% of the battery capacity, or 85% of the battery capacity. For example, when the monitored battery power is less than 90% of the battery power, the current time is written into the configuration file at intervals of 0.1 second, which is recorded as T1, the configuration file is stored on the network monitoring master device, and the time recorded by the configuration file is T1, and the time is updated at each writing.

And step S2, when the master device is restarted, comparing the current time of the master device with the time recorded in the configuration file, when the current time of the master device is greater than the time recorded in the configuration file, considering the time of the master device to be normal, otherwise, considering the time of the master device to be abnormal, and selecting the current time of the terminal device accessing the master device as the system time.

The present embodiment records time T1 in the configuration file, and when the master device restarts in an abnormal situation such as a power failure, the current time of the master device is compared with the time recorded in the configuration file. Assuming that the current time is T and the time recorded in the configuration file is T1, then:

if T > T1, namely the current time of the network monitoring master device is after the time recorded by the configuration file, it means that the RTC clock circuit works normally when the network monitoring master device restarts, and the current time of the network monitoring master device is considered to be normal without recovering to the default time. At the moment, the system works normally, and the system time does not need to be reset.

If T < ═ T1, that is, the current time of the network monitoring master device is before the time recorded in the configuration file, it indicates that the RTC clock circuit is not working normally when the network monitoring master device restarts, and may have recovered to the default time, and it is considered that the current time of the monitoring master device is abnormal, and at this time, the system time needs to be reset.

The following is a description of several embodiments of resetting system time.

10页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种光传输网络的同步方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!