diff --git a/Universal_Serial_Adapter/Config.cpp b/Universal_Serial_Adapter/Config.cpp index 12adbca..42add7d 100644 --- a/Universal_Serial_Adapter/Config.cpp +++ b/Universal_Serial_Adapter/Config.cpp @@ -40,6 +40,29 @@ linespeed Config::getLineSpeed() { return currentLineSpeed; } +int Config::getLineSpeedBaud() { + switch (currentLineSpeed) { + case 1: // twentyFourHundredBaud + return 2400; + break; + case 2: // ninetySixHundredBaud + return 9600; + break; + case 3: // nineteenTwoK + return 19200; + break; + case 4: // thirtyeightFourK + return 38400; + break; + case 5: // fiftysevenFiveK + return 57600; + break; + case 6: // oneNineteenTwoK + return 119200; + break; + } +} + ttlvoltage Config::getVoltage() { return currentVoltage; } @@ -63,6 +86,30 @@ int Config::getTimeoutMilis() { } void Config::setMode(serialmode mode) { + switch (currentMode) { + case 1: // ttl + Serial1.end(); + break; + case 2: // db9_null + Serial2.end(); + break; + case 3: // cisco + Serial3.end(); + break; + } + + switch (mode) { + case 1: // ttl + Serial1.begin(getLineSpeedBaud()); + break; + case 2: // db9_null + Serial2.begin(getLineSpeedBaud()); + break; + case 3: // cisco + Serial3.begin(getLineSpeedBaud()); + break; + } + currentMode = mode; } @@ -96,8 +143,8 @@ void Config::setTimeout(timeout aTimeout) { } void Config::setDefaults() { - setMode(ttl); - setLineSpeed(oneNineteenTwoK); setVoltage(onePointEight); + setLineSpeed(oneNineteenTwoK); + setMode(ttl); setTimeout(thirtyseconds); } diff --git a/Universal_Serial_Adapter/Config.h b/Universal_Serial_Adapter/Config.h index 54fbd94..db27c9f 100644 --- a/Universal_Serial_Adapter/Config.h +++ b/Universal_Serial_Adapter/Config.h @@ -36,6 +36,7 @@ public: void setTimeout(timeout aTimeout); serialmode getSerialMode(); linespeed getLineSpeed(); + int getLineSpeedBaud(); ttlvoltage getVoltage(); timeout getTimeout(); int getTimeoutMilis();