Skip to content
Snippets Groups Projects
Commit bfadb42b authored by Jan Cantaert's avatar Jan Cantaert
Browse files

Temper class + USBTemper class programmed (1st try)

parent cf5df584
No related branches found
No related tags found
2 merge requests!8Fix TEMPer,!7WIP: Multi CPU + Temper usb (not working yet)
......@@ -9,5 +9,16 @@ namespace App\Sensor;
*/
class Temper
{
public $value= ""; //eg : T° value
public $part1= ""; //eg : 0a
public $part2= ""; //eg : 6c
public $temp=array();//eg : [26,28]
public function conversion()
{
$hexatemp=$this->part1 . $this->part2; //eg : 0a6c
$decitemp=hexdec($hexatemp); //eg : 2628
$this->temp[1]=substr($decitemp,0,-2); //eg : 26
$this->temp[2]=substr($decitemp,-2); //eg : 28
return $this->temp; //T° is 26.28°C
}
}
<?php
namespace App\Sensor;
/**
* Description of USBTemperature
*
* @author helha
*/
class USBtemperature extends \App\AbstractSensor
{
//get device responce (8 bytes) :
const REGEXP = "^(80 80)\s*([A-z\/0-9]+) \s*([A-z\/0-9]+)/m";
public function report()
{
$record = $this->getLastRecord("TEMPer");
if ($record == null) {
return "<p>No data available...</p>"
. "<p>Maybe <code>TEMPer</code> is not installed.</p>"
. "<p>You can install it following the tutorial on the Gitlab repository</p>";
}
$temper = self::parse($record['TEMPer']);
$return= "<p>Ambient temperature (USB TEMPer) : "
. $temper[1] . "." . $temper[2] . " °C " . "</p>";
return $return;
}
public function status()
{
$record = $this->getLastRecord("TEMPer");
if ($record == null) {
return self::STATUS_UNKNOWN;
}
$all_status = [];
foreach (self::parse($record['TEMPer']) as $USBTemp) {
/* @var $USBTemp Temper */
$status = self::STATUS_OK;
if ($USBTemp->temperature[1] > 75) {
$status = self::STATUS_WARNING;
}
$all_status[] = $status;
}
return max($all_status);
}
public static function parse(string $string)
{
$values = array();
preg_match_all(self::REGEXP, $string, $values); //get 8 bytes response from TEMPerUSB device
$temperatures = array();
$USBTemp = new Temper();
$USBTemp->part1 = $values[2];
$USBTemp->part2 = $values[3];
$temper[] = $USBTemp->conversion(); //1st element = integer part, 2th = decimal part
return $temper;
}
}
......@@ -32,7 +32,8 @@ class Server extends Model
\App\Sensor\ClientVersion::class,
\App\Sensor\Heartbeat::class,
\App\Sensor\DiskEvolution::class,
\App\Sensor\CPUtemperature::class
\App\Sensor\CPUtemperature::class,
\App\Sensor\USBtemperature::class
];
public function __construct(array $attributes = array())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment