Module Class

class Module

The Module class provides a generic interface to a BrainStem hardware module. The Module class is the parent class for all BrainStem modules. Each module inherits from Module and implements its hardware specific features.

Public Functions

Module(const uint8_t address)

Constructor. Implicitly creates a link object with no specifier. Most often objects created with this constructor will use linkDiscoverAndConnect to find and connect to a module.

Parameters
  • address: The BrainStem network address of the module. The default address (or base address for modules that support address offsets) is defined in each module’s “Defs.h” header.

virtual ~Module(void)

Destructor.

aErr connect(const linkType type, const uint32_t serialNum)

Connect using the current link specifier.

Return
aErrBusy - if the module is already in use.
Return
aErrParam - if the type is incorrect or serialNum is not specified
Return
aErrNotFound - if the module cannot be found.
Return
aErrNone If the connect was successful.
Parameters
  • type: - Transport on which to search for available BrainStem link modules. See the transport enum for supported transports.
  • serialNum: - Specify a serial number to connect to a specific link module. Use 0 to connect to the first link module found.

aErr connectFromSpec(const linkSpec linkSpecifier)

Connect to a link with a fully defined specifier.

Return
aErrInitialization - If there is currently no link object.
Return
aErrBusy - If the link is currently connected.
Return
aErrParam - if the specifier is incorrect.
Return
aErrNotFound - if the module cannot be found.
Return
aErrNone If the connect was successful.
Parameters
  • linkSpecifier: - Connect to module with specifier.

aErr discoverAndConnect(linkType type, const uint32_t serialNum = 0)

A discovery-based connect. This member function will connect to the first available BrainStem found on the given transport. If the serial number is passed, it will only connect to the module with that serial number. Passing 0 as the serial number will create a link to the first link module found on the specified transport. If a link module is found on the specified transport, a connection will

Return
aErrBusy - if the module is already in use.
Return
aErrParam - if the transport type is undefined.
Return
aErrNotFound - if the module cannot be found.
Return
aErrNone If the connect was successful.
Parameters
  • type: - Transport on which to search for available BrainStem link modules. See the transport enum for supported transports.
  • serialNum: - Specify a serial number to connect to a specific link module. Use 0 to connect to the first link module found.

aErr connectThroughLinkModule(Module *pModule)

Connect using link from another Module. This member function will connect to the same BrainStem used by given Module. If a link module is found on the specified transport, a connection will

Return
aErrParam - if the module is undefined.
Return
aErrNone - if the connect was successful.
Parameters
  • pModule: - Pointer to a valid Module class object.

bool isConnected(void)

Is the link connected to the BrainStem Module.

linkStatus getStatus(void)

Check the status of the BrainStem module connection.

Return
linkStatus (see aLink.h for status values)

aErr disconnect(void)

Disconnect from the BrainStem module.

Return
aErrResource - If the there is no valid connection.
Return
aErrConnection - If the disconnect failed, due to a communication issue.
Return
aErrNone If the disconnect was successful.

aErr reconnect()

Reconnect using the current link specifier.

Return
aErrBusy - if the module is already in use.
Return
aErrParam - if the specifier is incorrect.
Return
aErrNotFound - if the module cannot be found.
Return
aErrNone If the connect was successful.

Link *getLink(void) const

Get the current link object.

Return
The link associated with the module.

uint8_t getModuleAddress(void) const

Accessor to get the address of the BrainStem module associated with the instance on the host machine. (Not to be confused with the System entity which effects the device hardware.)

Return
The module address.

void setModuleAddress(const uint8_t address)

Accessor to set the address of the BrainStem module associated with the instance on the host machine. (Not to be confused with the System entity which effects the device hardware.)

Parameters
  • address: The module address.

aErr getLinkSpecifier(linkSpec *spec)

Get linkSpecifier

Return
aErrNone - If the module does not have a spec.
Parameters
  • spec: - allocated linkspec struct will be filled with spec.

aErr hasUEI(const uint8_t command, const uint8_t option, const uint8_t index, const uint8_t flags)

Queries the module to determine if it implements a UEI. Each UEI has a command, option or variant, index and flag. The hasUEI method queries for a fully specified UEI. Returns aErrNone if the variation is supported and an appropriate error if not. This call is blocking for up to the nMSTimeout period.

Return
aErrNone - The module supports this command and access flags.
Return
aErrMode - The module supports the command but not the access flag.
Return
aErrNotFound - The module does not support the command, option, or index.
Return
aErrTimeout - The request timed out without a response.
Return
aErrConnection - There is no active link
Parameters
  • command: One of the UEI commands (cmdXXX).
  • option: The option or variant of the command.
  • index: The entity index.
  • flags: The flags (ueiOPTION_SET or ueiOPTION_GET).

aErr classQuantity(const uint8_t command, uint8_t *count)

Queries the module to determine how many entities of the specified class are implemented by the module. Zero is a valid return value. For example, calling classQuantity with the command parameter of cmdANALOG would return the number of analog entities implemented by the module.

Return
aErrNone - Success.
Return
aErrTimeout - The request timed out without a response.
Return
aErrConnection - There is no active link.
Parameters
  • command: One of UEI commands (cmdXXX).
  • count: When the request is successful count is updated with the number of entities found.

aErr subClassQuantity(const uint8_t command, const uint8_t index, uint8_t *count)

Queries the module to determine how many subclass entities of the specified class are implemented by the module for a given entity index. This is used for entities which may be 2-dimensional. E.g. cmdMUX subclasses are the number of channels supported by a particular mux type (index); as a specific example, a module may support 4 UART channels, so subClassQuantity(cmdMUX, aMUX_UART…) could return 4. Zero is a valid return value.

Return
aErrNone - Success.
Return
aErrTimeout - The request timed out waiting for response.
Return
aErrConnection - There is no active link.
Parameters
  • command: One of the UEI commands (cmdXXX).
  • index: The entity index.
  • count: The number of subclasses found.

aErr entityGroup(const uint8_t command, const uint8_t index, uint8_t *group)

Queries the module the group assigned to an entity and index. Entities groups are used to specify when certain hardware features are fundamentally related. E.g. certain hardware modules may have some digital pins associated with an adjustable voltage rail; these digitals would be in the same group as the rail. Zero is the default group.

Return
aErrNone - Success.
Return
aErrTimeout - The request timed out without response.
Return
aErrConnection - There is no active link.
Parameters
  • command: One of the UEI commands (cmdXXX).
  • index: The entity index.
  • group: Upon success, group is filled with the entities group value.

aErr debug(const uint8_t *pData, const uint8_t length)

Sends a debug packet to the module containing the provided data. Modules receiving debug packets simply echo the packet back to the sender. If the round-trip is successful, the reply data will match the data sent. This method returns aErrNone when successful, if not successful, an appropriate error is returned.

Return
aErrNone - Success.
Return
aErrTimeout - Timeout occured without response.
Return
aErrConnection - No active link exists.
Parameters
  • pData: A pointer to an array of data to be sent in the debug packet.
  • length: The length of the data array.

void setNetworkingMode(const bool mode)

Sets the networking mode of the module object. By default the module object is configure to automatically adjust its address based on the devices current module address. So that, if the device has a software or hardware offset it will still be able to communication with the device. If advanced networking is required the auto networking mode can be turned off.

Parameters
  • mode: True/1 for Auto Networking, False/0 for manual networking