| Newsgroups |
gmane.comp.hardware.rabbit-semiconductor |
| Message-ID |
<[email protected]> |
I am trying to implement a web button that will fetch the current time from a NIST time server, with the routine based on the NIST_TIME.C sample code. My code will get the NIST time if that function is called before starting the http handler. And the http handler will work fine until an attempt is made to get the NIST time. With the attached C and HTML code, each time the user clicks the --Test-- button, a line prints in the STDIO window. But clicking the --Get NIST Time-- button kills the browser code. In the C code, a call to the function which gets the NIST time is commented out (about 10 lines from the bottom). If that line is made active, the program will get the NIST time and print it, but then the browser code doesn’t work. Obviously I know nothing when it comes to TCPIP st
uff. Please, can anyone help?
C code
--------------------------------------------
#class auto
#memmap xmem
#define TCPCONFIG 3
#define NIST_SERVER_IP "129.6.15.30" // time-c.nist.gov NIST, Gaithersburg, Maryland
#define NIST_PORT 13 // Maryland, USA
#define NIST_TIMEOUT 30 // max. number of secs. to wait for response
#define USE_RABBITWEB 1
#use "dcrtcp.lib"
#use "http.lib"
#ximport "/nisttest.html" index_html
tcp_Socket s;
int testButton;
int nistButton;
#web testButton
#web nistButton
SSPEC_MIMETABLE_START // define file handlers
SSPEC_MIME_FUNC(".html", "text/html", zhtml_handler),
SSPEC_MIME(".html", "text/html")
SSPEC_MIMETABLE_END
SSPEC_RESOURCETABLE_START // define resources
SSPEC_RESOURCE_XMEMFILE("/", index_html),
SSPEC_RESOURCE_XMEMFILE("/index.html", index_html)
SSPEC_RESOURCETABLE_END
void nistTime(int TIMEZONE)
{
int status;
char buffer[2048];
longword ip;
int i, dst, health;
struct tm t;
unsigned long longsec;
printf("nConnecting with NIST server ...n");
sock_init();
while (ifpending(IF_DEFAULT) == IF_COMING_UP)
{
tcp_tick(NULL);
}
ip=resolve(NIST_SERVER_IP);
tcp_open(&s, 0, ip, NIST_PORT, NULL);
sock_wait_established(&s, NIST_TIMEOUT, NULL, &status);
sock_mode(&s, TCP_MODE_ASCII);
// Receive and process data -- the server will close the connection,
// which will cause execution to continue at sock_err below.
while (tcp_tick(&s))
{
sock_wait_input(&s, NIST_TIMEOUT, NULL, &status);
sock_gets(&s, buffer, 48);
}
sock_err:
if (status == -1)
{
printf("nConnection timed out, exiting.n");
exit(1);
}
if (status != 1)
{
printf("nUnknown sock_err (%d), exiting.n", status);
exit(1);
}
sock_close(&s);
t.tm_year = 100 + 10*(buffer[6]-'0') + (buffer[7]-'0');
t.tm_mon = 10*(buffer[9]-'0') + (buffer[10]-'0');
t.tm_mday = 10*(buffer[12]-'0') + (buffer[13]-'0');
t.tm_hour = 10*(buffer[15]-'0') + (buffer[16]-'0');
t.tm_min = 10*(buffer[18]-'0') + (buffer[19]-'0');
t.tm_sec = 10*(buffer[21]-'0') + (buffer[22]-'0');
dst = 10*(buffer[24]-'0') + (buffer[25]-'0');
health = buffer[27]-'0';
longsec = mktime(&t);
longsec += 3600ul * TIMEZONE; // adjust for timezone
dst = (dst >= 1 && dst <= 50 ); // adjust for DST
if (dst)
longsec += 3600ul;
mktm(&t, longsec); // convert back to tm struct for display
if (health < 2) // set the RTC if the NIST results are good
write_rtc(longsec);
printf("nCurrent time: %02d:%02d:%02d %02d/%02d/%04dn",
t.tm_hour, t.tm_min, t.tm_sec,
t.tm_mon, t.tm_mday, 1900 + t.tm_year);
}
void changeStatus()
{
printf("Test button pushedn");
testButton = 0;
}
#web_update testButton changeStatus
#web_update nistButton nistTime
void main()
{
int TIMEZONE;
TIMEZONE = -8;
testButton = 0;
nistButton = 0;
brdInit();
// nistTime(TIMEZONE);
sock_init();
http_init();
tcp_reserveport(80);
while(1)
{
http_handler();
}
}
HTML code
--------------------------------------------
<HTML>
<BODY BGCOLOR="#ffffdd">
<form action="/index.html" method="post">
<input type="hidden" name="testButton" value=1>
<input id="test_button" type="submit" value="Test">
</form>
<form action="/index.html" method="post">
<input type="hidden" name="nistButton" value=1>
<input id="nist_button" type="submit" value="Get NIST Time">
</form>
</BODY>
</HTML>
------------------------------------
------------------------------------
------------------------------------
Yahoo Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/rabbit-semi/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/rabbit-semi/join
(Yahoo! ID required)
<*> To change settings via email:
[email protected]
[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/