Home2L - C/C++ API v1.4-0-g38cc (2024-05-25)
Smart Tools for a Private Home
|
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 ... | |
TBrRequest * | Request () |
Get pointer to the request buffer (e.g. for filling it). | |
TBrReply * | Reply () |
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... | |
EBrStatus CBrownieLink::Open | ( | const char * | devName = NULL | ) |
Open link.
devName | is the device identifier or NULL to select the default defined by 'br.link'. |
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.
adr | is the TWI address. |
noResend | disables 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). |
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().
adr | is the TWI address. |
noResend | disables 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). |
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.
adr | is the TWI address. |
noResend | disables 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). |
Check the device for reachability and (optionally) return its feature and configuration records.
adr | is the device's TWI address. |
brownie | is 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. |
|
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.
void CBrownieLink::StatisticsReset | ( | bool | local = false | ) |
Reset all statistics counters.
local | is 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. |
const char * CBrownieLink::StatisticsStr | ( | CString * | ret, |
bool | local = false |
||
) |
Get the statistics as a readable string.
ret | is the destination buffer. |
local | is 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. |
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.
bool CBrownieLink::ServerIterate | ( | TTicks | maxSleepTime = -1 | ) |
Perform all socket server services (if enabled).
maxSleepTime | is 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. |