测试使用:关于这个socket.ntptm()功能的时间准确度测试
使用air780EG同时从gps和stnp获取(脉冲信号给gpio22上)
代码:
sys.taskInit(function()
sys.waitUntil("IP_READY")
socket.sntp()
end)
sys.subscribe("NTP_ERROR", function()
log.info("socket", "sntp error")
socket.sntp()
end)
sntp_num = 0
sys.subscribe("NTP_UPDATE", function()
log.info("sntp", "NTP_UPDATE")
sntp_num = sntp_num + 1
if sntp_num <= 3 then
sys.taskInit(function() socket.sntp() end)
else
sntp_num=3
end
end)
GPS_stamp_time=0
GPS_stamp_time_ms=0
sys.subscribe("GNSS_STATE", function(event, ticks)
log.info("gnss", "state1:", event, ticks)
if event == "FIXED" then
if GPS_time == 0 then
GPS_time = 1
local Rmc = libgnss.getRmc(2)
GPS_stamp_time = os.time({
year = Rmc["year"],
mon = Rmc["month"],
day = Rmc["day"],
hour = Rmc["hour"],
min = Rmc["min"],
sec = Rmc["sec"]
})
end
end
end)
function gps_ms_task()
GPS_stamp_time_ms = GPS_stamp_time_ms + 1
if GPS_stamp_time_ms > 1001 then
GPS_stamp_time_ms = GPS_stamp_time_ms - 1000
GPS_stamp_time = GPS_stamp_time + 1
GPS_time = 0;
log.info("GPS_ms_task",GPS_stamp_time_ms)
end
end
gps_ms_id =nil
gps_ms_id=sys.timerLoopStart(gps_ms_task,1)
hist_tick=0
hist_tick_str=bit64.to64(0)
timecha=0
sys.timerStart(function()
timecha=0
end,60000)
gpio.setup(22, function()
local tick_str, tick_per = mcu.tick64(true)
local tmp_str=bit64.minus(bit64.minus(tick_str,hist_tick_str),26000000)
hist_tick_str=tick_str
timecha=timecha+bit64.to32(tmp_str)
if GPS_stamp_time_ms~=1000 then
local tm = socket.ntptm()
log.info("GPIO22",tm["tms"], GPS_stamp_time_ms)
end
GPS_stamp_time_ms = 0
GPS_stamp_time=GPS_stamp_time + 1
end, gpio.PULLUP,gpio.RISING)
timenum=0
sys.timerLoopStart(function()
local tm = socket.ntptm()
log.info("time1",os.date("!%Y-%m-%d %H:%M:%S", tm["tsec"]),tm["tms"])
log.info("time2",os.date("!%Y-%m-%d %H:%M:%S", GPS_stamp_time),GPS_stamp_time_ms)
log.info("tick64cha",timecha)
sys.taskInit(function()
timenum=timenum+200
if timenum > 2000 then
timenum=0
end
sys.wait(timenum)
socket.sntp()
end)
sntp_num=1
end,10000)
socket.ntptm()时间波动在0-500ms
socket.ntptm()时间波动在0-500ms
[2024-02-19 00:40:22.175][000000010.489] I/user.time1 2024-02-18 16:40:21 822
[2024-02-19 00:40:22.180][000000010.491] I/user.time2 33-00-00 00:00:10 173
[2024-02-19 00:40:22.181][000000010.492] I/user.tick64cha 8141537
[2024-02-19 00:40:32.180][000000020.488] I/user.time1 2024-02-18 16:40:32 150
[2024-02-19 00:40:32.185][000000020.491] I/user.time2 33-00-00 00:00:20 173
[2024-02-19 00:40:32.188][000000020.492] I/user.tick64cha 8141427
[2024-02-19 00:40:42.185][000000030.489] I/user.time1 2024-02-18 16:40:42 154
[2024-02-19 00:40:42.190][000000030.491] I/user.time2 33-00-00 00:00:30 174
[2024-02-19 00:40:42.192][000000030.492] I/user.tick64cha 8132095
[2024-02-19 00:40:52.179][000000040.488] I/user.time1 2024-02-18 16:40:51 819
[2024-02-19 00:40:52.185][000000040.491] I/user.time2 2024-02-18 16:40:52 174
[2024-02-19 00:40:52.188][000000040.492] I/user.tick64cha 8131841
[2024-02-19 00:41:02.178][000000050.488] I/user.time1 2024-02-18 16:41:01 819
[2024-02-19 00:41:02.184][000000050.491] I/user.time2 2024-02-18 16:41:02 174
[2024-02-19 00:41:02.187][000000050.492] I/user.tick64cha 8131771
[2024-02-19 00:41:12.182][000000060.488] I/user.time1 2024-02-18 16:41:11 821
[2024-02-19 00:41:12.191][000000060.491] I/user.time2 2024-02-18 16:41:12 174
[2024-02-19 00:41:12.198][000000060.492] I/user.tick64cha 0
[2024-02-19 00:41:22.178][000000070.488] I/user.time1 2024-02-18 16:41:22 151
[2024-02-19 00:41:22.186][000000070.491] I/user.time2 2024-02-18 16:41:22 174
[2024-02-19 00:41:22.188][000000070.492] I/user.tick64cha -711
[2024-02-19 00:41:32.177][000000080.489] I/user.time1 2024-02-18 16:41:31 822
[2024-02-19 00:41:32.184][000000080.491] I/user.time2 2024-02-18 16:41:32 174
[2024-02-19 00:41:32.186][000000080.492] I/user.tick64cha -1234
[2024-02-19 00:41:42.178][000000090.488] I/user.time1 2024-02-18 16:41:41 821
[2024-02-19 00:41:42.187][000000090.491] I/user.time2 2024-02-18 16:41:42 174
[2024-02-19 00:41:42.189][000000090.492] I/user.tick64cha -1388
[2024-02-19 00:41:52.177][000000100.488] I/user.time1 2024-02-18 16:41:51 824
[2024-02-19 00:41:52.186][000000100.491] I/user.time2 2024-02-18 16:41:52 174
[2024-02-19 00:41:52.202][000000100.492] I/user.tick64cha -1362
[2024-02-19 00:42:02.186][000000110.488] I/user.time1 2024-02-18 16:42:01 818
[2024-02-19 00:42:02.192][000000110.491] I/user.time2 2024-02-18 16:42:02 174
[2024-02-19 00:42:02.194][000000110.492] I/user.tick64cha -1845
[2024-02-19 00:42:12.186][000000120.488] I/user.time1 2024-02-18 16:42:11 825
[2024-02-19 00:42:12.193][000000120.491] I/user.time2 2024-02-18 16:42:12 174
[2024-02-19 00:42:12.196][000000120.492] I/user.tick64cha -2171
[2024-02-19 00:42:22.180][000000130.488] I/user.time1 2024-02-18 16:42:22 156
[2024-02-19 00:42:22.187][000000130.491] I/user.time2 2024-02-18 16:42:22 174
[2024-02-19 00:42:22.189][000000130.492] I/user.tick64cha -2600
[2024-02-19 00:42:32.175][000000140.489] I/user.time1 2024-02-18 16:42:32 155
[2024-02-19 00:42:32.182][000000140.491] I/user.time2 2024-02-18 16:42:32 174
[2024-02-19 00:42:32.187][000000140.492] I/user.tick64cha -3356
[2024-02-19 00:42:42.185][000000150.488] I/user.time1 2024-02-18 16:42:41 823
[2024-02-19 00:42:42.193][000000150.491] I/user.time2 2024-02-18 16:42:42 174
[2024-02-19 00:42:42.196][000000150.492] I/user.tick64cha -3512
[2024-02-19 00:42:52.176][000000160.488] I/user.time1 2024-02-18 16:42:51 824
[2024-02-19 00:42:52.187][000000160.491] I/user.time2 2024-02-18 16:42:52 174
[2024-02-19 00:42:52.190][000000160.492] I/user.tick64cha -3830
2024-02-19 00:43:02.181][000000170.489] I/user.time1 2024-02-18 16:43:01 821
[2024-02-19 00:43:02.190][000000170.491] I/user.time2 2024-02-18 16:43:02 174
[2024-02-19 00:43:02.192][000000170.492] I/user.tick64cha -4202
1109
没看懂, 是有问题还是没问题... 最新代码编译的固件吗?
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
没有问题就是对这个的socket.ntptm()获取时间准确性测试,另外在想看看能不能进行优化
I/user.time1 2024-02-18 16:42:41 823(sntp的时间)
I/user.time2 2024-02-18 16:42:42 174(GPS计算给出的时间)
多次测试后的误差结论500ms以内
经过一天后长时间的时间稳定性错个10ms内但是晶振能多退少补一直跑的稳定
就相当于给socket.ntptm()做了一个测试如果有人对这个有问题可以看这个
1小时应该也可以
这个就是为了每次都是更新时间戳和gps的准确时间对比
登录 后才可以发表评论