Use getispeed instead of masking control bits.

pull/143/head^2
Fredrik Öhrström 2020-08-16 15:50:43 +02:00
rodzic e7a94a1423
commit 01554aaa82
1 zmienionych plików z 18 dodań i 7 usunięć

Wyświetl plik

@ -1080,14 +1080,12 @@ vector<string> SerialCommunicationManagerImp::listSerialDevices()
#endif
#define CHECK_SPEED(x) { if (bits == x) return #x; }
#define CHECK_SPEED(x) { if (speed == x) return #x; }
string lookupSpeed(tcflag_t bits)
string translateSpeed(speed_t speed)
{
string flags;
bits &= CBAUD;
CHECK_SPEED(B50)
CHECK_SPEED(B75)
CHECK_SPEED(B110)
@ -1149,11 +1147,24 @@ string lookupSpeed(tcflag_t bits)
CHECK_SPEED(B4000000)
#endif
return "UnknownSpeed";
return "UnknownSpeed";
};
#undef CHECK_SPEED
string lookupSpeed(struct termios *tios)
{
speed_t in = cfgetispeed(tios);
speed_t out = cfgetispeed(tios);
if (in == out)
{
return translateSpeed(in);
}
return translateSpeed(in)+","+translateSpeed(out);
}
#define CHECK_FLAG(x) { if (bits & x) flags += #x "|"; }
string iflags(tcflag_t bits)
@ -1211,8 +1222,7 @@ string cflags(tcflag_t bits)
CHECK_FLAG(CSTOPB)
CHECK_FLAG(HUPCL)
flags += lookupSpeed(bits);
if (flags.length() > 0) flags.pop_back();
return flags;
};
@ -1274,6 +1284,7 @@ static string showTTYSettings(int fd)
int rc = tcgetattr(fd, &tios);
if (rc != 0) goto err;
info += "speed("+lookupSpeed(&tios)+") ";
info += "input("+iflags(tios.c_iflag) + ") ";
info += "output("+oflags(tios.c_oflag) + ") ";
info += "control("+cflags(tios.c_cflag) + ") ";