Skip to content

Commit

Permalink
(#647) cleaned up Log internal api
Browse files Browse the repository at this point in the history
  • Loading branch information
knmcguire committed Nov 16, 2020
1 parent 212f66e commit 64be05f
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 35 deletions.
10 changes: 5 additions & 5 deletions examples/demos/app_push_demo/src/push.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ void appMain()

vTaskDelay(M2T(3000));

uint16_t idUp = logGetVarId("range", "up");
uint16_t idLeft = logGetVarId("range", "left");
uint16_t idRight = logGetVarId("range", "right");
uint16_t idFront = logGetVarId("range", "front");
uint16_t idBack = logGetVarId("range", "back");
logVarId_t idUp = logGetVarId("range", "up");
logVarId_t idLeft = logGetVarId("range", "left");
logVarId_t idRight = logGetVarId("range", "right");
logVarId_t idFront = logGetVarId("range", "front");
logVarId_t idBack = logGetVarId("range", "back");

paramVarId_t idPositioningDeck = paramGetVarId("deck", "bcFlow2");
paramVarId_t idMultiranger = paramGetVarId("deck", "bcMultiranger");
Expand Down
18 changes: 9 additions & 9 deletions examples/demos/swarm_demo/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ static uint8_t trajectoryCount = 255;
static uint8_t remainingTrajectories = 0;

// Log and param ids
static uint16_t logIdStateEstimateX;
static uint16_t logIdStateEstimateY;
static uint16_t logIdStateEstimateZ;
static uint16_t logIdKalmanVarPX;
static uint16_t logIdKalmanVarPY;
static uint16_t logIdKalmanVarPZ;
static uint16_t logIdPmState;
static uint16_t logIdlighthouseEstBs0Rt;
static uint16_t logIdlighthouseEstBs1Rt;
static logVarId_t logIdStateEstimateX;
static logVarId_t logIdStateEstimateY;
static logVarId_t logIdStateEstimateZ;
static logVarId_t logIdKalmanVarPX;
static logVarId_t logIdKalmanVarPY;
static logVarId_t logIdKalmanVarPZ;
static logVarId_t logIdPmState;
static logVarId_t logIdlighthouseEstBs0Rt;
static logVarId_t logIdlighthouseEstBs1Rt;

static paramVarId_t paramIdStabilizerController;
static paramVarId_t paramIdCommanderEnHighLevel;
Expand Down
2 changes: 1 addition & 1 deletion src/deck/drivers/src/usddeck.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ void usddeckTriggerLogging(void)
memcpy(usdLogBuffer, &ticks, 4);
int offset = 4;
for (int i = 0; i < usdLogConfig.numSlots; ++i) {
int varid = usdLogConfig.varIds[i];
logVarId_t varid = usdLogConfig.varIds[i];
switch (logGetType(varid)) {
case LOG_UINT8:
case LOG_INT8:
Expand Down
85 changes: 77 additions & 8 deletions src/modules/interface/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,84 @@
void logInit(void);
bool logTest(void);

/* Internal access of log variables */
int logGetVarId(char* group, char* name);
int logGetType(int varid);
void logGetGroupAndName(int varid, char** group, char** name);
void* logGetAddress(int varid);
/* Public API to access of log variables */

/** Variable identifier.
*
* Should be fetched with logGetVarId(). This is to be considered as an
* opaque type, internal structure might change.
*
* Use LOG_VARID_IS_VALID() to check if the ID is valid.
*/
typedef uint16_t logVarId_t;

/** Get the varId from group and name of variable
*
* @param group Group name of the variable
* @param name Name of the variable
* @return The variable ID or an invalid ID. Use LOG_VARID_IS_VALID() to check validity.
*/
logVarId_t logGetVarId(char* group, char* name);

/** Check variable ID validity
*
* @param varId variable ID, returned by logGetLogId()
* @return true if the variable ID is valid, false otherwise.
*/
#define LOG_VARID_IS_VALID(varId) (varId != 0xffffu)

/** Return the logging type
*
* @param varId variable ID, returned by logGetVarId()
* @return Type of the variable. The value correspond to the defines used when
* declaring a param variable.
*/
int logGetType(logVarId_t varid);

/** Get group and name strings of a parameter
*
* @param varId variable ID, returned by logGetVarId()
* @param group Pointer to a char* that will be filled with the group name
* @param group Pointer to a char* that will be filled with the variable name
*
* The string buffers must be able to hold at least 32 bytes.
*/
void logGetGroupAndName(logVarId_t varid, char** group, char** name);

/** Get address of the logging variable
*
* @param varId variable ID, returned by logGetVarId()
* @return Address of the location of log variable
* */
void* logGetAddress(logVarId_t varid);

/** Get log variable size in byte
*
* @param type Type returned by logGetType()
* @return Size in byte occupied by variable of this type
*/
uint8_t logVarSize(int type);
float logGetFloat(int varid);
int logGetInt(int varid);
unsigned int logGetUint(int varid);

/** Return float value of a logging variable
*
* @param varId variable ID, returned by logGetVarId()
* @return Current value of the variable
*/
float logGetFloat(logVarId_t varid);

/** Return int value of a logging variable
*
* @param varId variable ID, returned by logGetVarId()
* @return Current value of the variable
*/
int logGetInt(logVarId_t varid);

/** Return Unsigned int value of a logging variable
*
* @param varId variable ID, returned by paramGetVarId()
* @return Current value of the variable
*/
unsigned int logGetUint(logVarId_t varid);

/* Basic log structure */
struct log_s {
Expand Down
29 changes: 17 additions & 12 deletions src/modules/src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,29 +960,34 @@ static void logReset(void)
}

/* Public API to access log TOC from within the copter */
int logGetVarId(char* group, char* name)
static logVarId_t invalidVarId = 0xffffu;

logVarId_t logGetVarId(char* group, char* name)
{
int i;
logVarId_t varId = invalidVarId;
char * currgroup = "";

for(i=0; i<logsLen; i++)
{
if (logs[i].type & LOG_GROUP) {
if (logs[i].type & LOG_START)
currgroup = logs[i].name;
} if ((!strcmp(group, currgroup)) && (!strcmp(name, logs[i].name)))
return i;
} if ((!strcmp(group, currgroup)) && (!strcmp(name, logs[i].name))) {
varId = (logVarId_t)i;
return varId;
}
}

return -1;
return invalidVarId;
}

int logGetType(int varid)
int logGetType(logVarId_t varid)
{
return logs[varid].type;
}

void logGetGroupAndName(int varid, char** group, char** name)
void logGetGroupAndName(logVarId_t varid, char** group, char** name)
{
char * currgroup = "";
*group = 0;
Expand All @@ -1003,7 +1008,7 @@ void logGetGroupAndName(int varid, char** group, char** name)
}
}

void* logGetAddress(int varid)
void* logGetAddress(logVarId_t varid)
{
return logs[varid].address;
}
Expand All @@ -1013,11 +1018,11 @@ uint8_t logVarSize(int type)
return typeLength[type];
}

int logGetInt(int varid)
int logGetInt(logVarId_t varid)
{
int valuei = 0;

ASSERT(varid >= 0);
ASSERT(LOG_VARID_IS_VALID(varid));

switch(logs[varid].type)
{
Expand Down Expand Up @@ -1047,17 +1052,17 @@ int logGetInt(int varid)
return valuei;
}

float logGetFloat(int varid)
float logGetFloat(logVarId_t varid)
{
ASSERT(varid >= 0);
ASSERT(LOG_VARID_IS_VALID(varid));

if (logs[varid].type == LOG_FLOAT)
return *(float *)logs[varid].address;

return logGetInt(varid);
}

unsigned int logGetUint(int varid)
unsigned int logGetUint(logVarId_t varid)
{
return (unsigned int)logGetInt(varid);
}
Expand Down

0 comments on commit 64be05f

Please sign in to comment.