In my last post I demonstrated how easy it is to get data from IoT Foundation. But many of you might thing, why? Well I just wanted to show how easy it is to report on IoT data using pure old DOORS 9 but there was no fun in the preview post, just boring numbers.
Example Scenario
Let's have a hypothetical example where we measure yaw/pitch/roll and have following rules:
- Measurable parameters of an Android Device shall not exceed expected maximum values
- Each report of a value exceeding 0.77 of maximum should be indicated Orange
- Each report of a value exceeding 0.88 of maximum should be indicated Red
So we need something to read data from IoT device, storage for a maximum value and some nice indicators.
Module Attributes
I just extended my module with extra attributes:
- iot_data (real) - doesn't affect change bar, doesn't affect change dates and doesn't generate history
- range_max (real) - a regular attribute of type range
Having add those I can update my layout DXL column to render color depending on current value:
if (findPlainText(re, ":", l, o, false)) {
string ss = re[l+1:length(re) -3]
real r = realOf ss
obj."iot_data" = r
real m = obj."range_max"
real rm = r/m
DBE cnv = getCanvas
realBackground(cnv, realColor_Green)
if (rm >= 0.77 && rm < 0.88) {
realBackground(cnv, realColor_Orange)
realColor(cnv, realColor_White)
}
else if (rm >= 0.88) {
realBackground(cnv, realColor_Red)
realColor(cnv, realColor_White)
}
else {
realColor(cnv, realColor_Black)
}
display ss
}
Code isn't perfect, could be faster, but that's not the point here ;)
Now let's have some fun with canvas DXL. Add new DXL column and set its DXL to:
DBE canvas = getCanvas
if (canvas==null) halt
int rh = 50 du
int rw = 100 du
setHeight rh
setWidth rw
int normalize(real x, max) {
real i = 180.0+ x/max * 180.0
return intOf i
}
real x = (obj."iot_data")
real m = (obj."range_max")
if (m == 0.0) halt
int v = normalize(x, m)
int margin = 1
realColor(canvas, realColor_Green)
if (v >= 280 && v < 320) {
realColor(canvas, realColor_Orange)
margin = 2
}
else if (v >= 320) {
realColor(canvas, realColor_Red)
margin = 5
}
ellipse(canvas, 0, 0, rw, 2*rh)
realColor(canvas, realColor_White)
ellipse(canvas, margin, margin, rw-2*margin, (2*rh)-2*margin)
realColor(canvas, realColor_Black)
polarLine(canvas, rw/2, rh-1, rh, v)
Resulting View will show us (almost) real-time events and warning from our device.
Remember this could be a group of devices or a single device. It all depends what you want to measure.

No comments:
Post a Comment
Note: only a member of this blog may post a comment.