79 lines
1.3 KiB
PHP
79 lines
1.3 KiB
PHP
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||
|
|
||
|
/**
|
||
|
* This class is handling Ademco Contact ID Events
|
||
|
*
|
||
|
* @package HAlMon
|
||
|
* @category Helpers
|
||
|
* @author Deon George
|
||
|
* @copyright (c) 2010 Deon George
|
||
|
* @license http://dev.leenooks.net/license.html
|
||
|
*/
|
||
|
class Protocol_ContactID extends Protocol {
|
||
|
protected $_protocol = PROTOCOL_CONTACTID;
|
||
|
|
||
|
private $_checksum_map = array(
|
||
|
'0'=>10,
|
||
|
'1'=>1,
|
||
|
'2'=>2,
|
||
|
'3'=>3,
|
||
|
'4'=>4,
|
||
|
'5'=>5,
|
||
|
'6'=>6,
|
||
|
'7'=>7,
|
||
|
'8'=>8,
|
||
|
'9'=>9,
|
||
|
'*'=>11,
|
||
|
'#'=>12,
|
||
|
'A'=>13,
|
||
|
'B'=>14,
|
||
|
'C'=>15,
|
||
|
);
|
||
|
|
||
|
public function accnum() {
|
||
|
return substr($this->_id,0,4);
|
||
|
}
|
||
|
|
||
|
public function area() {
|
||
|
return substr($this->_id,10,2);
|
||
|
}
|
||
|
|
||
|
// Check that this event is valid
|
||
|
public function check($id) {
|
||
|
if (strlen($id) != 16)
|
||
|
return FALSE;
|
||
|
|
||
|
// Our checksum should be mod15
|
||
|
$c = $t = 0;
|
||
|
while ($c<strlen($id))
|
||
|
$t += $this->_checksum_map[substr($id,$c++,1)];
|
||
|
|
||
|
return ($t%15 === 0) ? TRUE : FALSE;
|
||
|
}
|
||
|
|
||
|
public function checksum() {
|
||
|
return substr($this->_id,15,1);
|
||
|
}
|
||
|
|
||
|
public function equal() {
|
||
|
return substr($this->_id,6,1);
|
||
|
}
|
||
|
|
||
|
public function etype() {
|
||
|
return substr($this->_id,7,3);
|
||
|
}
|
||
|
|
||
|
public function info() {
|
||
|
return substr($this->_id,12,3);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Message Type
|
||
|
* @note This is typically always 18
|
||
|
*/
|
||
|
public function type() {
|
||
|
return substr($this->_id,4,2);
|
||
|
}
|
||
|
}
|
||
|
?>
|