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.
root / trunk / DomotiGa / CDSC.class @ 788
History | View | Annotate | Download (20.1 kB)
| 1 | ' Gambas class file |
|---|---|
| 2 | |
| 3 | ' Description: |
| 4 | ' CDSC.class |
| 5 | ' Support for DSC Security Panels. |
| 6 | |
| 7 | ' Development Status: |
| 8 | ' Beta. Needs Testing. |
| 9 | |
| 10 | ' DomotiGa - an open source home automation program. |
| 11 | ' Copyright(C) 2008-2010 Ron Klinkien |
| 12 | |
| 13 | ' This module is written by and Copyright(C) 2009-2010 Timo Sariwating |
| 14 | |
| 15 | ' Read file called COPYING for license details. |
| 16 | |
| 17 | PROPERTY Port AS String |
| 18 | PROPERTY Baud AS String |
| 19 | PROPERTY DSCDebug AS Boolean |
| 20 | |
| 21 | PRIVATE sPort AS String |
| 22 | PRIVATE sBaud AS String |
| 23 | PRIVATE bDSCDebug AS Boolean |
| 24 | |
| 25 | PUBLIC hDSC AS NEW SerialPort |
| 26 | PUBLIC tDSC AS NEW Timer |
| 27 | |
| 28 | PUBLIC sBuffer AS String |
| 29 | |
| 30 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 31 | ' open serial port |
| 32 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 33 | PUBLIC FUNCTION Connect() AS Boolean |
| 34 | |
| 35 | ' try to close the port |
| 36 | TRY hDSC.Close |
| 37 | |
| 38 | ' get a new one |
| 39 | hDSC = NEW Serialport AS "DSC" |
| 40 | |
| 41 | WITH hDSC |
| 42 | .PortName = sPort |
| 43 | .Speed = sBaud |
| 44 | .Parity = 0 |
| 45 | .DataBits = 8 |
| 46 | .StopBits = 1 |
| 47 | .EndOfLine = 1 |
| 48 | .Open() |
| 49 | END WITH |
| 50 | |
| 51 | DSC_Descriptive_Arming() |
| 52 | DSC_System_Time() |
| 53 | DSC_LCDText() |
| 54 | TX("001")
|
| 55 | |
| 56 | ' start poll timer for DSC status LED |
| 57 | tDSC = NEW Timer AS "tDSCLED" |
| 58 | tDSC.Delay = 250 |
| 59 | tDSC.Stop |
| 60 | |
| 61 | ' all ok |
| 62 | RETURN TRUE |
| 63 | |
| 64 | CATCH ' some errors |
| 65 | Main.WriteLog(("DSC Error: ") & ERROR.Text)
|
| 66 | RETURN FALSE |
| 67 | |
| 68 | END |
| 69 | |
| 70 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 71 | ' Enable Descriptive Arming |
| 72 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 73 | PUBLIC SUB DSC_Descriptive_Arming() |
| 74 | |
| 75 | TX("0501")
|
| 76 | Main.WriteDebugLog(("[DSC] Descriptive Arming Enabled"))
|
| 77 | |
| 78 | END |
| 79 | |
| 80 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 81 | ' Send System Time to DSC Panel |
| 82 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 83 | PUBLIC SUB DSC_System_Time() |
| 84 | |
| 85 | DIM sTime_Now AS String |
| 86 | |
| 87 | sTime_Now = "010" & Format$(Now, "hhnnmmddyy") |
| 88 | TX(sTime_Now) |
| 89 | Main.WriteDebugLog(("[DSC] System time set to ") & Now & (" on alarm system"))
|
| 90 | |
| 91 | END |
| 92 | |
| 93 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 94 | ' Read Serial Port |
| 95 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 96 | PUBLIC SUB DSC_Read() |
| 97 | |
| 98 | DIM sData AS String |
| 99 | |
| 100 | READ #hDSC, sData, 1 |
| 101 | IF sData = Chr(10) THEN ' buffer until newline then parse |
| 102 | IF Len(sBuffer) > 1 THEN RX(sBuffer) |
| 103 | sBuffer = NULL |
| 104 | ELSE |
| 105 | sBuffer &= sData |
| 106 | END IF |
| 107 | |
| 108 | END |
| 109 | |
| 110 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 111 | ' RX - Process the Received Data |
| 112 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 113 | PUBLIC SUB RX(sStr AS String) |
| 114 | |
| 115 | DIM sString, sCommand, sData, sChecksum, sCheckSumCalculating, sCheckSumCalculated AS String |
| 116 | DIM iCheckSumFloat, iInd, iDeviceId, iVirtDeviceId AS Integer |
| 117 | |
| 118 | ' read rs-232 datastream |
| 119 | sCommand = Left$(sStr, 3) |
| 120 | sData = Left$(Mid$(sStr, 4, Len(sStr)), -3) |
| 121 | sChecksum = Right$(sStr, 3) |
| 122 | |
| 123 | ' calculate checksum |
| 124 | FOR iInd = 1 TO Len(sCommand) |
| 125 | sCheckSumCalculating = Asc(Mid$(sCommand, iInd, 1)) |
| 126 | iCheckSumFloat = iCheckSumFloat + sCheckSumCalculating |
| 127 | NEXT |
| 128 | FOR iInd = 1 TO Len(sData) |
| 129 | sCheckSumCalculating = Asc(Mid$(sData, iInd, 1)) |
| 130 | iCheckSumFloat = iCheckSumFloat + sCheckSumCalculating |
| 131 | NEXT |
| 132 | sCheckSumCalculated = Right$(Hex$(iCheckSumFloat), 2) |
| 133 | |
| 134 | ' process if checksum is ok |
| 135 | IF Val(sChecksum) = Val(sCheckSumCalculated) |
| 136 | |
| 137 | iVirtDeviceId = Devices.FindVirtualDeviceID("securitysystem")
|
| 138 | |
| 139 | SELECT CASE sCommand |
| 140 | CASE 500 |
| 141 | Main.WriteLog(("[DSC] Command Acknowledge ") & sData)
|
| 142 | CASE 501 |
| 143 | Main.WriteLog(("[DSC] Bad Checksum [501]"))
|
| 144 | CASE 502 |
| 145 | Error_Code(sData) |
| 146 | CASE 550 |
| 147 | Main.WriteDebugLog(("[DSC] System Time ") & sData)
|
| 148 | CASE 561 |
| 149 | Main.WriteDebugLog(("[DSC] Indoor Temperature ") & sData)
|
| 150 | CASE 562 |
| 151 | Main.WriteDebugLog(("[DSC] Outdoor Temperature ") & sData)
|
| 152 | CASE 601 |
| 153 | Main.WriteLog(("[DSC] Partition ") & Left$(sData, 1) & (" Zone ") & Right$(sData, -1) & (" !ALARM!"))
|
| 154 | iDeviceId = Devices.Find(Right$(sData, -1), Devices.FindInterface("DSC5401 Interface"), "DSC DWS")
|
| 155 | IF iDeviceId THEN |
| 156 | TRY Main.hDB.Exec("UPDATE security SET lcd_line1 = &1, lcd_line2 = &2 WHERE id = 0", "System in Alarm <>", Devices.FindNameForDevice(iDeviceId))
|
| 157 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "!ALARM!", "", Devices.FindNameForDevice(iDeviceId), "") |
| 158 | IF Main.bSMSEnabled THEN Main.SendSMS(("DomotiGa: Security System is in Alarm! Zone: " & Devices.FindNameForDevice(iDeviceId)), Main.sSMSContact)
|
| 159 | ELSE |
| 160 | TRY Main.hDB.Exec("UPDATE security SET lcd_line1 = &1, lcd_line2 = &2 WHERE id = 0", "System in Alarm <>", ("Zone " & Right$(sData, -1)))
|
| 161 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "!ALARM!", "", "Zone " & Right$(sData, -1), "") |
| 162 | IF Main.bSMSEnabled THEN Main.SendSMS(("DomotiGa: Security System is in Alarm! Zone: " & Right$(sData, -1)), Main.sSMSContact)
|
| 163 | END IF |
| 164 | Main.BroadcastEvent("[SecurityUpdate]")
|
| 165 | CASE 602 |
| 166 | Main.WriteLog(("[DSC] Partition ") & Left$(sData, 1) & (" Zone ") & Right$(sData, -1) & (" Alarm Restored"))
|
| 167 | CASE 603 |
| 168 | iDeviceId = Devices.Find(Right$(sData, -1), Devices.FindInterface("DSC5401 Interface"), "DSC DWS")
|
| 169 | IF iDeviceId THEN |
| 170 | Main.WriteLog(("[DSC] Partition ") & Left$(sData, 1) & (" Zone ") & Right$(sData, -1) & " " & Devices.FindNameForDevice(iDeviceId) & (" Tamper"))
|
| 171 | Devices.ValueUpdate(iDeviceId, "", "Tamper", "", "") |
| 172 | END IF |
| 173 | CASE 604 |
| 174 | iDeviceId = Devices.Find(Right$(sData, -1), Devices.FindInterface("DSC5401 Interface"), "DSC DWS")
|
| 175 | IF iDeviceId THEN |
| 176 | Main.WriteDebugLog(("[DSC] Partition ") & Left$(sData, 1) & (" Zone ") & Right$(sData, -1) & " " & Devices.FindNameForDevice(iDeviceId) & (" Tamper Restored"))
|
| 177 | Devices.ValueUpdate(iDeviceId, "", "Secure", "", "") |
| 178 | END IF |
| 179 | CASE 605 |
| 180 | Main.WriteDebugLog(("[DSC] Zone ") & sData & (" Fault"))
|
| 181 | CASE 606 |
| 182 | Main.WriteDebugLog(("[DSC] Zone ") & sData & (" Fault Restored"))
|
| 183 | CASE 609 |
| 184 | iDeviceId = Devices.Find(sData, Devices.FindInterface("DSC5401 Interface"), "DSC PIR")
|
| 185 | IF bDSCDebug AND iDeviceId THEN |
| 186 | Main.WriteDebugLog(("[DSC] Zone ") & sData & " " & Devices.FindNameForDevice(iDeviceId) & (" Open"))
|
| 187 | END IF |
| 188 | IF iDeviceId THEN |
| 189 | Devices.ValueUpdate(iDeviceId, "Motion", "", "", "") |
| 190 | END IF |
| 191 | CASE 610 |
| 192 | iDeviceId = Devices.Find(sData, Devices.FindInterface("DSC5401 Interface"), "DSC PIR")
|
| 193 | IF bDSCDebug AND iDeviceId THEN |
| 194 | Main.WriteDebugLog(("[DSC] Zone ") & sData & " " & Devices.FindNameForDevice(iDeviceId) & (" Restored"))
|
| 195 | END IF |
| 196 | IF iDeviceId THEN |
| 197 | Devices.ValueUpdate(iDeviceId, "No Motion", "", "", "") |
| 198 | END IF |
| 199 | CASE 620 |
| 200 | IF bDSCDebug THEN |
| 201 | Main.WriteDebugLog(("[DSC] Duress Alarm ") & sData)
|
| 202 | END IF |
| 203 | CASE 621 |
| 204 | Main.WriteLog(("[DSC] Fire Alarm Key Activated"))
|
| 205 | CASE 622 |
| 206 | Main.WriteDebugLog(("[DSC] Fire Alarm Key Restored"))
|
| 207 | CASE 623 |
| 208 | Main.WriteLog(("[DSC] Key Alarm Key Activated"))
|
| 209 | CASE 624 |
| 210 | Main.WriteDebugLog(("[DSC] Key Alarm Restored"))
|
| 211 | CASE 625 |
| 212 | Main.WriteLog(("[DSC] Panic Key Alarm Activated"))
|
| 213 | CASE 626 |
| 214 | Main.WriteDebugLog(("[DSC] Panel Key Alarm Restored"))
|
| 215 | CASE 631 |
| 216 | Main.WriteDebugLog(("[DSC] 2-Wire Smoke Alarm Activated"))
|
| 217 | iDeviceId = Devices.Find(sData, Devices.FindInterface("DSC5401 Interface"), "DSC SMOKE")
|
| 218 | IF iDeviceId THEN |
| 219 | Devices.ValueUpdate(iDeviceId, "Panic", "", "", "") |
| 220 | END IF |
| 221 | CASE 632 |
| 222 | Main.WriteDebugLog(("[DSC] 2-Wire Smoke Alarm Restored"))
|
| 223 | iDeviceId = Devices.Find(sData, Devices.FindInterface("DSC5401 Interface"), "DSC SMOKE")
|
| 224 | IF iDeviceId THEN |
| 225 | Devices.ValueUpdate(iDeviceId, "Normal", "", "", "") |
| 226 | END IF |
| 227 | CASE 650 |
| 228 | IF bDSCDebug THEN |
| 229 | Main.WriteDebugLog("[DSC] Partition " & sData & " Ready")
|
| 230 | END IF |
| 231 | TRY Main.hDB.Exec("UPDATE security SET ready = TRUE WHERE id = 0")
|
| 232 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "Ready", "", "") |
| 233 | Main.BroadcastEvent("[SecurityUpdate]")
|
| 234 | CASE 651 |
| 235 | IF bDSCDebug THEN |
| 236 | Main.WriteDebugLog(("[DSC] Partition ") & sData & (" Not Ready"))
|
| 237 | END IF |
| 238 | TRY Main.hDB.Exec("UPDATE security SET ready = FALSE WHERE id = 0")
|
| 239 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "Not Ready", "", "") |
| 240 | Main.BroadcastEvent("[SecurityUpdate]")
|
| 241 | CASE 652 |
| 242 | TRY Main.hDB.Exec("UPDATE security SET ready = FALSE, armed = TRUE WHERE id = 0")
|
| 243 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", " ", "", "") |
| 244 | SELECT CASE Right$(sData) |
| 245 | CASE 0 |
| 246 | Main.WriteLog(("[DSC] Partition ") & Left$(sData) & (" Armed Away"))
|
| 247 | TRY Main.hDB.Exec("UPDATE security SET lcd_line1 = &1, lcd_line2 = &2 WHERE id = 0", "System Armed", "in Away Mode <>")
|
| 248 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "Armed Away", "", "", "") |
| 249 | Main.BroadcastEvent("[SecurityUpdate]")
|
| 250 | CASE 1 |
| 251 | Main.WriteLog(("[DSC] Partition ") & Left$(sData) & (" Armed Stay"))
|
| 252 | TRY Main.hDB.Exec("UPDATE security SET lcd_line1 = &1, lcd_line2 = &2 WHERE id = 0", "System Armed", "in Stay Mode <>")
|
| 253 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "Armed Stay", "", "", "") |
| 254 | Main.BroadcastEvent("[SecurityUpdate]")
|
| 255 | CASE 2 |
| 256 | Main.WriteLog(("[DSC] Partition ") & Left$(sData) & (" Armed Zero Entry Away"))
|
| 257 | TRY Main.hDB.Exec("UPDATE security SET lcd_line1 = &1, lcd_line2 = &2 WHERE id = 0", "System Armed", "in Zero Entry Away Mode <>")
|
| 258 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "Armed Zero Entry Away", "", "", "") |
| 259 | Main.BroadcastEvent("[SecurityUpdate]")
|
| 260 | CASE 3 |
| 261 | Main.WriteLog(("[DSC] Partition ") & Left$(sData) & (" Armed Zero Entry Stay"))
|
| 262 | TRY Main.hDB.Exec("UPDATE security SET lcd_line1 = &1, lcd_line2 = &2 WHERE id = 0", "System Armed", "in Zero Entry Stay Mode <>")
|
| 263 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "Armed Zero Entry Stay", "", "", "") |
| 264 | Main.BroadcastEvent("[SecurityUpdate]")
|
| 265 | END SELECT |
| 266 | CASE 654 |
| 267 | Main.WriteLog(("[DSC] Partition ") & sData & (" !ALARM!"))
|
| 268 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "!ALARM!", "Partition " & sData, "", "") |
| 269 | CASE 655 |
| 270 | Main.WriteLog(("[DSC] Partition ") & sData & (" Disarmed"))
|
| 271 | TRY Main.hDB.Exec("UPDATE security SET ready = TRUE, armed = FALSE WHERE id = 0")
|
| 272 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "Disarmed", "Ready", "", "") |
| 273 | DSC_LCDText() |
| 274 | CASE 656 |
| 275 | Main.WriteLog(("[DSC] Exit Delay Partition ") & sData)
|
| 276 | TRY Main.hDB.Exec("UPDATE security SET armed = TRUE, lcd_line1 = &1, lcd_line2 = &2 WHERE id = 0", "Exit Delay in", "Progress")
|
| 277 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "Exit Delay", "Arming", "", "") |
| 278 | Main.BroadcastEvent("[SecurityUpdate]")
|
| 279 | CASE 657 |
| 280 | Main.WriteLog(("[DSC] Entry Delay Partition ") & sData)
|
| 281 | TRY Main.hDB.Exec("UPDATE security SET lcd_line1 = &1, lcd_line2 = &2 WHERE id = 0", "Entry Active", "Enter Your Code")
|
| 282 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "Entry Delay", "", "", "") |
| 283 | Main.BroadcastEvent("[SecurityUpdate] Entry")
|
| 284 | CASE 658 |
| 285 | Main.WriteLog(("[DSC] Keypad Lock-out Partition ") & sData)
|
| 286 | CASE 670 |
| 287 | Main.WriteLog(("[DSC] Invalid Acces Code Partition ") & sData)
|
| 288 | TRY Main.hDB.Exec("UPDATE security SET lcd_line1 = &1, lcd_line2 = &2 WHERE id = 0", "Invalid Access Code", "")
|
| 289 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "Invalid Access Code", "", "", "") |
| 290 | Main.BroadcastEvent("[SecurityUpdate]")
|
| 291 | CASE 671 |
| 292 | Main.WriteDebugLog(("[DSC] Function Not Available Partition ") & sData)
|
| 293 | CASE 700 |
| 294 | Main.WriteLog(("[DSC] Partition ") & Left$(sData, 1) & (" armed by user ") & Right$(sData, -1))
|
| 295 | CASE 701 |
| 296 | Main.WriteLog(("[DSC] Special Closing Partition ") & sData)
|
| 297 | CASE 702 |
| 298 | Main.WriteLog(("[DSC] Partial Closing Partition ") & sData)
|
| 299 | CASE 750 |
| 300 | Main.WriteLog(("[DSC] Partition ") & Left$(sData, 1) & (" disarmed by user ") & Right$(sData, -1))
|
| 301 | CASE 751 |
| 302 | Main.WriteLog(("[DSC] Special Opening Partition ") & sData)
|
| 303 | CASE 800 |
| 304 | Main.WriteLog(("[DSC] Panel Battery Trouble"))
|
| 305 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", "Battery Trouble", "") |
| 306 | CASE 801 |
| 307 | Main.WriteDebugLog(("[DSC] Panel Battery Trouble Restore"))
|
| 308 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", " ", "") |
| 309 | CASE 802 |
| 310 | Main.WriteLog(("[DSC] Panel AC Trouble"))
|
| 311 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", "AC Trouble", "") |
| 312 | CASE 803 |
| 313 | Main.WriteLog(("[DSC] Panel AC Trouble Restore"))
|
| 314 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", " ", "") |
| 315 | CASE 806 |
| 316 | Main.WriteLog(("[DSC] System Bell Trouble"))
|
| 317 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", "Bell Trouble", "") |
| 318 | CASE 807 |
| 319 | Main.WriteDebugLog(("[DSC] System Bell Trouble Restored"))
|
| 320 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", " ", "") |
| 321 | CASE 810 |
| 322 | Main.WriteLog(("[DSC] TLM Trouble"))
|
| 323 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", "TLM Trouble", "") |
| 324 | CASE 811 |
| 325 | Main.WriteDebugLog(("[DSC] TLM Trouble Restored"))
|
| 326 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", " ", "") |
| 327 | CASE 812 |
| 328 | Main.WriteLog(("[DSC] TLM Line 2 Trouble"))
|
| 329 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", "TLM Line 2 Trouble", "") |
| 330 | CASE 813 |
| 331 | Main.WriteDebugLog(("[DSC] TLM Line 2 Trouble Restored"))
|
| 332 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", " ", "") |
| 333 | CASE 814 |
| 334 | Main.WriteLog(("[DSC] FTC Trouble"))
|
| 335 | CASE 816 |
| 336 | Main.WriteLog(("[DSC] Event Buffer Near Full"))
|
| 337 | CASE 821 |
| 338 | Main.WriteLog(("[DSC] Wireless Low Battery Zone ") & sData)
|
| 339 | CASE 822 |
| 340 | Main.WriteDebugLog(("[DSC] Wireless Low Battery Restore Zone ") & sData)
|
| 341 | CASE 825 |
| 342 | Main.WriteLog(("[DSC] Wireless Low Battery Key ") & sData)
|
| 343 | CASE 826 |
| 344 | Main.WriteDebugLog(("[DSC] Wireless Low Battery Restore Key ") & sData)
|
| 345 | CASE 827 |
| 346 | Main.WriteLog(("[DSC] Wireless Low Battery Handheld ") & sData)
|
| 347 | CASE 828 |
| 348 | Main.WriteDebugLog(("[DSC] Wireless Low Battery Restore Handheld ") & sData)
|
| 349 | CASE 829 |
| 350 | Main.WriteLog(("[DSC] General System Tamper"))
|
| 351 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", "System Tamper", "") |
| 352 | CASE 830 |
| 353 | Main.WriteDebugLog(("[DSC] General System Tamper Restored"))
|
| 354 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", " ", "") |
| 355 | CASE 831 |
| 356 | Main.WriteLog(("[DSC] ESCORT 5580TC Trouble"))
|
| 357 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", "ESCORT 5580TC Trouble", "") |
| 358 | CASE 832 |
| 359 | Main.WriteDebugLog(("[DSC] ESCORT 5580TC Trouble Restored"))
|
| 360 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", " ", "") |
| 361 | CASE 840 |
| 362 | Main.WriteDebugLog(("[DSC] Trouble Status Partition ") & sData)
|
| 363 | TRY Main.hDB.Exec("UPDATE security SET trouble = TRUE WHERE id = 0")
|
| 364 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", "Trouble " & sData, "") |
| 365 | Main.BroadcastEvent("[SecurityUpdate]")
|
| 366 | CASE 841 |
| 367 | Main.WriteDebugLog(("[DSC] Trouble Status Partition ") & sData & (" Restored"))
|
| 368 | TRY Main.hDB.Exec("UPDATE security SET trouble = FALSE WHERE id = 0")
|
| 369 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", " ", "") |
| 370 | Main.BroadcastEvent("[SecurityUpdate]")
|
| 371 | CASE 842 |
| 372 | Main.WriteLog(("[DSC] Fire Trouble Alarm"))
|
| 373 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", "Fire Trouble", "") |
| 374 | CASE 843 |
| 375 | Main.WriteDebugLog(("[DSC] Fire Trouble Restored"))
|
| 376 | IF iVirtDeviceId THEN Devices.ValueUpdate(iVirtDeviceId, "", "", " ", "") |
| 377 | CASE 900 |
| 378 | Main.WriteLog(("[DSC] Code Required"))
|
| 379 | Main.BroadcastEvent("[SecurityUpdate] Entry")
|
| 380 | END SELECT |
| 381 | ' checksum not ok |
| 382 | ELSE |
| 383 | Main.WriteDebugLog(("[DSC] Bad CheckSum"))
|
| 384 | END IF |
| 385 | |
| 386 | Main.ControlLed("DSC", "On")
|
| 387 | tDSC.Start |
| 388 | |
| 389 | END |
| 390 | |
| 391 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 392 | ' Process Error Codes |
| 393 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 394 | PUBLIC SUB Error_Code(sStr AS String) |
| 395 | |
| 396 | SELECT CASE Val(sStr) |
| 397 | CASE 000 |
| 398 | Main.WriteLog(("[DSC] System Error - No Error"))
|
| 399 | CASE 001 |
| 400 | Main.WriteLog(("[DSC] System Error - RS-232 Receive Buffer Overrun"))
|
| 401 | CASE 002 |
| 402 | Main.WriteLog(("[DSC] System Error - RS-232 Receive Buffer Overfow"))
|
| 403 | CASE 003 |
| 404 | Main.WriteLog(("[DSC] System Error - Keybus Transmit Buffer Overrun"))
|
| 405 | CASE 010 |
| 406 | Main.WriteLog(("[DSC] System Error - Keybus Transmit Buffer Overrun"))
|
| 407 | CASE 011 |
| 408 | Main.WriteLog(("[DSC] System Error - Keybus Transmit Time Timeout"))
|
| 409 | CASE 012 |
| 410 | Main.WriteLog(("[DSC] System Error - Keybus Transmit Mode Timeout"))
|
| 411 | CASE 013 |
| 412 | Main.WriteLog(("[DSC] System Error - Keybus Transmit Keystring Timeout"))
|
| 413 | CASE 014 |
| 414 | Main.WriteLog(("[DSC] System Error - Keybus Not Functioning"))
|
| 415 | CASE 015 |
| 416 | Main.WriteLog(("[DSC] System Error - Keybus Busy (Attempting to Arm / Disarm)"))
|
| 417 | CASE 016 |
| 418 | Main.WriteLog(("[DSC] System Error - Keybus Busy (Lockout)"))
|
| 419 | CASE 017 |
| 420 | Main.WriteLog(("[DSC] System Error - Keybus Busy (Installers Mode)"))
|
| 421 | CASE 020 |
| 422 | Main.WriteLog(("[DSC] System Error - API Command Syntax Error"))
|
| 423 | CASE 021 |
| 424 | Main.WriteLog(("[DSC] System Error - API Command Partition Error"))
|
| 425 | CASE 022 |
| 426 | Main.WriteLog(("[DSC] System Error - API Command Not Supported"))
|
| 427 | CASE 023 |
| 428 | Main.WriteLog(("[DSC] System Error - API System Not Armed"))
|
| 429 | CASE 024 |
| 430 | Main.WriteLog(("[DSC] System Error - API System Not Ready to Arm"))
|
| 431 | TRY Main.hDB.Exec("UPDATE security SET lcd_line1 = &1 WHERE id = 0", "System not Ready to Arm")
|
| 432 | Main.BroadcastEvent("[SecurityUpdate]")
|
| 433 | CASE 025 |
| 434 | Main.WriteLog(("[DSC] System Error - API Command Invalid Length"))
|
| 435 | CASE 026 |
| 436 | Main.WriteLog(("[DSC] System Error - API User Code Not Required"))
|
| 437 | CASE 027 |
| 438 | Main.WriteLog(("[DSC] System Error - API Invalid Characters in Command"))
|
| 439 | CASE ELSE |
| 440 | Main.WriteLog(("[DSC] System Error - ") & sStr)
|
| 441 | END SELECT |
| 442 | |
| 443 | END |
| 444 | |
| 445 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 446 | ' TX - Calculate the CheckSum and Transmit the data |
| 447 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 448 | PUBLIC SUB TX(sStr AS String) |
| 449 | |
| 450 | DIM sCheckSumCalculating, sCheckSumCalculated AS String |
| 451 | DIM iCheckSumFloat, iInd AS Integer |
| 452 | |
| 453 | ' calculate checksum |
| 454 | FOR iInd = 1 TO Len(sStr) |
| 455 | sCheckSumCalculating = Asc(Mid$(sStr, iInd, 1)) |
| 456 | iCheckSumFloat = iCheckSumFloat + sCheckSumCalculating |
| 457 | NEXT |
| 458 | sCheckSumCalculated = Right(Hex$(iCheckSumFloat), 2) |
| 459 | |
| 460 | PRINT #hDSC, sStr & sCheckSumCalculated |
| 461 | |
| 462 | END |
| 463 | |
| 464 | PUBLIC SUB tDSCLED_Timer() |
| 465 | |
| 466 | Main.ControlLed("DSC", "Off")
|
| 467 | tDSC.Stop |
| 468 | |
| 469 | END |
| 470 | |
| 471 | PUBLIC SUB DSC_LCDText() |
| 472 | |
| 473 | DIM sLCDTime AS String = Format$(Now(), "dd/mmmm/yyyy hh:nn") |
| 474 | |
| 475 | TRY Main.hDB.Exec("UPDATE security SET lcd_line1 = &1, lcd_line2 = &2 WHERE id = 0", "DSC Security", sLCDTime)
|
| 476 | Main.BroadcastEvent("[SecurityUpdate]")
|
| 477 | |
| 478 | END |
| 479 | |
| 480 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 481 | ' close port |
| 482 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 483 | PUBLIC FUNCTION Disconnect() AS Boolean |
| 484 | |
| 485 | ' try to close the connection |
| 486 | TRY hDSC.Close |
| 487 | Main.WriteLog(("DSC serial port close."))
|
| 488 | |
| 489 | ' all ok |
| 490 | RETURN TRUE |
| 491 | |
| 492 | CATCH ' some errors |
| 493 | Main.WriteLog(("DSC Error: ") & ERROR.Text)
|
| 494 | RETURN FALSE |
| 495 | |
| 496 | END |
| 497 | |
| 498 | ' implement properties |
| 499 | PRIVATE FUNCTION Port_Read() AS String |
| 500 | |
| 501 | RETURN sPort |
| 502 | |
| 503 | END |
| 504 | |
| 505 | SUB Port_Write(Value AS String) |
| 506 | |
| 507 | sPort = Value |
| 508 | |
| 509 | END |
| 510 | |
| 511 | PRIVATE FUNCTION Baud_Read() AS String |
| 512 | |
| 513 | RETURN sBaud |
| 514 | |
| 515 | END |
| 516 | |
| 517 | PRIVATE SUB Baud_Write(Value AS String) |
| 518 | |
| 519 | sBaud = Value |
| 520 | |
| 521 | END |
| 522 | |
| 523 | PRIVATE FUNCTION DSCDebug_Read() AS Boolean |
| 524 | |
| 525 | RETURN bDSCDebug |
| 526 | |
| 527 | END |
| 528 | |
| 529 | PRIVATE SUB DSCDebug_Write(Value AS Boolean) |
| 530 | |
| 531 | bDSCDebug = Value |
| 532 | |
| 533 | END |
