usb_cables: add option to print cable connection mismatches
This commit is contained in:
parent
84db14e71c
commit
4aec3da96c
|
@ -173,7 +173,7 @@ static void command_cables(void* argument)
|
|||
printf("= cable check =\n");
|
||||
for (uint8_t cable = 0; cable < LENGTH(usb_cables); cable++) { // test every cable
|
||||
uint8_t pair_defined, pair_undefined, pair_disconnected;
|
||||
bool result = usb_cables_check_cable(&usb_cables[cable], &pair_defined, &pair_undefined, &pair_disconnected);
|
||||
bool result = usb_cables_check_cable(&usb_cables[cable], &pair_defined, &pair_undefined, &pair_disconnected, false);
|
||||
printf("%s: %s (defined=%u, undefined=%u, disconnected=%u)\n", result ? "OK" : "KO", usb_cables[cable].name, pair_defined, pair_undefined, pair_disconnected);
|
||||
}
|
||||
|
||||
|
@ -264,9 +264,9 @@ static void command_find(void* argument)
|
|||
}
|
||||
// match cable
|
||||
uint8_t pair_defined, pair_undefined, pair_disconnected;
|
||||
bool match = usb_cables_check_cable(&usb_cables[cable], &pair_defined, &pair_undefined, &pair_disconnected);
|
||||
bool match = usb_cables_check_cable(&usb_cables[cable], &pair_defined, &pair_undefined, &pair_disconnected, false);
|
||||
printf("- %s: %s (defined=%u, undefined=%u, disconnected=%u)\n", match ? "OK" : "KO", usb_cables[cable].name, pair_defined, pair_undefined, pair_disconnected);
|
||||
cable_score[LENGTH(usb_cables)] = usb_cables[cable].pin_pairs_nb - pair_defined + pair_undefined + pair_disconnected; // calculate score
|
||||
cable_score[cable] = usb_cables[cable].pin_pairs_nb - pair_defined + pair_undefined + pair_disconnected; // calculate score
|
||||
if (match) {
|
||||
matches++;
|
||||
}
|
||||
|
@ -293,6 +293,7 @@ static void command_find(void* argument)
|
|||
}
|
||||
if (cable_score[cable] == best_score) {
|
||||
printf("- %s\n", usb_cables[cable].name);
|
||||
usb_cables_check_cable(&usb_cables[cable], NULL, NULL, NULL, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -488,7 +489,7 @@ static void command_test(void* argument)
|
|||
bool cable_ok = false; // if the cable is connected
|
||||
while (!cable_ok) { // wait until all pin pairs of cable are connected
|
||||
uint8_t defined, undefined, disconnected; // pair counting variables
|
||||
cable_ok = usb_cables_check_cable(&test_cables[cable], &defined, &undefined, &disconnected); // test cable
|
||||
cable_ok = usb_cables_check_cable(&test_cables[cable], &defined, &undefined, &disconnected, true); // test cable
|
||||
if (!cable_ok && defined > 0) { // not all pairs are connected
|
||||
printf("connection issues: defined=%u/%u, undefined=%u, disconnected=%u\n", defined, test_cables[cable].pin_pairs_nb, undefined, disconnected); // show issue summary
|
||||
}
|
||||
|
|
14
usb_cables.c
14
usb_cables.c
|
@ -1754,7 +1754,7 @@ bool usb_cables_check_load(const struct usb_connector_t* connector)
|
|||
return loaded;
|
||||
}
|
||||
|
||||
bool usb_cables_check_cable(const struct usb_cable_t* usb_cable, uint8_t* defined, uint8_t* undefined, uint8_t* disconnected)
|
||||
bool usb_cables_check_cable(const struct usb_cable_t* usb_cable, uint8_t* defined, uint8_t* undefined, uint8_t* disconnected, bool print)
|
||||
{
|
||||
if (NULL == usb_cable) {
|
||||
return false;
|
||||
|
@ -1766,8 +1766,12 @@ bool usb_cables_check_cable(const struct usb_cable_t* usb_cable, uint8_t* define
|
|||
for (uint8_t pin_from = 0; pin_from < usb_cable->connectors[connector_from]->pins_nb; pin_from++) { // test from every pin
|
||||
uint32_t from_port = usb_cable->connectors[connector_from]->pins[pin_from].port;
|
||||
uint32_t from_pin = usb_cable->connectors[connector_from]->pins[pin_from].pin;
|
||||
for (uint8_t connector_to = 0; connector_to < usb_cable->connectors_nb; connector_to++) { // test to every connector
|
||||
for (uint8_t connector_to = connector_from; connector_to < usb_cable->connectors_nb; connector_to++) { // test to every connector
|
||||
for (uint8_t pin_to = 0; pin_to < usb_cable->connectors[connector_to]->pins_nb; pin_to++) { // test to every pin (except itself)
|
||||
if (connector_to == connector_from && pin_to < pin_from) {
|
||||
continue; // skip already tested internal connection
|
||||
}
|
||||
|
||||
uint32_t to_port = usb_cable->connectors[connector_to]->pins[pin_to].port;
|
||||
uint32_t to_pin = usb_cable->connectors[connector_to]->pins[pin_to].pin;
|
||||
|
||||
|
@ -1801,10 +1805,16 @@ bool usb_cables_check_cable(const struct usb_cable_t* usb_cable, uint8_t* define
|
|||
_defined++;
|
||||
} else {
|
||||
_undefined++;
|
||||
if (print) {
|
||||
printf("unspecified connection: %s %s to %s %s\n", usb_cable->connectors[connector_from]->name, usb_cable->connectors[connector_from]->pins[pin_from].name, usb_cable->connectors[connector_to]->name, usb_cable->connectors[connector_to]->pins[pin_to].name);
|
||||
}
|
||||
}
|
||||
} else { // there is no connection
|
||||
if (pair_defined) {
|
||||
_disconnected++;
|
||||
if (print) {
|
||||
printf("no connection: %s %s to %s %s\n", usb_cable->connectors[connector_from]->name, usb_cable->connectors[connector_from]->pins[pin_from].name, usb_cable->connectors[connector_to]->name, usb_cable->connectors[connector_to]->pins[pin_to].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,7 +117,8 @@ bool usb_cables_check_load(const struct usb_connector_t* connector);
|
|||
* @param[out] defined number of pin pairs that are connected according to definition
|
||||
* @param[out] undefined number of pin pairs that are connected but not according to definition
|
||||
* @param[out] disconnected number of pin pairs that are not connected but should according to definition
|
||||
* @param[in] print print connection errors
|
||||
* @return if the connections of the cable correspond to the definition
|
||||
* @note each pair is checked in both directions
|
||||
*/
|
||||
bool usb_cables_check_cable(const struct usb_cable_t* usb_cable, uint8_t* defined, uint8_t* undefined, uint8_t* disconnected);
|
||||
bool usb_cables_check_cable(const struct usb_cable_t* usb_cable, uint8_t* defined, uint8_t* undefined, uint8_t* disconnected, bool print);
|
||||
|
|
Loading…
Reference in New Issue