Skip to content

Commit

Permalink
add ff_optpow CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
pkotamnives committed Oct 9, 2023
1 parent 04cadd7 commit 593fdc3
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions projects/cm_mcu/CommandLineTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ static struct command_t commands[] = {
"Displays a table showing the CDR loss of lock alarms of the fireflies.\r\n",
0,
},
{
"ff_optpow",
ff_optpow,
"Displays a table showing the avg. optical power of the I2C fireflies.\r\n",
0,
},
{
"ff_temp",
ff_temp,
Expand Down
55 changes: 55 additions & 0 deletions projects/cm_mcu/commands/SensorControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,61 @@ BaseType_t ff_temp(int argc, char **argv, char *m)
return pdFALSE;
}

BaseType_t ff_optpow(int argc, char **argv, char *m)
{
// argument handling
int copied = 0;

static int whichff = 0;
static int n = 0;

if (whichff == 0) {
// check for stale data
TickType_t now = pdTICKS_TO_S(xTaskGetTickCount());

if (isFFStale()) {
TickType_t last = pdTICKS_TO_S(getFFupdateTick(isFFStale()));
int mins = (now - last) / 60;
copied += snprintf(m + copied, SCRATCH_SIZE - copied,
"%s: stale data, last update %d minutes ago\r\n", argv[0], mins);
}
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "FF Avg. Optical Power:\r\n");
}

for (; n < NFIREFLY_ARG; ++n) {
for (; whichff < ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].num_dev; ++whichff) {
int dev = whichff - ff_moni2c_arg[n].int_idx + ff_moni2c_arg[n].dev_int_idx;
if (isEnabledFF(ff_moni2c_arg[n].int_idx + dev)) {
uint8_t val = getFFoptpow(whichff);
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2d", ff_moni2c_addrs[whichff].name, val);
}
else // dummy value
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2s", ff_moni2c_addrs[whichff].name, "--");

bool isTx = (strstr(ff_moni2c_addrs[whichff].name, "Tx") != NULL);
if (isTx)
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\t");
else
copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\r\n");
if ((SCRATCH_SIZE - copied) < 20) {
++whichff;
return pdTRUE;
}
}
}

if (whichff % 2 == 1) {
m[copied++] = '\r';
m[copied++] = '\n';
m[copied] = '\0';
}
whichff = 0;
n = 0;

return pdFALSE;
}


// this command takes up to two arguments
BaseType_t ff_ctl(int argc, char **argv, char *m)
{
Expand Down
1 change: 1 addition & 0 deletions projects/cm_mcu/commands/SensorControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ BaseType_t adc_ctl(int argc, char **argv, char *m);

// Fireflies
BaseType_t ff_ctl(int argc, char **argv, char *m);
BaseType_t ff_optpow(int argc, char **argv, char *m);
BaseType_t ff_temp(int argc, char **argv, char *m);
BaseType_t ff_status(int argc, char **argv, char *m);
BaseType_t ff_los_alarm(int argc, char **argv, char *m);
Expand Down

0 comments on commit 593fdc3

Please sign in to comment.