Last active
August 29, 2015 14:16
-
-
Save jeancarl/a3eb3c9932d8c9eaa05a to your computer and use it in GitHub Desktop.
DQuid PHP library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* DQuid Library | |
* | |
* Retrieves values from a Bay Tek Game machine given the serial number. | |
* / | |
class Dquid | |
{ | |
var $serial_number; | |
var $end_point; | |
function __construct($end_point, $serial_number) | |
{ | |
$this->end_point = $end_point; | |
$this->serial_number = $serial_number; | |
} | |
function get_stats($since) | |
{ | |
$values = array(); | |
$ch = curl_init($this->end_point.$this->serial_number.'?from='.$since); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$return = json_decode(curl_exec($ch)); | |
foreach($return as $o) | |
{ | |
$values[$o->propertyName] = hexdec($o->propertyValue); | |
} | |
$new_values = array(); | |
foreach($values as $k=>$v) | |
{ | |
if($this->_ends_with($k, 'SB')) | |
{ | |
if($this->_ends_with($k, 'MLSB')) | |
{ | |
$new_key = substr($k, 0, strlen($k)-4); | |
} | |
else | |
{ | |
$new_key = substr($k, 0, strlen($k)-3); | |
} | |
$new_values[$new_key] = hexdec((isset($values[$k.'MSB']) ? $values[$k.'MSB'] : '').(isset($values[$k.'MLSB']) ? $values[$k.'MLSB'] : '').(isset($values[$k.'LSB']) ? $values[$k.'LSB'] : '')); | |
} | |
else | |
{ | |
$new_values[$k] = $v; | |
} | |
} | |
return $new_values; | |
} | |
function _ends_with($haystack, $needle) { | |
return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment