Skip to content

Commit 4e1455c

Browse files
committed
Updates
1 parent 12f28d2 commit 4e1455c

File tree

13 files changed

+375
-3
lines changed

13 files changed

+375
-3
lines changed

src/Interfaces/Hardware/Device.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,45 @@
44

55
namespace Flat3\RevPi\Interfaces\Hardware;
66

7+
/**
8+
* Interface Device
9+
*
10+
* Defines the basic contract for a hardware device, allowing it to be opened, closed,
11+
* and support reading and writing data.
12+
*/
713
interface Device
814
{
15+
/**
16+
* Open a connection to the device specified by its pathname.
17+
*
18+
* @param string $pathname The device file or resource path.
19+
* @param int $flags Flags to control how the device is opened.
20+
* @return int Returns a resource handle or file descriptor on success, or -1 on failure.
21+
*/
922
public function open(string $pathname, int $flags): int;
1023

24+
/**
25+
* Close the connection to the device.
26+
*
27+
* @return int Returns 0 on success or -1 on failure.
28+
*/
1129
public function close(): int;
1230

31+
/**
32+
* Read from the device into the provided buffer.
33+
*
34+
* @param string $buffer Variable to store the read data (passed by reference).
35+
* @param int $count Maximum number of bytes to read.
36+
* @return int The number of bytes read, or -1 on error.
37+
*/
1338
public function read(string &$buffer, int $count): int;
1439

40+
/**
41+
* Write data to the device.
42+
*
43+
* @param string $buffer The data to write.
44+
* @param int $count Number of bytes to write.
45+
* @return int The number of bytes written, or -1 on error.
46+
*/
1547
public function write(string $buffer, int $count): int;
1648
}

src/Interfaces/Hardware/Ioctl.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@
44

55
namespace Flat3\RevPi\Interfaces\Hardware;
66

7+
/**
8+
* Interface Ioctl
9+
*
10+
* Hardware abstraction for devices supporting ioctl operations.
11+
*/
712
interface Ioctl
813
{
14+
/**
15+
* Perform an ioctl operation on the device.
16+
*
17+
* @param int $request The ioctl request code.
18+
* @param string|null $argp Optional; additional argument for the ioctl operation, passed by reference.
19+
* @return int The result code from the ioctl system call.
20+
*/
921
public function ioctl(int $request, ?string &$argp = null): int;
1022
}

src/Interfaces/Hardware/IoctlCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44

55
use BackedEnum;
66

7+
/**
8+
* Interface IoctlCommand
9+
*
10+
* Represents an IOCTL (input/output control) command.
11+
*/
712
interface IoctlCommand extends BackedEnum {}

src/Interfaces/Hardware/PiControl.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,14 @@
44

55
namespace Flat3\RevPi\Interfaces\Hardware;
66

7+
/**
8+
* Interface PiControl
9+
*
10+
* Represents a PiControl hardware component, combining device operations,
11+
* IOCTL (input/output control), and seek capabilities.
12+
*
13+
* @see Device
14+
* @see Ioctl
15+
* @see Seek
16+
*/
717
interface PiControl extends Device, Ioctl, Seek {}

src/Interfaces/Hardware/Seek.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@
44

55
namespace Flat3\RevPi\Interfaces\Hardware;
66

7+
/**
8+
* Interface Seek
9+
*
10+
* Provides an interface for seeking within a hardware context, such as moving a file pointer
11+
* or device resource to a specific position.
12+
*/
713
interface Seek
814
{
15+
/**
16+
* Set the position of the resource pointer.
17+
*
18+
* Moves the pointer to a specific offset, relative to the position defined by $whence.
19+
*
20+
* @param int $offset The position to move to, measured in bytes.
21+
* @param int $whence The reference position for the offset; one of SEEK_SET, SEEK_CUR, or SEEK_END.
22+
* @return int The new position of the pointer on success.
23+
*/
924
public function lseek(int $offset, int $whence): int;
1025
}

src/Interfaces/Hardware/Stream.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@
44

55
namespace Flat3\RevPi\Interfaces\Hardware;
66

7+
/**
8+
* Interface Stream
9+
*
10+
* Represents a hardware stream that can provide a file descriptor resource.
11+
*/
712
interface Stream
813
{
9-
/** @return resource */
14+
/**
15+
* Open or retrieve a file descriptor resource for the stream.
16+
*
17+
* @return resource The file descriptor resource associated with the stream.
18+
*/
1019
public function fdopen(): mixed;
1120
}

src/Interfaces/Hardware/Struct.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,31 @@
44

55
namespace Flat3\RevPi\Interfaces\Hardware;
66

7+
/**
8+
* Interface Struct
9+
*
10+
* Interface for packable and unpackable binary structure representations.
11+
*/
712
interface Struct
813
{
14+
/**
15+
* Packs the current data structure into a binary string.
16+
*
17+
* @return string The packed binary representation of this structure.
18+
*/
919
public function pack(): string;
1020

21+
/**
22+
* Unpacks the given binary buffer into this data structure.
23+
*
24+
* @param string $buffer The binary buffer to unpack into this structure.
25+
*/
1126
public function unpack(string $buffer): void;
1227

28+
/**
29+
* Returns the length in bytes of the packed data structure.
30+
*
31+
* @return int The length in bytes.
32+
*/
1333
public function length(): int;
1434
}

src/Interfaces/Hardware/Terminal.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,68 @@
44

55
namespace Flat3\RevPi\Interfaces\Hardware;
66

7+
/**
8+
* Interface Terminal
9+
*
10+
* Represents terminal communication capabilities common to hardware serial interfaces.
11+
* Extends Device, Ioctl, and Stream interfaces.
12+
*/
713
interface Terminal extends Device, Ioctl, Stream
814
{
15+
/**
16+
* Get the input baud rate stored in the termios buffer.
17+
*
18+
* @param string &$buffer The termios structure buffer (passed by reference).
19+
* @return int The input baud rate, or -1 on failure.
20+
*/
921
public function cfgetispeed(string &$buffer): int;
1022

23+
/**
24+
* Get the output baud rate stored in the termios buffer.
25+
*
26+
* @param string &$buffer The termios structure buffer (passed by reference).
27+
* @return int The output baud rate, or -1 on failure.
28+
*/
1129
public function cfgetospeed(string &$buffer): int;
1230

31+
/**
32+
* Set the input baud rate in the termios buffer.
33+
*
34+
* @param string &$buffer The termios structure buffer (passed by reference).
35+
* @param int $speed The new input baud rate to set.
36+
* @return int Returns 0 on success, -1 on failure.
37+
*/
1338
public function cfsetispeed(string &$buffer, int $speed): int;
1439

40+
/**
41+
* Set the output baud rate in the termios buffer.
42+
*
43+
* @param string &$buffer The termios structure buffer (passed by reference).
44+
* @param int $speed The new output baud rate to set.
45+
* @return int Returns 0 on success, -1 on failure.
46+
*/
1547
public function cfsetospeed(string &$buffer, int $speed): int;
1648

49+
/**
50+
* Discard data in the input/output queue.
51+
*
52+
* @param int $queue_selector Selector indicating which queue(s) to flush (e.g., TCIFLUSH, TCOFLUSH).
53+
* @return int Returns 0 on success, or -1 on failure.
54+
*/
1755
public function tcflush(int $queue_selector): int;
1856

57+
/**
58+
* Wait until all output written to the terminal is transmitted.
59+
*
60+
* @return int Returns 0 on success, or -1 on failure.
61+
*/
1962
public function tcdrain(): int;
2063

64+
/**
65+
* Transmit a continuous stream of zero bits for a specific duration.
66+
*
67+
* @param int $duration Duration to send the break (in 0.25s units), default is 0 for 0.25 seconds.
68+
* @return int Returns 0 on success, or -1 on failure.
69+
*/
2170
public function tcsendbreak(int $duration = 0): int;
2271
}

src/Interfaces/Led.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,22 @@
88

99
interface Led
1010
{
11+
/**
12+
* Set the LED to the specified colour.
13+
*
14+
* @param LedColour $colour The colour to set the LED.
15+
*/
1116
public function set(LedColour $colour): void;
1217

18+
/**
19+
* Get the current colour of the LED.
20+
*
21+
* @return LedColour The current colour of the LED.
22+
*/
1323
public function get(): LedColour;
1424

25+
/**
26+
* Turn off the LED.
27+
*/
1528
public function off(): void;
1629
}

src/Interfaces/Module.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,46 @@
77
use Flat3\RevPi\Led\LedPosition;
88
use Flat3\RevPi\Monitors\Monitor;
99

10+
/**
11+
* Interface Module
12+
*
13+
* Represents a hardware module in the RevPi ecosystem, providing methods for controlling
14+
* LEDs, accessing process images, monitoring, and serial port access.
15+
*/
1016
interface Module
1117
{
18+
/**
19+
* Get a LED instance at the specified position.
20+
*
21+
* @param LedPosition $position The position of the LED to retrieve.
22+
* @return Led The LED instance at the specified position.
23+
*/
1224
public function getLed(LedPosition $position): Led;
1325

26+
/**
27+
* Obtain the process image associated with this module.
28+
*
29+
* @return ProcessImage The process image of the module.
30+
*/
1431
public function getProcessImage(): ProcessImage;
1532

33+
/**
34+
* Resume normal operation for the module after a pause or reset.
35+
*/
1636
public function resume(): void;
1737

38+
/**
39+
* Attach a monitor to the module for status tracking or event watching.
40+
*
41+
* @param Monitor $monitor The monitor instance to attach.
42+
*/
1843
public function monitor(Monitor $monitor): void;
1944

45+
/**
46+
* Get a serial port instance for communication on the specified device path.
47+
*
48+
* @param string $devicePath The path to the serial device (e.g. "/dev/ttyS0").
49+
* @return SerialPort The serial port instance.
50+
*/
2051
public function getSerialPort(string $devicePath): SerialPort;
2152
}

0 commit comments

Comments
 (0)