application: extend connection action
This commit is contained in:
parent
788a36b175
commit
30b7e9c4ba
104
application.c
104
application.c
|
@ -525,40 +525,84 @@ end:
|
|||
*/
|
||||
static void command_connections(void* argument)
|
||||
{
|
||||
(void)argument; // we won't use the argument
|
||||
|
||||
printf("= checking all pin connections =\n");
|
||||
uint16_t connections_nb = 0;
|
||||
uint8_t (*connections)[2] = (uint8_t (*)[2])usb_cables_check_connections(usb_connectors, LENGTH(usb_connectors), true, false, &connections_nb);
|
||||
if (NULL == connections) {
|
||||
if (connections_nb) {
|
||||
printf("no memory available\n");
|
||||
char* str = (char*)argument; // we won't use the argument
|
||||
bool intra = false; // check only connection internal connections
|
||||
bool inter = false; // check only inter-connector connections
|
||||
if (str) {
|
||||
if (0 == strcmp(str, "intra")) {
|
||||
intra = true;
|
||||
} else if (0 == strcmp(str, "inter")) {
|
||||
inter = true;
|
||||
} else {
|
||||
printf("no connections\n");
|
||||
printf("unknown argument: %s\n", str);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
printf("found %u connections:\n", connections_nb);
|
||||
for (uint16_t i = 0; i < connections_nb; i++) {
|
||||
const struct usb_connector_t* connector_from = usb_cables_get_connector(connections[i][0]);
|
||||
const struct usb_connector_t* connector_to = usb_cables_get_connector(connections[i][1]);
|
||||
if (NULL == connector_from || NULL == connector_to) {
|
||||
printf("no connector for a pin pair\n");
|
||||
continue;
|
||||
|
||||
|
||||
uint16_t connections_nb = 0;
|
||||
uint8_t (*connections)[2] = NULL;
|
||||
if (intra) {
|
||||
printf("= checking internal connections =\n");
|
||||
for (uint8_t i = 0; i < LENGTH(usb_connectors); i++) {
|
||||
const struct usb_connector_t* connector = usb_connectors[i];
|
||||
connections = (uint8_t (*)[2])usb_cables_check_connections(&connector, 1, true, false, &connections_nb);
|
||||
if (NULL == connections) {
|
||||
if (connections_nb) {
|
||||
printf("no memory available\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
printf("%s ", connector->name);
|
||||
if (connector->variant) {
|
||||
printf("(%s) ", connector->variant);
|
||||
}
|
||||
printf(": %u connection(s)\n", connections_nb);
|
||||
for (uint16_t connection = 0; connection < connections_nb; connection++) {
|
||||
printf("- %s to %s\n", usb_pins[connections[connection][0]].name, usb_pins[connections[connection][1]].name);
|
||||
}
|
||||
if (connections) {
|
||||
free(connections);
|
||||
connections = NULL;
|
||||
}
|
||||
}
|
||||
printf("%s ", connector_from->name);
|
||||
if (connector_from->variant) {
|
||||
printf("(%s) ", connector_from->variant);
|
||||
} else {
|
||||
if (inter) {
|
||||
printf("= checking connections between connectors =\n");
|
||||
} else {
|
||||
printf("= checking all connections =\n");
|
||||
}
|
||||
printf("%s to %s ", usb_pins[connections[i][0]].name, connector_to->name);
|
||||
if (connector_to->variant) {
|
||||
printf("(%s) ", connector_from->variant);
|
||||
connections = (uint8_t (*)[2])usb_cables_check_connections(usb_connectors, LENGTH(usb_connectors), !inter, false, &connections_nb);
|
||||
if (NULL == connections) {
|
||||
if (connections_nb) {
|
||||
printf("no memory available\n");
|
||||
} else {
|
||||
printf("no connections\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
printf("found %u connections:\n", connections_nb);
|
||||
for (uint16_t i = 0; i < connections_nb; i++) {
|
||||
const struct usb_connector_t* connector_from = usb_cables_get_connector(connections[i][0]);
|
||||
const struct usb_connector_t* connector_to = usb_cables_get_connector(connections[i][1]);
|
||||
if (NULL == connector_from || NULL == connector_to) {
|
||||
printf("no connector for a pin pair\n");
|
||||
continue;
|
||||
}
|
||||
printf("%s ", connector_from->name);
|
||||
if (connector_from->variant) {
|
||||
printf("(%s) ", connector_from->variant);
|
||||
}
|
||||
printf("%s to %s ", usb_pins[connections[i][0]].name, connector_to->name);
|
||||
if (connector_to->variant) {
|
||||
printf("(%s) ", connector_from->variant);
|
||||
}
|
||||
printf("%s\n", usb_pins[connections[i][1]].name);
|
||||
}
|
||||
if (connections) {
|
||||
free(connections);
|
||||
connections = NULL;
|
||||
}
|
||||
printf("%s\n", usb_pins[connections[i][1]].name);
|
||||
}
|
||||
if (connections) {
|
||||
free(connections);
|
||||
connections = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -666,8 +710,8 @@ static const struct menu_command_t menu_commands[] = {
|
|||
.shortcut = 'x',
|
||||
.name = "connections",
|
||||
.command_description = "test all pin connections",
|
||||
.argument = MENU_ARGUMENT_NONE,
|
||||
.argument_description = NULL,
|
||||
.argument = MENU_ARGUMENT_STRING,
|
||||
.argument_description = "[inter|intra]",
|
||||
.command_handler = &command_connections,
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue