public function PrettyPrint() { /** * Output the variable header key value pairs. */ mbus_utils::mylog("========================================================"); mbus_utils::mylog("---- Frame Information ----"); mbus_utils::mylog("--------------------------------------------------------"); foreach ($this->varframe as $key => $value) { mbus_utils::mylog(str_pad(" {$key} ", 30) . $value); } mbus_utils::mylog(str_pad(" Data ", 30) . ""); mbus_utils::outputByteString($this->data); mbus_utils::mylog("--------------------------------------------------------"); /** * Output the variable header key value pairs. */ mbus_utils::mylog("========================================================"); mbus_utils::mylog("---- Slave Information ----"); mbus_utils::mylog("--------------------------------------------------------"); foreach ($this->varheader as $key => $value) { mbus_utils::mylog(str_pad(" {$key} ", 30) . $value); } mbus_utils::mylog("--------------------------------------------------------"); /** * Output the variable records key value pairs. */ mbus_utils::mylog("========================================================"); mbus_utils::mylog("---- Record Information ----"); foreach ($this->varrecords as $key1 => $record) { mbus_utils::mylog("--------------------------------------------------------"); mbus_utils::mylog(str_pad("Record Number ", 30) . $key1); mbus_utils::mylog("General"); $difgeneralarray = $record['general']; foreach ($difgeneralarray as $dif_general_key => $dif_general_value) { mbus_utils::mylog(str_pad(" {$dif_general_key} ", 30) . $dif_general_value); } //$sbp = $record['general']['StartBytePosition']; //mbus_utils::mylog(str_pad(" StartByte ", 30) . dechex($this->dataarray[$sbp])); //$ebp = $record['general']['EndBytePosition']; //mbus_utils::mylog(str_pad(" EndByte ", 30) . dechex($this->dataarray[$ebp])); mbus_utils::mylog("DIF found"); $difarray = $record['dif']; foreach ($difarray as $dif_key => $dif_value) { mbus_utils::mylog(str_pad(" {$dif_key} ", 30) . $dif_value); } $difearray = $record["dife"]; if (isset($difearray)) { mbus_utils::mylog("DIFe found"); foreach ($difearray as $dife_key => $dife_value) { foreach ($dife_value as $dife_key2 => $dife_value2) { mbus_utils::mylog(str_pad(" {$dife_key2} ", 30) . $dife_value2); } } } else { mbus_utils::mylog("No DIFe"); } $vifarray = $record["vif"]; if (isset($vifarray)) { mbus_utils::mylog("VIF found"); foreach ($vifarray as $vif_key => $vif_value) { mbus_utils::mylog(str_pad(" {$vif_key} ", 30) . $vif_value); } } else { mbus_utils::mylog("No VIF"); } $vifearray = $record["vife"]; if (isset($vifearray)) { mbus_utils::mylog("VIFe found"); foreach ($vifearray as $vife_key => $vife_value) { foreach ($vife_value as $vife_key2 => $vife_value2) { mbus_utils::mylog(str_pad(" {$vife_key2} ", 30) . $vife_value2); } } } else { mbus_utils::mylog("No VIFe"); } mbus_utils::mylog("Data"); $value = $record['Value']; if (isset($value)) { mbus_utils::mylog(str_pad(" Value ", 30) . $value); } else { mbus_utils::mylog(" No Value"); } $dataarray = $record['data']; if (isset($dataarray)) { $data = ""; foreach ($dataarray as $data_key => $data_value) { $data .= mbus_utils::ByteToHex($data_value); } mbus_utils::mylog(str_pad(" Raw Bytes ", 30) . $data); } else { mbus_utils::mylog(str_pad(" Raw Bytes ", 30) . "No data"); } } mbus_utils::mylog("--------------------------------------------------------"); }
public static function getValue($dif, $vif, $data) { if ($vif != 0x0) { $vifNoExt = $vif & 0x7f; switch ($vifNoExt) { // E110 110n Time Point // n = 0 date // n = 1 time & date // data type G // data type F case $vifNoExt >= 0x6c && $vifNoExt <= 0x6d: if ($vif & 0x1) { // Data length should be 4 bytes. if (count($data) < 4) { return "Invalid number of bytes to determine date and time!"; } return mbus_utils::data_date_time_decode($data); } else { return "NYI - Time Point (date)"; } break; // This is the units of the value. Not the actual value! Still need to get value in this record. // Tricky eh, see 6.3 plain text VIF // This is the units of the value. Not the actual value! Still need to get value in this record. // Tricky eh, see 6.3 plain text VIF case $vifNoExt == 0x7c: if ($data_length <= 0xbf) { return mbus_utils::data_str_decode($data); } break; } } switch ($dif & 0xf) { case 0x0: // no data return "No Data"; break; case 0x1: // 1 byte integer (8 bit) // 1 byte integer (8 bit) case 0x2: // 2 byte integer (16 bit) // 2 byte integer (16 bit) case 0x3: // 3 byte integer (24 bit) // 3 byte integer (24 bit) case 0x4: // 4 byte integer (32 bit) // 4 byte integer (32 bit) case 0x6: // 6 byte integer (48 bit) // 6 byte integer (48 bit) case 0x7: // 8 byte integer (64 bit) return mbus_utils::data_int_decode($data); break; case 0x9: // 2 digit BCD (8 bit) // 2 digit BCD (8 bit) case 0xa: // 4 digit BCD (16 bit) // 4 digit BCD (16 bit) case 0xb: // 6 digit BCD (24 bit) // 6 digit BCD (24 bit) case 0xc: // 8 digit BCD (32 bit) // 8 digit BCD (32 bit) case 0xe: // 12 digit BCD return mbus_utils::data_bcd_decode($data); break; case 0xe: // Special Functions return "Special Functions"; break; case 0xd: // variable length ASCII if ($data_length <= 0xbf) { return mbus_utils::data_str_decode($data); break; } // FALLTHROUGH // FALLTHROUGH default: return "Unknown DIF (0x" . dechex($dif) . ")"; break; } return ""; }
<?php error_reporting(E_ALL); ini_set('error_reporting', E_ALL ^ E_NOTICE); ini_set('display_errors', 1); include_once "mbus_client.php"; include_once "mbus_utils.php"; mbus_utils::logToTerminal(); // View Browser in Source mode to get nice formatting. //mbus_utils::turnLogOff(); //mbus_utils::mylog("Start\n"); /** * Set to true for testing, it will not bother connecting, it will just read a hard coded string of byte data. */ $testmode = false; $mbusClient = new mbus_client(); $mbusClient->run($testmode); //mbus_utils::mylog("Finshed.\n");