Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoder for cable test results #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/com_cabletest.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int do_cabletest (int argc, const char **argv, struct ngadmin *nga)
}

for (i = 0; i < j; i++)
printf("port %i: %08X %08X\n", ct[i].port, ct[i].v1, ct[i].v2);
printf("port %i: %s, code=%d, distance=%d m\n", ct[i].port, getCableTestResultStr(ct[i].test_result), ct[i].test_result, ct[i].fault_distance);

end:
free(ct);
Expand Down
18 changes: 15 additions & 3 deletions lib/include/ngadmin.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,23 @@ struct igmp_conf {
*/
struct cabletest {
char port; /**< port */
int v1; /**< raw value 1 */
int v2; /**< raw value 2 */
int test_result; /**< test result code (see enum) */
int fault_distance; /**< fault distance / cable length in meters */
};


/**
* Cabletest result codes
*/
enum {
CABLETEST_OK = 0, // System0056 = OK
CABLETEST_NO_CABLE = 1, // System0052 = No Cable
CABLETEST_OPEN_CABLE = 2, // System0053 = Open Cable
CABLETEST_SHORT_CIRCUIT = 3, // System0054 = Short Circuit
CABLETEST_FIBER_CABLE = 4, // System0055 = Fiber Cable
CABLETEST_SHORTED_CABLE = 5, // System0064 = Shorted cable
CABLETEST_UNKNOWN = 6, // System0065 = Unknown
CABLETEST_CROSSTALK = 7 // System0066 = Crosstalk
};

#ifdef __cplusplus
extern "C" {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/ports.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ int ngadmin_cabletest (struct ngadmin *nga, struct cabletest *ct, int nb)
goto end;
}
if (acr->port == ct[i].port) {
ct[i].v1 = acr->v1;
ct[i].v2 = acr->v2;
ct[i].test_result = acr->test_result;
ct[i].fault_distance = acr->fault_distance;
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions raw/include/nsdp/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ struct attr_cabletest_do {

struct attr_cabletest_result {
unsigned char port; /* port number */
unsigned int v1; /* raw value 1 (values unknown yet) */
unsigned int v2; /* raw value 2 (values unknown yet) */
unsigned int test_result; /* Cable test result code */
unsigned int fault_distance; /* fault distance or cable length in meters */
} __attribute__((packed));


Expand Down
2 changes: 2 additions & 0 deletions raw/include/nsdp/str.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern const char* const qos_prio_str_tab[];
extern const char* const bitrate_str_tab[];
extern const char* const code_str_tab[];
extern const char* const error_str_tab[];
extern const char* const cable_test_result_str_tab[];


static inline const char* safeStr (const char *s)
Expand All @@ -39,6 +40,7 @@ static inline const char* getValueStr (const char* const* tab, unsigned char min
#define getBitrateStr(bitrate) getValueStr(bitrate_str_tab, BITRATE_NOLIMIT, BITRATE_512M, bitrate)
#define getCodeStr(code) getValueStr(code_str_tab, CODE_READ_REQ, CODE_WRITE_REP, code)
#define getErrorStr(error) getValueStr(error_str_tab, ERROR_NONE, ERROR_DENIED, error)
#define getCableTestResultStr(error) getValueStr(cable_test_result_str_tab, ERROR_NONE, ERROR_DENIED, error)


int parseValueStr (const char* const* tab, unsigned char mini, unsigned char maxi, const char *str);
Expand Down
8 changes: 4 additions & 4 deletions raw/src/attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ static int cabletest_result_endecode (struct attr *at, bool encode)
return -EMSGSIZE;

if (encode) {
acr->v1 = htonl(acr->v1);
acr->v2 = htonl(acr->v2);
acr->test_result = htonl(acr->test_result);
acr->fault_distance = htonl(acr->fault_distance);
} else {
acr->v1 = ntohl(acr->v1);
acr->v2 = ntohl(acr->v2);
acr->test_result = ntohl(acr->test_result);
acr->fault_distance = ntohl(acr->fault_distance);
}

return 0;
Expand Down
12 changes: 12 additions & 0 deletions raw/src/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ const char* const error_str_tab[] = {
};


const char* const cable_test_result_str_tab[] = {
[CABLETEST_OK] = "OK",
[CABLETEST_NO_CABLE] = "No Cable",
[CABLETEST_OPEN_CABLE] = "Open Cable",
[CABLETEST_SHORT_CIRCUIT] = "Short Circuit",
[CABLETEST_FIBER_CABLE] = "Fiber Cable",
[CABLETEST_SHORTED_CABLE] = "Shorted cable",
[CABLETEST_UNKNOWN] = "Unknown",
[CABLETEST_CROSSTALK] = "Crosstalk",
NULL
};

int parseValueStr (const char* const* tab, unsigned char mini, unsigned char maxi, const char *str)
{
unsigned char i;
Expand Down