mirror of
https://github.com/autc04/Retro68.git
synced 2025-02-05 19:32:29 +00:00
LaunchAPPL/Serial: configurable bauf rate
This commit is contained in:
parent
f2542a0ff9
commit
6eb7da51c3
@ -3,9 +3,9 @@
|
||||
#include "Utilities.h"
|
||||
#include "Stream.h"
|
||||
#include "ReliableStream.h"
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <poll.h>
|
||||
|
||||
@ -49,6 +49,7 @@ private:
|
||||
SerialStream::SerialStream(po::variables_map &options)
|
||||
{
|
||||
std::string port = options["serial-port"].as<std::string>();
|
||||
int baud = options["serial-baud"].as<int>();
|
||||
fd = open(port.c_str(), O_RDWR | O_NOCTTY | O_NDELAY );
|
||||
if(fd < 0)
|
||||
throw std::runtime_error("Cannot open serial port.\n");
|
||||
@ -56,7 +57,20 @@ SerialStream::SerialStream(po::variables_map &options)
|
||||
struct termios tios;
|
||||
tcgetattr(fd,&tios);
|
||||
|
||||
tios.c_cflag = B19200 | CRTSCTS | CS8 | CLOCAL | CREAD;
|
||||
tios.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD;
|
||||
|
||||
switch(baud)
|
||||
{
|
||||
case 9600: tios.c_cflag |= B9600; break;
|
||||
case 19200: tios.c_cflag |= B19200; break;
|
||||
case 38400: tios.c_cflag |= B38400; break;
|
||||
case 57600: tios.c_cflag |= B57600; break;
|
||||
case 115200: tios.c_cflag |= B115200; break;
|
||||
case 230400: tios.c_cflag |= B230400; break;
|
||||
default:
|
||||
throw std::runtime_error("Unsupported baud rate.\n");
|
||||
}
|
||||
|
||||
tios.c_iflag = 0;//IGNPAR | ICRNL;
|
||||
tios.c_lflag = 0;
|
||||
tios.c_oflag = 0;
|
||||
@ -194,6 +208,7 @@ void Serial::GetOptions(options_description &desc)
|
||||
{
|
||||
desc.add_options()
|
||||
("serial-port", po::value<std::string>()->default_value("/dev/ttyUSB0"), "serial port to use")
|
||||
("serial-baud", po::value<int>()->default_value(19200), "serial port speed")
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,8 @@ enum
|
||||
{
|
||||
kMenuApple = 128,
|
||||
kMenuFile,
|
||||
kMenuEdit
|
||||
kMenuEdit,
|
||||
kMenuSpeed
|
||||
};
|
||||
|
||||
enum
|
||||
@ -50,6 +51,9 @@ enum
|
||||
kItemQuit = 1
|
||||
};
|
||||
|
||||
long gBaud = 19200;
|
||||
|
||||
void SetBaud(long baud);
|
||||
|
||||
void ShowAboutBox()
|
||||
{
|
||||
@ -116,6 +120,16 @@ void UpdateMenus()
|
||||
DisableItem(m,5);
|
||||
DisableItem(m,6);
|
||||
}
|
||||
|
||||
m = GetMenu(kMenuSpeed);
|
||||
for(int i = 1; i <= CountMenuItems(m); i++)
|
||||
{
|
||||
Str255 str;
|
||||
long baud;
|
||||
GetMenuItemText(m, i, str);
|
||||
StringToNum(str, &baud);
|
||||
CheckMenuItem(m, i, baud == gBaud);
|
||||
}
|
||||
}
|
||||
|
||||
void DoMenuCommand(long menuCommand)
|
||||
@ -154,7 +168,12 @@ void DoMenuCommand(long menuCommand)
|
||||
// edit command not handled by desk accessory
|
||||
}
|
||||
}
|
||||
|
||||
else if(menuID == kMenuSpeed)
|
||||
{
|
||||
GetMenuItemText(GetMenu(menuID), menuItem, str);
|
||||
StringToNum(str, &gBaud);
|
||||
SetBaud(gBaud);
|
||||
}
|
||||
HiliteMenu(0);
|
||||
}
|
||||
|
||||
@ -313,6 +332,12 @@ public:
|
||||
|
||||
short outRefNum;
|
||||
long outSize, outSizeRemaining;
|
||||
MacSerialStream *gSerialStream;
|
||||
|
||||
void SetBaud(long baud)
|
||||
{
|
||||
gSerialStream->setBaud(baud);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -334,6 +359,7 @@ int main()
|
||||
statusWindow = GetNewWindow(129, NULL, (WindowPtr) -1);
|
||||
SetStatus(AppStatus::ready);
|
||||
MacSerialStream stream;
|
||||
gSerialStream = &stream;
|
||||
|
||||
//#define SIMULATE_ERRORS
|
||||
#ifdef SIMULATE_ERRORS
|
||||
|
@ -55,8 +55,23 @@ resource 'MENU' (130) {
|
||||
}
|
||||
};
|
||||
|
||||
resource 'MENU' (131) {
|
||||
131, textMenuProc;
|
||||
allEnabled, enabled;
|
||||
"Speed";
|
||||
{
|
||||
"9600", noIcon, noKey, noMark, plain;
|
||||
"19200", noIcon, noKey, check, plain;
|
||||
"38400", noIcon, noKey, noMark, plain;
|
||||
"57600", noIcon, noKey, noMark, plain;
|
||||
"115200", noIcon, noKey, noMark, plain;
|
||||
"230400", noIcon, noKey, noMark, plain;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
resource 'MBAR' (128) {
|
||||
{ 128, 129, 130 };
|
||||
{ 128, 129, 130, 131 };
|
||||
};
|
||||
|
||||
data 'TEXT' (128) {
|
||||
|
@ -67,3 +67,25 @@ void MacSerialStream::idle()
|
||||
notifyReceive((uint8_t*)readBuffer, count1);
|
||||
}
|
||||
}
|
||||
|
||||
void MacSerialStream::setBaud(int baud)
|
||||
{
|
||||
short baudval = 0;
|
||||
switch(baud)
|
||||
{
|
||||
case 9600: baudval = baud9600; break;
|
||||
case 14400: baudval = baud14400; break;
|
||||
case 19200: baudval = baud19200; break;
|
||||
case 28800: baudval = baud28800; break;
|
||||
case 38400: baudval = baud38400; break;
|
||||
case 57600: baudval = baud57600; break;
|
||||
case 115200: baudval = 0; break;
|
||||
case 230400: baudval = 0; break;
|
||||
}
|
||||
SerReset(outRefNum, baudval | data8 | noParity | stop10);
|
||||
|
||||
if(baud == 115200)
|
||||
Control(outRefNum, kSERD115KBaud, nullptr);
|
||||
else if(baud == 230400)
|
||||
Control(outRefNum, kSERD230KBaud, nullptr);
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ public:
|
||||
~MacSerialStream();
|
||||
|
||||
void close();
|
||||
|
||||
void setBaud(int baud);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user