Change DEBUG to a static const

This commit is contained in:
2023-07-19 10:27:47 +10:00
parent ee03604de3
commit dcae06aad9
5 changed files with 48 additions and 48 deletions

View File

@@ -877,12 +877,12 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
case self::XOFF:
case self::XON|0x80:
case self::XOFF|0x80:
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s: - ls_zdonereceiver XON/XOFF, skip it',self::LOGKEY));
break;
case self::ZPAD:
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s: - ls_zdonereceiver ZPAD',self::LOGKEY));
if (($rc=$this->ls_zrecvhdr($this->ls_rxHdr,$this->ls_HeaderTimeout)) < 0)
@@ -1085,7 +1085,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
*/
private function ls_zrecvdata16(string &$data,int &$len,int $timeout): int
{
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s:+ ls_zrecvdata16',self::LOGKEY),['d'=>$data]);
$got = 0; /* Bytes total got */
@@ -1094,7 +1094,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$rcvdata = 1; /* Data is being received NOW (not CRC) */
while ($rcvdata && (($c = $this->ls_readzdle($timeout)) >= 0)) {
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s: - ls_zrecvdata16 got [%x] (%c)',self::LOGKEY,$c,($c<31 ? 32 : $c)),['c'=>serialize($c)]);
if ($c < 256) {
@@ -1140,7 +1140,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$incrc = crc16($data.chr($frametype));
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s: - ls_zrecvdata16 CRC%d got %08x - calculated %08x',self::LOGKEY,16,$incrc,$crc));
if ($incrc != $crc)
@@ -1148,7 +1148,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$len = $got;
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s:= ls_zrecvdata16 - frametype [%d]',self::LOGKEY,$frametype));
return $frametype;
@@ -1164,7 +1164,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
*/
private function ls_zrecvdata32(string &$data,int &$len,int $timeout): int
{
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s:+ ls_zrecvdata32',self::LOGKEY),['d'=>$data]);
$got = 0; /* Bytes total got */
@@ -1173,7 +1173,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$rcvdata = 1; /* Data is being received NOW (not CRC) */
while ($rcvdata && (($c=$this->ls_readzdle($timeout)) >= 0)) {
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s: - ls_zrecvdata32 got [%x] (%c)',self::LOGKEY,$c,($c<31 ? 32 : $c)),['c'=>serialize($c)]);
if ($c < 256) {
@@ -1225,7 +1225,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$crc |= ($c << 0x18);
$incrc = crc32($data.chr($frametype));
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s: - ls_zrecvdata32 CRC%d got %08x - calculated %08x',self::LOGKEY,32,$incrc,$crc));
if ($incrc != $crc)
@@ -1233,7 +1233,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$len = $got;
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s:= ls_zrecvdata32 - frametype [%d]',self::LOGKEY,$frametype));
return $frametype;
@@ -1550,7 +1550,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
*/
private function ls_zrecvhdr(array &$hdr,int $timeout): int
{
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s:+ Receive header with [%d] timeout',self::LOGKEY,$timeout));
$state = self::rhInit;
@@ -1567,7 +1567,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$c = -1;
if ($state === self::rhInit) {
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s:- ls_zrecvhdr Init State',self::LOGKEY));
$frametype = self::ERROR;
@@ -1581,7 +1581,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
}
while ($rc=$this->client->hasData($timeout)) {
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s:- ls_zrecvhdr hasData - readmode [%d], garbage chars [%d], state [%d]',self::LOGKEY,$readmode,$garbage,$state));
switch ($readmode) {
@@ -1602,7 +1602,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
break;
}
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s: - ls_zrecvhdr [%x] (%c)',self::LOGKEY,$c,$c));
/* Here is error */
@@ -1717,7 +1717,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
break;
case self::rhBYTE:
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s: / ls_zrecvhdr [%02x] (%d)',self::LOGKEY,$c,$got));
$hdr[$got] = $c;
@@ -1730,7 +1730,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
break;
case self::rhCRC:
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s: %% ls_zrecvhdr [%02x] (%d|%d)',self::LOGKEY,$c,$crcgot+1,$got));
if ($crcl === 2) {
@@ -1763,7 +1763,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$this->ls_Protocol |= self::LSZ_OPTCRC32;
}
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s:- ls_zrecvhdr CRC%d got [%08x] - calculated [%08x]',self::LOGKEY,(($crcl==2) ? 16 : 32),$incrc,$crc));
if ($incrc != $crc)
@@ -1788,7 +1788,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
/* we need LF after <CR> */
case self::CR:
case self::CR|0x80:
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s:? ls_zrecvhdr rhCR, ignoring any remaining chars [%x]',self::LOGKEY,$c));
/* At this point, most implementations ignore checking for the remaining chars */
@@ -1802,7 +1802,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
case self::XON:
case self::XON|0x80:
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s:? ls_zrecvhdr rhCR, got XON without CR/LF [%x]',self::LOGKEY,$c));
return $frametype;
@@ -1833,7 +1833,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
case self::rhXON:
$state = self::rhInit;
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s: - ls_zrecvhdr rhXON',self::LOGKEY));
switch ($c) {
@@ -2004,11 +2004,11 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
*/
private function ls_zsenddata(string $data,int $frame): int
{
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s:+ ls_zsenddata [%d] (%d)',self::LOGKEY,strlen($data),$frame));
if ($this->ls_Protocol&self::LSZ_OPTCRC32) {
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s: - ls_zsenddata CRC32',self::LOGKEY));
for ($n=0;$n<strlen($data);$n++)
@@ -2037,7 +2037,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$crc >>= 8;
} else {
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s: - ls_zsenddata CRC16',self::LOGKEY));
for ($n=0;$n<strlen($data);$n++) {
@@ -2255,7 +2255,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
case self::ZACK:
$this->ls_txLastACK = $this->ls_fetchlong($this->ls_rxHdr);
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s: - ls_zsendfile ZACK',self::LOGKEY),['ls_rxHdr'=>$this->ls_rxHdr,'ls_txLastACK'=>$this->ls_txLastACK,'ls_rxHdr'=>$this->ls_rxHdr]);
break;
@@ -2522,7 +2522,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
/* Send HEX header. Use CRC16, send var. len. if could */
private function ls_zsendhhdr(int $frametype,array $hdr): int
{
if ($this->DEBUG)
if (static::DEBUG)
Log::debug(sprintf('%s:+ ls_zsendhhdr',self::LOGKEY));
/* Send **<DLE> */