Home2L - C/C++ API  v1.2-2-ga4fe (2023-04-15)
Smart Tools for a Private Home
List of all members
CBrownieLink Class Reference

Description

Brownie communication (TWI) link

Definition at line 420 of file brownies.H.

#include "brownies.H"

Public Member Functions

Initialization, open and close ...
 CBrownieLink ()
 
 ~CBrownieLink ()
 
EBrStatus Open (const char *devName=NULL)
 Open link. More...
 
EBrStatus Reopen ()
 Reopen a previously open link.
 
void Close ()
 
const char * IfName ()
 Get the current interface file name.
 
ETwiIfType IfType ()
 Get the current interface type.
 
Accessing buffers and last status ...
TBrRequestRequest ()
 Get pointer to the request buffer (e.g. for filling it).
 
TBrReplyReply ()
 Get pointer to the reply buffer (e.g. for reading it).
 
EBrStatus Status ()
 Get the status of the last operation.
 
Communication primitives ...

For simple use, only Communicate() is needed. SendRequest() and FetchReply() may be used for split transactions with multiple brownies. Flush() and ClearBus() may be used for error maintenance to obtain a clear bus/brownie state.

void ClearBus ()
 Issue bus clock pulses to resolve potential bus locking.
 
void Flush (int adr)
 (Try to) Read and discard a reply to make sure none is pending
 
EBrStatus SendRequest (int adr, bool noResend=false)
 Send a request & perform possible error correction detected during transmission. More...
 
EBrStatus FetchReply (int adr, bool noResend=false)
 Fetch a reply & perform possible error correction. More...
 
EBrStatus Communicate (int adr, bool noResend=false)
 Perform a complete communication cycle including possible error correction. More...
 
Operations ...
EBrStatus CheckDevice (int adr, CBrownie *brownie=NULL)
 Check the device for reachability and (optionally) return its feature and configuration records. More...
 
EBrStatus RegRead (int adr, uint8_t reg, uint8_t *retVal, bool noResend=false)
 
EBrStatus RegRead (CBrownie *brownie, uint8_t reg, uint8_t *retVal, bool noResend=false)
 Read a register.
 
uint8_t RegReadNext (EBrStatus *status, int adr, uint8_t reg, bool noResend=false)
 
uint8_t RegReadNext (EBrStatus *status, CBrownie *brownie, uint8_t reg, bool noResend=false)
 Read a register (alternative arguments). More...
 
EBrStatus RegWrite (int adr, uint8_t reg, uint8_t val, bool noResend=false)
 
EBrStatus RegWrite (CBrownie *brownie, uint8_t reg, uint8_t val, bool noResend=false)
 Write to a register.
 
void RegWriteNext (EBrStatus *status, int adr, uint8_t reg, uint8_t val, bool noResend=false)
 
void RegWriteNext (EBrStatus *status, CBrownie *brownie, uint8_t reg, uint8_t val, bool noResend=false)
 Write a register (alternative arguments, see comment on RegReadNext()).
 
EBrStatus MemRead (int adr, unsigned memAdr, int bytes, uint8_t *retData, bool printProgress=false)
 Read from memory.
 
EBrStatus MemWrite (int adr, unsigned memAdr, int bytes, uint8_t *data, bool printProgress=false)
 Write to memory.
 
Maintenance socket server ...
bool ServerStart ()
 Start the socket server, if configured by 'br.serveSocket'. More...
 
void ServerStop ()
 Stop the socket server (if it was running).
 
bool ServerIterate (TTicks maxSleepTime=-1)
 Perform all socket server services (if enabled). More...
 

Statistics ...

void StatisticsReset (bool local=false)
 Reset all statistics counters. More...
 
const char * StatisticsStr (CString *ret, bool local=false)
 Get the statistics as a readable string. More...
 

Member Function Documentation

◆ Open()

EBrStatus CBrownieLink::Open ( const char *  devName = NULL)

Open link.

Parameters
devNameis the device identifier or NULL to select the default defined by 'br.link'.
Returns
success/error status (also stored in 'status').

◆ SendRequest()

EBrStatus CBrownieLink::SendRequest ( int  adr,
bool  noResend = false 
)

Send a request & perform possible error correction detected during transmission.

The request must be copied before to the buffer returned by Request(). Changes the last status field according to the return value.

Parameters
adris the TWI address.
noResenddisables the resending of the request for error corrections. This is required for reading registers, which are auto-modified by reading (for example, BR_REG_CHANGED or BR_REG_MATRIX_EVENT).
Returns
the error/success status.

◆ FetchReply()

EBrStatus CBrownieLink::FetchReply ( int  adr,
bool  noResend = false 
)

Fetch a reply & perform possible error correction.

In case of an error, SendRequest() is called again since the brownie may have discarded the original request. Hence, the request must not be changed between calling SendRequest() and FetchReply(). Changes the last status field according to the return value. On success, the reply can be fetched from the buffer returned by Reply().

Parameters
adris the TWI address.
noResenddisables the resending of the request for error corrections. This is required for reading registers, which are auto-modified by reading (for example, BR_REG_CHANGED or BR_REG_MATRIX_EVENT).
Returns
the error/success status.

◆ Communicate()

EBrStatus CBrownieLink::Communicate ( int  adr,
bool  noResend = false 
)

Perform a complete communication cycle including possible error correction.

Changes the last status field accordingly to the return value.

Parameters
adris the TWI address.
noResenddisables the resending of the request for error corrections. This is required for reading registers, which are auto-modified by reading (for example, BR_REG_CHANGED or BR_REG_MATRIX_EVENT).
Returns
the error/success status.

◆ CheckDevice()

EBrStatus CBrownieLink::CheckDevice ( int  adr,
CBrownie brownie = NULL 
)

Check the device for reachability and (optionally) return its feature and configuration records.

Parameters
adris the device's TWI address.
brownieis the object into which the ID, the feature, and the configuration record are read. If set to 'NULL', the feature record and firmware version are not checked, no records are returned, and the communication is much simpler and faster.

◆ RegReadNext()

uint8_t CBrownieLink::RegReadNext ( EBrStatus status,
CBrownie brownie,
uint8_t  reg,
bool  noResend = false 
)
inline

Read a register (alternative arguments).

     These methods are optimized for fetching multiple registers. The register contents are returned
     by the return value, and the status field is updated on the fly. If '*status' is not 'brOk'
     on method entry, nothing is done. This allows to read multiple registers without checking the
     status after each single one. 

Definition at line 514 of file brownies.H.

◆ StatisticsReset()

void CBrownieLink::StatisticsReset ( bool  local = false)

Reset all statistics counters.

Parameters
localis only relevant if the link type is ifSocket. If set to 'true', the statistics of the local socket connection are selected, otherwise (by default), the statistics of the remote server are selected.

◆ StatisticsStr()

const char* CBrownieLink::StatisticsStr ( CString ret,
bool  local = false 
)

Get the statistics as a readable string.

Parameters
retis the destination buffer.
localis only relevant if the link type is ifSocket. If set to 'true', the statistics of the local socket connection are selected, otherwise (by default), the statistics of the remote server are selected.

◆ ServerStart()

bool CBrownieLink::ServerStart ( )

Start the socket server, if configured by 'br.serveSocket'.

If none is configured, this method will fail silently. Otherwise, a warning is logged on failure.

Returns
success status.

◆ ServerIterate()

bool CBrownieLink::ServerIterate ( TTicks  maxSleepTime = -1)

Perform all socket server services (if enabled).

Parameters
maxSleepTimeis the maximum time to sleep if a client is connected (<0 = wait unlimited until the connection proceeds). If no client is connected, the method never sleeps.
Returns
'true' if some client is connected and using this link. In this case, the link should not be used locally until 'false' is returned by this method again. Otherwise, 'brNoBus' is returned from all

The documentation for this class was generated from the following file: