The files contained in this repository can be downloaded to your computer using a svn client.
On Linux you simply type the command displayed below.

This URL has Read-Only access.

Statistics
| Revision:

root / trunk / DomotiGaServer / CRFXComxPL.class @ 707

History | View | Annotate | Download (21.4 kB)

1
' Gambas class file
2
3
' Description:
4
' CRFXComxPL.class
5
' Connect to RFXCom xPL interface via xPL protocol.
6
7
' Development Status:
8
' Works, needs some more testing.
9
10
' Credits:
11
' Thanks to Bert Weijenberg of RFXCOM for all the support.
12
13
' DomotiGa - an open source home automation program.
14
' Copyright(C) 2008-2011 Ron Klinkien
15
16
' Read file called COPYING for license details.
17
18
PROPERTY RXAddress AS String
19
PROPERTY TXAddress AS String
20
PROPERTY GlobalX10 AS Boolean
21
PROPERTY OldAddrFmt AS Boolean
22
PROPERTY RFXComDebug AS Boolean
23
24
PRIVATE sRXAddress AS String
25
PRIVATE sTXAddress AS String
26
PRIVATE bGlobalX10 AS Boolean
27
PRIVATE bOldAddrFmt AS Boolean
28
PRIVATE bRFXComDebug AS Boolean
29
30
PRIVATE CONST VENDOR AS String = "domotiga-xpl"
31
32
PUBLIC SUB ProcessxPLMsg(oxPLMsg AS Object)
33
34
  DIM sDevice, sDeviceType, sType, sAddressType, sAddress, sValue, sValue2, sValue3, sValue4, sBattery, sCurrent, sLog, sMsgType AS String
35
  DIM iDeviceId AS Integer
36
  DIM aAddress AS String[]
37
38
  Main.ControlLed("RFXCom", "On")
39
  SELECT oxPLMsg.Schema
40
    CASE "hbeat.app", "hbeat.basic"
41
      IF bRFXComDebug THEN Main.WriteDebugLog("[RFXComxPL] Got heartbeat msg of type '" & oxPLMsg.Schema & " from '" & oxPLMsg.Source & "'")
42
      sValue = Main.hxPL.GetBodyValueFromKey(oxPLMsg, "info")
43
      IF Len(sValue) THEN Main.WriteDebugLog("[RFXComxPL] Got heartbeat msg from RFXCom xPL interface with info '" & sValue & "'")
44
    CASE "log.basic"
45
      sLog = "LOG: " & Main.hxPL.GetBodyValueFromKey(oxPLMsg, "type") & " [" & Main.hxPL.GetBodyValueFromKey(oxPLMsg, "text") & "]" & Main.hxPL.GetBodyValueFromKey(oxPLMsg, "code")
46
    CASE "datetime.basic"
47
      sValue = Main.hxPL.GetBodyValueFromKey(oxPLMsg, "time")
48
      sValue2 = Main.hxPL.GetBodyValueFromKey(oxPLMsg, "date")
49
      sValue3 = Main.hxPL.GetBodyValueFromKey(oxPLMsg, "datetime")
50
      sType = "DT1"
51
    CASE "ac.basic"
52
      sAddress = Main.hxPL.GetBodyValueFromKey(oxPLMsg, "address") & " " & Main.hxPL.GetBodyValueFromKey(oxPLMsg, "unit")
53
      sValue = Main.Caps(Main.hxPL.GetBodyValueFromKey(oxPLMsg, "command"))
54
      sType = "AC"
55
    CASE "x10.basic"
56
      sAddress = ConvertX10Address(Main.hxPL.GetBodyValueFromKey(oxPLMsg, "device"))
57
      sValue = Main.Caps(Main.hxPL.GetBodyValueFromKey(oxPLMsg, "command"))
58
      sType = "X10"
59
    CASE "x10.security"
60
      sDevice = Main.hxPL.GetBodyValueFromKey(oxPLMsg, "device")
61
      sAddress = ConvertAddress("secure " & sDevice, TRUE)
62
      sValue = Main.Caps(Main.hxPL.GetBodyValueFromKey(oxPLMsg, "command"))
63
      sValue3 = Main.Caps(Main.hxPL.GetBodyValueFromKey(oxPLMsg, "delay"))
64
      sAddressType = Main.hxPL.GetBodyValueFromKey(oxPLMsg, "type")
65
      ' cn is a Chacon, Avidsen, NEXA smoke detector
66
      ' mct and mcw are Visonic PowerCode sensors other types are X10
67
      SELECT CASE sAddressType
68
        CASE "cn", "sd18,c018" ' smoke alarm
69
          sAddress = ConvertAddress("smoke " & sDevice, TRUE)
70
          sType = "SMOKE"
71
        CASE "ms10,ms20,ms90,mcw", "mcw", "ms10,mcw", "ms20", "ms90,mcw", "dm10" ' motion sensor
72
          sAddress = ConvertAddress("motion " & sDevice, TRUE)
73
          SELECT CASE sValue
74
            CASE "Normal"
75
              sValue = "No Motion"
76
            CASE "Alert"
77
              sValue = "Motion"
78
          END SELECT
79
          sType = "MOTION"
80
        CASE "ds10,ds90", "ds10,ds90,sd90,mct302,mct550", "ds90", "ds90,mct302,mct550" ' door/window sensor OR sd90 smoke alarm, OR mct550 water sensor
81
          sAddress = ConvertAddress("dws " & sDevice, TRUE)
82
          iDeviceId = Devices.Find(sAddress, Devices.FindInterface("RFXCom xPL"), "DWS")
83
          IF iDeviceId THEN
84
            SELECT Devices.FindDescrForDeviceType(Devices.FindModuleForDevice(iDeviceId))
85
              CASE "Smoke Detector", "Water Sensor" ' sd90, mct550
86
              CASE ELSE ' real door/window sensor
87
                SELECT CASE sValue
88
                  CASE "Normal"
89
                    sValue = "Closed"
90
                  CASE "Alert"
91
                    sValue = "Open"
92
                END SELECT
93
            END SELECT
94
          ENDIF
95
        CASE "sh624,mct234", "sh624", "kr10", "kr10,sd90,mct234", "hp564" ' remote control/keyfob
96
          sAddress = ConvertAddress("remote " & sDevice, TRUE)
97
          sType = "REMOTE"
98
          SELECT CASE sValue
99
            CASE "Arm-away"
100
              sValue = "Arm Away"
101
            CASE "Arm-home"
102
              sValue = "Arm Home"
103
            CASE "Lights-on2"
104
              sValue = "Lights On"
105
          END SELECT
106
      END SELECT
107
      IF sValue3 = "" THEN sValue3 = "Min"
108
      IF Main.hxPL.GetBodyValueFromKey(oxPLMsg, "tamper") = "true" THEN
109
        sValue2 = "Tamper"
110
      ELSE
111
        sValue2 = "Secure"
112
      ENDIF
113
      sBattery = Main.hxPL.GetBodyValueFromKey(oxPLMsg, "low-battery")
114
      IF sBattery = "true" THEN
115
        sBattery = "Low"
116
      ELSE
117
        sBattery = "OK"
118
      ENDIF
119
    CASE "remote.basic"
120
      sDevice = Main.hxPL.GetBodyValueFromKey(oxPLMsg, "device")
121
      sAddress = ConvertAddress(sDevice)
122
      sValue = Main.hxPL.GetBodyValueFromKey(oxPLMsg, "keys")
123
      sType = "REMOTE"
124
    CASE "sensor.basic"
125
      sDevice = Main.hxPL.GetBodyValueFromKey(oxPLMsg, "device")
126
      sAddress = ConvertAddress(sDevice)
127
      aAddress = Split(sDevice, " ")
128
      IF aAddress.Count = 2 THEN
129
        sDeviceType = UCase(aAddress[0])
130
      ELSE
131
        sDeviceType = UCase(sDevice)
132
      ENDIF
133
      sCurrent = Main.hxPL.GetBodyValueFromKey(oxPLMsg, "current")
134
      sMsgType = Main.hxPL.GetBodyValueFromKey(oxPLMsg, "type")
135
      sType = sDeviceType
136
      SELECT sDeviceType
137
        CASE "TH1", "TH2", "TH3", "TH4", "TH5", "TH6", "THB1", "THB2"
138
          IF sMsgType = "temp" THEN sValue = sCurrent
139
          IF sMsgType = "humidity" THEN
140
            sValue2 = sCurrent
141
            sValue3 = Main.Caps(Main.hxPL.GetBodyValueFromKey(oxPLMsg, "description"))
142
          ENDIF
143
          IF sMsgType = "status" THEN sValue3 = sCurrent
144
          IF sMsgType = "pressure" THEN
145
            sValue4 = sCurrent
146
            sValue3 = Main.Caps(Main.hxPL.GetBodyValueFromKey(oxPLMsg, "forecast")) ' to check
147
          ENDIF
148
          IF sMsgType = "battery" THEN sBattery = sCurrent
149
        CASE "UV1", "UV2"
150
          IF sMsgType = "uv" THEN sValue = sCurrent
151
          IF sMsgType = "battery" THEN sBattery = sCurrent
152
          sValue2 = Main.Caps(Main.hxPL.GetBodyValueFromKey(oxPLMsg, "description"))
153
        CASE "RAIN1", "RAIN2"
154
          IF sMsgType = "rainrate" THEN sValue = sCurrent
155
          IF sMsgType = "raintotal" THEN sValue2 = sCurrent
156
          IF sMsgType = "battery" THEN sBattery = sCurrent
157
        CASE "TEMP1", "TEMP2", "TEMP3", "TEMP4"
158
          IF sMsgType = "temp" THEN sValue = sCurrent
159
          IF sMsgType = "battery" THEN sBattery = sCurrent
160
        CASE "WIND1", "WIND2", "WIND3"
161
          IF sMsgType = "average speed" THEN sValue = sCurrent
162
          IF sMsgType = "gust" THEN sValue2 = sCurrent
163
          IF sMsgType = "direction" THEN sValue3 = sCurrent
164
          IF sMsgType = "battery" THEN sBattery = sCurrent
165
        CASE "RFXMETER"
166
          sValue = sCurrent
167
        CASE "RFXSENSOR"
168
          IF sMsgType = "temp" THEN sValue = sCurrent
169
          IF sMsgType = "voltage" THEN sValue2 = sCurrent
170
        CASE "WEIGHT1", "WEIGHT2"
171
          IF sMsgType = "weight" THEN sValue = sCurrent
172
        CASE "ELEC1_1", "ELEC1_2", "ELEC1_3"
173
          IF sMsgType = "current" THEN
174
            SELECT Right(sDeviceType, 1)
175
              CASE "1"
176
                sValue = sCurrent
177
              CASE "2"
178
                sValue2 = sCurrent
179
              CASE "3"
180
                sValue3 = sCurrent
181
            END SELECT
182
          ENDIF
183
        CASE "ELEC2"
184
          IF sMsgType = "power" THEN sValue = sCurrent
185
          IF sMsgType = "energy" THEN sValue2 = sCurrent
186
        CASE "DIGIMAX"
187
          IF sMsgType = "temp" THEN sValue = sCurrent
188
          IF sMsgType = "setpoint" THEN sValue2 = sCurrent
189
          IF sMsgType = "demand" THEN sValue3 = sCurrent
190
        CASE "IO0", "IO1", "IO2", "IO3", "IO4", "IO5", "IO6", "IO7"
191
          sAddress = sDevice
192
          SELECT sCurrent
193
            CASE "low"
194
              sValue = "Off"
195
            CASE "high"
196
              sValue = "On"
197
          END SELECT
198
        CASE ELSE
199
          IF bRFXComDebug THEN Main.WriteDebugLog(("[RFXComxPL] Received unsupported devicetype '" & sDeviceType & "'"))
200
    END SELECT
201
  CASE ELSE
202
    IF bRFXComDebug THEN Main.WriteDebugLog(("[RFXComxPL] Received unsupported message schema '" & oxPLMsg.Schema & "'"))
203
  END SELECT
204
205
  IF oxPLMsg.Schema = "log.basic" THEN
206
    IF bRFXComDebug THEN Main.WriteDebugLog("[RFXComxPL] " & sLog)
207
  ELSE IF oxPLMsg.Schema = "hbeat.app" OR IF oxPLMsg.Schema = "hbeat.basic" THEN
208
    IF bRFXComDebug THEN Main.WriteDebugLog(("[xPL] Got heartbeat msg of type '" & oxPLMsg.Schema & "' from '" & oxPLMsg.Source & "'"))
209
  ELSE
210
    ' find device id
211
    iDeviceId = Devices.Find(sAddress, Devices.FindInterface("RFXCom xPL"), sType)
212
    ' update device
213
    IF iDeviceId THEN
214
      Devices.ValueUpdate(iDeviceId, sValue, sValue2, sValue3, sValue4)
215
      IF sBattery THEN Devices.Battery(iDeviceId, sBattery)
216
    ENDIF
217
    IF bRFXComDebug THEN Main.WriteDebugLog("[RFXComxPL] Device with address '" & sAddress & "' reported" & IIf(sValue, " value1 = '" & sValue & "'", "") & IIf(sValue2, " value2 = '" & sValue2 & "'", "") & IIf(sValue3, " value3 = '" & sValue3 & "'", "") & IIf(sValue4, " value4 = '" & sValue4 & "'", "") & IIf(sBattery, " battery Level = '" & sBattery & "'", ""))
218
  ENDIF
219
  Main.ControlLed("RFXCom", "Off")
220
  oxPLMsg = NULL
221
222
END
223
224
' convert A1 to A01, leave A10+ alone
225
PRIVATE SUB ConvertX10Address(sAddress AS String) AS String
226
227
  IF Len(sAddress) = 3 THEN
228
    RETURN sAddress
229
  ELSE
230
    RETURN Left(sAddress, 1) & Format(Right(sAddress, 1), "0#")
231
  ENDIF
232
233
END
234
235
PRIVATE SUB ConvertAddress(sAddr AS String, OPTIONAL bNotHex AS Boolean) AS String
236
237
  DIM aAddress AS String[]
238
239
  IF bOldAddrFmt THEN
240
    aAddress = Split(sAddr, " ")
241
    IF bNotHex = FALSE THEN
242
      TRY RETURN UCase(aAddress[0] & "[" & Val("&H" & Replace(aAddress[1], "0x", "") & "&") & "]")
243
      IF ERROR THEN RETURN sAddr
244
    ELSE
245
      TRY RETURN UCase(aAddress[0] & "[" & Replace(aAddress[1], "0x", "") & "]")
246
      IF ERROR THEN RETURN sAddr
247
    ENDIF
248
  ELSE
249
    RETURN sAddr
250
  ENDIF
251
252
END
253
254
PUBLIC SUB SendX10Basic(sTarget AS String, sAddress AS String, sCommand AS String, OPTIONAL sProtocol AS String, OPTIONAL sLevel AS String)
255
256
  DIM sCmndMsg AS String = "xpl-cmnd\n{\nhop=1\nsource=" & VENDOR & "." & System.Host & "\ntarget=" & IIf(Len(sTarget), sTarget, "*") & "\n}\n"
257
  DIM sX10BasicMsg AS String = "x10.basic\n{\ndevice=" & sAddress & "\ncommand=" & sCommand
258
259
  IF sLevel THEN sX10BasicMsg &= "\nlevel=" & sLevel
260
  IF sProtocol THEN sX10BasicMsg &= "\nprotocol=" & sProtocol ' default is X10
261
  sX10BasicMsg &= "\n}\n"
262
263
  ' xpl-cmnd
264
  ' {
265
  '   hop=1
266
  '   source=xpl-prog.house
267
  '   target=*
268
  ' }
269
  ' x10.basic
270
  ' {
271
  ' device=<house code[device code]>
272
  ' command=on|off|dim|bright|all_lights_on|all_lights_off
273
  ' [level=(0-100)]
274
  ' [protocol=arc|flamingo|koppla|waveman|harrison|he105|rts10]
275
  ' }
276
277
  Main.hxPL.SendMessage(sCmndMsg & sX10BasicMsg)
278
279
END
280
281
PUBLIC SUB SendControlBasic(sTarget AS String, sDevice AS String, sType AS String, sCurrent AS String)
282
283
  DIM sCmndMsg AS String = "xpl-cmnd\n{\nhop=1\nsource=" & VENDOR & "." & System.Host & "\ntarget=" & IIf(Len(sTarget), sTarget, "*") & "\n}\n"
284
  DIM sControlBasicMsg AS String = "control.basic\n{\ndevice=" & sDevice & "\ntype=" & sType & "\ncurrent=" & sCurrent & "\n}\n"
285
286
  ' xpl-cmnd
287
  ' {
288
  '   hop=1
289
  '   source=xpl-prog.house
290
  '   target=*
291
  ' }
292
  ' control.basic
293
  ' {
294
  ' device=(io0-io7)
295
  ' type=output
296
  ' current=high|low|toggle
297
  ' }
298
299
  Main.hxPL.SendMessage(sCmndMsg & sControlBasicMsg)
300
301
END
302
303
PUBLIC SUB SendACBasic(sTarget AS String, sAddress AS String, sUnit AS String, sCommand AS String, bEU AS Boolean, OPTIONAL sLevel AS String)
304
305
  DIM sCmndMsg AS String = "xpl-cmnd\n{\nhop=1\nsource=" & VENDOR & "." & System.Host & "\ntarget=" & IIf(Len(sTarget), sTarget, "*") & "\n}\n"
306
  DIM sACBasicMsg AS String = "ac.basic\n{\naddress=" & sAddress & "\nunit=" & sUnit & "\ncommand=" & sCommand
307
308
  IF bEU THEN sACBasicMsg &= "\neu=true"
309
  IF sLevel THEN sACBasicMsg &= "\nlevel=" & sLevel
310
311
  sACBasicMsg &= "\n}\n"
312
313
  ' xpl-cmnd
314
  ' {
315
  '   hop=1
316
  '   source=xpl-prog.house
317
  '   target=*
318
  ' }
319
  ' ac.basic
320
  ' {
321
  ' address=(0x1-0x3ffffff)
322
  ' unit=(0-15)|group
323
  ' command=on|off|preset
324
  ' [level=(0-15)]
325
  ' }
326
327
  Main.hxPL.SendMessage(sCmndMsg & sACBasicMsg)
328
329
END
330
331
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
332
' disconnect from the host
333
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
334
PUBLIC FUNCTION Disconnect() AS Boolean
335
336
  ' all ok
337
  RETURN TRUE
338
339
CATCH ' some errors
340
  Main.WriteLog(("RFXCom Error: ") & ERROR.Text)
341
  RETURN FALSE
342
343
END
344
345
PUBLIC SUB SendCommand(sAddress AS String, sCmd AS String)
346
347
  DIM iDeviceId, iDim AS Integer
348
  DIM sType, sCommand, sLevel AS String
349
  DIM aAddress AS String[]
350
351
  iDeviceId = Devices.Find(sAddress, Devices.FindInterface("RFXCom xPL"))
352
  IF iDeviceId THEN
353
    sType = Devices.FindTypeForDevice(iDeviceId)
354
  ELSE
355
    RETURN
356
  ENDIF
357
358
  IF InStr(sCmd, "DIM") THEN
359
    iDim = Val(Replace(sCmd, "DIM ", ""))
360
    sCmd = "DIM"
361
  ENDIF
362
363
  SELECT sType
364
    CASE "X10" ' X10
365
      IF CheckX10Address(sAddress) THEN
366
        SELECT CASE UCase(sCmd)
367
          CASE "ON", "OFF", "DIM", "BRIGHT"
368
            SendX10Basic(Main.hRFXComxPL.TXAddress, sAddress, LCase(sCmd))
369
          CASE "ALL_LIGHTS_ON", "ALL_LIGHTS_OFF"
370
            SendX10Basic(Main.hRFXComxPL.TXAddress, Left(sAddress, 1), LCase(sCmd))
371
        CASE ELSE
372
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for X10!"))
373
        END SELECT
374
      ELSE
375
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sAddress & ("' given for a X10 device!"))
376
      ENDIF
377
      '"HE",
378
    CASE "ARC", "KAKU" ' KAKU, Chacon, HomeEasy, NexaIF CheckX10Address(sAddress) THEN
379
      IF CheckX10Address(sAddress) THEN
380
        SELECT CASE UCase(sCmd)
381
          CASE "ON", "OFF", "DIM", "BRIGHT"
382
            SendX10Basic(Main.hRFXComxPL.TXAddress, sAddress, LCase(sCmd), "arc")
383
          CASE "ALL_LIGHTS_ON", "ALL_LIGHTS_OFF"
384
            SendX10Basic(Main.hRFXComxPL.TXAddress, Left(sAddress, 1), LCase(sCmd), "arc")
385
        CASE ELSE
386
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for ARC!"))
387
        END SELECT
388
      ELSE
389
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sAddress & ("' given for a ARC device!"))
390
      ENDIF
391
    CASE "Flamingo" ' Flamingo
392
      IF CheckX10Address(sAddress) THEN
393
        SELECT CASE UCase(sCmd)
394
          CASE "ON", "OFF"
395
            SendX10Basic(Main.hRFXComxPL.TXAddress, sAddress, LCase(sCmd), "flamingo")
396
        CASE ELSE
397
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for Flamingo!"))
398
        END SELECT
399
      ELSE
400
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sAddress & ("' given for a Flamingo device!"))
401
      ENDIF
402
    CASE "Koppla" ' Koppla
403
      IF CheckX10Address(sAddress) THEN
404
        SELECT CASE UCase(sCmd)
405
          CASE "ON", "OFF", "BRIGHT"
406
            SendX10Basic(Main.hRFXComxPL.TXAddress, sAddress, LCase(sCmd), "koppla")
407
          CASE "ALL_LIGHTS_ON", "ALL_LIGHTS_OFF"
408
            SendX10Basic(Main.hRFXComxPL.TXAddress, Left(sAddress, 1), LCase(sCmd), "koppla")
409
          CASE "DIM"
410
            sLevel = CInt(iDim / 10)
411
            SendX10Basic(Main.hRFXComxPL.TXAddress, sAddress, LCase(sCmd), "koppla", sLevel)
412
          CASE ELSE
413
            Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for Koppla!"))
414
        END SELECT
415
      ELSE
416
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sAddress & ("' given for a Koppla device!"))
417
      ENDIF
418
    CASE "Waveman" ' Waveman
419
      IF CheckX10Address(sAddress) THEN
420
        SELECT CASE UCase(sCmd)
421
          CASE "ON", "OFF"
422
            SendX10Basic(Main.hRFXComxPL.TXAddress, sAddress, LCase(sCmd), "waveman")
423
          CASE "ALL_LIGHTS_ON", "ALL_LIGHTS_OFF"
424
            SendX10Basic(Main.hRFXComxPL.TXAddress, Left(sAddress, 1), LCase(sCmd), "waveman")
425
        CASE ELSE
426
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for Waveman!"))
427
        END SELECT
428
      ELSE
429
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sAddress & ("' given for a Waveman device!"))
430
      ENDIF
431
    CASE "HE105" ' HomeEasy Heating HE105
432
      IF CheckX10Address(sAddress, TRUE) THEN
433
        SELECT CASE UCase(sCmd)
434
          CASE "ON", "OFF"
435
            SendX10Basic(Main.hRFXComxPL.TXAddress, sAddress, LCase(sCmd), "he105")
436
        CASE ELSE
437
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for HE105!"))
438
        END SELECT
439
      ELSE
440
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sAddress & ("' given for a HE105 device!"))
441
      ENDIF
442
    CASE "RTS10" ' Digimax RTS10
443
      IF CheckX10Address(sAddress) THEN
444
        SELECT CASE UCase(sCmd)
445
          CASE "ON", "OFF", "ALL_LIGHTS_ON", "ALL_LIGHTS_OFF"
446
            SendX10Basic(Main.hRFXComxPL.TXAddress, sAddress, LCase(sCmd), "rts10")
447
        CASE ELSE
448
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for RTS10!"))
449
        END SELECT
450
      ELSE
451
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sAddress & ("' given for a RTS10 device!"))
452
      ENDIF
453
    CASE "Harrison" ' Harrison Curtain Control
454
      IF CheckX10Address(sAddress) THEN
455
        SELECT CASE UCase(sCmd)
456
          CASE "ON", "OFF", "DIM", "BRIGHT", "ALL_LIGHTS_ON", "ALL_LIGHTS_OFF"
457
            SendX10Basic(Main.hRFXComxPL.TXAddress, sAddress, LCase(sCmd), "harrison")
458
          CASE ELSE
459
            Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for Harrison!"))
460
        END SELECT
461
      ELSE
462
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sAddress & ("' given for a Harrison device!"))
463
      ENDIF
464
    CASE "AC", "HE" ' AC protocol, for units with program learn button, Chacon, KAKU, Nexa, Proove, Intertechno, Duwi , HEUK, HEEU
465
      aAddress = Split(sAddress, " ")
466
      IF aAddress.Count = 2 AND Left(aAddress[0]) = "0x" THEN
467
        SELECT CASE UCase(sCmd)
468
          CASE "ON", "OFF"
469
            SendACBasic(Main.hRFXComxPL.TXAddress, aAddress[0], aAddress[1], LCase(sCmd), FALSE)
470
          CASE "DIM"
471
            sLevel = CInt(iDim / 10)
472
            SendACBasic(Main.hRFXComxPL.TXAddress, aAddress[0], aAddress[1], "preset", FALSE, sLevel)
473
          CASE ELSE
474
            Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for AC!"))
475
        END SELECT
476
      ELSE
477
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sAddress & ("' given for a AC device!"))
478
      ENDIF
479
    CASE "HEEU" ' AC protocol, for  HEEU
480
      SELECT CASE UCase(sCmd)
481
        CASE "ON", "OFF"
482
          SendACBasic(Main.hRFXComxPL.TXAddress, sAddress, LCase(sCmd), TRUE)
483
        CASE "DIM"
484
          sLevel = CInt(iDim / 10)
485
          SendACBasic(Main.hRFXComxPL.TXAddress, sAddress, "preset", TRUE, sLevel)
486
        CASE ELSE
487
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for AC!"))
488
      END SELECT
489
    CASE "RFXLanIO"
490
      IF Left$(sAddress, 2) = "io" AND IF Right$(sAddress, 1) LIKE "[0-7]" THEN
491
        SELECT UCase(sCmd)
492
          CASE "ON"
493
            SendControlBasic(Main.hRFXComxPL.TXAddress, sAddress, "output", "high")
494
          CASE "OFF"
495
            SendControlBasic(Main.hRFXComxPL.TXAddress, sAddress, "output", "low")
496
          CASE "TOGGLE"
497
            SendControlBasic(Main.hRFXComxPL.TXAddress, sAddress, "output", "toggle")
498
          CASE ELSE
499
            Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for RFXLanIO!"))
500
        END SELECT
501
      ELSE
502
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sAddress & ("' given for a RFXLanIO device!"))
503
      ENDIF
504
    CASE "Mertik"
505
      SELECT UCase(sCmd)
506
        CASE "ON", "OFF", "STEP_UP", "STEP_DOWN", "RUN_UP", "RUN_DOWN", "STOP"
507
          SendControlBasic(Main.hRFXComxPL.TXAddress, sAddress, "mertik", LCase(sCmd))
508
        CASE ELSE
509
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for Mertik!"))
510
      END SELECT
511
    CASE "Ninja"
512
      SELECT UCase(sCmd)
513
        CASE "LEFT", "RIGHT", "UP", "DOWN", "P1", "PROG_P1", "P2", "PROG_P2", "P3", "PROG_P3", "P4", "PROG_P4", "CENTER", "PROG_CENTER", "SWEEP", "PROG_SWEEP"
514
          SendControlBasic(Main.hRFXComxPL.TXAddress, sAddress, "ninja", LCase(sCmd))
515
        CASE ELSE
516
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for X10 Ninja!"))
517
      END SELECT
518
    DEFAULT
519
      Main.WriteDebugLog(("[RFXComxPL] The '" & sType & "' protocol is not supported by RFXCom xPL code!"))
520
      RETURN
521
  END SELECT
522
523
END
524
525
PRIVATE SUB CheckX10Address(sAddress AS String, OPTIONAL bAB AS Boolean) AS Boolean
526
527
  IF Len(sAddress) = 3 AND IF Left$(sAddress, 1) LIKE IIf(bAB, "[A-B]", "[A-P]") AND Right$(sAddress, 1) LIKE "[0-9]" THEN
528
    RETURN TRUE
529
  ELSE
530
    RETURN FALSE
531
  ENDIF
532
533
END
534
535
' implement properties
536
PRIVATE FUNCTION RXAddress_Read() AS String
537
538
  RETURN sRXAddress
539
540
END
541
542
PRIVATE SUB RXAddress_Write(Value AS String)
543
544
  sRXAddress = Value
545
546
END
547
548
PRIVATE FUNCTION TXAddress_Read() AS String
549
550
  RETURN sTXAddress
551
552
END
553
554
PRIVATE SUB TXAddress_Write(Value AS String)
555
556
  sTXAddress = Value
557
558
END
559
560
PRIVATE FUNCTION GlobalX10_Read() AS Boolean
561
562
  RETURN bGlobalX10
563
564
END
565
566
PRIVATE SUB GlobalX10_Write(Value AS Boolean)
567
568
  bGlobalX10 = Value
569
570
END
571
572
PRIVATE FUNCTION OldAddrFmt_Read() AS Boolean
573
574
  RETURN bOldAddrFmt
575
576
END
577
578
PRIVATE SUB OldAddrFmt_Write(Value AS Boolean)
579
580
  bOldAddrFmt = Value
581
582
END
583
584
PRIVATE FUNCTION RFXComDebug_Read() AS Boolean
585
586
  RETURN bRFXComDebug
587
588
END
589
590
PRIVATE SUB RFXComDebug_Write(Value AS Boolean)
591
592
  bRFXComDebug = Value
593
594
END