SerialConnect: fix baudrate settings save.

There was a mixup of using the baudrate value (eg 115200), constant
(B_115200_BPS = 17) and position in the menu (18), leading to the
baudrate setting not being saved and restored properly.
This commit is contained in:
Adrien Destugues 2013-12-21 20:30:47 +01:00
parent c516bac9f4
commit e2367275a8
3 changed files with 14 additions and 66 deletions

View File

@ -135,69 +135,7 @@ void SerialApp::MessageReceived(BMessage* message)
fSerialPort.SetFlowControl(flowcontrol);
if(message->FindInt32("baudrate", &baudrate) == B_OK) {
data_rate rate;
switch(baudrate) {
case 50:
rate = B_50_BPS;
break;
case 75:
rate = B_75_BPS;
break;
case 110:
rate = B_110_BPS;
break;
case 134:
rate = B_134_BPS;
break;
case 150:
rate = B_150_BPS;
break;
case 200:
rate = B_200_BPS;
break;
case 300:
rate = B_300_BPS;
break;
case 600:
rate = B_600_BPS;
break;
case 1200:
rate = B_1200_BPS;
break;
case 1800:
rate = B_1800_BPS;
break;
case 2400:
rate = B_2400_BPS;
break;
case 4800:
rate = B_4800_BPS;
break;
case 9600:
rate = B_9600_BPS;
break;
case 19200:
rate = B_19200_BPS;
break;
case 31250:
rate = B_31250_BPS;
break;
case 38400:
rate = B_38400_BPS;
break;
case 57600:
rate = B_57600_BPS;
break;
case 115200:
rate = B_115200_BPS;
break;
case 230400:
rate = B_230400_BPS;
break;
default:
rate = B_0_BPS;
break;
}
data_rate rate = (data_rate)baudrate;
fSerialPort.SetDataRate(rate);
}
@ -275,7 +213,7 @@ status_t SerialApp::PollSerial(void*)
{
ssize_t bytesRead;
bytesRead = application->fSerialPort.Read(buffer, 256);
bytesRead = application->fSerialPort.Read(buffer, sizeof(buffer));
if (bytesRead == B_FILE_ERROR)
{
// Port is not open - wait for it and start over

View File

@ -24,6 +24,15 @@ const int SerialWindow::kBaudrates[] = { 50, 75, 110, 134, 150, 200, 300, 600,
};
// The values for these constants are not in the expected order, so we have to
// rely on this lookup table if we want to keep the menu items sorted.
const int SerialWindow::kBaudrateConstants[] = { B_50_BPS, B_75_BPS, B_110_BPS,
B_134_BPS, B_150_BPS, B_200_BPS, B_300_BPS, B_600_BPS, B_1200_BPS,
B_1800_BPS, B_2400_BPS, B_4800_BPS, B_9600_BPS, B_19200_BPS, B_31250_BPS,
B_38400_BPS, B_57600_BPS, B_115200_BPS, B_230400_BPS
};
const char* SerialWindow::kWindowTitle = "SerialConnect";
@ -135,7 +144,7 @@ SerialWindow::SerialWindow()
for (int i = sizeof(kBaudrates) / sizeof(char*); --i >= 0;)
{
message = new BMessage(kMsgSettings);
message->AddInt32("baudrate", kBaudrates[i]);
message->AddInt32("baudrate", kBaudrateConstants[i]);
char buffer[7];
sprintf(buffer,"%d", kBaudrates[i]);
@ -323,7 +332,7 @@ void SerialWindow::MessageReceived(BMessage* message)
int32 code;
item->Message()->FindInt32("baudrate", &code);
if(code == kBaudrates[baudrate])
if(baudrate == code)
item->SetMarked(true);
}
}

View File

@ -32,5 +32,6 @@ class SerialWindow: public BWindow
BFilePanel* fLogFilePanel;
static const int kBaudrates[];
static const int kBaudrateConstants[];
static const char* kWindowTitle;
};