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 @ 716

History | View | Annotate | Download (21.6 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, sX10 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
      sX10 = MakeX10Address(sAddress)
366
      IF Len(sX10) THEN
367
        SELECT CASE UCase(sCmd)
368
          CASE "ON", "OFF", "DIM", "BRIGHT"
369
            SendX10Basic(Main.hRFXComxPL.TXAddress, sX10, LCase(sCmd))
370
          CASE "ALL_LIGHTS_ON", "ALL_LIGHTS_OFF"
371
            SendX10Basic(Main.hRFXComxPL.TXAddress, Left(sX10, 1), LCase(sCmd))
372
        CASE ELSE
373
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for X10!"))
374
        END SELECT
375
      ELSE
376
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sX10 & ("' given for a X10 device!"))
377
      ENDIF
378
      '"HE",
379
    CASE "ARC", "KAKU" ' KAKU, Chacon, HomeEasy, NexaIF CheckX10Address(sAddress) THEN
380
      sX10 = MakeX10Address(sAddress)
381
      IF Len(sX10) THEN
382
        SELECT CASE UCase(sCmd)
383
          CASE "ON", "OFF", "DIM", "BRIGHT"
384
            SendX10Basic(Main.hRFXComxPL.TXAddress, sX10, LCase(sCmd), "arc")
385
          CASE "ALL_LIGHTS_ON", "ALL_LIGHTS_OFF"
386
            SendX10Basic(Main.hRFXComxPL.TXAddress, Left(sX10, 1), LCase(sCmd), "arc")
387
        CASE ELSE
388
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for ARC!"))
389
        END SELECT
390
      ELSE
391
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sX10 & ("' given for a ARC device!"))
392
      ENDIF
393
    CASE "Flamingo" ' Flamingo
394
      sX10 = MakeX10Address(sAddress)
395
      IF Len(sX10) THEN
396
        SELECT CASE UCase(sCmd)
397
          CASE "ON", "OFF"
398
            SendX10Basic(Main.hRFXComxPL.TXAddress, sX10, LCase(sCmd), "flamingo")
399
        CASE ELSE
400
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for Flamingo!"))
401
        END SELECT
402
      ELSE
403
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sX10 & ("' given for a Flamingo device!"))
404
      ENDIF
405
    CASE "Koppla" ' Koppla
406
      sX10 = MakeX10Address(sAddress)
407
      IF Len(sX10) THEN
408
        SELECT CASE UCase(sCmd)
409
          CASE "ON", "OFF", "BRIGHT"
410
            SendX10Basic(Main.hRFXComxPL.TXAddress, sX10, LCase(sCmd), "koppla")
411
          CASE "ALL_LIGHTS_ON", "ALL_LIGHTS_OFF"
412
            SendX10Basic(Main.hRFXComxPL.TXAddress, Left(sX10, 1), LCase(sCmd), "koppla")
413
          CASE "DIM"
414
            sLevel = CInt(iDim / 10)
415
            SendX10Basic(Main.hRFXComxPL.TXAddress, sX10, LCase(sCmd), "koppla", sLevel)
416
          CASE ELSE
417
            Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for Koppla!"))
418
        END SELECT
419
      ELSE
420
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sX10 & ("' given for a Koppla device!"))
421
      ENDIF
422
    CASE "Waveman" ' Waveman
423
      sX10 = MakeX10Address(sAddress)
424
      IF Len(sX10) THEN
425
        SELECT CASE UCase(sCmd)
426
          CASE "ON", "OFF"
427
            SendX10Basic(Main.hRFXComxPL.TXAddress, sX10, LCase(sCmd), "waveman")
428
          CASE "ALL_LIGHTS_ON", "ALL_LIGHTS_OFF"
429
            SendX10Basic(Main.hRFXComxPL.TXAddress, Left(sX10, 1), LCase(sCmd), "waveman")
430
        CASE ELSE
431
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for Waveman!"))
432
        END SELECT
433
      ELSE
434
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sX10 & ("' given for a Waveman device!"))
435
      ENDIF
436
    CASE "HE105" ' HomeEasy Heating HE105
437
      sX10 = MakeX10Address(sAddress)
438
      IF Len(sX10) THEN
439
        SELECT CASE UCase(sCmd)
440
          CASE "ON", "OFF"
441
            SendX10Basic(Main.hRFXComxPL.TXAddress, sX10, LCase(sCmd), "he105")
442
        CASE ELSE
443
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for HE105!"))
444
        END SELECT
445
      ELSE
446
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sX10 & ("' given for a HE105 device!"))
447
      ENDIF
448
    CASE "RTS10" ' Digimax RTS10
449
      sX10 = MakeX10Address(sAddress)
450
      IF Len(sX10) THEN
451
        SELECT CASE UCase(sCmd)
452
          CASE "ON", "OFF", "ALL_LIGHTS_ON", "ALL_LIGHTS_OFF"
453
            SendX10Basic(Main.hRFXComxPL.TXAddress, sX10, LCase(sCmd), "rts10")
454
        CASE ELSE
455
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for RTS10!"))
456
        END SELECT
457
      ELSE
458
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sX10 & ("' given for a RTS10 device!"))
459
      ENDIF
460
    CASE "Harrison" ' Harrison Curtain Control
461
      sX10 = MakeX10Address(sAddress)
462
      IF Len(sX10) THEN
463
        SELECT CASE UCase(sCmd)
464
          CASE "ON", "OFF", "DIM", "BRIGHT", "ALL_LIGHTS_ON", "ALL_LIGHTS_OFF"
465
            SendX10Basic(Main.hRFXComxPL.TXAddress, sX10, LCase(sCmd), "harrison")
466
          CASE ELSE
467
            Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for Harrison!"))
468
        END SELECT
469
      ELSE
470
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sX10 & ("' given for a Harrison device!"))
471
      ENDIF
472
    CASE "AC", "HE" ' AC protocol, for units with program learn button, Chacon, KAKU, Nexa, Proove, Intertechno, Duwi , HEUK, HEEU
473
      aAddress = Split(sAddress, " ")
474
      IF aAddress.Count = 2 AND Left(aAddress[0]) = "0x" THEN
475
        SELECT CASE UCase(sCmd)
476
          CASE "ON", "OFF"
477
            SendACBasic(Main.hRFXComxPL.TXAddress, aAddress[0], aAddress[1], LCase(sCmd), FALSE)
478
          CASE "DIM"
479
            sLevel = CInt(iDim / 10)
480
            SendACBasic(Main.hRFXComxPL.TXAddress, aAddress[0], aAddress[1], "preset", FALSE, sLevel)
481
          CASE ELSE
482
            Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for AC!"))
483
        END SELECT
484
      ELSE
485
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sAddress & ("' given for a AC device!"))
486
      ENDIF
487
    CASE "HEEU" ' AC protocol, for  HEEU
488
      SELECT CASE UCase(sCmd)
489
        CASE "ON", "OFF"
490
          SendACBasic(Main.hRFXComxPL.TXAddress, sAddress, LCase(sCmd), TRUE)
491
        CASE "DIM"
492
          sLevel = CInt(iDim / 10)
493
          SendACBasic(Main.hRFXComxPL.TXAddress, sAddress, "preset", TRUE, sLevel)
494
        CASE ELSE
495
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for AC!"))
496
      END SELECT
497
    CASE "RFXLanIO"
498
      IF Left$(sAddress, 2) = "io" AND IF Right$(sAddress, 1) LIKE "[0-7]" THEN
499
        SELECT UCase(sCmd)
500
          CASE "ON"
501
            SendControlBasic(Main.hRFXComxPL.TXAddress, sAddress, "output", "high")
502
          CASE "OFF"
503
            SendControlBasic(Main.hRFXComxPL.TXAddress, sAddress, "output", "low")
504
          CASE "TOGGLE"
505
            SendControlBasic(Main.hRFXComxPL.TXAddress, sAddress, "output", "toggle")
506
          CASE ELSE
507
            Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for RFXLanIO!"))
508
        END SELECT
509
      ELSE
510
        Main.WriteDebugLog(("[RFXComxPL] Invalid address '") & sAddress & ("' given for a RFXLanIO device!"))
511
      ENDIF
512
    CASE "Mertik"
513
      SELECT UCase(sCmd)
514
        CASE "ON", "OFF", "STEP_UP", "STEP_DOWN", "RUN_UP", "RUN_DOWN", "STOP"
515
          SendControlBasic(Main.hRFXComxPL.TXAddress, sAddress, "mertik", LCase(sCmd))
516
        CASE ELSE
517
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for Mertik!"))
518
      END SELECT
519
    CASE "Ninja"
520
      SELECT UCase(sCmd)
521
        CASE "LEFT", "RIGHT", "UP", "DOWN", "P1", "PROG_P1", "P2", "PROG_P2", "P3", "PROG_P3", "P4", "PROG_P4", "CENTER", "PROG_CENTER", "SWEEP", "PROG_SWEEP"
522
          SendControlBasic(Main.hRFXComxPL.TXAddress, sAddress, "ninja", LCase(sCmd))
523
        CASE ELSE
524
          Main.WriteDebugLog(("[RFXComxPL] The '" & sCmd & "' command is invalid for X10 Ninja!"))
525
      END SELECT
526
    DEFAULT
527
      Main.WriteDebugLog(("[RFXComxPL] The '" & sType & "' protocol is not supported by RFXCom xPL code!"))
528
      RETURN
529
  END SELECT
530
531
END
532
533
PRIVATE SUB MakeX10Address(sAddress AS String, OPTIONAL bAB AS Boolean) AS String
534
535
  IF Len(sAddress) = 3 AND IF Left$(sAddress, 1) LIKE IIf(bAB, "[A-B]", "[A-P]") AND Right$(sAddress, 1) LIKE "[0-9]" THEN
536
    IF Mid$(sAddress, 2, 1) = "0" THEN
537
      RETURN Left$(sAddress, 1) & Right$(sAddress, 1)
538
    ELSE
539
      RETURN sAddress
540
    ENDIF
541
  ELSE
542
    RETURN ""
543
  ENDIF
544
545
END
546
547
' implement properties
548
PRIVATE FUNCTION RXAddress_Read() AS String
549
550
  RETURN sRXAddress
551
552
END
553
554
PRIVATE SUB RXAddress_Write(Value AS String)
555
556
  sRXAddress = Value
557
558
END
559
560
PRIVATE FUNCTION TXAddress_Read() AS String
561
562
  RETURN sTXAddress
563
564
END
565
566
PRIVATE SUB TXAddress_Write(Value AS String)
567
568
  sTXAddress = Value
569
570
END
571
572
PRIVATE FUNCTION GlobalX10_Read() AS Boolean
573
574
  RETURN bGlobalX10
575
576
END
577
578
PRIVATE SUB GlobalX10_Write(Value AS Boolean)
579
580
  bGlobalX10 = Value
581
582
END
583
584
PRIVATE FUNCTION OldAddrFmt_Read() AS Boolean
585
586
  RETURN bOldAddrFmt
587
588
END
589
590
PRIVATE SUB OldAddrFmt_Write(Value AS Boolean)
591
592
  bOldAddrFmt = Value
593
594
END
595
596
PRIVATE FUNCTION RFXComDebug_Read() AS Boolean
597
598
  RETURN bRFXComDebug
599
600
END
601
602
PRIVATE SUB RFXComDebug_Write(Value AS Boolean)
603
604
  bRFXComDebug = Value
605
606
END