84#define BR_CONF_DEFAULT_NAME "brownies.conf"
94const char *
BrMcuStr (
int mcuType,
const char *unknown = NULL);
127struct TBrCfgDescriptor {
137extern const TBrCfgDescriptor brCfgDescList[];
138extern const int brCfgDescs;
173 CBrownie () { features = 0; Clear (); }
178 void SetId (
const char *
id) { strncpy (idRecord,
id,
sizeof (idRecord)); idRecord[
sizeof (idRecord) - 1] =
'\0'; }
179 void SetFeatureRecord (
TBrFeatureRecord *_featureRecord) { featureRecord = *_featureRecord; }
180 void SetConfigRecord (
TBrConfigRecord *_configRecord) { configRecord = *_configRecord; }
181 void SetDatabaseString (
const char *s) { databaseString.Set (s); }
190 const char *
ToStr (
CString *ret,
bool withIdentification =
true,
bool withVersionInfo =
true);
199 const char *
Id () {
return idRecord; }
240 const char *GetOptValue (
CString *ret,
int optIdx);
241 bool SetOptValue (
int optIdx,
const char *str);
252 friend class CBrRcDriver;
254 class CBrFeature *featureList[8];
283 void CheckExpiration ();
310 CBrownie *Get (
const char *
id) {
int *pAdr = adrMap.Get (
id);
return pAdr ? Get (*pAdr) : NULL; }
311 CBrownie *
Get (
int adr) {
return (adr < 0 || adr > 127) ? NULL : brList[adr]; }
376 int rcLastCheckedAdr;
410struct TSocketHeader {
510 EBrStatus RegRead (
int adr, uint8_t reg, uint8_t *retVal,
bool noResend =
false);
513 uint8_t RegReadNext (
EBrStatus *status,
int adr, uint8_t reg,
bool noResend =
false);
521 EBrStatus RegWrite (
int adr, uint8_t reg, uint8_t val,
bool noResend =
false);
524 void RegWriteNext (
EBrStatus *status,
int adr, uint8_t reg, uint8_t val,
bool noResend =
false);
528 EBrStatus MemRead (
int adr,
unsigned memAdr,
int bytes, uint8_t *retData,
bool printProgress =
false);
530 EBrStatus MemWrite (
int adr,
unsigned memAdr,
int bytes, uint8_t *data,
bool printProgress =
false);
575 void TwiOpen (
bool warn);
578 EBrStatus TwiSend (
int adr,
const void *buf,
int bytes);
579 EBrStatus TwiFetch (
int adr,
void *buf,
int bytes);
590 TTicks tLastStatisticsReset;
591 int requests, requestRetries[brEND], requestFailures[brEND];
592 int replies, replyRetries[brEND], replyFailures[brEND];
595 TTicks rcTSumCycle, rcTSumFastPoll, rcTSumSlowPoll;
596 TTicks rcTCycleMin, rcTCycleMax, rcTFastPollMin, rcTFastPollMax, rcTSlowPollMin, rcTSlowPollMax;
601 TSocketHeader sockHead;
Brownie communication (TWI) link
EBrStatus RegWrite(CBrownie *brownie, uint8_t reg, uint8_t val, bool noResend=false)
Write to a register.
EBrStatus RegRead(CBrownie *brownie, uint8_t reg, uint8_t *retVal, bool noResend=false)
Read a register.
EBrStatus SendRequest(int adr, bool noResend=false)
Send a request & perform possible error correction detected during transmission.
uint8_t RegReadNext(EBrStatus *status, CBrownie *brownie, uint8_t reg, bool noResend=false)
Read a register (alternative arguments).
EBrStatus MemRead(int adr, unsigned memAdr, int bytes, uint8_t *retData, bool printProgress=false)
Read from memory.
EBrStatus Reopen()
Reopen a previously open link.
ETwiIfType IfType()
Get the current interface type.
void ServerStop()
Stop the socket server (if it was running).
void ClearBus()
Issue bus clock pulses to resolve potential bus locking.
TBrRequest * Request()
Get pointer to the request buffer (e.g. for filling it).
void StatisticsReset(bool local=false)
Reset all statistics counters.
EBrStatus CheckDevice(int adr, CBrownie *brownie=NULL)
Check the device for reachability and (optionally) return its feature and configuration records.
bool ServerIterate(TTicks maxSleepTime=-1)
Perform all socket server services (if enabled).
EBrStatus FetchReply(int adr, bool noResend=false)
Fetch a reply & perform possible error correction.
TBrReply * Reply()
Get pointer to the reply buffer (e.g. for reading it).
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 Open(const char *devName=NULL)
Open link.
const char * IfName()
Get the current interface file name.
EBrStatus MemWrite(int adr, unsigned memAdr, int bytes, uint8_t *data, bool printProgress=false)
Write to memory.
const char * StatisticsStr(CString *ret, bool local=false)
Get the statistics as a readable string.
EBrStatus Communicate(int adr, bool noResend=false)
Perform a complete communication cycle including possible error correction.
void Flush(int adr)
(Try to) Read and discard a reply to make sure none is pending
bool ServerStart()
Start the socket server, if configured by 'br.serveSocket'.
EBrStatus Status()
Get the status of the last operation.
void Del(int adr)
Delete database entry.
void ResourcesInit(CRcEventDriver *_rcDriver, class CBrownieLink *_rcLink)
Register all resources and assign a driver and link to the Brownie set.
void ResourcesDone()
Forget about the driver / link and clean up all resources-related data.
void ResourcesIterate(bool noLink=false, bool noSleep=false)
Query Brownies and report any pending resource changes.
bool WriteDatabase(const char *fileName=NULL)
Write the set as a database file.
CBrownie * Get(int adr)
Get a reference to the brownie for reading. To modify a brownie object, it must be first removed and ...
CBrownie * Unlink(int adr)
Forget brownie and return it (caller becomes owner of CBrownie object).
void Set(CBrownie *brownie)
Add/Change brownie (takes ownership of CBrownie object).
bool ReadDatabase(const char *fileName=NULL)
Read a database file.
Representation of a Brownie device.
bool IsCompatible(const char *_databaseString)
Check if the current object, typically read back from a device, is compatible to the passed database ...
const char * ToStr(CString *ret, bool withIdentification=true, bool withVersionInfo=true)
Return the contents of the feature record and the config record as a string in the database syntax.
TBrConfigRecord * ConfigRecord()
Get the config record.
bool IsValid()
Data is generally valid.
bool UpdateFromDevice(class CBrownieLink *link)
Read out device, check for compatibility, and update the feature record and config record on success.
bool HasDeviceConfig()
Config record is valid and comes from the device.
int Adr()
Get the TWI address of the Brownie.
bool HasDeviceFeatures()
Feature record is valid and comes from the device.
bool HasFeatures()
Feature record appears to be valid (either set from database or from device).
const char * Id()
Get the ID record (a null-terminated string).
bool SetFromStr(const char *str, CString *ret=NULL)
Set fields in the feature record or config record according to a text line in database string syntax.
const char * DatabaseString()
Get options set in the database file as a string.
TBrFeatureRecord * FeatureRecord()
Get the feature record.
Driver for local resources.
Local driver using the event processor mechanism for the 'DriveValue()' functionality.
Typed value tagged with a state and a time stamp.
Dynamically allocated string.
char * Get() const
Get the C string. Unless explicitely set by 'SetC', this will never return NULL or an invalid pointer...
#define BR_MAGIC
Magic byte value to identify this device as a brownie.
char TBrIdRecord[32]
Brownie ID (stored in EEPROM).
const char * envBrDatabaseFile
Name of the selected database file (read-only).
static const char * BrVersionGetAsStr(CString *ret, TBrFeatureRecord *featureRecord)
Get a readable string of the version fields of the feature record. The result is written to '*ret' an...
const char * envBrLinkDev
Name of the selected link device (read-only).
const char * BrMcuStr(int mcuType, const char *unknown=NULL)
Get a readable string (for example, "t84") for an MCU model ID (see BR_MCU_* macros)....
uint32_t BrVersionGet(TBrFeatureRecord *featureRecord)
Retrieve version from feature record.
bool BrFeaturesFromStr(TBrFeatureRecord *featureRecord, const char *str)
Set the feature-related fields of the feature record according to the given string.
int BrMcuFromStr(const char *mcuStr)
Get the MCU model ID (see BR_MCU_* macros) from a string (for example, "t84"). On error,...
const char * BrFeaturesToStr(CString *ret, TBrFeatureRecord *featureRecord)
Get a readable string of the feature-related fields of the feature record. The result is written to '...
const char * BrStatusStr(EBrStatus s)
Get a readable string for Brownie status codes.
bool BrVersionFromStr(TBrFeatureRecord *featureRecord, const char *str)
Set the version fields of the feature record according to the given version string.
ETwiIfType
Brownie link interface type.
@ ifSocket
Unix domain socket (to connect to already running Brownie driver instance on the local machine)
int64_t TTicks
Time value (relative, absolute, or monotonic).
const char * VersionToStr(class CString *ret, uint32_t ver)
Get a string representation of the version. This may be shorter than an eventual original string pass...
Brownie configuration record (stored in EEPROM).
uint8_t adr
Own TWI address.
uint8_t magic
Identify as a Brownie (should always be BR_MAGIC)
Brownie feature record (stored in VROM).
uint8_t magic
Brownie identification (always = BR_MAGIC)
uint16_t gpiPresence
GPIO input presence mask (must be disjoint with output presence)
uint16_t features
Feature presence (see BR_FEATURE_... masks)
uint16_t gpoPresence
GPIO output presence mask (must be disjoint with input presence)