293 Star 1.6K Fork 379

GVP合宙Luat / LuatOS

 / 详情

[🐛Bug]: 关于这个socket.ntptm()功能的时间准确度测试

已完成
创建于  
2024-02-19 00:56

描述一下这个bug / Describe the bug

测试使用:关于这个socket.ntptm()功能的时间准确度测试

使用air780EG同时从gps和stnp获取(脉冲信号给gpio22上)

复现步骤 / To Reproduce

代码:

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)

如果正常,应该是什么样 / Expected behavior

socket.ntptm()时间波动在0-500ms

截图 / Screenshots

socket.ntptm()时间波动在0-500ms

日志 / Logs

[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

PACK包版本 / Version

1109

验证

  • 检查过该问题,之前没有人提过 / Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • 提供了最小可复现工程或详细的复现步骤,确保开发者可以复现 / The provided reproduction is a minimal reproducible example of the bug.
  • 已经提供了完整的报错信息、日志、截图,没有经过删减。

评论 (7)

杨壮壮 创建了任务
Wendal 修改了描述
展开全部操作日志

没看懂, 是有问题还是没问题... 最新代码编译的固件吗?

没有问题就是对这个的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()做了一个测试如果有人对这个有问题可以看这个

60秒ntp一次试试?

1小时应该也可以

Wendal 添加了
 
讨论
标签
Wendal 添加了
 
新特性
标签
Wendal 负责人设置为Wendal
Wendal 优先级设置为主要
Wendal 关联分支设置为master

这个就是为了每次都是更新时间戳和gps的准确时间对比

alien2017 任务状态待办的 修改为已完成

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(2)
4674 wendal 1578914274
Lua
1
https://gitee.com/openLuat/LuatOS.git
git@gitee.com:openLuat/LuatOS.git
openLuat
LuatOS
LuatOS

搜索帮助