Bug in SNTP_oneshot()

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Bug in SNTP_oneshot()

1,074件の閲覧回数
lucky06200
Contributor II

Hello,

I think there is a bug in SNTP_oneshot()

When call to NTP server is unsuccessful, function call set however the system time with a zero value, clearing previous data.

We have then a 0 in system time. What about ?

Best regards,

Luc

ラベル(1)
タグ(1)
0 件の賞賛
返信
2 返答(返信)

668件の閲覧回数
DavidS
NXP Employee
NXP Employee

Hi Luc,
To add to Daniel's good comments I did an experiment using TWR-K60F120M tower kit.
I started with the C:\Freescale\Freescale_MQX_4_0_2_GA\rtcs\examples\shell\cw10gcc\rtcs_shell_twrk60f120m example using CW10.5.
In the demo_cmd.c file I added the following (the line with "//DES test" comment):
    { "ipconfig",  Shell_ipconfig },
    { "oneshot", Shell_SNTP_oneshot },   //DES test

In the shell RTOS component I added the following to the sh_rtcs.h header:
extern int_32 Shell_iwconfig(int_32 argc, char_ptr argv[] );
extern int_32 Shell_SNTP_oneshot(int_32 argc, char_ptr argv[] ); //DES test

In the shell RTOS component I copied and pasted the sh_tftp.c and renamed it "sh_oneshot.c".  I then added the file into the shell component (drag-n-drop using Windows Explorer) "Shell Source-->rtcs" folder (i.e. it gets added to the project for compiling).  I've attached this file to the post as it is the only file I had to generate.

Compile the shell RTOS component and then the rtcs_shell application.

I used the NIST Internet Time Server ( http://tf.nist.gov/tf-cgi/servers.cgi ) to find a NTP Server IP Address to use below.

My Terminal prompt output is:

shell>
shell> help oneshot
Usage: oneshot  <host> <timeout_ms>
   <host>   = host ip address or name
   <timeout_ms>   = timeout delay in milliseconds
shell>
shell> oneshot 64.90.182.55 6000
Connecting to 64.90.182.55 [64.90.182.55]: <-- NTP SERVER DOWN :-(
Connection failed, error 0x1103
Connection closed
shell>
shell> oneshot 129.6.15.30 8000
Connecting to 129.6.15.30 [129.6.15.30]: <-- NTP SERVER UP :-)
Connection closed
shell>
shell> help
Available commands:
   gethbn <host>
   help [<command>]
   ipconfig [<device>] [<command>]
   oneshot <host> <timeout_ms>  <--NEW COMMAND in the help list
shell>
shell> dir
Error, directory does not exist.
shell>
shell> format a: david

Formating...
Done. Volume name is DAVID     
Free disk space: 11776 bytes
shell>
shell> write bob 1    
shell>
shell> dir
DAVID               0 00-00-1980 00:00:00    V   DAVID <-- NOT SURE WHY NOT PROPER DATE and TIME
BOB                 1 03-04-2014 19:19:20      A BOB <-- PROPER DATE and TIME !
shell>
shell>
shell>
shell>
shell> gethbn time-c.nist.gov  <--IF YOU KNOW SERVERNAME AND WANT IP ADDRESS
time-c.nist.gov...129.6.15.30
shell>

Regards,
David

0 件の賞賛
返信

668件の閲覧回数
danielchen
NXP TechSupport
NXP TechSupport

Hi Luc:

According to MQX_RTCS_User_Guide.pdf, SNTP_oneshot function sends an SNTP packet and waits for a reply. If a reply is received before timeout elapse, the time is set. If no reply is received within the specified time,RTCSERR_TIMEOUT is returned. The local time is set in UTC (coordinated universal time)

You can see the code in function SNTP_timed_send_recv,

......

   /* Send packet */

   error = sendto(sock, (char_ptr)&header, sizeof(SNTP_HEADER), 0, (sockaddr *)&addr,

      sizeof(sockaddr_in));

   /* Get reply only if request was sent */

   if (error != sizeof(SNTP_HEADER)) {

      return RTCS_geterror(sock);

   } /* Endif */

.......

So I guess maybe your NTP server returned a zero value, but not sure, need further information to analyze.


Have a great day,
Daniel

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信