\n"; echo "\n"; // page - list ZKLs $query = "SELECT id,idcode,serienr FROM zkl ORDER BY idcode"; $result = mysql_run($query, $db_main_handle); echo "
";
echo "\n";
echo "
\n";
echo " Extra debug informatie.
\n";
echo " Versie-informatie.
\n";
echo "";
echo "
";
echo "" . $zkl_info['idcode'] . ":
";
// login in with the TCP server
$result = mysql_run("SELECT adres FROM server WHERE id = (SELECT tcp_server FROM zkl WHERE id=" . $zkl . ")", $db_main_handle);
$row = mysql_fetch_assoc($result);
$tcp_server = $row['adres'];
// not using shared memory, because we (may) need to retrieve the Switch status
$tcp_channel = zkl_tcplogin($zkl, $tcp_server, NULL, NULL, ZKL_NORMAL);
if( $tcp_channel === FALSE ) {
echo "Error: " . $zkl_error . "
\n";
}
else {
// get (cached) status
$status = zkl_get_cached_status($tcp_channel, $tcp_timeout);
// detection and measurements
if( in_array("meting", $zkl_info['capabilities']) ) {
echo "Detectie: ";
if( $status['detection']['active'] ) {
if( $status['detection']['ok'] )
echo "ok";
else
echo "alarm";
echo ", b/a=" . sprintf("%.3f", $status['detection']['b/a']);
if( $debug ) echo " (grens: " . sprintf("%.3f", $status['detection']['b/a limit']) . ")";
echo ", %Vrms=" . sprintf("%.1f", sqrt($status['detection']['rms']));
}
else {
echo "uitgeschakeld";
}
echo "
\n";
}
// Switch3000
if( in_array("kortsluiting schakelen", $zkl_info['capabilities']) && $debug ) {
zkl_store($tcp_channel, "SWITCH", "F0");
usleep(500000);
$swstatus = zkl_retrieve($tcp_channel, "SWITCH", $tcp_timeout);
if( $swstatus !== FALSE ) {
$status_str = $swstatus;
$swstatus = intval(substr($status_str, 2), 16);
$swerror = intval(substr($status_str, 0, 2), 16);
}
}
else $swstatus = FALSE;
if( in_array("kortsluiting schakelen", $zkl_info['capabilities']) ) {
echo "Switch3000: ";
if( $status['switch3000']['on'] )
echo "ingeschakeld";
else
echo "uitgeschakeld";
if( $debug ) {
echo ", status: ";
if( $swstatus !== FALSE ) {
if( ($swerror & 0x01) == 0 ) {
echo "oude gegevens ";
}
if( ($swerror & 0x80) != 0 ) {
if( ($swstatus & 0x00100000) != 0 )
echo "Switch3000 time-out";
else if( ($swstatus & 0x00200000) != 0 )
echo "Switch3000 fout op 1-Wire verbinding";
else
echo "onbekende Switch3000 fout";
}
else {
if( ($swstatus & 0x000F0000) == 0x00000000 )
echo "alle secties uitgeschakeld";
else if( ($swstatus & 0x000F0000) == 0x000F0000 )
echo "alle secties ingeschakeld";
else for( $i = 0; $i < 4; $i++ ) {
if( $i > 0 ) echo ", ";
echo "sectie " . ($i + 1) . " ";
if( $status['sw3000']['on'] ) {
if( ($swstatus & (1 << ($i + 16))) != 0 )
echo "ingeschakeld";
else
echo "uitgeschakeld";
}
else {
if( ($swstatus & (1 << ($i + 16))) != 0 )
echo "ingeschakeld";
else
echo "uitgeschakeld";
}
}
}
}
else echo "geen antwoord binnen " . sprintf("%.1f", $tcp_timeout) . " s";
}
echo "
\n";
}
if( in_array("sleutelschakelaar", $zkl_info['capabilities']) ) {
echo "Sleutelschakelaar: ";
if( $status['switch3000']['key']['on'] ) echo "aan
";
else if( $status['switch3000']['key']['off'] ) echo "uit
";
else echo "operationeel
";
echo "
\n";
}
// Batteries
if( $swstatus !== FALSE && ($swerror & 0x80) == 0 && in_array("kortsluiting schakelen", $zkl_info['capabilities']) ) {
echo "Batterijen Switch3000: ";
if( ($swstatus & 0x00008F00) == 0x00008F00 )
echo "ok";
else {
for( $i = 0; $i < 4; $i++ ) {
if( $i > 0 ) echo ", ";
echo "sectie " . ($i + 1) . " ";
if( ($swstatus & (1 << ($i + 8))) == 0 )
echo "niet ok";
else
echo "ok";
}
echo ", noodschakelaar ";
if( ($swstatus & 0x00008000) == 0 )
echo "niet ok";
else
echo "ok";
}
echo "
\n";
}
for( $batt = 0; $batt < $zkl_info['nr_batterijen']; $batt++ ) {
echo "Accu " . ($batt + 1) . ": ";
echo sprintf("%.3fV, ", $status['batt'][$batt]['V']);
if( $status['batt'][$batt]['status'] == "ok" )
echo "ok";
else if( $status['batt'][$batt]['status'] == "removed" )
echo "verwijderd";
else if( $status['batt'][$batt]['status'] == "alarm" )
echo "alarm";
else
echo "leeg";
if( $status['batt']['select'] == $batt || $status['batt']['select'] == -1 ) echo ", ingeschakeld";
echo "
\n";
}
// GSM (debug only)
if( $debug && in_array("gsm", $zkl_info['capabilities']) && $status['gsm']['enabled'] ) {
echo "GSM: ";
if( !$status['gsm']['connected'] ) {
echo "";
echo "netwerk";
echo "";
echo ", ";
}
if( $status['gsm']['sim initialized'] )
echo "";
echo "SIM";
echo "";
echo ", ";
if( $status['gsm']['gprs connected'] )
echo "";
echo "GPRS";
echo "";
echo ", ";
if( $status['gsm']['tcp/ip connected'] )
echo "";
echo "TCP";
echo "";
if( $status['gsm']['received signal strength'] != -999 ) {
echo ", signaal=";
if( $status['gsm']['received signal strength'] <= -97.0 )
echo "";
else if( $status['gsm']['received signal strength'] <= -81.0 )
echo "";
else
echo "";
echo sprintf("%d dBm", $status['gsm']['received signal strength']);
echo ", bit error rate=" . $status['gsm']['bit error rate'];
}
echo "
\n";
}
// Temperature
if( in_array("temperatuursensor on-board", $zkl_info['capabilities']) ) {
echo "Ton-board: " . sprintf("%.1f°C", $status['temp']['on-board']['C']) . "
\n";
}
if( in_array("temperatuursensor extern", $zkl_info['capabilities']) ) {
if( $status['temp']['ext1']['C'] !== FALSE && $status['temp']['ext1']['C'] > -128 )
echo "Text1: " . sprintf("%.1f°C", $status['temp']['ext1']['C']) . "
\n";
if( $status['temp']['ext2']['C'] !== FALSE && $status['temp']['ext2']['C'] > -128 )
echo "Text2: " . sprintf("%.1f°C", $status['temp']['ext2']['C']) . "
\n";
}
if( in_array("kortsluiting schakelen", $zkl_info['capabilities']) ) {
if( $status['temp']['switch3000']['C'] !== FALSE && $status['temp']['switch3000']['C'] > -128 )
echo "Tswitch3000: " . sprintf("%.1f°C", $status['temp']['switch3000']['C']) . "
\n";
}
if( $swstatus !== FALSE && ($swerror & 0x80) == 0 ) {
echo "Tswitch: " . sprintf("%.1f°C", $swstatus & 0xFF) . "
\n";
}
// GPS
if( in_array("gps", $zkl_info['capabilities']) ) {
echo "GPS: ";
echo sprintf("%.6f,%.6f", $status['gps']['latitude'], $status['gps']['longitude']);
// OBSOLETE: age is affected too much by whether someone is viewing the RT status
//if( $status['gps']['tijd'] != 0 ) {
// $age = time() - $status['gps']['tijd'];
// if( $age < 0 ) $age = 0; // clocks may differ...
// echo sprintf(", ouderdom=%u′%02u″", $age / 60, $age % 60);
//}
if( $status['gps']['speed'] != 0.0 ) {
echo sprintf(", tc=%.1f, speed=%.1f km/h", $status['gps']['heading'], $status['gps']['speed']);
}
echo sprintf(", hdop=%.1f", $status['gps']['hdop']);
if( $debug ) {
if( isset($status['gps']['nsv']) ) {
echo ", nsv=" . $status['gps']['nsv'];
}
switch( $status['gps']['mode'] ) {
case 'A':
echo ", fix=normaal";
break;
case 'D':
echo ", fix=differentieel";
break;
case 'E':
echo ", fix=schatting";
break;
case 'I':
echo ", oude data van mcu";
break;
case 'U':
echo ", initialiseert";
break;
case 'N':
echo ", geen fix";
break;
default:
if( !$status['gps']['fix'] ) echo ", geen fix";
break;
}
}
else if( !$status['gps']['fix'] ) {
echo ", geen fix";
}
echo "
\n";
// Geofence
if( $zkl_info['geofence'] ) {
echo "Geofence: ";
if( $status['geofence']['inside'] ) {
echo "binnen";
$geofences = zkl_command($tcp_channel, $tcp_timeout, "\$GEOFENCE");
if( $geofences === FALSE ) {
echo ", geen antwoord binnen " . sprintf("%.1f", $tcp_timeout) . " s";
}
else {
$geofences = explode(",", $geofences);
$result = mysql_run("SELECT naam FROM geofence WHERE id IN (" . implode(",", $geofences) . ")", $db_main_handle);
$sep = " ";
while( $row = mysql_fetch_assoc($result) ) {
echo $sep;
echo $row['naam'];
$sep = ", ";
}
}
echo "
\n";
}
else {
echo "buiten";
echo "
\n";
}
}
}
// Firmware
if( $versions ) {
zkl_queue_retrieval($tcp_channel, "VERSION[FW-MCU]");
zkl_queue_retrieval($tcp_channel, "VERSION[FW-WCPU]");
zkl_queue_retrieval($tcp_channel, "VERSION[FW-WAVECOM]");
zkl_read_result($tcp_channel, $mcu_version, $tcp_timeout);
zkl_read_result($tcp_channel, $wcpu_version, $tcp_timeout);
zkl_read_result($tcp_channel, $q2686_version, $tcp_timeout);
echo "Firmware: " . $mcu_version . ", " . $wcpu_version . ", " . $q2686_version . "
\n";
}
// Done
zkl_tcplogout($tcp_channel);
}
echo "