Tronixlabs (Australia) offers several CAN shields based on Microchip’s MCP2515 stand-alone controller and MCP2551 transcei… — Read on at can-newsletter.org
Category: General
OpenSSL Wins the Levchin Prize
“When the largest web company in the world blocks out competitors, it smells less like an accident and more like strategy,”
A development truth
Good intro to Markdown
The question is…
Timers. One can wonder what they do in the decision matrix? They even have their own events defined in the CLASS2.VSCP class.
First let us define what a VSCP timer is.
A VSCP timer is a free running 32-bit timer with millisecond resolution. That is they can hold 0xffffffff = 4294967295 milliseconds which mens they will roll over in about 50 days.
There are actions defined to
There is the following internal events defined related to timers
- CLASS2.VSCPD, Type = 25 (0x0019) Timer started
- CLASS2.VSCPD, Type = 26 (0x001A) Timer paused
- CLASS2.VSCPD, Type = 27 (0x001B) Timer resumed
- CLASS2.VSCPD, Type = 28 (0x001C) Timer stopped
- CLASS2.VSCPD, Type = 29 (0x001D) Timer Elapsed
To create and start a timer
<row enable="true" groupid="timers" > <comment> Create timer </comment> <mask priority="0" class="0xFFFF" type="0xFFFF" GUID="00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00" /> <filter priority="0" class="65535" type="23" GUID="00:01:02:03:04:05:06:07:08:09:0A:0B:0C:0D:0E:0F" /> <action>0x60</action> <param> 1;10;timer1flag;true </param> </row>
Here a timer with id = 1 is created. The timer has an initial time set to 10 seconds. When this timer elapses it will set the variable //timer1flag// to true. The last argument is the reload flag. Here it is set to true so when the time has elapsed the initial value will be loaded again and the timer will start again.
In the example above we could have added “;4” at the end of the parameter which would have the effect that the reload would stop after four runs. Default is thus forever.
When the timer is started a CLASS2.VSCPD, Type = 25 (0x0019) Timer started event is generated. When the ten seconds has gone and the timer elapses the CLASS2.VSCPD, Type = 29 (0x001D) Timer Elapsed event is generated.
We can use either one of these two generated events to do any action periodically like this.
<row enable="true" groupid="timers" > <comment> Handle timer elapsed </comment> <mask priority="0" class="0xFFFF" type="0xFFFF" GUID="00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00" /> <filter priority="0" class="65535" type="29" GUID="00:01:02:03:04:05:06:07:08:09:0A:0B:0C:0D:0E:0F" /> <action>0x70</action> <param> /srv/vscp/timefile;1;%isoboth: Timer with id=%event.data.int32[0] elapsed %lf </param> </row> <row enable="true" groupid="timers" > <comment> Handle timer elapsed </comment> <mask priority="0" class="0xFFFF" type="0xFFFF" GUID="00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00" /> <filter priority="0" class="65535" type="25" GUID="00:01:02:03:04:05:06:07:08:09:0A:0B:0C:0D:0E:0F" /> <action>0x70</action> <param> /srv/vscp/timefile;1;%isoboth: Timer with id=%event.data.int32[0] elapsed counter=%event.data.uint32[0]ms %lf </param> </row>
Here some info is just written to a file when the timer is started and when it elapses. But if you want to send an event periodically instead or do other actions this is the way to do it.
You don’t have to give a variable nor a reload flag when you start a timer. If no variable is given (use ;;) it is just ignored. The reload value will be set to false as default value, that is the timer will run only once. As the last parameter you can set the number of times the timer should reload before it should stop. The full documentation is here and here.
One useful use of timers is to handle resend of events. The working is like this
Send the event you expect a reply event from another node.
- Create/start a timer that have period equal to resend intervals for the event you want to send. The timer should have true for autoloading and the number of autoloads set to the number of resend that are allowed. You can trigger the creation of the timer by make a DM entry that triggering on one of the reserved events for example, CLASS1.LOCAL or CLASS1.LABORATORY so that when you send this local event the actual event will be sent (see next point)
- In the timer started event send the event you want to send.
- When/If the expected reply is received pause the timer.
- Now if the timer the timer stopped event is detected the reply wait timeout has expired so do timeout handling there by sending another local event or CLASS1.ERROR, Type = 32 Time out.
Can be used for much more of course. Just useful and simple.
In another Howto we looked at the measurement compares that are available in the decision matrix (DM) record (VSCP HOWTO: COMPARE VALUES WITHOUT CODING). Here we will look at an action that work in a similar equal manner.
The check measurement action
VSCP_DAEMON_ACTION_CODE_CHECK_MEASUREMENT
is defined to make it possible to check a measurement against a literal value and just as we described in the howto about the check variable actions it stores the logical outcome of the compare in a boolean remote variable.
Also here equal to, less than, greater than etc is available. A typical parameter row can look like this
0;0;99.5;gt;flag
This says that if a measurement comes in that have a value that is greater than 99.5 the remote variable “flag” will be set to true. In all other cases “flag” will be set to “false”. The “0;0” that is the first two values of the parameter line is unit and sensor index. In this case the measurement therefore must have unit=0 and sensor index = 0 as well for the test to be evaluated at all.
A complete example is available in the documentation of the action. You can find pre written samples here.
As a note. Instead of a literal value for the compare you can use another variable. The parameter above can be rewritten
0;0;%variable:[critical_value];gt;flag
and instead of the literal “99.5” the value of the remote variable 99.5 is used for the compare. VSCP DM escapes are evaluated before an action is carried out. There is many of them and they can be very useful when you want to make decision matrix rows act in a more dynamic way without go so far as to use full JavaScript or Lua. You can read more about the VSCP DM escapes here.
It isn’t harder than that actually.