Interface IfaceAware<T extends BinaryMsgIface>
public interface IfaceAware<T extends BinaryMsgIface>
It is common that a
Board class in KOS is linked to physical
hardware using an adapter. The Board class then needs to get
access to the BinaryMsgSession to the adapter in order to create
an instance of the iface used to communicate to the board.
To simplify this process, an adapter can implement the board iface.
This allows HardwareService to automatically detect when the
adapter is started, fetch the board details, and link the physical
board to the logical board without any additional code. However, this
doesn't solve the problem of creating the custom iface instance to
interact with the board.
A board that implements IfaceAware that leverages the board
detection logic mentioned above, will automatically call createIface()
when the board is linked and make the iface available via getIface().
This eliminates the need to override the link callbacks just to
add / remove a custom iface instance.
- Version:
- 2025-04-09
-
Method Summary
Modifier and TypeMethodDescriptioncreateIface(BinaryMsgSession session) Return an instance of the custom iface for the board.default TgetIface()Return the iface instance returned bycreateIface().default TgetIface(boolean throwException) Return the iface instance returned bycreateIface().
-
Method Details
-
createIface
Return an instance of the custom iface for the board. This is called when the adapter for the board connects to java. The iface returned by this method can be accessed viagetIface(). This will be called every time the adapter connects to the board. For removable hardware, this generally corresponds to every time the physical hardware is detected and the linking process is initiated. -
getIface
Return the iface instance returned bycreateIface(). Based on thethrowExceptionflag, this will either return null or throw aBoardUnlinkedExceptionif the board is not currently linked.- Parameters:
throwException- if true, throw exception if board not linked- Returns:
- the iface for the board or null if not linked
-
getIface
Return the iface instance returned bycreateIface(). This will return null if the board isn't linked to physical hardware. Users should check the return value for null, which indicates that the logical board is not linked to the physical hardware.- Returns:
- the iface for the board or null if not linked
-