Project

General

Profile

Feature #588

Enable GenericIO to cater for more than 4 + battery values

Added by thechad over 3 years ago. Updated over 2 years ago.

Status:
In Progress
Priority:
Normal
Assignee:
Category:
DomotiGa3
Target version:
Start date:
10/19/2015
Due date:
% Done:

10%

Estimated time:
Resolution:

Description

Hi Guys,
When I originally coded GenericIO DomotiGa could only cater for 4 device values (plus battery value).

Now, it can do many more. But with the existing code, if I try and send "1,2,3,4,5,6" into GenericIO interface, it will error with

I was taking a look at the code and I suspect it's easy to change the module to cater for it but my gambas skills have become rusty...so was wondering if you guys could either make the change or suggest the right line of code.

Sorry for the iposition.

This is the relevant code segment.
The first case block deals with when you are setting one defined value, ie. "temp=12.12" and the relevant regex for the device determines which value slot to put this in...eg if the address field in device is |R1|R2|temp|litres|, the we are updating value field 3 in this device.

The second block sets the values if the incoming data is just a set of delimited numbers ie. "12,3,45.44,455,3.784". A simple for loop should do it.

It assumes the value in the fifth spot is the battery voltage (as that was the default at the time). I guess if we change it, that will now go in value 5 of the device (and not the battery value) so that may be a change for some people?
I am not even sure battery is used any more - is it?

Thanks!

      Select aValueToUpdate.Count
        Case 1
          Select iValueToUpdate
            Case 1
              Devices.ValueUpdate(iDeviceId, 1, Trim(aValueToUpdate[0]))
              If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value" & iValueToUpdate & " to '" & Trim(aValueToUpdate[0]) & "'")
            Case 2
              Devices.ValueUpdate(iDeviceId, 2, Trim(aValueToUpdate[0]))
              If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value" & iValueToUpdate & " to '" & Trim(aValueToUpdate[0]) & "'")
            Case 3
              Devices.ValueUpdate(iDeviceId, 3, Trim(aValueToUpdate[0]))
              If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value" & iValueToUpdate & " to '" & Trim(aValueToUpdate[0]) & "'")
            Case 4
              Devices.ValueUpdate(iDeviceId, 4, Trim(aValueToUpdate[0]))
              If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value" & iValueToUpdate & " to '" & Trim(aValueToUpdate[0]) & "'")
            Default
              Main.WriteDebugLog(LogLabel & "Unknown value to update :" & iValueToUpdate)
        End Select
        Case 2
          Devices.ValueUpdate(iDeviceId, 1, Trim(aValueToUpdate[0]))
          Devices.ValueUpdate(iDeviceId, 2, Trim(aValueToUpdate[1]))
          If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value1:'" & Trim(aValueToUpdate[0]) & "' Value2:'" & Trim(aValueToUpdate[1]) & "'")
        Case 3
          Devices.ValueUpdate(iDeviceId, 1, Trim(aValueToUpdate[0]))
          Devices.ValueUpdate(iDeviceId, 2, Trim(aValueToUpdate[1]))
          Devices.ValueUpdate(iDeviceId, 3, Trim(aValueToUpdate[2]))
          If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value1:'" & Trim(aValueToUpdate[0]) & "' Value2:" & Trim(aValueToUpdate[1]) & "' Value3:'" & Trim(aValueToUpdate[2]) & "'")
        Case 4
          Devices.ValueUpdate(iDeviceId, 1, Trim(aValueToUpdate[0]))
          Devices.ValueUpdate(iDeviceId, 2, Trim(aValueToUpdate[1]))
          Devices.ValueUpdate(iDeviceId, 3, Trim(aValueToUpdate[2]))
          Devices.ValueUpdate(iDeviceId, 4, Trim(aValueToUpdate[3]))
          If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value1:'" & Trim(aValueToUpdate[1]) & "' Value2:'" & Trim(aValueToUpdate[1]) & "' Value3:'" & Trim(aValueToUpdate[2]) & "' Value4:'" & Trim(aValueToUpdate[3]) & "'")
        Case 5
          Devices.ValueUpdate(iDeviceId, 1, Trim(aValueToUpdate[0]))
          Devices.ValueUpdate(iDeviceId, 2, Trim(aValueToUpdate[1]))
          Devices.ValueUpdate(iDeviceId, 3, Trim(aValueToUpdate[2]))
          Devices.ValueUpdate(iDeviceId, 4, Trim(aValueToUpdate[3]))
          If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value1:'" & Trim(aValueToUpdate[1]) & "' Value2:'" & Trim(aValueToUpdate[1]) & "' Value3:'" & Trim(aValueToUpdate[2]) & "' Value4:'" & Trim(aValueToUpdate[3]) & "'")
          If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Battery:'" & Trim(aValueToUpdate[4]) & "'")
          Devices.Battery(iDeviceId, Trim(aValueToUpdate[4]))
        Default
          If $bDebug Then Main.WriteDebugLog(LogLabel & "Unknown value to update :" & aValueToUpdate.Count)
          Return
      End Select
   Endif
domotiga val update.png (19.4 KB) domotiga val update.png thechad, 11/14/2015 02:47 AM
domotiga val update.png (19.1 KB) domotiga val update.png thechad, 11/14/2015 02:56 AM
2455
2456

History

#1 Updated by johanvandyck about 3 years ago

Hi

You didn't mention your error in the text.

#2 Updated by thechad about 3 years ago

johanvandyck wrote:

Hi

You didn't mention your error in the text.

It falls through to the line..
[[Default
If $bDebug Then Main.WriteDebugLog(LogLabel & "Unknown value to update :" & aValueToUpdate.Count)
Return]]

So the error is "Unknown value to update :6" <--- ie. "6" is not a known value field (5 is battery but really should not be now that we can have more than 4 values, it should be value5.

#3 Updated by wwolkers about 3 years ago

quick untested partial fix would be like this:

--- a/DomotiGa3/.src/CGenericIO.class
+++ b/DomotiGa3/.src/CGenericIO.class
@ -363,21 +363,8 @ Private Sub ParseLine(sData As String)

Select aValueToUpdate.Count
Case 1
- Select iValueToUpdate
- Case 1
- Devices.ValueUpdate(iDeviceId, 1, Trim(aValueToUpdate[0]))
- If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value" & iValueToUpdate & " to '" & Trim(aValueToUpdate[0]) & "'")
- Case 2
- Devices.ValueUpdate(iDeviceId, 2, Trim(aValueToUpdate[0]))
- If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value" & iValueToUpdate & " to '" & Trim(aValueToUpdate[0]) & "'")
- Case 3
- Devices.ValueUpdate(iDeviceId, 3, Trim(aValueToUpdate[0]))
- If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value" & iValueToUpdate & " to '" & Trim(aValueToUpdate[0]) & "'")
- Case 4
- Devices.ValueUpdate(iDeviceId, 4, Trim(aValueToUpdate[0]))
- If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value" & iValueToUpdate & " to '" & Trim(aValueToUpdate[0]) & "'")
- Default
- Main.WriteDebugLog(LogLabel & "Unknown value to update :" & iValueToUpdate)
+ Devices.ValueUpdate(iDeviceId, iValueToUpdate, Trim(aValueToUpdate[0]))
+ If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value" & iValueToUpdate & " to '" & Trim(aValueToUpdate[0]) & "'")
End Select
Case 2
Devices.ValueUpdate(iDeviceId, 1, Trim(aValueToUpdate[0]))

#4 Updated by wwolkers about 3 years ago

  • Category set to DomotiGa3
  • Status changed from New to In Progress
  • Assignee set to wwolkers
  • Target version set to 1.0.023
  • % Done changed from 0 to 10

quick untested partial fix would be like this:
(Yes, battery value will be put in value 5 now, perhaps this should be moved to battery?)

diff --git a/DomotiGa3/.src/CGenericIO.class b/DomotiGa3/.src/CGenericIO.class
index 58413e7..d8d7486 100644
--- a/DomotiGa3/.src/CGenericIO.class
+++ b/DomotiGa3/.src/CGenericIO.class
@ -331,8 +331,8 @ End
Private Sub ParseLine(sData As String)

Dim aScan, aValueToUpdate As String[]
- Dim sLine, sAddress, sRegexExpression, sAddressToChange, sValueFields As String
- Dim iDeviceId, iValueToUpdate, iAddressPosition As Integer
+ Dim sLine, sAddress, sRegexExpression, sAddressToChange, sValueFields, sLog As String
+ Dim iDeviceId, iValueToUpdate, iAddressPosition, X As Integer
Dim rRegex As Regexp
If $bDebug Then Main.WriteDebugLog(LogLabel & "Raw Data read '" & sData & "'")
@ -361,51 +361,13 @ Private Sub ParseLine(sData As String)
aValueToUpdate = Split(sValueFields, $sGenericIODelimiter)

- Select aValueToUpdate.Count
- Case 1
- Select iValueToUpdate
- Case 1
- Devices.ValueUpdate(iDeviceId, 1, Trim(aValueToUpdate0))
- If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value" & iValueToUpdate & " to '" & Trim(aValueToUpdate0) & "'")
- Case 2
- Devices.ValueUpdate(iDeviceId, 2, Trim(aValueToUpdate0))
- If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value" & iValueToUpdate & " to '" & Trim(aValueToUpdate0) & "'")
- Case 3
- Devices.ValueUpdate(iDeviceId, 3, Trim(aValueToUpdate0))
- If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value" & iValueToUpdate & " to '" & Trim(aValueToUpdate0) & "'")
- Case 4
- Devices.ValueUpdate(iDeviceId, 4, Trim(aValueToUpdate0))
- If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value" & iValueToUpdate & " to '" & Trim(aValueToUpdate0) & "'")
- Default
- Main.WriteDebugLog(LogLabel & "Unknown value to update :" & iValueToUpdate)
- End Select
- Case 2
- Devices.ValueUpdate(iDeviceId, 1, Trim(aValueToUpdate0))
- Devices.ValueUpdate(iDeviceId, 2, Trim(aValueToUpdate1))
- If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value1:'" & Trim(aValueToUpdate0) & "' Value2:'" & Trim(aValueToUpdate1) & "'")
- Case 3
- Devices.ValueUpdate(iDeviceId, 1, Trim(aValueToUpdate0))
- Devices.ValueUpdate(iDeviceId, 2, Trim(aValueToUpdate1))
- Devices.ValueUpdate(iDeviceId, 3, Trim(aValueToUpdate2))
- If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value1:'" & Trim(aValueToUpdate0) & "' Value2:" & Trim(aValueToUpdate1) & "' Value3:'" & Trim(aValueToUpdate2) & "'")
- Case 4
- Devices.ValueUpdate(iDeviceId, 1, Trim(aValueToUpdate0))
- Devices.ValueUpdate(iDeviceId, 2, Trim(aValueToUpdate1))
- Devices.ValueUpdate(iDeviceId, 3, Trim(aValueToUpdate2))
- Devices.ValueUpdate(iDeviceId, 4, Trim(aValueToUpdate3))
- If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value1:'" & Trim(aValueToUpdate1) & "' Value2:'" & Trim(aValueToUpdate1) & "' Value3:'" & Trim(aValueToUpdate2) & "' Value4:'" & Trim(aValueToUpdate3) & "'")
- Case 5
- Devices.ValueUpdate(iDeviceId, 1, Trim(aValueToUpdate0))
- Devices.ValueUpdate(iDeviceId, 2, Trim(aValueToUpdate1))
- Devices.ValueUpdate(iDeviceId, 3, Trim(aValueToUpdate2))
- Devices.ValueUpdate(iDeviceId, 4, Trim(aValueToUpdate3))
- If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Value1:'" & Trim(aValueToUpdate1) & "' Value2:'" & Trim(aValueToUpdate1) & "' Value3:'" & Trim(aValueToUpdate2) & "' Value4:'" & Trim(aValueToUpdate3) & "'")
- If $bDebug Then Main.WriteDebugLog(LogLabel & "Update Battery:'" & Trim(aValueToUpdate4) & "'")
- Devices.Battery(iDeviceId, Trim(aValueToUpdate4))
- Default
- If $bDebug Then Main.WriteDebugLog(LogLabel & "Unknown value to update :" & aValueToUpdate.Count)
- Return
- End Select
+ If $bDebug Then sLog = LogLabel & "Update"
+ For X = 1 to aValueToUpdate.Count
+ Devices.ValueUpdate(iDeviceId, X, Trim(aValueToUpdate[X-1]))
+ If $bDebug Then sLog &= " Value" & X & ":'" & Trim(aValueToUpdate[X-1]) & "'"
+ Next

If $bDebug Then Main.WriteDebugLog(sLog)
Endif

Catch

#5 Updated by thechad about 3 years ago

2455

wwolkers wrote:

quick untested partial fix would be like this...

<snip>

Thanks wwonkers for putting this up...brain was too full to work it out myself! (a 1 1/2 year old to look after will do that to you!)

I just applied this and am running it now. Looks like it is working fine.

2015/11/14 12:54:06 [GenericIO] Data read ('S28=2381,316,244,778,2948') with regex ('^.*?[=]') applied gives AddressToChange of : 'S28='
2015/11/14 12:54:06 [GenericIO] Updating iDeviceId '123' Address 'S28=' to '2381,316,244,778,2948'

Note:
Attached image was incorrect so using the one in the below post
Values differ slightly due to nupdate between raw data and screen capture.

Could one of the dev's give this a look over and include in the Beta if you agree?

#7 Updated by wwolkers about 3 years ago

Thanks for testing, good to see it works.
Now we need to come up with a way how to define what value is the battery value? or is there none?
Once that is done I'll include it in beta, so that it will be in the next release.

#8 Updated by thechad about 3 years ago

wwolkers wrote:

Thanks for testing, good to see it works.
Now we need to come up with a way how to define what value is the battery value? or is there none?
Once that is done I'll include it in beta, so that it will be in the next release.

I do not think you can define the field that contains the battery value.

I really do not see any need for a separate "battery" value field now that we have more than 4 value fields available.
If we make a defined battery field, my concern is that it is no longer generic.

But as I do not know what people are using this for, i guess there is some risk that by changing it, people who do use the battery in field 5, will now see it appear in "value5" fild instead.

May not be a bid deal?

#9 Updated by Alexie over 2 years ago

any progress guys?

Also available in: Atom PDF