Commit e8c95666 authored by Adam Wujek's avatar Adam Wujek 💬

shell: store sfp product number in sfp_pn for cmd_sfp

--Don't use "static char pn" top store sfp's pn.
--Print error when unable to read SFP
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent f9e8b825
...@@ -21,6 +21,8 @@ int32_t sfp_deltaTx = 0; ...@@ -21,6 +21,8 @@ int32_t sfp_deltaTx = 0;
int32_t sfp_deltaRx = 0; int32_t sfp_deltaRx = 0;
int32_t sfp_in_db = 0; int32_t sfp_in_db = 0;
char sfp_pn[SFP_PN_LEN];
int sfp_present(void) int sfp_present(void)
{ {
return !gpio_in(GPIO_SFP_DET); return !gpio_in(GPIO_SFP_DET);
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#define SFP_NOT_MATCHED 1 #define SFP_NOT_MATCHED 1
#define SFP_MATCHED 2 #define SFP_MATCHED 2
extern char sfp_pn[SFP_PN_LEN];
extern int32_t sfp_in_db; extern int32_t sfp_in_db;
extern int32_t sfp_alpha; extern int32_t sfp_alpha;
extern int32_t sfp_deltaTx; extern int32_t sfp_deltaTx;
......
...@@ -36,15 +36,21 @@ static int cmd_sfp(const char *args[]) ...@@ -36,15 +36,21 @@ static int cmd_sfp(const char *args[])
{ {
int8_t sfpcount = 1, i, temp; int8_t sfpcount = 1, i, temp;
struct s_sfpinfo sfp; struct s_sfpinfo sfp;
static char pn[SFP_PN_LEN + 1] = "\0";
if (args[0] && !strcasecmp(args[0], "detect")) { if (args[0] && !strcasecmp(args[0], "detect")) {
if (!sfp_present()) /* clear sfp_pn */
sfp_pn[0] = '\0';
if (!sfp_present()) {
pp_printf("No SFP.\n"); pp_printf("No SFP.\n");
else return -1;
sfp_read_part_id(pn); }
pn[16] = 0; if (sfp_read_part_id(sfp_pn)) {
pp_printf("%s\n", pn); pp_printf("SFP read error\n");
return -1;
}
for (temp = 0; temp < SFP_PN_LEN; ++temp)
pp_printf("%c", sfp.pn[temp]);
pp_printf("\n");
return 0; return 0;
} }
// else if (!strcasecmp(args[0], "i2cscan")) // else if (!strcasecmp(args[0], "i2cscan"))
...@@ -57,13 +63,13 @@ static int cmd_sfp(const char *args[]) ...@@ -57,13 +63,13 @@ static int cmd_sfp(const char *args[])
EE_RET_I2CERR) EE_RET_I2CERR)
pp_printf("Could not erase DB\n"); pp_printf("Could not erase DB\n");
} else if (args[4] && !strcasecmp(args[0], "add")) { } else if (args[4] && !strcasecmp(args[0], "add")) {
if (strlen(args[1]) > 16) if (strlen(args[1]) > SFP_PN_LEN)
temp = 16; temp = SFP_PN_LEN;
else else
temp = strlen(args[1]); temp = strlen(args[1]);
for (i = 0; i < temp; ++i) for (i = 0; i < temp; ++i)
sfp.pn[i] = args[1][i]; sfp.pn[i] = args[1][i];
while (i < 16) while (i < SFP_PN_LEN)
sfp.pn[i++] = ' '; //padding sfp.pn[i++] = ' '; //padding
sfp.dTx = atoi(args[2]); sfp.dTx = atoi(args[2]);
sfp.dRx = atoi(args[3]); sfp.dRx = atoi(args[3]);
...@@ -89,17 +95,17 @@ static int cmd_sfp(const char *args[]) ...@@ -89,17 +95,17 @@ static int cmd_sfp(const char *args[])
} }
} }
pp_printf("%d: PN:", i + 1); pp_printf("%d: PN:", i + 1);
for (temp = 0; temp < 16; ++temp) for (temp = 0; temp < SFP_PN_LEN; ++temp)
pp_printf("%c", sfp.pn[temp]); pp_printf("%c", sfp.pn[temp]);
pp_printf(" dTx: %d, dRx: %d, alpha: %d\n", sfp.dTx, pp_printf(" dTx: %d, dRx: %d, alpha: %d\n", sfp.dTx,
sfp.dRx, sfp.alpha); sfp.dRx, sfp.alpha);
} }
} else if (args[0] && !strcasecmp(args[0], "match")) { } else if (args[0] && !strcasecmp(args[0], "match")) {
if (pn[0] == '\0') { if (sfp_pn[0] == '\0') {
pp_printf("Run sfp detect first\n"); pp_printf("Run sfp detect first\n");
return 0; return 0;
} }
strncpy(sfp.pn, pn, SFP_PN_LEN); strncpy(sfp.pn, sfp_pn, SFP_PN_LEN);
if (storage_match_sfp(&sfp) > 0) { if (storage_match_sfp(&sfp) > 0) {
pp_printf("SFP matched, dTx=%d, dRx=%d, alpha=%d\n", pp_printf("SFP matched, dTx=%d, dRx=%d, alpha=%d\n",
sfp.dTx, sfp.dRx, sfp.alpha); sfp.dTx, sfp.dRx, sfp.alpha);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment