Hytera repeater support #4163

Merged
merged 1 commit into from Aug 23, 2016

Projects

None yet

6 participants

@zarya
Contributor
zarya commented Aug 22, 2016

Support for the Hytera DMR repeaters

@crcro
Contributor
crcro commented Aug 22, 2016

@zarya some code indentation cleanup is required:

if (expression) {

}

for (expression) {

}

@zarya
Contributor
zarya commented Aug 22, 2016

Fixed

@laf laf commented on an outdated diff Aug 22, 2016
includes/discovery/os/hytera.inc.php
@@ -0,0 +1,8 @@
+<?php
+
+if (!$os || $os == "hytera") {
@laf
laf Aug 22, 2016 Member

Just needs to be if (!os) {

@laf laf and 1 other commented on an outdated diff Aug 22, 2016
includes/discovery/os/hytera.inc.php
@@ -0,0 +1,8 @@
+<?php
+
+if (!$os || $os == "hytera") {
+ if (preg_match("/^lwIP/", $sysDescr)) {
@laf
laf Aug 22, 2016 Member

Can you not use the sysObjectId instead?

@murrant
murrant Aug 22, 2016 Contributor

Yeah, this preg_match seems to generic and could have false positives.

@laf laf commented on an outdated diff Aug 22, 2016
includes/discovery/sensors/temperatures/hytera.inc.php
@@ -0,0 +1,26 @@
+<?php
+
+if ($device['os'] == "hytera") {
+ $oids = snmp_walk($device, "rptPaTemprature", "-OsqnU","HYTERA-REPEATER-MIB");
+ if ($debug) {
@laf
laf Aug 22, 2016 Member

Replace if ($debug) and the following lines with just d_echo($oids);

@laf laf commented on an outdated diff Aug 22, 2016
includes/discovery/sensors/temperatures/hytera.inc.php
@@ -0,0 +1,26 @@
+<?php
+
+if ($device['os'] == "hytera") {
+ $oids = snmp_walk($device, "rptPaTemprature", "-OsqnU","HYTERA-REPEATER-MIB");
+ if ($debug) {
+ echo($oids."\n");
+ }
+ if ($oids !== false) echo("HYTERA-REPEATER-MIB ");
@laf
laf Aug 22, 2016 Member

Needs to be full if () {

@laf laf commented on an outdated diff Aug 22, 2016
includes/discovery/sensors/voltages/hytera.inc.php
@@ -0,0 +1,25 @@
+<?php
+
+if ($device['os'] == "hytera") {
+ $oids = snmp_walk($device, "rptVoltage", "-OsqnU","HYTERA-REPEATER-MIB");
+ if ($debug) {
@laf
laf Aug 22, 2016 Member

Same as earlier

@laf laf commented on an outdated diff Aug 22, 2016
includes/discovery/sensors/voltages/hytera.inc.php
@@ -0,0 +1,25 @@
+<?php
+
+if ($device['os'] == "hytera") {
+ $oids = snmp_walk($device, "rptVoltage", "-OsqnU","HYTERA-REPEATER-MIB");
+ if ($debug) {
+ echo($oids."\n");
+ }
+ if ($oids !== false) echo("HYTERA-REPEATER-MIB ");
@laf
laf Aug 22, 2016 Member

Same as earlier.

@laf laf commented on an outdated diff Aug 22, 2016
includes/polling/functions.inc.php
@@ -31,6 +31,9 @@ function poll_sensor($device, $class, $unit) {
else if ($device['os'] == 'canopy') {
include 'includes/polling/temperatures/canopy.inc.php';
}
+ else if ($device['os'] == 'hytera') {
@laf
laf Aug 22, 2016 Member

} elseif () {

@laf laf commented on an outdated diff Aug 22, 2016
includes/polling/functions.inc.php
@@ -50,6 +53,22 @@ function poll_sensor($device, $class, $unit) {
}
}//end if
}
+ else if ($class == "voltage") {
@laf
laf Aug 22, 2016 Member

} elseif () {

@laf laf commented on an outdated diff Aug 22, 2016
includes/polling/functions.inc.php
@@ -50,6 +53,22 @@ function poll_sensor($device, $class, $unit) {
}
}//end if
}
+ else if ($class == "voltage") {
+ if ($device['os'] == 'hytera') {
+ require_once "includes/polling/voltages/hytera.inc.php";
+ }
@laf
laf Aug 22, 2016 Member

} else {

@laf laf commented on an outdated diff Aug 22, 2016
includes/polling/functions.inc.php
@@ -50,6 +53,22 @@ function poll_sensor($device, $class, $unit) {
}
}//end if
}
+ else if ($class == "voltage") {
+ if ($device['os'] == 'hytera') {
+ require_once "includes/polling/voltages/hytera.inc.php";
+ }
+ else {
+ for ($i = 0;$i < 5;$i++) {
@laf
laf Aug 22, 2016 Member

Where has the code this } else { come from? It voltage classes would have just fallen back to line 94.

Probably better to do:

} elseif ($class == "voltage" && $device['os'] == 'hytera') {

And just run the voltage include and then leave all other os' untouched.

@laf
Member
laf commented Aug 22, 2016

Some inline comments made + you need to look at the scrutinizer output: https://scrutinizer-ci.com/g/librenms/librenms/inspections/1fb91573-d70f-4f99-b7f5-e477db3235ef/issues/

@zarya zarya Hytera repeater support
e09b81b
@scrutinizer-notifier

The inspection completed: 2 new issues, 1 updated code elements

@murrant murrant commented on the diff Aug 23, 2016
includes/functions.php
@@ -1463,3 +1463,73 @@ function report_this($message) {
return '<h2>'.$message.' Please <a href="'.$config['project_issues'].'">report this</a> to the '.$config['project_name'].' developers.</h2>';
}//end report_this()
+
+function hytera_h2f($number,$nd)
@murrant
murrant Aug 23, 2016 Contributor

Does this function just change hex to float?

Could you just use floatval($hex) or (float)$hex?

@zarya
zarya Aug 23, 2016 Contributor

floatval("90 4E 63 41") : 90
(float)"90 4E 63 41" : 90
hytera_h2f("90 4E 63 41",2) : 14.21

@murrant
murrant Aug 23, 2016 edited Contributor

That's some special encoding right there :) hexdec was the one I was thinking of. But yeah, nice work.

@laf laf removed the Blocker label Aug 23, 2016
@laf laf merged commit 10d7451 into librenms:master Aug 23, 2016

2 checks passed

Auto-Deploy Build finished.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment