Changeset 11
- Timestamp:
- 2011-05-23 19:30:08 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified I_ElkAlarmPanel1.lua ¶
r10 r11 30 30 local log = luup.log 31 31 32 ---------- Generic Utilities----------32 ------------------------------ Generic Utilities ------------------------------ 33 33 34 34 local function debug (text) … … 149 149 end 150 150 151 ---------- Action implementations----------151 ---------------------------- Action implementations --------------------------- 152 152 153 153 local function requestArmMode (device, state, pinCode) … … 190 190 end 191 191 192 ---------- Message Handling----------192 ------------------------- Message Handling: Constants ------------------------- 193 193 194 194 --[[ Here only for reference: … … 388 388 ['T'] = "Intercom Key" 389 389 } 390 391 ----------------- Message Processing: Function Implementations ---------------- 390 392 391 393 local function processZoneChangeUpdate (data) … … 579 581 end 580 582 581 ---------- Incoming Message Processing----------583 ------------------------- Incoming Message Processing ------------------------- 582 584 583 585 local PANEL_RESPONSES = { … … 587 589 debug ("Message type description: Zone Definition Data") 588 590 processZoneDefinitionData (data) 591 return true 589 592 end 590 593 }, … … 594 597 debug ("Message type description: Zone Partion Report") 595 598 processZonePartitionReport (data) 599 return true 596 600 end 597 601 }, … … 601 605 debug ("Message type description: Zone and Partition Labels") 602 606 processLabels (data) 607 return true 603 608 end 604 609 }, … … 608 613 debug ("Message type description: Zone Status Report") 609 614 processZoneStatusReport (data) 615 return true 610 616 end 611 617 }, … … 615 621 debug ("Message type description: Arming Status Report") 616 622 processArmingStatusReport (data) 623 return true 617 624 end 618 625 }, … … 622 629 debug ("Message type description: Keypad Function Key Press") 623 630 processKeypadKeyPress (data) 631 return true 624 632 end 625 633 }, … … 629 637 debug ("Message type description: System Trouble Status") 630 638 processSystemTroubleStatus (data) 639 return true 631 640 end 632 641 }, … … 636 645 debug ("Message type description: Log Data") 637 646 processLogData (data) 647 return true 638 648 end 639 649 }, … … 643 653 debug ("Message type description: Zone Change Update") 644 654 processZoneChangeUpdate (data) 655 return true 656 end 657 }, 658 ["VN"] = { 659 "M1 Version Number", 660 function (data) 661 debug ("Message type description: M1 Version Number") 662 if (data == "") then 663 log ("ERROR: Missing version data.") 664 return 665 end 666 local uver, mver, lver = data:match ("^(%w%w)(%w%w)(%w%w)") 667 return string.format ("%d.%d.%d", tonumber (uver, 16), tonumber (mver, 16), tonumber (lver, 16)) 645 668 end 646 669 } … … 676 699 end 677 700 678 ---------- Startup Functions----------701 ------------------------------ Startup Functions ------------------------------ 679 702 680 703 local function sendCommand (command, data) … … 686 709 debug ("(sendCommand) Command to send: " .. cmd) 687 710 if (not luup.io.write (cmd)) then 688 local message = string.format ("ERROR (sendCommand): Cannot send command: '%s'", cmd) 689 log (message) 690 luup.set_failure (true) 691 692 return false, message 693 end 694 695 return true, "Ok" 711 log (string.format ("(sendCommand) ERROR: Failed to send command: '%s'", cmd)) 712 return false 713 end 714 715 return true 696 716 end 697 717 … … 756 776 757 777 778 local function getZonesStatus() 779 luup.io.intercept() 780 local status = sendCommand ("zs") 781 if (not status) then 782 log ("(getZonesStatus) ERROR: Failed to get zones status.") 783 return false, "Failed to get zones status." 784 end 785 local msg = luup.io.read() 786 status = processMessage (msg) 787 if (not status) then 788 log ("(getZonesStatus) ERROR: Failed to get zones status.") 789 return false, "Failed to get zones status." 790 end 791 792 end 793 794 758 795 local function getZoneNames() 759 796 for i in ipairs (g_childDevices.zones) do 760 sendCommand ("sd", string.format ("00%03d", i)) 797 luup.io.intercept() 798 local status = sendCommand ("sd", string.format ("00%03d", i)) 799 if (not status) then 800 log ("(getZoneNames) ERROR: Failed to get zones names.") 801 end 802 local msg = luup.io.read() 803 status = processMessage (msg) 804 if (not status) then 805 log ("(getZoneNames) ERROR: Failed to get zones names.") 806 end 761 807 end 762 808 end … … 792 838 793 839 794 local function getPartitionNames() 840 local function getPartitionsStatus() 841 luup.io.intercept() 842 local status = sendCommand ("as") 843 if (not status) then 844 log ("(getPartitionsStatus) ERROR: Failed to get partitions status.") 845 return false, "Failed to get partitions status." 846 end 847 local msg = luup.io.read() 848 status = processMessage (msg) 849 if (not status) then 850 log ("(getPartitionsStatus) ERROR: Failed to get partitions status.") 851 return false, "Failed to get partitions status." 852 end 853 end 854 855 856 local function getPartitionsName() 795 857 for i in ipairs (g_childDevices.partitions) do 796 sendCommand ("sd", string.format ("01%03d", i)) 858 luup.io.intercept() 859 local status = sendCommand ("sd", string.format ("01%03d", i)) 860 if (not status) then 861 log ("(getPartitionNames) ERROR: Failed to get partition names.") 862 return 863 end 864 local msg = luup.io.read() 865 status = processMessage (msg) 866 if (not status) then 867 log ("(getPartitionNames) ERROR: Failed to get partition names.") 868 return 869 end 797 870 end 798 871 end … … 801 874 local function getZonesAndPartitions() 802 875 -- Get zone information. 803 local status, message = sendCommand ("zd") 804 if (status) then 805 -- Get partition information. 806 status, message = sendCommand ("zp") 807 end 808 809 return status, message 876 luup.io.intercept() 877 local status = sendCommand ("zd") 878 if (not status) then 879 log ("(getZonesAndPartitions) ERROR: Failed to get zones and partitions.") 880 return false, "Failed to get zones and partitions." 881 end 882 local msg = luup.io.read() 883 status = processMessage (msg) 884 if (not status) then 885 log ("(getZonesAndPartitions) ERROR: Failed to get zones and partitions.") 886 return false, "Failed to get zones and partitions." 887 end 888 889 -- Get partition information. 890 luup.io.intercept() 891 status = sendCommand ("zp") 892 if (not status) then 893 log ("(getZonesAndPartitions) ERROR: Failed to get zones and partitions.") 894 return false, "Failed to get zones and partitions." 895 end 896 msg = luup.io.read() 897 status = processMessage (msg) 898 if (not status) then 899 log ("(getZonesAndPartitions) ERROR: Failed to get zones and partitions.") 900 return false, "Failed to get zones and partitions." 901 end 902 903 return true 810 904 end 811 905 … … 813 907 local function getVersion() 814 908 luup.io.intercept() 815 sendCommand ("vn") 816 local msg = luup.io.read() 817 local msgType, data = checkMessage (message) 818 if (not msgType || data == "") then 819 debug ("(getVersion) ERROR: Missing version data.") 820 return "N/A" 821 end 822 823 local uver, mver, lver = data:match ("^(%w%w)(%w%w)(%w%w)") 824 825 return string.format ("%d.%d.%d", tonumber (uver, 16), tonumber (mver, 16), tonumber (lver, 16)) 826 end 827 828 -------------------------------------------------------------------------------------------------- 909 local status = sendCommand ("vn") 910 if (status) then 911 local msg = luup.io.read() 912 return processMessage (msg) 913 end 914 end 915 916 ------------------------------------------------------------------------------- 829 917 830 918 function start (lul_device) … … 847 935 end 848 936 849 getPartitionNames() 937 getPartitionsName() 938 850 939 -- Get each Partition's status. 851 status, message = sendCommand ("as")940 status, message = getPartitionsStatus() 852 941 if (not status) then 853 942 return status, message, "Elk Alarm Panel" 854 943 end 944 855 945 -- Get the Chime Mode for each partition. 856 946 sendCommand ("kf", "010") 947 857 948 -- Create a device for each active partition. 858 949 appendPartitions (rootPtr) 859 950 860 951 getZoneNames() 952 861 953 -- Get each Zone's status. 862 status, message = sendCommand ("zs")954 status, message = getZonesStatus() 863 955 if (not status) then 864 956 return status, message, "Elk Alarm Panel" 865 957 end 958 866 959 -- Create a device for each zone. 867 960 appendZones (rootPtr)
Note: See TracChangeset
for help on using the changeset viewer.