Skip to content

Commit ec42038

Browse files
committed
Updates
1 parent 1dd3078 commit ec42038

File tree

6 files changed

+18
-17
lines changed

6 files changed

+18
-17
lines changed

src/Constants.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
final class Constants
88
{
9+
public const BlockSize = 8192;
10+
911
public const f1Hz = 1;
1012

1113
public const f20Hz = 1 / 20;

src/Hardware/HasDeviceIoctl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
trait HasDeviceIoctl
1212
{
13-
protected function ioctl(IoctlCommand $command, ?Struct $message = null): int
13+
public function ioctl(IoctlCommand $command, ?Struct $message = null): int
1414
{
1515
assert(is_int($command->value));
1616

src/Hardware/Remote/RemoteCharacterDevice.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Flat3\RevPi\Hardware\Remote;
66

7+
use Flat3\RevPi\Constants;
78
use Flat3\RevPi\Interfaces\Hardware\Stream;
89
use Flat3\RevPi\JsonRpc\Event;
910
use Flat3\RevPi\JsonRpc\JsonRpcPeer;
@@ -39,9 +40,13 @@ public function fdopen(): mixed
3940
});
4041

4142
EventLoop::onReadable($this->remote, function ($callbackId, $stream) {
42-
$data = @fread($stream, 8192);
43-
assert(is_string($data));
44-
$this->write($data, strlen($data));
43+
$data = @fread($stream, Constants::BlockSize);
44+
45+
if (is_string($data) && $data !== '') {
46+
$this->write($data, strlen($data));
47+
} elseif (! is_resource($stream) || @feof($stream)) {
48+
EventLoop::cancel($callbackId);
49+
}
4550
});
4651

4752
return $this->local;

src/Hardware/Virtual/VirtualPiControlDevice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function ioctl(int $request, ?string &$argp = null): int
155155
throw new IoctlFailedException; // @phpstan-ignore deadCode.unreachable
156156
}
157157

158-
protected function reset(): void
158+
public function reset(): void
159159
{
160160
$this->memory = str_repeat("\0", 4096);
161161

src/JsonRpc/JsonRpcPeer.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Amp\Websocket\Server\WebsocketClientHandler;
1212
use Amp\Websocket\WebsocketClient;
1313
use Closure;
14+
use Flat3\RevPi\Constants;
1415
use Flat3\RevPi\Exceptions\NotImplementedException;
1516
use Flat3\RevPi\Exceptions\RemoteDeviceException;
1617
use Flat3\RevPi\Interfaces\Hardware\Device;
@@ -59,13 +60,6 @@ public function withSocket(WebsocketClient $socket): self
5960
return $this;
6061
}
6162

62-
public function withDevice(Device $device): self
63-
{
64-
$this->device = $device;
65-
66-
return $this;
67-
}
68-
6963
/**
7064
* @param JsonRpcMethodT $method
7165
* @param JsonRpcRequestParamsT $params
@@ -149,7 +143,7 @@ public function on(Closure $callback): void
149143
* @param array<string, int|string|null> $params
150144
* @return JsonRpcResponseResultT
151145
*/
152-
public function handle(string $method, array $params): mixed
146+
protected function handle(string $method, array $params): mixed
153147
{
154148
switch ($method) {
155149
case 'open':
@@ -256,12 +250,12 @@ public function handle(string $method, array $params): mixed
256250
$stream = $this->device->fdopen();
257251

258252
EventLoop::onReadable($stream, function ($callbackId, $stream) {
259-
$newData = @fread($stream, 8192);
253+
$data = @fread($stream, Constants::BlockSize);
260254

261-
if (is_string($newData) && $newData !== '') {
255+
if (is_string($data) && $data !== '') {
262256
$request = new Event;
263257
$request->type = 'readable';
264-
$request->payload = $newData;
258+
$request->payload = $data;
265259

266260
$this->socket->sendBinary(serialize($request));
267261
} elseif (! is_resource($stream) || @feof($stream)) {

src/ProcessImage/ProcessImage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function dumpImage(): string
148148
return $buffer;
149149
}
150150

151-
protected function findVariable(string $variable): VariableStruct
151+
public function findVariable(string $variable): VariableStruct
152152
{
153153
$message = new VariableStruct;
154154
$message->varName = $variable;

0 commit comments

Comments
 (0)