Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for AD2* Devices #389

Merged
merged 78 commits into from
Jun 13, 2014
Merged

Add Support for AD2* Devices #389

merged 78 commits into from
Jun 13, 2014

Conversation

krkeegan
Copy link
Collaborator

This is an expansion of the great work done by Kirk Friedenberger, Wayne Gatlin, and Howard Plato

MAJOR NOTE: I changed the name of the library from AD2USB to AD2 as this library can be used with AD2Serial, AD2USB, AD2Pi, and whatever other fantastic products that Sean comes up with. This change will affect anyone upgrading from an older version to this, generally you can simply change all configuration settings from ad2usb->ad2.

The initial code relied very heavily on INI definitions and only created a single object inside MisterHouse. This new code attempts to maintain support for that initial configuration.

In addition, this code allows for the definition of objects using mht style definitions. You can also now treat each zone as a separate object. This allows for use of all of the normal Generic_Items functions that we are used to, such as $garage_zone->tie_event('$garage_light->set(ON)', 'fault');. I believe the code is also much more robust. It allows for multiple AD2 devices to exist, multiple partitions, and many other features.

I highly recommend reviewing the POD documentation contained within the file, or viewing it through the http://localhost/docs portal. I have also posted a copy of the documentation here for those who wish to review the documentation without merging this branch. http://jsfiddle.net/7sCa9/

The AD2 and the alarm panels in general have many many options. This code works flawlessly for me, but I have not and likely cannot test all of the various permutations, so I am sure it has flaws. If you fork this branch and send pull requests to me, I will merge them in. If you don't want to do that, I will do my best to fix errors as they are identified. As demonstrated by the 76 commits and 3 months of work, I have become a little burnt out on this library and have undoubtedly missed many many things.

hplato and others added 30 commits January 4, 2014 13:39
- Allows for use of all Generic_Item options including tie_events
- Remove states because this is not an "editable" object
Tabs are set at 3 spaces which is odd
Can't use a global variable, otherwise users would not be able to have multiple panels setup in MH.

Greatly simply DefineCmdMsg mess.
Make new() sub much easier to read, get rid of verbose coding.

Remove all changes to Config Hash, this should be read-only as it represents the contents of the ini file, this contents can be updated by MH
No need for this if regex includes start and end of line
Also cleanup parser to make a little easier
…CheckCmd, Removed Switch Package

Returning a hash makes the code infinitely more readable, no longer need to remember the numbers for various message types.

Removed Switch to make compatible with Perl 5.8.8
Relying on substr is dangerous, particularly since a user can enable the !KPM: prefix.

Add more message parsing to GetStatusType, this routine can likely be converted to parse_message and save a lot of code
Get rid of all of the complicated tests.

Allow ChangeZones to loop around from a high zone to a low zone.

NOTE: May need to add a check to ChangeZones to see if it is reseting a mapped zone.
Anytime we get a keypad message we can check the status bits.

Stop using substr and use hash flags.
Wow, can't believe I missed that.
Using hash keys makes the code much more condensed and easier to read.
I have to admit I don't really understand all of the optional settings for wireless objects
Add an object for a partition.

Cleanup unused function sof door and motion items.  Some odd functions still remain.
Mapped zones are faulted by direct messages received from the AD2.

This correction fixes the following oddity:

-------

Zones 1 and 3 are faulted.

The Alpha message describing the Zone 3 fault just arrived.

Zone 10, a mapped zone is then faulted.  The fault is immediately detected by an EXP! message.  MH updates the status of zone 10 to faulted.

AD2 then starts over with the Alpha fault list by sending the Alpha message that Zone 1 is faulted.

Since the last alpha fault received was zone 3, MH resets all zones between 3 -> 1 as ready, clearing out 10.

Two messages later, the Alpha message for zone 10 arrives, putting zone 10 back in a faulted state.

-------

This fixes the oddity by not reseting any mapped zones based on alpha messages.
The alphanumeric fault messages are more complicated than i realized.  The list of faulted zones restarts at the lowest faulted zone everytime a fault occurs.  So for example, if zones 1-5 are faulted, and the panel has just finished sending the zone 3 fault message, if zone 7 is then faulted, the next message will be a zone 1 fault again.

If we blindly perform wrap-around resets, it is very easy to create a "fluttering" zone when multiple zones are faulted.

To cut down on the potential for fluttering, this change only performs a wrap-around reset if the highest faulted zone that is reported remains constant for 2 cycles.  While not completly ensuring that all zones have been report, it is unlikely that the panel will be interrupted at exactly the same point in its cycle twice.

The major downside of this, is that there may be a slight delay in reseting zones from fault -> ready.  This is particularly true of the higher unmapped zones.
Try to optimize code as much as possible.

On a dual core machine, using AD2 code seems to add between .3-.7% CPU usage to one of the cores.  I think this is mostly a side effect of using a socket.
…eclaration

The old design for the ini declaration was a little confusing.  Plus, carrying it over directly into the Configation Hash did not allow for mht style declarations of a wireless object.

The new design seems more logical to me and adds the framework to support an mht style declaration.

The old design for ini declarations is stil supported for backwards compatibility.
…or MHT Declarations

They are essentially identical.  This gets rid of the duplicative code.

Added framework to support mht declaration of wireless, expander and relay items.
All references to AD2USB has been replaced with AD2.

This means all configuration settings and user code settings need to be updated as well.

The change was necessary because this module will work with at leaast AD2Serial, AD2USB, AD2Pi, and likely many more AD2 style products that will be released in the future.
Cannot use comma in mht definitions

Keyfob was not likely ever set to fault, since fault and ready were set in same loop.
…in Partition

Checking for faults using the Alphanumeric messages is really complicated.  The concept sounds simple, but building a test that doesn't get confused is difficult. I think this current system is more accurate, but a little slower to move from fault->ready.

I added a lot more comments to explain my logic since code alone is not really enough.

Also fixed a error in the partition child.
krkeegan added a commit that referenced this pull request Jun 13, 2014
Add Support for AD2* Devices
@krkeegan krkeegan merged commit 64dce93 into hollie:master Jun 13, 2014
@krkeegan krkeegan deleted the ad2usb branch June 13, 2014 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants