From beb202aeacbf4bca2be8fad912034c45afdf4dd1 Mon Sep 17 00:00:00 2001
From: Oliver Schmidt
Date: Wed, 14 Feb 2018 21:18:24 +0100
Subject: [PATCH] Added baud rate option.
Interestingly libserialport doesn't complain about any weird value. So there's nothing to validate.
Surprisingly Windows doesn't complain about any weird value! So even the sp_set_config() succeeds!
---
server/main.cpp | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/server/main.cpp b/server/main.cpp
index f61c017..f7710e6 100644
--- a/server/main.cpp
+++ b/server/main.cpp
@@ -53,6 +53,7 @@ int main(int argc, char *argv[])
bool bVerbose = false;
bool bLog = true;
char *pPortname = 0;
+ int iBaudrate = 230400;
char *apFilename[2] = {0, 0};
for (int iArg = 1; iArg < argc; iArg++)
@@ -60,6 +61,22 @@ int main(int argc, char *argv[])
// Process option
if (argv[iArg][0] == '-')
{
+ if (argv[iArg][1] == 'b')
+ {
+ char *pEnd;
+ long lBaudrate = strtol(&argv[iArg][2], &pEnd, 10);
+ iBaudrate = (int)lBaudrate;
+ if (*pEnd || iBaudrate != lBaudrate)
+ {
+ // Force usage
+ apFilename[0] = 0;
+ break;
+ }
+ if (bVerbose)
+ printf("Baud: %d\n", iBaudrate);
+ continue;
+ }
+
if (argv[iArg][1] == 'p')
{
pPortname = &argv[iArg][2];
@@ -106,9 +123,10 @@ int main(int argc, char *argv[])
if (apFilename[0] == 0)
{
- printf("Usage: %s [-nv] [-p] img1 [img2]\n"
+ printf("Usage: %s [-nv] [-b] [-p] img1 [img2]\n"
"\t-n\t\tno logging\n"
"\t-v\t\tbe verbose\n"
+ "\t-b\tbaud rate\n"
"\t-p\t(partial) serial portname\n"
"\timg1\t\tdrive 1 disk image filename\n"
"\timg2\t\tdrive 2 disk image filename\n",
@@ -149,7 +167,7 @@ int main(int argc, char *argv[])
// Create a configuration for the serial ports
struct sp_port_config *pSerialConfig = 0;
assert(sp_new_config(&pSerialConfig) == SP_OK);
- assert(sp_set_config_baudrate(pSerialConfig, 230400) == SP_OK);
+ assert(sp_set_config_baudrate(pSerialConfig, iBaudrate) == SP_OK);
assert(sp_set_config_bits(pSerialConfig, 8) == SP_OK);
assert(sp_set_config_parity(pSerialConfig, SP_PARITY_NONE) == SP_OK);
assert(sp_set_config_stopbits(pSerialConfig, 1) == SP_OK);