From 56b3340dd93cfd8bae82e78e7903b1062743acb8 Mon Sep 17 00:00:00 2001 From: Peace Kotamnives Date: Fri, 13 Oct 2023 12:51:37 -0400 Subject: [PATCH] add optpow CLI + clean-up structs --- projects/cm_mcu/CommandLineTask.c | 2 +- projects/cm_mcu/LocalTasks.c | 119 ++++++++++++++++----- projects/cm_mcu/MonitorI2CTask.c | 44 +------- projects/cm_mcu/MonitorI2CTask.h | 14 +-- projects/cm_mcu/commands/SensorControl.c | 127 ++++++++++++++--------- 5 files changed, 174 insertions(+), 132 deletions(-) diff --git a/projects/cm_mcu/CommandLineTask.c b/projects/cm_mcu/CommandLineTask.c index ed0c303e..3fe29f00 100644 --- a/projects/cm_mcu/CommandLineTask.c +++ b/projects/cm_mcu/CommandLineTask.c @@ -287,7 +287,7 @@ static struct command_t commands[] = { { "ff_optpow", ff_optpow, - "Displays a table showing the avg. optical power of the I2C fireflies.\r\n", + "Displays a table showing the per-ch optical power of the I2C fireflies.\r\n", 0, }, { diff --git a/projects/cm_mcu/LocalTasks.c b/projects/cm_mcu/LocalTasks.c index 5a860ec7..e8b2ce07 100644 --- a/projects/cm_mcu/LocalTasks.c +++ b/projects/cm_mcu/LocalTasks.c @@ -165,11 +165,13 @@ struct sm_command_t sm_command_ffldaq_f1[] = { {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, {1, 0x00, 0x03, 1, "FF_LOS_ALARM", 0xff, "", PM_STATUS}, {1, 0x00, 0x05, 1, "FF_CDR_LOL_ALARM", 0xff, "", PM_STATUS}, - {2, 0x00, 0x22, 1, "FF_OPT_POW", 0xff, "mw", PM_STATUS}, // read 4 Rx-ch registers with increasing addresses + {2, 0x00, 0x22, 1, "FF_CH01_OPT_POW", 0xff, "mw", PM_STATUS}, // read 4 Rx-ch registers with increasing addresses + {2, 0x00, 0x24, 1, "FF_CH02_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x00, 0x26, 1, "FF_CH03_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x00, 0x28, 1, "FF_CH04_OPT_POW", 0xff, "mw", PM_STATUS}, }; uint16_t ffldaq_f1_values[NSUPPLIES_FFLDAQ_F1 * NCOMMANDS_FFLDAQ_F1]; -uint16_t ffldaq_f1_optpow_values[NSUPPLIES_FFLDAQ_F1]; struct MonitorI2CTaskArgs_t ffldaq_f1_args = { .name = "FFDAQ", @@ -186,8 +188,6 @@ struct MonitorI2CTaskArgs_t ffldaq_f1_args = { .smbus_status = &eStatus4, .xSem = NULL, .ffpart_bit_mask = 0U, - .n_rxchs = FF_DAQ_NRXCH, - .opt_pow_values = ffldaq_f1_optpow_values, .present_bit_mask = 0U, .stack_size = 4096U, }; @@ -200,6 +200,21 @@ struct sm_command_t sm_command_fflit_f1[] = { {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, {2, 0x00, 0x07, 1, "FF_LOS_ALARM", 0xffff, "", PM_STATUS}, {2, 0x00, 0x14, 1, "FF_CDR_LOL_ALARM", 0xffff, "", PM_STATUS}, + // there are no registers to read optical power for 14Gbps ECUO. + // registers below are a placeholder with a reading equal to zero + // the reason we need them because n_commands is fixed + {1, 0x00, 0x00, 1, "FF_CH01_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH02_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH03_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH04_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH05_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH06_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH07_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH08_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH09_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH10_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH11_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH12_OPT_POW", 0xff, "mw", PM_STATUS}, }; // register maps for OT-DTC Fireflies 12-ch part -- 25Gbps ECUO (no connected devices to test as of 08.04.22) @@ -209,7 +224,19 @@ struct sm_command_t sm_command_fflot_f1[] = { {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, {2, 0x00, 0x07, 1, "FF_LOS_ALARM", 0xffff, "", PM_STATUS}, {2, 0x00, 0x14, 1, "FF_CDR_LOL_ALARM", 0xffff, "", PM_STATUS}, - {2, 0x01, 0xe4, 1, "FF_OPT_POW", 0xff, "mw", PM_STATUS}, // read 12 Rx-ch registers with decreasing addresses + {2, 0x01, 0xe4, 1, "FF_CH01_OPT_POW", 0xff, "mw", PM_STATUS}, // read 12 Rx-ch registers with decreasing addresses + {2, 0x01, 0xe2, 1, "FF_CH02_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xe0, 1, "FF_CH03_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xde, 1, "FF_CH04_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xdc, 1, "FF_CH05_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xda, 1, "FF_CH06_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xd8, 1, "FF_CH07_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xd6, 1, "FF_CH08_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xd4, 1, "FF_CH09_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xd2, 1, "FF_CH10_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xd0, 1, "FF_CH11_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xce, 1, "FF_CH12_OPT_POW", 0xff, "mw", PM_STATUS}, + }; #ifdef REV1 @@ -238,7 +265,6 @@ struct dev_moni2c_addr_t ffl12_f1_moni2c_addrs[NFIREFLIES_IT_F1] = { #endif uint16_t ffl12_f1_values[NSUPPLIES_FFL12_F1 * NCOMMANDS_FFL12_F1]; -uint16_t ffl12_f1_optpow_values[NSUPPLIES_FFL12_F1]; struct MonitorI2CTaskArgs_t ffl12_f1_args = { .name = "FF12", @@ -255,8 +281,6 @@ struct MonitorI2CTaskArgs_t ffl12_f1_args = { .smbus_status = &eStatus4, .xSem = NULL, .ffpart_bit_mask = 0U, - .n_rxchs = FF_12_NRXCH, - .opt_pow_values = ffl12_f1_optpow_values, .present_bit_mask = 0U, .stack_size = 4096U, }; @@ -291,10 +315,12 @@ struct sm_command_t sm_command_ffldaq_f2[] = { {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, {1, 0x00, 0x03, 1, "FF_LOS_ALARM", 0xff, "", PM_STATUS}, {1, 0x00, 0x05, 1, "FF_CDR_LOL_ALARM", 0xff, "", PM_STATUS}, - {2, 0x00, 0x22, 1, "FF_OPT_POW", 0xff, "mw", PM_STATUS}, // read 4 Rx-ch registers with increasing addresses + {2, 0x00, 0x22, 1, "FF_CH01_OPT_POW", 0xff, "mw", PM_STATUS}, // read 4 Rx-ch registers with increasing addresses + {2, 0x00, 0x24, 1, "FF_CH02_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x00, 0x26, 1, "FF_CH03_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x00, 0x28, 1, "FF_CH04_OPT_POW", 0xff, "mw", PM_STATUS}, }; uint16_t ffldaq_f2_values[NSUPPLIES_FFLDAQ_F2 * NCOMMANDS_FFLDAQ_F2]; -uint16_t ffldaq_f2_optpow_values[NSUPPLIES_FFLDAQ_F2]; struct MonitorI2CTaskArgs_t ffldaq_f2_args = { .name = "FFDAV", @@ -311,8 +337,6 @@ struct MonitorI2CTaskArgs_t ffldaq_f2_args = { .smbus_status = &eStatus3, .xSem = NULL, .ffpart_bit_mask = 0U, - .n_rxchs = FF_DAQ_NRXCH, - .opt_pow_values = ffldaq_f2_optpow_values, .present_bit_mask = 0U, .stack_size = 4096U, }; @@ -325,7 +349,21 @@ struct sm_command_t sm_command_fflit_f2[] = { {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, {2, 0x00, 0x07, 1, "FF_LOS_ALARM", 0xffff, "", PM_STATUS}, {2, 0x00, 0x14, 1, "FF_CDR_LOL_ALARM", 0xffff, "", PM_STATUS}, - + // there are no registers to read optical power for 14Gbps ECUO. + // registers below are a placeholder with a reading equal to zero + // the reason we need them because n_commands is fixed + {1, 0x00, 0x00, 1, "FF_CH01_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH02_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH03_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH04_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH05_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH06_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH07_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH08_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH09_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH10_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH11_OPT_POW", 0xff, "mw", PM_STATUS}, + {1, 0x00, 0x00, 1, "FF_CH12_OPT_POW", 0xff, "mw", PM_STATUS}, }; // register maps for OT-DTC Fireflies 12-ch part -- 25Gbps ECUO (no connected devices to test as of 08.04.22) // **commands below have not been tested yet** @@ -334,7 +372,18 @@ struct sm_command_t sm_command_fflot_f2[] = { {1, 0x00, 0x16, 2, "FF_TEMPERATURE", 0xff, "C", PM_STATUS}, {2, 0x00, 0x07, 1, "FF_LOS_ALARM", 0xffff, "", PM_STATUS}, {2, 0x00, 0x14, 1, "FF_CDR_LOL_ALARM", 0xffff, "", PM_STATUS}, - {2, 0x01, 0xe4, 1, "FF_OPT_POW", 0xff, "mw", PM_STATUS}, // read 12 Rx-ch registers with decreasing addresses + {2, 0x01, 0xe4, 1, "FF_CH01_OPT_POW", 0xff, "mw", PM_STATUS}, // read 12 Rx-ch registers with decreasing addresses + {2, 0x01, 0xe2, 1, "FF_CH02_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xe0, 1, "FF_CH03_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xde, 1, "FF_CH04_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xdc, 1, "FF_CH05_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xda, 1, "FF_CH06_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xd8, 1, "FF_CH07_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xd6, 1, "FF_CH08_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xd4, 1, "FF_CH09_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xd2, 1, "FF_CH10_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xd0, 1, "FF_CH11_OPT_POW", 0xff, "mw", PM_STATUS}, + {2, 0x01, 0xce, 1, "FF_CH12_OPT_POW", 0xff, "mw", PM_STATUS}, }; #ifdef REV1 @@ -358,7 +407,6 @@ struct dev_moni2c_addr_t ffl12_f2_moni2c_addrs[NFIREFLIES_IT_F2] = { #endif uint16_t ffl12_f2_values[NSUPPLIES_FFL12_F2 * NCOMMANDS_FFL12_F2]; -uint16_t ffl12_f2_optpow_values[NSUPPLIES_FFL12_F2]; struct MonitorI2CTaskArgs_t ffl12_f2_args = { .name = "FF12V", @@ -375,8 +423,6 @@ struct MonitorI2CTaskArgs_t ffl12_f2_args = { .smbus_status = &eStatus3, .xSem = NULL, .ffpart_bit_mask = 0U, - .n_rxchs = FF_12_NRXCH, - .opt_pow_values = ffl12_f2_optpow_values, .present_bit_mask = 0U, .stack_size = 4096U, }; @@ -670,28 +716,45 @@ uint16_t getFFtemp(const uint8_t i) uint16_t getFFoptpow(const uint8_t i) { - uint16_t val; + + uint16_t avg_val; + uint16_t sum_val; configASSERT(i < NFIREFLIES); if (i < NFIREFLIES_IT_F1) { - int index = i; - val = ffl12_f1_args.opt_pow_values[index]; + for (int i1 = 4; i1 < ffl12_f1_args.n_commands; ++i1) { + int dev = i - ff_moni2c_arg[0].int_idx + ff_moni2c_arg[0].dev_int_idx; + int index = dev * (ffl12_f1_args.n_commands * ffl12_f1_args.n_pages) + i1; + sum_val += ffl12_f1_args.sm_values[index]; + } + avg_val = sum_val/(ffl12_f1_args.n_commands-4); } else if (NFIREFLIES_IT_F1 <= i && i < NFIREFLIES_IT_F1 + NFIREFLIES_DAQ_F1) { - int index = i - NFIREFLIES_IT_F1; - val = ffldaq_f1_args.opt_pow_values[index]; + for (int i1 = 4; i1 < ffldaq_f1_args.n_commands; ++i1) { + int dev = i - ff_moni2c_arg[1].int_idx + ff_moni2c_arg[1].dev_int_idx; + int index = (dev) * (ffldaq_f1_args.n_commands * ffldaq_f1_args.n_pages) + i1; + sum_val += ffldaq_f1_args.sm_values[index]; + } + avg_val = sum_val/(ffldaq_f1_args.n_commands-4); } else if (NFIREFLIES_F1 <= i && i < NFIREFLIES_F1 + NFIREFLIES_IT_F2) { - int index = i - NFIREFLIES_F1; - val = ffl12_f2_args.opt_pow_values[index]; + for (int i1 = 4; i1 < ffl12_f2_args.n_commands; ++i1) { + int dev = i - ff_moni2c_arg[2].int_idx + ff_moni2c_arg[2].dev_int_idx; + int index = (dev) * (ffl12_f2_args.n_commands * ffl12_f2_args.n_pages) + i1; + sum_val += ffl12_f2_args.sm_values[index]; + } + avg_val = sum_val/(ffl12_f2_args.n_commands-4); } else { - int index = i - NFIREFLIES_F1 - NFIREFLIES_IT_F2; - val = ffldaq_f2_args.opt_pow_values[index]; + for (int i1 = 4; i1 < ffldaq_f2_args.n_commands; ++i1) { + int dev = i - ff_moni2c_arg[3].int_idx + ff_moni2c_arg[3].dev_int_idx; + int index = (dev) * (ffldaq_f2_args.n_commands * ffldaq_f2_args.n_pages) + i1; + sum_val += ffldaq_f2_args.sm_values[index]; + } + avg_val = sum_val/(ffldaq_f2_args.n_commands-4); } - - return val; + return avg_val; } uint16_t getFFpresentbit(const uint8_t i) diff --git a/projects/cm_mcu/MonitorI2CTask.c b/projects/cm_mcu/MonitorI2CTask.c index fa5b5b22..f1f23534 100644 --- a/projects/cm_mcu/MonitorI2CTask.c +++ b/projects/cm_mcu/MonitorI2CTask.c @@ -178,6 +178,7 @@ void MonitorI2CTask(void *parameters) // Read I2C registers/commands for (int c = 0; c < args->n_commands; ++c) { + int index = ps * (args->n_commands * args->n_pages) + c; log_debug(LOG_MONI2C, "%s: command %s.\r\n", args->name, args->commands[c].name); @@ -205,49 +206,6 @@ void MonitorI2CTask(void *parameters) } // loop over commands -#ifdef REV2 - // get optical power information from 25Gbs FFs - bool has_opt_pow = false; - if (IsFFDAQ) - has_opt_pow = true; - if (IsFF12 && (ps % 2 == 1)) - has_opt_pow = 0x1U & (args->ffpart_bit_mask >> (int)ps / 2); - - if (has_opt_pow) { - uint16_t opt_pow_values = 0x0U; - uint8_t page_reg_value = args->commands[FF_OPT_POW_C].page; - int r = apollo_i2c_ctl_reg_w(args->i2c_dev, args->devices[ps].dev_addr, 1, args->selpage_reg, 1, page_reg_value); - if (r != 0) { - log_error(LOG_MONI2C, "%s : page fail %s\r\n", args->devices[ps].name, SMBUS_get_error(r)); - break; - } - - for (int ch = 0; ch < args->n_rxchs; ++ch) { - uint32_t output_raw; - uint16_t opt_pw_command; - if (IsFFDAQ) { - opt_pw_command = args->commands[FF_OPT_POW_C].command + 2 * ch; - } - else { - opt_pw_command = args->commands[FF_OPT_POW_C].command - 2 * ch; - } - int res = apollo_i2c_ctl_reg_r(args->i2c_dev, args->devices[ps].dev_addr, args->commands[FF_OPT_POW_C].reg_size, - opt_pw_command, args->commands[FF_OPT_POW_C].size, &output_raw); - - if (res != 0) { - log_error(LOG_MONI2C, "%s: %s read Error %s, break (ps=%d)\r\n", args->name, args->commands[FF_OPT_POW_C].name, SMBUS_get_error(res), ps); - opt_pow_values = 0xff; - break; - } - else { - opt_pow_values += output_raw; - } - } - opt_pow_values = opt_pow_values / args->n_rxchs; - args->opt_pow_values[ps] = opt_pow_values; - } - -#endif // REV2 log_debug(LOG_MONI2C, "%s: end loop commands\r\n", args->name); args->updateTick = xTaskGetTickCount(); // current time in ticks diff --git a/projects/cm_mcu/MonitorI2CTask.h b/projects/cm_mcu/MonitorI2CTask.h index 746383b6..f6ecbe6c 100644 --- a/projects/cm_mcu/MonitorI2CTask.h +++ b/projects/cm_mcu/MonitorI2CTask.h @@ -43,24 +43,18 @@ struct MonitorI2CTaskArgs_t { SemaphoreHandle_t xSem; // semaphore for controlling access to device uint8_t ffpart_bit_mask; // this mask is only used for detecting 12-ch 25Gbps on the REV2 board uint32_t present_bit_mask; // this mask is used for all ffs to detect if it is mounted or not - const uint8_t n_rxchs; // the number of optical receiver channels - uint16_t *opt_pow_values; // optical power measurements from 4/12ch FFs with 25Gbs UBaseType_t stack_size; // stack size of task }; #define FF_SELPAGE_REG 0x7f #define CLK_SELPAGE_REG 0x1 -#define FF_OPT_POW_C 4 // the order of optical power command in sm_command array -#define FF_DAQ_NRXCH 4 -#define FF_12_NRXCH 12 - #ifndef REV2 #define NSUPPLIES_FFLDAQ_F1 (3) #else // REV2 #define NSUPPLIES_FFLDAQ_F1 (4) #endif // REV 2 -#define NCOMMANDS_FFLDAQ_F1 4 // number of commands +#define NCOMMANDS_FFLDAQ_F1 8 // number of commands #define NPAGES_FFLDAQ_F1 1 // number of pages on the 4-channel firefly ports #ifndef REV2 @@ -68,7 +62,7 @@ struct MonitorI2CTaskArgs_t { #else // REV1 #define NSUPPLIES_FFL12_F1 (6) #endif // REV 2 -#define NCOMMANDS_FFL12_F1 4 // number of commands +#define NCOMMANDS_FFL12_F1 16 // number of commands #define NPAGES_FFL12_F1 1 // number of pages on the 12-channel firefly ports #ifndef REV2 @@ -76,7 +70,7 @@ struct MonitorI2CTaskArgs_t { #else // REV1 #define NSUPPLIES_FFLDAQ_F2 (4) #endif // REV 2 -#define NCOMMANDS_FFLDAQ_F2 4 // number of commands +#define NCOMMANDS_FFLDAQ_F2 8 // number of commands #define NPAGES_FFLDAQ_F2 1 // number of pages on the 4-channel firefly ports #ifndef REV2 @@ -84,7 +78,7 @@ struct MonitorI2CTaskArgs_t { #else // REV1 #define NSUPPLIES_FFL12_F2 (6) #endif // REV 2 -#define NCOMMANDS_FFL12_F2 4 // number of commands +#define NCOMMANDS_FFL12_F2 16 // number of commands #define NPAGES_FFL12_F2 1 // number of pages on the 12-channel firefly ports extern struct dev_moni2c_addr_t ffl12_f1_moni2c_addrs[NFIREFLIES_IT_F1]; diff --git a/projects/cm_mcu/commands/SensorControl.c b/projects/cm_mcu/commands/SensorControl.c index 31692e9f..0563a47f 100644 --- a/projects/cm_mcu/commands/SensorControl.c +++ b/projects/cm_mcu/commands/SensorControl.c @@ -876,56 +876,83 @@ BaseType_t ff_temp(int argc, char **argv, char *m) 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; + // argument handling + int copied = 0; + + static int whichff = 0; + static int n = 0; + static int i1 = 4; + + 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 Optical Power:\r\n"); + } + + + for (; n < NFIREFLY_ARG; ++n) { + struct MonitorI2CTaskArgs_t *ff_arg = ff_moni2c_arg[n].arg; + 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 (strstr(ff_moni2c_addrs[whichff].name, "Tx") != NULL) + continue; + if (isEnabledFF(ff_moni2c_arg[n].int_idx + dev)) { + i1 = 4; + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: \r\n", ff_moni2c_addrs[whichff].name); + for (; i1 < ff_arg->n_commands; ++i1) { + int index = dev * (ff_arg->n_commands * ff_arg->n_pages) + i1; + uint8_t val = ff_arg->sm_values[index]; + if ((SCRATCH_SIZE - copied) < 20) { + return pdTRUE; + } + + if ((i1-4)%6 == 0) + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "CH%2d: %2d \t", i1 - 3, val); + else if ((i1-4)%6 == 1) + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "CH%2d: %2d \t", i1 - 3, val); + else if ((i1-4)%6 == 2) + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "CH%2d: %2d \t", i1 - 3, val); + else if ((i1-4)%6 == 3) + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "CH%2d: %2d \t", i1 - 3, val); + else if ((i1-4)%6 == 4) + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "CH%2d: %2d \t", i1 - 3, val); + else + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "CH%2d: %2d \r\n", i1 - 3, val); + + } + + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "\r\n"); + + } + else // dummy value + copied += snprintf(m + copied, SCRATCH_SIZE - copied, "%17s: %2s \r\n", ff_moni2c_addrs[whichff].name, "--"); + + + 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; + i1 = 4; + return pdFALSE; } // this command takes up to two arguments