Microchip
直播中

张莉

8年用户 1336经验值
私信 关注
[问答]

无法获得正确的Unix时间

你好,我叫洛伦佐。这是我第一次在这里写,我是一个带照片的新手。我是一个使用PIC32 MZ2048 EFH144的项目的学生,我使用MPLAB X IDE V3.55和OrthyV1.06。我正在尝试制作SNTP,但是我面临一些问题:当我调用函数TcPIpSntppUutcSudisGET(无效)时,我希望得到UNIX时间,但我所得到的只是数字。EN 33和39(我想它们是从我开始调试的那一刻起的某种延迟)。我试图修改一些东西(代码是由另一个人用和声生成的SNTP。C),但它不起作用。我注意到TaTcCPipntpPiLeCH定义为2208988 800 UL,为01/01/2040.0,这是问题所在吗?我希望能很好地解释我的问题,谢谢你的答复。

以上来自于百度翻译


      以下为原文

    Hello, my name is Lorenzo.

It is the first time I have written here and I am a newbie with PICs. I am a student working on a project with a PIC32MZ2048EFH144 and I am using MPLAB X IDE v3.55 and HARMony v1.06.

I am trying to making work SNTP but I am facing with some problems: when I call the function TCPIP_SNTP_UTCSecondsGet(void), I would expect to get Unix time but all I get is numbers between 33 and 39 (and I suppose they are some sort of delay from the moment I started debugging).
I tried to modify something (code was sntp.c generated by another person with Harmony) but it does not work. I noticed that TCPIP_NTP_EPOCH is defined like 2208988800ul which is 01/01/2040.

Could this be the problem?

I hope to have explained my problem well , thank you in advance for your replies.

回帖(17)

李兆峰

2019-4-2 09:16:25
它就像这个/ /参考时期使用。(默认值:01-JAN-1970 1970:00)定义旧的MLA中的NTPL历元(864万UL*(365UL*70UL+17UL)…希望这有帮助!

以上来自于百度翻译


      以下为原文

    It was like this
 
// Reference Epoch to use.  (default: 01-Jan-1970 00:00:00)
#define NTP_EPOCH                 (86400ul * (365ul * 70ul + 17ul))
 
in old MLA...
hope this may help!
举报

郑雅颖

2019-4-2 09:24:35
嗯,我只是开始调侃和谐V1.09和V2.02.00。也许我根本不应该评论,但是这个论坛只是我学到的唯一实用的地方。(也许有些专家可以插嘴。)我真的很感激!总之,这里是如何运行的(我想):TCPIPPSNTPUTCUSESGET()调用SysTyTMR.TICKCONGTGET(),它检索SysMyRoStubj.SysStukCube。现在…SysSimRoBjC.SysStkCube初始化为零(我想),而ySysStRMJARALCALLACK()函数负责每秒更新它。你的程序,不知何故,在SysMsRojPoto.SyStCyCalk中存储了一个有意义的值,我想你会看到自从系统初始化以来已经经过的秒数。我正在实现一个UDP客户端应用程序,并且在我的工作站的端口17上有一个UDP时间服务器。(最终,这将与DHCP后台程序和专用UDP服务器上的专有UDP服务器一起运行。)的想法是,在启动时,PIC32从工作站获得UNIX时间(从1970年1月1日起经过的秒),并以此为基础在PIC32上进行一天中的时间。系统。我还没有到达那里,但这正是我的目标。我可以告诉你,使用公历计算,这是从1月1日到0000日到1月1日1970秒的时间。当然,这是胡说八道,因为我们没有在零年的1月1日(事实上,没有零年——想想吧!)因为在第十六到第十八个世纪的日历调整大大改变了事情。(“损失”了一大堆秒,等等)。但至少这是从格里高利日历计算出来的,如果我们从1月1日1970回来。我无法想象价值2208988800是如何或为什么有用的,但它确实存在。我也无法想象这个未被评论的“神奇数字”是某种宇宙巧合。(然而:请参阅脚注)我的意思是,有人有理由定义那个特定的常数。但是,仅仅因为有一个原因并不意味着这是一个很好的理由。我简直想不出这是不是一个好理由。DaveFootnote,

以上来自于百度翻译


      以下为原文

   
 
Well, I'm just starting to poke around Harmony v1.09 and v2.02.00b.  Maybe I shouldn't comment at all, but this forum is just about the only place I learn anything practical, so here goes.  (Maybe some experts can chime in.  I would really, really appreciate it!)
 
Anyhow, here's how it goes (I think):
TCPIP_SNTP_UTCSecondsGet() calls SYS_TMR_TickCountGet(), which retrieves sSysTmrObject.sysTickCount.
Now...
sSysTmrObject.sysTickCount is initialized to zero (I think), and the _SYS_TMR_AlarmCallback() function is responsible for updating it every second.
 
So: Unless your program, somewhere, somehow, stores a meaningful value in sSysTmrObject.sysTickCount,
I think you will be reading the number of seconds that have elapsed since the system was initialized.
 
I'm implementing a UDP client application and I have a UDP time server on port 17 of my workstation. (Eventually this will be running along with a DHCP daemon and a specialized UDP server on a proprietary port on a dedicated laptop.)  The idea is that upon bootup, the PIC32 gets UNIX time (seconds elapsed since Jan 1, 1970) from the workstation and uses this as a base for time-of-day on the PIC32 system.  I haven't got there yet, but that's what I'm aiming for.
 

Well, I can tell you that, using Gregorian Calendar calculations, that is the number of seconds elapsed from Jan 1, 0000 through Jan 1 1970.  Of course that's nonsense since we didn't have January 1 in the year zero (Actually, there was no year zero---think about it!), and because calendar adjustments in the 16th though 18th centuries changed things considerably.  ("Lost" a bunch of seconds, among other things.)  But at least that's what comes out of the Gregorian calendar calculations if we project back from Jan 1 1970.
 
I can't imagine how or why the value 2208988800 is useful, but there it is.  I also can't imagine that this uncommented "magic number" is some cosmic coincidence.  (However: See Footnote)
 
I mean, someone had a reason to define that particular constant.  But, just because there is a reason doesn't mean it's a good reason.  I simply can't figure out whether it was a good reason.
 
 
Regards,

Dave
 
Footnote:
举报

王焕树

2019-4-2 09:30:06
以上来自于百度翻译


      以下为原文

   

 
举报

李子跃

2019-4-2 09:49:42
好吧,我可以告诉你,使用公历计算,这是从1月1日到0000日到1月1日1970秒的时间。当然,这是胡说八道,因为我们没有在零年的1月1日(事实上,没有零年——想想吧!)因为在第十六到第十八个世纪的日历调整大大改变了事情。(“损失”了一大堆秒,等等)。但至少这是从格里高利日历计算出来的,如果我们从1月1日1970回来。我无法想象价值2208988800是如何或为什么有用的,但它确实存在。我也无法想象这个未被评论的“神奇数字”是某种宇宙巧合。(但是:请参阅脚注),它是用来从NTP时间转换为UNIX时间的值,即UNIX时间=NTP秒- 2208988800(忽略NTP时间的小数部分)。

以上来自于百度翻译


      以下为原文

   
Well, I can tell you that, using Gregorian Calendar calculations, that is the number of seconds elapsed from Jan 1, 0000 through Jan 1 1970.  Of course that's nonsense since we didn't have January 1 in the year zero (Actually, there was no year zero---think about it!), and because calendar adjustments in the 16th though 18th centuries changed things considerably.  ("Lost" a bunch of seconds, among other things.)  But at least that's what comes out of the Gregorian calendar calculations if we project back from Jan 1 1970.
 
I can't imagine how or why the value 2208988800 is useful, but there it is.  I also can't imagine that this uncommented "magic number" is some cosmic coincidence.  (However: See Footnote)
 

That is the value used to convert from NTP time to Unix time i.e. Unix time = NTP Seconds - 2208988800 (ignoring the fractional part of NTP time).
 
I think it is up to you to configure the System Timer in harmony.
举报

更多回帖

发帖
×
20
完善资料,
赚取积分