nnCron and nnCron LITE discussion
by LuckMan212 » Mon, 04 Jul 2005, 12:10
ok I am trying out the nnCron and it seems really powerful. I am using version v 1.91b11 Build 1049. I am not really a programmer but I usually can figure things out and I do know a little javascript, perl, and batch files hehe  Anyway I have here a task which WORKS 99% except there a few things that I cant figure out even after hours of poring over documentation and even trying to read Thinking Forth.PDF which was suggested:
So basically it is an "advanced" time-sync Task, here are the features:
- 1) there is a file called "time_servers.txt" containing a list of NTP servers, one on each line, that will be tried until one succeeds to set the time
- 2) if this time_servers.txt file is missing or empty, do not attempt to sync the clock and pop a balloon hint showing an error
- 3) the filename (in my case "time_servers.txt") is stored in a variable (array??) so it can easily be changed
- 4) if console is open, activity will also be sent to the console
- 5) if no sync can occur after going through entire list of servers, then show a permanent "hint" window so in case I am away, I am alerted to the problem.
OK that's basically the idea. So everything is working, except I have a couple of questions, PLEASE!- Q1) when I try to replace the following (on line #10):
- Code: Select all
S" time_servers.txt" R/O OPEN-FILE-SHARED THROW time_server_list ! ...with this (variable used):- Code: Select all
time_server_file COUNT TYPE R/O OPEN-FILE-SHARED THROW time_server_list ! ....it doesnt work and I get strange errors and exceptions thrown in Console. I have also tried these variations:- Code: Select all
%time_server_file% time_server_file @ S" %time_server_file COUNT% How can I insert the filename to open from the variable?
- Q2) This code is a little sloppy, is there a better way (instead of using EXIT command) to break out of the WHILE loop once it is successfully sync'ed? I would like to not have to repeat sections of the code, e.g. the line to CLOSE-FILE is repeated, can this be made more efficient? Ideally, I would like the fork on the WHILE loop to test for BOTH conditions-- like this (in human-language):
- Code: Select all
IF there is another line to be read from the text file AND the time has not yet been synced THEN continue trying ELSE exit the loop and close the file handle ENDIF
- Q3) is there some place I can read a beginner's tutorial of using variables, especially string variables, in SP-FORTH? I am finding this very difficult to grasp, all the different ways to reference and declare variables like VARIABLE, CREATE, ALLOT, @, W@, C@, %var% etc etc.. I am lost!!
so anyway here is the code.... - Code: Select all
#( Time_Sync VARIABLE time_server_list CREATE time_server_file 256 ALLOT S" time_servers.txt" time_server_file PLACE CREATE curNtpSrv 256 ALLOT Time: 45 0,4,8,16,20 * * * * Action: FILE-EXIST: "%time_server_file COUNT%" FILE-EMPTY: "%time_server_file COUNT%" NOT AND IF S" time_servers.txt" R/O OPEN-FILE-SHARED THROW time_server_list ! BEGIN curNtpSrv 1+ 255 time_server_list @ READ-LINE THROW WHILE curNtpSrv C!
TP-SYNC: "%curNtpSrv COUNT%" TP-SYNC-RESULT 0<> IF ." NTP : could not sync with " curNtpSrv COUNT TYPE CR ELSE 1 BalloonIcon ! BALLOON: "NTP Update Succeeded" "Synchronized with %curNtpSrv COUNT% (%TP-SYNC-DELAY% ms)" ." NTP : synchronized with " curNtpSrv COUNT TYPE ." (" TP-SYNC-DELAY . ." ms)" CR time_server_list @ CLOSE-FILE DROP EXIT THEN
REPEAT DROP HINT-OFF HINT-POS: 837 960 HINT-SIZE: 436 27 HINT: "NTP Error: Could not synchronize with any of the time servers provided." time_server_list @ CLOSE-FILE DROP ELSE 3 BalloonIcon ! BALLOON: "NTP Configuration Error" "The '%time_server_file COUNT%' file is missing or empty." THEN )#
can anyone please help me? thanks!! 
-
LuckMan212
-
- Posts: 133
- Joined: Mon, 04 Jul 2005, 11:19
by Nicholas_Nemtsev » Tue, 05 Jul 2005, 09:19
1. Use ZPLACE and ASCIIZ> instead PLACE and COUNT.
- Code: Select all
CREATE time_server_file 256 ALLOT S" time_servers.txt" time_server_file ZPLACE ... FILE-EXIST: "%time_server_file ASCIIZ>%" ... ... time_server_file ASCIIZ> R/O OPEN-FILE-SHARED THROW time_server_list !
2. - Code: Select all
: get-next-line ( -- a u true | -- false ) ... ; : sync-time ( -- ?) ... ; ... BEGIN get-next-line IF sync-time ELSE TRUE THEN UNTIL
3. There is not documentation for all sp-forth/nncron words. See sources.
Nicholas Nemtsev
-

Nicholas_Nemtsev
- Site Admin
-
- Posts: 857
- Joined: Thu, 01 Jul 2004, 22:25
- Location: Псков
-
by LuckMan212 » Tue, 05 Jul 2005, 10:08
Thank you, #1 works perfect
as for #2, I see you are asking me to define some new "words". But what does this mean:
- Code: Select all
( -- a u true | -- false ) ... ;
is that just comments? I am not sure where I am supposed to put this. I am supposed to chop up the code into subroutines I guess?
Do these word declarations go inside the "action" portion of the Task,or before it, or completely in a separate .spf "plugin" file..?
Please can you pretend I don't know anything (because I really dont) and try to give me a little more details, sorry to be a pain but I just did buy the software and am looking for some help... thanks 
-
LuckMan212
-
- Posts: 133
- Joined: Mon, 04 Jul 2005, 11:19
by Nicholas_Nemtsev » Tue, 05 Jul 2005, 10:38
Yes, ( -- ... ) is comment.
- Code: Select all
#( Time_Sync VARIABLE time_server_list CREATE time_server_file 256 ALLOT S" time_servers.txt" time_server_file PLACE CREATE curNtpSrv 256 ALLOT Time: 45 0,4,8,16,20 * * * * : next-line ( -- ? ) curNtpSrv 1+ 255 time_server_list @ READ-LINE 0<> SWAP 0= OR IF DROP FALSE ELSE curNtpSrv C! TRUE THEN ; : sync-time ( -- ?) TP-SYNC: "%curNtpSrv COUNT%" TP-SYNC-RESULT 0= ; Action: ...
Nicholas Nemtsev
-

Nicholas_Nemtsev
- Site Admin
-
- Posts: 857
- Joined: Thu, 01 Jul 2004, 22:25
- Location: Псков
-
by LuckMan212 » Wed, 06 Jul 2005, 10:22
Nicholas,
I know English is not your 1st language. And I see you are a man of few words. I can respect that.
But please.. I am really begging you  . Pretend I don't know anything about programming and can you please tell me how to make this task (complete) . Posting these small code fragments is not helping me, it just leads to more frustration.
I have tried to help support you by purchasing the program. I really need a little bit more help with this.
Thank you.
Can you please fill in the incorrect portions of this? (completely broken code below!) - Code: Select all
#( Time_Sync VARIABLE time_server_list CREATE time_server_file 256 ALLOT S" time_servers.txt" time_server_file ZPLACE CREATE curNtpSrv 256 ALLOT Time: 45 0,4,8,16,20 * * * * : next-line ( -- ? ) curNtpSrv 1+ 255 time_server_list @ READ-LINE 0<> SWAP 0= OR IF DROP FALSE ELSE curNtpSrv C! TRUE THEN ; : sync-time ( -- ?) TP-SYNC: "%curNtpSrv COUNT%" TP-SYNC-RESULT 0= ;
Action: FILE-EXIST: "%time_server_file ASCIIZ>%" FILE-EMPTY: "%time_server_file ASCIIZ>%" NOT AND IF time_server_file ASCIIZ> R/O OPEN-FILE-SHARED THROW time_server_list ! BEGIN next-line THROW WHILE sync-time IF ." NTP : could not sync with " curNtpSrv COUNT TYPE CR ELSE 1 BalloonIcon ! BALLOON: "NTP Update Succeeded" "Synchronized with %curNtpSrv COUNT% (%TP-SYNC-DELAY% ms)" ." NTP : synchronized with " curNtpSrv COUNT TYPE ." (" TP-SYNC-DELAY . ." ms)" CR THEN
REPEAT DROP HINT-OFF HINT-POS: 837 960 HINT-SIZE: 436 27 HINT: "NTP Error: Could not synchronize with any of the time servers provided." time_server_list @ CLOSE-FILE DROP ELSE 3 BalloonIcon ! BALLOON: "NTP Configuration Error" "The '%time_server_file ASCIIZ>%' file is missing or empty." THEN )#
-
LuckMan212
-
- Posts: 133
- Joined: Mon, 04 Jul 2005, 11:19
by Nicholas_Nemtsev » Wed, 06 Jul 2005, 13:17
:)
- Code: Select all
#( Time_Sync VARIABLE time_server_list CREATE time_server_file 256 ALLOT S" time_servers.txt" time_server_file ZPLACE CREATE curNtpSrv 256 ALLOT Time: 45 0,4,8,16,20 * * * * : next-line ( -- ?) curNtpSrv 1+ 255 time_server_list @ READ-LINE 0<> SWAP 0= OR IF DROP FALSE ELSE curNtpSrv C! TRUE THEN ; : sync-time ( -- ?) TP-SYNC: "%curNtpSrv COUNT%" TP-SYNC-RESULT 0= ; VARIABLE flagSynchronized Action: FILE-EXIST: "%time_server_file ASCIIZ>%" FILE-EMPTY: "%time_server_file ASCIIZ>%" NOT AND IF flagSynchronized OFF time_server_file ASCIIZ> R/O OPEN-FILE-SHARED THROW time_server_list ! BEGIN next-line WHILE sync-time IF flagSynchronized ON 1 BalloonIcon ! BALLOON: "NTP Update Succeeded" "Synchronized with %curNtpSrv COUNT% (%TP-SYNC-DELAY% ms)" ." NTP : synchronized with " curNtpSrv COUNT TYPE ." (" TP-SYNC-DELAY . ." ms)" CR ELSE ." NTP : could not sync with " curNtpSrv COUNT TYPE CR THEN flagSynchronized @ UNTIL THEN flagSynchronized @ 0= IF HINT-OFF HINT-POS: 837 960 HINT-SIZE: 436 27 HINT: "NTP Error: Could not synchronize with any of the time servers provided." THEN time_server_list @ CLOSE-FILE DROP ELSE 3 BalloonIcon ! BALLOON: "NTP Configuration Error" "The '%time_server_file ASCIIZ>%' file is missing or empty." THEN )#
Nicholas Nemtsev
-

Nicholas_Nemtsev
- Site Admin
-
- Posts: 857
- Joined: Thu, 01 Jul 2004, 22:25
- Location: Псков
-
by LuckMan212 » Wed, 06 Jul 2005, 13:52
wow this is genius!!
thank you so much
I am going to study each line to try to figure out how you did it
Thank you for this help!!
-
LuckMan212
-
- Posts: 133
- Joined: Mon, 04 Jul 2005, 11:19
Return to nnCron forum (English)
Who is online
Users browsing this forum: No registered users and 0 guests
|
|