Just optimisations

This commit is contained in:
Deon George
2019-05-20 17:18:18 +10:00
parent 9317f78a3a
commit df849c0cfd
12 changed files with 877 additions and 519 deletions

View File

@@ -66,16 +66,6 @@ class FTNPacket extends FTN
{
$this->messages = collect();
// @todo - is this appropriate to set here
$this->date = now();
$this->software['prodcode-lo'] = 0;
$this->software['prodcode-hi'] = 1;
$this->software['rev-maj'] = 2;
$this->software['rev-min'] = 3;
$this->cap['valid'] = 0; // @todo this is wrong
$this->cap['word'] = 0; // @todo this is wrong
$this->pktver = 0x02;
if ($file) {
$this->filename = $file;
@@ -83,8 +73,42 @@ class FTNPacket extends FTN
}
}
public function __get($k)
{
switch ($k)
{
case 'fz': return ftn_address_split($this->pktsrc,'z');
case 'fn': return ftn_address_split($this->pktsrc,'n');
case 'ff': return ftn_address_split($this->pktsrc,'f');
case 'fp': return ftn_address_split($this->pktsrc,'p');
case 'tz': return ftn_address_split($this->pktdst,'z');
case 'tn': return ftn_address_split($this->pktdst,'n');
case 'tf': return ftn_address_split($this->pktdst,'f');
case 'tp': return ftn_address_split($this->pktdst,'p');
default:
return isset($this->{$k}) ? $this->{$k} : NULL;
}
}
public function __toString(): string
{
// @todo - is this appropriate to set here
$this->date = now();
$this->pktsrc = '10:1/5.0';
$this->pktdst = '10:1/0.0';
$this->software['prodcode-lo'] = 0x00;
$this->software['prodcode-hi'] = 0xde;
$this->software['rev-maj'] = 0x00;
$this->software['rev-min'] = 0x01;
// Type 2+ Packet
$this->cap['valid'] = 0x0100;
$this->cap['word'] = 0x0001;
$this->pktver = 0x0002;
$return = $this->createHeader();
foreach ($this->messages as $o)
@@ -102,8 +126,8 @@ class FTNPacket extends FTN
{
try {
$a = pack(join('',collect($this->pack1)->pluck(1)->toArray()),
$this->sf,
$this->df,
$this->ff,
$this->tf,
$this->date->year,
$this->date->month,
$this->date->day,
@@ -112,27 +136,27 @@ class FTNPacket extends FTN
$this->date->second,
$this->baud,
$this->pktver,
$this->sn,
$this->dn,
$this->software['prodcode-lo'], // @todo change to this software
$this->software['rev-maj'] // @todo change to this software
$this->fn, // @todo if point, this needs to be 0xff
$this->tn,
$this->software['prodcode-lo'], // @todo change to this software
$this->software['rev-maj'] // @todo change to this software
);
$b = pack(join('',collect($this->pack2)->pluck(1)->toArray()),
$this->sz,
$this->dz,
0x00, // Baud
$this->cap['valid'], // @todo to check
$this->software['prodcode-hi'], // @todo change to this software
$this->software['rev-min'], // @todo change to this software
$this->cap['word'], // @todo to check
$this->sz,
$this->dz,
$this->sp,
$this->dp
0x0000, // @note: Type 2 packet this is $this->sz,
0x0000, // @note: Type 2 packet this is $this->dz,
0x0000, // Filler $this->>sn if message to point.
$this->cap['valid'], // @todo to check
$this->software['prodcode-hi'], // @todo change to this software
$this->software['rev-min'], // @todo change to this software
$this->cap['word'], // @todo to check
$this->fz,
$this->tz,
$this->fp, // @note: point address, type 2+ packets
$this->tp // @note: point address, type 2+ packets
);
return $a.pack('a8',$this->password).$b."mbse"; // @todo change to this software
return $a.pack('a8',strtoupper($this->password)).$b."mbse"; // @todo change to this software
} catch (\Exception $e) {
return $e->getMessage();
@@ -185,7 +209,7 @@ class FTNPacket extends FTN
// Messages start with 02H 00H
if (strlen($x) == 2 AND $x != "\02\00")
throw new InvalidFidoPacketException('Not a valid packet: '.$x);
throw new InvalidFidoPacketException('Not a valid packet: '.bin2hex($x));
// No message attached
else if (! strlen($x))
@@ -222,6 +246,7 @@ class FTNPacket extends FTN
$result2 = unpack($this->unpackheader($this->pack2),substr($header,0x22,0x14));
$this->proddata = array_get(unpack('A*p',substr($header,0x36,4)),'p');
// @todo replcae these vars with the tz/fz
$this->sz = array_get($result2,'ozone');
$this->sn = array_get($result1,'onet');
$this->sf = array_get($result1,'onode');