Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: CReese on November 14, 2013, 11:49:10 AM

Title: Periodic, staged process
Post by: CReese on November 14, 2013, 11:49:10 AM
So I'm setting up a network watchdog. I have a list of, say, 24 IP addresses I want to ping periodically and set status bits to see if they're around. I'd like to run it every so often. My instinct would be to set up a staged process, where the ping jumps to either an error stage or a success stage, where the result bit is set accordingly.

Wanting to run it every five seconds, however, I'd want to use a task ... which is incompatible with stages. I could use a for loop inside a task, but I'm unclear how the asynchronous nature of the ping would work with indexing a results array. I'm sure this is a pretty basic program structure question, and I'm hoping it will help me understand how best to do this.

Thanks.
Title: Re: Periodic, staged process
Post by: BobO on November 14, 2013, 11:57:01 AM
I'd use stages in a program. Just add a timer to the last stage of the program and jump back to the top when it fires. If you plan on disabling the monitor, just add a conditional EXIT to the last stage.
Title: Re: Periodic, staged process
Post by: CReese on November 14, 2013, 12:03:04 PM
Ok, here's a question. Say I have a stage that runs the ping command. My understanding is that this stage continues to run as long as it is enabled. Does this mean a ping will be executed each scan until one succeeds or fails to send it to force the jump? So if a timeout period is 500ms, as many pings as scans executed in 500ms will occur? I could program around this easily, but am just curious.
Title: Re: Periodic, staged process
Post by: BobO on November 14, 2013, 12:07:35 PM
No. PING is edge triggered. If you put it in a stage with no input logic, it will fire once. If you use PING's internal stage transition logic, it will run until complete or fails, and jump to the appropriate stage. Just do one per stage, and jump to the next on success, or an error handler on failure. This is what stage in programs was created for.
Title: Re: Periodic, staged process
Post by: CReese on November 14, 2013, 12:08:23 PM
Edge-triggered, that's what I was looking for.
Title: Re: Periodic, staged process
Post by: BobO on November 14, 2013, 12:18:45 PM
I would do something like this greatly simplified example. S0 and S1 are pinging devices, S2 is the final stage with timer, S10 is the error handler. Note the triangle on the PING instructions...that means they are edge triggered.
Title: Re: Periodic, staged process
Post by: CReese on November 14, 2013, 01:49:38 PM
I did something similar.

S0
SETNUMR WatchdogIndex 0
SETNUMR WatchdogMaxInd 48
JMP S1

S1
PING IP WatchdogIPs[WatchdogIndex]
On SUCCESS S2
On FAIL S3

S2
SET WatchdogStat[WatchdogIndex]
JMP S4

S3
RST WatchDogStat[WatchdogIndex]
JMP S4

S4
WatchdogIndex < WatchdogMaxInd --> MATH WatchdogIndex++
WatchdogIndex >= WatchdogMaxInd --> JMP S5
JMP S1

S5
TMR WatchdogDelay

TMR.Done && NOT WatchdogEnable --> EXIT
TMR.Done --> JMP S0
Title: Re: Periodic, staged process
Post by: BobO on November 14, 2013, 04:03:08 PM
I like it better. Good use of looping and indexing in stage.
Title: Re: Periodic, staged process
Post by: CReese on November 14, 2013, 04:18:41 PM
Thank you, sir. Credit these boards alone.
Title: Re: Periodic, staged process
Post by: franji1 on November 14, 2013, 04:19:16 PM
I like it better. Good use of looping and indexing in stage.
Agreed!  Note the lack of looping instructions, but still utilizing array indexing.  Looping instructions are actually just a means-to-an-end.  Indirection (i.e. arrays, pointers, etc.) is where the power lies.  Great Do-more pattern!
Title: Re: Periodic, staged process
Post by: BobO on November 14, 2013, 04:24:07 PM
Thank you, sir. Credit these boards alone.

We are glad to hear that you find some benefit here. I absolutely love to see the 'light turn on' for folks using Do-more, and seeing complicated problems become deceptively simple.