application: display connection details when single cable is tested
This commit is contained in:
parent
ac3975c1b2
commit
73bbb7974d
174
application.c
174
application.c
|
@ -631,6 +631,79 @@ static void cable_issues(struct cable_t* cable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** print cable connections
|
||||||
|
* @param[in] cable cable for which to calculate the score
|
||||||
|
*/
|
||||||
|
static void cable_print_connections(const struct cable_t* cable)
|
||||||
|
{
|
||||||
|
if (NULL == cable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (cable->cable_best < LENGTH(usb_cables) && cable->cable_best < LENGTH(cable->unconnected_nb) && cable->cable_best < LENGTH(cable->unconnected_nb) && cable->cables[cable->cable_best]) {
|
||||||
|
// there is a best cable
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cable->unconnected_nb[cable->cable_best] > 0) {
|
||||||
|
printf("unconnected pins:\n");
|
||||||
|
for (uint16_t i = 0; i < cable->unconnected_nb[cable->cable_best]; i++) {
|
||||||
|
const struct usb_connector_t* connector_from = usb_cables_get_connector(cable->unconnected[i][0]);
|
||||||
|
const struct usb_connector_t* connector_to = usb_cables_get_connector(cable->unconnected[i][1]);
|
||||||
|
if (NULL == connector_from || NULL == connector_to) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
printf("- %s ", connector_from->name);
|
||||||
|
if (connector_from->variant) {
|
||||||
|
printf("(%s) ", connector_from->variant);
|
||||||
|
}
|
||||||
|
printf("%s to %s ", usb_pins[cable->unconnected[i][0]].name, connector_to->name);
|
||||||
|
if (connector_to->variant) {
|
||||||
|
printf("(%s) ", connector_from->variant);
|
||||||
|
}
|
||||||
|
printf("%s\n", usb_pins[cable->unconnected[i][1]].name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cable->unspecified_nb[cable->cable_best] > 0) {
|
||||||
|
printf("unspecified connections:\n");
|
||||||
|
for (uint16_t i = 0; i < cable->unspecified_nb[cable->cable_best]; i++) {
|
||||||
|
const struct usb_connector_t* connector_from = usb_cables_get_connector(cable->unspecified[i][0]);
|
||||||
|
const struct usb_connector_t* connector_to = usb_cables_get_connector(cable->unspecified[i][1]);
|
||||||
|
if (NULL == connector_from || NULL == connector_to) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
printf("- %s ", connector_from->name);
|
||||||
|
if (connector_from->variant) {
|
||||||
|
printf("(%s) ", connector_from->variant);
|
||||||
|
}
|
||||||
|
printf("%s to %s ", usb_pins[cable->unspecified[i][0]].name, connector_to->name);
|
||||||
|
if (connector_to->variant) {
|
||||||
|
printf("(%s) ", connector_to->variant);
|
||||||
|
}
|
||||||
|
printf("%s\n", usb_pins[cable->unspecified[i][1]].name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cable->optional_nb[cable->cable_best] > 0) {
|
||||||
|
printf("optional connections:\n");
|
||||||
|
for (uint16_t i = 0; i < cable->optional_nb[cable->cable_best]; i++) {
|
||||||
|
const struct usb_connector_t* connector_from = usb_cables_get_connector(cable->optional[i][0]);
|
||||||
|
const struct usb_connector_t* connector_to = usb_cables_get_connector(cable->optional[i][1]);
|
||||||
|
if (NULL == connector_from || NULL == connector_to) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
printf("- %s ", connector_from->name);
|
||||||
|
if (connector_from->variant) {
|
||||||
|
printf("(%s) ", connector_from->variant);
|
||||||
|
}
|
||||||
|
printf("%s to %s ", usb_pins[cable->optional[i][0]].name, connector_to->name);
|
||||||
|
if (connector_to->variant) {
|
||||||
|
printf("(%s) ", connector_to->variant);
|
||||||
|
}
|
||||||
|
printf("%s\n", usb_pins[cable->optional[i][1]].name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ================================
|
// ================================
|
||||||
// = generic commands definitions =
|
// = generic commands definitions =
|
||||||
// ================================
|
// ================================
|
||||||
|
@ -690,19 +763,46 @@ static void command_cables(void* argument)
|
||||||
usb_cables_pins_float(); // start with all pins in safe floating state
|
usb_cables_pins_float(); // start with all pins in safe floating state
|
||||||
|
|
||||||
// step 2: check for known cable configuration
|
// step 2: check for known cable configuration
|
||||||
|
struct cable_t* cable = calloc(1, sizeof(struct cable_t)); // structure to store cable information
|
||||||
printf("= cable check =\n");
|
printf("= cable check =\n");
|
||||||
for (uint8_t cable = 0; cable < LENGTH(usb_cables); cable++) { // test every cable
|
for (uint8_t cable_j = 0; cable_j < LENGTH(usb_cables); cable_j++) { // test every cable
|
||||||
iwdg_reset(); // kick the dog
|
iwdg_reset(); // kick the dog
|
||||||
if (0xff == cable_i || cable == cable_i) { // only test specified cable (or all if unspecified)
|
if (0xff == cable_i || cable_j == cable_i) { // only test specified cable (or all if unspecified)
|
||||||
uint8_t pair_defined, pair_optional, pair_undefined;
|
// define the cable to be tested
|
||||||
bool result = usb_cables_test_cable(&usb_cables[cable], &pair_defined, &pair_optional, &pair_undefined, false);
|
cable_clear(cable);
|
||||||
printf("%02u %s: %s ", cable, result ? "pass" : "fail", usb_cables[cable].name);
|
cable->cables_nb = 1;
|
||||||
if (usb_cables[cable].variant) {
|
cable->cables[cable_j] = true;
|
||||||
printf("- %s ", usb_cables[cable].variant);
|
cable->cable_best = cable_j;
|
||||||
|
for (uint8_t connector_i = 0; connector_i < usb_cables[cable_j].connectors_nb; connector_i++) {
|
||||||
|
for (uint8_t connector_j = 0; connector_j < LENGTH(usb_connectors) && connector_j < LENGTH(cable->connectors); connector_j++) {
|
||||||
|
if (usb_cables[cable_j].connectors[connector_i] == usb_connectors[connector_j]) {
|
||||||
|
cable->connectors[connector_j] = true;
|
||||||
|
cable->connectors_nb++;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
printf("(defined=%u/%u, optional=%u/%u, undefined=%u)\n", pair_defined, usb_cables[cable].mandatory_pairs_nb, pair_optional, usb_cables[cable].optional_pairs_nb, pair_undefined);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// show the number of issues
|
||||||
|
cable_issues_nb(cable);
|
||||||
|
uint16_t issues_nb = cable->unconnected_nb[cable_j] + cable->unspecified_nb[cable_j];
|
||||||
|
printf("%02u %s: %s ", cable_j, 0 == issues_nb ? "pass" : "fail", usb_cables[cable_j].name);
|
||||||
|
if (usb_cables[cable_j].variant) {
|
||||||
|
printf("- %s ", usb_cables[cable_j].variant);
|
||||||
|
}
|
||||||
|
printf("(unconnected=%u/%u, optional=%u/%u, unspecified=%u)\n", cable->unconnected_nb[cable_j], usb_cables[cable_j].mandatory_pairs_nb, cable->optional_nb[cable_j], usb_cables[cable_j].optional_pairs_nb, cable->unspecified_nb[cable_j]);
|
||||||
|
if (cable_j == cable_i) { // print connection details if a specific cable has been provided
|
||||||
|
cable_issues(cable); // get the connections
|
||||||
|
cable_print_connections(cable); // print connection details
|
||||||
|
cable_load(cable); // check if there is a load
|
||||||
|
printf("there is %s load in the cable\n", cable->load ? "a" : "no");
|
||||||
|
}
|
||||||
|
cable_clear(cable); // free memory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cable) {
|
||||||
|
free(cable);
|
||||||
|
cable = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
usb_cables_pins_float(); // put all pins back in safe floating state
|
usb_cables_pins_float(); // put all pins back in safe floating state
|
||||||
}
|
}
|
||||||
|
@ -815,63 +915,7 @@ static void command_find(void* argument)
|
||||||
putc('\n');
|
putc('\n');
|
||||||
printf("connection issue(s): %u (%u unconnected, %u unspecified)\n", issues, cable->unconnected_nb[cable->cable_best], cable->unspecified_nb[cable->cable_best]);
|
printf("connection issue(s): %u (%u unconnected, %u unspecified)\n", issues, cable->unconnected_nb[cable->cable_best], cable->unspecified_nb[cable->cable_best]);
|
||||||
}
|
}
|
||||||
if (cable->unconnected_nb[cable->cable_best] > 0) {
|
cable_print_connections(cable); // print cable connections details
|
||||||
printf("unconnected pins:\n");
|
|
||||||
for (uint16_t i = 0; i < cable->unconnected_nb[cable->cable_best]; i++) {
|
|
||||||
const struct usb_connector_t* connector_from = usb_cables_get_connector(cable->unconnected[i][0]);
|
|
||||||
const struct usb_connector_t* connector_to = usb_cables_get_connector(cable->unconnected[i][1]);
|
|
||||||
if (NULL == connector_from || NULL == connector_to) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
printf("- %s ", connector_from->name);
|
|
||||||
if (connector_from->variant) {
|
|
||||||
printf("(%s) ", connector_from->variant);
|
|
||||||
}
|
|
||||||
printf("%s to %s ", usb_pins[cable->unconnected[i][0]].name, connector_to->name);
|
|
||||||
if (connector_to->variant) {
|
|
||||||
printf("(%s) ", connector_from->variant);
|
|
||||||
}
|
|
||||||
printf("%s\n", usb_pins[cable->unconnected[i][1]].name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cable->unspecified_nb[cable->cable_best] > 0) {
|
|
||||||
printf("unspecified connections:\n");
|
|
||||||
for (uint16_t i = 0; i < cable->unspecified_nb[cable->cable_best]; i++) {
|
|
||||||
const struct usb_connector_t* connector_from = usb_cables_get_connector(cable->unspecified[i][0]);
|
|
||||||
const struct usb_connector_t* connector_to = usb_cables_get_connector(cable->unspecified[i][1]);
|
|
||||||
if (NULL == connector_from || NULL == connector_to) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
printf("- %s ", connector_from->name);
|
|
||||||
if (connector_from->variant) {
|
|
||||||
printf("(%s) ", connector_from->variant);
|
|
||||||
}
|
|
||||||
printf("%s to %s ", usb_pins[cable->unspecified[i][0]].name, connector_to->name);
|
|
||||||
if (connector_to->variant) {
|
|
||||||
printf("(%s) ", connector_to->variant);
|
|
||||||
}
|
|
||||||
printf("%s\n", usb_pins[cable->unspecified[i][1]].name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cable->optional_nb[cable->cable_best] > 0) {
|
|
||||||
printf("optional connections:\n");
|
|
||||||
for (uint16_t i = 0; i < cable->optional_nb[cable->cable_best]; i++) {
|
|
||||||
const struct usb_connector_t* connector_from = usb_cables_get_connector(cable->optional[i][0]);
|
|
||||||
const struct usb_connector_t* connector_to = usb_cables_get_connector(cable->optional[i][1]);
|
|
||||||
if (NULL == connector_from || NULL == connector_to) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
printf("- %s ", connector_from->name);
|
|
||||||
if (connector_from->variant) {
|
|
||||||
printf("(%s) ", connector_from->variant);
|
|
||||||
}
|
|
||||||
printf("%s to %s ", usb_pins[cable->optional[i][0]].name, connector_to->name);
|
|
||||||
if (connector_to->variant) {
|
|
||||||
printf("(%s) ", connector_to->variant);
|
|
||||||
}
|
|
||||||
printf("%s\n", usb_pins[cable->optional[i][1]].name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("there is %s load in the cable\n", cable->load ? "a" : "no");
|
printf("there is %s load in the cable\n", cable->load ? "a" : "no");
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
|
Loading…
Reference in New Issue