better wording, add sections to cmdline help, simplify+rename variant argument

This commit is contained in:
John
2022-12-11 10:01:40 +01:00
parent 40884341f7
commit 8590a8048c
+31 -45
View File
@@ -46,32 +46,35 @@ const char *argp_program_version = "eBUS adapter PIC firmware loader";
/** the documentation of the program. */ /** the documentation of the program. */
static const char argpdoc[] = static const char argpdoc[] =
"A tool for loading firmware to the eBUS adapter PIC and configure some adjustable settings." "A tool for loading firmware to the eBUS adapter PIC and configure adjustable settings."
"\vPORT is either the serial port to use (e.g./dev/ttyUSB0) that also supports a trailing wildcard '*' for testing" "\vPORT is either the serial port to use (e.g./dev/ttyUSB0) that also supports a trailing wildcard '*' for testing"
" multiple ports, or a network port as \"ip:port\" for use with e.g. socat or ebusd-esp."; " multiple ports, or a network port as \"ip:port\" for use with e.g. socat or ebusd-esp in PIC pass-through mode.";
static const char argpargsdoc[] = "PORT"; static const char argpargsdoc[] = "PORT";
/** the definition of the known program arguments. */ /** the definition of the known program arguments. */
static const struct argp_option argpoptions[] = { static const struct argp_option argpoptions[] = {
{"verbose", 'v', nullptr, 0, "enable verbose output", 0 }, {nullptr, 0, nullptr, 0, "IP options:", 1 },
{"dhcp", 'd', nullptr, 0, "set dynamic IP address via DHCP (default)", 0 }, {"dhcp", 'd', nullptr, 0, "set dynamic IP address via DHCP (default)", 0 },
{"ip", 'i', "IP", 0, "set fix IP address (e.g. 192.168.0.10)", 0 }, {"ip", 'i', "IP", 0, "set fix IP address (e.g. 192.168.0.10)", 0 },
{"mask", 'm', "MASK", 0, "set fix IP mask (e.g. 24)", 0 }, {"mask", 'm', "MASK", 0, "set fix IP mask (e.g. 24)", 0 },
{"gateway", 'g', "GW", 0, "set fix IP gateway to GW (if necessary and other than net address + 1)", 0 }, {"gateway", 'g', "GW", 0, "set fix IP gateway to GW (if necessary and other than net address + 1)", 0 },
{"macip", 'M', nullptr, 0, "set the MAC address suffix from the IP address", 0 }, {"macip", 'M', nullptr, 0, "set the MAC address suffix from the IP address", 0 },
{"macid", 'I', nullptr, 0, "set the MAC address suffix from internal ID (default)", 0 }, {"macid", 'N', nullptr, 0, "set the MAC address suffix from internal ID (default)", 0 },
{nullptr, 0, nullptr, 0, "eBUS options:", 2 },
{"arbdel", 'a', "US", 0, "set arbitration delay to US microseconds (0-620 in steps of 10, default 200" {"arbdel", 'a', "US", 0, "set arbitration delay to US microseconds (0-620 in steps of 10, default 200"
", since firmware 20211128)", 0 }, ", since firmware 20211128)", 0 },
{nullptr, 0, nullptr, 0, "PIC options:", 3 },
{"pingon", 'p', nullptr, 0, "enable visual ping (default)", 0 }, {"pingon", 'p', nullptr, 0, "enable visual ping (default)", 0 },
{"pingoff", 'o', nullptr, 0, "disable visual ping", 0 }, {"pingoff", 'o', nullptr, 0, "disable visual ping", 0 },
{"softvar", -3, "VARIANT", 0, "set the soft jumpers VARIANT to U=USB/RPI (default), W=WIFI, E=Ethernet," {"variant", -3, "VARIANT", 0, "set the VARIANT to U=USB/RPI, W=WIFI, E=Ethernet,"
" N=non-enhanced USB/RPI/WIFI, F=non-enhanced Ethernet" " N=non-enhanced USB/RPI/WIFI, F=non-enhanced Ethernet"
" (prefer hard jumpers in lowercase, ignore hard jumpers in uppercase" " (lowercase to allow hardware jumpers, default \"u\""
", since firmware 20221206)", 0 }, ", since firmware 20221206)", 0 },
{"hardvar", -4, nullptr, 0, "set the variant from hard jumpers only (ignore soft jumpers)", 0 },
{"flash", 'f', "FILE", 0, "flash the FILE to the device", 0 }, {"flash", 'f', "FILE", 0, "flash the FILE to the device", 0 },
{"reset", 'r', nullptr, 0, "reset the device at the end on success", 0 }, {"reset", 'r', nullptr, 0, "reset the device at the end on success", 0 },
{nullptr, 0, nullptr, 0, "Tool options:", 9 },
{"verbose", 'v', nullptr, 0, "enable verbose output", 0 },
{"slow", 's', nullptr, 0, "use low speed for transfer", 0 }, {"slow", 's', nullptr, 0, "use low speed for transfer", 0 },
{nullptr, 0, nullptr, 0, nullptr, 0 }, {nullptr, 0, nullptr, 0, nullptr, 0 },
}; };
@@ -90,10 +93,9 @@ static bool setArbitrationDelay = false;
static uint16_t setArbitrationDelayMicros = 0; static uint16_t setArbitrationDelayMicros = 0;
static bool setVisualPing = false; static bool setVisualPing = false;
static bool setVisualPingOn = false; static bool setVisualPingOn = false;
static bool setSoftVariant = false; static bool setVariant = false;
static uint8_t setSoftVariantValue = 0; static uint8_t setVariantValue = 0;
static bool setSoftVariantForced = false; static bool setVariantForced = false;
static bool setHardVariant = false;
static char* flashFile = nullptr; static char* flashFile = nullptr;
static bool reset = false; static bool reset = false;
static bool lowSpeed = false; static bool lowSpeed = false;
@@ -272,7 +274,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
setMacFromIp = true; setMacFromIp = true;
setMacFromIpValue = true; setMacFromIpValue = true;
break; break;
case 'I': // --macid case 'N': // --macid
setMacFromIp = true; setMacFromIp = true;
setMacFromIpValue = false; setMacFromIpValue = false;
break; break;
@@ -295,40 +297,27 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
setVisualPing = true; setVisualPing = true;
setVisualPingOn = false; setVisualPingOn = false;
break; break;
case -3: // --softvar=U|W|E|F|N|u|w|e|f|n case -3: // --variant=U|W|E|F|N|u|w|e|f|n
if (setHardVariant) {
argp_error(state, "can't set hard and soft jumpers");
return EINVAL;
}
if (arg == nullptr || arg[0] == 0) { if (arg == nullptr || arg[0] == 0) {
argp_error(state, "invalid variant"); argp_error(state, "invalid variant");
return EINVAL; return EINVAL;
} }
if (arg[0] == 'u' || arg[0] == 'U') { if (arg[0] == 'u' || arg[0] == 'U') {
setSoftVariantValue = 3; setVariantValue = 3;
} else if (arg[0] == 'w' || arg[0] == 'W') { } else if (arg[0] == 'w' || arg[0] == 'W') {
setSoftVariantValue = 2; setVariantValue = 2;
} else if (arg[0] == 'e' || arg[0] == 'E') { } else if (arg[0] == 'e' || arg[0] == 'E') {
setSoftVariantValue = 1; setVariantValue = 1;
} else if (arg[0] == 'f' || arg[0] == 'F') { } else if (arg[0] == 'f' || arg[0] == 'F') {
setSoftVariantValue = 4; setVariantValue = 4;
} else if (arg[0] == 'n' || arg[0] == 'N') { } else if (arg[0] == 'n' || arg[0] == 'N') {
setSoftVariantValue = 0; setVariantValue = 0;
} else { } else {
argp_error(state, "invalid variant"); argp_error(state, "invalid variant");
return EINVAL; return EINVAL;
} }
setSoftVariantForced = arg[0]<'a'; setVariantForced = arg[0]<'a';
setSoftVariant = true; setVariant = true;
break;
case -4: // --hardvar
if (setSoftVariant) {
argp_error(state, "can't set hard and soft jumpers");
return EINVAL;
}
setSoftVariantValue = 3;
setSoftVariantForced = false;
setHardVariant = true;
break; break;
case 'f': // --flash=firmware.hex case 'f': // --flash=firmware.hex
if (arg == nullptr || arg[0] == 0 || stat(arg, &st) != 0 || !S_ISREG(st.st_mode)) { if (arg == nullptr || arg[0] == 0 || stat(arg, &st) != 0 || !S_ISREG(st.st_mode)) {
@@ -1096,9 +1085,6 @@ int readSettings(int fd, uint8_t* currentData = nullptr) {
std::cout << "off" << std::endl; std::cout << "off" << std::endl;
} }
std::cout << "Variant: "; // since firmware 20221206 std::cout << "Variant: "; // since firmware 20221206
if ((configData[5]&0x07)==0x07) {
std::cout << "hard jumpers only (includes USB/RPI enhanced when no jumpers are set)" << std::endl;
} else {
switch (configData[5]&0x03) { switch (configData[5]&0x03) {
case 3: case 3:
std::cout << "USB/RPI"; std::cout << "USB/RPI";
@@ -1118,12 +1104,14 @@ int readSettings(int fd, uint8_t* currentData = nullptr) {
} }
} }
if (configData[5]&0x04) { if (configData[5]&0x04) {
std::cout << ", prefer hard jumpers"; std::cout << ", allow hardware jumpers";
} else { } else {
std::cout << ", ignore hard jumpers"; std::cout << ", ignore hardware jumpers";
}
if ((configData[5]&0x07)==0x07) {
std::cout << " (default)";
} }
std::cout << std::endl; std::cout << std::endl;
}
return 0; return 0;
} }
@@ -1155,13 +1143,11 @@ bool writeSettings(int fd, uint8_t* currentData = nullptr) {
if (setVisualPing) { if (setVisualPing) {
configData[5] = (configData[5]&0x1f) | (setVisualPingOn?0x20:0); configData[5] = (configData[5]&0x1f) | (setVisualPingOn?0x20:0);
} }
if (setSoftVariant) { if (setVariant) {
configData[5] = (configData[5]&0x38) | (setSoftVariantForced?0:0x04) | (setSoftVariantValue&0x03); configData[5] = (configData[5]&0x38) | (setVariantForced?0:0x04) | (setVariantValue&0x03);
if (setSoftVariantValue==0) { if (setVariantValue==0) {
configData[1] = (configData[1]&~0x1f); // set mask=0 to disable Ethernet configData[1] = (configData[1]&~0x1f); // set mask=0 to disable Ethernet
} }
} else if (setHardVariant) {
configData[5] = (configData[5]&0x38) | 0x07;
} }
if (writeConfig(fd, 0x0000, 8, configData) != 0) { if (writeConfig(fd, 0x0000, 8, configData) != 0) {
std::cerr << "failed" << std::endl; std::cerr << "failed" << std::endl;
@@ -1313,7 +1299,7 @@ int run(int fd) {
success = false; success = false;
} }
} }
if (setMacFromIp || setIp || setDhcp || setArbitrationDelay || setVisualPing || setSoftVariant || setHardVariant) { if (setMacFromIp || setIp || setDhcp || setArbitrationDelay || setVisualPing || setVariant) {
if (writeSettings(fd, useCurrentConfigData ? currentConfigData : nullptr)) { if (writeSettings(fd, useCurrentConfigData ? currentConfigData : nullptr)) {
std::cout << "Settings changed to:" << std::endl; std::cout << "Settings changed to:" << std::endl;
readSettings(fd); readSettings(fd);