TheWaterboy
Lifetime Supporting Member + Moderator
The idea here is to provide for a brief rapid influx of message codes while preventing sequentially repeating the same message.
i.e. if two explosions occurred a second or two apart - only one audible announcement of an explosion will be required.
But if an Explosion and a Flood happened half a second (or 5, 10 seconds) apart, then announce them both, Explosion first , then Flood.
The plague of Locusts is not scheduled for another hour. It will be a single event that still needs to be announced.
Because the device being used is serial control it uses a ETH I/P gateway so there is a scan delay between command and response. So the logic here needs to wait for it.
I need to test the device for [BusyFlag] before allowing [PLAY] to be set or stack to be popped,
but Stack still needs to be able to push additional values should they arrive.
This process begs for a Pi or Arduino with CIP Ethernet but I dont know if that protocol even exists in that space and even if it did I just have the time to learn one of those now.
Some of this is this way because the HMS serial/IP Gateway requires it to be.
One example is that to actually send any character out or read anything back into the gateway serially you increment a seperate trigger byte.
The player itself is MUCH simpler and responds to single ASCII characters, but comm is serial so I gotta do this incrementation thing
I have the device working and can play messages through the PLC by toggling bits and moving values, but I cant get over this queueing hurdle.
Many of you use a FIFO queue far more than I so I hope I can get some example code I can grasp the required flow from.
DEFINES:
[IncomingCode] = 3 digit code used to choose the message to be played (Flood, Famine, Zombies etc)
[CheckForBusy] = random number sent to the Player asking for its status, It responds with a code that I filter into a bool called [BusyFlag]
[EvaluationTag] = Tag the [IncomingCode] is moved to for local processing, allowing [IncomingCode] to be cleared and then re-populated from elsewhere
STACK = FFL/FFU Pair to hold new codes that arrive while Player is busy - I have the FIFO pair working fine, it Pushes and Pops correctly. just cant visualize how to implement it here.
[BusyFlag] = Bit indicating the Player is busy doing something else (and it is not capable of queueing)
[PLAY] = Bit to tell the player to play the message code contained in [AnnunciatorInputTag]
[AnnunciatorInputTag] = The 3 Digit message code that is sent to the Player followed by [PLAY]
[ReadyFlag] = Opposite of [BusyFlag]
This below is only meant as a flow chart -I just couldn't come up with a better way to convey it
i.e. if two explosions occurred a second or two apart - only one audible announcement of an explosion will be required.
But if an Explosion and a Flood happened half a second (or 5, 10 seconds) apart, then announce them both, Explosion first , then Flood.
The plague of Locusts is not scheduled for another hour. It will be a single event that still needs to be announced.
Because the device being used is serial control it uses a ETH I/P gateway so there is a scan delay between command and response. So the logic here needs to wait for it.
I need to test the device for [BusyFlag] before allowing [PLAY] to be set or stack to be popped,
but Stack still needs to be able to push additional values should they arrive.
This process begs for a Pi or Arduino with CIP Ethernet but I dont know if that protocol even exists in that space and even if it did I just have the time to learn one of those now.
Some of this is this way because the HMS serial/IP Gateway requires it to be.
One example is that to actually send any character out or read anything back into the gateway serially you increment a seperate trigger byte.
The player itself is MUCH simpler and responds to single ASCII characters, but comm is serial so I gotta do this incrementation thing
I have the device working and can play messages through the PLC by toggling bits and moving values, but I cant get over this queueing hurdle.
Many of you use a FIFO queue far more than I so I hope I can get some example code I can grasp the required flow from.
DEFINES:
[IncomingCode] = 3 digit code used to choose the message to be played (Flood, Famine, Zombies etc)
[CheckForBusy] = random number sent to the Player asking for its status, It responds with a code that I filter into a bool called [BusyFlag]
[EvaluationTag] = Tag the [IncomingCode] is moved to for local processing, allowing [IncomingCode] to be cleared and then re-populated from elsewhere
STACK = FFL/FFU Pair to hold new codes that arrive while Player is busy - I have the FIFO pair working fine, it Pushes and Pops correctly. just cant visualize how to implement it here.
[BusyFlag] = Bit indicating the Player is busy doing something else (and it is not capable of queueing)
[PLAY] = Bit to tell the player to play the message code contained in [AnnunciatorInputTag]
[AnnunciatorInputTag] = The 3 Digit message code that is sent to the Player followed by [PLAY]
[ReadyFlag] = Opposite of [BusyFlag]
This below is only meant as a flow chart -I just couldn't come up with a better way to convey it
Code:
BEGIN PseudoCode
While [IncomingCode] > 0 'just a timer but shown here for sake of clarity
Increment [CheckForBusy] integer every 5 seconds. 'Repeatedly check for Busy when a code comes in
End While
If [IncomingCode] > 0
Move [IncomingCode] to [EvaluationTag]
Clear [IncomingCode]
End If
If [ReadyFlag] is set then 'the result of incrementing [CheckForBusy]
If [EvaluationTag] <> Previous Value OR > 20 seconds elapsed since last
PUSH [EvaluationTag] to STACK
Set [EvaluationTag] = 0
While STACK.Pos > 0 'need to ensure the POP'd value is handled before popping another one
POP STACK to [AnnunciatorInputTag] ' what do I use for this?
If [BusyFlag] = 0 'will this race against the first While Loop ?
Latch [Play] Tag 'resulting in External device responding by setting [BusyFlag] Tag
[BusyFlag] = 1 -> Unlatch [PLAY] tag
End If
End While
End If
End If
END Pseudocode