Support software controllable termination

This commit is contained in:
Paul Hollinsky
2021-04-11 22:13:51 -04:00
parent c8bf1f26da
commit e82b5d15e0
16 changed files with 588 additions and 6 deletions
+46 -1
View File
@@ -87,6 +87,7 @@ void printMainMenu() {
printf("I - Set HS CAN to 250K\n");
printf("J - Set HS CAN to 500K\n");
printf("L - Set Digital IO\n");
printf("M - Set HS CAN termination\n");
printf("X - Exit\n");
}
@@ -236,7 +237,7 @@ int main() {
while(true) {
printMainMenu();
printf("\n");
char input = getCharInput(24, 'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'L', 'l', 'X', 'x');
char input = getCharInput(26, 'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'L', 'l', 'M', 'm', 'X', 'x');
printf("\n");
switch(input) {
// List current devices
@@ -699,6 +700,50 @@ int main() {
}
}
break;
// Set HS CAN termination
case 'M':
case 'm':
{
// Select a device and get its description
if(numDevices == 0) {
printf("No devices found! Please scan for new devices.\n\n");
break;
}
selectedDevice = selectDevice();
// Get the product description for the device
char productDescription[ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION] = {};
size_t descriptionLength = ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION;
icsneo_describeDevice(selectedDevice, productDescription, &descriptionLength);
printf("Termination is ");
const bool val = icsneo_isTerminationEnabledFor(selectedDevice, ICSNEO_NETID_HSCAN);
neoevent_t err = {};
if(icsneo_getLastError(&err)) {
printf("not available at this time: %s\n\n", err.description);
break;
}
printf(val ? "currently enabled\n" : "currently disabled\n");
printf("[0] Disable\n[1] Enable\n[2] Cancel\n\n");
char selection2 = getCharInput(3, '0', '1', '2');
printf("\n");
if(selection2 == '2') {
printf("Canceling!\n\n");
break;
}
// Attempt to set baudrate and apply settings
if(icsneo_setTerminationFor(selectedDevice, ICSNEO_NETID_HSCAN, selection2 == '1') && icsneo_settingsApply(selectedDevice)) {
printf("Successfully set HS CAN termination for %s!\n\n", productDescription);
} else {
printf("Failed to set HS CAN termination for %s!\n\n", productDescription);
printLastError();
printf("\n");
}
}
break;
// Exit
case 'X':
case 'x':
@@ -43,6 +43,7 @@ void printMainMenu() {
std::cout << "J - Set LSFT CAN to 250K" << std::endl;
std::cout << "K - Add/Remove a message callback" << std::endl;
std::cout << "L - Set Digital IO" << std::endl;
std::cout << "M - Set HS CAN termination" << std::endl;
std::cout << "X - Exit" << std::endl;
}
@@ -192,7 +193,7 @@ int main() {
while(true) {
printMainMenu();
std::cout << std::endl;
char input = getCharInput(std::vector<char> {'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'X', 'x'});
char input = getCharInput(std::vector<char> {'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'X', 'x'});
std::cout << std::endl;
switch(input) {
@@ -721,6 +722,44 @@ int main() {
std::cout << "Failure! (" << icsneo::GetLastError() << ")" << std::endl << std::endl;
}
break;
// Set HS CAN termination
case 'M':
case 'm':
{
// Select a device and get its description
if(devices.size() == 0) {
std::cout << "No devices found! Please scan for new devices." << std::endl << std::endl;
break;
}
selectedDevice = selectDevice(devices);
std::cout << "Termination is ";
const auto val = selectedDevice->settings->isTerminationEnabledFor(icsneo::Network::NetID::HSCAN);
if(!val.has_value()) {
std::cout << "not available at this time: " << icsneo::GetLastError() << std::endl << std::endl;
break;
}
std::cout << (*val ? "currently enabled" : "currently disabled") << std::endl;
std::cout << "[0] Disable\n[1] Enable\n[2] Cancel" << std::endl << std::endl;
char selection2 = getCharInput({ '0', '1', '2' });
std::cout << std::endl;
if(selection2 == '2') {
std::cout << "Canceling!" << std::endl << std::endl;
break;
}
// Attempt to set termination and apply settings
if(selectedDevice->settings->setTerminationFor(icsneo::Network::NetID::HSCAN, selection2 == '1') && selectedDevice->settings->apply()) {
std::cout << "Successfully set HS CAN termination for " << selectedDevice->describe() << std::endl;
} else {
std::cout << "Failed to set HS CAN termination for " << selectedDevice->describe() << std::endl;
std::cout << icsneo::GetLastError() << std::endl;;
}
std::cout << std::endl;
}
break;
// Exit
case 'X':
case 'x':